summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRusty Wagner <rusty@vector35.com>2016-10-20 00:14:41 -0400
committerRusty Wagner <rusty@vector35.com>2016-10-20 00:14:41 -0400
commit254d5aa23c0d114e9a275f60538fcb3b76ac1c69 (patch)
treee409404b63f241d5484acf7b68be43aad6532f29
parentc99fd8fddc8734c121383d8d3e078674cb1a5e88 (diff)
Add API for multiple architectures distinguished by address
-rw-r--r--architecture.cpp20
-rw-r--r--binaryninjaapi.h4
-rw-r--r--binaryninjacore.h2
3 files changed, 26 insertions, 0 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,