Skip to content

Instantly share code, notes, and snippets.

@actboy168
Created January 18, 2018 06:33
Show Gist options
  • Save actboy168/373c15468dc8e6e768b372c374d6781a to your computer and use it in GitHub Desktop.
Save actboy168/373c15468dc8e6e768b372c374d6781a to your computer and use it in GitHub Desktop.
#pragma once
#include <Dbghelp.h>
#pragma comment(lib, "Dbghelp.lib")
class Symbols {
public:
Symbols()
: m_process(GetCurrentProcess())
{
::SymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS);
::SymInitialize(m_process, NULL, TRUE);
}
~Symbols()
{
::SymCleanup(m_process);
}
uintptr_t operator [](const wchar_t* name) {
SymbolInfo info;
if (!::SymFromNameW(m_process, name, info))
{
return 0;
}
return static_cast<uintptr_t>(info->Address);
}
private:
class SymbolInfo {
public:
SymbolInfo() {
(*this)->SizeOfStruct = sizeof(SYMBOL_INFOW);
(*this)->MaxNameLen = MAX_SYM_NAME;
}
operator PSYMBOL_INFOW () {
return static_cast<PSYMBOL_INFOW>(static_cast<void*>(m_buffer));
}
PSYMBOL_INFOW operator ->() {
return *this;
}
private:
ULONG64 m_buffer[(sizeof(SYMBOL_INFOW) + MAX_SYM_NAME * sizeof(wchar_t) + sizeof(ULONG64) - 1) / sizeof(ULONG64)];
};
HANDLE m_process;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment