A Windows DLL injection library for runtime hooking of ActiveX controls ๐ฏ
- ๐ช Function Hooking - Intercepts specific ActiveX control methods using Microsoft Detours
- ๐ Runtime Caption Modification - Dynamically modifies the caption text of ImhLabel controls
- ๐ UDP Command Interface - Receives commands via UDP on port 1305 to update caption text
- ๐ฅ๏ธ Console Debug Output - Provides real-time logging of intercepted function calls
- ๐ Clean Hook/Unhook - Properly restores original functions on DLL detachment
ActiveXPatchLibrary is a Proof of Concept (PoC) dynamic library that intercepts and modifies function calls of ActiveX controls. Specifically, it targets the ImhLabel ActiveX control (mhLbl.dll) and provides runtime patching capabilities through a UDP-based communication interface.
The library consists of four main components:
| Component | File | Description |
|---|---|---|
| ๐ฏ Main Hook Engine | src/main.cpp |
Manages the DLL lifecycle and function hooking |
| ๐ UDP Server | inc/UdpServer.h |
Listens for external commands on UDP port 1305 |
| ๐ ๏ธ Utility Functions | inc/Utils.h |
Provides string conversion and console setup utilities |
| ๐ฆ ActiveX Interface | inc/ImhLabel.h |
Defines the ImhLabel COM interface with RVA offsets |
- ๐ The DLL is injected into a target process using the Detours library
- ๐ On
DLL_PROCESS_ATTACH, it:- Sets up a debug console ๐ฅ๏ธ
- Hooks the
SetCaptionmethod of ImhLabel control at RVA offset 0x4c4d ๐ช - Starts a UDP server on port 1305 ๐
- ๐ When
SetCaptionis called on any ImhLabel control:- The original caption is intercepted and logged ๐
- If a new caption has been received via UDP, it replaces the original โ๏ธ
- Otherwise, the original caption is passed through unchanged โก๏ธ
- ๐งน On
DLL_PROCESS_DETACH, all hooks are removed cleanly
- ๐ ๏ธ Visual Studio 2022 (Platform Toolset v143)
- ๐ช Windows SDK 10.0
- ๐ Microsoft Detours (included as git submodule)
Step 1: Clone the repository with submodules ๐ฅ
git clone --recursive https://github.com/yourusername/ActiveXPatchLibrary.git
cd ActiveXPatchLibraryStep 2: If you already cloned without submodules ๐
git submodule update --init --recursiveStep 3: Open in Visual Studio ๐
Open ActiveXPatchLibrary/ActiveXPatchLibrary.sln in Visual Studio
Step 4: Build the solution ๐๏ธ
- Configuration: Release
- Platform: Win32
- Output: DLL library
Use the Detours withdll.exe utility or your preferred DLL injection method:
withdll.exe /d:ActiveXPatchLibrary.dll target_application.exeSend UTF-8 encoded text via UDP to localhost:1305 to change the caption:
Using netcat ๐ฑ
echo "New Caption Text" | nc -u localhost 1305Using PowerShell ๐
$udpClient = New-Object System.Net.Sockets.UdpClient
$bytes = [System.Text.Encoding]::UTF8.GetBytes("New Caption Text")
$udpClient.Send($bytes, $bytes.Length, "localhost", 1305)
$udpClient.Close()Using Python ๐
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto("New Caption Text".encode('utf-8'), ('localhost', 1305))
sock.close()Key configuration parameters can be found in src/main.cpp:
| Parameter | Default Value | Description |
|---|---|---|
BIND_PORT |
1305 | UDP server listening port |
PATCH_TABLE |
See below | Maps function names to RVA offsets |
std::map<std::string, std::pair<uintptr_t, uintptr_t>> PATCH_TABLE = {
{
"SetCaption",
{
(uintptr_t)((BYTE*)GetModuleHandleW(L"mhLbl.dll") + 0x4c4d),
(uintptr_t)(&NewSetCaption)
}
},
};ActiveXPatchLibrary/
โโโ ActiveXPatchLibrary/
โ โโโ inc/
โ โ โโโ ImhLabel.h # ๐ฆ ActiveX control interface definition
โ โ โโโ UdpServer.h # ๐ UDP server implementation
โ โ โโโ Utils.h # ๐ ๏ธ Utility functions
โ โโโ src/
โ โ โโโ main.cpp # ๐ฏ Main DLL entry point and hooking logic
โ โโโ ActiveXPatchLibrary.sln
โ โโโ ActiveXPatchLibrary.vcxproj
โโโ Detours/ # ๐ Microsoft Detours (git submodule)
โโโ LICENSE # ๐ Apache License 2.0
โโโ README.md # ๐ This file
| Function | RVA Offset | Description |
|---|---|---|
| SetCaption | 0x4c4d | Sets the caption/text of the label control |
| Dependency | Purpose |
|---|---|
| Microsoft Detours | Function interception and hooking framework |
| Winsock2 | UDP socket communication |
| Windows COM | BSTR string handling |
The ImhLabel interface is defined with the following key methods:
- SetCaption (0x4c4d) - Sets the label text
- GetCaption (0x4ed9) - Retrieves the label text
- SetForeColor (0x4e65) - Sets the foreground color
- SetBackColor (0x4ca7) - Sets the background color
- โ Security research and analysis
- โ Debugging and testing ActiveX controls
- โ Automated testing frameworks
- โ Reverse engineering for compatibility
โ Do not use this tool for:
- Unauthorized modification of software
- Malicious purposes
- Violation of software licenses or terms of service
Licensed under the Apache License, Version 2.0. See LICENSE for full text.
Copyright 2024 ActiveXPatchLibrary Contributors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
- Microsoft Detours: https://github.com/microsoft/Detours
- This project uses Detours for runtime function hooking
๐ซ DLL fails to load
- โ Ensure all dependencies (Detours) are properly built
- โ Check that the target process architecture matches the DLL (x86)
- โ Verify you have proper permissions to inject into the target process
- โ Check Windows Defender or antivirus isn't blocking the DLL
โ Function hooks not working
- โ Verify mhLbl.dll is loaded in the target process
- โ Confirm the RVA offsets match your version of mhLbl.dll
- โ Use a tool like PE Explorer or IDA Pro to verify offsets if needed
- โ Check the console output for "Patched:" messages
๐ UDP commands not received
- โ Check firewall settings allow UDP port 1305
- โ Verify the console window shows "UDP Echo Server is running"
- โ Ensure you're sending to the correct IP (localhost/127.0.0.1)
- โ Try using a network monitoring tool like Wireshark to debug
๐ฅ๏ธ Console window not appearing
- โ
Ensure
Utils::SetupConsole()is being called in F:/workspace/ActiveXPatchLibrary/ActiveXPatchLibrary/src/main.cpp:126 - โ Check if the target process has permission to create console windows
- โ Try running the target application as Administrator
๐ฅ Application crashes after injection
- โ Verify RVA offsets are correct for your mhLbl.dll version
- โ Check for conflicts with other hooks or security software
- โ Ensure the DLL was built with the correct configuration (Release/Win32)
- โ Look for error messages in the console before the crash
- ๐ค Naming: Use camelCase for functions, PascalCase for classes
- ๐ Indentation: 4 spaces
- ๐ฌ Comments: Document all hooked functions and RVA offsets
- Find the RVA offset using a disassembler (IDA Pro, Ghidra, x64dbg)
- Add to ImhLabel.h with the method signature
- Create a new hook function in main.cpp
- Add to PATCH_TABLE with the offset and hook function
- Test thoroughly to ensure stability
- ๐ฅ๏ธ Watch the console output for hook confirmation messages
- ๐ Use Process Monitor to track DLL loading and function calls
- ๐ Attach a debugger (x64dbg/WinDbg) to the target process
- ๐ Enable verbose logging in your hook functions