summaryrefslogtreecommitdiff
path: root/architecture.cpp
diff options
context:
space:
mode:
authorRusty Wagner <rusty@vector35.com>2015-02-20 03:12:19 -0500
committerRusty Wagner <rusty@vector35.com>2015-02-20 03:12:19 -0500
commitf2b794bf897a2e208407bf5f4a13f4f813531e68 (patch)
treed439622fedebdede54833c445251040a60ad30cb /architecture.cpp
parent584e4d244a9124f6ec403162994434ff085e9c5d (diff)
Initial code for generating function graphs
Diffstat (limited to 'architecture.cpp')
-rw-r--r--architecture.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/architecture.cpp b/architecture.cpp
index 60fa4efa..0d010d0e 100644
--- a/architecture.cpp
+++ b/architecture.cpp
@@ -20,6 +20,12 @@ void InstructionInfo::AddBranch(BNBranchType type, uint64_t target)
}
+InstructionTextToken::InstructionTextToken(BNInstructionTextTokenType t, const std::string& txt, uint64_t val) :
+ type(t), text(txt), value(val)
+{
+}
+
+
Architecture::Architecture(BNArchitecture* arch): m_arch(arch)
{
}
@@ -42,11 +48,48 @@ bool Architecture::GetInstructionInfoCallback(void* ctxt, BNBinaryView* data, ui
}
+bool Architecture::GetInstructionTextCallback(void* ctxt, BNBinaryView* data, uint64_t addr,
+ BNInstructionTextToken** result, size_t* count)
+{
+ Architecture* arch = (Architecture*)ctxt;
+ Ref<BinaryView> view = new BinaryView(BNNewViewReference(data));
+
+ vector<InstructionTextToken> tokens;
+ bool ok = arch->GetInstructionText(view, addr, tokens);
+ if (!ok)
+ {
+ *result = nullptr;
+ *count = 0;
+ return false;
+ }
+
+ *count = tokens.size();
+ *result = new BNInstructionTextToken[tokens.size()];
+ for (size_t i = 0; i < tokens.size(); i++)
+ {
+ (*result)[i].type = tokens[i].type;
+ (*result)[i].text = BNAllocString(tokens[i].text.c_str());
+ (*result)[i].value = tokens[i].value;
+ }
+ return true;
+}
+
+
+void Architecture::FreeInstructionTextCallback(BNInstructionTextToken* tokens, size_t count)
+{
+ for (size_t i = 0; i < count; i++)
+ BNFreeString(tokens[i].text);
+ delete[] tokens;
+}
+
+
void Architecture::Register(Architecture* arch)
{
BNCustomArchitecture callbacks;
callbacks.context = arch;
callbacks.getInstructionInfo = GetInstructionInfoCallback;
+ callbacks.getInstructionText = GetInstructionTextCallback;
+ callbacks.freeInstructionText = FreeInstructionTextCallback;
arch->m_arch = BNRegisterArchitecture(arch->m_nameForRegister.c_str(), &callbacks);
}
@@ -93,3 +136,18 @@ bool CoreArchitecture::GetInstructionInfo(BinaryView* view, uint64_t addr, Instr
{
return BNGetInstructionInfo(m_arch, view->GetViewObject(), addr, &result);
}
+
+
+bool CoreArchitecture::GetInstructionText(BinaryView* view, uint64_t addr, std::vector<InstructionTextToken>& result)
+{
+ BNInstructionTextToken* tokens = nullptr;
+ size_t count = 0;
+ if (!BNGetInstructionText(m_arch, view->GetViewObject(), addr, &tokens, &count))
+ return false;
+
+ for (size_t i = 0; i < count; i++)
+ result.push_back(InstructionTextToken(tokens[i].type, tokens[i].text, tokens[i].value));
+
+ BNFreeInstructionText(tokens, count);
+ return true;
+}