Anti Debugging

By injecting anti-debugging code into your assembly, Babel Obfuscator can take proactive measures when a debugger is attached, such as terminating the application or executing custom logic. This capability serves as a crucial defense against reverse engineering and unauthorized access to your code, safeguarding the integrity and confidentiality of your software.

Configuring Anti Debugging

To enable anti-debugging protection and configure a custom action when a debugger is detected using Babel Obfuscator, follow these steps.

Command Line

Add the --antidebugging switch to the Babel command line when obfuscating your assembly. For example:

babel myapp.exe --antidebugging

MSBuild Babel Task

If you are using the Babel task, add the DebuggingProtection="true" attribute to your configuration. For example:

<Babel InputFile="$(AppName).exe" DebuggingProtection="true" ... />

Custom Action on Debugger Detected

To customize the response when a debugger is detected inside your assembly, add the following method to an existing class to define the custom action that will be executed when a debugger is detected:

[Obfuscation(Feature = "on debugger detected method")]
static void OnDebuggerDetected()
{
    // Custom logic to be executed when a debugger is detected
    // This code must be thread-safe as it can be called by different running threads
}

When the application is executed, and a debugger is detected, the OnDebuggerDetected() method will be called. You can place your desired custom logic within this method. It is important to ensure that the code inside OnDebuggerDetected() is thread-safe since it can be called multiple times and by different threads when a debugger is detected.

Here's an example of how the code might look in a C# application:

using System;
using System.Reflection;

public class Program
{
    [Obfuscation(Feature = "on debugger detected method")]
    static void OnDebuggerDetected()
    {
        // Custom action to be executed when a debugger is detected
        Console.WriteLine("Debugger detected! Terminating application...");
        Environment.Exit(0);
    }

    static void Main()
    {
        // Your application's main logic
        // ...
    }
}

In the above example, when a debugger is detected, the application will terminate with an exit code of 0, displaying the message "Debugger detected! Terminating application..." to the console. You can replace this custom action with any behaviour you desire, such as logging, displaying an error message, or taking other defensive measures.

Last updated