Step 1.9: Hardware lock
Receiving a hardware identifier
Before we lock to hardware, we must receive a hardware identifier. The identifier is put into a serial number, and when the number is passed to the licensing system, it checks if identifiers match. So, first we need to receive 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 the system thinks “test” is a hardware identifier of our PC:
HWID: test
Important! The program will display the real hardware identifier only after it is processed with VMProtect.
Hardware-locked serial number
To lock our test serial number to hardware, we should add one more line to the ini-file. This time we define the identifier that is “put into” the serial number:
KeyHWID=test
Then we complicate main() back a bit. Now it will pass a serial number and analyze the result it gets:
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 = 0
The licensing system has compared the current hardware identifier with the one written in the serial number. Identifiers are equal, so the VMProtectSetSerialNumber() function returned 0 – the serial number matches.
Now let’s try to “run” our program on another hardware. We simply change the value of the MyHWID parameter in the ini-file from “test” to “new test”. Run the program again:
HWID: new test state = SERIAL_STATE_FLAG_BAD_HWID
This time the licensing system returned the SERIAL_STATE_FLAG_BAD_HWID flag, which means the real hardware identifier and the one stored in the serial number are not matching. The current identifier we see on the screen is “new test”, while the serial number holds “test”. If we change the KeyHWID parameter in the ini-file to “new test” we can make our serial number work on this “hardware” too.