8.5.2.3 SecureDELTA SDK MFC Demo Application Dlg File
8.5.2.3 SecureDELTA SDK MFC Demo App
SecureDELTA SDK MFC Demo Application Dlg file
The listing for SecureDELTA_SDK_MFC_Demo_Application_Dlg_x86.cpp
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
/////////////////////////////////////////////////////////////////////////
//
// SecureDELTA SDK - SecureDECODE MFC Demo Application Dlg
// 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 partners,
// especially NetLUP Xtreme Technologies srl
//
// INTELLECTUAL PROPERTY
// The intellectual and technical concepts contained herein are also
// proprietary to agersoftware srl and its suppliers or technological
// partners, especially 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
//
///////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "SecureDELTA_SDK_MFC_Demo_App.h"
#include "SecureDELTA_SDK_MFC_Demo_Application_Dlg_x86.h"
#define IMPORT_ENCODE_DLL_PROCEDURE_(_function_type, _mp_function_variable, _literal_function_name_) \
_mp_function_variable = (_function_type)GetProcAddress( m_hSecureDeltaDllEncode, _literal_function_name_ );\
ASSERT(_mp_function_variable != NULL);\
if (_mp_function_variable == NULL)\
{\
MessageBox(L"Exported Encode Dll function not found", L"Error", MB_OK);\
return FALSE;\
}
#define IMPORT_DECODE_DLL_PROCEDURE_(_function_type, _mp_function_variable, _literal_function_name_) \
_mp_function_variable = (_function_type)GetProcAddress( m_hSecureDeltaDllDecode, _literal_function_name_ );\
ASSERT(_mp_function_variable != NULL);\
if (_mp_function_variable == NULL)\
{\
MessageBox(L"Exported Decode Dll function not found", L"Error", MB_OK);\
return FALSE;\
}
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_ABOUTBOX };
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(IDD_ABOUTBOX)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
CSecureDELTA_SDK_MFC_DemoAppDlg::CSecureDELTA_SDK_MFC_DemoAppDlg(CWnd* pParent /*=nullptr*/)
: CDialog(IDD_MFC_SECURE_DELTA_SDK_DEMO_APP_DIALOG_x86, pParent), m_bUseXtremeEngine(0)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CSecureDELTA_SDK_MFC_DemoAppDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_PROGRESS1, m_progressCurrentBar);
DDX_Control(pDX, IDC_EDIT_INITIAL_FILE_NAME, m_edtInitialSourceFile);
DDX_Control(pDX, IDC_EDIT_TARGET_FILE_NAME, m_edtTargetFile);
DDX_Control(pDX, IDC_EDIT_SECURE_DELTA_FILE_NAME, m_edtSecureDeltaFile);
DDX_Control(pDX, IDC_CHECK_USE_XTREME_DELTA, m_chkBoxUseXtremeEngine);
DDX_Control(pDX, IDC_STATIC_ENCODE_STATUS, m_stSecureEncodeStatus);
DDX_Control(pDX, IDC_STATIC_DECODE_STATUS, m_stSecureDecodeStatus);
DDX_Control(pDX, IDC_EDIT_PUBLIC_KEY_FOLDER, m_edtPublicKeyFolder);
DDX_Control(pDX, IDC_PROGRESS2, m_progressMainBar);
}
BEGIN_MESSAGE_MAP(CSecureDELTA_SDK_MFC_DemoAppDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_ENCODE, &CSecureDELTA_SDK_MFC_DemoAppDlg::OnBnClickedButtonEncode)
ON_BN_CLICKED(IDC_BUTTON_DECODE, &CSecureDELTA_SDK_MFC_DemoAppDlg::OnBnClickedButtonDecode)
ON_BN_CLICKED(IDC_CHECK_USE_XTREME_DELTA, &CSecureDELTA_SDK_MFC_DemoAppDlg::OnBnClickedCheckUseXtremeDelta)
ON_BN_CLICKED(IDC_BUTTON_BROWSE_SOURCE, &CSecureDELTA_SDK_MFC_DemoAppDlg::OnBnClickedButtonBrowseSource)
ON_BN_CLICKED(IDC_BUTTON_BROWSE_TARGET, &CSecureDELTA_SDK_MFC_DemoAppDlg::OnBnClickedButtonBrowseTarget)
ON_BN_CLICKED(IDC_BUTTON_BROWSE_PUBLICKEY_FOLDER, &CSecureDELTA_SDK_MFC_DemoAppDlg::OnBnClickedButtonBrowsePublickeyFolder)
END_MESSAGE_MAP()
BOOL CSecureDELTA_SDK_MFC_DemoAppDlg::Load_Encode_Dll(void)
{
CString csStrSecureENCODE_Status;
// ENCODE DLL
m_hSecureDeltaDllEncode = ::LoadLibrary(SECURE_ENCODE_SDK_DLL_NAME_x86);
if (m_hSecureDeltaDllEncode == NULL)
{
csStrSecureENCODE_Status.Format(L"%s <NOT> loaded!\n", SECURE_ENCODE_SDK_DLL_NAME_x86);
}
else
{
csStrSecureENCODE_Status.Format(L"%s loaded successfuly!\n", SECURE_ENCODE_SDK_DLL_NAME_x86);
IMPORT_ENCODE_DLL_PROCEDURE_(PF_SECUREDELTA_SDK_SECUREENCODE_MAIN, m_p_Secure_Delta_DLL_Encode_Main_funct, SecureDELTA_SDK_DLL_SecureENCODE_Main_Func_)
IMPORT_ENCODE_DLL_PROCEDURE_(PF_SECUREDELTA_SDK_SECUREENCODE_DLL_GETMESSAGESTRING_FROM_ID_, m_p_Secure_Delta_DLL_Encode_Get_String_fromID_funct, SecureDELTA_SDK_DLL_SecureENCODE_GetMessage_fromID_Func_)
if (NULL != m_p_Secure_Delta_DLL_Encode_Main_funct) {
csStrSecureENCODE_Status += L"SecureENCODE DLL Main Decode function located.\n";
}
if (NULL != m_p_Secure_Delta_DLL_Encode_Get_String_fromID_funct) {
csStrSecureENCODE_Status += L"SecureENCODE DLL GetString function located.";
}
}
m_stSecureEncodeStatus.SetWindowText(csStrSecureENCODE_Status);
return TRUE;
}
BOOL CSecureDELTA_SDK_MFC_DemoAppDlg::Load_Decode_Dll(void)
{
CString csStrSecureDECODE_Status;
// DECODE DLL
m_hSecureDeltaDllDecode = ::LoadLibrary(SECURE_DECODE_SDK_DLL_NAME_x86);
if (m_hSecureDeltaDllDecode == NULL)
{
csStrSecureDECODE_Status.Format(L"%s <NOT> loaded!\n", SECURE_DECODE_SDK_DLL_NAME_x86);
}
else
{
csStrSecureDECODE_Status.Format(L"%s loaded successfuly!\n", SECURE_DECODE_SDK_DLL_NAME_x86);
IMPORT_DECODE_DLL_PROCEDURE_(PF_SECUREDELTA_SDK_SECUREDECODE_MAIN, m_p_Secure_Delta_DLL_Decode_Main_funct, SecureDELTA_SDK_DLL_SecureDECODE_Main_Func_)
IMPORT_DECODE_DLL_PROCEDURE_(PF_SECUREDELTA_SDK_SECUREDECODE_DLL_GETMESSAGESTRING_FROM_ID_, m_p_Secure_Delta_DLL_Decode_Get_String_fromID_funct, SecureDELTA_SDK_DLL_SecureDECODE_GetMessage_fromID_Func_)
if (NULL != m_p_Secure_Delta_DLL_Decode_Main_funct) {
csStrSecureDECODE_Status += L"SecureDECODE DLL Main Decode function located.\n";
}
if (NULL != m_p_Secure_Delta_DLL_Decode_Get_String_fromID_funct) {
csStrSecureDECODE_Status += L"SecureDECODE DLL GetString function located.";
}
}
m_stSecureDecodeStatus.SetWindowText(csStrSecureDECODE_Status);
return TRUE;
}
BOOL CSecureDELTA_SDK_MFC_DemoAppDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != nullptr)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically...
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
Load_Encode_Dll();
Load_Decode_Dll();
return TRUE; // return TRUE unless you set the focus to a control
}
void CSecureDELTA_SDK_MFC_DemoAppDlg::OnSysCommand(uint32_t nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CSecureDELTA_SDK_MFC_DemoAppDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this function to obtain the cursor to display while the user drags the minimized window.
HCURSOR CSecureDELTA_SDK_MFC_DemoAppDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
const SD_SDK_SECURE_ENCODE_RETURN_ID __stdcall secure_delta_encode_callback_funct(_SD_SDK_SECURE_ENCODE_CALLBACK_EVENT _cb_event, void *p_delta_encode_user_data)
{
CSecureDELTA_SDK_MFC_DemoAppDlg* pUpdaterObject = (CSecureDELTA_SDK_MFC_DemoAppDlg*)p_delta_encode_user_data;
ASSERT( pUpdaterObject && ::IsWindow( pUpdaterObject->GetSafeHwnd()));
if( pUpdaterObject && ::IsWindow( pUpdaterObject->GetSafeHwnd()))
{
pUpdaterObject->PeekMessages();
pUpdaterObject->UpdateProgress(_cb_event.dbl_operation_progress_indicator, _cb_event.uint_main_progress_indicator);
}
return SD_SDK_ENCODE_NO_ERROR_;
}
const SD_SDK_SECURE_DECODE_RETURN_ID __stdcall secure_delta_decode_callback_funct(_SD_SDK_SECURE_DECODE_CALLBACK_EVENT _cb_event, void *p_delta_decode_user_data, HWND hWnd)
{
CSecureDELTA_SDK_MFC_DemoAppDlg* pUpdaterObject = (CSecureDELTA_SDK_MFC_DemoAppDlg*)p_delta_decode_user_data;
ASSERT( pUpdaterObject && ::IsWindow( pUpdaterObject->GetSafeHwnd()));
if( pUpdaterObject && ::IsWindow( pUpdaterObject->GetSafeHwnd()))
{
pUpdaterObject->PeekMessages();
pUpdaterObject->UpdateProgress(_cb_event.dbl_operation_progress_indicator, _cb_event.uint_main_progress_indicator);
}
return SD_SDK_DECODE_NO_ERROR_;
}
void CSecureDELTA_SDK_MFC_DemoAppDlg::OnBnClickedButtonEncode()
{
wchar_t tcCurrPath_initial[_SD_SDK_MAXPATH_] = {0};
m_edtInitialSourceFile.GetWindowText(tcCurrPath_initial, _SD_SDK_MAXPATH_);
wchar_t tcCurrPath_target[_SD_SDK_MAXPATH_] = {0};
m_edtTargetFile.GetWindowText(tcCurrPath_target, _SD_SDK_MAXPATH_);
wchar_t tcCurrPath_delta[_SD_SDK_MAXPATH_] = {0};
m_edtSecureDeltaFile.GetWindowText(tcCurrPath_delta, _SD_SDK_MAXPATH_);
if(!_file_exists(tcCurrPath_initial) || !_file_exists(tcCurrPath_initial) || !_file_exists(tcCurrPath_initial)) {
MessageBox(L"File not found, please check parameters", L"Error", MB_OK);
return;
}
SD_SDK_SECURE_ENCODE_PARAMS _delta_param_struct_to_encode;
_delta_param_struct_to_encode._use_xtreme_mode = (uint8_t)m_bUseXtremeEngine;
wcsncpy_s(_delta_param_struct_to_encode._wchr_sourcefile_path, tcCurrPath_initial, _SD_SDK_MAXPATH_);
wcsncpy_s(_delta_param_struct_to_encode._wchr_targetfile_path, tcCurrPath_target, _SD_SDK_MAXPATH_);
wcsncpy_s(_delta_param_struct_to_encode._wchr_securedelta_path, tcCurrPath_delta, _SD_SDK_MAXPATH_);
wcsncpy_s(_delta_param_struct_to_encode._wchr_versionSource, L"v1.01.100", _SD_SDK_MAX_VER_);
wcsncpy_s(_delta_param_struct_to_encode._wchr_versionTarget, L"v2.00.200", _SD_SDK_MAX_VER_);
_delta_param_struct_to_encode._use_callback = 0x01;
_delta_param_struct_to_encode._callback_user_hwnd = GetSafeHwnd();
_delta_param_struct_to_encode._callback_p_user_data = this;
_delta_param_struct_to_encode._sd_sdk_secure_callback_function = (pf_secure_encode_sdk_event_cb)secure_delta_encode_callback_funct;
int32_t _dll_encode_res = (*m_p_Secure_Delta_DLL_Encode_Main_funct)(_delta_param_struct_to_encode);
CString csReturn;
csReturn.Format(_dll_encode_res == 0x00 ? L"Operation ended successfuly, retcode=%d" : L"Operation failed, retcode=%d", _dll_encode_res );
MessageBox(csReturn, L"Done!", MB_OK);
}
void CSecureDELTA_SDK_MFC_DemoAppDlg::OnBnClickedButtonDecode()
{
wchar_t tcCurrPath_initial[ _SD_SDK_MAXPATH_ ] = {0};
m_edtInitialSourceFile.GetWindowText(tcCurrPath_initial, _SD_SDK_MAXPATH_);
wchar_t tcCurrPath_target[ _SD_SDK_MAXPATH_ ] = {0};
m_edtTargetFile.GetWindowText(tcCurrPath_target, _SD_SDK_MAXPATH_);
wchar_t tcCurrPath_delta[ _SD_SDK_MAXPATH_ ] = {0};
m_edtSecureDeltaFile.GetWindowText(tcCurrPath_delta, _SD_SDK_MAXPATH_);
wchar_t tcCurrPath_publicKey[ _SD_SDK_MAXPATH_ ] = {0};
m_edtPublicKeyFolder.GetWindowText(tcCurrPath_publicKey, _SD_SDK_MAXPATH_);
if(!_file_exists(tcCurrPath_initial) || !_file_exists(tcCurrPath_initial) || !_file_exists(tcCurrPath_initial)) {
MessageBox(L"File not found, please check parameters", L"Error", MB_OK);
return;
}
SD_SDK_SECURE_DECODE_PARAMS _delta_param_struct_to_decode;
wcsncpy_s(_delta_param_struct_to_decode._wchr_securedelta_path, tcCurrPath_delta, _SD_SDK_MAXPATH_);
wcsncpy_s(_delta_param_struct_to_decode._wchr_sourcefile_path, tcCurrPath_initial, _SD_SDK_MAXPATH_);
wcsncpy_s(_delta_param_struct_to_decode._wchr_targetfile_path, tcCurrPath_target, _SD_SDK_MAXPATH_);
wcsncpy_s(_delta_param_struct_to_decode._wchr_publickey_path, tcCurrPath_publicKey, _SD_SDK_MAXPATH_);
_delta_param_struct_to_decode._use_callback = 1;
_delta_param_struct_to_decode._callback_p_user_data = this;
_delta_param_struct_to_decode._callback_user_hwnd = GetSafeHwnd();
_delta_param_struct_to_decode._sd_sdk_secure_callback_function = (pf_secure_decode_sdk_event_cb)secure_delta_decode_callback_funct;
int32_t _dll_decode_res = (*m_p_Secure_Delta_DLL_Decode_Main_funct)(_delta_param_struct_to_decode);
CString csReturn;
csReturn.Format(_dll_decode_res == 0x00 ? L"Operation ended successfuly, retcode=%d" : L"Operation failed, retcode=%d", _dll_decode_res );
MessageBox(csReturn, L"Done!", MB_OK);
}
void CSecureDELTA_SDK_MFC_DemoAppDlg::OnBnClickedCheckUseXtremeDelta()
{
m_bUseXtremeEngine = (m_chkBoxUseXtremeEngine.GetCheck() == BST_CHECKED);
}
void CSecureDELTA_SDK_MFC_DemoAppDlg::OnBnClickedButtonBrowseSource()
{
CFileDialog fileDlg(TRUE, NULL, NULL, OFN_OVERWRITEPROMPT, L"All Files(*.*)|*.*||");
int iRet = (int)fileDlg.DoModal();
CString csSourceFileName = fileDlg.GetPathName();
if (iRet == IDOK)
{
m_edtInitialSourceFile.SetWindowText(csSourceFileName);
}
}
void CSecureDELTA_SDK_MFC_DemoAppDlg::OnBnClickedButtonBrowseTarget()
{
CFileDialog fileDlg(TRUE, NULL, NULL, OFN_OVERWRITEPROMPT, L"All Files(*.*)|*.*||");
int iRet = (int)fileDlg.DoModal();
CString csTargetFileName = fileDlg.GetPathName();
if (iRet == IDOK)
{
m_edtTargetFile.SetWindowText(csTargetFileName);
m_edtSecureDeltaFile.SetWindowText(csTargetFileName + L".secureDELTA");
}
}
void CSecureDELTA_SDK_MFC_DemoAppDlg::OnBnClickedButtonBrowsePublickeyFolder()
{
CFolderPickerDialog dlgFolder;
if (dlgFolder.DoModal() == IDOK)
{
m_edtPublicKeyFolder.SetWindowText(dlgFolder.GetPathName());
}
}