Babel Obfuscator
HomeDocumentationShop
  • Introduction
    • General Features
  • Getting Started
    • Install
    • Product Activation
  • Command Line
    • Command Line Reference
      • Miscellaneous
      • Input Files
      • Output Files
      • Plugins
      • Merge and Embed
      • Renaming
      • Control Flow Obfuscation
      • Encryption and Protection
      • Code Generation
  • MSBuild Task
    • Babel Task Reference
    • Customizing Intellisense
  • NuGet Package
    • NuGet Pakage Reference
  • User Interface
    • Obfuscation
    • Tools
    • Custom Themes
  • Obfuscation Rules
    • XML Rules
      • Example Rules
    • Custom Attributes
    • Obfuscation Agent
  • Merge and Embed
    • Assembly Merging
    • Assembly Embedding
  • Symbols Renaming
    • XML Map Files
    • Cross Assembly Renaming
    • XAML Renaming
    • Decoding Stack Traces
  • String Encryption
    • Custom String Encryption
  • Control Flow Obfuscation
  • Code Encryption
    • External Code Files
    • Password Protected Code
    • Dynamic Code
  • Dynamic Proxy
  • Resource Encryption
  • Value And Array Encryption
  • Tampering Detection
  • Anti Debugging
  • Enhancing Code Security
  • Optimizations
    • Dead Code Removal
    • Metadata Optimizations
    • Code Optimizations
  • Appendix
  • Examples
    • Examples
    • General Samples
      • ClickOnce Deploy
      • Detecting Babel Obfuscation
      • Obfuscate .NET MAUI
      • Blazor Web App
    • Code Encryption
      • Feature Based Licenses
    • Cross Assembly Renaming
      • Publish .NET App
    • Build Servers
      • GitHub Actions
      • Unit Tests
    • Babel Obfuscator NuGet
      • Android Application
  • Plugins
    • Babel Obfuscator Plugins
    • Encrypt Plugin
      • Getting Started
      • Source Code
Powered by GitBook
On this page
  • Configuring Anti Debugging
  • Command Line
  • MSBuild Babel Task
  • Custom Action on Debugger Detected

Was this helpful?

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 1 year ago

Was this helpful?