I need to determine the caller code coming from an exe or dll.
Dll
#ifdef DLL_EXPORTS __declspec(dllexport) void say_hello(); __declspec(dllexport) void getCurrentModuleName(); #else __declspec(dllimport) void say_hello(); __declspec(dllexport) void getCurrentModuleName(); #endif #include <cstdio> #include <windows.h> #include <Dbghelp.h> #include <iostream> #include <tchar.h> #include "dll.h" #include "Psapi.h" __declspec(naked) void *GetStackPointer() { __asm { mov eax, esp ret } } void getCurrentModuleName() { BOOL result = SymInitialize(GetCurrentProcess(), NULL , TRUE); DWORD64 dwBaseAddress = SymGetModuleBase64(GetCurrentProcess(), (DWORD64)GetStackPointer()); TCHAR szBuffer[50]; GetModuleBaseName(GetCurrentProcess(), (HMODULE) dwBaseAddress, szBuffer, sizeof(szBuffer)); std::wcout << _T("--->") << szBuffer << std::endl; } void say_hello() { getCurrentModuleName(); }
Exe
#include <windows.h> #include <cstdio> #include "dll.h" int main() { printf ("ENTERING EXE CODE...\n"); getCurrentModuleName(); printf ("ENTERING DLL CODE...\n"); say_hello(); getchar(); }
Here is the result.
ENTERING EXE CODE... --->exe.exe ENTERING DLL CODE... --->exe.exe
I'm sorry I can't get
ENTERING EXE CODE... --->exe.exe ENTERING DLL CODE... --->dll.dll
Like the last caller code from the DLL itself (say_hello in the DLL)
Is there any way to achieve this?
source share