Windows-version

Description

Windows key generators are DLL-files for x86 and x64 platforms, a C language header file and an MSVC-compatible lib-file. Therefore, the library can be both linked statically and loaded dynamically.

All files of the generator are located in the Keygen\DLL folder. A test application generating serial numbers is also there.

Generator API

The generator exports just two functions: the first one generates a serial number, while the second one frees up memory allocated by the first one. Let's start with the first and the main one:

VMProtectErrors __stdcall VMProtectGenerateSerialNumber(
                                VMProtectProductInfo * pProductInfo, 
                                VMProtectSerialNumberInfo * pSerialInfo, 
                                char ** pSerialNumber
                        );

The first parameter is a pointer to the VMProtectProductInfo structure, which contents are uploaded to VMProtect (see Exporting product parameters). The structure contains product private key, the algorithm used and the identifier of the product. More details on filling this structure follow below.

The second parameter is a pointer to the VMProtectSerialNumberInfo structure, which contents are moved to the generated serial number. The structure holds all fields of a serial number and a bit mask that defines which fields should be written to the serial number.

struct VMProtectSerialNumberInfo
{
        INT              flags;
        wchar_t *        pUserName;
        wchar_t *        pEMail;
        DWORD            dwExpDate;
        DWORD            dwMaxBuildDate;
        BYTE             nRunningTimeLimit;
        char *           pHardwareID;
        size_t           nUserDataLength;
        BYTE *           pUserData;
}; 

The flags field contains bit flags from the VMProtectSerialNumberFlags set described before the structure:

The third parameter is a pointer to a pointer. The address of the generated serial number is written there. After generating the serial number, it should be copied, and the address must be passed to the second API function of the generator that will free memory taken by the serial number.

void __stdcall VMProtectFreeSerialNumberMemory(char * pSerialNumber);

The VMProtectGenerateSerialNumber function returns a VMProtectErrors value that either contains 0 if the serial number is successfully generated, or an error code. Possible error codes are:

Errors can be of two categories: those caused by incorrect parameters or incorrect value of the first parameter, and all the rest. First category errors are rare and they indicate incorrect configuration of the structure. You should upload the product information again and check if the structure is filled correctly. An example of a proper filling of the structure can be found below.

Second category errors are caused by an attempt to put more data to the key than it can hold with its size. In this case we recommend to send a message to the e-commerce provider containing a text like "The key will be sent in 24 hours" instead of the actual serial number, and send all the required information to your own e-mail. In this case, the key is generated manually in VMProtect, some data are truncated to fit all crucial information to the maximum key size.

Example of usage

Below is a code example that calls the above functions and generates a serial number. Notice the block of code in the very beginning. The example will not work until you replace it with the one exported from VMProtect for your product:

//////////////////////////////////////////////////////////////////////////
// !!! this block should be generated by VMProtect !!!                 ///
//////////////////////////////////////////////////////////////////////////

VMProtectAlgorithms g_Algorithm = ALGORITHM_RSA;
size_t g_nBits = 0;
byte g_vModulus[1];
byte g_vPrivate[1];
byte g_vProductCode[1];

//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////

int _tmain(int argc, _TCHAR* argv[])
{
        VMProtectProductInfo     pi;
        pi.algorithm = g_Algorithm;
        pi.nBits = g_nBits;
        pi.nModulusSize = sizeof(g_vModulus);
        pi.pModulus = g_vModulus;
        pi.nPrivateSize = sizeof(g_vPrivate);
        pi.pPrivate = g_vPrivate;
        pi.nProductCodeSize = sizeof(g_vProductCode);
        pi.pProductCode = g_vProductCode;

        VMProtectSerialNumberInfo si = {0};
        si.flags = HAS_USER_NAME | HAS_EMAIL;
        si.pUserName = L"John Doe";
        si.pEMail = L"john@doe.com";
        char * pBuf = NULL;
        VMProtectErrors res = VMProtectGenerateSerialNumber(&pi, &si, &pBuf);
        if (res == ALL_RIGHT)
        {
                printf("Serial number:\n%s\n", pBuf);
                VMProtectFreeSerialNumberMemory(pBuf);
        }
        else
        {
                printf("Error: %d\n", res);
        }

        return 0;
} 

This is an example project for Microsoft Visual Studio from Keygen\DLL\Example. Below are the most interesting parts of the code with our comments.

First lines of the main function fill the VMProtectProductInfo structure with data, exported from VMProtect. This code is typical and it shouldn't be changed to avoid errors. Then we create the VMProtectSerialNumberInfo structure and insert a bit combination of user name and e-mail to the flag field. In the next line, we put the user name and the password to the appropriate fields in the structure. Note, values are accepted in the UNICODE encoding. The key generator will transform them to UTF-8.

Then, we initialize a pointer variable where the address of the generated key will be stored, and call VMProtectGenerateSerialNumber, then analyze the return code. If there are no errors, the generated key goes out to console, and a call to free serial number memory function is made.

The rest fields of the VMprotectSerialNumberInfo structure

Some fields of the structure may needs some additional explanations. For example, dwExpDate and dwMaxBuildDate fields contain dates in the specific format: 0xYYYYMMDD, that is, the year is stored in the high wordб while the month and the day are in the respectively high and low bytes of the low word. To produce such a number, the following macros is used: MAKEDATE(y, m, d). You can call it like this: MAKEDATE(2010, 05, 12).

The pHardwareID field should contain a pointer to a string the VMProtectGetCurrentHWID method from the licensing SDK has returned.







© 2006-2015 Copyright VMProtect Software