Skip to content

Virtualizer macro

The VIRTUALIZER macro marks code for execution inside a SecureEngineĀ® Virtual Machine. When execution reaches the macro, SecureEngine takes control and emulates the original code with virtual opcodes understood only by that Virtual Machine.

VIRTUALIZER is the original generic macro name. We recommend specifying the Virtual Machine in the marker name. For example, use VIRTUALIZER_TIGER_WHITE_START/END instead of VIRTUALIZER_START/END. Select the available architectures in the Virtual Machine panel.

Use this macro whenever possible. It offers flexible and continuously improved internal protection.

Delphi Macro Usage

{$I VIRTUALIZER_TIGER_BLACK_START.inc}

// your code goes here

{$I VIRTUALIZER_TIGER_BLACK_END.inc}

C/C++ Macro Usage

VIRTUALIZER_TIGER_BLACK_START

// your code goes here

VIRTUALIZER_TIGER_BLACK_END

Visual Basic Macro Usage

Call VarPtr("VIRTUALIZER_START")

' your code goes here

Call VarPtr("VIRTUALIZER_END")

Named Macro Usage

You can assign a readable name to a VIRTUALIZER macro:

VIRTUALIZER_START_NAMED("MyDecryptFunction")

// your code goes here

VIRTUALIZER_END

A named macro works exactly like the corresponding VIRTUALIZER_START macro. Its name is displayed in the Protection Macros panel and during protection, making the macro and its associated function easier to recognize.

Every Virtual Machine family and variant also provides a named start marker. Use it with the corresponding end marker. For example:

VIRTUALIZER_TIGER_WHITE_START_NAMED("MyDecryptFunction")

// your code goes here

VIRTUALIZER_TIGER_WHITE_END

Other examples include VIRTUALIZER_FISH_RED_START_NAMED, VIRTUALIZER_PUMA_BLACK_START_NAMED, and the equivalent START_NAMED marker for every available Virtual Machine.

Pass a non-empty, NUL-terminated UTF-8 string containing 1 to 255 bytes, excluding the terminator. Control characters are not accepted. A string literal is recommended so Code Virtualizer can recover the label reliably.

Use the normal corresponding end marker. There are no END_NAMED markers.

Calls to other protected functions

A VIRTUALIZER macro protects the call instruction and parameter preparation inside its region, but it does not automatically include the body of a called function. The called function must be inlined into the region or protected separately.

When the caller and the called function are protected separately, they remain two independent virtualized regions. An out-of-line call leaves the caller's virtualized flow through the called function's normal entry point, which then redirects execution into its own virtualized code. When the called function returns, execution resumes in the caller's virtualized flow.

Both regions may use the same Virtual Machine type internally, but this does not create one continuous VM-to-VM execution flow. If eliminating the intermediate callable entry point is essential, keep the helper function inline.

See also Protect Function macro and Does a VM macro also virtualize functions called from inside it?.

Remarks

Consider the following restrictions when choosing where to insert a VIRTUALIZER macro:

  • Avoid tight loops with many iterations inside a VIRTUALIZER macro. For code that runs many times per second, use a lighter architecture such as VIRTUALIZER_TIGER_WHITE or do not virtualize it.

  • When protecting a switch/case statement or a try/except block, place the start marker before the complete block and the end marker after it.