summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Potchik <brian@vector35.com>2017-11-13 17:09:13 -0500
committerBrian Potchik <brian@vector35.com>2017-11-13 17:09:13 -0500
commit0cff612e91e59a343fad898daa6fa51ab525a789 (patch)
tree551ff0b624ffc18be23824757fab1a13fd9819e7
parent32b22a22aaf7b76d47e91ed49a3246b66b431991 (diff)
Add GetInstructionAlignment Callback to Architecture.
-rw-r--r--architecture.cpp20
-rw-r--r--binaryninjaapi.h3
-rw-r--r--binaryninjacore.h2
-rw-r--r--examples/x86_extension/src/x86_extension.cpp5
-rw-r--r--python/architecture.py13
-rw-r--r--python/examples/nes.py1
6 files changed, 43 insertions, 1 deletions
diff --git a/architecture.cpp b/architecture.cpp
index eb588394..17d02909 100644
--- a/architecture.cpp
+++ b/architecture.cpp
@@ -111,6 +111,13 @@ size_t Architecture::GetDefaultIntegerSizeCallback(void* ctxt)
}
+size_t Architecture::GetInstructionAlignmentCallback(void* ctxt)
+{
+ Architecture* arch = (Architecture*)ctxt;
+ return arch->GetInstructionAlignment();
+}
+
+
size_t Architecture::GetMaxInstructionLengthCallback(void* ctxt)
{
Architecture* arch = (Architecture*)ctxt;
@@ -443,6 +450,7 @@ void Architecture::Register(Architecture* arch)
callbacks.getEndianness = GetEndiannessCallback;
callbacks.getAddressSize = GetAddressSizeCallback;
callbacks.getDefaultIntegerSize = GetDefaultIntegerSizeCallback;
+ callbacks.getInstructionAlignment = GetInstructionAlignmentCallback;
callbacks.getMaxInstructionLength = GetMaxInstructionLengthCallback;
callbacks.getOpcodeDisplayLength = GetOpcodeDisplayLengthCallback;
callbacks.getAssociatedArchitectureByAddress = GetAssociatedArchitectureByAddressCallback;
@@ -523,6 +531,12 @@ size_t Architecture::GetDefaultIntegerSize() const
}
+size_t Architecture::GetInstructionAlignment() const
+{
+ return 1;
+}
+
+
size_t Architecture::GetMaxInstructionLength() const
{
return BN_DEFAULT_NSTRUCTION_LENGTH;
@@ -905,6 +919,12 @@ size_t CoreArchitecture::GetDefaultIntegerSize() const
}
+size_t CoreArchitecture::GetInstructionAlignment() const
+{
+ return BNGetArchitectureInstructionAlignment(m_object);
+}
+
+
size_t CoreArchitecture::GetMaxInstructionLength() const
{
return BNGetArchitectureMaxInstructionLength(m_object);
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index 5f3aace7..4f62ef5f 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -1585,6 +1585,7 @@ namespace BinaryNinja
static BNEndianness GetEndiannessCallback(void* ctxt);
static size_t GetAddressSizeCallback(void* ctxt);
static size_t GetDefaultIntegerSizeCallback(void* ctxt);
+ static size_t GetInstructionAlignmentCallback(void* ctxt);
static size_t GetMaxInstructionLengthCallback(void* ctxt);
static size_t GetOpcodeDisplayLengthCallback(void* ctxt);
static BNArchitecture* GetAssociatedArchitectureByAddressCallback(void* ctxt, uint64_t* addr);
@@ -1640,6 +1641,7 @@ namespace BinaryNinja
virtual size_t GetAddressSize() const = 0;
virtual size_t GetDefaultIntegerSize() const;
+ virtual size_t GetInstructionAlignment() const;
virtual size_t GetMaxInstructionLength() const;
virtual size_t GetOpcodeDisplayLength() const;
@@ -1780,6 +1782,7 @@ namespace BinaryNinja
virtual BNEndianness GetEndianness() const override;
virtual size_t GetAddressSize() const override;
virtual size_t GetDefaultIntegerSize() const override;
+ virtual size_t GetInstructionAlignment() const override;
virtual size_t GetMaxInstructionLength() const override;
virtual size_t GetOpcodeDisplayLength() const override;
virtual Ref<Architecture> GetAssociatedArchitectureByAddress(uint64_t& addr) override;
diff --git a/binaryninjacore.h b/binaryninjacore.h
index 45e6310c..cb99958c 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -1003,6 +1003,7 @@ extern "C"
BNEndianness (*getEndianness)(void* ctxt);
size_t (*getAddressSize)(void* ctxt);
size_t (*getDefaultIntegerSize)(void* ctxt);
+ size_t (*getInstructionAlignment)(void* ctxt);
size_t (*getMaxInstructionLength)(void* ctxt);
size_t (*getOpcodeDisplayLength)(void* ctxt);
BNArchitecture* (*getAssociatedArchitectureByAddress)(void* ctxt, uint64_t* addr);
@@ -1946,6 +1947,7 @@ extern "C"
BINARYNINJACOREAPI BNEndianness BNGetArchitectureEndianness(BNArchitecture* arch);
BINARYNINJACOREAPI size_t BNGetArchitectureAddressSize(BNArchitecture* arch);
BINARYNINJACOREAPI size_t BNGetArchitectureDefaultIntegerSize(BNArchitecture* arch);
+ BINARYNINJACOREAPI size_t BNGetArchitectureInstructionAlignment(BNArchitecture* arch);
BINARYNINJACOREAPI size_t BNGetArchitectureMaxInstructionLength(BNArchitecture* arch);
BINARYNINJACOREAPI size_t BNGetArchitectureOpcodeDisplayLength(BNArchitecture* arch);
BINARYNINJACOREAPI BNArchitecture* BNGetAssociatedArchitectureByAddress(BNArchitecture* arch, uint64_t* addr);
diff --git a/examples/x86_extension/src/x86_extension.cpp b/examples/x86_extension/src/x86_extension.cpp
index 9efcc119..076551ab 100644
--- a/examples/x86_extension/src/x86_extension.cpp
+++ b/examples/x86_extension/src/x86_extension.cpp
@@ -327,6 +327,11 @@ public:
return LittleEndian;
}
+ virtual size_t GetInstructionAlignment() const override
+ {
+ return 1;
+ }
+
virtual bool GetInstructionInfo(const uint8_t* data, uint64_t addr, size_t maxLen, InstructionInfo& result) override
{
return m_arch->GetInstructionInfo(data, addr, maxLen, result);
diff --git a/python/architecture.py b/python/architecture.py
index 72403fec..41a130bf 100644
--- a/python/architecture.py
+++ b/python/architecture.py
@@ -111,6 +111,7 @@ class Architecture(object):
endianness = Endianness.LittleEndian
address_size = 8
default_int_size = 4
+ instr_alignment = 1
max_instr_length = 16
opcode_display_length = 8
regs = {}
@@ -132,6 +133,7 @@ class Architecture(object):
self.__dict__["endianness"] = Endianness(core.BNGetArchitectureEndianness(self.handle))
self.__dict__["address_size"] = core.BNGetArchitectureAddressSize(self.handle)
self.__dict__["default_int_size"] = core.BNGetArchitectureDefaultIntegerSize(self.handle)
+ self.__dict__["instr_alignment"] = core.BNGetArchitectureInstructionAlignment(self.handle)
self.__dict__["max_instr_length"] = core.BNGetArchitectureMaxInstructionLength(self.handle)
self.__dict__["opcode_display_length"] = core.BNGetArchitectureOpcodeDisplayLength(self.handle)
self.__dict__["stack_pointer"] = core.BNGetArchitectureRegisterName(self.handle,
@@ -228,6 +230,7 @@ class Architecture(object):
self._cb.getEndianness = self._cb.getEndianness.__class__(self._get_endianness)
self._cb.getAddressSize = self._cb.getAddressSize.__class__(self._get_address_size)
self._cb.getDefaultIntegerSize = self._cb.getDefaultIntegerSize.__class__(self._get_default_integer_size)
+ self._cb.getInstructionAlignment = self._cb.getInstructionAlignment.__class__(self._get_instruction_alignment)
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 = \
@@ -385,7 +388,8 @@ class Architecture(object):
def __setattr__(self, name, value):
if ((name == "name") or (name == "endianness") or (name == "address_size") or
- (name == "default_int_size") or (name == "regs") or (name == "get_max_instruction_length")):
+ (name == "default_int_size") or (name == "regs") or (name == "get_max_instruction_length") or
+ (name == "get_instruction_alignment")):
raise AttributeError("attribute '%s' is read only" % name)
else:
try:
@@ -420,6 +424,13 @@ class Architecture(object):
log.log_error(traceback.format_exc())
return 4
+ def __get_instruction_alignment(self, ctxt):
+ try:
+ return self.__class__.instr_alignment
+ except:
+ log.log_error(traceback.format_exc())
+ return 1
+
def _get_max_instruction_length(self, ctxt):
try:
return self.__class__.max_instr_length
diff --git a/python/examples/nes.py b/python/examples/nes.py
index e55a90b7..39544c9f 100644
--- a/python/examples/nes.py
+++ b/python/examples/nes.py
@@ -367,6 +367,7 @@ class M6502(Architecture):
name = "6502"
address_size = 2
default_int_size = 1
+ instr_alignment = 1
max_instr_length = 3
regs = {
"a": RegisterInfo("a", 1),