### Basic Registration Check (Insecure) Source: https://vmpsoft.com/vmprotect/user-manual This example shows a common but insecure way to check registration keys. An intruder can easily bypass this by modifying the function to always return true. ```pascal function CheckRegistration(const RegNumber: String): Boolean; begin if RegNumber='123' then Result:=True else Result:=False; end; procedure TForm1.Button1Click(Sender: TObject); begin ... if not CheckRegistration(RegNumber) then exit; Application.CreateForm(TForm2, Form2); Form2.ShowModal; ... end; ``` -------------------------------- ### Assembly Code Modification Example Source: https://vmpsoft.com/vmprotect/user-manual Demonstrates a malicious modification to a function's prologue, aiming to prevent virtualized code execution. This example shows how a hacker might alter the entry point. ```assembly mov eax, 1 ret ``` -------------------------------- ### Date Storage and Retrieval Example Source: https://vmpsoft.com/vmprotect/user-manual Demonstrates how to store and retrieve dates in a serial number using a double word in Little Endian format. Requires a pointer to the date address. ```c byte *pDate = 0xNNNNNN; // date address *(DWORD *)pDate = (2010 << 16) | (10 << 8) | 1; // October 1, 2010 DWORD dwExp = *(DWORD *)pDate; ``` -------------------------------- ### PJW Hashing Algorithm for Key Verification Source: https://vmpsoft.com/vmprotect/user-manual This example uses Peter Weinberger's PJW hashing algorithm to compare hashes of registration keys instead of their actual values. This makes it much harder for crackers to retrieve the original key. ```pascal var HashOfValidRegNumber: Longint; ... // Peter Weinberger's PJW hashing algorithm example of use function HashPJW(const Value: String): Longint; var I:Integer; G:Longint; begin Result:=0; for I:=1 to Length(Value) do begin Result:=(Result shl 4)+Ord(Value[I]); G:=Result and $F0000000; if G<>0 then Result:=(Result xor (G shr 24)) xor G; end; end; function CheckRegistration(const RegNumber: String): Boolean; begin if HashPJW(RegNumber)=HashOfValidRegNumber then Result:=True else Result:=False; end; ... initialization HashOfValidRegNumber:=HashPJW(ValidRegNumber); end. ``` -------------------------------- ### Assembly Function Prologue and Epilogue Source: https://vmpsoft.com/vmprotect/user-manual Illustrates the standard prologue and epilogue sequences found in assembly language functions, which handle stack frame setup and teardown. ```assembly push ebp \ mov ebp, esp \ prologue push 00 / push ebx / ... pop ebx \ pop ecx \ epilogue pop ebp / ret / ``` -------------------------------- ### Generate Serial Number with VMProtect C++ SDK Source: https://vmpsoft.com/vmprotect/user-manual This C++ code example demonstrates how to generate a serial number using the VMProtect SDK. Ensure the initial block is replaced with product-specific data generated by VMProtect. The code initializes product information, serial number details (including user name and email), generates the serial number, prints it if successful, and then frees the allocated memory. ```cpp ////////////////////////////////////////////////////////////////////////// // !!! 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; } ``` -------------------------------- ### INI File Configuration for User Data Source: https://vmpsoft.com/vmprotect/user-manual Example of configuring user data in an INI file for serial number validation. UserData must be in HEX format with an even number of characters. ```ini [TestLicense] AcceptedSerialNumber=Xserialnumber ``` ```ini UserData=010203A0B0C0D0E0 ``` -------------------------------- ### Get Current Hardware ID Source: https://vmpsoft.com/vmprotect/user-manual Obtains the hardware identifier of the PC. Call with NULL and 0 for size to get the required buffer size, then allocate memory and call again to retrieve the identifier. Remember to deallocate the memory after use. ```c int VMProtectGetCurrentHWID(char * HWID, int Size); ``` ```c int nSize = VMProtectGetCurrentHWID(NULL, 0); // get the required buffer size char *pBuf = new char[nSize]; // allocate memory for the buffer VMProtectGetCurrentHWID(pBuf, nSize); // obtain the identifier // use the identifier delete [] pBuf; // release memory ``` -------------------------------- ### PE Imports Class Source: https://vmpsoft.com/vmprotect/user-manual Provides methods to access and manage the list of imported libraries for a PE executable. Use `item` to get a specific library by index or `itemByName` to retrieve it by name. ```cpp class PEImports { public: PEImport item(int index); int count(); PEImport itemByName(string name); }; ``` -------------------------------- ### Invalid Serial Number Console Output Source: https://vmpsoft.com/vmprotect/user-manual Example console output when the provided serial number is invalid. ```text serial number is bad state = SERIAL_STATE_FLAG_INVALID ``` -------------------------------- ### MacFile Class for Mach-O Files Source: https://vmpsoft.com/vmprotect/user-manual Provides methods to access information about a Mach-O file, such as its name, format, size, and architectures. Use this class to get an overview of the file's structure. ```c++ class MacFile { public: string name(); // returns the name of the file string format(); // returns the name of the "Mach-O" format uint64 size(); // returns the size of the file int count(); // returns the number of architectures in the list MacArchitecture item(int index); // returns an architecture with the given index uint64 seek(uint64 offset); // sets the file position uint64 tell(); // returns the file position int write(string buffer); // writes a buffer to the file }; ``` -------------------------------- ### Get Offline Activation String - VMProtectGetOfflineActivationString Source: https://vmpsoft.com/vmprotect/user-manual Generates a text block for offline activation. This block should be transferred to an internet-connected computer and used in the WebLM offline activation form. Ensure the buffer size is sufficient. ```c int VMProtectGetOfflineActivationString(const char *code, char *buf, int size); ``` -------------------------------- ### Run Protected Application with Valid Serial Source: https://vmpsoft.com/vmprotect/user-manual This output demonstrates a successful run of a protected application after providing a valid serial number in serial.txt. ```bash C:\test>dummy_app.vmp.exe serial number is correct, calling foo() I'm foo done ``` -------------------------------- ### Store Registration State in Global Variable Source: https://vmpsoft.com/vmprotect/user-manual Demonstrates a basic method of storing registration state using a global variable. This approach is vulnerable to memory scanning by intruders. ```Pascal var IsRegistered: Boolean; ... procedure TForm1.Button1Click(Sender: TObject); begin ... if not IsRegistered then IsRegistered:=CheckRegistration(RegNumber); if not IsRegistered then exit; ... end; ``` -------------------------------- ### Mach-O Imported Function Details Source: https://vmpsoft.com/vmprotect/user-manual Represents an imported function within a Mach-O architecture. Get the function's address and name. ```cpp class MacImportFunction { public: uint64 address(); // returns the memory address where the address of the imported function is stored string name(); // returns the name of the imported function }; ``` -------------------------------- ### Mach-O Symbols List Source: https://vmpsoft.com/vmprotect/user-manual Provides access to the list of symbols within a Mach-O architecture. Use item() to get a specific symbol by its index. ```cpp class MacSymbols { public: MacSymbol item(int index); // returns a symbol with the given index int count(); // returns the number of symbols in the list }; ``` -------------------------------- ### Configure PHP Key Generator Source: https://vmpsoft.com/vmprotect/user-manual This section shows the configuration variables at the beginning of the PHP key generator file. These variables must be generated by VMProtect License Manager and copied accurately. ```php ////////////////////////////////////////////////////////////////////////////////////////////// // The following lines should be generated by VMProtect License Manager $exported_algorithm = "RSA"; $exported_bits = 2048; $exported_private = "PJvj4kEpoQMIpYK+9wEt......xKeiSZgzdiln8Q=="; $exported_modulus = "rOlny/3QgZb/VmGr3CmY......I6ESAUmtQ+RBqQ=="; $exported_product_code = "oLQdGUn8kVk="; ////////////////////////////////////////////////////////////////////////////////////////////// ``` -------------------------------- ### Output: Program Registered (Max Build Date Valid) Source: https://vmpsoft.com/vmprotect/user-manual This output indicates that the program is registered and the serial number is valid, as the maximum build date has not yet expired. ```text state = 0 I'm registered ``` -------------------------------- ### Configure Accepted Serial Number (INI) Source: https://vmpsoft.com/vmprotect/user-manual Create a VMProtectLicense.ini file to specify accepted serial numbers for testing. Place this file in the application's working directory. ```ini [TestLicense] AcceptedSerialNumber=Xserialnumber ``` -------------------------------- ### Include VMProtect SDK Header Source: https://vmpsoft.com/vmprotect/user-manual Include the necessary VMProtect SDK header file in your C++ project. Ensure VMProtectSDK.h, VMProtectSDK32.lib, and VMProtectSDK32.dll are in your working directory. ```cpp #include #include #include "VMProtectSDK.h" ``` -------------------------------- ### Registration Check by Direct Comparison (Insecure) Source: https://vmpsoft.com/vmprotect/user-manual This method directly compares the entered registration key with a stored valid key. A cracker can easily find the valid key by tracing the string comparison function's arguments. ```pascal var ValidRegNumber: String; ... function CheckRegistration(const RegNumber: String): Boolean; begin if RegNumber=ValidRegNumber then Result:=True else Result:=False; end; ``` -------------------------------- ### MacSegment Class for Mach-O Architecture Segment Source: https://vmpsoft.com/vmprotect/user-manual Represents a single segment within a Mach-O architecture. Use this class to get details about a segment, such as its address, name, size, and file position. ```c++ class MacSegment { public: uint64 address(); // returns the address of the segment string name(); // returns the name of the segment uint64 size(); // returns the size of the segment int physicalOffset(); // returns the file position of the segment int physicalSize(); // returns the file size of the segment int flags(); // returns flags of the segment bool excludedFromPacking(); // returns the "Excluded from packing" property }; ``` -------------------------------- ### Run Old Version with Blacklisted Serial Source: https://vmpsoft.com/vmprotect/user-manual This output shows that an older version of the protected application may still accept a serial number that has since been blacklisted. ```bash C:\test>dummy_app1.vmp.exe serial number is correct, calling foo() I'm foo done ``` -------------------------------- ### PEDirectories Class Methods Source: https://vmpsoft.com/vmprotect/user-manual Methods for interacting with PE architecture directories. ```APIDOC ## PEDirectories Class ### Description Provides methods to access and manipulate PE architecture directories. ### Methods - `PEDirectory item(int index)`: Returns a directory with the given index. - `int count()`: Returns the number of directories in the list. - `PEDirectory itemByType(int type)`: Returns a directory of the given type. ``` -------------------------------- ### Get Serial Number State Source: https://vmpsoft.com/vmprotect/user-manual Use this function to retrieve status flags for a serial number. If any flag is set, it indicates a problem with the serial number, and the program may not function correctly. ```c int VMProtectGetSerialNumberState(); ``` -------------------------------- ### VMProtect Folder Class Methods Source: https://vmpsoft.com/vmprotect/user-manual Methods for interacting with custom folders, allowing management of subfolders, retrieval of folder names, and deletion of folders and their contents. ```cpp class Folder { public: int count(); // returns the number of subfolders Folder item(int index); // returns a subfolder with the given index Folder add(string name); // adds a new subfolder string name(); // returns the name of the folder void clear(); // clears the list of subfolders void destroy(); // destroys the folder an all child subfolders }; ``` -------------------------------- ### PEDirectory Class Methods Source: https://vmpsoft.com/vmprotect/user-manual Methods for interacting with a PE architecture directory. ```APIDOC ## PEDirectory Class ### Description Provides methods to access and manipulate a PE architecture directory. ### Methods - `uint64 address()`: Returns the address of the directory. - `string name()`: Returns the name of the directory. ``` -------------------------------- ### Get Current Hardware ID in C++ Source: https://vmpsoft.com/vmprotect/user-manual Retrieves the hardware identifier of the current machine. This is necessary for hardware-locking serial numbers. The buffer size is determined first, then the identifier is read into the buffer. ```cpp 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; } ``` -------------------------------- ### PEDirectories Class for PE Directory List Source: https://vmpsoft.com/vmprotect/user-manual Manages the list of directories within a PE architecture. Provides methods to access individual directories by index or by type, and to get the total count of directories. ```c++ class PEDirectories { public: PEDirectory item(int index); // returns a directory with the given index int count(); // returns the number of directories in the list PEDirectory itemByType(int type); // returns a directory of the given type }; ``` -------------------------------- ### Create Basic C++ Application Source: https://vmpsoft.com/vmprotect/user-manual A simple C++ application demonstrating a basic serial number check. This serves as the foundation before integrating VMProtect SDK. ```cpp #include #include bool is_registered(const char *serial) { return serial && serial[0] == 'X'; } int main(int argc, char **argv) { char *serial = "Xserialnumber"; // we set the serial number directly in the code, for simplicity if (!is_registered(serial)) { printf("please register!\n"); return 0; } printf("We are registered.\n"); return 0; } ``` -------------------------------- ### PESections Class for PE Section List Source: https://vmpsoft.com/vmprotect/user-manual Manages the list of sections within a PE architecture. Provides methods to access individual sections by index or by address, and to get the total count of sections. ```c++ class PESections { public: PESection item(int index); // returns a section with the given index int count(); // returns the number of sections in the list PESection itemByAddress(uint64 address); // returns a section at the given address }; ``` -------------------------------- ### PESegments Class for PE Segment List Source: https://vmpsoft.com/vmprotect/user-manual Manages the list of segments within a PE architecture. Provides methods to access individual segments by index or by address, and to get the total count of segments. ```c++ class PESegments { public: PESegment item(int index); // returns a segment with the given index int count(); // returns the number of segments in the list PESegment itemByAddress(uint64 address); // returns the segment at the given address }; ``` -------------------------------- ### C++: Implement Max Build Date Check Source: https://vmpsoft.com/vmprotect/user-manual This C++ code snippet demonstrates how to set a serial number and check if it has expired based on the maximum build date. If expired, it prints the maximum build date and prompts the user to register. ```cpp int main(int argc, char **argv) { char *serial = "Xserialnumber"; // we set the serial number directly in the code, for simplicity int res = VMProtectSetSerialNumber(serial); print_state(res); if (res) { VMProtectSerialNumberData sd = {0}; VMProtectGetSerialNumberData(&sd, sizeof(sd)); printf("max. build date: y = %d, m = %d, d = %d\n", sd.dtMaxBuild.wYear, sd.dtMaxBuild.bMonth, sd.dtMaxBuild.bDay); printf("please register!\n"); return 0; } printf("I'm registered\n"); return 0; } ``` -------------------------------- ### MacSection Class for Mach-O Architecture Section Source: https://vmpsoft.com/vmprotect/user-manual Represents a single section within a Mach-O architecture. Use this class to get details about a section, such as its address, name, size, file position, and parent segment. ```c++ class MacSection { public: uint64 address(); // returns the address of the section string name(); // returns the name of the section uint64 size(); // returns the size of the section int offset(); // returns the file position of the section MacSegment segment(); // returns the parent segment }; ``` -------------------------------- ### VMProtect License Class Methods Source: https://vmpsoft.com/vmprotect/user-manual Provides methods to retrieve details about a specific license, such as its creation date, customer information, order reference, comments, serial number, and blocked status. ```cpp class License { public: string date(string format = "%c"); // returns the date of the license string customerName(); // returns the name of the license owner string customerEmail(); // returns an e-mail of the license owner string orderRef(); // returns the order id the license was purchased string comments(); // returns comments to the license string serialNumber(); // returns the serial number of the license bool blocked(); // returns the "Blocked" property void setBlocked(bool value); // sets the "Blocked" property } ``` -------------------------------- ### Get Offline Deactivation String - VMProtectGetOfflineDeactivationString Source: https://vmpsoft.com/vmprotect/user-manual Generates a text block for offline deactivation. This block should be transferred to an internet-connected computer and used in the WebLM offline deactivation form. Ensure the buffer size is sufficient. ```c int VMProtectGetOfflineDeactivationString(const char *serial, char *buf, int size); ``` -------------------------------- ### PEArchitecture Class Methods Source: https://vmpsoft.com/vmprotect/user-manual Methods for interacting with a PE architecture object. ```APIDOC ## PEArchitecture Class ### Description Provides methods to access and manipulate PE architecture properties. ### Methods - `string name()`: Returns the name of the architecture. - `PEFile file()`: Returns the parent file. - `uint64 entryPoint()`: Returns the starting address. - `uint64 imageBase()`: Returns the base offset. - `OperandSize cpuAddressSize()`: Returns bit count of the architecture. - `uint64 size()`: Returns the size of the architecture. - `PESegments segments()`: Returns the list of segments. - `PESections sections()`: Returns the list of sections. - `PEDirectories directories()`: Returns the list of directories. - `PEImports imports()`: Returns the list of imported libraries. - `PEExports exports()`: Returns the list of exported functions. - `PEResources resources()`: Returns the list of resources. - `PERelocs relocs()`: Returns the list of relocations (fixups). - `MapFunctions mapFunctions()`: Returns the list of functions available for protection. - `IntelFunctions functions()`: Returns the list of protected functions. - `bool addressSeek(uint64 address)`: Sets a file position. - `uint64 seek(uint64 offset)`: Sets a file position. - `uint64 tell()`: Returns a file position. - `int write(string buffer)`: Writes a buffer to a file. ``` -------------------------------- ### Run Protected Application with Blacklisted Serial Source: https://vmpsoft.com/vmprotect/user-manual This output indicates that the application rejects a serial number that has been added to the blacklist. ```bash C:\test>dummy_app.vmp.exe serial number is bad state = SERIAL_STATE_FLAG_BLACKLISTED ``` -------------------------------- ### VMProtect Console Version Command Line Source: https://vmpsoft.com/vmprotect/user-manual Use this command to protect files or projects using the VMProtect console version. Specify input and output files, project files, script files, licensing parameters, build date, and watermark name. ```bash VMProtect_Con File [Output File] [-pf Project File] [-sf Script File] [-lf Licensing Parameters File] [-bd Build Date (yyyy-mm-dd)] [-wm Watermark Name] [-we] ``` -------------------------------- ### Get Serial Number Data Source: https://vmpsoft.com/vmprotect/user-manual This function retrieves detailed information about a serial number. Ensure the provided structure size is correct and the pointer is valid to avoid errors. Returns FALSE if the licensing system is corrupted, the structure address is zero, or the size is incorrect. ```c bool VMProtectGetSerialNumberData(VMProtectSerialNumberData *Data, int Size); ``` -------------------------------- ### VMProtect Core Class Methods Source: https://vmpsoft.com/vmprotect/user-manual Methods for interacting with the VMProtect core, allowing manipulation of project settings, file names, watermarks, and project options. ```cpp class Core { public: string projectFileName(); // returns the name of the project void saveProject(); // saves the project string inputFileName(); // returns the name of the source file for the current project string outputFileName(); // returns the name of the output file for the current project void setOutputFileName(string name); // sets the name of the output file for the current project string watermarkName(); // returns the name of the watermark of the current project void setWatermarkName(string name); // sets the name of the watermark for the current project int options(); // returns options of the current project void setOptions(int options); // sets options of the current project string vmSectionName(); // returns VM segment name for the current project void setVMSectionName(); // sets VM segment name for the current project Licenses licenses(); // returns the list of licenses for the current project Files files(); // returns the list of files for the current project Watermarks watermarks(); // returns the list of watermarks PEFile/MacFile inputFile(); // returns source file PEFile/MacFile outputFile(); // returns output file PEArchitecture/MacArchitecture inputArchitecture(); // returns source architecture PEArchitecture/MacArchitecture outputArchitecture(); // returns output architecture }; ``` -------------------------------- ### OnBeforePackFile Event Handler Source: https://vmpsoft.com/vmprotect/user-manual This event is invoked before the protected file is packed. It allows modification of the file to be packed, but only if the 'Pack output file' option is enabled. ```script function OnBeforePackFile() end ``` -------------------------------- ### PEFile Class for PE File Operations Source: https://vmpsoft.com/vmprotect/user-manual Provides methods to interact with a PE file, including retrieving its name, format, size, and architecture information. It also allows for file seeking and writing. ```c++ class PEFile { public: string name(); // returns the filename string format(); // returns the "PE" format name uint64 size(); // returns the size of the file int count(); // returns the number of architectures in the list PEArchitecture item(int index); // returns an architecture with the given index uint64 seek(uint64 offset); // sets a file position uint64 tell(); // returns a file position int write(string buffer); // records a buffer to the file }; ``` -------------------------------- ### PEArchitecture Class for PE Architecture Details Source: https://vmpsoft.com/vmprotect/user-manual Represents the architecture of a PE file, offering access to its name, parent file, entry point, image base, CPU address size, and various components like segments, sections, directories, imports, exports, resources, relocations, and functions. Supports file seeking and writing. ```c++ class PEArchitecture { public: string name(); // returns the name of the architecture PEFile file(); // returns the parent file uint64 entryPoint(); // returns the starting address uint64 imageBase(); // returns the base offset OperandSize cpuAddressSize(); // returns bit count of the architecture uint64 size(); // returns the size of the architecture PESegments segments(); // returns the list of segments PESections sections(); // returns the list of sections PEDirectories directories(); // returns the list of directories PEImports imports(); // returns the list of imported libraries PEExports exports(); // returns the list of exported functions PEResources resources(); // returns the list of resources PERelocs relocs(); // returns the list of relocations (fixups); MapFunctions mapFunctions(); // returns the list of functions available for protection IntelFunctions functions(); // returns the list of protected functions bool addressSeek(uint64 address); // sets a file position uint64 seek(uint64 offset); // sets a file position uint64 tell(); // returns a file position int write(string buffer); // writes a buffer to a file }; ``` -------------------------------- ### VMProtect Folders Class Methods Source: https://vmpsoft.com/vmprotect/user-manual Provides methods for managing custom folders within a VMProtect project, including adding new folders, clearing the list, and accessing existing folders. ```cpp class Folders { public: int count(); // returns the number of folders in the list Folder item(int index); // returns a folder with the given index Folder add(string name); // adds a new folder void clear(); // clears the list }; ``` -------------------------------- ### Licenses Class Source: https://vmpsoft.com/vmprotect/user-manual Manages the list of licenses for a VMProtect project. ```APIDOC ## Licenses Class ### Description A class to work with the list of licenses. ### Methods - **keyLength()**: Returns the length of the key. - **publicExp()**: Returns the public exponent. - **privateExp()**: Returns the private exponent. - **modulus()**: Returns the modulus. - **item(int index)**: Returns a license with the given index. - **count()**: Returns the number of licenses in the list. ``` -------------------------------- ### Store Registration State in Dynamic Memory Source: https://vmpsoft.com/vmprotect/user-manual Shows how to store registration state in dynamically allocated memory to prevent easy detection by memory scanning tools. Requires dynamic memory allocation and deallocation. ```Pascal type PBoolean = ^Boolean; var IsRegistered: PBoolean; ... procedure TForm1.Button1Click(Sender: TObject); begin ... if not IsRegistered^ then IsRegistered^:=CheckRegistration(RegNumber); if not IsRegistered^ then exit; ... end; ... initialization New(IsRegistered); ``` -------------------------------- ### OnAfterCompilation Event Handler Source: https://vmpsoft.com/vmprotect/user-manual Invoked after all project objects are compiled. Provides access to the compiled project for actions like adding a digital signature. ```script function OnAfterCompilation() end ``` -------------------------------- ### Integrated Registration Check (Secure) Source: https://vmpsoft.com/vmprotect/user-manual This approach embeds the registration check directly into the main operation logic, making it harder for intruders to isolate and bypass the check. The program fails if the check is bypassed. ```pascal function CheckRegistration(const RegNumber: String): Boolean; begin if RegNumber='123' then begin Application.CreateForm(TForm2, Form2); Result:=True end else Result:=False; end; procedure TForm1.Button1Click(Sender: TObject); begin ... Form2:=nil; if not CheckRegistration(RegNumber) then exit; Form2.ShowModal; ... end; ``` -------------------------------- ### Activate License Online - VMProtectActivateLicense Source: https://vmpsoft.com/vmprotect/user-manual Passes the activation code to the server to obtain a serial number for the current computer. Ensure the provided buffer size is adequate for the serial number. ```c int VMProtectActivateLicense(const char *code, char *serial, int size); ``` -------------------------------- ### File Class Source: https://vmpsoft.com/vmprotect/user-manual Represents a single file within a VMProtect project. ```APIDOC ## File Class ### Description A class to work with a file. ### Methods - **name()**: Returns the name of the file. - **fileName()**: Returns the filename. - **options()**: Returns the options. - **setName(string name)**: Sets the name of the file. - **setFileName(string name)**: Sets the filename of the file. - **setOptions()**: Sets the options. ``` -------------------------------- ### VMProtectActivateLicense Source: https://vmpsoft.com/vmprotect/user-manual Activates a license by passing an activation code to the server and returns a unique serial number for the computer. Handles online activation. ```APIDOC ## VMProtectActivateLicense ### Description This function passes the activation code to the server and returns a serial number for this specific computer. Otherwise, an error code is returned. ### Function Signature ```c int VMProtectActivateLicense(const char *code, char *serial, int size); ``` ### Parameters - **code** (const char *) - The activation code obtained from Web License Manager. - **serial** (char *) - A memory block where the generated serial number will be stored. - **size** (int) - The size of the memory block provided for the serial number. ``` -------------------------------- ### Folders Class Source: https://vmpsoft.com/vmprotect/user-manual Manages custom folders within a VMProtect project. ```APIDOC ## Folders Class ### Description A class to work with custom folders. ### Methods - **count()**: Returns the number of folders in the list. - **item(int index)**: Returns a folder with the given index. - **add(string name)**: Adds a new folder. - **clear()**: Clears the list. ``` -------------------------------- ### VMProtectGetOfflineActivationString Source: https://vmpsoft.com/vmprotect/user-manual Generates a string required for offline activation of the license. ```APIDOC ## VMProtectGetOfflineActivationString ### Description Generates a string required for offline activation of the license. ### Method ```c int VMProtectGetOfflineActivationString(const char *SerialNumber, const char *LicenseInfo, char *Buffer, int Size); ``` ``` -------------------------------- ### VMProtect Licenses Class Methods Source: https://vmpsoft.com/vmprotect/user-manual Methods for accessing license-related information for a VMProtect project, including key length, cryptographic exponents, modulus, and license counts. ```cpp class Licenses { public: int keyLength(); // returns the length of the key string publicExp(); // returns the public exponent string privateExp(); // returns the private exponent string modulus(); // returns modulus License item(int index); // returns a license with the given index int count(); // returns the number of licenses in the list } ``` -------------------------------- ### PESection Class Methods Source: https://vmpsoft.com/vmprotect/user-manual Methods for interacting with a PE architecture section. ```APIDOC ## PESection Class ### Description Provides methods to access and manipulate a PE architecture section. ### Methods - `uint64 address()`: Returns the address of the section. - `string name()`: Returns the name of the section. - `uint64 size()`: Returns the size of the section. - `int offset()`: Returns the file positions of the section. - `PESegment segment()`: Returns the parent segment. ``` -------------------------------- ### Folder Class Source: https://vmpsoft.com/vmprotect/user-manual Represents a custom folder and its subfolders. ```APIDOC ## Folder Class ### Description A class to work with a custom folder. ### Methods - **count()**: Returns the number of subfolders. - **item(int index)**: Returns a subfolder with the given index. - **add(string name)**: Adds a new subfolder. - **name()**: Returns the name of the folder. - **clear()**: Clears the list of subfolders. - **destroy()**: Destroys the folder and all child subfolders. ``` -------------------------------- ### VMProtectBeginVirtualization Source: https://vmpsoft.com/vmprotect/user-manual Marks the beginning of a protected code area with a predefined 'virtualization' compilation type. The MarkerName parameter defines the name of the marker, and the compilation type cannot be changed later. ```APIDOC ## VMProtectBeginVirtualization ### Description Marks the beginning of a protected code area with the predefined “virtualization” compilation type. MarkerName defines the name of the marker. The compilation type of this marker cannot be changed during further work with VMProtect. ### Method ```c void VMProtectBeginVirtualization(const char *MarkerName); ``` ``` -------------------------------- ### VMProtect Files Class Methods Source: https://vmpsoft.com/vmprotect/user-manual Methods for managing the list of files associated with a VMProtect project, allowing access to individual files by index and retrieving the total count. ```cpp class Files { public: File item(int index); // returns a file with the given index int count(); // returns the number of files in the list } ``` -------------------------------- ### IntelCommandType Enum Source: https://vmpsoft.com/vmprotect/user-manual Lists all known types of Intel commands supported. ```cpp enum IntelCommandType { Unknown, Push, Pop, Mov, Add, Xor, Test, Lea, Ud0, Ret, Ssh, Crc, Call, Jmp, Fstsw, Fsqrt, Fchs, Fstcw, Fldcw, Fild, Fist, Fistp, Fld, Fstp, Fst, Fadd, Fsub, Fsubr, Fisub, Fisubr, Fdiv, Fcomp, Fmul, Repe, Repne, Rep, DB, DW, DD, DQ, Movs, Cmps, Scas, Movzx, Movsx, Inc, Dec, Les, Lds, Lfs, Lgs, Lss, Xadd, Bswap, Jxx, And, Sub, Stos, Lods, Nop, Xchg, Pushf, Popf, Sahf, Lahf, Shl, Shr, Sal, Sar, Rcl, Rcr, Rol, Ror, Shld, Shrd, Loope, Loopne, Loop, Jcxz, In, Ins, Out, Outs, Wait, Cbw, Cwde, Cdqe, Cwd, Cdq, Cqo, Clc, Stc, Cli, Sti, Cld, Std, Not, Neg, Div, Imul, Idiv, Mul, Or, Adc, Cmp, Sbb, Pusha, Popa, Clflush, Pause, Bound, Arpl, Daa, Das, Aaa, Aam, Aad, Aas, Enter, Leave, Int, Into, Iret, Set, Cmov, Addpd, Addps, Addsd, Addss, Andpd, Andps, Andnpd, Andnps, Cmppd, Cmpps, Cmpsd, Cmpss, Comisd, Comiss, Cvtdq2ps, Cvtpd2dq, Cvtdq2pd, Cvtpd2pi, Cvtps2pi, Cvtpd2ps, Cvtps2pd, Cvtpi2pd, Cvtpi2ps, Cvtps2dq, Cvtsd2si, Cvtss2si, Cvtsd2ss, Cvtss2sd, Cvttpd2pi, Cvttps2pi, Cvttpd2dq, Cvttps2dq, Cvttsd2si, Cvttss2si, Divpd, Divps, Divsd, Divss, Maxpd, Maxps, Maxsd, Maxss, Minpd, Minps, Minsd, Minss, Mulpd, Mulps, Mulsd, Mulss, Orpd, Orps, Movd, Movq, Movntq, Movapd, Movaps, Movdqa, Movdqu, Movdq2q, Movq2dq, Movhlps, Movhpd, Movhps, Movlhps, Movlpd, Movlps, Movmskpd, Movmskps, Movnti, Movntpd, Movntps, Movsd, Movss, Movupd, Movups, Pmovmskb, Psadbw, Pshufw, Pshufd, Pshuflw, Pshufhw, Psubb, Psubw, Psubd, Psubq, Psubsb, Psubsw, Psubusb, Psubusw, Paddb, Paddw, Paddd, Paddq, Paddsb, Paddsw, Paddusb, Paddusw, Pavgb, Pavgw, Pinsrw, Pextrw, Pmaxsw, Pmaxub, Pminsw, Pminub, Pmulhuw, Pmulhw, Pmullw, Pmuludq, Psllw, Pslld, Psllq, Pslldq, Psraw, Psrad, Psrlw, Psrld, Psrlq, Psrldq, Punpcklbw, Punpcklwd, Punpckldq, Punpcklqdq, Punpckhqdq, Packusdw, Pcmpgtb, Pcmpgtw, Pcmpgtd, Pcmpeqb, Pcmpeqw, Pcmpeqd, Emms, Packsswb, Packuswb, Punpckhbw, Punpckhwd, Punpckhdq, Packssdw, Pand, Pandn, Por, Pxor, Pmaddwd, Rcpps, Rcpss, Rsqrtss, Movsxd, Shufps, Shufpd, Sqrtpd, Sqrtps, Sqrtsd, Sqrtss, Subpd, Subps, Subsd, Subss, Ucomisd, Ucomiss, Unpckhpd, Unpckhps, Unpcklpd, Unpcklps, Xorpd, Xorps, Bt, Bts, Btr, Btc, Xlat, Cpuid, Rsm, Bsf, Bsr, Cmpxchg, Cmpxchg8b, Hlt, Cmc, Lgdt, Sgdt, Lidt, Sidt, Smsw, Lmsw, Invlpg, Lar, Lsl, Clts, Invd, Wbinvd, Ud2, Wrmsr, Rdtsc, Rdmsr, Rdpmc, Fcom, Fdivr, Fiadd, Fimul, Ficom, Ficomp, Fidiv, Fidivr, Faddp, Fmulp, Fsubp, Fsubrp, Fdivp, Fdivrp, Fbld, Fbstp, Ffree, Frstor, Fsave, Fucom, Fucomp, Fldenv, Fstenvm, Fxch, Fabs, Fxam, Fld1, Fldl2t, Fldl2e, Fldpi, Fldlg2, Fldln2, Fldz, Fyl2x, Fptan, Fpatan, Fxtract, Fprem1, Fdecstp, Fincstp, Fprem, Fyl2xp1, Fsincos, Frndint, Fscale, Fsin, Fcos, Ftst, Fstenv, F2xm1, Fnop, Finit, Fclex, Fcompp, Sysenter, Sysexit, Sldt, Str, Lldt, Ltr, Verr, Verw, Sfence, Lfence, Mfence, Prefetchnta, Prefetcht0, Prefetcht1, Prefetcht2, Prefetch, Prefetchw, Fxrstor, Fxsave, Ldmxcsr, Stmxcsr, Fcmovb, Fcmove, Fcmovbe, Fcmovu, Fcmovnb, Fcmovne, Fcmovnbe, Fcmovnu, Fucomi, Fcomi, Fucomip, Fcomip, Fucompp, Vmcall, Vmlaunch, Vmresume, Vmxoff, Monitor, Mwait, Xgetbv, Xsetbv, Vmrun, Vmmcall, Vmload, Vmsave, Stgi, Clgi, Skinit, Invlpga, Swapgs, Rdtscp, Syscall, Sysret, Femms, Getsec, Pshufb, Phaddw, Phaddd, Phaddsw, Pmaddubsw, Phsubw, Phsubd, Phsubsw, Psignb, Psignw, Psignd, Pmulhrsw, Pabsb, Pabsw, Pabsd, Movbe, Palignr, Rsqrtps, Vmread, Vmwrite, Svldt }; ``` -------------------------------- ### C++: Implement Runtime Limit Check Source: https://vmpsoft.com/vmprotect/user-manual This C++ code snippet demonstrates how to set a serial number, retrieve its data including running time, and pause execution for the specified duration. It also shows how to check the serial number state before and after the runtime limit. ```cpp int main(int argc, char **argv) { char *serial = "Xserialnumber"; // we set the serial number directly in the code, for simplicity int res = VMProtectSetSerialNumber(serial); print_state(res); if (res) return 0; VMProtectSerialNumberData sd = {0}; VMProtectGetSerialNumberData(&sd, sizeof(sd)); printf("I will run for %d minute(s)\n", sd.bRunningTime); print_state(VMProtectGetSerialNumberState()); Sleep(60 * 1000 * sd.bRunningTime); printf("After %d minute(s):\n", sd.bRunningTime); print_state(VMProtectGetSerialNumberState()); return 0; } ``` -------------------------------- ### Set Program Operation Time Limit Source: https://vmpsoft.com/vmprotect/user-manual Configure the maximum runtime for a program by adding 'TimeLimit=1' to the ini-file. The program then checks the status flag to manage its operation duration. ```ini TimeLimit=1 ``` -------------------------------- ### PEFile Class Methods Source: https://vmpsoft.com/vmprotect/user-manual Methods for interacting with a PE file object. ```APIDOC ## PEFile Class ### Description Provides methods to access and manipulate PE file properties. ### Methods - `string name()`: Returns the filename. - `string format()`: Returns the "PE" format name. - `uint64 size()`: Returns the size of the file. - `int count()`: Returns the number of architectures in the list. - `PEArchitecture item(int index)`: Returns an architecture with the given index. - `uint64 seek(uint64 offset)`: Sets a file position. - `uint64 tell()`: Returns a file position. - `int write(string buffer)`: Records a buffer to the file. ``` -------------------------------- ### Add Class.Foo to Virtualization Protection Source: https://vmpsoft.com/vmprotect/user-manual Adds a class member to the 'Functions For Protection' section with the 'Virtualization' compilation type. ```csharp class Class { [Obfuscation(Feature = "virtualization")] public Foo() { ... ``` -------------------------------- ### Console Output with User Data Source: https://vmpsoft.com/vmprotect/user-manual Expected console output after successfully processing a serial number with user data. ```text state = 0 Serial number has 0 byte(s) of data ``` ```text state = 0 Serial number has 8 byte(s) of data 01 02 03 A0 B0 C0 D0 E0 ``` -------------------------------- ### VMProtectBeginVirtualizationLockByKey Source: https://vmpsoft.com/vmprotect/user-manual Marks the beginning of a protected code area with the predefined 'virtualization' compilation type and the 'Lock to Serial Number' option enabled. The MarkerName parameter defines the name of the marker, and the compilation type cannot be changed later. ```APIDOC ## VMProtectBeginVirtualizationLockByKey ### Description Marks the beginning of a protected code area with the predefined “virtualization” compilation type and the enabled “Lock to Serial Number” option. MarkerName defines the name of the marker. The compilation type of this marker cannot be changed during further work with VMProtect. ### Method ```c void VMProtectBeginVirtualizationLockByKey(const char *MarkerName); ``` ``` -------------------------------- ### Mach-O Imported Libraries List Source: https://vmpsoft.com/vmprotect/user-manual Manages the list of imported libraries for a Mach-O architecture. Retrieve libraries by index or name. ```cpp class MacImports { public: MacImport item(int index); // returns an imported library with the given index int count(); // returns the number of imported libraries in the list MacImport itemByName(string name); // returns an imported library with the given name }; ``` -------------------------------- ### IntelCommand Class Source: https://vmpsoft.com/vmprotect/user-manual Provides methods to access various properties of an Intel command, such as its address, type, size, and operands. ```APIDOC ## IntelCommand Class ### Description A class to work with an Intel command, providing access to its properties and associated data. ### Methods - `uint64 address()`: returns the address of the command. - `IntelCommandType type()`: returns the type of the command. - `string text()`: returns the text representation of the command. - `int size()`: returns the size of the command. - `int dump(int index)`: returns data of the command with the given index. - `CommandLink link()`: returns the command link. - `int flags()`: returns command flags. - `IntelSegment baseSegment()`: returns the base segment. - `IntelCommandType preffix()`: returns the type of the prefix command. - `IntelOperand operand(int index)`: returns an operand with the given index. ``` -------------------------------- ### Files Class Source: https://vmpsoft.com/vmprotect/user-manual Manages the list of files associated with a VMProtect project. ```APIDOC ## Files Class ### Description A class to work with the list of files. ### Methods - **item(int index)**: Returns a file with the given index. - **count()**: Returns the number of files in the list. ``` -------------------------------- ### VMProtectBeginUltraLockByKey Source: https://vmpsoft.com/vmprotect/user-manual Marks the beginning of a protected code area with the predefined 'ultra (virtualization+mutation)' compilation type and the 'Lock to Serial Number' option enabled. The MarkerName parameter defines the name of the marker, and the compilation type cannot be changed later. ```APIDOC ## VMProtectBeginUltraLockByKey ### Description Marks the beginning of a protected code area with the predefined “ultra (virtualization+mutation)” compilation type and the enabled “Lock to Serial Number” option. MarkerName defines the name of the marker. The compilation type of this marker cannot be changed during further work with VMProtect. ### Method ```c void VMProtectBeginUltraLockByKey(const char *MarkerName); ``` ``` -------------------------------- ### .NET ObfuscationAttribute for Renaming and Virtualization Source: https://vmpsoft.com/vmprotect/user-manual Apply multiple ObfuscationAttribute instances to .NET code to control renaming and apply specific compilation types like virtualization. Ensure correct Exclude and ApplyToMembers values. ```csharp [Obfuscation(Feature = "strings", Exclude = false)] class Class { [Obfuscation(Feature = "renaming", Exclude = true)] [Obfuscation(Feature = "virtualization", Exclude = false)] public Foo() { ... ``` -------------------------------- ### IntelFunctions Class Source: https://vmpsoft.com/vmprotect/user-manual Provides methods to manage a list of Intel functions, including accessing, counting, clearing, and adding functions by address or name. ```cpp class IntelFunctions { public: IntelFunction item(int index); int count(); void clear(); IntelFunction itemByAddress(uint64 address); IntelFunction itemByName(string name); IntelFunction addByAddress(uint64 address, CompilationType type = ctVirtualization); }; ```