A serial number can hold up to 255 bytes of arbitrary data that the licensing system passes to the program as-is. This data can contain any additional information about the sale, data required for the operation of the full version, or something else. Let’s modify our main() function so that it reads data from a serial number and displays it on the screen:
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;
}
We also reduce the INI file to this:
[TestLicense]
AcceptedSerialNumber=Xserialnumber
Now we run the program and make sure our serial number works correctly but does not contain any dаta:
state = 0
Serial number has 0 byte(s) of data
To add new user data to the serial number, we need to create the UserData variable in the INI file and assign data to it in HEX format. Symbols must go in pairs, meaning the length of the string must be a multiple of 2, like this:
UserData=010203A0B0C0D0E0
In this case, if we run the program, we will get the following result:
state = 0
Serial number has 8 byte(s) of data
01 02 03 A0 B0 C0 D0 E0