diff options
| -rw-r--r-- | binaryninjaapi.h | 13 | ||||
| -rw-r--r-- | binaryninjacore.h | 26 | ||||
| -rw-r--r-- | demangle.cpp | 20 | ||||
| -rw-r--r-- | docs/about/open-source.md | 11 | ||||
| -rw-r--r-- | python/__init__.py | 31 | ||||
| -rw-r--r-- | python/examples/angr_plugin.py | 12 | ||||
| -rw-r--r-- | type.cpp | 46 |
7 files changed, 144 insertions, 15 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index ee1c9c0e..7c297f73 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -21,6 +21,7 @@ #pragma once #ifdef WIN32 +#define NOMINMAX #include <windows.h> #endif #include <stddef.h> @@ -1489,6 +1490,7 @@ namespace BinaryNinja }; class Structure; + class UnknownType; class Enumeration; struct NameAndType @@ -1516,6 +1518,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); @@ -1532,6 +1536,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); @@ -1542,6 +1547,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 281850a2..ac615922 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; @@ -362,7 +363,8 @@ extern "C" ArrayTypeClass = 7, FunctionTypeClass = 8, VarArgsTypeClass = 9, - ValueTypeClass = 10 + ValueTypeClass = 10, + UnknownTypeClass = 11 }; enum BNStructureType @@ -391,7 +393,8 @@ extern "C" { PointerReferenceType = 0, ReferenceReferenceType = 1, - RValueReferenceType = 2 + RValueReferenceType = 2, + NoReference = 3 }; enum BNPointerSuffix @@ -478,7 +481,11 @@ extern "C" RttiBaseClassDescriptor, RttiBaseClassArray, RttiClassHeirarchyDescriptor, - RttiCompleteObjectLocator + RttiCompleteObjectLocator, + OperatorUnaryMinusNameType, + OperatorUnaryPlusNameType, + OperatorUnaryBitAndNameType, + OperatorUnaryStarNameType }; enum BNCallingConventionName @@ -1953,6 +1960,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); @@ -2218,6 +2232,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/docs/about/open-source.md b/docs/about/open-source.md index c3663e6b..dcebbfa5 100644 --- a/docs/about/open-source.md +++ b/docs/about/open-source.md @@ -25,6 +25,11 @@ The previous tools are used in the generation of our documentation, but are not - [zlib] ([zlib license] - zlib license) - [openssl] ([openssl license] - openssl license) - [discount] ([discount license] - BSD) + - [sqlite] ([sqlite license] - public domain) + - [llvm] ([llvm license] - BSD-style) + +* Other + - [yasm] ([yasm license] - 2-clause BSD) * Upvector update Library - [tomcrypt] ([tomcrypt license] - public domain) @@ -63,6 +68,12 @@ Please note that we offer no support for running Binary Ninja with modified Qt l [lzf license]: http://oldhome.schmorp.de/marc/liblzf.html [discount]: http://www.pell.portland.or.us/~orc/Code/discount/ [discount license]: http://www.pell.portland.or.us/~orc/Code/discount/COPYRIGHT.html +[sqlite]: https://www.sqlite.org/index.html +[sqlite license]: https://www.sqlite.org/copyright.html +[llvm]: http://llvm.org/releases/3.8.1/ +[llvm license]: http://llvm.org/releases/3.8.1/LICENSE.TXT +[yasm]: http://yasm.tortall.net/ +[yasm license]: https://github.com/yasm/yasm/blob/master/BSD.txt [zlib]: http://www.zlib.net/ [zlib license]: http://www.zlib.net/zlib_license.html [openssl]: https://www.openssl.org/ diff --git a/python/__init__.py b/python/__init__.py index af5e0b55..70267678 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -243,7 +243,7 @@ class FileMetadata(object): del cls._associated_data[handle.value] @classmethod - def set_default_data(cls, name, value): + def set_default_session_data(cls, name, value): _FileMetadataAssociatedDataStore.set_default(name, value) @property @@ -324,7 +324,7 @@ class FileMetadata(object): self.nav = value @property - def data(self): + def session_data(self): """Dictionary object where plugins can store arbitrary data associated with the file""" handle = ctypes.cast(self.handle, ctypes.c_void_p) if handle.value not in FileMetadata._associated_data: @@ -1156,7 +1156,7 @@ class BinaryView(object): del cls._associated_data[handle.value] @classmethod - def set_default_data(cls, name, value): + def set_default_session_data(cls, name, value): _BinaryViewAssociatedDataStore.set_default(name, value) def __del__(self): @@ -1415,7 +1415,7 @@ class BinaryView(object): return result @property - def data(self): + def session_data(self): """Dictionary object where plugins can store arbitrary data associated with the view""" handle = ctypes.cast(self.handle, ctypes.c_void_p) if handle.value not in BinaryView._associated_data: @@ -4320,6 +4320,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 @@ -4754,7 +4758,7 @@ class Function(object): del cls._associated_data[handle.value] @classmethod - def set_default_data(cls, name, value): + def set_default_session_data(cls, name, value): _FunctionAssociatedDataStore.set_default(name, value) @property @@ -4882,7 +4886,7 @@ class Function(object): return result @property - def data(self): + def session_data(self): """Dictionary object where plugins can store arbitrary data associated with the function""" handle = ctypes.cast(self.handle, ctypes.c_void_p) if handle.value not in Function._associated_data: @@ -11008,6 +11012,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/python/examples/angr_plugin.py b/python/examples/angr_plugin.py index 5d567511..c6e6f87d 100644 --- a/python/examples/angr_plugin.py +++ b/python/examples/angr_plugin.py @@ -21,8 +21,8 @@ import os logging.disable(logging.WARNING) # Create sets in the BinaryView's data field to store the desired path for each view -BinaryView.set_default_data("angr_find", set()) -BinaryView.set_default_data("angr_avoid", set()) +BinaryView.set_default_session_data("angr_find", set()) +BinaryView.set_default_session_data("angr_avoid", set()) def escaped_output(str): return '\n'.join([s.encode("string_escape") for s in str.split('\n')]) @@ -89,7 +89,7 @@ def find_instr(bv, addr): block.function.set_auto_instr_highlight(block.arch, addr, GreenHighlightColor) # Add the instruction to the list associated with the current view - bv.data.angr_find.add(addr) + bv.session_data.angr_find.add(addr) def avoid_instr(bv, addr): # Highlight the instruction in red @@ -99,17 +99,17 @@ def avoid_instr(bv, addr): block.function.set_auto_instr_highlight(block.arch, addr, RedHighlightColor) # Add the instruction to the list associated with the current view - bv.data.angr_avoid.add(addr) + bv.session_data.angr_avoid.add(addr) def solve(bv): - if len(bv.data.angr_find) == 0: + if len(bv.session_data.angr_find) == 0: show_message_box("Angr Solve", "You have not specified a goal instruction.\n\n" + "Please right click on the goal instruction and select \"Find Path to This Instruction\" to " + "continue.", OKButtonSet, ErrorIcon) return # Start a solver thread for the path associated with the view - s = Solver(bv.data.angr_find, bv.data.angr_avoid, bv) + s = Solver(bv.session_data.angr_find, bv.session_data.angr_avoid, bv) s.start() # Register commands for the user to interact with the plugin @@ -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; |
