8.5.6.2 SecureDELTA Object Pascal Main Demo App


   SecureDELTA Object Pascal Main Demo Application file


The listing for securedelta_pascal_main_demo.pas


  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
///////////////////////////////////////////////////////////////////////
//                                                                     
// SecureDELTA SDK Objective Pascal Main DEMO Application              
// Part of SecureDELTA SDK v2.56.109 (C) agersoftware srl              
//                                                                     
// Designed, developed and implemented by agersoftware srl and its     
// technology partner, NetLUP Xtreme Technologies srl                  
//                                                                     
// Copyright (C) 2019-2029 agersoftware srl, All Rights Reserved.      
// Portions Copyright (C) 2019-2029 NetLUP Xtreme Technologies srl.    
//                                                                     
// NOTICE:                                                             
// All information contained herein is and remains the property of     
// agersoftware srl and its suppliers or technological partners        
// NetLUP Xtreme Technologies srl                                      
//                                                                     
// INTELLECTUAL PROPERTY                                               
// The intellectual and technical concepts contained herein are also   
// proprietary to agersoftware srl and its suppliers or technological  
// partner NetLUP Xtreme Technologies srl and are protected by trade   
// secret or copyright law.                                            
//                                                                     
// CONFIDENTIAL                                                        
// Dissemination of this information or reproduction of this material  
// is strictly forbidden unless prior written permission is obtained   
// from agersoftware srl or NetLUP Xtreme Technologies srl.            
//                                                                     
// COPYRIGHT                                                           
// This software is provided by the copyright holders and technology   
// partners "as is" and any express or implied warranties, including,  
// but not limited to, the implied warranties of merchantability and   
// fitness for a particular purpose are disclaimed.                    
//                                                                     
// NO LIABILITY                                                        
// In no event shall the copyright owner or technology partners be     
// liable for any direct, indirect, incidental, special, exemplary, or 
// consequential damages(including, but not limited to, procurement    
// of  substitute goods or services; loss of use, data, or profits;    
// or business interruption) however caused and on any theory of       
// liability, whether in contract, strict liability, or tort           
// (including negligence or otherwise)  arising in any way out of the  
// use of this software, even if advised of the possibility of such    
// damage.                                                             
//                                                                     
// INFO & CONTACT                                                      
// securesdk@securedelta.eu | securesdkinfo@agersoftware.com           
//                                                                     
///////////////////////////////////////////////////////////////////////

unit SecureDELTA_Pascal_Main_Demo;

{$mode objfpc}{$H+}

interface


uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls, windows;

const
  _SD_SDK_MAXPATH_ = 380;
  _SD_SDK_MAX_VER_ = 32;

  SD_SDK_SecureENCODE_DLL_Name = 'SecureENCODE_SDK_DLL_x86.dll';
  SD_SDK_SecureENCODE_DLL_FuncMain_Name = 'SecureDELTA_SDK_SecureENCODE_Main_';

  SD_SDK_SecureDECODE_DLL_Name = 'SecureDECODE_SDK_DLL_x86.dll';
  SD_SDK_SecureDECODE_DLL_FuncMain_Name = 'SecureDELTA_SDK_SecureDECODE_Main_';

type

  { TPascalEncodeDecodeDemoForm }
  {$packrecords 8}
  TEncodeDLLHeaderStruct = packed record
    _use_xtreme_mode          : Byte;    // 1 Byte
    _use_callback             : Byte;    // 1 byte
    _cpu_priority_level       : Byte;    // 1 byte
    _reserved1                : Byte;    // 1 bytes

    _dwReserved               : Longint; // 4 bytes

    _dwSourceMajorFileVersion : Longint; // 4 bytes
    _dwSourceMinorFileVersion : Longint; // 4 bytes
    _dwTargetMajorFileVersion : Longint; // 4 bytes
    _dwTargetMinorFileVersion : Longint; // 4 bytes

    _wchr_sourcefile_path     : array [0.._SD_SDK_MAXPATH_ - 1 {null terminator}] of WideChar;
    _wchr_targetfile_path     : array [0.._SD_SDK_MAXPATH_ - 1 {null terminator}] of WideChar;
    _wchr_securedelta_path    : array [0.._SD_SDK_MAXPATH_ - 1 {null terminator}] of WideChar;

    _wchr_versionSource       : array [0.._SD_SDK_MAX_VER_ - 1 {null terminator}] of WideChar;
    _wchr_versionTarget       : array [0.._SD_SDK_MAX_VER_ - 1 {null terminator}] of WideChar;

    _callback_p_user_data     : ^UInt32;// void *  8bytes (x64)
    _callback_user_hwnd       : HWnd; //  8 bytes        HWND
    _callback_function        : ^UInt32;
  end;

  TImportedEncodeFunc = function({send as reference} var  header: TEncodeDLLHeaderStruct) : Longint; stdcall;

  {$packrecords 8}
  TDecodeDLLHeaderStruct = packed record
    _use_callback             : Byte;    // 1 byte
    _cpu_priority_level       : Byte;    // 1 byte
    _reserved1                : Byte;    // 1 byte
    _reserved2                : Byte;    // 1 byte

    _dwReserved               : Longint; // 4 bytes

    _wchr_sourcefile_path     : array [0.._SD_SDK_MAXPATH_ - 1 {null terminator}] of WideChar;
    _wchr_targetfile_path     : array [0.._SD_SDK_MAXPATH_ - 1 {null terminator}] of WideChar;
    _wchr_securedelta_path    : array [0.._SD_SDK_MAXPATH_ - 1 {null terminator}] of WideChar;

    _callback_p_user_data     : ^UInt32; // void * n 64bits
    _callback_user_hwnd       : HWnd;    // 4 bytes HWND
    _callback_function        : ^UInt32;
  end;


  TImportedDecodeFunc = function({send as reference} var header: TDecodeDLLHeaderStruct) : Longint; stdcall;

  TPascalEncodeDecodeDemoForm = class(TForm)
    ButtonBrowseSourceEncode: TButton;
    ButtonBrowseSourceEncode1: TButton;
    ButtonBrowseTargetEncode: TButton;
    ButtonBrowseTargetEncode1: TButton;
    ButtonEncode: TButton;
    ButtonDecode: TButton;
    XtremeDELTA: TCheckBox;

    edtOperationResultDecode: TEdit;
    edtOperationResultEncode: TEdit;

    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;

    sourceFileNameEncodeEdit: TEdit;
    sourceFileNameDecodeEdit: TEdit;

    targetFileNameEncodeEdit: TEdit;
    targetFileNameDecodeEdit: TEdit;

    deltaFileNameEncodeEdit: TEdit;
    deltaFileNameDecodeEdit: TEdit;

    OpenDialog1: TOpenDialog;

    procedure XtremeDELTAChange(Sender: TObject);

    procedure OnSourceEncodeChange(Sender: TObject);
    procedure OnSourceDecodeChange(Sender: TObject);

    procedure OnTargetDecodeChange(Sender: TObject);
    procedure OnTargetEncodeChange(Sender: TObject);

    procedure OnDeltaEncodeChange(Sender: TObject);
    procedure OnDeltaDecodeChange(Sender: TObject);

    procedure Load_SecureDECODE_DLL();
    procedure Load_SecureENCODE_DLL();

    procedure ButtonBrowseSourceEncodeClick(Sender: TObject);
    procedure ButtonBrowseTargetEncodeClick(Sender: TObject);

    procedure ButtonEncodeClick(Sender: TObject);
    procedure ButtonDecodeClick(Sender: TObject);
    procedure ButtonBrowseTargetSDeltaClick(Sender: TObject);

    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);

  private
    { private declarations }

    resSecureENCODE: SmallInt;
    encodeDLL32bit: THandle;
    SecureENCODEFuncMain : TImportedEncodeFunc;
    encodeDLLHeaderStruct: TEncodeDLLHeaderStruct;

    resSecureDECODE: SmallInt;
    decodeDLL32bit : THandle;
    SecureDECODEFuncMain : TImportedDecodeFunc;
    decodeDLLHeaderStruct: TDecodeDLLHeaderStruct;

  end;

var
  PascalEncodeDecodeDemoForm: TPascalEncodeDecodeDemoForm;

var
   i : SmallInt;
   temp : String;

   addr1 : UInt32;
   addr2 : UInt32;
   addr3 : UInt32;

   useXtremeDelta : bool;
   encodeStructSize : SmallInt;
   decodeStructSize : SmallInt;

   sourceFilenameEncode: String;
   targetFilenameEncode: String;
   deltaFilenameEncode:  String;

   sourceFilenameDecode: String;
   targetFilenameDecode: String;
   deltaFilenameDecode:  String;


   szCaptionDLLEncodeLoad : string;
   szCaptionDLLDecodeLoad : string;

implementation

{$R *.lfm}

{ TPascalEncodeDecodeDemoForm }
procedure TPascalEncodeDecodeDemoForm.FormCreate(Sender: TObject);
begin
   ButtonEncode.Enabled := False;
   ButtonDecode.Enabled := False;

   Load_SecureENCODE_DLL();
   Load_SecureDECODE_DLL();

   addr1 := $1122CC99;
   addr2 := $1234A0BB;
   addr3 := $0EF0AABB;

end;
procedure TPascalEncodeDecodeDemoForm.FormDestroy(Sender: TObject);
 begin
   if (encodeDLL32bit <> 0) then
      FreeLibrary(encodeDLL32bit);

   if (decodeDLL32bit <> 0) then
      FreeLibrary(decodeDLL32bit);
 end;

procedure TPascalEncodeDecodeDemoForm.Load_SecureENCODE_DLL();
begin
   encodeDLL32bit := LoadLibrary(SD_SDK_SecureENCODE_DLL_Name);
   if (encodeDLL32bit <> 0) then
   begin
     ButtonEncode.Enabled := True;
     szCaptionDLLEncodeLoad := SD_SDK_SecureENCODE_DLL_Name + ' loaded Ok!';
   end
   else
   begin
        szCaptionDLLEncodeLoad := SD_SDK_SecureENCODE_DLL_Name + ' loaded NOK. Error code = ' + IntToStr(GetLastError);
   end;
   edtOperationResultEncode.Text := szCaptionDLLEncodeLoad;
end;

procedure TPascalEncodeDecodeDemoForm.Load_SecureDECODE_DLL();
begin
  decodeDLL32bit := LoadLibrary(SD_SDK_SecureDECODE_DLL_Name);
  if (decodeDLL32bit <> 0) then
  begin
    ButtonDecode.Enabled := True;
    szCaptionDLLDecodeLoad := SD_SDK_SecureDECODE_DLL_Name + ' loaded Ok!';
  end
  else
  begin
       szCaptionDLLDecodeLoad := SD_SDK_SecureDECODE_DLL_Name + ' loaded NOK. Error code = ' + IntToStr(GetLastError);
  end;
  edtOperationResultDecode.Text := szCaptionDLLDecodeLoad;
end;
procedure TPascalEncodeDecodeDemoForm.OnSourceEncodeChange(Sender: TObject);
begin
  begin
       sourceFilenameEncode := sourceFileNameEncodeEdit.Text;
  end;
end;

procedure TPascalEncodeDecodeDemoForm.OnSourceDecodeChange(Sender: TObject);
begin
  begin
       sourceFilenameDecode := sourceFileNameDecodeEdit.Text;
  end;
end;

procedure TPascalEncodeDecodeDemoForm.OnTargetDecodeChange(Sender: TObject);
begin
   begin
       targetFilenameDecode := targetFilenameDecodeEdit.Text;
  end;
end;

procedure TPascalEncodeDecodeDemoForm.XtremeDELTAChange(Sender: TObject);
begin
   useXtremeDelta := XtremeDELTA.Checked;
end;

procedure TPascalEncodeDecodeDemoForm.OnTargetEncodeChange(Sender: TObject);
begin
  begin
       targetFilenameEncode := targetFileNameEncodeEdit.Text;
  end;
end;

procedure TPascalEncodeDecodeDemoForm.OnDeltaEncodeChange(Sender: TObject);
begin
  begin
       deltaFilenameEncode := deltaFilenameEncodeEdit.Text;
  end;
end;

procedure TPascalEncodeDecodeDemoForm.OnDeltaDecodeChange(Sender: TObject);
begin
  begin
       deltaFilenameDecode := deltaFilenameDecodeEdit.Text;
  end;
end;

procedure TPascalEncodeDecodeDemoForm.ButtonBrowseSourceEncodeClick(Sender: TObject);
begin
  if OpenDialog1.Execute then
  begin
       sourceFilenameEncode := OpenDialog1.Filename;
       {ShowMessage(targetFilenameEncode);}
       sourceFilenameEncodeEdit.Text := sourceFilenameEncode;
       sourceFilenameDecodeEdit.Text := sourceFilenameEncode;
  end;
end;
procedure TPascalEncodeDecodeDemoForm.ButtonBrowseTargetEncodeClick(Sender: TObject);
begin
  if OpenDialog1.Execute then
  begin
       targetFilenameEncode := OpenDialog1.Filename;
       {ShowMessage(targetFilenameEncode);}
       deltaFilenameEncode := targetFilenameEncode + '.secureDelta';
       targetFileNameEncodeEdit.Text := targetFilenameEncode;
       deltaFileNameEncodeEdit.Text := deltaFilenameEncode;

       targetFileNameDecodeEdit.Text := targetFilenameEncode + '.secureDelta' + '.new';
       deltaFileNameDecodeEdit.Text := deltaFilenameEncode;
  end;
end;

procedure TPascalEncodeDecodeDemoForm.ButtonBrowseTargetSDeltaClick(Sender: TObject);
begin
  if OpenDialog1.Execute then
  begin
       deltaFilenameEncode := OpenDialog1.Filename;
       deltaFilenameDecode := deltaFilenameEncode;
       {ShowMessage(targetFilenameEncode);}
       deltaFileNameEncodeEdit.Text := deltaFilenameEncode;
       deltaFileNameDecodeEdit.Text := deltaFilenameEncode;

       temp := deltaFilenameEncode + '.new';
       targetFileNameEncodeEdit.Text := temp;
       targetFileNameDecodeEdit.Text := temp;

  end;
end;

procedure MakeWideArrayFromString(_stringToArray : string; var _arr: array of AnsiChar);
begin
  for i := 0 to (length(_stringToArray) - 1) do
  begin
      _arr[i*2 + 1] := #0;
      _arr[i*2] := AnsiChar(_stringToArray[i+1]);
   end;
end;

procedure TPascalEncodeDecodeDemoForm.ButtonEncodeClick(Sender: TObject);
begin
  if ((encodeDLL32bit <> 0)  and
      (sourceFileNameEncodeEdit.GetTextLen > 0) and
      (targetFilenameEncodeEdit.GetTextLen > 0) and
      (deltaFilenameEncodeEdit.GetTextLen > 0)) then
  begin
     SecureENCODEFuncMain := TImportedEncodeFunc(GetProcAddress(encodeDLL32bit, SD_SDK_SecureENCODE_DLL_FuncMain_Name));
     if (@SecureENCODEFuncMain <> nil) then
     begin
          encodeDLLHeaderStruct._use_callback := 0;
          encodeDLLHeaderStruct._cpu_priority_level := 0;

          encodeDLLHeaderStruct._dwSourceMajorFileVersion := 0;
          encodeDLLHeaderStruct._dwTargetMajorFileVersion := 0;

          if (useXtremeDelta = True) then
             encodeDLLHeaderStruct._use_xtreme_mode := Byte (1);

          //https://smartpascal.github.io/help/assets/stringtowidechar.htm

          StringToWideChar(sourceFilenameEncode, encodeDLLHeaderStruct._wchr_sourcefile_path, _SD_SDK_MAXPATH_-1);
          StringToWideChar(targetFilenameEncode, encodeDLLHeaderStruct._wchr_targetfile_path, _SD_SDK_MAXPATH_-1);
          StringToWideChar(deltaFilenameEncode, encodeDLLHeaderStruct._wchr_securedelta_path, _SD_SDK_MAXPATH_-1);

          StringToWideChar(String('v.1.1.100'), encodeDLLHeaderStruct._wchr_versionSource, 10);
          StringToWideChar(String('v.2.3.501'), encodeDLLHeaderStruct._wchr_versionTarget, 10);

          //MakeWideArrayFromString('v.1.1.100', encodeDLLHeaderStruct._wchr_versionSource);
          //MakeWideArrayFromString('v.2.3.501', encodeDLLHeaderStruct._wchr_versionTarget);

          encodeDLLHeaderStruct._callback_function    := Addr(addr1);
          encodeDLLHeaderStruct._callback_p_user_data := Addr(addr2);
          encodeDLLHeaderStruct._callback_user_hwnd   := addr3;

          encodeStructSize := sizeOf(encodeDLLHeaderStruct);
          resSecureENCODE := SecureENCODEFuncMain(encodeDLLHeaderStruct);

          ShowMessage('SecureENCODE Func returned ' + IntToStr(resSecureENCODE));

          // if everything ok move the parameters to DECODE
          if (resSecureENCODE = 0) Then
          begin
           sourceFileNameDecodeEdit.Text := sourceFilenameEncode;
           targetFileNameDecodeEdit.Text := targetFilenameEncode;
           deltaFileNameDecodeEdit.Text := deltaFilenameEncode;
          end
     end
     else
          ShowMessage('SecureENCODE Entry Point not found! Please check the validity of this DLL!');
  end
  else
  begin
          ShowMessage('SecureENCODE Parameters are required!');
  end
end;

procedure TPascalEncodeDecodeDemoForm.ButtonDecodeClick(Sender: TObject);
begin
  if ((decodeDLL32bit <> 0) and
      (sourceFileNameDecodeEdit.GetTextLen > 0) and
      (targetFilenameDecodeEdit.GetTextLen > 0) and
      (deltaFilenameDecodeEdit.GetTextLen > 0)) then
  begin
     SecureDECODEFuncMain := TImportedDecodeFunc(GetProcAddress(decodeDLL32bit, SD_SDK_SecureDECODE_DLL_FuncMain_Name));
     if (@SecureDECODEFuncMain <> nil) then
     begin
          decodeDLLHeaderStruct._use_callback := 0;
          decodeDLLHeaderStruct._cpu_priority_level := 0;

          StringToWideChar(sourceFilenameDecode, decodeDLLHeaderStruct._wchr_sourcefile_path, _SD_SDK_MAXPATH_-1);
          StringToWideChar(targetFilenameDecode, decodeDLLHeaderStruct._wchr_targetfile_path, _SD_SDK_MAXPATH_-1);
          StringToWideChar(deltaFilenameDecode,  decodeDLLHeaderStruct._wchr_securedelta_path, _SD_SDK_MAXPATH_-1);

          decodeDLLHeaderStruct._callback_function    := Addr(addr1);
          decodeDLLHeaderStruct._callback_p_user_data := Addr(addr2);
          decodeDLLHeaderStruct._callback_user_hwnd   := addr3;

          decodeStructSize := sizeOf(decodeDLLHeaderStruct);
          resSecureDECODE := SecureDECODEFuncMain(decodeDLLHeaderStruct);

          ShowMessage('SecureDECODE Func returned ' + IntToStr(resSecureDECODE));

     end
     else
          ShowMessage('SecureDECODE Entry Point not found! Please check the validity of this DLL');
  end
  else
  begin
          ShowMessage('SecureDECODE Parameters are required!');
  end;
end;

end.