Skip to content

Commit

Permalink
Add support for duplicate symbol handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
bpotchik committed Apr 6, 2021
1 parent 1f70e70 commit ccc46ee
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 49 deletions.
1 change: 0 additions & 1 deletion binaryninjaapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,6 @@ __attribute__ ((format (printf, 1, 2)))
uint64_t GetOrdinal() const;
bool IsAutoDefined() const;
NameSpace GetNameSpace() const;
std::vector<std::string> GetAliases() const;

static Ref<Symbol> ImportedFunctionFromImportAddressSymbol(Symbol* sym, uint64_t addr);
};
Expand Down
1 change: 0 additions & 1 deletion binaryninjacore.h
Original file line number Diff line number Diff line change
Expand Up @@ -3819,7 +3819,6 @@ __attribute__ ((format (printf, 1, 2)))
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);
Expand Down
14 changes: 0 additions & 14 deletions binaryview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,20 +341,6 @@ Ref<Symbol> Symbol::ImportedFunctionFromImportAddressSymbol(Symbol* sym, uint64_
}


vector<string> Symbol::GetAliases() const
{
vector<string> 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<void()>& callback):
m_callback(callback)
{
Expand Down
11 changes: 1 addition & 10 deletions examples/triage/imports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,7 @@ QVariant GenericImportsModel::data(const QModelIndex& index, int role) const
if (index.column() == 0)
return QString("0x") + QString::number(m_entries[index.row()]->GetAddress(), 16);
if (index.column() == m_nameCol)
{
QString name = QString::fromStdString(m_entries[index.row()]->GetFullName());
if (name.endsWith("@GOT"))
name = name.mid(0, name.size() - (int)strlen("@GOT"));
else if (name.endsWith("@PLT"))
name = name.mid(0, name.size() - (int)strlen("@PLT"));
else if (name.endsWith("@IAT"))
name = name.mid(0, name.size() - (int)strlen("@IAT"));
return name;
}
return QString::fromStdString(m_entries[index.row()]->GetFullName());
if (index.column() == m_moduleCol)
return getNamespace(m_entries[index.row()]);
if (index.column() == m_ordinalCol)
Expand Down
13 changes: 5 additions & 8 deletions python/binaryview.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import json
import inspect

from collections import OrderedDict
from collections import defaultdict, OrderedDict

# Binary Ninja components
from binaryninja import _binaryninjacore as core
Expand Down Expand Up @@ -1912,13 +1912,10 @@ def symbols(self):
"""Dict of symbols (read-only)"""
count = ctypes.c_ulonglong(0)
syms = core.BNGetSymbols(self.handle, count, None)
result = {}
result = defaultdict(list)
for i in range(0, count.value):
sym = types.Symbol(None, None, None, handle=core.BNNewSymbolReference(syms[i]))
if sym.raw_name in result:
result[sym.raw_name] = [result[sym.raw_name], sym]
else:
result[sym.raw_name] = sym
result[sym.raw_name].append(sym)
core.BNFreeSymbolList(syms, count.value)
return result

Expand Down Expand Up @@ -3875,7 +3872,7 @@ def get_symbols(self, start=None, length=None, namespace=None):
:Example:
>>> bv.get_symbols(0x1000200c, 1)
[<ImportAddressSymbol: "KERNEL32!IsProcessorFeaturePresent@IAT" @ 0x1000200c>]
[<ImportAddressSymbol: "KERNEL32!IsProcessorFeaturePresent" @ 0x1000200c>]
>>>
"""
count = ctypes.c_ulonglong(0)
Expand Down Expand Up @@ -3906,7 +3903,7 @@ def get_symbols_of_type(self, sym_type, start=None, length=None, namespace=None)
:Example:
>>> bv.get_symbols_of_type(SymbolType.ImportAddressSymbol, 0x10002028, 1)
[<ImportAddressSymbol: "KERNEL32!GetCurrentThreadId@IAT" @ 0x10002028>]
[<ImportAddressSymbol: "KERNEL32!GetCurrentThreadId" @ 0x10002028>]
>>>
"""
if isinstance(sym_type, str):
Expand Down
16 changes: 1 addition & 15 deletions python/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def __init__(self, name, offset, ref_type):
self._name = name
self._offset = offset
self._ref_type = ref_type

def __str__(self):
if self.ref_type == TypeReferenceType.DirectTypeReferenceType:
s = 'direct'
Expand Down Expand Up @@ -354,20 +354,6 @@ def ordinal(self):
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


class FunctionParameter(object):
def __init__(self, param_type, name = "", location = None):
Expand Down

0 comments on commit ccc46ee

Please sign in to comment.