Home » Support » User Manual » The Software Licensing System » Example of usage » Step #3: Get state of serial number

Step #3: Get state of serial number

A function to print flags

First of all, let’s write a simple function that will print flags in human-readable format. Code of the function is below:

#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");
}

It is big, but simple. It checks flags one by one and prints those flags that are set. Now replace printf with print_state and pass a wrong serial number to the licensing module:

char *serial = "Xserialnumber1";
int res = VMProtectSetSerialNumber(serial);
print_state(res);

After running the application, you will see the following:

state = SERIAL_STATE_FLAG_INVALID
please register!

If we’ll take our “correct” serial number back, and run the application again, we should see this:

state = 0
We are registered.

Now we can see all the flags that licensing module sets, we may continue.

Getting state of serial number

There are three methods to get state of serial number: by calling VMProtectSetSerialNumber() function, VMProtectGetSerialNumberState() function or VMProtectGetSerialNumberData() function (flags will be placed to the one of the fields of structure). The first check of serial number state should be made after setting it. You should analyze returned flags and maybe terminate application immediately. This will block invalid and expired serial numbers, blocked numbers etc. If the serial number may contain running time limitations, you have to check its state periodically using the second function. The third function allows to get all information about serial number that may help to describe some of flags in state.