Get Demo
  • Windows
  • MacOS
  • Linux

Step 1.9: Hardware lock

Receiving a hardware identifier

Before we lock to hardware, we must obtain a hardware identifier. The identifier is stored in a serial number, and when the number is passed to the licensing system, it checks whether the identifiers match. So, first we need to retrieve the identifier of our hardware. Let’s reduce the main() function to the bare minimum:

int main(int argc, char **argv)
{
    int nSize = VMProtectGetCurrentHWID(NULL, 0);
    char *buf = new char[nSize];
    VMProtectGetCurrentHWID(buf, nSize);
    printf("HWID: %s\n", buf);
    delete [] buf;
    return 0;
}

By running the program, we receive a default test hardware identifier:

HWID: myhwid

To change the identifier, add the following line to the INI file:

MyHWID=test

If we run the program afterwards, we can see that the system treats “test” as the hardware identifier of our PC:

HWID: test

Important

The program will display the real hardware identifier only after it has been processed with VMProtect.

Hardware-locked serial number

To lock our test serial number to hardware, we need to add one more line to the INI file. This time we define the identifier that is “stored” in the serial number:

KeyHWID=test

Then we slightly expand main() again. Now it will pass a serial number and analyze the result it receives:

int main(int argc, char **argv)
{
    int nSize = VMProtectGetCurrentHWID(NULL, 0);
    char *buf = new char[nSize];
    VMProtectGetCurrentHWID(buf, nSize);
    printf("HWID: %s\n", buf);
    delete [] buf;
    char *serial = "Xserialnumber";
    int res = VMProtectSetSerialNumber(serial);
    print_state(res);
    return 0;
}

After running the code, we will see the following result:

HWID: test
state = SERIAL_STATE_SUCCESS

The licensing system has compared the current hardware identifier with the one stored in the serial number. Since the identifiers match, the VMProtectSetSerialNumber() function returns SERIAL_STATE_SUCCESS — meaning the serial number is valid.

Now let’s try to “run” our program on different hardware. We simply change the value of the MyHWID parameter in the INI file from “test” to “new test”. Then we run the program again:

HWID: new test
state = SERIAL_STATE_FLAG_BAD_HWID

This time the licensing system returns the SERIAL_STATE_FLAG_BAD_HWID flag, which means the current hardware identifier and the one stored in the serial number do not match. The identifier we see on the screen is “new test”, while the serial number contains “test”. If we change the KeyHWID parameter in the INI file to “new test”, the same serial number will work on this “hardware” as well.

Last updated 11 days ago