-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Moved symbols initialization into a separate class
- Loading branch information
1 parent
82fb0d5
commit 75b3bc5
Showing
6 changed files
with
83 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#pragma once | ||
|
||
#include <windows.h> | ||
#include <dbghelp.h> | ||
#pragma comment(lib, "dbghelp") | ||
|
||
class ProcessSymbolsManager | ||
{ | ||
public: | ||
ProcessSymbolsManager(HANDLE _hProcess) | ||
: hProcess(_hProcess), isInit(false) | ||
{ | ||
} | ||
|
||
~ProcessSymbolsManager() | ||
{ | ||
FreeSymbols(); | ||
} | ||
|
||
bool InitSymbols() | ||
{ | ||
if (!isInit) { | ||
SymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEBUG | SYMOPT_INCLUDE_32BIT_MODULES); | ||
if (SymInitialize(hProcess, NULL, TRUE)) { | ||
isInit = true; | ||
} | ||
} | ||
return isInit; | ||
} | ||
|
||
//--- | ||
|
||
static bool dumpSymbolInfo(HANDLE hProcess, ULONG_PTR addr) | ||
{ | ||
CHAR buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME] = { 0 }; | ||
PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer; | ||
pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO); | ||
pSymbol->MaxNameLen = MAX_SYM_NAME; | ||
DWORD64 Displacement = { 0 }; | ||
|
||
BOOLEAN result = SymFromAddr(hProcess, addr, &Displacement, pSymbol); | ||
if (result) { | ||
std::cout << std::dec << "[" << GetProcessId(hProcess) << "]" << std::hex << addr << " Sym: " << pSymbol->ModBase << " : " << pSymbol->Name << " disp: " << Displacement | ||
<< " Flags: " << pSymbol->Flags << " Tag: " << pSymbol->Tag << std::endl; | ||
if (pSymbol->Flags == SYMFLAG_CLR_TOKEN) std::cout << "CLR token!\n"; | ||
} | ||
else { | ||
std::cout << std::dec << "[" << GetProcessId(hProcess) << "]" << std::hex << addr << " UNK \n"; | ||
} | ||
return true; | ||
} | ||
|
||
protected: | ||
bool FreeSymbols() | ||
{ | ||
if (!isInit) return true; | ||
if (SymCleanup(hProcess)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
HANDLE hProcess; | ||
bool isInit; | ||
}; |