From 941a7368a137e6d67708d006485ae193fd39c813 Mon Sep 17 00:00:00 2001 From: rollsafe Date: Thu, 18 Jul 2019 17:58:31 -0400 Subject: Add Symbol aliases to cope with duplicate symbols --- binaryninjaapi.h | 1 + binaryninjacore.h | 1 + binaryview.cpp | 14 ++++++++++++++ python/types.py | 14 ++++++++++++++ 4 files changed, 30 insertions(+) diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 3fb60a84..76595ca7 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -1067,6 +1067,7 @@ namespace BinaryNinja uint64_t GetOrdinal() const; bool IsAutoDefined() const; NameSpace GetNameSpace() const; + std::vector GetAliases() const; static Ref ImportedFunctionFromImportAddressSymbol(Symbol* sym, uint64_t addr); }; diff --git a/binaryninjacore.h b/binaryninjacore.h index b154b4d1..c6244cba 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -3003,6 +3003,7 @@ extern "C" BINARYNINJACOREAPI uint64_t BNGetSymbolAddress(BNSymbol* sym); BINARYNINJACOREAPI uint64_t BNGetSymbolOrdinal(BNSymbol* sym); BINARYNINJACOREAPI bool BNIsSymbolAutoDefined(BNSymbol* sym); + BINARYNINJACOREAPI char** BNGetSymbolAliases(BNSymbol* sym, size_t* count); BINARYNINJACOREAPI BNSymbol* BNGetSymbolByAddress(BNBinaryView* view, uint64_t addr, const BNNameSpace* nameSpace); BINARYNINJACOREAPI BNSymbol* BNGetSymbolByRawName(BNBinaryView* view, const char* name, const BNNameSpace* nameSpace); diff --git a/binaryview.cpp b/binaryview.cpp index 85d09721..97f4a542 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -274,6 +274,20 @@ Ref Symbol::ImportedFunctionFromImportAddressSymbol(Symbol* sym, uint64_ } +vector Symbol::GetAliases() const +{ + vector result; + size_t count = 0; + char** aliases = BNGetSymbolAliases(m_object, &count); + result.reserve(count); + for (size_t i = 0; i < count; i++) + result.push_back(aliases[i]); + + BNFreeStringList(aliases, count); + return result; +} + + AnalysisCompletionEvent::AnalysisCompletionEvent(BinaryView* view, const std::function& callback): m_callback(callback) { diff --git a/python/types.py b/python/types.py index 8880d152..b3403f6d 100644 --- a/python/types.py +++ b/python/types.py @@ -255,6 +255,20 @@ class Symbol(object): def auto(self): return core.BNIsSymbolAutoDefined(self.handle) + @property + def aliases(self): + """ + List of aliases tied to this symbol. + Aliases are the names of any other symbols that also happen to be at the same address. + """ + result = [] + count = ctypes.c_ulonglong(0) + aliases = core.BNGetSymbolAliases(self.handle, count) + for i in range(count.value): + result.append(aliases[i]) + core.BNFreeStringList(aliases, count) + return result + def __repr__(self): return "<%s: \"%s\" @ %#x>" % (self.type, self.full_name, self.address) -- cgit v1.3.1