What Is DLL Injection? How Game Cheats Load Code into Processes
How DLL injection works technically, the main injection methods used by cheats, and how anti-cheat systems detect and prevent it.
By SensePublished
What Is DLL Injection?
DLL injection is a technique used to run custom code inside another process by forcing it to load a Dynamic Link Library (DLL) that was not part of its original design. In the context of game cheating, DLL injection is the most common method used to get cheat code running inside a game's process, giving the cheat direct access to the game's memory, functions, and rendering pipeline.
When a DLL is injected into a game process, it runs with the same permissions and access as the game itself. This means the injected code can read and modify game variables directly, hook rendering functions to draw ESP overlays, intercept input to implement aimbot, and manipulate any aspect of the game's operation from within.
Common DLL Injection Methods
CreateRemoteThread
The most straightforward injection method uses Windows API functions to create a new thread in the target process that loads the DLL:
- OpenProcess: The injector opens a handle to the game process with PROCESS_ALL_ACCESS permissions.
- VirtualAllocEx: Memory is allocated inside the game process to hold the DLL path string.
- WriteProcessMemory: The full path to the cheat DLL is written into the allocated memory.
- CreateRemoteThread: A new thread is created in the game process, with its start address set to the
LoadLibraryAfunction and the DLL path as the parameter.
When the remote thread executes, it calls LoadLibrary with the cheat DLL path, causing Windows to load the DLL into the game process. The DLL's DllMain function runs automatically, initializing the cheat.
This method is the easiest to implement but also the easiest for anti-cheat to detect because it leaves obvious traces: a new thread with a start address pointing to LoadLibrary, an externally allocated memory region, and a new module in the process's loaded module list.
Manual Mapping
Manual mapping bypasses the standard Windows DLL loading mechanism entirely. Instead of using LoadLibrary, the injector manually performs every step of DLL loading:
- Read the DLL file from disk into the injector's memory.
- Allocate memory in the target process for the DLL image.
- Copy the DLL headers and sections into the allocated memory, applying section relocations.
- Resolve imports: Walk the DLL's import table and resolve each imported function address in the target process.
- Apply relocations: Fix up any addresses in the DLL that depend on the base address.
- Execute the entry point: Call DllMain through a remote thread or by hijacking an existing thread.
Manual mapping avoids adding the DLL to the process's loaded module list (PEB.Ldr), making it invisible to basic module enumeration. However, the allocated memory region is still detectable, and the executable code in an unnamed memory region is suspicious.
Thread Hijacking
Instead of creating a new thread (which is easily detected), thread hijacking repurposes an existing thread in the target process:
- Suspend an existing thread in the game process using SuspendThread.
- Get the thread's context (register state) using GetThreadContext.
- Modify the instruction pointer to point to shellcode that loads the DLL.
- Resume the thread, which now executes the loading code.
- The shellcode loads the DLL, then restores the original thread context and continues normal execution.
This avoids the CreateRemoteThread detection vector but can cause crashes if the hijacked thread was in the middle of a critical operation.
Kernel-Mode Injection
The most advanced injection method uses a kernel driver to inject the DLL without any user-mode API calls that anti-cheat can monitor:
- A custom kernel driver maps the DLL into the game's address space by directly manipulating page tables or using kernel memory management functions.
- The driver queues an APC (Asynchronous Procedure Call) to a game thread to execute the DLL's entry point.
- All operations happen at ring 0, invisible to user-mode anti-cheat hooks.
This requires a loaded kernel driver, which itself needs to bypass driver signature enforcement.
How Anti-Cheats Detect DLL Injection
Module Enumeration
Anti-cheats regularly enumerate the loaded modules in the game process by walking the PEB (Process Environment Block) loader lists. Any module that was not present at game startup or is not on a whitelist is flagged.
Thread Monitoring
New threads created in the game process are logged. The anti-cheat checks the thread's start address: if it points to LoadLibrary or to memory that was recently allocated by an external process, injection is detected.
Memory Scanning
Anti-cheats scan the game process's virtual address space for executable memory regions that do not correspond to loaded modules. Manually mapped DLLs create such regions: executable code in memory that has no associated module.
Hook Detection
Injected DLLs typically hook game functions to implement their features. Anti-cheats verify the integrity of critical functions by checking whether their first bytes match expected values or whether function pointers in virtual method tables have been redirected.
Handle Monitoring
The anti-cheat monitors which processes open handles to the game process. Any process that opens a handle with PROCESS_VM_WRITE or PROCESS_CREATE_THREAD access is logged and may be blocked.
After Getting Caught
Being detected using DLL injection results in a permanent ban with hardware identification. Sense AC's HWID spoofer changes the hardware identifiers that anti-cheat systems read, allowing a new account on the same hardware after a ban.