diff options
| -rw-r--r-- | binaryninjaapi.h | 10 | ||||
| -rw-r--r-- | binaryninjacore.h | 18 | ||||
| -rw-r--r-- | platform.cpp | 121 | ||||
| -rw-r--r-- | python/platform.py | 79 |
4 files changed, 228 insertions, 0 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index ed9cedc5..4f3a0275 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -2342,6 +2342,16 @@ namespace BinaryNinja void AddRelatedPlatform(Architecture* arch, Platform* platform); Ref<Platform> GetAssociatedPlatformByAddress(uint64_t& addr); + std::map<QualifiedName, Ref<Type>> GetTypes(); + std::map<QualifiedName, Ref<Type>> GetVariables(); + std::map<QualifiedName, Ref<Type>> GetFunctions(); + std::map<uint32_t, QualifiedNameAndType> GetSystemCalls(); + Ref<Type> GetTypeByName(const QualifiedName& name); + Ref<Type> GetVariableByName(const QualifiedName& name); + Ref<Type> GetFunctionByName(const QualifiedName& name); + std::string GetSystemCallName(uint32_t n); + Ref<Type> GetSystemCallType(uint32_t n); + std::string GenerateAutoPlatformTypeId(const QualifiedName& name); Ref<NamedTypeReference> GenerateAutoPlatformTypeReference(BNNamedTypeReferenceClass cls, const QualifiedName& name); diff --git a/binaryninjacore.h b/binaryninjacore.h index 4b810002..7c4b6db0 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -1220,6 +1220,13 @@ extern "C" uint64_t end; }; + struct BNSystemCallInfo + { + uint32_t number; + BNQualifiedName name; + BNType* type; + }; + BINARYNINJACOREAPI char* BNAllocString(const char* contents); BINARYNINJACOREAPI void BNFreeString(char* str); BINARYNINJACOREAPI void BNFreeStringList(char** strs, size_t count); @@ -2202,6 +2209,17 @@ extern "C" BINARYNINJACOREAPI void BNAddRelatedPlatform(BNPlatform* platform, BNArchitecture* arch, BNPlatform* related); BINARYNINJACOREAPI BNPlatform* BNGetAssociatedPlatformByAddress(BNPlatform* platform, uint64_t* addr); + BINARYNINJACOREAPI BNQualifiedNameAndType* BNGetPlatformTypes(BNPlatform* platform, size_t* count); + BINARYNINJACOREAPI BNQualifiedNameAndType* BNGetPlatformVariables(BNPlatform* platform, size_t* count); + BINARYNINJACOREAPI BNQualifiedNameAndType* BNGetPlatformFunctions(BNPlatform* platform, size_t* count); + BINARYNINJACOREAPI BNSystemCallInfo* BNGetPlatformSystemCalls(BNPlatform* platform, size_t* count); + BINARYNINJACOREAPI void BNFreeSystemCallList(BNSystemCallInfo* syscalls, size_t count); + BINARYNINJACOREAPI BNType* BNGetPlatformTypeByName(BNPlatform* platform, BNQualifiedName* name); + BINARYNINJACOREAPI BNType* BNGetPlatformVariableByName(BNPlatform* platform, BNQualifiedName* name); + BINARYNINJACOREAPI BNType* BNGetPlatformFunctionByName(BNPlatform* platform, BNQualifiedName* name); + BINARYNINJACOREAPI char* BNGetPlatformSystemCallName(BNPlatform* platform, uint32_t number); + BINARYNINJACOREAPI BNType* BNGetPlatformSystemCallType(BNPlatform* platform, uint32_t number); + //Demangler BINARYNINJACOREAPI bool BNDemangleMS(BNArchitecture* arch, const char* mangledName, diff --git a/platform.cpp b/platform.cpp index 3bf4c0a4..afbcbbf3 100644 --- a/platform.cpp +++ b/platform.cpp @@ -255,6 +255,127 @@ Ref<Platform> Platform::GetAssociatedPlatformByAddress(uint64_t& addr) } +map<QualifiedName, Ref<Type>> Platform::GetTypes() +{ + size_t count; + BNQualifiedNameAndType* types = BNGetPlatformTypes(m_object, &count); + + map<QualifiedName, Ref<Type>> result; + for (size_t i = 0; i < count; i++) + { + QualifiedName name = QualifiedName::FromAPIObject(&types[i].name); + result[name] = new Type(BNNewTypeReference(types[i].type)); + } + + BNFreeTypeList(types, count); + return result; +} + + +map<QualifiedName, Ref<Type>> Platform::GetVariables() +{ + size_t count; + BNQualifiedNameAndType* types = BNGetPlatformVariables(m_object, &count); + + map<QualifiedName, Ref<Type>> result; + for (size_t i = 0; i < count; i++) + { + QualifiedName name = QualifiedName::FromAPIObject(&types[i].name); + result[name] = new Type(BNNewTypeReference(types[i].type)); + } + + BNFreeTypeList(types, count); + return result; +} + + +map<QualifiedName, Ref<Type>> Platform::GetFunctions() +{ + size_t count; + BNQualifiedNameAndType* types = BNGetPlatformFunctions(m_object, &count); + + map<QualifiedName, Ref<Type>> result; + for (size_t i = 0; i < count; i++) + { + QualifiedName name = QualifiedName::FromAPIObject(&types[i].name); + result[name] = new Type(BNNewTypeReference(types[i].type)); + } + + BNFreeTypeList(types, count); + return result; +} + + +map<uint32_t, QualifiedNameAndType> Platform::GetSystemCalls() +{ + size_t count; + BNSystemCallInfo* calls = BNGetPlatformSystemCalls(m_object, &count); + + map<uint32_t, QualifiedNameAndType> result; + for (size_t i = 0; i < count; i++) + { + QualifiedNameAndType nt; + nt.name = QualifiedName::FromAPIObject(&calls[i].name); + nt.type = new Type(BNNewTypeReference(calls[i].type)); + result[calls[i].number] = nt; + } + + BNFreeSystemCallList(calls, count); + return result; +} + + +Ref<Type> Platform::GetTypeByName(const QualifiedName& name) +{ + BNQualifiedName nameObj = name.GetAPIObject(); + BNType* type = BNGetPlatformTypeByName(m_object, &nameObj); + QualifiedName::FreeAPIObject(&nameObj); + if (!type) + return nullptr; + return new Type(type); +} + + +Ref<Type> Platform::GetVariableByName(const QualifiedName& name) +{ + BNQualifiedName nameObj = name.GetAPIObject(); + BNType* type = BNGetPlatformVariableByName(m_object, &nameObj); + QualifiedName::FreeAPIObject(&nameObj); + if (!type) + return nullptr; + return new Type(type); +} + + +Ref<Type> Platform::GetFunctionByName(const QualifiedName& name) +{ + BNQualifiedName nameObj = name.GetAPIObject(); + BNType* type = BNGetPlatformFunctionByName(m_object, &nameObj); + QualifiedName::FreeAPIObject(&nameObj); + if (!type) + return nullptr; + return new Type(type); +} + + +string Platform::GetSystemCallName(uint32_t n) +{ + char* str = BNGetPlatformSystemCallName(m_object, n); + string result = str; + BNFreeString(str); + return result; +} + + +Ref<Type> Platform::GetSystemCallType(uint32_t n) +{ + BNType* type = BNGetPlatformSystemCallType(m_object, n); + if (!type) + return nullptr; + return new Type(type); +} + + string Platform::GenerateAutoPlatformTypeId(const QualifiedName& name) { BNQualifiedName nameObj = name.GetAPIObject(); diff --git a/python/platform.py b/python/platform.py index 5d90997d..ccc80476 100644 --- a/python/platform.py +++ b/python/platform.py @@ -216,6 +216,55 @@ class Platform(object): core.BNFreeCallingConventionList(cc, count.value) return result + @property + def types(self): + """List of platform-specific types (read-only)""" + count = ctypes.c_ulonglong(0) + type_list = core.BNGetPlatformTypes(self.handle, count) + result = {} + for i in xrange(0, count.value): + name = types.QualifiedName._from_core_struct(type_list[i].name) + result[name] = types.Type(core.BNNewTypeReference(type_list[i].type)) + core.BNFreeTypeList(type_list, count.value) + return result + + @property + def variables(self): + """List of platform-specific variable definitions (read-only)""" + count = ctypes.c_ulonglong(0) + type_list = core.BNGetPlatformVariables(self.handle, count) + result = {} + for i in xrange(0, count.value): + name = types.QualifiedName._from_core_struct(type_list[i].name) + result[name] = types.Type(core.BNNewTypeReference(type_list[i].type)) + core.BNFreeTypeList(type_list, count.value) + return result + + @property + def functions(self): + """List of platform-specific function definitions (read-only)""" + count = ctypes.c_ulonglong(0) + type_list = core.BNGetPlatformFunctions(self.handle, count) + result = {} + for i in xrange(0, count.value): + name = types.QualifiedName._from_core_struct(type_list[i].name) + result[name] = types.Type(core.BNNewTypeReference(type_list[i].type)) + core.BNFreeTypeList(type_list, count.value) + return result + + @property + def system_calls(self): + """List of system calls for this platform (read-only)""" + count = ctypes.c_ulonglong(0) + call_list = core.BNGetPlatformSystemCalls(self.handle, count) + result = {} + for i in xrange(0, count.value): + name = types.QualifiedName._from_core_struct(call_list[i].name) + t = types.Type(core.BNNewTypeReference(call_list[i].type)) + result[call_list[i].number] = (name, t) + core.BNFreeSystemCallList(call_list, count.value) + return result + def __setattr__(self, name, value): try: object.__setattr__(self, name, value) @@ -261,6 +310,36 @@ class Platform(object): result = core.BNGetAssociatedPlatformByAddress(self.handle, new_addr) return Platform(None, handle = result), new_addr.value + def get_type_by_name(self, name): + name = types.QualifiedName(name)._get_core_struct() + obj = core.BNGetPlatformTypeByName(self.handle, name) + if not obj: + return None + return types.Type(obj) + + def get_variable_by_name(self, name): + name = types.QualifiedName(name)._get_core_struct() + obj = core.BNGetPlatformVariableByName(self.handle, name) + if not obj: + return None + return types.Type(obj) + + def get_function_by_name(self, name): + name = types.QualifiedName(name)._get_core_struct() + obj = core.BNGetPlatformFunctionByName(self.handle, name) + if not obj: + return None + return types.Type(obj) + + def get_system_call_name(self, number): + return core.BNGetPlatformSystemCallName(self.handle, number) + + def get_system_call_type(self, number): + obj = core.BNGetPlatformSystemCallType(self.handle, number) + if not obj: + return None + return types.Type(obj) + def generate_auto_platform_type_id(self, name): name = types.QualifiedName(name)._get_core_struct() return core.BNGenerateAutoPlatformTypeId(self.handle, name) |
