summaryrefslogtreecommitdiff
path: root/python/externallibrary.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/externallibrary.py')
-rw-r--r--python/externallibrary.py112
1 files changed, 91 insertions, 21 deletions
diff --git a/python/externallibrary.py b/python/externallibrary.py
index 8164465a..c4aa0528 100644
--- a/python/externallibrary.py
+++ b/python/externallibrary.py
@@ -29,6 +29,9 @@ from . import types
class ExternalLibrary:
+ """
+ An ExternalLibrary is an abstraction for a library that is optionally backed by a ProjectFile.
+ """
def __init__(self, handle: core.BNExternalLibrary):
self._handle = handle
@@ -44,10 +47,20 @@ class ExternalLibrary:
@property
def name(self) -> str:
+ """
+ Get the name of this external library
+
+ :return: The name of this external library
+ """
return core.BNExternalLibraryGetName(self._handle) # type: ignore
@property
def backing_file(self) -> Optional[project.ProjectFile]:
+ """
+ Get the file backing this external library
+
+ :return: The file backing this external library or None
+ """
handle = core.BNExternalLibraryGetBackingFile(self._handle)
if handle is None:
return None
@@ -55,6 +68,11 @@ class ExternalLibrary:
@backing_file.setter
def backing_file(self, new_file: Optional[project.ProjectFile]):
+ """
+ Set the file backing this external library
+
+ :param new_file: The file that will back this external library
+ """
new_file_handle = None
if new_file is not None:
new_file_handle = new_file._handle
@@ -62,6 +80,9 @@ class ExternalLibrary:
class ExternalLocation:
+ """
+ An ExternalLocation is an association from a source symbol in a binary view to a target symbol and/or address in an ExternalLibrary.
+ """
def __init__(self, handle: core.BNExternalLocation):
self._handle = handle
@@ -70,50 +91,94 @@ class ExternalLocation:
core.BNFreeExternalLocation(self._handle)
def __repr__(self) -> str:
- return f'<ExternalLocation: {self.internal_symbol}>'
+ return f'<ExternalLocation: {self.source_symbol}>'
def __str__(self) -> str:
- return f'<ExternalLocation: {self.internal_symbol}>'
+ return f'<ExternalLocation: {self.source_symbol}>'
@property
- def internal_symbol(self) -> 'types.CoreSymbol':
- sym = core.BNExternalLocationGetInternalSymbol(self._handle)
- assert sym is not None, "core.BNExternalLocationGetInternalSymbol returned None"
+ def source_symbol(self) -> 'types.CoreSymbol':
+ """
+ Get the source symbol for this ExternalLocation
+
+ :return: The source symbol for this ExternalLocation
+ """
+ sym = core.BNExternalLocationGetSourceSymbol(self._handle)
+ assert sym is not None, "core.BNExternalLocationGetSourceSymbol returned None"
return types.CoreSymbol(sym)
@property
- def has_address(self) -> bool:
- return core.BNExternalLocationHasAddress(self._handle)
+ def has_target_address(self) -> bool:
+ """
+ Check if this ExternalLocation has a target address
+
+ :return: True is this ExternalLocation has a target address, False otherwise
+ """
+ return core.BNExternalLocationHasTargetAddress(self._handle)
@property
- def has_symbol(self) -> bool:
- return core.BNExternalLocationHasSymbol(self._handle)
+ def has_target_symbol(self) -> bool:
+ """
+ Check if this ExternalLocation has a target symbol
+
+ :return: True is this ExternalLocation has a target symbol, False otherwise
+ """
+ return core.BNExternalLocationHasTargetSymbol(self._handle)
@property
- def address(self) -> Optional[int]:
- if not self.has_address:
+ def target_address(self) -> Optional[int]:
+ """
+ Get the address pointed to by this ExternalLocation
+
+ :return: The address pointed to by this ExternalLocation if one exists, None otherwise
+ """
+ if not self.has_target_address:
return None
- return core.BNExternalLocationGetAddress(self._handle)
+ return core.BNExternalLocationGetTargetAddress(self._handle)
+
+ @target_address.setter
+ def target_address(self, new_address: Optional[int]) -> bool:
+ """
+ Set the address pointed to by this ExternalLocation.
+ ExternalLocations must have a valid target address and/or symbol set.
- @address.setter
- def address(self, new_address: Optional[int]):
+ :param new_address: The address that this ExternalLocation will point to
+ :return: True if the address was set, False otherwise
+ """
c_addr = None
if new_address is not None:
c_addr = ctypes.c_ulonglong(new_address)
- return core.BNExternalLocationSetAddress(self._handle, c_addr)
+ return core.BNExternalLocationSetTargetAddress(self._handle, c_addr)
@property
- def symbol(self) -> Optional[str]:
- if not self.has_symbol:
+ def target_symbol(self) -> Optional[str]:
+ """
+ Get the symbol pointed to by this ExternalLocation
+
+ :return: The symbol pointed to by this ExternalLocation if one exists, None otherwise
+ """
+ if not self.has_target_symbol:
return None
- return core.BNExternalLocationGetSymbol(self._handle)
+ return core.BNExternalLocationGetTargetSymbol(self._handle)
- @symbol.setter
- def symbol(self, new_symbol: Optional[str]):
- return core.BNExternalLocationSetSymbol(self._handle, new_symbol)
+ @target_symbol.setter
+ def target_symbol(self, new_symbol: Optional[str]) -> bool:
+ """
+ Set the symbol pointed to by this ExternalLocation.
+ ExternalLocations must have a valid target address and/or symbol set.
+
+ :param new_symbol: The raw symbol that this ExternalLocation will point to
+ :return: True if the symbol was set, False otherwise
+ """
+ return core.BNExternalLocationSetTargetSymbol(self._handle, new_symbol)
@property
def library(self) -> Optional[ExternalLibrary]:
+ """
+ Get the ExternalLibrary that this ExternalLocation targets
+
+ :return: The ExternalLibrary pointed in to by this ExternalLocation if one exists, None otherwise
+ """
handle = core.BNExternalLocationGetExternalLibrary(self._handle)
if handle is None:
return None
@@ -121,5 +186,10 @@ class ExternalLocation:
@library.setter
def library(self, new_library: Optional[ExternalLibrary]):
+ """
+ Set the ExternalLibrary that this ExternalLocation targets
+
+ :param new_library: The ExternalLibrary that this ExternalLocation will pointed in to
+ """
lib_handle = new_library._handle if new_library is not None else None
return core.BNExternalLocationSetExternalLibrary(self._handle, lib_handle)