At the first stage we made several simple apps to test the API of the licensing system. Now, on the second stage we'll create just one application. It will also be a console app with the foo() function working only in the registered version. Here is the code of our test application:
#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; }
Compile the program without the debug information, but in the linker settings we enable creating of the MAP-file - we will need it to work with VMProtect. After we run the program, we should see the following text:
serial number is bad state = SERIAL_STATE_FLAG_INVALID
Currently, the licensing system still works in the test mode, because the file wasn't processed by VMProtect and doesn't contain a licensing module in it. On the next step we will create a VMProtect project and will try to protect our application.