Skip to content
View in the app

A better way to browse. Learn more.

DECODEHUB - Software and reverse engineering community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
Decodehub.org rank system
New badge system

AntiDebug Engine – Multi-Layer Anti-Debugging & Early EntryPoint Protection for Windows

Featured Replies

AntiDebug Engine – Multi-Layer Anti-Debugging & Early EntryPoint Protection for Windows

AntiDebug Engine is a lightweight C++ anti-debugging framework for Windows applications. The project combines multiple independent debugger-detection techniques into a single protection layer and performs checks both during the early initialization stage and continuously while the application is running.

The main goal of the project is to make basic and common debugging attempts easier to detect by combining API-based, PEB-based, native NT API, timing, debug-register, window-detection, TLS callback, and EntryPoint checks.


Features

🔹 Multiple Anti-Debugging Techniques

AntiDebug Engine currently implements several detection methods:

  • IsDebuggerPresent() detection

  • CheckRemoteDebuggerPresent() detection

  • PEB BeingDebugged flag detection

  • NtQueryInformationProcess / ProcessDebugPort detection

  • NtQueryInformationProcess inline-hook detection

  • Debugger window detection

  • Timing-based debugger detection

  • CPU debug-register (Dr0–Dr3 / Dr7) detection

Each technique works independently, allowing multiple detection layers to be combined.


🔐 Early TLS Callback Protection

The project registers a TLS callback using the MSVC CRT TLS callback mechanism.

The callback is executed during process initialization and performs an anti-debugging check before the normal application initialization flow continues.

void NTAPI TLSCallback(PVOID DllHandle, DWORD Reason, PVOID Reserved)
{
    if (Reason == DLL_PROCESS_ATTACH)
    {
        AntiDebug::EntryPointCheck();
    }
}

This provides an additional protection layer before the application's normal entry-point logic is executed.


🚪 Fake EntryPoint / Real EntryPoint Architecture

The project separates the visible entry point from the actual application initialization.

The execution flow is conceptually:

Process Start
     │
     ▼
TLS Callback
     │
     ├── Debugger detected → Terminate
     │
     ▼
Fake EntryPoint
     │
     ├── Debugger detected → Terminate
     │
     ▼
RealEntry()
     │
     ▼
Application

The FakeEntry() function performs another debugger check before transferring execution to RealEntry().

extern "C" __declspec(noreturn) void FakeEntry()
{
    if (AntiDebug::IsDebugging())
    {
        TerminateProcess(GetCurrentProcess(), 0);
    }

    RealEntry();

    ExitProcess(0);
}

This architecture allows the protection layer to be placed before the application's primary initialization code.


🧩 Continuous Background Monitoring

After the application reaches RealEntry(), a detached monitoring thread periodically performs the complete anti-debugging routine.

void AntiDebug::StartThreadedCheck()
{
    std::thread([] {
        while (true)
        {
            if (IsDebugging())
            {
                TerminateProcess(GetCurrentProcess(), 0);
            }

            std::this_thread::sleep_for(
                std::chrono::milliseconds(5)
            );
        }
    }).detach();
}

This means the checks are not limited to application startup. The process continues monitoring for debugger-related conditions while it is running.


Detection Methods

1. IsDebuggerPresent API

Uses the Windows IsDebuggerPresent() API to determine whether the current process is being debugged.

::IsDebuggerPresent();

2. Remote Debugger Detection

Uses CheckRemoteDebuggerPresent() to check whether a debugger is attached to the process.

BOOL isDebugger = FALSE;

CheckRemoteDebuggerPresent(
    GetCurrentProcess(),
    &isDebugger
);

3. PEB BeingDebugged Flag

The project directly accesses the Process Environment Block (PEB) and checks the BeingDebugged flag.

For x86:

__readfsdword(0x30);

For x64:

__readgsqword(0x60);

This provides a lower-level alternative to relying exclusively on the standard Windows debugging APIs.


4. NtQueryInformationProcess

The project dynamically resolves NtQueryInformationProcess from ntdll.dll and queries ProcessDebugPort.

This allows the application to perform a native NT-level debugger check without statically importing the function.


5. NTDLL Inline Hook Detection

The project performs a basic validation of the beginning of NtQueryInformationProcess.

Unexpected bytes may indicate that the function has been modified or redirected.

Note: this is intentionally a lightweight heuristic rather than a complete integrity-verification system.


6. Debugger Window Detection

The project checks for several commonly used debugger windows, including:

  • OllyDbg

  • x32dbg

  • x64dbg

Example:

FindWindowA("OLLYDBG", nullptr);
FindWindowA("Qt5QWindowIcon", "x32dbg");
FindWindowA("Qt5QWindowIcon", "x64dbg");

Additional debugger window signatures can be added easily.


7. Timing Check

A small CPU workload is measured using QueryPerformanceCounter().

The project compares the execution time against a predefined threshold. Significant delays may indicate debugging or instrumentation overhead.

QueryPerformanceFrequency(&freq);

QueryPerformanceCounter(&t1);

// Test workload

QueryPerformanceCounter(&t2);

8. Hardware Debug Register Detection

The current thread context is queried using GetThreadContext() with CONTEXT_DEBUG_REGISTERS.

The implementation checks:

Dr0
Dr1
Dr2
Dr3
Dr7

If active hardware breakpoints are detected, the function reports a debugging condition.


Project Structure

AntiDebug/
│
├── AntiDebug.h
├── AntiDebug.cpp
├── AntiDebugTLS.cpp
├── FakeEntry.cpp
└── Main.cpp

AntiDebug.h

Contains the AntiDebug namespace and function declarations.

AntiDebug.cpp

Contains the main debugger-detection implementations.

AntiDebugTLS.cpp

Registers the TLS callback responsible for performing an early anti-debugging check.

FakeEntry.cpp

Contains the intermediate EntryPoint and redirects execution to RealEntry().

Main.cpp

Contains the actual application initialization and starts the continuous monitoring thread.


Requirements

  • Windows

  • Visual Studio / MSVC

  • C++17 or newer recommended

  • Windows SDK

  • x86 or x64 target

The project is designed around Windows-specific APIs and therefore is Windows-only.


How to Use

1. Add the source files to your Visual Studio project

Add:

AntiDebug.h
AntiDebug.cpp
AntiDebugTLS.cpp
FakeEntry.cpp
Main.cpp

2. Configure the project architecture

Build the project for the desired target:

x86

or

x64

The PEB access implementation automatically selects the appropriate segment register depending on the compiler architecture.


3. Initialize the application through RealEntry()

Place the main application initialization inside:

extern "C" void RealEntry()
{
    AntiDebug::StartThreadedCheck();

    // Application initialization
}

4. Configure the EntryPoint

The intended execution architecture is:

TLS Callback
      ↓
FakeEntry
      ↓
RealEntry
      ↓
Application

The project's build/link configuration must therefore be arranged so that the desired entry-point flow is actually used.


Detection Flow

The central function is:

bool AntiDebug::IsDebugging()
{
    if (IsDebuggerPresentAPI()) return true;
    if (IsRemoteDebuggerPresentAPI()) return true;
    if (CheckPEBFlag()) return true;
    if (CheckNtQueryInfo()) return true;
    if (CheckNtInlineHooks()) return true;
    if (CheckDbgWindows()) return true;
    if (CheckTiming()) return true;
    if (CheckDRxRegisters()) return true;

    return false;
}

A positive result from any detection method causes the protection layer to report a debugger condition.

The current implementation responds by terminating the process:

TerminateProcess(
    GetCurrentProcess(),
    0
);

Why Multiple Checks?

No single anti-debugging technique is perfect.

For example:

API Detection
      +
PEB Detection
      +
NT Query Detection
      +
Timing Detection
      +
Debug Register Detection
      +
Window Detection
      +
TLS Callback
      +
Continuous Monitoring

Combining different techniques creates a layered detection architecture instead of relying on a single indicator.


Customization

The project is designed to be extended.

Additional checks can be added to:

AntiDebug::IsDebugging()

For example:

if (NewDetectionMethod())
    return true;

Possible future extensions include:

  • Additional process/environment checks

  • More debugger signatures

  • Module integrity verification

  • Import/address validation

  • Additional native API checks

  • Configurable detection policies

  • Logging/debug mode for development

  • Per-check enable/disable configuration


Important Notes

This project is intended as an anti-debugging research and software-protection example.

Anti-debugging techniques are heuristic by nature and can produce false positives depending on the environment, virtualization software, instrumentation frameworks, security products, or compatibility layers.

Some checks may also become unreliable across different Windows versions or compiler configurations.

The project should therefore be tested thoroughly before being integrated into production software.

This is the hidden content, please

PROFESSIONAL

  • 2 months later...
  • Replies 8
  • Views 3.5k
  • Created
  • Last Reply

Top Posters In This Topic

Most Popular Posts

Thanks for sharing!

Pls update OP with the archive PW. I was able to figure it out, but...

Edited by Stingered

14 minutes ago, Stingered said:

Pls update OP with the archive PW. I was able to figure it out, but...

Please tell me what the password is.

On 8/27/2026 at 12:54 AM, cambaz said:

AntiDebug Engine – Multi-Layer Anti-Debugging & Early EntryPoint Protection for Windows

AntiDebug Engine is a lightweight C++ anti-debugging framework for Windows applications. The project combines multiple independent debugger-detection techniques into a single protection layer and performs checks both during the early initialization stage and continuously while the application is running.

The main goal of the project is to make basic and common debugging attempts easier to detect by combining API-based, PEB-based, native NT API, timing, debug-register, window-detection, TLS callback, and EntryPoint checks.


Features

🔹 Multiple Anti-Debugging Techniques

AntiDebug Engine currently implements several detection methods:

  • IsDebuggerPresent() detection

  • CheckRemoteDebuggerPresent() detection

  • PEB BeingDebugged flag detection

  • NtQueryInformationProcess / ProcessDebugPort detection

  • NtQueryInformationProcess inline-hook detection

  • Debugger window detection

  • Timing-based debugger detection

  • CPU debug-register (Dr0–Dr3 / Dr7) detection

Each technique works independently, allowing multiple detection layers to be combined.


🔐 Early TLS Callback Protection

The project registers a TLS callback using the MSVC CRT TLS callback mechanism.

The callback is executed during process initialization and performs an anti-debugging check before the normal application initialization flow continues.

void NTAPI TLSCallback(PVOID DllHandle, DWORD Reason, PVOID Reserved)
{
    if (Reason == DLL_PROCESS_ATTACH)
    {
        AntiDebug::EntryPointCheck();
    }
}

This provides an additional protection layer before the application's normal entry-point logic is executed.


🚪 Fake EntryPoint / Real EntryPoint Architecture

The project separates the visible entry point from the actual application initialization.

The execution flow is conceptually:

Process Start
     │
     ▼
TLS Callback
     │
     ├── Debugger detected → Terminate
     │
     ▼
Fake EntryPoint
     │
     ├── Debugger detected → Terminate
     │
     ▼
RealEntry()
     │
     ▼
Application

The FakeEntry() function performs another debugger check before transferring execution to RealEntry().

extern "C" __declspec(noreturn) void FakeEntry()
{
    if (AntiDebug::IsDebugging())
    {
        TerminateProcess(GetCurrentProcess(), 0);
    }

    RealEntry();

    ExitProcess(0);
}

This architecture allows the protection layer to be placed before the application's primary initialization code.


🧩 Continuous Background Monitoring

After the application reaches RealEntry(), a detached monitoring thread periodically performs the complete anti-debugging routine.

void AntiDebug::StartThreadedCheck()
{
    std::thread([] {
        while (true)
        {
            if (IsDebugging())
            {
                TerminateProcess(GetCurrentProcess(), 0);
            }

            std::this_thread::sleep_for(
                std::chrono::milliseconds(5)
            );
        }
    }).detach();
}

This means the checks are not limited to application startup. The process continues monitoring for debugger-related conditions while it is running.


Detection Methods

1. IsDebuggerPresent API

Uses the Windows IsDebuggerPresent() API to determine whether the current process is being debugged.

::IsDebuggerPresent();

2. Remote Debugger Detection

Uses CheckRemoteDebuggerPresent() to check whether a debugger is attached to the process.

BOOL isDebugger = FALSE;

CheckRemoteDebuggerPresent(
    GetCurrentProcess(),
    &isDebugger
);

3. PEB BeingDebugged Flag

The project directly accesses the Process Environment Block (PEB) and checks the BeingDebugged flag.

For x86:

__readfsdword(0x30);

For x64:

__readgsqword(0x60);

This provides a lower-level alternative to relying exclusively on the standard Windows debugging APIs.


4. NtQueryInformationProcess

The project dynamically resolves NtQueryInformationProcess from ntdll.dll and queries ProcessDebugPort.

This allows the application to perform a native NT-level debugger check without statically importing the function.


5. NTDLL Inline Hook Detection

The project performs a basic validation of the beginning of NtQueryInformationProcess.

Unexpected bytes may indicate that the function has been modified or redirected.


6. Debugger Window Detection

The project checks for several commonly used debugger windows, including:

  • OllyDbg

  • x32dbg

  • x64dbg

Example:

FindWindowA("OLLYDBG", nullptr);
FindWindowA("Qt5QWindowIcon", "x32dbg");
FindWindowA("Qt5QWindowIcon", "x64dbg");

Additional debugger window signatures can be added easily.


7. Timing Check

A small CPU workload is measured using QueryPerformanceCounter().

The project compares the execution time against a predefined threshold. Significant delays may indicate debugging or instrumentation overhead.

QueryPerformanceFrequency(&freq);

QueryPerformanceCounter(&t1);

// Test workload

QueryPerformanceCounter(&t2);

8. Hardware Debug Register Detection

The current thread context is queried using GetThreadContext() with CONTEXT_DEBUG_REGISTERS.

The implementation checks:

Dr0
Dr1
Dr2
Dr3
Dr7

If active hardware breakpoints are detected, the function reports a debugging condition.


Project Structure

AntiDebug/
│
├── AntiDebug.h
├── AntiDebug.cpp
├── AntiDebugTLS.cpp
├── FakeEntry.cpp
└── Main.cpp

AntiDebug.h

Contains the AntiDebug namespace and function declarations.

AntiDebug.cpp

Contains the main debugger-detection implementations.

AntiDebugTLS.cpp

Registers the TLS callback responsible for performing an early anti-debugging check.

FakeEntry.cpp

Contains the intermediate EntryPoint and redirects execution to RealEntry().

Main.cpp

Contains the actual application initialization and starts the continuous monitoring thread.


Requirements

  • Windows

  • Visual Studio / MSVC

  • C++17 or newer recommended

  • Windows SDK

  • x86 or x64 target

The project is designed around Windows-specific APIs and therefore is Windows-only.


How to Use

1. Add the source files to your Visual Studio project

Add:

AntiDebug.h
AntiDebug.cpp
AntiDebugTLS.cpp
FakeEntry.cpp
Main.cpp

2. Configure the project architecture

Build the project for the desired target:

x86

or

x64

The PEB access implementation automatically selects the appropriate segment register depending on the compiler architecture.


3. Initialize the application through RealEntry()

Place the main application initialization inside:

extern "C" void RealEntry()
{
    AntiDebug::StartThreadedCheck();

    // Application initialization
}

4. Configure the EntryPoint

The intended execution architecture is:

TLS Callback
      ↓
FakeEntry
      ↓
RealEntry
      ↓
Application

The project's build/link configuration must therefore be arranged so that the desired entry-point flow is actually used.


Detection Flow

The central function is:

bool AntiDebug::IsDebugging()
{
    if (IsDebuggerPresentAPI()) return true;
    if (IsRemoteDebuggerPresentAPI()) return true;
    if (CheckPEBFlag()) return true;
    if (CheckNtQueryInfo()) return true;
    if (CheckNtInlineHooks()) return true;
    if (CheckDbgWindows()) return true;
    if (CheckTiming()) return true;
    if (CheckDRxRegisters()) return true;

    return false;
}

A positive result from any detection method causes the protection layer to report a debugger condition.

The current implementation responds by terminating the process:

TerminateProcess(
    GetCurrentProcess(),
    0
);

Why Multiple Checks?

No single anti-debugging technique is perfect.

For example:

API Detection
      +
PEB Detection
      +
NT Query Detection
      +
Timing Detection
      +
Debug Register Detection
      +
Window Detection
      +
TLS Callback
      +
Continuous Monitoring

Combining different techniques creates a layered detection architecture instead of relying on a single indicator.


Customization

The project is designed to be extended.

Additional checks can be added to:

AntiDebug::IsDebugging()

For example:

if (NewDetectionMethod())
    return true;

Possible future extensions include:

  • Additional process/environment checks

  • More debugger signatures

  • Module integrity verification

  • Import/address validation

  • Additional native API checks

  • Configurable detection policies

  • Logging/debug mode for development

  • Per-check enable/disable configuration


Important Notes

This project is intended as an anti-debugging research and software-protection example.

Anti-debugging techniques are heuristic by nature and can produce false positives depending on the environment, virtualization software, instrumentation frameworks, security products, or compatibility layers.

Some checks may also become unreliable across different Windows versions or compiler configurations.

The project should therefore be tested thoroughly before being integrated into production software.

This is the hidden content, please

password?????

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.