summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorplafosse <peter@vector35.com>2016-08-25 00:22:43 +0100
committerplafosse <peter@vector35.com>2016-10-09 13:53:16 -0400
commit1584c0f2ae591eafe6b69a9d663dbff4d32beaff (patch)
tree618575b223e3125b7250759e0a36f1d86d1e67f2
parent55ac7a184b7956c0c2e2ca41d512e7c4a81267d9 (diff)
adding gnu3 demangler apis
-rw-r--r--binaryninjaapi.h12
-rw-r--r--binaryninjacore.h23
-rw-r--r--demangle.cpp20
-rw-r--r--python/__init__.py19
-rw-r--r--type.cpp46
5 files changed, 118 insertions, 2 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index b115263c..ed714be6 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -1449,6 +1449,7 @@ namespace BinaryNinja
};
class Structure;
+ class UnknownType;
class Enumeration;
struct NameAndType
@@ -1476,6 +1477,8 @@ namespace BinaryNinja
bool CanReturn() const;
Ref<Structure> GetStructure() const;
Ref<Enumeration> GetEnumeration() const;
+ Ref<UnknownType> GetUnknownType() const;
+
uint64_t GetElementCount() const;
void SetFunctionCanReturn(bool canReturn);
@@ -1492,6 +1495,7 @@ namespace BinaryNinja
static Ref<Type> IntegerType(size_t width, bool sign, const std::string& altName = "");
static Ref<Type> FloatType(size_t width, const std::string& typeName = "");
static Ref<Type> StructureType(Structure* strct);
+ static Ref<Type> UnknownNamedType(UnknownType* unknwn);
static Ref<Type> EnumerationType(Architecture* arch, Enumeration* enm, size_t width = 0, bool issigned = false);
static Ref<Type> PointerType(Architecture* arch, Type* type, bool cnst = false, bool vltl = false,
BNReferenceType refType = PointerReferenceType);
@@ -1502,6 +1506,14 @@ namespace BinaryNinja
static std::string GetQualifiedName(const std::vector<std::string>& names);
};
+ class UnknownType: public CoreRefCountObject<BNUnknownType, BNNewUnknownTypeReference, BNFreeUnknownType>
+ {
+ public:
+ UnknownType(BNUnknownType* s, std::vector<std::string> name = {});
+ std::vector<std::string> GetName() const;
+ void SetName(const std::vector<std::string>& name);
+ };
+
struct StructureMember
{
Ref<Type> type;
diff --git a/binaryninjacore.h b/binaryninjacore.h
index b6d2f7ed..e841b2d7 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -94,6 +94,7 @@ extern "C"
struct BNLowLevelILFunction;
struct BNType;
struct BNStructure;
+ struct BNUnknownType;
struct BNEnumeration;
struct BNCallingConvention;
struct BNPlatform;
@@ -355,7 +356,8 @@ extern "C"
ArrayTypeClass = 7,
FunctionTypeClass = 8,
VarArgsTypeClass = 9,
- ValueTypeClass = 10
+ ValueTypeClass = 10,
+ UnknownTypeClass = 11
};
enum BNStructureType
@@ -471,7 +473,11 @@ extern "C"
RttiBaseClassDescriptor,
RttiBaseClassArray,
RttiClassHeirarchyDescriptor,
- RttiCompleteObjectLocator
+ RttiCompleteObjectLocator,
+ OperatorUnaryMinusNameType,
+ OperatorUnaryPlusNameType,
+ OperatorUnaryBitAndNameType,
+ OperatorUnaryStarNameType
};
enum BNCallingConventionName
@@ -1878,6 +1884,13 @@ extern "C"
BINARYNINJACOREAPI char* BNGetTypeStringBeforeName(BNType* type);
BINARYNINJACOREAPI char* BNGetTypeStringAfterName(BNType* type);
+ BINARYNINJACOREAPI BNType* BNCreateUnknownNamedType(BNUnknownType* ut);
+ BINARYNINJACOREAPI BNUnknownType* BNCreateUnknownType(void);
+ BINARYNINJACOREAPI void BNSetUnknownTypeName(BNUnknownType* ut, const char** name, size_t size);
+ BINARYNINJACOREAPI char** BNGetUnknownTypeName(BNUnknownType* ut, size_t* size);
+ BINARYNINJACOREAPI void BNFreeUnknownType(BNUnknownType* ut);
+ BINARYNINJACOREAPI BNUnknownType* BNNewUnknownTypeReference(BNUnknownType* ut);
+
BINARYNINJACOREAPI BNStructure* BNCreateStructure(void);
BINARYNINJACOREAPI BNStructure* BNNewStructureReference(BNStructure* s);
BINARYNINJACOREAPI void BNFreeStructure(BNStructure* s);
@@ -2143,6 +2156,12 @@ extern "C"
BINARYNINJACOREAPI BNMessageBoxButtonResult BNShowMessageBox(const char* title, const char* text,
BNMessageBoxButtonSet buttons, BNMessageBoxIcon icon);
+ BINARYNINJACOREAPI bool BNDemangleGNU3(BNArchitecture* arch,
+ const char* mangledName,
+ BNType** outType,
+ char*** outVarName,
+ size_t* outVarNameElements);
+ BINARYNINJACOREAPI void BNFreeDemangledName(char*** name, size_t nameElements);
#ifdef __cplusplus
}
#endif
diff --git a/demangle.cpp b/demangle.cpp
index 1a998a87..a12303ca 100644
--- a/demangle.cpp
+++ b/demangle.cpp
@@ -21,3 +21,23 @@ bool DemangleMS(Architecture* arch,
delete [] localVarName;
return true;
}
+
+
+bool DemangleGNU3(Architecture* arch,
+ const std::string& mangledName,
+ Type** outType,
+ std::vector<std::string>& outVarName)
+{
+ BNType* localType = (*outType)->GetObject();
+ char** localVarName = nullptr;
+ size_t localSize = 0;
+ if (!BNDemangleGNU3(arch->GetObject(), mangledName.c_str(), &localType, &localVarName, &localSize))
+ return false;
+ for (size_t i = 0; i < localSize; i++)
+ {
+ outVarName.push_back(localVarName[i]);
+ BNFreeString(localVarName[i]);
+ }
+ delete [] localVarName;
+ return true;
+}
diff --git a/python/__init__.py b/python/__init__.py
index 26c8fb5d..f5a46798 100644
--- a/python/__init__.py
+++ b/python/__init__.py
@@ -4151,6 +4151,10 @@ class Type(object):
return Type(core.BNCreateUnknownType(unknown_type.handle))
@classmethod
+ def unknown_type(self, s):
+ return Type(core.BNCreateUnknownType(s.handle))
+
+ @classmethod
def enumeration_type(self, arch, e, width = None):
if width is None:
width = arch.default_int_size
@@ -10839,6 +10843,21 @@ def demangle_ms(arch, mangled_name):
names.append(outName[i])
#core.BNFreeDemangledName(outName.value, outSize.value)
return (Type(handle), names)
+ return (None, mangledName)
+
+
+def demangle_gnu3(arch, mangledName):
+ handle = ctypes.POINTER(core.BNType)()
+ outName = ctypes.POINTER(ctypes.c_char_p)()
+ outSize = ctypes.c_ulonglong()
+ names = []
+ if core.BNDemangleGNU3(arch.handle, mangledName, ctypes.byref(handle), ctypes.byref(outName), ctypes.byref(outSize)):
+ for i in xrange(outSize.value):
+ names.append(outName[i])
+ #core.BNFreeDemangledName(outName.value, outSize.value)
+ if not handle:
+ return (None, names)
+ return (Type(handle), names)
return (None, mangled_name)
diff --git a/type.cpp b/type.cpp
index 34e142b6..e0235664 100644
--- a/type.cpp
+++ b/type.cpp
@@ -235,6 +235,12 @@ Ref<Type> Type::StructureType(Structure* strct)
}
+Ref<Type> Type::UnknownNamedType(UnknownType* unknwn)
+{
+ return new Type(BNCreateUnknownNamedType(unknwn->GetObject()));
+}
+
+
Ref<Type> Type::EnumerationType(Architecture* arch, Enumeration* enm, size_t width, bool isSigned)
{
return new Type(BNCreateEnumerationType(arch->GetObject(), enm->GetObject(), width, isSigned));
@@ -277,6 +283,46 @@ void Type::SetFunctionCanReturn(bool canReturn)
}
+UnknownType::UnknownType(BNUnknownType* ut, vector<string> names)
+{
+ m_object = ut;
+ const char ** nameList = new const char*[names.size()];
+ for (size_t i = 0; i < names.size(); i++)
+ {
+ nameList[i] = names[i].c_str();
+ }
+ BNSetUnknownTypeName(ut, nameList, names.size());
+ delete [] nameList;
+}
+
+
+void UnknownType::SetName(const vector<string>& names)
+{
+ const char ** nameList = new const char*[names.size()];
+ for (size_t i = 0; i < names.size(); i++)
+ {
+ nameList[i] = names[i].c_str();
+ }
+ BNSetUnknownTypeName(m_object, nameList, names.size());
+ delete [] nameList;
+}
+
+
+vector<string> UnknownType::GetName() const
+{
+ size_t size;
+ char** name = BNGetUnknownTypeName(m_object, &size);
+ vector<string> result;
+ for (size_t i = 0; i < size; i++)
+ {
+ result.push_back(name[i]);
+ BNFreeString(name[i]);
+ }
+ delete [] name;
+ return result;
+}
+
+
Structure::Structure(BNStructure* s)
{
m_object = s;