summaryrefslogtreecommitdiff
path: root/function.cpp
diff options
context:
space:
mode:
authorRusty Wagner <rusty@vector35.com>2016-04-24 00:33:26 -0400
committerRusty Wagner <rusty@vector35.com>2016-04-24 00:33:26 -0400
commitc382a4610cc0ea7f8b8134b847d29bca7dc25398 (patch)
tree8dc2347b36c85b431164f435b78305a3c276230c /function.cpp
parent12217ad7a1d821c4d232e04da2c9ac4b4e365bf6 (diff)
Create API for adding known indirect branch targets
Diffstat (limited to 'function.cpp')
-rw-r--r--function.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/function.cpp b/function.cpp
index 12f99d1f..8631eb0b 100644
--- a/function.cpp
+++ b/function.cpp
@@ -313,3 +313,73 @@ bool Function::GetStackVariableAtFrameOffset(int64_t offset, StackVariable& resu
BNFreeStackVariable(&var);
return true;
}
+
+
+void Function::SetAutoIndirectBranches(Architecture* sourceArch, uint64_t source, const std::vector<ArchAndAddr>& branches)
+{
+ BNArchitectureAndAddress* branchList = new BNArchitectureAndAddress[branches.size()];
+ for (size_t i = 0; i < branches.size(); i++)
+ {
+ branchList[i].arch = branches[i].arch->GetObject();
+ branchList[i].address = branches[i].address;
+ }
+ BNSetAutoIndirectBranches(m_object, sourceArch->GetObject(), source, branchList, branches.size());
+ delete[] branchList;
+}
+
+
+void Function::SetUserIndirectBranches(Architecture* sourceArch, uint64_t source, const std::vector<ArchAndAddr>& branches)
+{
+ BNArchitectureAndAddress* branchList = new BNArchitectureAndAddress[branches.size()];
+ for (size_t i = 0; i < branches.size(); i++)
+ {
+ branchList[i].arch = branches[i].arch->GetObject();
+ branchList[i].address = branches[i].address;
+ }
+ BNSetUserIndirectBranches(m_object, sourceArch->GetObject(), source, branchList, branches.size());
+ delete[] branchList;
+}
+
+
+vector<IndirectBranchInfo> Function::GetIndirectBranches()
+{
+ size_t count;
+ BNIndirectBranchInfo* branches = BNGetIndirectBranches(m_object, &count);
+
+ vector<IndirectBranchInfo> result;
+ for (size_t i = 0; i < count; i++)
+ {
+ IndirectBranchInfo b;
+ b.sourceArch = new CoreArchitecture(branches[i].sourceArch);
+ b.sourceAddr = branches[i].sourceAddr;
+ b.destArch = new CoreArchitecture(branches[i].destArch);
+ b.destAddr = branches[i].destAddr;
+ b.autoDefined = branches[i].autoDefined;
+ result.push_back(b);
+ }
+
+ BNFreeIndirectBranchList(branches);
+ return result;
+}
+
+
+vector<IndirectBranchInfo> Function::GetIndirectBranchesAt(Architecture* arch, uint64_t addr)
+{
+ size_t count;
+ BNIndirectBranchInfo* branches = BNGetIndirectBranchesAt(m_object, arch->GetObject(), addr, &count);
+
+ vector<IndirectBranchInfo> result;
+ for (size_t i = 0; i < count; i++)
+ {
+ IndirectBranchInfo b;
+ b.sourceArch = new CoreArchitecture(branches[i].sourceArch);
+ b.sourceAddr = branches[i].sourceAddr;
+ b.destArch = new CoreArchitecture(branches[i].destArch);
+ b.destAddr = branches[i].destAddr;
+ b.autoDefined = branches[i].autoDefined;
+ result.push_back(b);
+ }
+
+ BNFreeIndirectBranchList(branches);
+ return result;
+}