# Events

The built in script language is an efficient way to automate creation of protected applications with VMProtect. Procedures and functions required at various stages of building the protected file are invoked in certain events processed by the VMProtect core. You can set your own handlers for 5 events that are called by the VMProtect core in the following order:

- OnBeforeCompilation
- OnBeforeSaveFile
- OnBeforePackFile
- OnAfterSaveFile
- OnAfterCompilation

    function OnBeforeCompilation()

    end

This event is invoked when the list of protection objects is created. In the OnBeforeCompilation handler, you can add new procedures to the project, or modify or delete already existing ones.

    function OnBeforeSaveFile()

    end

The event is invoked before all objects created during compilation are written to the output file. In the OnBeforeSaveFile event handler you can change the file and its properties (such as the list of resources, the list of exported function, section names etc.) that are automatically written to the output file.

    function OnBeforePackFile()

    end

The event is invoked before packing the protected file of the application. With OnBeforePackFile you can modify a file that is to be packed. This event is only invoked is the "Pack output file" option is enabled.

    function OnAfterSaveFile()

    end

This event is invoked after writing all objects created during compilation to the output file. The event handler can add new data to the output file or change previously written ones.

    function OnAfterCompilation()

    end

The even is invoked after compiling all objects of the project. At this stage a user has access to the compiled project, and can perform any actions with it, like adding a digital sign (certificate).

When writing even handlers you can create your own procedures and functions. Event names are displayed with a bold font in the script editor.

© 2006-2015 Copyright VMProtect Software