summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--binaryninjaapi.h18
-rw-r--r--binaryninjacore.h14
-rw-r--r--demangle.cpp16
-rw-r--r--python/demangle.py13
4 files changed, 27 insertions, 34 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index 7e956161..8604e44f 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -700,14 +700,14 @@ __attribute__ ((format (printf, 1, 2)))
void SetCurrentPluginLoadOrder(BNPluginLoadOrder order);
void AddRequiredPluginDependency(const std::string& name);
void AddOptionalPluginDependency(const std::string& name);
- bool DemangleMS(Architecture* arch,
- const std::string& mangledName,
- Type** outType,
- QualifiedName& outVarName);
- bool DemangleGNU3(Ref<Architecture> arch,
- const std::string& mangledName,
- Type** outType,
- QualifiedName& outVarName);
+
+ class BinaryView;
+
+ bool DemangleMS(Architecture* arch, const std::string& mangledName, Type** outType,
+ QualifiedName& outVarName, const Ref<BinaryView>& view);
+ bool DemangleGNU3(Ref<Architecture> arch, const std::string& mangledName, Type** outType,
+ QualifiedName& outVarName, const Ref<BinaryView>& view);
+
void RegisterMainThread(MainThreadActionHandler* handler);
Ref<MainThreadAction> ExecuteOnMainThread(const std::function<void()>& action);
void ExecuteOnMainThreadAndWait(const std::function<void()>& action);
@@ -831,8 +831,6 @@ __attribute__ ((format (printf, 1, 2)))
virtual bool Navigate(const std::string& view, uint64_t offset) = 0;
};
- class BinaryView;
-
class User : public CoreRefCountObject<BNUser, BNNewUserReference, BNFreeUser>
{
private:
diff --git a/binaryninjacore.h b/binaryninjacore.h
index db88c2ff..b13f9fb3 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -4463,11 +4463,8 @@ __attribute__ ((format (printf, 1, 2)))
BINARYNINJACOREAPI BNTypeLibrary** BNGetPlatformTypeLibrariesByName(BNPlatform* platform, char* depName, size_t* count);
//Demangler
- BINARYNINJACOREAPI bool BNDemangleMS(BNArchitecture* arch,
- const char* mangledName,
- BNType** outType,
- char*** outVarName,
- size_t* outVarNameElements);
+ BINARYNINJACOREAPI bool BNDemangleMS(BNArchitecture* arch, const char* mangledName, BNType** outType, char*** outVarName,
+ size_t* outVarNameElements, const BNBinaryView* const view);
// Download providers
BINARYNINJACOREAPI BNDownloadProvider* BNRegisterDownloadProvider(const char* name, BNDownloadProviderCallbacks* callbacks);
@@ -4609,11 +4606,8 @@ __attribute__ ((format (printf, 1, 2)))
const char* title, BNFlowGraph* graph);
BINARYNINJACOREAPI bool BNIsGNU3MangledString(const char* mangledName);
- BINARYNINJACOREAPI bool BNDemangleGNU3(BNArchitecture* arch,
- const char* mangledName,
- BNType** outType,
- char*** outVarName,
- size_t* outVarNameElements);
+ BINARYNINJACOREAPI bool BNDemangleGNU3(BNArchitecture* arch, const char* mangledName, BNType** outType,
+ char*** outVarName, size_t* outVarNameElements, const BNBinaryView* const view);
BINARYNINJACOREAPI void BNFreeDemangledName(char*** name, size_t nameElements);
// Plugin repository APIs
diff --git a/demangle.cpp b/demangle.cpp
index c3867aed..9ea2bfa0 100644
--- a/demangle.cpp
+++ b/demangle.cpp
@@ -4,15 +4,13 @@ using namespace std;
namespace BinaryNinja
{
- bool DemangleMS(Architecture* arch,
- const std::string& mangledName,
- Type** outType,
- QualifiedName& outVarName)
+ bool DemangleMS(Architecture* arch, const std::string& mangledName, Type** outType,
+ QualifiedName& outVarName, const Ref<BinaryView>& view)
{
BNType* localType = nullptr;
char** localVarName = nullptr;
size_t localSize = 0;
- if (!BNDemangleMS(arch->GetObject(), mangledName.c_str(), &localType, &localVarName, &localSize))
+ if (!BNDemangleMS(arch->GetObject(), mangledName.c_str(), &localType, &localVarName, &localSize, view->GetObject()))
return false;
if (!localType)
return false;
@@ -27,15 +25,13 @@ namespace BinaryNinja
}
- bool DemangleGNU3(Ref<Architecture> arch,
- const std::string& mangledName,
- Type** outType,
- QualifiedName& outVarName)
+ bool DemangleGNU3(Ref<Architecture> arch, const std::string& mangledName, Type** outType,
+ QualifiedName& outVarName, const Ref<BinaryView>& view)
{
BNType* localType;
char** localVarName = nullptr;
size_t localSize = 0;
- if (!BNDemangleGNU3(arch->GetObject(), mangledName.c_str(), &localType, &localVarName, &localSize))
+ if (!BNDemangleGNU3(arch->GetObject(), mangledName.c_str(), &localType, &localVarName, &localSize, view->GetObject()))
return false;
if (!localType)
return false;
diff --git a/python/demangle.py b/python/demangle.py
index 6ed4010e..67b211df 100644
--- a/python/demangle.py
+++ b/python/demangle.py
@@ -22,6 +22,7 @@ import ctypes
# Binary Ninja components
from binaryninja import _binaryninjacore as core
+from binaryninja.binaryview import BinaryView
from binaryninja import types
# 2-3 compatibility
@@ -47,7 +48,7 @@ def get_qualified_name(names):
return "::".join(names)
-def demangle_ms(arch, mangled_name):
+def demangle_ms(arch, mangled_name, view = None):
"""
``demangle_ms`` demangles a mangled Microsoft Visual Studio C++ name to a Type object.
@@ -65,7 +66,9 @@ def demangle_ms(arch, mangled_name):
outName = ctypes.POINTER(ctypes.c_char_p)()
outSize = ctypes.c_ulonglong()
names = []
- if core.BNDemangleMS(arch.handle, mangled_name, ctypes.byref(handle), ctypes.byref(outName), ctypes.byref(outSize)):
+ if isinstance(view, BinaryView):
+ view = view.handle
+ if core.BNDemangleMS(arch.handle, mangled_name, ctypes.byref(handle), ctypes.byref(outName), ctypes.byref(outSize), view):
for i in range(outSize.value):
names.append(pyNativeStr(outName[i]))
core.BNFreeDemangledName(ctypes.byref(outName), outSize.value)
@@ -73,12 +76,14 @@ def demangle_ms(arch, mangled_name):
return (None, mangled_name)
-def demangle_gnu3(arch, mangled_name):
+def demangle_gnu3(arch, mangled_name, view = None):
handle = ctypes.POINTER(core.BNType)()
outName = ctypes.POINTER(ctypes.c_char_p)()
outSize = ctypes.c_ulonglong()
names = []
- if core.BNDemangleGNU3(arch.handle, mangled_name, ctypes.byref(handle), ctypes.byref(outName), ctypes.byref(outSize)):
+ if isinstance(view, BinaryView):
+ view = view.handle
+ if core.BNDemangleGNU3(arch.handle, mangled_name, ctypes.byref(handle), ctypes.byref(outName), ctypes.byref(outSize), view):
for i in range(outSize.value):
names.append(pyNativeStr(outName[i]))
core.BNFreeDemangledName(ctypes.byref(outName), outSize.value)