From c382a4610cc0ea7f8b8134b847d29bca7dc25398 Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Sun, 24 Apr 2016 00:33:26 -0400 Subject: Create API for adding known indirect branch targets --- function.cpp | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'function.cpp') 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& 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& 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 Function::GetIndirectBranches() +{ + size_t count; + BNIndirectBranchInfo* branches = BNGetIndirectBranches(m_object, &count); + + vector 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 Function::GetIndirectBranchesAt(Architecture* arch, uint64_t addr) +{ + size_t count; + BNIndirectBranchInfo* branches = BNGetIndirectBranchesAt(m_object, arch->GetObject(), addr, &count); + + vector 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; +} -- cgit v1.3.1