Skip to content

Custom LoadLibrary / GetProcAddress (x86 / x64) - Load DLL and retrieve functions manually

License

Notifications You must be signed in to change notification settings

v1stra/Manual-DLL-Loader

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 

Repository files navigation

Banner

Manual DLL Loader

C++ Windows x86 x64

📖 Project Overview :

Custom LoadLibrary / GetProcAddress

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 :

  1. Copy PE image in memory
  2. Perform the relocations
  3. Resolve imports (IAT)
  4. Execute TLS callbacks
  5. Execute DLL's entry point

The GetFunctionAddress can also be used with a library imported with LoadLibraryA official Windows function.

🚀 Getting Started

Visual Studio :

  1. Open the solution file (.sln).
  2. Build the project in Release (x86 or x64)

The loader can be compiled in x86 or x64.

🧪 Example

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;
}
Demo.mp4

About

Custom LoadLibrary / GetProcAddress (x86 / x64) - Load DLL and retrieve functions manually

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 100.0%