summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorPeter LaFosse <peter@vector35.com>2018-10-14 21:37:09 -0400
committerPeter LaFosse <peter@vector35.com>2018-10-15 23:18:23 -0400
commit7006bdf444f2b9533bcc3aee2933ba7ff8e70d2e (patch)
treed4af914aa4b4ebad400106a278a7ed6791a66ff4 /python
parent50b3ff664665a6186d6d82364a0845d544ec8fac (diff)
Refactor to how symbols and namespaces work
Diffstat (limited to 'python')
-rw-r--r--python/binaryview.py54
-rw-r--r--python/types.py8
2 files changed, 21 insertions, 41 deletions
diff --git a/python/binaryview.py b/python/binaryview.py
index ecb25503..fe7a9dc9 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -1060,24 +1060,25 @@ class BinaryView(object):
core.BNFreeSymbolList(syms, count.value)
return result
- @property
+ @classmethod
def internal_namespace(self):
"""Internal namespace for the current BinaryView"""
- ns = core.BNGetInternalNameSpace(self.handle)
+ ns = core.BNGetInternalNameSpace()
result = types.NameSpace._from_core_struct(ns)
core.BNFreeNameSpace(ns)
return result
- @property
+ @classmethod
def external_namespace(self):
"""External namespace for the current BinaryView"""
- ns = core.BNGetExternalNameSpace(self.handle)
+ ns = core.BNGetExternalNameSpace()
result = types.NameSpace._from_core_struct(ns)
core.BNFreeNameSpace(ns)
return result
@property
def namespaces(self):
+ """Returns a list of namespaces for the current BinaryView"""
count = ctypes.c_ulonglong(0)
nameSpaceList = core.BNGetNameSpaces(self.handle, count)
result = []
@@ -2610,7 +2611,7 @@ class BinaryView(object):
core.BNFreeSymbolList(syms, count.value)
return result
- def define_auto_symbol(self, sym, namespace=None):
+ def define_auto_symbol(self, sym):
"""
``define_auto_symbol`` adds a symbol to the internal list of automatically discovered Symbol objects in a given
namespace.
@@ -2618,16 +2619,11 @@ class BinaryView(object):
.. warning:: If multiple symbols for the same address are defined, only the most recent symbol will ever be used.
:param Symbol sym: the symbol to define
- :param NameSpace namespace: the namespace of the symbol
:rtype: None
"""
- if isinstance(namespace, str):
- namespace = types.NameSpace(namespace)
- if isinstance(namespace, types.NameSpace):
- namespace = namespace._get_core_struct()
- core.BNDefineAutoSymbol(self.handle, sym.handle, namespace)
+ core.BNDefineAutoSymbol(self.handle, sym.handle)
- def define_auto_symbol_and_var_or_function(self, sym, sym_type, plat=None, namespace=None):
+ def define_auto_symbol_and_var_or_function(self, sym, sym_type, plat=None):
"""
``define_auto_symbol_and_var_or_function``
@@ -2636,7 +2632,6 @@ class BinaryView(object):
:param Symbol sym: the symbol to define
:param SymbolType sym_type: Type of symbol being defined
:param Platform plat: (optional) platform
- :param NameSpace namespace: the namespace of the symbol
:rtype: None
"""
if plat is None:
@@ -2645,55 +2640,36 @@ class BinaryView(object):
plat = plat.handle
if sym_type is not None:
sym_type = sym_type.handle
- if isinstance(namespace, str):
- namespace = types.NameSpace(namespace)
- if isinstance(namespace, types.NameSpace):
- namespace = namespace._get_core_struct()
- core.BNDefineAutoSymbolAndVariableOrFunction(self.handle, plat, sym.handle, sym_type, namespace)
+ core.BNDefineAutoSymbolAndVariableOrFunction(self.handle, plat, sym.handle, sym_type)
- def undefine_auto_symbol(self, sym, namespace=None):
+ def undefine_auto_symbol(self, sym):
"""
``undefine_auto_symbol`` removes a symbol from the internal list of automatically discovered Symbol objects.
:param Symbol sym: the symbol to undefine
- :param NameSpace namespace: the namespace of the symbol
:rtype: None
"""
- if isinstance(namespace, str):
- namespace = types.NameSpace(namespace)
- if isinstance(namespace, types.NameSpace):
- namespace = namespace._get_core_struct()
- core.BNUndefineAutoSymbol(self.handle, sym.handle, namespace)
+ core.BNUndefineAutoSymbol(self.handle, sym.handle)
- def define_user_symbol(self, sym, namespace=None):
+ def define_user_symbol(self, sym):
"""
``define_user_symbol`` adds a symbol to the internal list of user added Symbol objects.
.. warning:: If multiple symbols for the same address are defined, only the most recent symbol will ever be used.
:param Symbol sym: the symbol to define
- :param NameSpace namespace: the namespace of the symbol
:rtype: None
"""
- if isinstance(namespace, str):
- namespace = types.NameSpace(namespace)
- if isinstance(namespace, types.NameSpace):
- namespace = namespace._get_core_struct()
- core.BNDefineUserSymbol(self.handle, sym.handle, namespace)
+ core.BNDefineUserSymbol(self.handle, sym.handle)
- def undefine_user_symbol(self, sym, namespace=None):
+ def undefine_user_symbol(self, sym):
"""
``undefine_user_symbol`` removes a symbol from the internal list of user added Symbol objects.
:param Symbol sym: the symbol to undefine
- :param NameSpace namespace: the namespace of the symbol
:rtype: None
"""
- if isinstance(namespace, str):
- namespace = types.NameSpace(namespace)
- if isinstance(namespace, types.NameSpace):
- namespace = namespace._get_core_struct()
- core.BNUndefineUserSymbol(self.handle, sym.handle, namespace)
+ core.BNUndefineUserSymbol(self.handle, sym.handle)
def define_imported_function(self, import_addr_sym, func):
"""
diff --git a/python/types.py b/python/types.py
index 72a39378..c7ebaf19 100644
--- a/python/types.py
+++ b/python/types.py
@@ -154,7 +154,7 @@ class Symbol(object):
ExternalSymbol Symbols for data and code that reside outside the BinaryView
=========================== ==============================================================
"""
- def __init__(self, sym_type, addr, short_name, full_name=None, raw_name=None, handle=None, binding=None):
+ def __init__(self, sym_type, addr, short_name, full_name=None, raw_name=None, handle=None, binding=None, namespace=None):
if handle is not None:
self.handle = core.handle_of_type(handle, core.BNSymbol)
else:
@@ -166,7 +166,11 @@ class Symbol(object):
raw_name = full_name
if binding is None:
binding = SymbolBinding.NoBinding
- self.handle = core.BNCreateSymbol(sym_type, short_name, full_name, raw_name, addr, binding)
+ if isinstance(namespace, str):
+ namespace = NameSpace(namespace)
+ if isinstance(namespace, NameSpace):
+ namespace = namespace._get_core_struct()
+ self.handle = core.BNCreateSymbol(sym_type, short_name, full_name, raw_name, addr, binding, namespace)
def __del__(self):
core.BNFreeSymbol(self.handle)