summaryrefslogtreecommitdiff
path: root/python/demangle.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/demangle.py')
-rw-r--r--python/demangle.py24
1 files changed, 11 insertions, 13 deletions
diff --git a/python/demangle.py b/python/demangle.py
index 6f007a7b..db0bde1d 100644
--- a/python/demangle.py
+++ b/python/demangle.py
@@ -21,13 +21,9 @@
import ctypes
# Binary Ninja components
-from binaryninja import _binaryninjacore as core
-from binaryninja.binaryview import BinaryView
-from binaryninja import types
-
-# 2-3 compatibility
-from binaryninja import range
-from binaryninja import pyNativeStr
+from . import _binaryninjacore as core
+from . import binaryview
+from . import types
def get_qualified_name(names):
@@ -68,11 +64,11 @@ def demangle_ms(arch, mangled_name, options = False):
outName = ctypes.POINTER(ctypes.c_char_p)()
outSize = ctypes.c_ulonglong()
names = []
- if (isinstance(options, BinaryView) and core.BNDemangleMSWithOptions(arch.handle, mangled_name, ctypes.byref(handle), ctypes.byref(outName), ctypes.byref(outSize), options)) or \
+ if (isinstance(options, binaryview.BinaryView) and core.BNDemangleMSWithOptions(arch.handle, mangled_name, ctypes.byref(handle), ctypes.byref(outName), ctypes.byref(outSize), options)) or \
(isinstance(options, bool) and core.BNDemangleMS(arch.handle, mangled_name, ctypes.byref(handle), ctypes.byref(outName), ctypes.byref(outSize), options)) or \
(options is None and core.BNDemangleMSWithOptions(arch.handle, mangled_name, ctypes.byref(handle), ctypes.byref(outName), ctypes.byref(outSize), None)):
for i in range(outSize.value):
- names.append(pyNativeStr(outName[i]))
+ names.append(outName[i].decode('utf8'))
core.BNFreeDemangledName(ctypes.byref(outName), outSize.value)
return (types.Type(handle), names)
return (None, mangled_name)
@@ -93,11 +89,11 @@ def demangle_gnu3(arch, mangled_name, options = None):
outName = ctypes.POINTER(ctypes.c_char_p)()
outSize = ctypes.c_ulonglong()
names = []
- if (isinstance(options, BinaryView) and core.BNDemangleGNU3WithOptions(arch.handle, mangled_name, ctypes.byref(handle), ctypes.byref(outName), ctypes.byref(outSize), options)) or \
+ if (isinstance(options, binaryview.BinaryView) and core.BNDemangleGNU3WithOptions(arch.handle, mangled_name, ctypes.byref(handle), ctypes.byref(outName), ctypes.byref(outSize), options)) or \
(isinstance(options, bool) and core.BNDemangleGNU3(arch.handle, mangled_name, ctypes.byref(handle), ctypes.byref(outName), ctypes.byref(outSize), options)) or \
(options is None and core.BNDemangleGNU3WithOptions(arch.handle, mangled_name, ctypes.byref(handle), ctypes.byref(outName), ctypes.byref(outSize), None)):
for i in range(outSize.value):
- names.append(pyNativeStr(outName[i]))
+ names.append(outName[i].decode('utf8'))
core.BNFreeDemangledName(ctypes.byref(outName), outSize.value)
if not handle:
return (None, names)
@@ -115,7 +111,7 @@ def simplify_name_to_string(input_name):
:rtype: str
:Example:
- >>> bdemangle.simplify_name_to_string("std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >")
+ >>> demangle.simplify_name_to_string("std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >")
'std::string'
>>>
"""
@@ -147,8 +143,10 @@ def simplify_name_to_qualified_name(input_name, simplify = True):
result = None
if isinstance(input_name, str):
result = core.BNRustSimplifyStrToFQN(input_name, simplify)
+ assert result is not None, "core.BNRustSimplifyStrToFQN returned None"
elif isinstance(input_name, types.QualifiedName):
result = core.BNRustSimplifyStrToFQN(str(input_name), True)
+ assert result is not None, "core.BNRustSimplifyStrToFQN returned None"
else:
raise TypeError("Parameter must be of type `str` or `types.QualifiedName`")
@@ -156,7 +154,7 @@ def simplify_name_to_qualified_name(input_name, simplify = True):
for name in result:
if name == b'':
break
- native_result.append(name)
+ native_result.append(name.decode("utf-8"))
name_count = len(native_result)
native_result = types.QualifiedName(native_result)