Skip to content

Latest commit

 

History

History
91 lines (62 loc) · 3.02 KB

README.md

File metadata and controls

91 lines (62 loc) · 3.02 KB
        __  ___                        __   ____  __    __       __                    __       
       /  |/  /___ _____  __  ______ _/ /  / __ \/ /   / /      / /   ____  ____ _____/ /__  _____
      / /|_/ / __ `/ __ \/ / / / __ `/ /  / / / / /   / /      / /   / __ \/ __ `/ __  / _ \/ ___/
     / /  / / /_/ / / / / /_/ / /_/ / /  / /_/ / /___/ /___   / /___/ /_/ / /_/ / /_/ /  __/ /
    /_/  /_/\__,_/_/ /_/\__,_/\__,_/_/  /_____/_____/_____/  /_____/\____/\__,_/\__,_/\___/_/
                                                                                       
                                                                                       
                           Custom LoadLibrary / GetProcAddress (x86 / x64)  
                             Load DLL and retrieve functions manually 

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)

Note
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;
}

Test DLL

Demo.mp4
ImGui.Standalone.mp4