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
SetCaption
method of ImhLabel control at RVA offset 0x4c4d πͺ - Starts a UDP server on port 1305 π
- π When
SetCaption
is 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 ActiveXPatchLibrary
Step 2: If you already cloned without submodules π
git submodule update --init --recursive
Step 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.exe
Send UTF-8 encoded text via UDP to localhost:1305 to change the caption:
Using netcat π±
echo "New Caption Text" | nc -u localhost 1305
Using 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