Step #1: Create new test application
At the first stage we created several test applications while learning the licensing system API. At this stage we’ll use a single test application. As the first one it will be console-based. We’ll add a foo() function that will work in the registered version only. The code is below:
#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;
}
// foo() is a very short function, we need to prevent it from inlining
__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;
}
Configure MSVC, so it will create MAP-file while compiling the application. It will be used by VMProtect. Run the application:
serial number is bad state = SERIAL_STATE_FLAG_INVALID
At this moment the licensing module still works in the test mode, because our application was not yet protected with VMProtect that will replace test module with the real one. At the next step we’ll create VMProtect project and try to protect our application.