步驟 1.2:添加許可證檢查代碼
VMProtect 是保護應用程序代碼免遭分析和破解的可靠工具,但只有在正確構建應用程序內保護機制并且沒有可能破壞整個保護的典型錯誤的情況下才能最有效地使用。
VMProtect 是保護應用程序代碼免遭分析和破解的可靠工具,但只有在正確構建應用程序內保護機制并且沒有可能破壞整個保護的典型錯誤的情況下才能最有效地使用。
如果您以前沒有這樣做,是時候將 VMProtect SDK 包含到您的項目中了。SDK包含三個文件:頭文件(VMProtectSDK.h)、庫文件(VMProtectSDK32.lib)和帶實現的dll文件(VMProtectSDK32.dll)。對于 64 位系統,庫和 dll 文件有單獨的實現。
將 dll 文件、頭文件和庫文件放入我們應用程序的工作文件夾中,源文件所在的位置,并將頭文件包含到主文件中:
#include <windows.h> #include <stdio.h> #include "VMProtectSDK.h"
構建項目并確保它像以前一樣編譯和運行。許可系統尚未激活。
將序列號發送到許可系統
現在,在序列號行的正下方,我們添加對許可系統的 SDK 函數的調用:
char *serial = "Xserialnumber"; // we set the serial number directly in the code, for simplicity int res = VMProtectSetSerialNumber(serial); printf("res = 0x%08X\n", res);
如果執行此操作后程序停止并提示缺少所需的 dll 文件,請確保將相應的 DLL 文件放入我們應用程序的工作文件夾中。如果執行成功,您應該會看到以下消息:
2 對應于API 中描述的SERIAL_STATE_FLAG_INVALID 標志。這意味著許可系統認為我們的密鑰不正確,這是真的,因為我們沒有向系統“解釋”哪些密鑰是正確的,哪些不是。
[TestLicense] AcceptedSerialNumber=Xserialnumber
現在,再次運行我們的程序。如果您仍然收到“2”錯誤代碼,請確保 ini 文件位于應用程序的工作文件夾中。這次我們應該收到“0”。這是許可系統接受并批準序列號的標志。現在我們可以從代碼中刪除is_registered()函數——許可系統現在負責檢查序列號:
#include <windows.h> #include <stdio.h> #include "VMProtectSDK.h" int main(int argc, char **argv) { char *serial = "Xserialnumber"; // we set the serial number directly in the code, for simplicity int res = VMProtectSetSerialNumber(serial); printf("res = 0x%08X\n", res); if (res) { printf("please register!\n"); return 0; } printf("We are registered.\n"); return 0; }