Software Distributor
Free Copy Protection
Software Downloads
Help>Sample Code For Delphi Copy Protection
Software Distributor
Copy Protection
Menu
Info
Company
Resources
Copy Protection Sample Code for Borland Delphi Object Pascal



// Delphi Subroutine

unit ZSSSGLOCKUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls;
{ THIS IS FOR STATIC DLL - AFTER THE USES CLAUSE }
function ShareGuardLock(LocksmithParameters: PChar): PChar;
stdcall external 'ZSSGLOCK.dll';
function CRC32FileCheck(FileName: PChar): PChar;
stdcall external 'ZSSGCRC32.dll';
type
TFormShareGuardLockDLLDemo = class(TForm)
EditLocksmithParameters: TEdit;
EditStatic: TEdit;
EditDynamic: TEdit;
ButtonStatic: TButton;
ButtonDynamic: TButton;
ButtonClose: TButton;
LabelTitle: TLabel;
LabelDemo: TLabel;
LabelReasonCode: TLabel;
LabelLocksmithParameters: TLabel;
CheckBoxShutDown: TCheckBox;
LabelCRC: TLabel;
EditCRCStatic: TEdit;
EditCRCDynamic: TEdit;
procedure ButtonStaticClick(Sender: TObject);
procedure ButtonDynamicClick(Sender: TObject);
procedure ButtonCloseClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FormShareGuardLockDLLDemo:
TFormShareGuardLockDLLDemo;
implementation
{$R *.dfm}

procedure TFormShareGuardLockDLLDemo.ButtonStaticClick
(Sender: TObject);
{ THIS IS FOR STATIC DLL }
var
LocksmithParameters: String;

sReturnCode: String;
FileName: String;
sValue: String;
begin
// Static CRC Check
{
(1) Generate parameters in Locksmith Lock page
(2) Define either static or dynamic calling of DLLs
(3) Perform CRC check on the ZSSGLOCK.DLL to ensure that it
is correct. If it does not have the correct CRC value then
shut down the application.
(4) Call the ShareGuardLock function in the ZSSGLOCK.DLL with the
Locksmith Parameters for calling the Lock program (ZSSGL.EXE)
(5) Check the Return Code - if it is not zero then shut application
down
Reason Codes:
0 - OK
1 - CRC Check failed, DLL Missing
2 - CRC Check failed, product modifed - incorrect version or tampered
with by user
3 - Invalid Registration
4 - Demo Expired
5 - Parameters missing or invalid - ZSSGL.EXE parms
6 - System Migrated to another computer
7 - ZSSGL.EXE program missing }
FileName := 'ZSSGLOCK.DLL';
sValue := CRC32FileCheck(PChar(FileName));
EditCRCStatic.Text := sValue; // Just for display
if sValue <> '7DB4D285' then // Use Tools CRC Check for value of
ZSSGLOCK.DLL
   begin
     MessageDlg('Invalid CRC for ZSSGLOCK.DLL',
mtError, [mbOK], 0);
     Application.Terminate;
     Halt;
   end;

// Static Lock Check
LocksmithParameters := EditLocksmithParameters.Text;
sReturnCode := ShareGuardLock(PChar(LocksmithParameters));
EditStatic.Text := sReturnCode; // This is to display on form
if sReturnCode <> '0' then
// The following condition test is for demo purposes just to show
reason codes.
// Normally, you will shut down the application for anything other
than ZERO
if CheckBoxShutDown.Checked then // Remove this line of code
   begin
     MessageDlg('Shutting down the demo.', mtError, [mbOK], 0);
     Application.Terminate;
     Halt;
   end;
end;

procedure TFormShareGuardLockDLLDemo.ButtonDynamicClick
(Sender: TObject);
{ THIS IS FOR DYNAMIC DLL }
type TCRC32FileCheck = function(FileName: PChar): PChar;
stdcall;
type
TShareGuardLock = function(FileName: PChar): PChar; stdcall;
var
DLLInstance : THandle;
CRC32FileCheck : TCRC32FileCheck;
sValue: String;
ShareGuardLock : TShareGuardLock;
LocksmithParameters: String;
sReturnCode: String;
FileName: String;
begin
// Dynamic CRC Check
// Use Delphi Version as it is already used in Lock Program
FileName := 'ZSSGLOCK.DLL'; // Check the CRC value of the Lock DLL
DLLInstance := LoadLibrary('ZSSGCRC32.DLL');
if DLLInstance = 0 then
   begin
     MessageDlg('Unable to load ZSSGCRC32.DLL', mtError, [mbOK], 0);
     Application.Terminate;
     Halt;
end;
@CRC32FileCheck := GetProcAddress(DLLInstance, 'CRC32FileCheck');
if @CRC32FileCheck <> nil then
   sValue := CRC32FileCheck(PChar(FileName))
else
   begin
     MessageDlg('Unable to locate procedure address for ZSSGCRC32.DLL',
mtError, [mbOK], 0);
     Application.Terminate;
     Halt;
   end;
FreeLibrary(DLLInstance);
EditCRCDynamic.Text := sValue; // Just for display
if sValue <> '7DB4D285' then // Use Tools CRC Check for value of ZSSGLOCK.DLL
   begin
     MessageDlg('Invalid CRC for ZSSGLOCK.DLL', mtError, [mbOK], 0);
     Application.Terminate;
     Halt;
   end;

// Dynamic LOCK Check
LocksmithParameters := EditLocksmithParameters.Text;
DLLInstance := LoadLibrary('ZSSGLOCK.dll');
if DLLInstance = 0 then
   begin
     MessageDlg('Unable to load ZSSGLOCK.DLL', mtError, [mbOK], 0);
     Application.Terminate;
     Halt;
   end;
@ShareGuardLock := GetProcAddress(DLLInstance, 'ShareGuardLock');
if @ShareGuardLock <> nil then
   sReturnCode := ShareGuardLock(PChar(LocksmithParameters))
else
   begin
     MessageDlg('Unable to locate procedure
address for ZSSGLOCK.DLL', mtError, [mbOK], 0);
Application.Terminate;
Halt;
end;
FreeLibrary(DLLInstance);
EditDynamic.Text := sReturnCode; // This is to display on form
if sReturnCode <> '0' then
// The following condition test is for demo purposes just to show
reason codes.
// Normally, you will shut down the application for anything other
than ZERO
   if CheckBoxShutDown.Checked then // Remove this line of code
     begin
       MessageDlg('Shutting down the
demo.', mtError, [mbOK], 0);
       Application.Terminate;
       Halt;
     end;
end;

procedure TFormShareGuardLockDLLDemo.ButtonCloseClick
(Sender: TObject);
begin
FormShareGuardLockDLLDemo.Close;
end;

procedure TFormShareGuardLockDLLDemo.FormCreate(Sender: TObject);
begin
// Parameters taken from the Sample Application on the web site.
EditLocksmithParameters.Text := 'ZSSGL.EXE /D /A030 /R030 /$0.00
/KDC97C8877E90E509
/LDA768175D525C0F8 /Hwww.zappersoftware.com
/Msales@zappersoftware.com
/NWilliam_Bradshaw /OSample /PSAMPLE.EXE
/Uwww.zappersoftware.com/Sample/samplepurchase.php
/TSample_Demo';
end;

end.

NOTE: The previous code says to create a main routine and then call the subroutine. It should actually either be inline code (in your form create or startup code) or you can place "magic numbers" or something else to ensure that the subroutine has been executed. A hacker could, conceivably, bypass the subroutine call. Adding some additional tests makes it much more difficult. This code was setup this way to isolate what exact coding is required.

Simple Copy Protection Code Snippet
This code snippet is really easy as you just embed it within FormCreate of your module and then change the LocksmithParameters to the generated parameters from the ShareGuard Locksmith Lock Page.
Get The FREE Software:
Company Summary:

- Incorporated in 1995

- Consulting Services to Fortune 500 companies

- Developing software since 1980

- Developer Member of ASP

Products and Services for Windows and IBM

Software Distributor

Copyright © 1995-2004 Zapper Software 510862 B.C. Ltd. All rights reserved. Privacy Policy