Add Original SDK
This commit is contained in:
14
Dinkey Pro 7.6.1/Samples/Delphi/VCL/Runtime/ObjTest.dpr
Normal file
14
Dinkey Pro 7.6.1/Samples/Delphi/VCL/Runtime/ObjTest.dpr
Normal file
@@ -0,0 +1,14 @@
|
||||
program ObjTest;
|
||||
|
||||
uses
|
||||
Forms,
|
||||
apitest in 'apitest.pas' {Form1},
|
||||
dris in 'dris.pas';
|
||||
|
||||
{$R *.res}
|
||||
|
||||
begin
|
||||
Application.Initialize;
|
||||
Application.CreateForm(TForm1, Form1);
|
||||
Application.Run;
|
||||
end.
|
||||
97
Dinkey Pro 7.6.1/Samples/Delphi/VCL/Runtime/README.txt
Normal file
97
Dinkey Pro 7.6.1/Samples/Delphi/VCL/Runtime/README.txt
Normal file
@@ -0,0 +1,97 @@
|
||||
Sample code to call Runtime modules in Delphi
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
This project is written in Delphi 6 but will work in more recent versions
|
||||
(they will upgrade the Project to the latest version. For Delphi XE or earlier
|
||||
you will need to delete the reference to System.UITypes).
|
||||
|
||||
If you want to create multi-platform or multi-device applications please use
|
||||
the FireMonkey projects instead.
|
||||
|
||||
The source files in the project are:
|
||||
|
||||
File name Description
|
||||
apitest.pas main source code file for Delphi
|
||||
dris.pas contains DRIS structure definition and other definitions.
|
||||
apitest.dfm
|
||||
ObjTest.dpr 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 can also compile to 64-bit code (if your version of Delphi supports 64-bit
|
||||
code i.e. Delphi XE2 and higher). Just Add the 64-bit Platform to the project.
|
||||
|
||||
In order for the projects to compile without modification we have also installed in
|
||||
this folder the relevant object modules for Delphi:
|
||||
|
||||
dpwin32_omf.obj for 32-bit builds
|
||||
dpwin64_delphi.obj for 64-bit builds
|
||||
|
||||
The sample code will detect whether you are building in 32-bit or 64-bit and compile
|
||||
the appropriate Windows module.
|
||||
|
||||
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).
|
||||
|
||||
The project currently links with our static protection modules. If you want to link to
|
||||
our dynamic protection modules instead (dpwin32.dll or dpwin64.dll) then you need
|
||||
to modify dris.pas as follows:
|
||||
|
||||
1) Modify the declarations of DDProtCheck and DDGetNetUserList so that they refer
|
||||
to the appropriate runtime DLL.
|
||||
|
||||
2) Delete the code that links the object module.
|
||||
|
||||
We have made these changes and put them in a file called dris_for_dll.pas.
|
||||
Use this in your project instead of dris.pas.
|
||||
|
||||
It is also recommended that you rename dpwin32.dll to a name of your choice. In
|
||||
this case you will need to modify the dll name in the dris.pas file.
|
||||
|
||||
Note - if you link the static module dpwin32_omf.obj then you should protect your program.
|
||||
If you are linking to dpwin32.dll then you need to protect dpwin32.dll and *not* your program.
|
||||
Because your program is linked to the DLL it is protected. The protected DLL will need to be
|
||||
in the same folder as your compiled program for it to run correctly.
|
||||
|
||||
Debug Modules
|
||||
~~~~~~~~~~~~~~
|
||||
Note - once your program (or dpwin32.dll) 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. You will also not be able to run your program from
|
||||
the development platform either as Delphi still has the Debugger running. You should run
|
||||
it instead from My Computer or from the command line. If you do want to debug your code
|
||||
then you can use our debug module: dpwin32_omf_debug.obj (or dpwin32debug.dll), 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.
|
||||
29
Dinkey Pro 7.6.1/Samples/Delphi/VCL/Runtime/apitest.dfm
Normal file
29
Dinkey Pro 7.6.1/Samples/Delphi/VCL/Runtime/apitest.dfm
Normal file
@@ -0,0 +1,29 @@
|
||||
object Form1: TForm1
|
||||
Left = 386
|
||||
Top = 317
|
||||
Width = 372
|
||||
Height = 265
|
||||
Caption = 'Form1'
|
||||
Color = clBtnFace
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -11
|
||||
Font.Name = 'MS Sans Serif'
|
||||
Font.Style = []
|
||||
OldCreateOrder = False
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 13
|
||||
object Label1: TLabel
|
||||
Left = 104
|
||||
Top = 88
|
||||
Width = 146
|
||||
Height = 37
|
||||
Caption = 'It Worked!'
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -32
|
||||
Font.Name = 'MS Sans Serif'
|
||||
Font.Style = []
|
||||
ParentFont = False
|
||||
end
|
||||
end
|
||||
874
Dinkey Pro 7.6.1/Samples/Delphi/VCL/Runtime/apitest.pas
Normal file
874
Dinkey Pro 7.6.1/Samples/Delphi/VCL/Runtime/apitest.pas
Normal file
@@ -0,0 +1,874 @@
|
||||
unit apitest;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
||||
Dialogs, StdCtrls, System.UITypes, { !!!! for Delphi XE and earlier remove System.UITypes }
|
||||
dris; { contains the DRIS structure declaration }
|
||||
|
||||
type
|
||||
TForm1 = class(TForm)
|
||||
Label1: TLabel;
|
||||
private
|
||||
{ Private declarations }
|
||||
public
|
||||
{ Public declarations }
|
||||
end;
|
||||
|
||||
var
|
||||
Form1: TForm1;
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.dfm}
|
||||
|
||||
{ !! 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;
|
||||
messagedlg(display, mtError, [mbok], 0);
|
||||
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
|
||||
messagedlg('A network dongle has not been detected. Therefore you cannot display the network users.', mtError, [mbok], 0);
|
||||
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
|
||||
messagedlg('Error ' + IntToStr(result) + '/' + IntToStr(extended_error) + ' finding network user information.', mtError, [mbok], 0);
|
||||
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;
|
||||
messagedlg(display, mtInformation, [mbok], 0);
|
||||
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
|
||||
messagedlg('Incorrect SDSN! Please modify your source code so that MY_SDSN is set to be your SDSN.', mtError, [mbok], 0);
|
||||
result := -1;
|
||||
exit;
|
||||
end;
|
||||
|
||||
if (dris.prodcode <> AnsiString(MY_PRODCODE)) then
|
||||
begin
|
||||
messagedlg('Incorrect Product Code! Please modify your source code so that MY_PRODCODE is set to be the Product Code in the dongle.', mtError, [mbok], 0);
|
||||
result := -1;
|
||||
exit;
|
||||
end;
|
||||
|
||||
{ later on in your program you can check the return code again }
|
||||
if (dris.ret_code <> 0) then
|
||||
begin
|
||||
messagedlg('Dinkey Dongle protection error.', mtError, [mbok], 0);
|
||||
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
|
||||
messagedlg('Incorrect SDSN! Please modify your source code so that MY_SDSN is set to be your SDSN.', mtError, [mbok], 0);
|
||||
result := -1;
|
||||
exit;
|
||||
end;
|
||||
|
||||
{ later on in your program you can check the return code again }
|
||||
if (dris.ret_code <> 0) then
|
||||
begin
|
||||
messagedlg('Dinkey Dongle protection error.', mtError, [mbok], 0);
|
||||
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
|
||||
messagedlg('Dinkey protection error! You have not patched your algorithm in the MyAlgorithm routine', mtError, [mbok], 0);
|
||||
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
|
||||
messagedlg('Incorrect SDSN! Please modify your source code so that MY_SDSN is set to be your SDSN.', mtError, [mbok], 0);
|
||||
result := -1;
|
||||
exit;
|
||||
end;
|
||||
|
||||
{ later on in your program you can check the return code again }
|
||||
if (dris.ret_code <> 0) then
|
||||
begin
|
||||
messagedlg('Dinkey Dongle protection error.', mtError, [mbok], 0);
|
||||
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
|
||||
messagedlg('Incorrect SDSN! Please modify your source code so that MY_SDSN is set to be your SDSN.', mtError, [mbok], 0);
|
||||
result := -1;
|
||||
exit;
|
||||
end;
|
||||
|
||||
{ later on in your program you can check the return code again }
|
||||
if (dris.ret_code <> 0) then
|
||||
begin
|
||||
messagedlg('Dinkey Dongle protection error.', mtError, [mbok], 0);
|
||||
result := -1;
|
||||
exit;
|
||||
end;
|
||||
|
||||
DataToRead[13] := Chr(0); { null end of string }
|
||||
display := 'Dinkey Dongle data area contains: ' + DataToRead;
|
||||
messagedlg(display, mtInformation, [mbok], 0);
|
||||
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
|
||||
messagedlg('Incorrect SDSN! Please modify your source code so that MY_SDSN is set to be your SDSN.', mtError, [mbok], 0);
|
||||
result := -1;
|
||||
exit;
|
||||
end;
|
||||
|
||||
{ later on in your program you can check the return code again }
|
||||
if (dris.ret_code <> 0) then
|
||||
begin
|
||||
messagedlg('Dinkey Dongle protection error.', mtError, [mbok], 0);
|
||||
result := -1;
|
||||
exit;
|
||||
end;
|
||||
|
||||
DataString[13] := Chr(0); { null end of string }
|
||||
display := 'Decrypted data is: ' + DataString;
|
||||
messagedlg(display, mtInformation, [mbok], 0);
|
||||
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
|
||||
messagedlg('Incorrect SDSN! Please modify your source code so that MY_SDSN is set to be your SDSN.', mtError, [mbok], 0);
|
||||
result := -1;
|
||||
exit;
|
||||
end;
|
||||
|
||||
if (dris.prodcode <> AnsiString(MY_PRODCODE)) then
|
||||
begin
|
||||
messagedlg('Incorrect Product Code! Please modify your source code so that MY_PRODCODE is set to be the Product Code in the dongle.', mtError, [mbok], 0);
|
||||
result := -1;
|
||||
exit;
|
||||
end;
|
||||
|
||||
{ later on in your program you can check the return code again }
|
||||
if (dris.ret_code <> 0) then
|
||||
begin
|
||||
messagedlg('Dinkey Dongle protection error.', mtError, [mbok], 0);
|
||||
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
|
||||
messagedlg('Incorrect SDSN! Please modify your source code so that MY_SDSN is set to be your SDSN.', mtError, [mbok], 0);
|
||||
result := -1;
|
||||
exit;
|
||||
end;
|
||||
|
||||
{ later on in your program you can check the return code again }
|
||||
if (dris.ret_code <> 0) then
|
||||
begin
|
||||
messagedlg('Dinkey Dongle protection error.', mtError, [mbok], 0);
|
||||
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
|
||||
messagedlg('Dinkey protection error! You have not patched your algorithm in the MyAlgorithm routine', mtError, [mbok], 0);
|
||||
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
|
||||
messagedlg('Incorrect SDSN! Please modify your source code so that MY_SDSN is set to be your SDSN.', mtError, [mbok], 0);
|
||||
result := -1;
|
||||
exit;
|
||||
end;
|
||||
|
||||
{ later on in your program you can check the return code again }
|
||||
if (dris.ret_code <> 0) then
|
||||
begin
|
||||
messagedlg('Dinkey Dongle protection error.', mtError, [mbok], 0);
|
||||
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
|
||||
messagedlg('Incorrect SDSN! Please modify your source code so that MY_SDSN is set to be your SDSN.', mtError, [mbok], 0);
|
||||
result := -1;
|
||||
exit;
|
||||
end;
|
||||
|
||||
{ later on in your program you can check the return code again }
|
||||
if (dris.ret_code <> 0) then
|
||||
begin
|
||||
messagedlg('Dinkey Dongle protection error.', mtError, [mbok], 0);
|
||||
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]) + ' ';
|
||||
messagedlg(display, mtInformation, [mbok], 0);
|
||||
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
|
||||
messagedlg('Incorrect SDSN! Please modify your source code so that MY_SDSN is set to be your SDSN.', mtError, [mbok], 0);
|
||||
result := -1;
|
||||
exit;
|
||||
end;
|
||||
|
||||
{ later on in your program you can check the return code again }
|
||||
if (dris.ret_code <> 0) then
|
||||
begin
|
||||
messagedlg('Dinkey Dongle protection error.', mtError, [mbok], 0);
|
||||
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]) + ' ';
|
||||
messagedlg(display, mtInformation, [mbok], 0);
|
||||
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.
|
||||
|
||||
BIN
Dinkey Pro 7.6.1/Samples/Delphi/VCL/Runtime/dpwin32_omf.obj
Normal file
BIN
Dinkey Pro 7.6.1/Samples/Delphi/VCL/Runtime/dpwin32_omf.obj
Normal file
Binary file not shown.
BIN
Dinkey Pro 7.6.1/Samples/Delphi/VCL/Runtime/dpwin64_delphi.obj
Normal file
BIN
Dinkey Pro 7.6.1/Samples/Delphi/VCL/Runtime/dpwin64_delphi.obj
Normal file
Binary file not shown.
102
Dinkey Pro 7.6.1/Samples/Delphi/VCL/Runtime/dris.pas
Normal file
102
Dinkey Pro 7.6.1/Samples/Delphi/VCL/Runtime/dris.pas
Normal file
@@ -0,0 +1,102 @@
|
||||
{ !! this file should not be modified }
|
||||
unit dris;
|
||||
|
||||
interface
|
||||
|
||||
uses Windows;
|
||||
|
||||
TYPE
|
||||
drisType = packed record
|
||||
{ the first 4 fields are never encrypted }
|
||||
header : array[0..3] of AnsiChar; { should be set to DRIS }
|
||||
{ inputs }
|
||||
size : longint; { size of this structure }
|
||||
seed1 : longint; { seed for data/dris encryption }
|
||||
seed2 : longint; { as above }
|
||||
{ maybe encrypted from now on }
|
||||
myfunction : longint; { specify only one function. NB can't name it "function" as it is a reserved keyword }
|
||||
flags : longint; { options for the function selected. To use more than one OR them together: OPTION1 or OPTION2... }
|
||||
execs_decrement : longword; { amount by which to dec execs if we use flag: DEC_MANY_EXECS }
|
||||
data_crypt_key_num : longint; { number of the key (1-3) that the dongle uses to encrypt or decrypt user data }
|
||||
rw_offset : longint; { offset in the dongle data area to read or write data }
|
||||
rw_length : longint; { 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 : longint; { variable values for user algorithm }
|
||||
var_b : longint;
|
||||
var_c : longint;
|
||||
var_d : longint;
|
||||
var_e : longint;
|
||||
var_f : longint;
|
||||
var_g : longint;
|
||||
var_h : longint;
|
||||
alg_number : longint; { the number of the user algorithm that you want to execute }
|
||||
{ outputs }
|
||||
ret_code : longint; { return code from the protection check }
|
||||
ext_err : longint; { extended error }
|
||||
dongle_type : longint; { type of dongle detected. 1 = Pro, 2 = FD. NB "type" is a reserved word so I use dongle_type }
|
||||
model : longint; { model of dongle detected. 1 = Lite, 2 = Plus, 4 = Net 5, 7 = Net Unlimited }
|
||||
sdsn : longint; { Software Developer's Serial Number }
|
||||
prodcode : array[0..11] of AnsiChar; { Product Code (null-terminated) }
|
||||
dongle_number : longword;
|
||||
update_number : longint;
|
||||
data_area_size : longword; { size of the data area in the dongle detected }
|
||||
max_alg_num : longint; { the maximum algorithm number in the dongle detected }
|
||||
execs : longint; { executions left: -1 indicates 'no limit' }
|
||||
exp_day : longint; { expiry day: -1 indicates 'no limit' }
|
||||
exp_month : longint; { expiry month: -1 indicates 'no limit' }
|
||||
exp_year : longint; { expiry year: -1 indicates 'no limit' }
|
||||
features : longword; { features value }
|
||||
net_users : longint; { maximum number of network users for the dongle detected: -1 indicates 'no limit' }
|
||||
alg_answer : longint; { answer to the user algorithm executed with the given variable values }
|
||||
fd_capacity : longword; { 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 : longint; { 0 = no swkey detected, 1 = temporary software key, 2 = demo software key }
|
||||
swkey_exp_day : longint; { software key expiry date (if software key detected) }
|
||||
swkey_exp_month : longint;
|
||||
swkey_exp_year : longint;
|
||||
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 }
|
||||
|
||||
{ runtime api functions}
|
||||
function DDProtCheck( dris, data:pointer ):LongInt; stdcall; external;
|
||||
function DDGetNetUserList(licence_name:PAnsiChar; num_net_users:PLongInt; nu_info:pointer; num_info_structs:LongInt; extended_error:PLongInt):LongInt; stdcall; external;
|
||||
|
||||
implementation
|
||||
|
||||
{$IFDEF WIN32}
|
||||
{$L dpwin32_omf.obj}
|
||||
{$ELSE}
|
||||
{$L dpwin64_delphi.obj}
|
||||
{$ENDIF}
|
||||
|
||||
end.
|
||||
100
Dinkey Pro 7.6.1/Samples/Delphi/VCL/Runtime/dris_for_dll.pas
Normal file
100
Dinkey Pro 7.6.1/Samples/Delphi/VCL/Runtime/dris_for_dll.pas
Normal file
@@ -0,0 +1,100 @@
|
||||
{ !! this file should not be modified }
|
||||
unit dris;
|
||||
|
||||
interface
|
||||
|
||||
uses Windows;
|
||||
|
||||
TYPE
|
||||
drisType = packed record
|
||||
{ the first 4 fields are never encrypted }
|
||||
header : array[0..3] of AnsiChar; { should be set to DRIS }
|
||||
{ inputs }
|
||||
size : longint; { size of this structure }
|
||||
seed1 : longint; { seed for data/dris encryption }
|
||||
seed2 : longint; { as above }
|
||||
{ maybe encrypted from now on }
|
||||
myfunction : longint; { specify only one function. NB can't name it "function" as it is a reserved keyword }
|
||||
flags : longint; { options for the function selected. To use more than one OR them together: OPTION1 or OPTION2... }
|
||||
execs_decrement : longword; { amount by which to dec execs if we use flag: DEC_MANY_EXECS }
|
||||
data_crypt_key_num : longint; { number of the key (1-3) that the dongle uses to encrypt or decrypt user data }
|
||||
rw_offset : longint; { offset in the dongle data area to read or write data }
|
||||
rw_length : longint; { 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 : longint; { variable values for user algorithm }
|
||||
var_b : longint;
|
||||
var_c : longint;
|
||||
var_d : longint;
|
||||
var_e : longint;
|
||||
var_f : longint;
|
||||
var_g : longint;
|
||||
var_h : longint;
|
||||
alg_number : longint; { the number of the user algorithm that you want to execute }
|
||||
{ outputs }
|
||||
ret_code : longint; { return code from the protection check }
|
||||
ext_err : longint; { extended error }
|
||||
dongle_type : longint; { type of dongle detected. 1 = Pro, 2 = FD. NB "type" is a reserved word so I use dongle_type }
|
||||
model : longint; { model of dongle detected. 1 = Lite, 2 = Plus, 4 = Net 5, 7 = Net Unlimited }
|
||||
sdsn : longint; { Software Developer's Serial Number }
|
||||
prodcode : array[0..11] of AnsiChar; { Product Code (null-terminated) }
|
||||
dongle_number : longword;
|
||||
update_number : longint;
|
||||
data_area_size : longword; { size of the data area in the dongle detected }
|
||||
max_alg_num : longint; { the maximum algorithm number in the dongle detected }
|
||||
execs : longint; { executions left: -1 indicates 'no limit' }
|
||||
exp_day : longint; { expiry day: -1 indicates 'no limit' }
|
||||
exp_month : longint; { expiry month: -1 indicates 'no limit' }
|
||||
exp_year : longint; { expiry year: -1 indicates 'no limit' }
|
||||
features : longword; { features value }
|
||||
net_users : longint; { maximum number of network users for the dongle detected: -1 indicates 'no limit' }
|
||||
alg_answer : longint; { answer to the user algorithm executed with the given variable values }
|
||||
fd_capacity : longword; { 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 : longint; { 0 = no swkey detected, 1 = temporary software key, 2 = demo software key }
|
||||
swkey_exp_day : longint; { software key expiry date (if software key detected) }
|
||||
swkey_exp_month : longint;
|
||||
swkey_exp_year : longint;
|
||||
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 ):LongInt; stdcall; external 'dpwin32.dll';
|
||||
function DDGetNetUserList(licence_name:PAnsiChar; num_net_users:PLongInt; nu_info:pointer; num_info_structs:LongInt; extended_error:PLongInt):LongInt; stdcall; external 'dpwin32.dll';
|
||||
{$ELSE}
|
||||
function DDProtCheck( dris, data:pointer ):LongInt; stdcall; external 'dpwin64.dll';
|
||||
function DDGetNetUserList(licence_name:PAnsiChar; num_net_users:PLongInt; nu_info:pointer; num_info_structs:LongInt; extended_error:PLongInt):LongInt; stdcall; external 'dpwin64.dll';
|
||||
{$ENDIF}
|
||||
|
||||
implementation
|
||||
|
||||
end.
|
||||
Reference in New Issue
Block a user