__ ___ __ ____ __ __ __ __
/ |/ /___ _____ __ ______ _/ / / __ \/ / / / / / ____ ____ _____/ /__ _____
/ /|_/ / __ `/ __ \/ / / / __ `/ / / / / / / / / / / / __ \/ __ `/ __ / _ \/ ___/
/ / / / /_/ / / / / /_/ / /_/ / / / /_/ / /___/ /___ / /___/ /_/ / /_/ / /_/ / __/ /
/_/ /_/\__,_/_/ /_/\__,_/\__,_/_/ /_____/_____/_____/ /_____/\____/\__,_/\__,_/\___/_/
Custom LoadLibrary / GetProcAddress (x86 / x64)
Load DLL and retrieve functions manually
This is a custom implementation of different Windows functions :
-
LoadLibraryA
-
GetProcAddress
-
FreeLibrary
You can manualy map DLL into your program, retrieve functions by name or ordinal and free the library.
The loader perform the relocations, and it is fully functionnal with x86 and x64 PE images.
Loading steps :
- Copy PE image in memory
- Perform the relocations
- Resolve imports (IAT)
- Execute TLS callbacks
- Execute DLL's entry point
The GetFunctionAddress can also be used with a library imported with LoadLibraryA official Windows function.
- Open the solution file (.sln).
- Build the project in Release (x86 or x64)
Note
The loader can be compiled in x86 or x64.
You can import DLL and functions easily like when you use LoadLibraryA and GetProcAddress.
//Function pointer
using MessageFncPtr = void (*)();
int main()
{
const auto lpModule = MemoryLoader::LoadDLL((LPSTR)"test.dll");
if (lpModule == nullptr)
return -1;
auto MessageFnc = (MessageFncPtr)MemoryLoader::GetFunctionAddress((LPVOID)lpModule, (const LPSTR)"Message");
if (MessageFnc == nullptr)
return -1;
MessageFnc();
MessageFnc = (MessageFncPtr)MemoryLoader::GetFunctionAddressByOrdinal((LPVOID)lpModule, 1);
if (MessageFnc == nullptr)
return -1;
MessageFnc();
MemoryLoader::FreeDLL(lpModule);
return 0;
}