summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorGlenn Smith <glenn@vector35.com>2022-08-08 21:49:30 -0400
committerGlenn Smith <glenn@vector35.com>2022-08-08 21:49:30 -0400
commitf49ae00f6d15a81876788df15f1678619a4c791d (patch)
tree8d83d59511980bd49e60fe4a9e4be13865913037 /python
parent116dc31f9905b1d003c9530dedd28d70d99c338c (diff)
Un-deprecate BinaryView.symbols(), and raise KeyError like a real dict
Diffstat (limited to 'python')
-rw-r--r--python/binaryview.py21
1 files changed, 16 insertions, 5 deletions
diff --git a/python/binaryview.py b/python/binaryview.py
index 0870aff3..fe182925 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -1509,7 +1509,10 @@ class SymbolMapping(collections.abc.Mapping): # type: ignore
def __getitem__(self, key):
if self._symbol_cache is None:
- return self._view.get_symbols_by_raw_name(key)
+ sym = self._view.get_symbols_by_raw_name(key)
+ if len(sym) == 0:
+ raise KeyError(f"'{key}': symbol not found")
+ return sym
else:
return self._symbol_cache[key]
@@ -1556,7 +1559,7 @@ class SymbolMapping(collections.abc.Mapping): # type: ignore
def __contains__(self, value):
try:
- self[value]
+ _ = self[value]
return True
except KeyError:
return False
@@ -2398,13 +2401,21 @@ class BinaryView:
return _function.Function(self, func)
@property
- @decorators.deprecated
def symbols(self) -> SymbolMapping:
"""
Dict of symbols (read-only)
+ Items in the dict are lists of all symbols matching that name.
+ :Example:
+
+ >>> bv.symbols['_main']
+ [<FunctionSymbol: "_main" @ 0x1dd0>]
+ >>> list(bv.symbols)
+ ['_start', '_main', '_printf', '_scanf', ...]
+ >>> bv.symbols['foo']
+ KeyError: "'foo': symbol not found"
- .. warning:: This method **should not** be used in any applications where speed is important as it \
- copies all symbols from the binaryview each time it is invoked.
+ :return: Dict-like generator of symbol names and values
+ :rtype: Generator[str, None, None]
"""
return SymbolMapping(self)