summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorplafosse <peter@vector35.com>2016-10-28 20:41:40 -0400
committerplafosse <peter@vector35.com>2016-10-28 20:41:40 -0400
commit18e7e9378a4d7dff8140ed35eb47ce7993bd850b (patch)
treec78882aa02a668637fb33124ae20f34a25e461f1
parent5e4cca1f1796bec109adacdb049d9e34c17656eb (diff)
parentb5eacc14097def2367b650fc4a9377d4910441eb (diff)
Merging with dev
-rw-r--r--architecture.cpp20
-rw-r--r--binaryninjaapi.h4
-rw-r--r--binaryninjacore.h2
-rw-r--r--docs/getting-started.md4
-rw-r--r--python/architecture.py14
-rw-r--r--python/examples/angr_plugin.py21
-rw-r--r--python/examples/bin_info.py16
-rw-r--r--python/examples/breakpoint.py20
-rw-r--r--python/function.py8
9 files changed, 99 insertions, 10 deletions
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> 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<Architecture> 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<Architecture> 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<InstructionTextToken>& 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<Architecture> 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<InstructionTextToken>& 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,
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
- - `&lt;ESC&gt;` : Navigate backward
- - `&lt;SPACE&gt;` : 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
diff --git a/python/architecture.py b/python/architecture.py
index 11aa4757..a8aa391b 100644
--- a/python/architecture.py
+++ b/python/architecture.py
@@ -222,6 +222,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)
@@ -411,6 +413,15 @@ class Architecture(object):
log.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.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)
@@ -820,6 +831,9 @@ class Architecture(object):
log.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):
"""
diff --git a/python/examples/angr_plugin.py b/python/examples/angr_plugin.py
index 675cc5f6..852eff65 100644
--- a/python/examples/angr_plugin.py
+++ b/python/examples/angr_plugin.py
@@ -1,3 +1,24 @@
+# Copyright (c) 2015-2016 Vector 35 LLC
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to
+# deal in the Software without restriction, including without limitation the
+# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+# IN THE SOFTWARE.
+
+
# This plugin assumes angr is already installed and available on the system. See the angr documentation
# for information about installing angr. It should be installed using the virtualenv method.
#
diff --git a/python/examples/bin_info.py b/python/examples/bin_info.py
index ab963e4e..a472495a 100644
--- a/python/examples/bin_info.py
+++ b/python/examples/bin_info.py
@@ -37,20 +37,20 @@ else:
bv = binaryninja.BinaryViewType[bintype].open(target)
bv.update_analysis_and_wait()
-print("-------- %s --------" % target)
-print("START: 0x%x" % bv.start)
-print("ENTRY: 0x%x" % bv.entry_point)
-print("ARCH: %s" % bv.arch.name)
-print("\n-------- Function List --------")
+log.log_info("-------- %s --------" % target)
+log.log_info("START: 0x%x" % bv.start)
+log.log_info("ENTRY: 0x%x" % bv.entry_point)
+log.log_info("ARCH: %s" % bv.arch.name)
+log.log_info("\n-------- Function List --------")
for func in bv.functions:
- print(func.symbol.name)
+ log.log_info(func.symbol.name)
-print("\n-------- First 10 strings --------")
+log.log_info("\n-------- First 10 strings --------")
for i in xrange(10):
start = bv.strings[i].start
length = bv.strings[i].length
string = bv.read(start, length)
- print("0x%x (%d):\t%s" % (start, length, string))
+ log.log_info("0x%x (%d):\t%s" % (start, length, string))
diff --git a/python/examples/breakpoint.py b/python/examples/breakpoint.py
index 44df19e2..2426e6a1 100644
--- a/python/examples/breakpoint.py
+++ b/python/examples/breakpoint.py
@@ -1,3 +1,23 @@
+# Copyright (c) 2015-2016 Vector 35 LLC
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to
+# deal in the Software without restriction, including without limitation the
+# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+# IN THE SOFTWARE.
+
from binaryninja import *
def write_breakpoint(view, start, length):
diff --git a/python/function.py b/python/function.py
index 37364840..2910d283 100644
--- a/python/function.py
+++ b/python/function.py
@@ -212,6 +212,14 @@ class Function(object):
return architecture.Architecture(arch)
@property
+ def platform(self):
+ """Function platform (read-only)"""
+ platform = core.BNGetFunctionPlatform(self.handle)
+ if platform is None:
+ return None
+ return platform.Platform(None, handle = platform)
+
+ @property
def start(self):
"""Function start (read-only)"""
return core.BNGetFunctionStart(self.handle)