8.5.1.2.2 Main Sample File (C++)
8.5.1.2.2 SecureENCODE C++ CmdLine Sample APP
SecureENCODE C++ CmdLine Sample Application:
The listing for the main C++ sample file
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
///////////////////////////////////////////////////////////////////////
//
// SecureENCODE DLL - SecureENCODE SDK Console App Tester (C++)
// 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 <SecureEncodeSDK.h> // SecureDELTA SDK 32bit defines for SecureENCODE
#define SD_SDK_TEST_APP_TITLE L"SecureENCODE_APP_Demo(32bit)"
HMODULE h_SecureEncodeSDK_DLL_x86 = 0; // HANDLE to the DLL module.
PF_SECUREDELTA_SDK_SECUREENCODE_MAIN lpfnSecureENCODE_Dll_MainEncodeFnct = nullptr; // DLL Exported Function pointer
PF_SECUREDELTA_SDK_SECUREENCODE_DLL_GETMESSAGESTRING_FROM_ID_ lpfnSecureENCODE_Dll_Main_getString_Fnct = nullptr; // DLL Exported Function pointer
//
// Implements the callback function.
//
// event: The event param is structure of type _SD_SDK_SECURE_ENCODE_CALLBACK_EVENT
// p_delta_encode_user_data: The parameter type is void. You may pass extra context information down
// into the callback function with the use of this userdata argument.
//
// Return type is SD_SDK_SECURE_ENCODE_RETURN_ID. Defined also in SecureEncodeSDK.h
//
const SD_SDK_SECURE_ENCODE_RETURN_ID __stdcall _cmd_line_secure_callback(_SD_SDK_SECURE_ENCODE_CALLBACK_EVENT _sd_sdk_event, void *p_delta_encode_user_data)
{
if (nullptr != lpfnSecureENCODE_Dll_Main_getString_Fnct)
{
const wchar_t* _operation_name = (*lpfnSecureENCODE_Dll_Main_getString_Fnct)(_sd_sdk_event.even_param_ID);
wprintf(L"\r SecureENCODING, please wait: %-60s %3.03f%% [ Overall: %3d%% ] ", _operation_name, _sd_sdk_event.dbl_operation_progress_indicator, _sd_sdk_event.uint_main_progress_indicator);
}
else
{
// Operation description text not available...
wprintf(L"\r SecureENCODING, please wait: %3.03f%% [ Overall: %3d%% ] ", _sd_sdk_event.dbl_operation_progress_indicator, _sd_sdk_event.uint_main_progress_indicator);
}
return SD_SDK_ENCODE_NO_ERROR_;
}
//Returns the last Win32 error, in string format. Returns an empty string if there is no error.
wchar_t* _getLastErrorString()
{
static wchar_t message[256];
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
message, (sizeof(message) / sizeof(wchar_t)), NULL);
return message;
}
int32_t Load_SecureEncodeSDK_DLL()
{
h_SecureEncodeSDK_DLL_x86 = LoadLibrary(SECURE_ENCODE_SDK_DLL_NAME_x86);
if (h_SecureEncodeSDK_DLL_x86 != NULL)
{
wprintf(L"\n Successfuly loaded SecureENCODE x86 DLL {%s}", SECURE_ENCODE_SDK_DLL_NAME_x86);
return 0x00;
}
return 0x01;
}
bool unLoad_SecureEncodeSDK_DLL()
{
bool bFreeRes = FALSE;
ASSERT(h_SecureEncodeSDK_DLL_x86);
if (h_SecureEncodeSDK_DLL_x86 != NULL)
{
bFreeRes = FreeLibrary(h_SecureEncodeSDK_DLL_x86);
if (bFreeRes)
wprintf(L"\n Successfuly unloading SecureENCODE x86 DLL");
else
wprintf(L"\n unSuccessfuly unloading SecureENCODE x86 DLL");
}
wprintf(L"\nDone!\n\n\n");
return bFreeRes;
}
int wmain(int argc, wchar_t *argv[])
{
int32_t argcStart = 1;
int32_t returnVal = NO_ERROR;
wprintf_s(L"\n %s, (C) agersoftware srl, 2018-2028\n", SD_SDK_TEST_APP_TITLE);
if (argc < 4)
{
wprintf_s(L"\n USAGE:\n %s source_file new_file diff.securedelta\n\n", SD_SDK_TEST_APP_TITLE);
return 1;
}
if (NO_ERROR != Load_SecureEncodeSDK_DLL())
{
wchar_t* pstrLastErrorString = _getLastErrorString();
wprintf(L"\n Error Loading SecureENCODE DLL {%s}. GetLastError: %s\n\n", SECURE_ENCODE_SDK_DLL_NAME_x86, pstrLastErrorString ? pstrLastErrorString : L"");
return 1;
}
ASSERT(h_SecureEncodeSDK_DLL_x86);
if (!h_SecureEncodeSDK_DLL_x86)
{
return 0x01;
}
{
wchar_t _wchr_delta_file[_SD_SDK_MAXPATH_] = { 0 };
wcsncpy_s(_wchr_delta_file, argv[3], _SD_SDK_MAXPATH_);
//
// Retrieve SecureENCODE DLL function pointer...
//
lpfnSecureENCODE_Dll_MainEncodeFnct = (PF_SECUREDELTA_SDK_SECUREENCODE_MAIN)GetProcAddress(h_SecureEncodeSDK_DLL_x86, SecureDELTA_SDK_DLL_SecureENCODE_Main_Func_);
if (!lpfnSecureENCODE_Dll_MainEncodeFnct)
{
// handle the error
FreeLibrary(h_SecureEncodeSDK_DLL_x86);
return 0x02;
}
else
{
lpfnSecureENCODE_Dll_Main_getString_Fnct = (PF_SECUREDELTA_SDK_SECUREENCODE_DLL_GETMESSAGESTRING_FROM_ID_)GetProcAddress(h_SecureEncodeSDK_DLL_x86, SecureDELTA_SDK_DLL_SecureENCODE_GetMessage_fromID_Func_);
if (nullptr == lpfnSecureENCODE_Dll_Main_getString_Fnct)
{
wprintf(L"\n\n WARNING: Corrupted or tampered DLL. SecureENCODE GetString DLL was not found!\n");
}
//
// Fill in SecureENCODE SDK Param
//
SD_SDK_SECURE_ENCODE_PARAMS _sdk_secureencode_param;
_sdk_secureencode_param._use_callback = 0x01;
_sdk_secureencode_param._sd_sdk_secure_callback_function = _cmd_line_secure_callback;
_sdk_secureencode_param._callback_user_hwnd = 0x00;
_sdk_secureencode_param._use_xtreme_mode = 0x00;
wcsncpy_s(_sdk_secureencode_param._wchr_versionSource, L"v1.1", _SD_SDK_MAX_VER_);
wcsncpy_s(_sdk_secureencode_param._wchr_versionTarget, L"v1.2", _SD_SDK_MAX_VER_);
wcsncpy_s(_sdk_secureencode_param._wchr_sourcefile_path, argv[1], _SD_SDK_MAXPATH_);
wcsncpy_s(_sdk_secureencode_param._wchr_targetfile_path, argv[2], _SD_SDK_MAXPATH_);
if(_sdk_secureencode_param._use_xtreme_mode)
wcsncat_s(_wchr_delta_file, L".XtremeDELTA", _SD_SDK_MAXPATH_);
else
wcsncat_s(_wchr_delta_file, L".SecureDELTA", _SD_SDK_MAXPATH_);
wcsncpy_s(_sdk_secureencode_param._wchr_securedelta_path, _wchr_delta_file, _SD_SDK_MAXPATH_);
DWORD dwStartTime = GetTickCount();
wprintf(L"\n SecureENCODING, please wait...\n ");
//
// Call SecureENCODE Main function
//
returnVal = lpfnSecureENCODE_Dll_MainEncodeFnct(_sdk_secureencode_param);
DWORD dwEndTime = GetTickCount();
DWORD dwElapsedTime = dwEndTime - dwStartTime;
wprintf(L"\n SecureENCODE x86 Finished. Return Code: %d.\n Elapsed: %3d.%03d sec", returnVal, dwElapsedTime / 1000, dwElapsedTime % 1000);
}
}
unLoad_SecureEncodeSDK_DLL();
return 0;
}