Skip to content

Instantly share code, notes, and snippets.

@stevemk14ebr
Created December 15, 2018 16:01
Show Gist options
  • Save stevemk14ebr/ceadd1826e9909a2bcd868ae2524ab5d to your computer and use it in GitHub Desktop.
Save stevemk14ebr/ceadd1826e9909a2bcd868ae2524ab5d to your computer and use it in GitHub Desktop.
By maamountki
#include <Windows.h>
#include <DbgHelp.h>
#include <stdio.h>
#pragma comment(lib, "dbghelp.lib")
BOOL CALLBACK EnumProc(SYMBOL_INFO* info, ULONG size, void* param)
{
// Check only SymTagFunction
if (info->Tag == 5)
{
if (strcmp(info->Name, (const char*)param) == 0)
{
printf("Member function found at RVA %lX\n", (DWORD)(info->Address - info->ModBase));
return FALSE;
}
}
return TRUE;
}
void CheckMemberFunction(const char* pdbFile, const char* memberFunction)
{
HANDLE handle = (HANDLE)0x493;
uintptr_t baseAddr = 0x400000;
if (!SymInitialize(handle, NULL, FALSE))
{
printf("Failed to initialise symbol handler.\n");
return;
}
// Load module.
baseAddr = SymLoadModuleEx(handle, NULL, pdbFile, NULL, baseAddr, 0x7fffffff, NULL, 0);
if (!baseAddr)
{
printf("Failed to load symbols for '%s' (Error %d)\n", pdbFile, GetLastError());
return;
}
printf("Symbols Enumerating...\n");
SymEnumSymbols(handle, baseAddr, "*", EnumProc, (PVOID)memberFunction);
// Done.
if (!SymUnloadModule(handle, (DWORD64)baseAddr))
{
printf("Failed unloading module.\n");
}
SymCleanup(handle);
}
int main()
{
const char* pdbFile = "C:\\some_file.exe";
CheckMemberFunction(pdbFile, "SomeClass::SomeFunction");
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment