Home » Support » User Manual » The Software Licensing System » Example of usage » Step #10: Read user data from serial number

Step #10: Read user data from serial number

A serial number may contain up to 255 bytes of “user” data, that can be read by protected application. You may store anything you need there. Additional information about license or order, some data that will be used by registered version etc. We’ll now change main() function, so it will read user data and print them:

int main(int argc, char **argv)
{
	char *serial = "Xserialnumber";
	int res = VMProtectSetSerialNumber(serial);
	print_state(res);
	if (res) return 0;

	VMProtectSerialNumberData sd = {0};
	VMProtectGetSerialNumberData(&sd, sizeof(sd));
	printf("Serial number has %d byte(s) of data\n", sd.nUserDataLength);
	for (int i = 0; i < sd.nUserDataLength; i++)
		printf("%02X ", sd.bUserData[i]);
	printf("\n");
	return 0;
}

Cut the INI-file to the following lines:

[TestLicense]
AcceptedSerialNumber=Xserialnumber

Run the application to see that our serial number doesn't have any user data:

state = 0
Serial number has 0 byte(s) of data

To add user data in the test mode, you need to add UserData parameter to INI-file. Value of the parameter is a HEX-string each to characters make a byte, so number of characters in the line should be even. For example, add the following line:

UserData=010203A0B0C0D0E0

Now run the application and see the bytes you put to INI-file:

state = 0
Serial number has 8 byte(s) of data
01 02 03 A0 B0 C0 D0 E0