summaryrefslogtreecommitdiff
path: root/function.cpp
diff options
context:
space:
mode:
authorJordan Wiens <jordan@psifertex.com>2016-05-08 03:50:36 -0400
committerJordan Wiens <jordan@psifertex.com>2016-05-08 03:52:19 -0400
commit45e8803c97b4d11719d1eadf3b6cf56f093ee505 (patch)
tree27b027286f8aa96644bb624a24aa66c2929730f3 /function.cpp
parent9841c8e7610b4fe184a2b33aba2f61bf54123edb (diff)
parentecaf78b419d323f6b589aac4b9ff5ff24b314bc6 (diff)
merge
Diffstat (limited to 'function.cpp')
-rw-r--r--function.cpp118
1 files changed, 118 insertions, 0 deletions
diff --git a/function.cpp b/function.cpp
index 12f99d1f..0fb163e0 100644
--- a/function.cpp
+++ b/function.cpp
@@ -229,6 +229,54 @@ vector<StackVariableReference> Function::GetStackVariablesReferencedByInstructio
}
+set<size_t> Function::GetLowLevelILFlagUsesForDefinition(size_t i, uint32_t flag)
+{
+ size_t count;
+ size_t* instrs = BNGetLowLevelILFlagUsesForDefinition(m_object, i, flag, &count);
+
+ set<size_t> result;
+ result.insert(&instrs[0], &instrs[count]);
+ BNFreeLowLevelILInstructionList(instrs);
+ return result;
+}
+
+
+set<size_t> Function::GetLowLevelILFlagDefinitionsForUse(size_t i, uint32_t flag)
+{
+ size_t count;
+ size_t* instrs = BNGetLowLevelILFlagDefinitionsForUse(m_object, i, flag, &count);
+
+ set<size_t> result;
+ result.insert(&instrs[0], &instrs[count]);
+ BNFreeLowLevelILInstructionList(instrs);
+ return result;
+}
+
+
+set<uint32_t> Function::GetFlagsReadByLowLevelILInstruction(size_t i)
+{
+ size_t count;
+ uint32_t* flags = BNGetFlagsReadByLowLevelILInstruction(m_object, i, &count);
+
+ set<uint32_t> result;
+ result.insert(&flags[0], &flags[count]);
+ BNFreeRegisterList(flags);
+ return result;
+}
+
+
+set<uint32_t> Function::GetFlagsWrittenByLowLevelILInstruction(size_t i)
+{
+ size_t count;
+ uint32_t* flags = BNGetFlagsWrittenByLowLevelILInstruction(m_object, i, &count);
+
+ set<uint32_t> result;
+ result.insert(&flags[0], &flags[count]);
+ BNFreeRegisterList(flags);
+ return result;
+}
+
+
Ref<Type> Function::GetType() const
{
return new Type(BNGetFunctionType(m_object));
@@ -313,3 +361,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;
+}