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

ManualMap DLL Injector – Automated Manual-Map DLL Injection Framework for Windows

Featured Replies

ManualMap Injector – Automated Manual-Map DLL Injection Framework for Windows

ManualMap Injector is a Windows C++ DLL injection framework designed to manually map a DLL into a target process instead of relying on the standard LoadLibrary-based injection approach.

The project includes a process-monitoring layer that continuously searches for configured target executables and schedules DLL injection after a user-defined delay.

The manual mapping engine handles the main PE loading tasks internally, including section mapping, relocations, imports, TLS callbacks, optional x64 exception support, memory protection adjustment, and post-mapping cleanup.


Features

🔹 Manual Map DLL Injection

Instead of loading the DLL through the normal Windows loader path, the project manually places the PE image into the target process and executes a mapping routine inside the remote process.

The mapper allocates memory according to the DLL's SizeOfImage, copies the PE header and individual sections, and then performs the required initialization steps.


🔹 Automatic Process Detection

The injector continuously scans the running processes and compares their executable names against a configurable target list.

Example configuration:

std::vector<TargetConfig> targets = {
    { L"example.exe", "test.dll" },
    { L"example.bin", "test.dll" }
};

Multiple target executables can therefore use the same DLL configuration.


🔹 Configurable Injection Delay

Before an injection is attempted, the injector waits for a user-defined number of seconds.

Example:

Wait time (seconds): 5

This can be useful when the target application requires additional startup time before the DLL is mapped.


🔹 Multiple Process Instance Support

The scanner does not assume that only one instance of a target process exists.

Every matching PID is processed individually.

The project also maintains an internal (PID + DLL) key so the same DLL is not repeatedly scheduled for the same process instance.

struct InjectKey {
    DWORD pid;
    std::string dll;
};

This allows multiple instances of the same executable to be handled independently.


Manual Mapping Engine

The core of the project is the ManualMapDll() function.

Its mapping pipeline can be summarized as:

DLL File
   │
   ▼
PE Validation
   │
   ▼
Architecture Check
   │
   ▼
Remote Image Allocation
   │
   ▼
PE Header Mapping
   │
   ▼
Section Mapping
   │
   ▼
Mapping Data
   │
   ▼
Remote Mapping Routine
   │
   ├── Relocations
   ├── Imports
   ├── TLS Callbacks
   └── Exception Support
   │
   ▼
DLL Entry Point
   │
   ▼
Memory Protection
   │
   ▼
Cleanup

PE Validation

Before mapping begins, the DLL is validated as a PE image.

The mapper checks the DOS signature:

if (reinterpret_cast<IMAGE_DOS_HEADER*>(pSrcData)->e_magic != 0x5A4D)
{
    return false;
}

It then locates the NT headers and checks whether the DLL architecture matches the injector architecture.

x86 injector → x86 DLL
x64 injector → x64 DLL

The source checks IMAGE_FILE_HEADER::Machine against the current build architecture before continuing.


Remote Image Allocation

The mapper allocates memory inside the target process according to the PE image size:

VirtualAllocEx(
    hProc,
    nullptr,
    pOldOptHeader->SizeOfImage,
    MEM_COMMIT | MEM_RESERVE,
    PAGE_READWRITE
);

The mapped image is initially allocated as writable memory before the individual section protections are configured later.


PE Header & Section Mapping

The PE header is copied into the allocated image and each section containing raw data is copied to its corresponding virtual address.

Conceptually:

Original DLL
│
├── PE Headers
├── .text
├── .rdata
├── .data
├── .rsrc
└── .reloc
       │
       ▼
Target Process Memory
│
├── PE Headers
├── .text
├── .rdata
├── .data
├── .rsrc
└── .reloc

The implementation writes the initial header and then iterates through IMAGE_SECTION_HEADER entries to map the individual sections.


Relocation Processing

If the DLL cannot be loaded at its preferred image base, the mapper processes the PE relocation directory.

The shellcode calculates the difference between the preferred image base and the actual mapped address:

BYTE* LocationDelta = pBase - pOpt->ImageBase;

Relocation entries are then processed and adjusted according to the target architecture.

The project supports:

IMAGE_REL_BASED_HIGHLOW  → x86
IMAGE_REL_BASED_DIR64    → x64

This allows the mapped image to operate from a different memory address than its original preferred base.


Import Resolution

The manual mapper resolves imported modules and functions manually.

For each import descriptor, the mapping routine calls:

LoadLibraryA()

and resolves imported functions through:

GetProcAddress()

Both ordinal-based and name-based imports are handled.


TLS Callback Support

The mapper also checks whether the DLL contains a TLS directory.

If TLS callbacks are present, they are executed with:

DLL_PROCESS_ATTACH

This allows DLLs that rely on TLS initialization callbacks to receive their expected initialization notification.


x64 Exception Support

For 64-bit builds, the mapper can optionally register the DLL's exception runtime function table through:

RtlAddFunctionTable()

The relevant exception directory is located through:

IMAGE_DIRECTORY_ENTRY_EXCEPTION

If registration fails, the mapper reports the failure through its mapping status structure.

Exception support is architecture-dependent and is only enabled for x64 builds in the current implementation.


DLL Entry Point

After the required PE initialization steps have completed, the mapper calls the DLL's entry point:

_DllMain(
    pBase,
    pData->fdwReasonParam,
    pData->reservedParam
);

By default, the injector passes:

DLL_PROCESS_ATTACH

as the reason parameter.


Section Protection Adjustment

After successful mapping, the project can restore memory permissions according to each PE section's characteristics.

For example:

Read-only section
Writable section
Executable + readable section

The implementation uses VirtualProtectEx() and derives the protection from the section's IMAGE_SCN_MEM_* flags.

This provides a more appropriate memory layout than leaving the entire mapped image permanently executable and writable.


Optional PE Cleanup

The mapper provides optional cleanup functionality.

Clear PE Header

When enabled, the first 0x1000 bytes of the mapped image are overwritten after initialization.

ClearHeader

Clear Non-Needed Sections

The mapper can also clear selected sections such as:

.reloc
.rsrc
.pdata

depending on the enabled options and exception-support configuration.

These options are configurable through the ManualMapDll() parameters.


Remote Mapping Routine

The mapping work is performed by the Shellcode() routine inside the target process.

The injector prepares a MANUAL_MAPPING_DATA structure containing function pointers and mapping parameters:

struct MANUAL_MAPPING_DATA
{
    f_LoadLibraryA pLoadLibraryA;
    f_GetProcAddress pGetProcAddress;

#ifdef _WIN64
    f_RtlAddFunctionTable pRtlAddFunctionTable;
#endif

    BYTE* pbase;
    HINSTANCE hMod;
    DWORD fdwReasonParam;
    LPVOID reservedParam;
    BOOL SEHSupport;
};

The structure is written into the target process before the remote mapping routine is started.


Mapping Status & Error Handling

The mapper communicates its status through the hMod field.

The implementation uses special values to indicate mapping problems:

0x404040 → Invalid mapping state
0x505050 → Exception support failure

The injector continuously checks the mapping structure until the mapping routine reports a result.


Automatic Monitoring

After initialization, the injector continuously scans for configured processes.

The basic runtime flow is:

Start Injector
      │
      ▼
Check DLL Files
      │
      ▼
Ask For Delay
      │
      ▼
Start Process Scanner
      │
      ▼
Find Target Process
      │
      ▼
Check PID + DLL
      │
      ├── Already handled → Skip
      │
      ▼
Schedule Injection
      │
      ▼
Wait
      │
      ▼
Manual Map DLL
      │
      ▼
Monitor Process
      │
      └── Process exits → Remove from tracking

The process-tracking set is periodically cleaned so that terminated processes can be detected again if a new instance starts.


Console Interface

The injector creates a console window and displays its current state.

Example:

Wait time (seconds): 5

Scanning. | Active clients: 1
Scanning.. | Active clients: 2
Scanning... | Active clients: 2
Scanning | Active clients: 1

The console title can also be customized through:

SetConsoleTitleA();

Project Structure

ManualMapInjector/
│
├── injector.cpp
├── injector.h
├── ManualMap.cpp
├── Shellcode.cpp
└── target DLL

The exact file organization can be adjusted depending on how the project is structured in Visual Studio.


How to Use

1. Build the Injector

Open the project in Visual Studio and select the appropriate architecture:

x86

or:

x64

The DLL must use the same architecture as the injector and target process.


2. Place the DLL

Place the DLL specified in the target configuration next to the injector executable or provide the desired path.

Example:

{ L"example.exe", "test.dll" }

3. Configure Target Processes

Edit the target list:

std::vector<TargetConfig> targets = {
    { L"example.exe", "test.dll" },
    { L"example.bin", "test.dll" }
};

You can add additional target executable names as required.


4. Start the Injector

Launch the injector and enter the desired delay:

Wait time (seconds): 5

The injector will then begin scanning for matching processes.


5. Start the Target Application

When a configured process is detected, the injector creates a delayed injection task.

Once the configured delay expires, the DLL is passed to the manual mapping engine.


Configuration Options

The main mapper exposes several configuration parameters:

ManualMapDll(
    hProc,
    pSrcData,
    FileSize,
    ClearHeader,
    ClearNonNeededSections,
    AdjustProtections,
    SEHExceptionSupport,
    fdwReason,
    lpReserved
);

Available options include:

Option

Description

ClearHeader

Clears the mapped PE header after initialization

ClearNonNeededSections

Clears selected sections after mapping

AdjustProtections

Restores section memory protections

SEHExceptionSupport

Enables x64 exception-function registration

fdwReason

DLL entry-point reason

lpReserved

Reserved parameter passed to the DLL entry point

The default configuration enables header cleanup, unnecessary-section cleanup, protection adjustment, and x64 exception support.


Advantages

✔ No Standard DLL Loader Dependency

The mapping process does not simply rely on the standard LoadLibrary() mechanism to load the target DLL.

✔ PE-Level Mapping

The project works directly with the PE structures and performs the required initialization stages itself.

✔ Automatic Process Monitoring

Target processes are discovered automatically.

✔ Multiple Target Names

Different executable names can be configured.

✔ Multiple Instances

Each process PID is tracked independently.

✔ x86 / x64 Support

The architecture is detected at compile time and the appropriate relocation type is selected.

✔ TLS Support

TLS callbacks contained in the mapped image are processed.

✔ Optional x64 Exception Support

Runtime function tables can be registered for 64-bit images.

✔ Memory Cleanup

Temporary mapping data and shellcode memory are released after successful mapping.


Limitations

This implementation is a lightweight manual mapping framework and is not a complete replacement for the Windows PE loader.

Potential compatibility limitations may include:

  • DLLs with unusual loader requirements

  • Complex loader dependencies

  • Advanced TLS behavior

  • Loader-lock-sensitive initialization

  • Unusual exception/unwind configurations

  • Architecture mismatches

  • Protected or restricted target processes

  • DLLs depending on loader-specific behavior

The project should therefore be tested against the specific DLLs and target applications it is intended to support.


Technical Overview

┌─────────────────────────────┐
│       Injector Process      │
├─────────────────────────────┤
│ Process Scanner             │
│ Target Configuration        │
│ Delay Scheduler             │
│ PID Tracking                │
│ DLL File Loader             │
└──────────────┬──────────────┘
               │
               ▼
┌─────────────────────────────┐
│      ManualMapDll()         │
├─────────────────────────────┤
│ PE Validation               │
│ Architecture Validation     │
│ Remote Memory Allocation    │
│ Header Mapping              │
│ Section Mapping             │
│ Mapping Data                │
│ Remote Mapping Routine      │
└──────────────┬──────────────┘
               │
               ▼
┌─────────────────────────────┐
│        Shellcode()          │
├─────────────────────────────┤
│ Relocations                 │
│ Import Resolution           │
│ TLS Callbacks               │
│ x64 Exception Support       │
│ DLL Entry Point             │
└──────────────┬──────────────┘
               │
               ▼
┌─────────────────────────────┐
│       Target Process        │
│       Mapped DLL            │
└─────────────────────────────┘

This is the hidden content, please

PROFESSIONAL

  • Replies 3
  • Views 923
  • Created
  • Last Reply

Top Posters In This Topic

  • 4 weeks later...
Thanks for sharing!

Create an account or sign in to comment

Recently Browsing 1

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.