From 254d5aa23c0d114e9a275f60538fcb3b76ac1c69 Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Thu, 20 Oct 2016 00:14:41 -0400 Subject: Add API for multiple architectures distinguished by address --- architecture.cpp | 20 ++++++++++++++++++++ binaryninjaapi.h | 4 ++++ binaryninjacore.h | 2 ++ 3 files changed, 26 insertions(+) diff --git a/architecture.cpp b/architecture.cpp index af7b0cba..3c7d9af8 100644 --- a/architecture.cpp +++ b/architecture.cpp @@ -111,6 +111,13 @@ size_t Architecture::GetOpcodeDisplayLengthCallback(void* ctxt) } +BNArchitecture* Architecture::GetAssociatedArchitectureByAddressCallback(void* ctxt, uint64_t* addr) +{ + Architecture* arch = (Architecture*)ctxt; + return arch->GetAssociatedArchitectureByAddress(*addr)->GetObject(); +} + + bool Architecture::GetInstructionInfoCallback(void* ctxt, const uint8_t* data, uint64_t addr, size_t maxLen, BNInstructionInfo* result) { @@ -408,6 +415,7 @@ void Architecture::Register(Architecture* arch) callbacks.getDefaultIntegerSize = GetDefaultIntegerSizeCallback; callbacks.getMaxInstructionLength = GetMaxInstructionLengthCallback; callbacks.getOpcodeDisplayLength = GetOpcodeDisplayLengthCallback; + callbacks.getAssociatedArchitectureByAddress = GetAssociatedArchitectureByAddressCallback; callbacks.getInstructionInfo = GetInstructionInfoCallback; callbacks.getInstructionText = GetInstructionTextCallback; callbacks.freeInstructionText = FreeInstructionTextCallback; @@ -499,6 +507,12 @@ size_t Architecture::GetOpcodeDisplayLength() const } +Ref Architecture::GetAssociatedArchitectureByAddress(uint64_t&) +{ + return this; +} + + bool Architecture::GetInstructionLowLevelIL(const uint8_t*, uint64_t, size_t&, LowLevelILFunction& il) { il.AddInstruction(il.Undefined()); @@ -919,6 +933,12 @@ size_t CoreArchitecture::GetOpcodeDisplayLength() const } +Ref CoreArchitecture::GetAssociatedArchitectureByAddress(uint64_t& addr) +{ + return new CoreArchitecture(BNGetAssociatedArchitectureByAddress(m_object, &addr)); +} + + bool CoreArchitecture::GetInstructionInfo(const uint8_t* data, uint64_t addr, size_t maxLen, InstructionInfo& result) { return BNGetInstructionInfo(m_object, data, addr, maxLen, &result); diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 7c297f73..6311271c 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -1257,6 +1257,7 @@ namespace BinaryNinja static size_t GetDefaultIntegerSizeCallback(void* ctxt); static size_t GetMaxInstructionLengthCallback(void* ctxt); static size_t GetOpcodeDisplayLengthCallback(void* ctxt); + static BNArchitecture* GetAssociatedArchitectureByAddressCallback(void* ctxt, uint64_t* addr); static bool GetInstructionInfoCallback(void* ctxt, const uint8_t* data, uint64_t addr, size_t maxLen, BNInstructionInfo* result); static bool GetInstructionTextCallback(void* ctxt, const uint8_t* data, uint64_t addr, @@ -1311,6 +1312,8 @@ namespace BinaryNinja virtual size_t GetMaxInstructionLength() const; virtual size_t GetOpcodeDisplayLength() const; + virtual Ref GetAssociatedArchitectureByAddress(uint64_t& addr); + virtual bool GetInstructionInfo(const uint8_t* data, uint64_t addr, size_t maxLen, InstructionInfo& result) = 0; virtual bool GetInstructionText(const uint8_t* data, uint64_t addr, size_t& len, std::vector& result) = 0; @@ -1454,6 +1457,7 @@ namespace BinaryNinja virtual size_t GetDefaultIntegerSize() const override; virtual size_t GetMaxInstructionLength() const override; virtual size_t GetOpcodeDisplayLength() const override; + virtual Ref GetAssociatedArchitectureByAddress(uint64_t& addr) override; virtual bool GetInstructionInfo(const uint8_t* data, uint64_t addr, size_t maxLen, InstructionInfo& result) override; virtual bool GetInstructionText(const uint8_t* data, uint64_t addr, size_t& len, std::vector& result) override; diff --git a/binaryninjacore.h b/binaryninjacore.h index ac615922..ea81c388 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -725,6 +725,7 @@ extern "C" size_t (*getDefaultIntegerSize)(void* ctxt); size_t (*getMaxInstructionLength)(void* ctxt); size_t (*getOpcodeDisplayLength)(void* ctxt); + BNArchitecture* (*getAssociatedArchitectureByAddress)(void* ctxt, uint64_t* addr); bool (*getInstructionInfo)(void* ctxt, const uint8_t* data, uint64_t addr, size_t maxLen, BNInstructionInfo* result); bool (*getInstructionText)(void* ctxt, const uint8_t* data, uint64_t addr, size_t* len, BNInstructionTextToken** result, size_t* count); @@ -1516,6 +1517,7 @@ extern "C" BINARYNINJACOREAPI size_t BNGetArchitectureDefaultIntegerSize(BNArchitecture* arch); BINARYNINJACOREAPI size_t BNGetArchitectureMaxInstructionLength(BNArchitecture* arch); BINARYNINJACOREAPI size_t BNGetArchitectureOpcodeDisplayLength(BNArchitecture* arch); + BINARYNINJACOREAPI BNArchitecture* BNGetAssociatedArchitectureByAddress(BNArchitecture* arch, uint64_t* addr); BINARYNINJACOREAPI bool BNGetInstructionInfo(BNArchitecture* arch, const uint8_t* data, uint64_t addr, size_t maxLen, BNInstructionInfo* result); BINARYNINJACOREAPI bool BNGetInstructionText(BNArchitecture* arch, const uint8_t* data, uint64_t addr, -- cgit v1.3.1 From 0ccbd5f5fe3e646ac18ea013bb443a2b5b29b609 Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Thu, 20 Oct 2016 18:28:43 -0400 Subject: Add associated arch API to Python --- python/__init__.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/python/__init__.py b/python/__init__.py index 70267678..63916b1f 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -6011,6 +6011,8 @@ class Architecture(object): self._cb.getDefaultIntegerSize = self._cb.getDefaultIntegerSize.__class__(self._get_default_integer_size) self._cb.getMaxInstructionLength = self._cb.getMaxInstructionLength.__class__(self._get_max_instruction_length) self._cb.getOpcodeDisplayLength = self._cb.getOpcodeDisplayLength.__class__(self._get_opcode_display_length) + self._cb.getAssociatedArchitectureByAddress = self._cb.getAssociatedArchitectureByAddress.__class__( + self._get_associated_arch_by_address) self._cb.getInstructionInfo = self._cb.getInstructionInfo.__class__(self._get_instruction_info) self._cb.getInstructionText = self._cb.getInstructionText.__class__(self._get_instruction_text) self._cb.freeInstructionText = self._cb.freeInstructionText.__class__(self._free_instruction_text) @@ -6200,6 +6202,15 @@ class Architecture(object): log_error(traceback.format_exc()) return 8 + def _get_associated_arch_by_address(self, ctxt, addr): + try: + result, new_addr = self.perform_get_associated_arch_by_address(addr[0]) + addr[0] = new_addr + return ctypes.cast(result.handle, ctypes.c_void_p).value + except: + log_error(traceback.format_exc()) + return ctypes.cast(self.handle, ctypes.c_void_p).value + def _get_instruction_info(self, ctxt, data, addr, max_len, result): try: buf = ctypes.create_string_buffer(max_len) @@ -6609,6 +6620,9 @@ class Architecture(object): log_error(traceback.format_exc()) return False + def perform_get_associated_arch_by_address(self, addr): + return self, addr + @abc.abstractmethod def perform_get_instruction_info(self, data, addr): """ @@ -6859,6 +6873,12 @@ class Architecture(object): """ return None + def get_associated_arch_by_address(self, addr): + new_addr = ctypes.c_ulonglong() + new_addr.value = addr + result = core.BNGetAssociatedArchitectureByAddress(self.handle, new_addr) + return Architecture(handle = result), new_addr.value + def get_instruction_info(self, data, addr): """ ``get_instruction_info`` returns an InstructionInfo object for the instruction at the given virtual address -- cgit v1.3.1 From 3d3680e8bafe551f73ca737473d116d01c3b9385 Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Mon, 24 Oct 2016 10:51:45 -0400 Subject: fix hotkey annotation --- docs/getting-started.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/getting-started.md b/docs/getting-started.md index b12debf4..82c833a5 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -52,8 +52,8 @@ Switching views happens multiple ways. In some instances, it's automatic (clicki - `h` : Switch to hex view - `p` : Create a function - - `<ESC>` : Navigate backward - - `<SPACE>` : Toggle between linear view and graph view + - `[ESC]` : Navigate backward + - `[SPACE]` : Toggle between linear view and graph view - `g` : Go To Address dialog - `n` : Name a symbol - `u` : Undefine a symbol -- cgit v1.3.1 From 5cfb38e1c3178195935b969201dd7e42419ea671 Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Mon, 24 Oct 2016 18:40:20 -0400 Subject: Add related platform API to Python --- python/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/python/__init__.py b/python/__init__.py index 63916b1f..6db17545 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -9713,6 +9713,15 @@ class Platform(object): """ core.BNRegisterPlatformCallingConvention(self.handle, cc.handle) + def get_related_platform(self, arch): + result = core.BNGetRelatedPlatform(self.handle, arch.handle) + if not result: + return None + return Platform(None, handle = result) + + def add_related_platform(self, arch, platform): + core.BNAddRelatedPlatform(self.handle, arch.handle, platform.handle) + class ScriptingOutputListener(object): def _register(self, handle): self._cb = core.BNScriptingOutputListener() -- cgit v1.3.1 From 6b307f7cad00e4d89e5ed66b9d67e374078f8b95 Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Mon, 24 Oct 2016 19:00:23 -0400 Subject: Add platform property to function --- python/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/python/__init__.py b/python/__init__.py index 6db17545..8176b8e6 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -4788,6 +4788,14 @@ class Function(object): return None return Architecture(arch) + @property + def platform(self): + """Function platform (read-only)""" + platform = core.BNGetFunctionPlatform(self.handle) + if platform is None: + return None + return Platform(None, handle = platform) + @property def start(self): """Function start (read-only)""" -- cgit v1.3.1