8.5.1.1.3 SecureDECODE C++ CmdLine Sample APP


   SecureDECODE 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
212
213
214
215
216
217
218
219
220
221
222

//                                                                     
// SecureDECODE DLL - SecureDECODE SDK Console App Tester (C++)        
// Part of SecureDELTA SDK (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 technological partner,                     
// NetLUP Xtreme Technologies srl                                      
//                                                                     
// INTELLECTUAL PROPERTY                                               
// The intellectual and technical concepts contained herein are also   
// proprietary to agersoftware srl and its 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 its 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 "framework.h"
#include <SecureDecodeSDK.h>  // SecureDELTA SDK defines for SecureDECODE

#define SD_SDK_TEST_APP_TITLE  L"SecureDECODE_APP_Demo(32bit)"

HMODULE h_SecureDecodeSDK_DLL_Handler_x86 = 0;
PF_SECUREDELTA_SDK_SECUREDECODE_MAIN lpfnSecureDECODE_Dll_MainDecodeFnct = nullptr;    // Function pointer
PF_SECUREDELTA_SDK_SECUREDECODE_DLL_GETMESSAGESTRING_FROM_ID_ lpfnSecureDECODE_Dll_Main_getString_Fnct = nullptr;    // DLL Exported Function pointer


/**
 * @brief Implements the callback function.
 *
 * @param event The event param is of type _CB_SD_SECURE_DECODE_EVENT
 *
 * @param p_delta_decode_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 The return type is SD_SDK_RETURN_ID. Defined also in SecureDecodeSDK.h
 *
 */

const SD_SDK_SECURE_DECODE_RETURN_ID __stdcall _secure_decode_callback(_SD_SDK_SECURE_DECODE_CALLBACK_EVENT _sd_sdk_event, void *p_delta_encode_user_data, HWND _caller_HWND)
{
    if (NULL != lpfnSecureDECODE_Dll_Main_getString_Fnct)
    {
        const wchar_t* _operation_name = (*lpfnSecureDECODE_Dll_Main_getString_Fnct)(_sd_sdk_event.even_param_ID);
        wprintf(L"\r %-s %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 SecureDECODING, please wait: %3.03f%% [ Overall: %3d%% ]    ", _sd_sdk_event.dbl_operation_progress_indicator, _sd_sdk_event.uint_main_progress_indicator);
    }
    return SD_SDK_DECODE_NO_ERROR_;
}

/**
 * @brief Retrieves the calling thread's last-error code value into a const wide char string
 *
 * @param no parameters. uses GetLastError()
 *
 * @return Returns the last Win32 error, in string format. Returns an empty string if there is no error.
 *
 */
const 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;
}

/**
 * @brief Load SecureDecodeSDK DLL
 *
 * @param no parameters. uses the constant SECURE_DECODE_SDK_DLL_NAME_x86
 *
 * @return Loads the DLL that implemented SecureDECODE function.
 *
 */
int32_t Load_SecureDecodeSDK_DLL()
{
    h_SecureDecodeSDK_DLL_Handler_x86 = LoadLibrary(SECURE_DECODE_SDK_DLL_NAME_x86);
    if (h_SecureDecodeSDK_DLL_Handler_x86 != NULL)
    {
        wprintf(L"\n Successfuly loaded SecureDECODE x86 DLL {%s}", SECURE_DECODE_SDK_DLL_NAME_x86);
        return 0x00;
    }

    return 0x01;
}

/**
 * @brief UnLoads/Frees SecureDecodeSDK DLL
 *
 * @param no parameters. uses the constant SECURE_DECODE_SDK_DLL_NAME_x86
 *
 * @return UnLoads/Frees the DLL that implemented SecureDECODE function.
 *
 */
bool unLoad_SecureDecodeSDK_DLL()
{
    bool fFreeRes = FALSE;
    ASSERT(h_SecureDecodeSDK_DLL_Handler_x86);
    if (h_SecureDecodeSDK_DLL_Handler_x86 != NULL)
    {
        fFreeRes = FreeLibrary(h_SecureDecodeSDK_DLL_Handler_x86);
        if (fFreeRes)
            wprintf(L"\n Successfuly unloaded SecureDECODE x86 DLL\n");
        else
            wprintf(L"\n Unsuccessfuly unloaded SecureDECODE x86 DLL\n");
    }
    return fFreeRes;
}

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 diff.securedelta new_file [publicKey_folder]\n\n", SD_SDK_TEST_APP_TITLE);
        return 1;
    }    

    if (NO_ERROR != Load_SecureDecodeSDK_DLL())
    {
        const wchar_t* pstrLastErrorString = _getLastErrorString();
        wprintf(L"\n Error Loading SecureDECODE x86 DLL {%s}. GetLastError: %s\n\n", SECURE_DECODE_SDK_DLL_NAME_x86, pstrLastErrorString ? pstrLastErrorString : L"");
        return 1;
    }

    //
    // Retrieve SecureDECODE DLL function pointer...
    //
    ASSERT(h_SecureDecodeSDK_DLL_Handler_x86);
    if (!h_SecureDecodeSDK_DLL_Handler_x86)
    {
        return 0x01;
    }

    {
        lpfnSecureDECODE_Dll_MainDecodeFnct = (PF_SECUREDELTA_SDK_SECUREDECODE_MAIN)GetProcAddress(h_SecureDecodeSDK_DLL_Handler_x86, SecureDELTA_SDK_DLL_SecureDECODE_Main_Func_);
        if (!lpfnSecureDECODE_Dll_MainDecodeFnct)
        {
            // handle the error
            FreeLibrary(h_SecureDecodeSDK_DLL_Handler_x86);
            return 0x02;
        }
        else
        {
            lpfnSecureDECODE_Dll_Main_getString_Fnct = (PF_SECUREDELTA_SDK_SECUREDECODE_DLL_GETMESSAGESTRING_FROM_ID_)GetProcAddress(h_SecureDecodeSDK_DLL_Handler_x86, SecureDELTA_SDK_DLL_SecureDECODE_GetMessage_fromID_Func_);
            if (nullptr == lpfnSecureDECODE_Dll_Main_getString_Fnct)
            {
                wprintf(L"\n\n WARNING: Corrupted or tampered DLL. SecureDECODE GetString DLL was not found!\n");
            }

            // call SecureDECODE Main function
            SD_SDK_SECURE_DECODE_PARAMS _sdk_securedecode_param;

            _sdk_securedecode_param._use_callback = 0x01;
            _sdk_securedecode_param._sd_sdk_secure_callback_function = _secure_decode_callback;
    
            wcsncpy_s(_sdk_securedecode_param._wchr_sourcefile_path, argv[1], _SD_SDK_MAXPATH_); 
            wcsncpy_s(_sdk_securedecode_param._wchr_securedelta_path, argv[2], _SD_SDK_MAXPATH_);
            wcsncpy_s(_sdk_securedecode_param._wchr_targetfile_path, argv[3], _SD_SDK_MAXPATH_);

            if (argc > 4) {
                wcsncpy_s(_sdk_securedecode_param._wchr_publickey_path, argv[4], _SD_SDK_MAXPATH_);
            }

            DWORD dwStartTime = GetTickCount();
            
            returnVal = lpfnSecureDECODE_Dll_MainDecodeFnct(_sdk_securedecode_param);
            
            DWORD dwEndTime = GetTickCount();
            DWORD dwElapsedTime = dwEndTime - dwStartTime;

            wprintf(L"\n SecureDECODE x86 Finished. Return Code: %d.\n Elapsed: %3d.%03d sec", returnVal, dwElapsedTime/1000, dwElapsedTime%1000);
        }
    }

    unLoad_SecureDecodeSDK_DLL();

    return 0;
}