Home » Support » User Manual » Using scripts » Built-in functions

Built-in functions

Besides methods and properties of classes available in the scripting language, the user of VMProtect can use functions making it possible to perform some basic operations. Among these functions there are both system functions allowing work with strings, dates and numbers, use of the command-line version of the program, display of various messages, and specialized functions allowing work with the VMProtect kernel and watermarks:

function VMProtector: TVMProtector;

Returns the instance of the TVMProtector class, which is the main object of the VMProtect kernel.

function Watermarks: TWatermarks;

Returns the instance of the TWatermarks class, which is the object for working with watermarks.

procedure Writeln(const S: String);

Writeln displays a text message in the script message window.

function ParamCount: Integer;

Returns the number of parameters passed to the program in the command line. The parameters are separated by spaces or tab characters. Double quotation marks put separate words together in one parameter (for example, long file names with spaces).

function ParamStr(Index: Integer): String;

Returns the parameter of the command line corresponding to the parameter with the Index number or an empty string if Index is larger than ParamCount. For example, if Index equals 2, the result of the function will be the second parameter in the command line. ParamStr(0) returns the path and name of the running program file (for example, C:\TEST\MYPROG.EXE).

function ChangeFileExt(const FileName, Extension: String): String;

Used to change the extension of the file passed in the FileName parameter for the extension passed in the Extension parameter. The ChangeFileExt function does not rename the source file, but only returns a string with the new file name.

function Random(Range: Integer): Integer;

Returns a random number within the following range: 0 <= X < Range.

function MsgBox(const Text, Caption: String; Flags: Integer): Integer;

Used to display a message dialog box with one or several buttons.

  • Text – message text, no 255-character length limitation. Long messages are automatically arranged in the dialog box.
  • Caption – dialog box title. The title may be longer than 255 characters, but is not arranged. A long title results in a wide message dialog box.
  • Flags – a set of bits determining the content and behavior of the dialog box. This parameter can be a combination of flags from the following groups:

    Dialog box button flag:

    MB_ABORTRETRYIGNORE The dialog box has three buttons: Abort, Retry and Ignore.
    MB_OK The dialog box has one button: OK. This is the default flag.
    MB_OKCANCEL The dialog box has two buttons: OK and Cancel.
    MB_RETRYCANCEL The dialog box has two buttons: Retry and Cancel.
    MB_YESNO The dialog box has two buttons: Yes and No.
    MB_YESNOCANCEL The dialog box has three buttons: Yes, No and Cancel.


    Dialog box icon flag:

    MB_ICONEXCLAMATION The dialog box shows the exclamation mark icon.
    MB_ICONINFORMATION The dialog box shows the "i" letter icon.
    MB_ICONQUESTION The dialog box shows the question mark icon.
    MB_ICONHAND The dialog box shows the Stop sign icon.


    Default button flags:

    MB_DEFBUTTON1 The first button is the default one. MB_DEFBUTTON1 is the default value unlike MB_DEFBUTTON2, MB_DEFBUTTON3 or MB_DEFBUTTON4 given below.
    MB_DEFBUTTON2 The second button is the default one.
    MB_DEFBUTTON3 The third button is the default one.
    MB_DEFBUTTON4 The forth button is the default one.


  • Return value
    0 Not enough memory to create a dialog box.
    IDOK The user clicked the OK button.
    IDCANCEL The user clicked the Cancel button.
    IDABORT The user clicked the Abort button.
    IDRETRY The user clicked the Retry button.
    IDIGNORE The user clicked the Ignore button.
    IDYES The user clicked the Yes button.
    IDNO The user clicked the Yes button.
function CompareText(const S1, S2: String): Integer;

Compares S1 and S2 and returns 0 if they are equal. If S1 is greater than S2, the function returns an integer larger than 0. If S1 is less than S2, CompareText returns an integer less than 0. The CompareText function is case-insensitive and its result does not depend on the current Windows locale.

function AnsiCompareText(const S1, S2: String): Integer;

Compares S1 and S2, case-insensitive. The result of the comparison operation depends on the current Windows locale. AnsiCompareText returns a value less than 0 if S1 < S2, a value greater than 0 if S1 > S2 and 0 if S1 = S2.

function Format(const Format: String; const Args: array of const): String;

Allows conversion of several items in an open array of arguments according to the instructions of the formatting string. Constants and/or variables of the integer or real-valued type, strings and pointers can be items in the array of arguments.

Format – the formatting string which is any string where you can insert the formatting specifier. The number of formatting specifiers must not be greater than the number of items in the Args array of arguments. During the operation of the function, every item from the array of arguments is put into the formatting string according to the sequence of formatting specifiers: the first specifier for the first argument, the second specifier for the second argument and so on. If the number of specifiers is less than the number of arguments, ‘extra’ arguments are ignored.

A formatting specifier always starts with the percent character and generally has the following structure (optional elements are enclosed in square brackets):

"%" [index ":"] ["-"] [width] ["." prec] type
  • index ":" – the index of the open array, this parameter can be used to explicitly specify the argument the specifier will process;
  • "-" defines if it is necessary to align the text formatted by the specifier to the left border of the area allocated for it;
  • width – the number defining the number of characters in the text processed by the specifier; if this number is less than the required number, this specifier parameter is ignored. If it is larger, the necessary number of spaces is added to the right side (if the "-" element is specified) or to the left side (if it is absent);
  • "." prec – defines the precision of integer and real-valued types;
  • type – the character defining the formatting type:

    d Whole decimal number. If the prec parameter is specified, its symbolic representation must contain at least prec digits after the point: if the symbolic representation has fewer digits, the 0 characters are added to the left of it, if it has more digits, the prec parameter is ignored. If the argument is not a whole number, an exception occurs.
    u Unsigned integer. It is used similarly to the d type, but the formatting result will be an unsigned integer.
    e Real-valued number in the exponential representation. The symbolic representation looks like -d, dddddddddddE+ddd. If the number is positive, the leading minus is dropped. If its modulus is less than 1, the plus sign is changed to minus. It always contains one digit in the integral part, at least one digit in the fractional part and not less than three digits of the decimal exponent. If the precision parameter is specified, it defines the total number of digits before the ? character, but not less than two: if the precision parameter equals to 1 or 0, it is changed for 2. If the symbolic representation contains more characters than prec, it is approximated according to the first dropped digit. The default value of the precision parameter is 15.
    f Real-value number in the form of -ddd, ddd (fixed representation). The precision parameter (2 by default) defines the number of digits in the fractional part. If it equals 0, only the intergral part of the number is displayed.
    g Real-valued number in the shortest possible representation (exponential or fixed). The precision parameter (15 by default) defines the largest possible number of significant positions. If the number has fewer digits, it is not completed to prec and if the number has no decimal part, it is displayed as an integer (without a decimal point).
    n Corresponds to the fixed representation, but uses the digit grouping symbol.
    m Real-valued number in the money representation. Similar to the n type, but the currency sign is added to the right.
    p Displays the content of the pointer in the form of 8 hexadecimal digits.
    s The argument must be a character, a string or a string with a trailing zero. If the precision parameter is specified, it defines the longest possible string: if the string is longer, it is trimmed. If it is shorter, the precision parameter is ignored.
    x Integer in the hexadecimal representation. The precision parameter determines the fewest possible number of hexadecimal digits (if the number is smaller, leading zeros are added to it).

The function is insensitive to the case of formatting characters. The index, prec and width parameters are specified explicitly (by numbers in the formatting string) or implicitly (with the "*" character). In this case, the value of the next argument in the list of arguments (it must be an integer) is taken as a parameter.

function Now: TDateTime;

Returns the current date and time.

function Time: TDateTime;

Returns the current time.

function DateTimeToStr(DateTime: TDateTime): String;

Converts the DateTime value into a formatted data and time string.

function TimeToStr(Time: TDateTime ): String;

Converts the Time value into a formatted time string.