This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
419 additions
and
50 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
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,58 @@ | ||
#include "pch.h" | ||
#include "SymbolManager.h" | ||
|
||
SymbolManager& SymbolManager::Get() { | ||
static SymbolManager mgr; | ||
return mgr; | ||
} | ||
|
||
SymbolManager::~SymbolManager() { | ||
Term(); | ||
} | ||
|
||
void SymbolManager::Term() { | ||
_procSymbols.clear(); | ||
} | ||
|
||
SymbolsHandler* SymbolManager::GetCommon() { | ||
return &_commonSymbols; | ||
} | ||
|
||
SymbolsHandler* SymbolManager::GetForProcess(DWORD pid) { | ||
auto it = _procSymbols.find(pid); | ||
if (it == _procSymbols.end()) { | ||
// attempt to get one | ||
|
||
auto symbols = SymbolsHandler::CreateForProcess(pid); | ||
if (symbols == nullptr) | ||
return nullptr; | ||
auto sym = symbols.get(); | ||
_procSymbols.insert({ pid, std::move(symbols) }); | ||
return sym; | ||
} | ||
if (::WaitForSingleObject(it->second->GetHandle(), 0) == WAIT_OBJECT_0) { | ||
// process dead, remove and try again | ||
_procSymbols.erase(pid); | ||
return GetForProcess(pid); | ||
} | ||
return it->second.get(); | ||
} | ||
|
||
std::unique_ptr<SymbolInfo> SymbolManager::GetSymbolFromAddress(DWORD pid, DWORD64 address, PDWORD64 offset) { | ||
if ((int64_t)address < 0) { | ||
// kernel address | ||
_commonSymbols.LoadKernelModule(address); | ||
return _commonSymbols.GetSymbolFromAddress(address, offset); | ||
} | ||
|
||
auto handler = GetForProcess(pid); | ||
if (handler) { | ||
auto symbol = handler->GetSymbolFromAddress(address, offset); | ||
if (symbol) | ||
return symbol; | ||
} | ||
return nullptr; | ||
} | ||
|
||
SymbolManager::SymbolManager() { | ||
} |
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,22 @@ | ||
#pragma once | ||
|
||
#include "SymbolsHandler.h" | ||
|
||
class SymbolManager { | ||
public: | ||
static SymbolManager& Get(); | ||
~SymbolManager(); | ||
void Term(); | ||
|
||
SymbolsHandler* GetCommon(); | ||
SymbolsHandler* GetForProcess(DWORD pid); | ||
|
||
std::unique_ptr<SymbolInfo> GetSymbolFromAddress(DWORD pid, DWORD64 address, PDWORD64 offset = nullptr); | ||
|
||
private: | ||
SymbolManager(); | ||
|
||
SymbolsHandler _commonSymbols; | ||
std::unordered_map<DWORD, std::unique_ptr<SymbolsHandler>> _procSymbols; | ||
}; | ||
|
Oops, something went wrong.