DLL Forward is a tool that allows for creation of, x86 or x64, mangled or unmangled signature, DLL proxies, redirecting the exports of an arbitrary DLL through your DLL instead.
After downloading the binaries or building the project for yourself, you may use the generated executable as follows:
DLLForward [--def] [--version] <input> <output (optional)>
Where the parameters represent:
- input: The input DLL file path which will be proxied, choose the desired architecture instance (x86 or x64) of the DLL to proxy.
- output: The output path, which is a file built from the the input DLL's data, by default a header (.h) with the same name as the proxied DLL.
- def: Or
-d
for short, if set will generate a module definition (.def) instead of a proxy header from the input DLL. - version: Or
-v
for short, will print the version of the program and exit.
DLLForward "C:/Windows/System32/msimg32.dll" "./msimg32.h"
Will generate a header file msimg32.h
at the current directory, this header must be included in your project for proxying the DLL. It should be included in your project where the implementation of the DllMain
entry point is as you must call dllforward::setup()
in DllMain when fdwReason
is DLL_PROCESS_ATTACH
.
Example project using the generated header (The project must be configured to build for the same architecture as the proxied DLL)
main.cpp
#include "Windows.h"
// You can specify the path to the original through a macro, or it's wide character version
// #define DLLFORWARD_ORIGINALDLLPATH ".\\msimg32.original.dll"
// #define DLLFORWARD_ORIGINALDLLPATH_W L".\\msimg32.original.dll"
#include "msimg32.h"
BOOL WINAPI DllMain(HMODULE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
if (fdwReason == DLL_PROCESS_ATTACH)
{
// Initialize the proxy for the DLL
dllforward::setup();
// Your code here to be executed when the DLL is loaded
}
return TRUE;
}
Note: There might be some need to modify the generated header file to change where the proxy DLL will look for the original DLL in order to load it.
Here are some macros you can define before importing the generated header to modify behavior:
DLLFORWARD_ORIGINALDLLPATH
: Sets the path to the original (proxied) DLL. If not specified, will be the absolute path to the DLL used to create the proxy header.DLLFORWARD_ORIGINALDLLPATH_W
: Same as above but for wide characters, has priority over the non-wide version.
Export resolution methods:
DLLFORWARD_RESOLVEPROC_NAME
: Resolve exports through the names. This is the default option.DLLFORWARD_RESOLVEPROC_RVA
: Resolve exports through the relative virtual addressesDLLFORWARD_RESOLVEPROC_ORDINAL
: Resolve exports through the ordinals
In practice resolving through the name should be more robust and there is no need to change it, but the option is available should the need arise.
Having done this you may rename the DLL you built to the name of the original DLL and place it in the same directory as the original DLL, and it will be loaded instead of the original DLL, having it's exports automatically redirected to the loading binary while also having your code run.
This is an alternate way to use the program where you can build a module definition .def
file from the input DLL, which can be used to generate a stub library with lib.exe
or similar tools.
DLLForward -d "C:/Windows/System32/msimg32.dll" "./msimg32.def"
This will generate a module definition file msimg32.def
at the current directory, it contains information about all the exports of the DLL.
By using a tool such as Microsoft's lib.exe you can generate a stub library from the module definition file, which can be used to link against the original DLL, allowing you to create a project that consumes said DLL and properly resolves the imports without manually resolving the addresses with GetProcAddress for example.
Example usage of lib.exe
to generate a stub library from the module definition file:
lib /def:msimg32.def /out:msimg32.lib /machine:x64
This will generate a stub library msimg32.lib
at the current directory, which can be used to link against your projects on which you wish to use the DLL.
- Allow for x86 and x64 proxy DLLs, debug or release.
- Allow for control of the proxy DLL's header with macros defined before including the header.
- Optional smarter and more robust ways of locating the original DLL.
- Support wide characters in paths.
- Create a parent project for generically generating and compiling a proxy DLL, with options to load other DLLs on a text file.
- Clone the repository recursively to get the submodules:
git clone --recurse-submodules https://github.com/itisluiz/DLLForward
(If you didn't clone the repository recursively, you can initialize the submodules withgit submodule update --init --recursive
) - Launch Visual Studio -> Select "Continue without code" -> File -> Open -> CMake -> Open the
CMakeLists.txt
file in the repository root. - Select your architecture at the top and build the project with
Ctrl + Shift + B
.
Pull requests are welcome, so are issues with suggestions or bug reports. For major changes, please open an issue first to discuss what you would like to change.