8.5.3.2 SecureDELTA SDK VB .NET Demo App


   SecureDELTA SDK VB .NET Demo Client Form Application file


The listing for SecureDELTA_SDK_DEMO_APP_VB_NET_ClientForm x86.vb


  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
///////////////////////////////////////////////////////////////////////
//                                                                     
// SecureDELTA SDK - VB .NET DEMO Application (32bit)                  
// Part of SecureDELTA SDK v2.56 (C) agersoftware srl                  
//                                                                     
// Designed, developed and implemented by agersoftware srl             
// And 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 partner,        
// 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 contributors 
// "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 contributors 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           
//                                                                     
///////////////////////////////////////////////////////////////////////

Imports System.Text.RegularExpressions
Imports System.Text
Imports Microsoft.VisualBasic
Imports System.Runtime.InteropServices

Module NativeMethods
    Public Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As IntPtr
    Public Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As IntPtr, ByVal lpProcName As String) As IntPtr
    Public Declare Function FreeLibrary Lib "kernel32" (ByVal hModule As IntPtr) As IntPtr
End Module

Public Class SecureDELTA_DemoApp_VB_NET_ClientForm_x86

    Public Const _SECURE_DELTA_EXT As String = ".SecureDELTA"
    Public Const _XTREME_DELTA_EXT As String = ".XtremeDELTA"

    Public Const _SD_SDK_MAXPATH_ As Integer = &H17C
    Public Const _SD_SDK_MAX_VER_ As Integer = &H20

    Dim SecureENCODE_LibraryHandle As IntPtr
    Dim SecureENCODE_FunctionHandle As IntPtr

    Dim SecureDECODE_LibraryHandle As IntPtr
    Dim SecureDECODE_FunctionHandle As IntPtr

    Enum SD_SDK_SECURE_ENCODE_RETURN_ID_TYPE
        SD_SDK_ENCODE_NO_ERROR_ = 0
        SD_SDK_ENCODE_ERROR_INITIALIZATION_ = -1
        SD_SDK_ENCODE_ERROR_USER_CANCELED_ = -2          ' Use this during current action to Abort
        SD_SDK_ENCODE_ERROR_NO_CALLBACK_PTR_ = -3
        SD_SDK_ENCODE_ERROR_NO_USER_DEFINED_PTR_ = -4
        SD_SDK_ENCODE_ERROR_NOT_USING_CALLBACK_PTR_ = -5
        SD_SDK_ENCODE_ERROR_USER_CANCELLED_NAG_WND = -6  ' User canceled the NAG screen In Trial Mode
    End Enum
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi, Pack:=8)>
    Structure SD_SDK_SECURE_ENCODE_CALLBACK_STRUCT
        Public _callback_ID As SD_SDK_SECURE_ENCODE_RETURN_ID_TYPE
        Public _callback_event_type_ID As UInt32
        Public dbl_operation_progress_indicator As Double
        Public uint_main_progress_indicator As UInt32

    End Structure

    Delegate Function SecureDelta_SecureENCODE_Callback_Main_Type(_sd_sdk_secure_decode_structure As SD_SDK_SECURE_ENCODE_CALLBACK_STRUCT, p_sd_sdk_user_data As IntPtr) As Integer
    Function SecureDelta_SecureENCODE_Callback_Main(_sd_sdk_secure_decode_structure As SD_SDK_SECURE_ENCODE_CALLBACK_STRUCT, p_sd_sdk_user_data As IntPtr) As Integer
        ctrlProgressBar_Action.Value = _sd_sdk_secure_decode_structure.dbl_operation_progress_indicator
        ctrlProgressBar_Main.Value = _sd_sdk_secure_decode_structure.uint_main_progress_indicator
        Application.DoEvents()
        Return SD_SDK_SECURE_ENCODE_RETURN_ID_TYPE.SD_SDK_ENCODE_NO_ERROR_ ' Use SD_SDK_SECUREENCODE_RETURN_ID_TYPE.SD_SDK_ENCODE_ERROR_USER_CANCELED_ to abort current action
    End Function

    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi, Pack:=8)>
    Structure SD_SDK_SecureENCODE_Struct_PARAM

        Public _use_xtreme_mode As Byte
        Public _use_callback As Byte
        Public _cpu_priority_level As Byte

        Public _reserved_0_ As Byte
        Public _dwReserved As UInt32

        Public _dwSourceMajorFileVersion As UInt32
        Public _dwSourceMinorFileVersion As UInt32
        Public _dwTargetMajorFileVersion As UInt32
        Public _dwTargetMinorFileVersion As UInt32

        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=_SD_SDK_MAXPATH_ * 2)>
        Public _wchr_sourcefile_path As Byte()

        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=_SD_SDK_MAXPATH_ * 2)>
        Public _wchr_new_targetfile_path As Byte()

        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=_SD_SDK_MAXPATH_ * 2)>
        Public _wchr_securedelta_path As Byte()

        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=_SD_SDK_MAX_VER_ * 2)>
        Public _wchr_versionSource As Byte()

        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=_SD_SDK_MAX_VER_ * 2)>
        Public _wchr_versionTarget As Byte()

        Public _callback_p_user_data As UInt32
        Public _callback_user_hwnd As UInt32
        Public _callback_function As SecureDelta_SecureENCODE_Callback_Main_Type
    End Structure

    Delegate Function SecureDelta_SecureENCODE_Main(ByRef _sd_sdk_secure_encode_structure As SD_SDK_SecureENCODE_Struct_PARAM) As Integer


    Enum SD_SDK_SECURE_DECODE_RETURN_ID_TYPE
        SD_SDK_DECODE_NO_ERROR_ = 0
        SD_SDK_DECODE_ERROR_INITIALIZATION_ = -1
        SD_SDK_DECODE_ERROR_USER_CANCELED_ = -2
        SD_SDK_DECODE_ERROR_NO_CALLBACK_PTR_ = -3
        SD_SDK_DECODE_ERROR_NOT_USING_CALLBACK_PTR_ = -4
        SD_SDK_DECODE_ERROR_GENERAL_ERROR_ = -5
    End Enum
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi, Pack:=8)>
    Structure SD_SDK_SECURE_DECODE_CALLBACK_STRUCT
        Public _callback_ID As SD_SDK_SECURE_DECODE_RETURN_ID_TYPE
        Public _callback_event_type_ID As UInt32
        Public dbl_operation_progress_indicator As Double
        Public uint_main_progress_indicator As UInt32

    End Structure

    Delegate Function SecureDelta_SecureDECODE_Callback_Main_Type(_sd_sdk_secure_decode_structure As SD_SDK_SECURE_DECODE_CALLBACK_STRUCT, p_sd_sdk_user_data As IntPtr, HWnd As UInt32) As Integer
    Function SecureDelta_SecureDECODE_Callback_Main(_sd_sdk_secure_decode_structure As SD_SDK_SECURE_DECODE_CALLBACK_STRUCT, p_sd_sdk_user_data As IntPtr, HWnd As UInt32) As Integer
        ctrlProgressBar_Action.Value = _sd_sdk_secure_decode_structure.dbl_operation_progress_indicator
        ctrlProgressBar_Main.Value = _sd_sdk_secure_decode_structure.uint_main_progress_indicator
        Application.DoEvents()
        Return SD_SDK_SECURE_DECODE_RETURN_ID_TYPE.SD_SDK_DECODE_NO_ERROR_ ' use SD_SDK_SECURE_DECODE_RETURN_ID_TYPE.SECURE_DELTA_ENCODE_ERROR_USER_CANCELED_ to cancel current action
    End Function

    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi, Pack:=8)>
    Structure SD_SDK_SecureDECODE_Struct_PARAM

        Public _use_callback As Byte
        Public _cpu_priority_level As Byte

        Public _reserved_0_ As Byte
        Public _reserved_1_ As Byte

        Public _dwReserved As UInt32

        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=_SD_SDK_MAXPATH_ * 2)>
        Public _wchr_sourcefile_path As Byte()

        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=_SD_SDK_MAXPATH_ * 2)>
        Public _wchr_new_targetfile_path As Byte()

        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=_SD_SDK_MAXPATH_ * 2)>
        Public _wchr_securedelta_path As Byte()

        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=_SD_SDK_MAXPATH_ * 2)>
        Public _wchr_publickey_path As Byte()

        Public _callback_p_user_data As UInt32
        Public _callback_user_hwnd As UInt32
        Public _callback_function As SecureDelta_SecureDECODE_Callback_Main_Type
    End Structure

    Delegate Function SecureDelta_SecureDECODE_Main(ByRef _sd_sdk_secure_decode_structure As SD_SDK_SecureDECODE_Struct_PARAM) As Integer

    Dim SecureENCODE_DLL_Path_ As String = "SecureENCODE_SDK_DLL_x86.dll"
    Dim SecureENCODE_DLL_Main_Function_ As String = "SecureDELTA_SDK_SecureENCODE_Main_"

    Dim SecureDECODE_DLL_Path_ As String = "SecureDECODE_SDK_DLL_x86.dll"
    Dim SecureDECODE_DLL_Main_Function_ As String = "SecureDELTA_SDK_SecureDECODE_Main_"

    Dim _source_file As String
    Dim _target_file As String
    Dim _delta_file As String

    Private Sub Error_MSG(message As String)
        MsgBox(message, vbOKOnly, "Error")
    End Sub

    Private Sub on_textChanged_Target(sender As Object, e As EventArgs) Handles TargetFile_textBox.TextChanged
        _target_file = sender.Text
        _target_file += _SECURE_DELTA_EXT
        SecureDELTA_File_textBox.Text = _target_file
    End Sub

    Public Sub Button_SecureENCODE_onClick(sender As Object, e As EventArgs) Handles Button_SecureENCODE.Click

        If (SourceFile_textBox.TextLength = 0) Or (TargetFile_textBox.TextLength = 0) Or (SecureDELTA_File_textBox.TextLength = 0) Then
            Error_MSG("No input files were specified!")
            Return
        End If

        Dim secureEncodeMain As SecureDelta_SecureENCODE_Main = DirectCast(Marshal.GetDelegateForFunctionPointer(SecureENCODE_FunctionHandle, GetType(SecureDelta_SecureENCODE_Main)), SecureDelta_SecureENCODE_Main)

        Dim _secure_encode_struct As SD_SDK_SecureENCODE_Struct_PARAM

        _secure_encode_struct._use_callback = 1
        _secure_encode_struct._cpu_priority_level = 0
        _secure_encode_struct._callback_p_user_data = 0
        _secure_encode_struct._callback_user_hwnd = Me.Handle
        _secure_encode_struct._callback_function = AddressOf SecureDelta_SecureENCODE_Callback_Main
       
        If (chkBox_useXtremeDELTA.Checked = True) Then
            _secure_encode_struct._use_xtreme_mode = 1
        End If

        _secure_encode_struct._wchr_sourcefile_path = System.Text.Encoding.Unicode.GetBytes(SourceFile_textBox.Text)
        ReDim Preserve _secure_encode_struct._wchr_sourcefile_path(_SD_SDK_MAXPATH_ * 2)

        _secure_encode_struct._wchr_new_targetfile_path = System.Text.Encoding.Unicode.GetBytes(TargetFile_textBox.Text)
        ReDim Preserve _secure_encode_struct._wchr_new_targetfile_path(_SD_SDK_MAXPATH_ * 2)

        _secure_encode_struct._wchr_securedelta_path = System.Text.Encoding.Unicode.GetBytes(SecureDELTA_File_textBox.Text)
        ReDim Preserve _secure_encode_struct._wchr_securedelta_path(_SD_SDK_MAXPATH_ * 2)

        _secure_encode_struct._wchr_versionSource = System.Text.Encoding.Unicode.GetBytes("v.1.101.200")
        ReDim Preserve _secure_encode_struct._wchr_versionSource(_SD_SDK_MAX_VER_ * 2)

        _secure_encode_struct._wchr_versionTarget = System.Text.Encoding.Unicode.GetBytes("v.2.201.100")
        ReDim Preserve _secure_encode_struct._wchr_versionTarget(_SD_SDK_MAX_VER_ * 2)

        Dim result As Int32 = secureEncodeMain(_secure_encode_struct)

        MsgBox("SecureENCODE(TM) Action result: " + CStr(result), vbOKOnly, "Done!")

    End Sub

    Public Sub Button_SecureDECODE_onClick(sender As Object, e As EventArgs) Handles Button_Decode.Click

        If (SourceFile_textBox.TextLength = 0) Or (TargetFile_textBox.TextLength = 0) Or (SecureDELTA_File_textBox.TextLength = 0) Then
            Error_MSG("No input files were specified!")
            Return
        End If

        Dim secureDecodeMain As SecureDelta_SecureDECODE_Main = DirectCast(Marshal.GetDelegateForFunctionPointer(SecureDECODE_FunctionHandle, GetType(SecureDelta_SecureDECODE_Main)), SecureDelta_SecureDECODE_Main)

        Dim _secure_decode_struct As SD_SDK_SecureDECODE_Struct_PARAM

        _secure_decode_struct._use_callback = 1
        _secure_decode_struct._cpu_priority_level = 0
        _secure_decode_struct._callback_p_user_data = 0
        _secure_decode_struct._callback_user_hwnd = Me.Handle
        _secure_decode_struct._callback_function = AddressOf SecureDelta_SecureDECODE_Callback_Main

        _secure_decode_struct._wchr_sourcefile_path = System.Text.Encoding.Unicode.GetBytes(SourceFile_textBox.Text)
        ReDim Preserve _secure_decode_struct._wchr_sourcefile_path(_SD_SDK_MAXPATH_ * 2)

        _secure_decode_struct._wchr_new_targetfile_path = System.Text.Encoding.Unicode.GetBytes(TargetFile_textBox.Text)
        ReDim Preserve _secure_decode_struct._wchr_new_targetfile_path(_SD_SDK_MAXPATH_ * 2)

        _secure_decode_struct._wchr_securedelta_path = System.Text.Encoding.Unicode.GetBytes(SecureDELTA_File_textBox.Text)
        ReDim Preserve _secure_decode_struct._wchr_securedelta_path(_SD_SDK_MAXPATH_ * 2)

        _secure_decode_struct._wchr_publickey_path = System.Text.Encoding.Unicode.GetBytes(PublicKey_Folder_TextBox.Text)
        ReDim Preserve _secure_decode_struct._wchr_publickey_path(_SD_SDK_MAXPATH_ * 2)

        Dim result As Int32 = secureDecodeMain(_secure_decode_struct)

        MsgBox("SecureDECODE(TM) Action result: " + CStr(result), vbOKOnly, "Done!")

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles BrowseBtn_Source.Click
        If OpenFileDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
            SourceFile_textBox.Text = OpenFileDialog1.FileName
        End If
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles BrowseBtn_Target.Click
        If OpenFileDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
            TargetFile_textBox.Text = OpenFileDialog1.FileName
        End If
    End Sub

        Private Sub VisitWebsite(sender As Object, e As EventArgs) Handles LinkLabel1.LinkClicked
            System.Diagnostics.Process.Start(DirectCast(sender, Label).Text)
        End Sub

        Private Sub OnFormLoad(sender As Object, e As EventArgs) Handles MyBase.Load

            Dim strMessage As String = ""

            ' Load SecureENCODE SDK DLL
            SecureENCODE_LibraryHandle = LoadLibrary(SecureENCODE_DLL_Path_)
            Dim lastError As Integer = Marshal.GetLastWin32Error()

            If (SecureENCODE_LibraryHandle = 0) Then
                strMessage = "SecureENCODE(TM) x86 DLL could not be loaded from current folder: " + My.Computer.FileSystem.CurrentDirectory + "\nGetLastError = " + CStr(lastError)
                MsgBox("SecureENCODE(TM) x86 DLL could not be loaded from current folder: " + My.Computer.FileSystem.CurrentDirectory, vbOKOnly, "Done!")
            Else
                strMessage = "SecureENCODE(TM) x86 DLL was loaded successfuly"
            End If

            SecureENCODE_FunctionHandle = GetProcAddress(SecureENCODE_LibraryHandle, SecureENCODE_DLL_Main_Function_)
            Dim lastErrorProc As Integer = Marshal.GetLastWin32Error()

            If (SecureENCODE_FunctionHandle = 0) Then
                strMessage += System.Environment.NewLine & "SecureENCODE(TM) x86 DLL Main Proc could not be found"
            Else                                                        
                strMessage += System.Environment.NewLine & "SecureENCODE(TM) x86 DLL Main Proc was successfuly located"
            End If

            txtBoxSecureENCODE_Status.Text = strMessage

            ' Load SecureDECODE SDK DLL
            SecureDECODE_LibraryHandle = LoadLibrary(SecureDECODE_DLL_Path_)
            lastError = Marshal.GetLastWin32Error()

            If (SecureDECODE_LibraryHandle = 0) Then
                strMessage = "SecureDECODE(TM) x86 DLL could not be loaded from current folder: " + My.Computer.FileSystem.CurrentDirectory + "\nGetLastError = " + CStr(lastError)
                MsgBox("SecureDECODE(TM) x86 DLL could not be loaded from current folder: " + My.Computer.FileSystem.CurrentDirectory, vbOKOnly, "Done!")
            Else
                strMessage = "SecureDECODE(TM) x86 DLL was loaded successfuly"
            End If

            SecureDECODE_FunctionHandle = GetProcAddress(SecureDECODE_LibraryHandle, SecureDECODE_DLL_Main_Function_)
            lastErrorProc = Marshal.GetLastWin32Error()

            If (SecureDECODE_FunctionHandle = 0) Then
                strMessage += System.Environment.NewLine & "SecureDECODE(TM) x86 DLL Main Proc could not be found"
            Else
                strMessage += System.Environment.NewLine & "SecureDECODE(TM) x86 DLL Main Proc was successfuly located"
            End If

            txtBoxSecureDECODE_Status.Text = strMessage

        End Sub

        Private Sub OnFormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
            If (SecureENCODE_LibraryHandle <> 0) Then
                FreeLibrary(SecureENCODE_LibraryHandle)
            End If
            If (SecureDECODE_LibraryHandle <> 0) Then
                FreeLibrary(SecureDECODE_LibraryHandle)
            End If
        End Sub

    Private Sub chkBox_useXtremeDELTA_Click(sender As Object, e As EventArgs) Handles chkBox_useXtremeDELTA.Click

        Dim csStrText as String = SecureDELTA_File_textBox.Text

        If csStrText.EndsWith(_XTREME_DELTA_EXT) = True Then
            csStrText = Replace(csStrText, _XTREME_DELTA_EXT, "") 
        End If

        If csStrText.EndsWith(_SECURE_DELTA_EXT) = True Then
            csStrText = Replace(csStrText, _SECURE_DELTA_EXT, "") 
        End If

        If (chkBox_useXtremeDELTA.Checked = True) Then
            csStrText += _XTREME_DELTA_EXT
        Else
            csStrText += _SECURE_DELTA_EXT
        End If

        SecureDELTA_File_textBox.Text = csStrText

    End Sub

    Private Sub BrowseBtn_PublicKEY_Click(sender As Object, e As EventArgs) Handles BrowseBtn_PublicKEY.Click
        If FolderBrowserDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
            PublicKey_Folder_TextBox.Text = FolderBrowserDialog1.SelectedPath
        End If
    End Sub

End Class