Home » Support » User Manual » The Software Licensing System » Example of usage » Licensing module API

Licensing module API

Licensing module API is a part of VMPortect API and located in its SDK. API allows to set serial number, read its state and detailed information. API also allows to obtain hardware identifier of current computer to lock serial numbers to it.

VMProtectSetSerialNumber

Function passes serial number to the licensing module. Full specification follows:

INT __stdcall VMProtectSetSerialNumber(const char *SerialNumber);

Parameter SerialNumber should contain text string with serial number generated by VMProtect or by standalone generator. Serial number
is base-64-encoded string, terminated by ‘\0′. Function returns set of bit flags, like the VMProtectGetSerialNumberState() does. Flags show if serial
number is correct or invalid and describe why. If serial number is correct, function returns 0.



VMProtectGetSerialNumberState

Function returns state of serial number, set by VMProtectSetSerialNumber() call. Full specification is simple:

INT __stdcall VMProtectGetSerialNumberState();

If at least one bit of returned value is set – key is invalid and application should terminate or fall back to the demo mode. Below is a description of possible flags:

Flag Value Description
SERIAL_STATE_FLAG_CORRUPTED 0×00000001 Licensing module is corrupted. This may be caused by cracking attempts. Usually you will never get this flag.
SERIAL_STATE_FLAG_INVALID 0×00000002 Serial number is invalid. You will get this flag if licensing module will be unable to decrypt serial number of if the serial number is not yet set or it is empty.
SERIAL_STATE_FLAG_BLACKLISTED 0×00000004 Serial number is correct, but it was blacklisted in VMProtect.
SERIAL_STATE_FLAG_DATE_EXPIRED 0×00000008 Serial number is expired. You will get this flag if serial number has expiration date chunk and this date is in the past. You may read the expiration date by calling VMProtectGetSerialNumberData() function.
SERIAL_STATE_FLAG_RUNNING_TIME_OVER 0×00000010 Running time limit for this session is over. You may read limit value by calling VMProtectGetSerialNumberData() function.
SERIAL_STATE_FLAG_BAD_HWID 0×00000020 Serial number is locked to another hardware identifier.
SERIAL_STATE_FLAG_MAX_BUILD_EXPIRED 0×00000040 Serial number will not work with this version of application, because it has “Max Build Date” block and the application was build after those date. You may read maximal build date by calling VMProtectGetSerialNumberData() function.


VMProtectGetSerialNumberData

Function reads content of serial number to the structure. Full specification follows:

BOOL __stdcall VMProtectGetSerialNumberData(VMProtectSerialNumberData *pData, UINT nSize);

The first parameter is a pointer to VMProtectSerialNumberData structure, that will receive all the information. The second parameter is a size of the structure.
Function returns FALSE if licensing module is corrupted or if the structure or its size is invalid. Otherwise it returns TRUE and you may analyze its fields:

Field Type Description
nState INT Serial number bit mask. Exactly as returned by VMProtectGetSerialNumberState().
wUserName wchar_t[256] User name in UNICODE with terminating ‘\0′.
wEMail wchar_t[256] E-Mail in UNICODE with terminating ‘\0′.
dtExpire VMProtectDate Serial number expiration date. Format of VMProtectDate stucture is described below.
dtMaxBuild VMProtectDate Maximal date of product build that will accept the serial number. Format of VMProtectDate structure is described below.
bRunningTime INT Number of minutes that the application is allowed to work.
nUserDataLength BYTE Length of user data, stored in bUserData field.
bUserData BYTE[255] User data, stored in serial number. Length of actual data is stored in nUserDataLength field.


VMProtectDate structure has the following fields:

Field Type Description
wYear WORD Year.
bMonth BYTE Month, starting from 1.
bDay BYTE Day, starting from 1.




VMProtectGetCurrentHWID

Function allows to get hardware identifier of current computer. Full specification follows:

INT __stdcall VMProtectGetCurrentHWID(char * HWID, UINT nSize);

The first parameter is a pointer to a memory that will receive identifier. The second parameter is a size of that memory. Function returns number of bytes with terminating ‘\0′. If the first parameter is NULL, function will return number of required bytes. The most correct way to call the function is here:

INT nSize = VMProtectGetCurrentHWID(NULL, 0); // get number of required bytes
char *pBuf = new char[nSize]; // allocate buffer
VMProtectGetCurrentHWID(pBuf, nSize); // obtain hardeare identifier
// use it
delete [] pBuf; // release buffer