From 8e56ea0294973b7c9f8f077a131b40fce13b8489 Mon Sep 17 00:00:00 2001 From: petrie911 Date: Tue, 6 May 2025 07:17:13 -0500 Subject: [PATCH] get symbol --- src/Companion.cpp | 17 +++++++++++++++++ src/Companion.h | 1 + 2 files changed, 18 insertions(+) diff --git a/src/Companion.cpp b/src/Companion.cpp index 1864236..91f84bb 100644 --- a/src/Companion.cpp +++ b/src/Companion.cpp @@ -1433,6 +1433,23 @@ std::optional> Companion::GetSafeNodeByAddr( } +std::string Companion::GetSymbolFromAddr(uint32_t address, bool validZero) { + auto dec = Companion::Instance->GetNodeByAddr(address); + std::ostringstream outSymbol; + + if(address == 0 && !validZero) { + outSymbol << "NULL"; + } else if (dec.has_value()) { + auto node = std::get<1>(dec.value()); + auto symbol = GetSafeNode(node, "symbol"); + outSymbol << "&" << symbol; + } else { + outSymbol << "0x" << std::uppercase << std::hex << address; + } + + return outSymbol.str(); +} + std::optional Companion::GetParseDataByAddr(uint32_t addr) { if(!this->gParseResults.contains(this->gCurrentFile)){ for (auto &file : this->gCurrentExternalFiles) { diff --git a/src/Companion.h b/src/Companion.h index 2807d8d..4354a9b 100644 --- a/src/Companion.h +++ b/src/Companion.h @@ -156,6 +156,7 @@ public: std::optional> GetNodeByAddr(uint32_t addr); std::optional> GetSafeNodeByAddr(const uint32_t addr, std::string type); std::optional>> GetNodesByType(const std::string& type); + std::string GetSymbolFromAddr(uint32_t addr, bool validZero = false); std::optional GetFileOffset(void) const { return this->gCurrentFileOffset; }; std::optional GetCurrSegmentNumber(void) const { return this->gCurrentSegmentNumber; };