summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorPeter LaFosse <peter@vector35.com>2021-11-29 09:23:53 -0500
committerPeter LaFosse <peter@vector35.com>2021-11-29 11:39:13 -0500
commitbbf4d616ebdec77538832c1353b8e200a1ad9bbf (patch)
tree9e9562c4538841753ad601a359bc8960842a5bfe /python
parent38a232121c233225860fec8fa929ebeb555dad88 (diff)
Better handling of symbols whose raw names are obfuscated
Diffstat (limited to 'python')
-rw-r--r--python/binaryview.py7
-rw-r--r--python/types.py16
2 files changed, 20 insertions, 3 deletions
diff --git a/python/binaryview.py b/python/binaryview.py
index a931ee0b..eda67c03 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -1287,7 +1287,7 @@ class SymbolMapping(collections.abc.Mapping): # type: ignore
def __init__(self, view:'BinaryView'):
self._symbol_list = None
self._count = None
- self._symbol_cache:Optional[Mapping[str, List[_types.CoreSymbol]]] = None
+ self._symbol_cache:Optional[Mapping[bytes, List[_types.CoreSymbol]]] = None
self._view = view
self._n = 0
@@ -1317,7 +1317,10 @@ class SymbolMapping(collections.abc.Mapping): # type: ignore
_handle = core.BNNewSymbolReference(self._symbol_list[i])
assert _handle is not None, "core.BNNewSymbolReference returned None"
sym = _types.CoreSymbol(_handle)
- self._symbol_cache[sym.raw_name].append(sym)
+ try:
+ self._symbol_cache[sym.raw_name].append(sym)
+ except UnicodeDecodeError:
+ self._symbol_cache[sym.raw_bytes].append(sym)
def __iter__(self):
if self._symbol_cache is None:
diff --git a/python/types.py b/python/types.py
index 4dbd9174..40a49ba8 100644
--- a/python/types.py
+++ b/python/types.py
@@ -218,7 +218,10 @@ class CoreSymbol:
core.BNFreeSymbol(self._handle)
def __repr__(self):
- return f"<{self.type.name}: \"{self.full_name}\" @ {self.address:#x}>"
+ try:
+ return f"<{self.type.name}: \"{self.full_name}\" @ {self.address:#x}>"
+ except UnicodeDecodeError:
+ return f"<{self.type.name}: \"{self.raw_bytes}\" @ {self.address:#x}>"
def __eq__(self, other):
if not isinstance(other, self.__class__):
@@ -272,6 +275,17 @@ class CoreSymbol:
return core.BNGetSymbolRawName(self._handle)
@property
+ def raw_bytes(self) -> bytes:
+ """Bytes of the raw symbol (read-only)"""
+ count = ctypes.c_ulonglong()
+ result = core.BNGetSymbolRawBytes(self._handle, count)
+ assert result is not None, "core.BNGetSymbolRawBytes returned None"
+ buf = ctypes.create_string_buffer(count.value)
+ ctypes.memmove(buf, result, count.value)
+ core.BNFreeSymbolRawBytes(result)
+ return buf.raw
+
+ @property
def address(self) -> int:
"""Symbol address (read-only)"""
return core.BNGetSymbolAddress(self._handle)