步驟 2.1:創建新的受保護應用程序
VMProtect是新一代軟件保護實用程序。VMProtect支持德爾菲、Borland C Builder、Visual C/C++、Visual Basic(本機)、Virtual Pascal和XCode編譯器。
同時,VMProtect有一個內置的反匯編程序,可以與Windows和Mac OS X可執行文件一起使用,并且還可以鏈接編譯器創建的MAP文件,以快速選擇要保護的代碼片段。 為了輕松實現應用程序保護任務的自動化,VMProtect實現了內置腳本語言。VMProtect完全支持Windows系列的32/64位操作系統(從Windows 2000開始)和Mac OSX(從版本10.6開始)。重要的是,無論目標平臺如何,VMProtect都支持所有范圍的可執行文件,即Windows版本可以處理Mac OS X版本的文件,反之亦然。
加密解密技術交流群(766135708)
在第一階段,我們制作了幾個簡單的應用程序來測試許可系統的 API。現在,在第二階段,我們將只創建一個應用程序。它還將是一個控制臺應用程序,其foo()函數僅在注冊版本中有效。這是我們的測試應用程序的代碼:
#include <windows.h> #include <stdio.h> #include "VMProtectSDK.h" #define PRINT_HELPER(state, flag) if (state & flag) printf("%s ", #flag) void print_state(INT state) { if (state == 0) { printf("state = 0\n"); return; } printf("state = "); PRINT_HELPER(state, SERIAL_STATE_FLAG_CORRUPTED); PRINT_HELPER(state, SERIAL_STATE_FLAG_INVALID); PRINT_HELPER(state, SERIAL_STATE_FLAG_BLACKLISTED); PRINT_HELPER(state, SERIAL_STATE_FLAG_DATE_EXPIRED); PRINT_HELPER(state, SERIAL_STATE_FLAG_RUNNING_TIME_OVER); PRINT_HELPER(state, SERIAL_STATE_FLAG_BAD_HWID); PRINT_HELPER(state, SERIAL_STATE_FLAG_MAX_BUILD_EXPIRED); printf("\n"); } char *read_serial(const char *fname) { FILE *f; if (0 != fopen_s(&f, fname, "rb")) return NULL; fseek(f, 0, SEEK_END); int s = ftell(f); fseek(f, 0, SEEK_SET); char *buf = new char[s + 1]; fread(buf, s, 1, f); buf[s] = 0; fclose(f); return buf; } // The foo() method is very short, but we need it to be an individual function // so we asked the compiler to not compile it inline __declspec(noinline) void foo() { printf("I'm foo!\n"); } int main(int argc, char **argv) { char *serial = read_serial("serial.txt"); int res = VMProtectSetSerialNumber(serial); delete [] serial; if (res) { printf("serial number is bad\n"); print_state(res); return 0; } printf("serial number is correct, calling foo()\n"); foo(); printf("done\n"); return 0; }
在沒有調試信息的情況下編譯程序,但在鏈接器設置中我們啟用了 MAP 文件的創建——我們將需要它與 VMProtect 一起工作。運行程序后,我們可以看到以下文本:
serial number is bad state = SERIAL_STATE_FLAG_INVALID
目前,許可系統仍在測試模式下運行,因為該文件未經過 VMProtect 處理,并且其中不包含許可模塊。在下一步中,我們將創建一個 VMProtect 項目并嘗試保護我們的應用程序。