A simple program to load DLL and call exported functions
I got interested into c++ after watching Pavel sir courses and reading books written by him on system programming. So I decided to explore this on my own and implement DLL rather than using static library
NOTE: Although I don't like windows for usage, but I use it for learning exploitation and learning about malwares.
- Create a DLL project (MyDLL)
- If you want to execute some code on load, use DllMain function already scaffolded, otherwise create functions
- Load the library using
LoadLibraryorLoadLibrayAfunction - Create cast types for function defined in dllmain.cpp (MyDLL/Header.h)
- Use the
GetProcAddressfunction to find address of the target function from the loaded dll - Type cast the
FARPROCto the typedef from the header file - Call the returned function object which has actual reference for executing code
- Free the library using
FreeLibraryfunction
Open the code in visual studio and build both the projects for x86 or x64 (recommended) architecture and run the program as shown below
usage: DLLLoad.exe <x> <y> <add|div|prod|sub>
- https://docs.microsoft.com/en-us/windows/win32/dlls/dllmain
- https://stackoverflow.com/questions/6945231/int-tmainint-argc-tchar-argv
- https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getprocaddress
- https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryw
- https://docs.microsoft.com/en-us/cpp/build/exporting-from-a-dll-using-def-files?view=msvc-160
- https://docs.microsoft.com/en-us/cpp/cpp/extern-cpp?view=msvc-160
- https://docs.microsoft.com/en-us/windows/desktop/api/libloaderapi/nf-libloaderapi-freelibrary
Linkedin: @tbhaxor
Twitter: @tbhaxor
Email: tbhaxor dot proton dot me
