Add Original SDK

This commit is contained in:
2026-05-06 07:47:36 +02:00
parent 2915e04380
commit 0ed627517a
674 changed files with 89334 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
program DllTest;
uses
System.StartUpCopy,
FMX.Forms,
apitest in 'apitest.pas' {Form1},
dris in 'dris.pas';
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

View File

@@ -0,0 +1,105 @@
Sample code to call Runtime modules in Delphi
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This project is written in Delphi 10.3 but should also work in other versions.
If you want to create traditional Delphi applications under Windows please
use the VCL projects instead.
The source files in the project are:
File name Description
apitest.pas main source code file
dris.pas contains DRIS structure definition and other definitions.
apitest.fmx form design
DllTest.dpr project file
DllTest.dproj project file
The idea is to include the dris.pas file in your project and use/modify which ever
functions from apitest.pas you feel are appropriate.
This sample has been tested under Win32, Win64, Mac32 and Mac64 environments. In order
to build and deploy under MacOS you need to setup a remote Mac machine using profile.
The sample code contains 11 functions. You will not need to use all these
functions in your code. Just use which ever functions are most appropriate
and customise in your own way. The sample code is just a guide. You should
implement the protection in a stronger way using the techniques described in
the "Increasing your Protection" chapter of the manual.
Code marked with !!!! are places where you should customise the sample code so
that it will work properly:
* Change the MY_SDSN value to the value of your SDSN
* Change the MY_PRODCODE value to the Product Code in the dongle
* Change the MyAlgorithm code (if you call a user algorithm)
* Change the CryptDRIS code (if you encrypt the DRIS)
* Change the CryptApiData (if you encrypt Data you send to our API)
* Change the MyRWAlgorithm code (if encrypt Data you send to our API using the R/W algorithm)
You will also probably want to replace our error messages with your own. However, you should
still display or log any error codes returned by the protection check otherwise you will not
be able to identify the cause of the error. (You can look up error codes in our knowledge
base: microcosm.com/kb).
This project calls the appropriate dynamic runtime module for the OS.
(Note, in Windows you could link with the static module instead (we do this for the ObjTest
project in the VCL samples). However, we do not supply the correct static libraries for MacOS.
This is because Delphi requires the object modules to be in its own custom format.)
Note - you should run DinkeyAdd and protect all the runtime modules that you require
(for each platform that you want to support. e.g. dpwin64.dll for Windows 64-bit).
Do not protect your program directly. Because your program is linked to this library it is
protected.
The protected library will need to be in the same folder as your compiled program
for it to run correctly (in the Mac of MacOS it needs to reside in the Contents/MacOS directory
of your application bundle). You can add the protected library to the list of deployment files
(Project | Deployment) so that it is copied to the correct location when you deploy it.
The Delphi compile has a few quirks under 64-bit MacOS build:
1) You need to have the runtime dynamic module dpmac64.dylib to be present in the project folder
for the project to build correctly (this is not necessary under the other build platforms).
2) There is a bug in the linker so that the dpmac64.dylib is not referenced correctly from the
deployed application (if you run otool -L on the application you will see that it only
references dpmac64.dylib. It should be @rpath/dpmac64.dylib.) The linker does this correctly for
the 32-bit build. After deploying you need to open a terminal, change directory to the application
/Contents/MacOS directory and then run the following command:
install_name_tool -change dpmac64.dylib @rpath/dpmac64.dylib <application name>
Ideally you would modify the deployment under MacOS64 so that a script executes this each time.
Unfortunately, there doesn't seem to be a way of doing this.
Debug Modules
~~~~~~~~~~~~~~
Note - once the runtime module is protected you will not be able to debug
your program - after our API has been called. Our strong anti-debug code will cause
the debugger to throw an exception. If you do want to debug your code
then you can use our debug modules: e.g. dpwin64debug.dll for 64-bit Windows, but these
should not be used for release.
You could setup your project so that your code links the debug module during your debug build
and the standard module when you produce your release code.
Note: the debug module has the following restrictions:
1) It will not correctly start a network user (network dongles only). However, other than that
the protection check will function correctly and return success.
2) You will not be able to encrypt the DRIS. (If you do encrypt the DRIS in your release build
then you should make sure that CryptDRIS does not get called in your debug build).
3) The protection check will take slightly longer than normal.
4) The DDGetNetUserList function will return error 428 (not implemented).
5) A temporary subprocess is created which may be (falsely) detected as malicious by anti-virus
programs.
Differences with the VCL code
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DRIS:
The longint type is changed to FixedInt because longint can be 8-bytes in some platforms
The longword type is change to FixedUInt because longword can be 8-bytes in some platforms
More conditional code to call native dynamic library on different platforms
Uses the dynamic modules and does not link with the static modules
APITEST:
Uses ShowMessage rather than MessageDlg (now deprecated)

View File

@@ -0,0 +1,3 @@
inherited Form1_Macintosh: TForm1_Macintosh
DesignerMasterStyle = 0
end

View File

@@ -0,0 +1,22 @@
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 197
ClientWidth = 306
FormFactor.Width = 320
FormFactor.Height = 480
FormFactor.Devices = [Desktop]
DesignerMasterStyle = 0
object Label1: TLabel
StyledSettings = [Family, Style, FontColor]
Position.X = 80.000000000000000000
Position.Y = 72.000000000000000000
Size.Width = 145.000000000000000000
Size.Height = 33.000000000000000000
Size.PlatformDefault = False
TextSettings.Font.Size = 30.000000000000000000
Text = 'It worked!'
TabOrder = 1
end
end

View File

@@ -0,0 +1,876 @@
unit apitest;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
FMX.Controls.Presentation, FMX.StdCtrls,
dris;
type
TForm1 = class(TForm)
Label1: TLabel;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
{$R *.Macintosh.fmx MACOS}
{ !! We strongly recommend that you read the "readme.txt" file in the sample code folder.
!! It contains important instructions on how to use the sample code }
{ The sample code contains 11 functions. You will not need to use all these
functions in your code. Just use which ever functions are most appropriate
and customise in your own way. The sample code is just a guide. You should
implement the protection in a stronger way using the techniques described in
the "Increasing your Protection" chapter of the manual. To choose which function
this code uses see the startup code at the bottom of this file.
this file contains 11 protection-check functions.
longint ProtCheck(); a standard protection check
longint ProtCheckWithAlg(); a protection check & executing an Algorithm
longint WriteBytes(); a protection check & write data to the dongle
longint ReadBytes(); a protection check & read data from the dongle
longint EncryptUserData(); a protection check & encrypting data and then decrypting the data
these functions are the same as the functions listed above but encrypting all parameters passed to our API
longint ProtCheckEnc(); a standard protection check
longint ProtCheckWithAlgEnc(); a protection check & executing an Algorithm
longint WriteBytesEnc(); a protection check & write data to the dongle
longint ReadBytesEnc(); a protection check & read data from the dongle
longint EncryptUserDataEnc(); a protection check & encrypting data and then decrypting the data
longint DisplayNetUsers(net_users, model); this function displays the current network users
If you are using Dinkey Lite then you can only use 4 functions:
ProtCheck, ProtCheckWithAlg, ProtCheckEnc, ProtCheckWithAlgEnc
}
const MY_SDSN = 10101; { !!!! change this value to be the value of your SDSN (demo = 10101) }
const MY_PRODCODE = 'DEMO';
{ this procedure initialises the DRIS with random bytes }
procedure random_set(data: PByte; length: integer);
var
i : integer;
begin
Randomize();
for i := 0 to length-1 do
begin
data^ := Random(256);
Inc(data); { increment the pointer so we can access the next byte }
end;
end;
{ displays messages for the most common errors. You will want to change this for your code }
procedure DisplayError(ret_code, extended_error:integer);
var
display : string;
begin
case ret_code of
401: display := 'Error! No dongles detected!';
403: display := 'Error! The dongle detected has a different type to the one specified in DinkeyAdd.';
404: display := 'Error! The dongle detected has a different model to those specified in DinkeyAdd.';
409: display := 'Error! The dongle detected has not been programmed by DinkeyAdd.';
410: display := 'Error! The dongle detected has a different Product Code to the one specified in DinkeyAdd.';
411: display := 'Error! The dongle detected does not contain the licence associated with this program.';
413: display := 'Error! This program has not been protected by DinkeyAdd. For guidance please read the DinkeyAdd chapter of the Dinkey manual.';
417: display := 'Error! One or more of the parameters set in the DRIS is incorrect. This could be caused if you are encrypting the DRIS in your code but did not specify DRIS encryption in DinkeyAdd - or vice versa.';
423: display := 'Error! The number of network users has been exceeded.';
435: display := 'Error! DinkeyServer has not been detected on the network.';
922: display := 'Error! The Software Key has expired.';
else
display := 'An error occurred checking the dongle. Error: ' + IntToStr(ret_code) + '. Extended Error code: ' + IntToStr(extended_error);
end;
ShowMessage(display);
end;
{ ************************* our 11 functions follow *************************** }
{ *********************** DisplayNetUsers ******************************* }
{ This function displays the current network users (for DinkeyNet only).
The DDProtCheck function must be called before this function is called.
(Normally you would use DinkeyServer to view the network users but this enables you to do it from the client if you want) }
Function DisplayNetUsers (net_users, model : LongInt) : LongInt;
var
display : string;
nu_info: packed array[0..99] of nu_infoType; { !!!! this assumes that you will display max. 100 net users }
i, max_net_users, num_net_users, extended_error : LongInt;
begin
if (net_users = -1) then
begin
max_net_users := 100; { if unlimited network users are allowed then display up to 100 users (for example) If you want more than 1000 net users you need to change the value above}
end
else
begin
max_net_users := net_users;
end;
if (net_users = 0) then { no network users are allowed, so nothing to do! }
begin
result := 0;
exit;
end;
if (model < 3) then
begin
ShowMessage('A network dongle has not been detected. Therefore you cannot display the network users.');
result := -1;
exit;
end;
{ now get net users }
result := DDGetNetUserList(NIL, @num_net_users, @nu_info, max_net_users, @extended_error);
if (result <> 0) then
begin
ShowMessage('Error ' + IntToStr(result) + '/' + IntToStr(extended_error) + ' finding network user information.');
end
else
begin
display:= 'number of net users: ' + IntToStr(num_net_users) + #13#10;
for i := 0 to num_net_users-1 do
begin
display := display + IntToStr(i+1) + '. licence: ' + String(nu_info[i].licenceName) + ', user: ' + String(nu_info[i].userName) +
', computer: ' + String(nu_info[i].computerName) + ', ipaddress: ' + String(nu_info[i].ipAddress) + #13#10;
end;
ShowMessage(display);
end;
end;
{ ************************** ProtCheck *************************************** }
Function ProtCheck : LongInt;
var
dris: drisType;
begin
{ set the DRIS to have random values }
random_set(@dris, SizeOf(dris));
{ then set the values we want to use }
Move(AnsiString('DRIS'), dris.header, 4);
dris.size:= SizeOf(dris);
dris.myfunction:= PROTECTION_CHECK; { standard protection check }
dris.flags:= 0; { no extra flags, but you may want to specify some if you want to start a network user or decrement execs,... }
{ call dongle-checking code }
result := DDProtCheck(@dris, NIL);
if (result <> 0) then
begin
DisplayError(result, dris.ext_err); { display messages for any errors that have occurred }
exit;
end;
{ later in your code you can check other values in the DRIS... }
if (dris.sdsn <> MY_SDSN) then
begin
ShowMessage('Incorrect SDSN! Please modify your source code so that MY_SDSN is set to be your SDSN.');
result := -1;
exit;
end;
if (dris.prodcode <> AnsiString(MY_PRODCODE)) then
begin
ShowMessage('Incorrect Product Code! Please modify your source code so that MY_PRODCODE is set to be the Product Code in the dongle.');
result := -1;
exit;
end;
{ later on in your program you can check the return code again }
if (dris.ret_code <> 0) then
begin
ShowMessage('Dinkey Dongle protection error.');
result := -1;
exit;
end;
{ if you are using a network dongle and you want to list the network users then use this function: }
{ DisplayNetUsers(dris.net_users, dris.model); }
end;
{ ************************** ProtCheckWithAlg ******************************** }
{ !!!! You should replace this function with the one generated by the
"generate source code" button in Algorithm tab for DinkeyAdd (if you have specified an algorithm).
If you are using Dinkey Lite the copy the source code from DinkeyLook }
Function MyAlgorithm(a,b,c,d,e,f,g,h:LongInt):LongInt;
begin
MyAlgorithm:= a + b + c + d + e + f + g + h;
end;
{ NB for this to work you must program at least "user algorithm" into the dongle
NB We have used a very simple algorithm here (in the MyAlgorithm function). You must patch this with the
sample code generated by DinkeyAdd for the algorithm that you are using. For Dinkey Lite copy source code from DinkeyLook}
Function ProtCheckWithAlg : LongInt;
var
dris: drisType;
begin
{ set the DRIS to have random values }
random_set(@dris, SizeOf(dris));
{ then set the values we want to use }
Move(AnsiString('DRIS'), dris.header, 4);
dris.size:= SizeOf(dris);
dris.myfunction:= EXECUTE_ALGORITHM; { standard protection check & execute algorithm }
dris.flags:= 0; { no extra flags, but you may want to specify some if you want to start a network user or decrement execs,... }
dris.alg_number := 1; { execute algorithm 1 (you do not need to specify this field if you are only using Lite models) }
{ you should remove these entries if you are using Dinkey Lite so that algorithm arguments are random }
dris.var_a := 1; { sample values }
dris.var_b := 2;
dris.var_c := 3;
dris.var_d := 4;
dris.var_e := 5;
dris.var_f := 6;
dris.var_g := 7;
dris.var_h := 8;
{ call dongle-checking code }
result := DDProtCheck(@dris, NIL);
if (result <> 0) then
begin
DisplayError(result, dris.ext_err); { display messages for any errors that have occurred }
exit;
end;
{ later in your code you can check other values in the DRIS... }
if (dris.sdsn <> MY_SDSN) then
begin
ShowMessage('Incorrect SDSN! Please modify your source code so that MY_SDSN is set to be your SDSN.');
result := -1;
exit;
end;
{ later on in your program you can check the return code again }
if (dris.ret_code <> 0) then
begin
ShowMessage('Dinkey Dongle protection error.');
result := -1;
exit;
end;
{ if you want you can check the algorithm answer - however if algorithm is from your code then best to just use the answer in your code
!!!! Make sure you have replaced the MyAlgorithm routine with the algorithm you have specified in DinkeyAdd }
if (MyAlgorithm(dris.var_a, dris.var_b, dris.var_c, dris.var_d, dris.var_e, dris.var_f, dris.var_g, dris.var_h) <> dris.alg_answer) then
begin
ShowMessage('Dinkey protection error! You have not patched your algorithm in the MyAlgorithm routine');
result := -1;
exit;
end;
end;
{ ************************** WriteBytes *************************************** }
{ This writes the Data "Hello, World" to the dongle data area at offset 7
In order for this function to work you will need to have a data area in your dongle that is at least 21 bytes long. }
Function WriteBytes : LongInt;
var
dris: drisType;
DataToWrite : array[0..13] of AnsiChar;
begin
{ set the DRIS to have random values }
random_set(@dris, SizeOf(dris));
{ then set the values we want to use }
Move(AnsiString('DRIS'), dris.header, 4);
dris.size:= SizeOf(dris);
dris.myfunction:= WRITE_DATA_AREA; { standard protection check & write data}
dris.flags:= 0; { no extra flags, but you may want to specify some if you want to start a network user or decrement execs,... }
dris.rw_offset := 7;
dris.rw_length := 13;
DataToWrite := 'Hello, World!'; { string to write }
dris.rw_data_ptr := Addr(DataToWrite);
{ call dongle-checking code }
result := DDProtCheck(@dris, NIL);
if (result <> 0) then
begin
DisplayError(result, dris.ext_err); { display messages for any errors that have occurred }
exit;
end;
{ later in your code you can check other values in the DRIS... }
if (dris.sdsn <> MY_SDSN) then
begin
ShowMessage('Incorrect SDSN! Please modify your source code so that MY_SDSN is set to be your SDSN.');
result := -1;
exit;
end;
{ later on in your program you can check the return code again }
if (dris.ret_code <> 0) then
begin
ShowMessage('Dinkey Dongle protection error.');
result := -1;
exit;
end;
end;
{ ************************** ReadBytes *************************************** }
{ This reads 14 bytes of data from offset 7 in the dongle data area
In order for this function to work you will need to have a data area in your dongle that is at least 21 bytes long.
In order for the data to be displayed properly by this routine it will need to be text data }
Function ReadBytes : LongInt;
var
dris: drisType;
DataToRead : array[0..13] of AnsiChar;
display : string;
begin
{ set the DRIS to have random values }
random_set(@dris, SizeOf(dris));
{ then set the values we want to use }
Move(AnsiString('DRIS'), dris.header, 4);
dris.size:= SizeOf(dris);
dris.myfunction:= READ_DATA_AREA; { standard protection check & write data}
dris.flags:= 0; { no extra flags, but you may want to specify some if you want to start a network user or decrement execs,... }
dris.rw_offset := 7;
dris.rw_length := 13; { we will add null termination after reading }
dris.rw_data_ptr := Addr(DataToRead);
{ call dongle-checking code }
result := DDProtCheck(@dris, NIL);
if (result <> 0) then
begin
DisplayError(result, dris.ext_err); { display messages for any errors that have occurred }
exit;
end;
{ later in your code you can check other values in the DRIS... }
if (dris.sdsn <> MY_SDSN) then
begin
ShowMessage('Incorrect SDSN! Please modify your source code so that MY_SDSN is set to be your SDSN.');
result := -1;
exit;
end;
{ later on in your program you can check the return code again }
if (dris.ret_code <> 0) then
begin
ShowMessage('Dinkey Dongle protection error.');
result := -1;
exit;
end;
DataToRead[13] := Chr(0); { null end of string }
display := 'Dinkey Dongle data area contains: ' + DataToRead;
ShowMessage(display);
end;
{ ************************** EncryptUserData ********************************** }
{ This function will do a protection check and ask the dongle to encrypt some data using encryption key 1
It will then do another protection check & decrypt the data }
Function EncryptUserData : LongInt;
var
dris: drisType;
display : string;
DataString : array[0..13] of AnsiChar;
begin
{ set the DRIS to have random values }
random_set(@dris, SizeOf(dris));
{ then set the values we want to use }
Move(AnsiString('DRIS'), dris.header, 4);
dris.size:= SizeOf(dris);
dris.myfunction:= ENCRYPT_USER_DATA; { standard protection check & encrypt data }
dris.flags:= 0; { no extra flags, but you may want to specify some if you want to start a network user or decrement execs,... }
dris.data_crypt_key_num := 1;
dris.rw_length := 13;
DataString := 'Hello, World!'; { string to encrypt }
dris.rw_data_ptr := Addr(DataString);
{ call dongle-checking code }
result := DDProtCheck(@dris, NIL);
if (result <> 0) then
begin
DisplayError(result, dris.ext_err); { display messages for any errors that have occurred }
exit;
end;
{ ... could add code to check other elements of the DRIS, e.g. ret_code, sdsn, ... }
{ Now decrypt the same data to get the original values }
random_set(@dris, SizeOf(dris));
{ then set the values we want to use }
Move(AnsiString('DRIS'), dris.header, 4);
dris.size:= SizeOf(dris);
dris.myfunction:= DECRYPT_USER_DATA; { standard protection check & decrypt data }
dris.flags:= 0; { no extra flags, but you may want to specify some if you want to start a network user or decrement execs,... }
dris.data_crypt_key_num := 1;
dris.rw_length := 13;
dris.rw_data_ptr := Addr(DataString);
{ call dongle-checking code }
result := DDProtCheck(@dris, NIL);
{ later in your code you can check other values in the DRIS... }
if (dris.sdsn <> MY_SDSN) then
begin
ShowMessage('Incorrect SDSN! Please modify your source code so that MY_SDSN is set to be your SDSN.');
result := -1;
exit;
end;
{ later on in your program you can check the return code again }
if (dris.ret_code <> 0) then
begin
ShowMessage('Dinkey Dongle protection error.');
result := -1;
exit;
end;
DataString[13] := Chr(0); { null end of string }
display := 'Decrypted data is: ' + DataString;
ShowMessage(display);
end;
{!!!! all the functions listed below encrypt all parameters to our API !!!!!!!!!!!!!!!!!!!!!
In order for them to work properly you need to choose "Encrypt DRIS" and "Encrypt Data passed to API"
in the Extra Security tab of DinkeyAdd. In this example, for Data Encryption I use the r/w algorithm
but the code can be modified easily to use the 3 encryption parameters. }
{ !!!! please overwrite this function with the one generated by DinkeyAdd for R/W Algorithm }
Function MyRWAlgorithm(a,b,c,d,e,f,g,h:LongInt):LongInt;
begin
MyRWAlgorithm:= a xor b xor c xor d xor e xor f;
end;
{ !!!! please overwrite this function with the one generated by DinkeyAdd }
procedure CryptDRIS(dris : PByte; seed1,seed2 : Longword);
var
i,j,k : Integer;
bigseed,S : packed array[0..255] of byte;
temp,t : byte;
begin
i := 0;
while (i < 255) do
begin
Move(seed1, bigseed[i], 4); {NB move actually copies data}
Move(seed2, bigseed[i+4], 4);
i := i + 8;
end;
for i := 0 to 255 do S[i]:= i;
j := 0;
for i := 0 to 255 do
begin
j := (j + S[i] + bigseed[i] + 123) Mod 256;
temp := S[i];
S[i] := S[j];
S[j] := temp;
end;
i := 0;
j := 0;
Inc(dris, 16); {the first part of the DRIS is not encrypted}
for k := 16 to SizeOf(drisType)-1 do
begin
i := (i + 1) Mod 256;
j := (j + S[i] + 212) Mod 256;
temp := S[i];
S[i] := S[j];
S[j] := temp;
t := (S[i] + S[j] + 97) Mod 256;
dris^ := dris^ xor S[t];
Inc(dris);
end;
end;
{ !!!! please overwrite this function with the one generated by DinkeyAdd }
procedure CryptApiData(data : pbyte; length : integer; seed1,seed2 : Longword; alg_answer: LongInt);
var
i,j,k : Integer;
bigseed,S : packed array[0..255] of byte;
temp,t : byte;
begin
i := 0;
while (i < 255) do
begin
Move(seed1, bigseed[i], 4); {NB move actually copies data}
Move(seed2, bigseed[i+4], 4);
i := i + 8;
end;
for i := 0 to 255 do S[i]:= i;
j := 0;
for i := 0 to 255 do
begin
j := (j + S[i] + bigseed[i] + (alg_answer And $FF)) Mod 256;
temp := S[i];
S[i] := S[j];
S[j] := temp;
end;
i := 0;
j := 0;
for k := 0 to length-1 do
begin
i := (i + 1) Mod 256;
j := (j + S[i] + ((alg_answer shr 8) And $FF)) Mod 256;
temp := S[i];
S[i] := S[j];
S[j] := temp;
t := (S[i] + S[j] + ((alg_answer shr 16) And $FF)) Mod 256;
data^ := data^ xor S[t];
Inc(data);
end;
end;
{ ************************** ProtCheckEnc ************************************ }
{ We encrypt the DRIS passed to the API.
Patch the CryptDRIS function in this file from source code generated by DinkeyAdd. }
Function ProtCheckEnc : LongInt;
var
dris: drisType;
begin
{ set the DRIS to have random values }
random_set(@dris, SizeOf(dris)); { NB this also fills seed1, seed2 with random values }
{ then set the values we want to use }
Move(AnsiString('DRIS'), dris.header, 4);
dris.size:= SizeOf(dris);
dris.myfunction:= PROTECTION_CHECK; { standard protection check }
dris.flags:= 0; { no extra flags, but you may want to specify some if you want to start a network user or decrement execs,... }
CryptDRIS(@dris, dris.seed1, dris.seed2); { encrypt DRIS - !!!! you should separate from DDProtCheck for greater security }
result := DDProtCheck(@dris, NIL);
CryptDRIS(@dris, dris.seed1, dris.seed2); { decrypt DRIS - !!!! you should separate from DDProtCheck for greater security }
if (result <> 0) then
begin
DisplayError(result, dris.ext_err); { display messages for any errors that have occurred }
exit;
end;
{ later in your code you can check other values in the DRIS... }
if (dris.sdsn <> MY_SDSN) then
begin
ShowMessage('Incorrect SDSN! Please modify your source code so that MY_SDSN is set to be your SDSN.');
result := -1;
exit;
end;
if (dris.prodcode <> AnsiString(MY_PRODCODE)) then
begin
ShowMessage('Incorrect Product Code! Please modify your source code so that MY_PRODCODE is set to be the Product Code in the dongle.');
result := -1;
exit;
end;
{ later on in your program you can check the return code again }
if (dris.ret_code <> 0) then
begin
ShowMessage('Dinkey Dongle protection error.');
result := -1;
exit;
end;
end;
{ ************************** ProtCheckWithAlgEnc ******************************** }
{ NB for this to work you must program at least "user algorithm" into the dongle
NB We have used a very simple algorithm here (in the MyAlgorithm function). You must patch this with the
sample code generated by DinkeyAdd for the algorithm that you are using. For Dinkey Lite copy source code from DinkeyLook.
We encrypt the DRIS passed to the API. Patch the CryptDRIS function in this file from source code generated by DinkeyAdd.}
Function ProtCheckWithAlgEnc : LongInt;
var
dris: drisType;
begin
{ set the DRIS to have random values }
random_set(@dris, SizeOf(dris)); { NB this also fills seed1, seed2, var_a...var_h with random values }
{ then set the values we want to use }
Move(AnsiString('DRIS'), dris.header, 4);
dris.size:= SizeOf(dris);
dris.myfunction:= EXECUTE_ALGORITHM; { standard protection check & execute algorithm }
dris.flags:= 0; { no extra flags, but you may want to specify some if you want to start a network user or decrement execs,... }
dris.alg_number := 1; { execute algorithm 1 - you do not need to specify this field if you are only using Lite models}
{ you should remove these entries if you are using Dinkey Lite so that algorithm arguments are random }
dris.var_a := 1; { sample values }
dris.var_b := 2;
dris.var_c := 3;
dris.var_d := 4;
dris.var_e := 5;
dris.var_f := 6;
dris.var_g := 7;
dris.var_h := 8;
CryptDRIS(@dris, dris.seed1, dris.seed2); { encrypt DRIS - !!!!you should separate from DDProtCheck for greater security }
result := DDProtCheck(@dris, NIL);
CryptDRIS(@dris, dris.seed1, dris.seed2); { decrypt DRIS - !!!!you should separate from DDProtCheck for greater security }
if (result <> 0) then
begin
DisplayError(result, dris.ext_err); { display messages for any errors that have occurred }
exit;
end;
{ later in your code you can check other values in the DRIS... }
if (dris.sdsn <> MY_SDSN) then
begin
ShowMessage('Incorrect SDSN! Please modify your source code so that MY_SDSN is set to be your SDSN.');
result := -1;
exit;
end;
{ later on in your program you can check the return code again }
if (dris.ret_code <> 0) then
begin
ShowMessage('Dinkey Dongle protection error.');
result := -1;
exit;
end;
{ if you want you can check the algorithm answer - however if algorithm is from your code then best to just use the answer in your code
!!!! Make sure you have replaced the MyAlgorithm routine with the algorithm you have specified in DinkeyAdd }
if (MyAlgorithm(dris.var_a, dris.var_b, dris.var_c, dris.var_d, dris.var_e, dris.var_f, dris.var_g, dris.var_h) <> dris.alg_answer) then
begin
ShowMessage('Dinkey protection error! You have not patched your algorithm in the MyAlgorithm routine');
result := -1;
exit;
end;
end;
{ ************************** WriteBytesEnc************************************** }
{ This writes the Data 012...9 to the dongle data area at offset 7
In order for this function to work you will need to have a data area in your dongle that is at least 18 bytes long.
We encrypt the DRIS and Data passed to the API. Patch the CryptDRIS and CryptApiData functions in this file from source code generated by DinkeyAdd.}
Function WriteBytesEnc : LongInt;
var
dris: drisType;
DataToWrite : packed array[0..9] of byte;
alg_ans, i: longint;
begin
for i := 0 to 9 do
DataToWrite[i] := i;
{ set the DRIS to have random values }
random_set(@dris, SizeOf(dris)); { NB this also fills seed1, seed2, var_a...var_h with random values }
{ then set the values we want to use }
Move(AnsiString('DRIS'), dris.header, 4);
dris.size:= SizeOf(dris);
dris.myfunction:= WRITE_DATA_AREA; { standard protection check & write data}
dris.flags:= 0; { no extra flags, but you may want to specify some if you want to start a network user or decrement execs,... }
dris.rw_offset := 7;
dris.rw_length := SizeOf(DataToWrite);
dris.rw_data_ptr := Addr(DataToWrite);
{ calculate r/w algorithm answer - NB need to replace MyRWAlgorithm code with code for r/w algorithm }
alg_ans := MyRWAlgorithm(dris.var_a, dris.var_b, dris.var_c, dris.var_d, dris.var_e, dris.var_f, dris.var_g, dris.var_h);
{ encrypt data we want to write }
CryptApiData(@DataToWrite, SizeOf(DataToWrite), dris.seed1, dris.seed2, alg_ans);
CryptDRIS(@dris, dris.seed1, dris.seed2); { encrypt DRIS - !!!!you should separate from DDProtCheck for greater security }
{ call dongle-checking code }
result := DDProtCheck(@dris, NIL);
CryptDRIS(@dris, dris.seed1, dris.seed2); { decrypt DRIS - !!!!you should separate from DDProtCheck for greater security }
if (result <> 0) then
begin
DisplayError(result, dris.ext_err); { display messages for any errors that have occurred }
exit;
end;
{ later in your code you can check other values in the DRIS... }
if (dris.sdsn <> MY_SDSN) then
begin
ShowMessage('Incorrect SDSN! Please modify your source code so that MY_SDSN is set to be your SDSN.');
result := -1;
exit;
end;
{ later on in your program you can check the return code again }
if (dris.ret_code <> 0) then
begin
ShowMessage('Dinkey Dongle protection error.');
result := -1;
exit;
end;
end;
{ ************************** ReadBytesEnc *************************************** }
{ This reads 10 bytes of data from offset 7 in the dongle data area
In order for this function to work you will need to have a data area in your dongle that is at least 18 bytes long.
We encrypt the DRIS and Data passed from the API. Patch the CryptDRIS and CryptApiData functions in this file from source code generated by DinkeyAdd.}
Function ReadBytesEnc : LongInt;
var
dris: drisType;
DataToRead : packed array[0..9] of byte;
display : string;
alg_ans, i: longint;
begin
{ set the DRIS to have random values }
random_set(@dris, SizeOf(dris)); { NB this also fills seed1, seed2, var_a...var_h with random values }
{ then set the values we want to use }
Move(AnsiString('DRIS'), dris.header, 4);
dris.size:= SizeOf(dris);
dris.myfunction:= READ_DATA_AREA; { standard protection check & write data}
dris.flags:= 0; { no extra flags, but you may want to specify some if you want to start a network user or decrement execs,... }
dris.rw_offset := 7;
dris.rw_length := SizeOf(DataToRead);
dris.rw_data_ptr := Addr(DataToRead);
{ calculate r/w algorithm answer - NB need to replace MyRWAlgorithm code with code for r/w algorithm }
alg_ans := MyRWAlgorithm(dris.var_a, dris.var_b, dris.var_c, dris.var_d, dris.var_e, dris.var_f, dris.var_g, dris.var_h);
CryptDRIS(@dris, dris.seed1, dris.seed2); { encrypt DRIS - !!!!you should separate from DDProtCheck for greater security }
{ call dongle-checking code }
result := DDProtCheck(@dris, NIL);
CryptDRIS(@dris, dris.seed1, dris.seed2); { decrypt DRIS - !!!!you should separate from DDProtCheck for greater security }
if (result <> 0) then
begin
DisplayError(result, dris.ext_err); { display messages for any errors that have occurred }
exit;
end;
{ later in your code you can check other values in the DRIS... }
if (dris.sdsn <> MY_SDSN) then
begin
ShowMessage('Incorrect SDSN! Please modify your source code so that MY_SDSN is set to be your SDSN.');
result := -1;
exit;
end;
{ later on in your program you can check the return code again }
if (dris.ret_code <> 0) then
begin
ShowMessage('Dinkey Dongle protection error.');
result := -1;
exit;
end;
{ decrypt data that was read }
CryptApiData(@DataToRead, SizeOf(DataToRead), dris.seed1, dris.seed2, alg_ans);
display := 'Dinkey Dongle data area contains: ';
for i:=0 to 9 do
display := display + IntToStr(DataToRead[i]) + ' ';
ShowMessage(display);
end;
{ ************************** EncryptUserDataEnc ******************************* }
{ This function will do a protection check and ask the dongle to encrypt some data using encryption key 1
It will then do another protection & decrypt the data.
We encrypt the DRIS and Data passed to/from the API. Patch the CryptDRIS and CryptApiData functions in this file from source code generated by DinkeyAdd.}
Function EncryptUserDataEnc : LongInt;
var
dris: drisType;
display : string;
DataBytes : packed array[0..9] of byte;
alg_ans,i : LongInt;
begin
for i := 0 to 9 do
DataBytes[i] := i; { initialise data to 0,1,2,3,4,5,6,7,8,9}
{ set the DRIS to have random values }
random_set(@dris, SizeOf(dris)); { NB this also fills seed1, seed2, var_a...var_h with random values }
{ then set the values we want to use }
Move(AnsiString('DRIS'), dris.header, 4);
dris.size:= SizeOf(dris);
dris.myfunction:= ENCRYPT_USER_DATA; { standard protection check & encrypt data }
dris.flags:= 0; { no extra flags, but you may want to specify some if you want to start a network user or decrement execs,... }
dris.data_crypt_key_num := 1;
dris.rw_length := SizeOf(DataBytes);
dris.rw_data_ptr := Addr(DataBytes);
{ calculate r/w algorithm answer - NB need to replace MyRWAlgorithm code with code for r/w algorithm }
alg_ans := MyRWAlgorithm(dris.var_a, dris.var_b, dris.var_c, dris.var_d, dris.var_e, dris.var_f, dris.var_g, dris.var_h);
{ encrypt data we want to write }
CryptApiData(@DataBytes, Sizeof(DataBytes), dris.seed1, dris.seed2, alg_ans);
CryptDRIS(@dris, dris.seed1, dris.seed2); { encrypt DRIS - !!!!you should separate from DDProtCheck for greater security }
{ call dongle-checking code }
result := DDProtCheck(@dris, NIL);
CryptDRIS(@dris, dris.seed1, dris.seed2); { decrypt DRIS - !!!!you should separate from DDProtCheck for greater security }
if (result <> 0) then
begin
DisplayError(result, dris.ext_err); { display messages for any errors that have occurred }
exit;
end;
{ ... could add code to check other elements of the DRIS, e.g. ret_code, sdsn, ... }
{ Now decrypt the same data to get the original values }
random_set(@dris, SizeOf(dris));
{ then set the values we want to use }
Move(AnsiString('DRIS'), dris.header, 4);
dris.size:= SizeOf(dris);
dris.myfunction:= DECRYPT_USER_DATA; { standard protection check & decrypt data }
dris.flags:= 0; { no extra flags, but you may want to specify some if you want to start a network user or decrement execs,... }
dris.data_crypt_key_num := 1;
dris.rw_length := SizeOf(DataBytes);
dris.rw_data_ptr := Addr(DataBytes);
CryptDRIS(@dris, dris.seed1, dris.seed2); { encrypt DRIS - !!!!you should separate from DDProtCheck for greater security }
{ call dongle-checking code }
result := DDProtCheck(@dris, NIL);
CryptDRIS(@dris, dris.seed1, dris.seed2); { decrypt DRIS - !!!!you should separate from DDProtCheck for greater security }
{ later in your code you can check other values in the DRIS... }
if (dris.sdsn <> MY_SDSN) then
begin
ShowMessage('Incorrect SDSN! Please modify your source code so that MY_SDSN is set to be your SDSN.');
result := -1;
exit;
end;
{ later on in your program you can check the return code again }
if (dris.ret_code <> 0) then
begin
ShowMessage('Dinkey Dongle protection error.');
result := -1;
exit;
end;
alg_ans := MyRWAlgorithm(dris.var_a, dris.var_b, dris.var_c, dris.var_d, dris.var_e, dris.var_f, dris.var_g, dris.var_h);
{ decrypt data that was read }
CryptApiData(@DataBytes, SizeOf(DataBytes), dris.seed1, dris.seed2, alg_ans);
display := 'Data decrypted by dongle is: ';
for i:=0 to 9 do
display := display + IntToStr(DataBytes[i]) + ' ';
ShowMessage(display);
end;
{ *************** code that gets executed on startup *********************** }
begin
{call the function(s) of your choice here - in this example I have chosen a standard protection check}
if (ProtCheck() <> 0) then
halt;
end.

View File

@@ -0,0 +1,108 @@
{ !! this file should not be modified }
unit dris;
interface
TYPE
drisType = packed record
{ the first 4 fields are never encrypted }
header : array[0..3] of AnsiChar; { should be set to DRIS }
{ inputs }
size : FixedInt; { size of this structure }
seed1 : FixedInt; { seed for data/dris encryption }
seed2 : FixedInt; { as above }
{ maybe encrypted from now on }
myfunction : FixedInt; { specify only one function. NB can't name it "function" as it is a reserved keyword }
flags : FixedInt; { options for the function selected. To use more than one OR them together: OPTION1 or OPTION2... }
execs_decrement : FixedUint; { amount by which to dec execs if we use flag: DEC_MANY_EXECS }
data_crypt_key_num : FixedInt; { number of the key (1-3) that the dongle uses to encrypt or decrypt user data }
rw_offset : FixedInt; { offset in the dongle data area to read or write data }
rw_length : FixedInt; { length of data are to read/write/encrypt/decrypt }
rw_data_ptr : Pbyte; { pointer to data to write / be read }
alt_licence_name : array[0..255] of AnsiChar; { protection check for different licence instead of the default one, must be null-terminated }
var_a : FixedInt; { variable values for user algorithm }
var_b : FixedInt;
var_c : FixedInt;
var_d : FixedInt;
var_e : FixedInt;
var_f : FixedInt;
var_g : FixedInt;
var_h : FixedInt;
alg_number : FixedInt; { the number of the user algorithm that you want to execute }
{ outputs }
ret_code : FixedInt; { return code from the protection check }
ext_err : FixedInt; { extended error }
dongle_type : FixedInt; { type of dongle detected. 1 = Pro, 2 = FD. NB "type" is a reserved word so I use dongle_type }
model : FixedInt; { model of dongle detected. 1 = Lite, 2 = Plus, 4 = Net 5, 7 = Net Unlimited }
sdsn : FixedInt; { Software Developer's Serial Number }
prodcode : array[0..11] of AnsiChar; { Product Code (null-terminated) }
dongle_number : FixedUInt;
update_number : FixedInt;
data_area_size : FixedUint; { size of the data area in the dongle detected }
max_alg_num : FixedInt; { the maximum algorithm number in the dongle detected }
execs : FixedInt; { executions left: -1 indicates 'no limit' }
exp_day : FixedInt; { expiry day: -1 indicates 'no limit' }
exp_month : FixedInt; { expiry month: -1 indicates 'no limit' }
exp_year : FixedInt; { expiry year: -1 indicates 'no limit' }
features : FixedUint; { features value }
net_users : FixedInt; { maximum number of network users for the dongle detected: -1 indicates 'no limit' }
alg_answer : FixedInt; { answer to the user algorithm executed with the given variable values }
fd_capacity : FixedUint; { capacity of the data area in FD dongle. Currently fixed at ~10MB but may change in the future. }
fd_drive : array[0..127] of AnsiChar; { drive letter of FD dongle detected (if any) 'f:\' }
swkey_type : FixedInt; { 0 = no swkey detected, 1 = temporary software key, 2 = demo software key }
swkey_exp_day : FixedInt; { software key expiry date (if software key detected) }
swkey_exp_month : FixedInt;
swkey_exp_year : FixedInt;
end;
TYPE
nu_infoType = packed record
licenceName : array[0..255] of AnsiChar;
userName : array[0..49] of AnsiChar;
computerName : array[0..255] of AnsiChar;
ipAddress : array[0..15] of AnsiChar;
end;
{ function constants - specify one only }
const PROTECTION_CHECK = 1; { checks for dongle, check program params... }
const EXECUTE_ALGORITHM = 2; { protection check + calculate answer for specified algorithm with specified inputs }
const WRITE_DATA_AREA = 3; { protection check + writes dongle data area }
const READ_DATA_AREA = 4; { protection check + reads dongle data area }
const ENCRYPT_USER_DATA = 5; { protection check + the dongle will encrypt user data }
const DECRYPT_USER_DATA = 6; { protection check + the dongle will decrypt user data }
const FAST_PRESENCE_CHECK = 7; { checks for the presence of the correct dongle only with minimal security, no flags allowed. }
const STOP_NET_USER = 8; { stops a network user (a protection check is NOT performed) }
{ flag constants - can specify more than one }
const DEC_ONE_EXEC = 1; { decrement execs by 1 }
const DEC_MANY_EXECS = 2; { decrement execs by number specified in execs_decrement }
const START_NET_USER = 4; { starts a network user }
const USE_FUNCTION_ARGUMENT = 16; { use the extra argument in the function for pointers }
const CHECK_LOCAL_FIRST = 32; { always look in local ports before looking in network ports }
const CHECK_NETWORK_FIRST = 64; { always look on the network before looking in local ports }
const USE_ALT_LICENCE_NAME = 128; { use name specified in alt_licence_name instead of the default one }
const DONT_SET_MAXDAYS_EXPIRY = 256; { if the max days expiry date has not been calculated then do not do it this time }
const MATCH_DONGLE_NUMBER = 512; { restrict the search to match the dongle number specified in the DRIS }
const DONT_RETURN_FD_DRIVE = 1024; { if an FD dongle has been detected then don't return the flash drive/mount name in the DRIS }
{$IFDEF WIN32}
function DDProtCheck( dris, data:pointer ):FixedInt; stdcall; external 'dpwin32.dll';
function DDGetNetUserList(licence_name:PAnsiChar; num_net_users:PFixedInt; nu_info:pointer; num_info_structs:FixedInt; extended_error:PFixedInt):FixedInt; stdcall; external 'dpwin32.dll';
{$ENDIF}
{$IFDEF WIN64}
function DDProtCheck( dris, data:pointer ):FixedInt; stdcall; external 'dpwin64.dll';
function DDGetNetUserList(licence_name:PAnsiChar; num_net_users:PFixedInt; nu_info:pointer; num_info_structs:FixedInt; extended_error:PFixedInt):FixedInt; stdcall; external 'dpwin64.dll';
{$ENDIF}
{$IFDEF MACOS32}
function DDProtCheck( dris, data:pointer ):FixedInt; cdecl; external 'dpmac32.dylib' name '_DDProtCheck';
function DDGetNetUserList(licence_name:PAnsiChar; num_net_users:PFixedInt; nu_info:pointer; num_info_structs:FixedInt; extended_error:PFixedInt):FixedInt; cdecl; external 'dpmac32.dylib' name '_DDGetNetUserList';
{$ENDIF}
{$IFDEF MACOS64}
function DDProtCheck( dris, data:pointer ):FixedInt; cdecl; external 'dpmac64.dylib';
function DDGetNetUserList(licence_name:PAnsiChar; num_net_users:PFixedInt; nu_info:pointer; num_info_structs:FixedInt; extended_error:PFixedInt):FixedInt; cdecl; external 'dpmac64.dylib';
{$ENDIF}
implementation
end.