Skip to content

Latest commit

 

History

History
91 lines (63 loc) · 3.38 KB

README.md

File metadata and controls

91 lines (63 loc) · 3.38 KB

DllDragon 🐉

DllDragon is a utility for dynamically loading functions from Windows DLLs (Dynamic Link Libraries) at runtime. It allows you to load a DLL module and retrieve the address of a specific function within that module, without having to link the DLL statically or load it manually.

Features

  • Dynamic Library Loading: Load a DLL module by specifying its file name (e.g., "mymodule.dll").
  • Function Resolution: Retrieve the address of a specific function within a loaded DLL module by providing the function name (e.g., "MyFunction").
  • Resource Management: Employs the RAII (Resource Acquisition Is Initialization) principle to ensure that loaded DLL modules are properly unloaded when they go out of scope, preventing resource leaks.
  • Error Logging: Logs errors using a custom logger class instead of throwing exceptions, providing better control over error handling and debugging.
  • Thread Safety: Designed to be thread-safe, with each thread having its own instance of the DLL wrapper class, avoiding potential race conditions and synchronization issues.
  • Caching Mechanism: Implements a caching mechanism to store loaded DLL modules and resolved function addresses, improving performance by avoiding redundant module loading and function resolution.
  • Modular Design: Separates the dynamic library loading and function resolution logic into a dedicated class (DllUtils), improving code organization and maintainability.
  • Improved API: Returns a std::function object instead of a raw function pointer, providing more flexibility and type safety.

Usage

To use the DllDragon utility, follow these steps:

  1. Include the necessary header file:
#include "dllutils.h"
  1. Load a function from a DLL:
auto myFunction = DllUtils::loadFunction("mymodule.dll", "MyFunction");
if (myFunction) {
    myFunction(); // Invoke the loaded function
}

The loadFunction method takes two arguments:

  • moduleName: The name of the DLL module to load (e.g., "mymodule.dll").
  • procName: The name of the function to retrieve from the loaded module (e.g., "MyFunction").

If the function is successfully loaded, the loadFunction method returns a std::function<void()> object representing the loaded function. You can then invoke the function by calling the returned object.

Examples

Check out the main.cpp file for more examples of how to use the DllDragon utility, including loading multiple functions, loading functions with parameters, and more.

Building and Running

To build and run the DllDragon utility, follow these steps:

  1. Clone the repository:
git clone https://github.com/your-repo/DllDragon.git
  1. Navigate to the project directory:
cd DllDragon
  1. Compile the source files:
g++ -o dlldragon main.cpp dllutils.cpp logger.cpp  # On Unix-like systems
cl /EHsc main.cpp dllutils.cpp logger.cpp          # On Windows with Visual C++
  1. Run the compiled executable:
./dlldragon    # On Unix-like systems
dlldragon.exe  # On Windows

Contributing

Contributions to the DllDragon project are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.

License

This project is licensed under the MIT License.

DllDragon/
├── main.cpp
├── dllutils.h
├── dllutils.cpp
├── logger.h
├── logger.cpp
└── LICENSE