summaryrefslogtreecommitdiff
path: root/function.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'function.cpp')
-rw-r--r--function.cpp88
1 files changed, 85 insertions, 3 deletions
diff --git a/function.cpp b/function.cpp
index 2d8db04c..ba2b419e 100644
--- a/function.cpp
+++ b/function.cpp
@@ -490,6 +490,18 @@ Confidence<Ref<Type>> Function::GetReturnType() const
}
+Confidence<vector<uint32_t>> Function::GetReturnRegisters() const
+{
+ BNRegisterSetWithConfidence regs = BNGetFunctionReturnRegisters(m_object);
+ vector<uint32_t> regList;
+ for (size_t i = 0; i < regs.count; i++)
+ regList.push_back(regs.regs[i]);
+ Confidence<vector<uint32_t>> result(regList, regs.confidence);
+ BNFreeRegisterSet(&regs);
+ return result;
+}
+
+
Confidence<Ref<CallingConvention>> Function::GetCallingConvention() const
{
BNCallingConventionWithConfidence cc = BNGetFunctionCallingConvention(m_object);
@@ -530,6 +542,18 @@ Confidence<size_t> Function::GetStackAdjustment() const
}
+map<uint32_t, Confidence<int32_t>> Function::GetRegisterStackAdjustments() const
+{
+ size_t count;
+ BNRegisterStackAdjustment* regStackAdjust = BNGetFunctionRegisterStackAdjustments(m_object, &count);
+ map<uint32_t, Confidence<int32_t>> result;
+ for (size_t i = 0; i < count; i++)
+ result[regStackAdjust[i].regStack] = Confidence<int32_t>(regStackAdjust[i].adjustment, regStackAdjust[i].confidence);
+ BNFreeRegisterStackAdjustments(regStackAdjust);
+ return result;
+}
+
+
Confidence<set<uint32_t>> Function::GetClobberedRegisters() const
{
BNRegisterSetWithConfidence regs = BNGetFunctionClobberedRegisters(m_object);
@@ -537,7 +561,7 @@ Confidence<set<uint32_t>> Function::GetClobberedRegisters() const
for (size_t i = 0; i < regs.count; i++)
regSet.insert(regs.regs[i]);
Confidence<set<uint32_t>> result(regSet, regs.confidence);
- BNFreeClobberedRegisters(&regs);
+ BNFreeRegisterSet(&regs);
return result;
}
@@ -557,6 +581,19 @@ void Function::SetAutoReturnType(const Confidence<Ref<Type>>& type)
}
+void Function::SetAutoReturnRegisters(const Confidence<std::vector<uint32_t>>& returnRegs)
+{
+ BNRegisterSetWithConfidence regs;
+ regs.regs = new uint32_t[returnRegs.GetValue().size()];
+ regs.count = returnRegs.GetValue().size();
+ for (size_t i = 0; i < regs.count; i++)
+ regs.regs[i] = returnRegs.GetValue()[i];
+ regs.confidence = returnRegs.GetConfidence();
+ BNSetAutoFunctionReturnRegisters(m_object, &regs);
+ delete[] regs.regs;
+}
+
+
void Function::SetAutoCallingConvention(const Confidence<Ref<CallingConvention>>& convention)
{
BNCallingConventionWithConfidence cc;
@@ -611,6 +648,22 @@ void Function::SetAutoStackAdjustment(const Confidence<size_t>& stackAdjust)
}
+void Function::SetAutoRegisterStackAdjustments(const map<uint32_t, Confidence<int32_t>>& regStackAdjust)
+{
+ BNRegisterStackAdjustment* adjust = new BNRegisterStackAdjustment[regStackAdjust.size()];
+ size_t i = 0;
+ for (auto& j : regStackAdjust)
+ {
+ adjust[i].regStack = j.first;
+ adjust[i].adjustment = j.second.GetValue();
+ adjust[i].confidence = j.second.GetConfidence();
+ i++;
+ }
+ BNSetAutoFunctionRegisterStackAdjustments(m_object, adjust, regStackAdjust.size());
+ delete[] adjust;
+}
+
+
void Function::SetAutoClobberedRegisters(const Confidence<std::set<uint32_t>>& clobbered)
{
BNRegisterSetWithConfidence regs;
@@ -640,6 +693,19 @@ void Function::SetReturnType(const Confidence<Ref<Type>>& type)
}
+void Function::SetReturnRegisters(const Confidence<std::vector<uint32_t>>& returnRegs)
+{
+ BNRegisterSetWithConfidence regs;
+ regs.regs = new uint32_t[returnRegs.GetValue().size()];
+ regs.count = returnRegs.GetValue().size();
+ for (size_t i = 0; i < regs.count; i++)
+ regs.regs[i] = returnRegs.GetValue()[i];
+ regs.confidence = returnRegs.GetConfidence();
+ BNSetUserFunctionReturnRegisters(m_object, &regs);
+ delete[] regs.regs;
+}
+
+
void Function::SetCallingConvention(const Confidence<Ref<CallingConvention>>& convention)
{
BNCallingConventionWithConfidence cc;
@@ -694,6 +760,22 @@ void Function::SetStackAdjustment(const Confidence<size_t>& stackAdjust)
}
+void Function::SetRegisterStackAdjustments(const map<uint32_t, Confidence<int32_t>>& regStackAdjust)
+{
+ BNRegisterStackAdjustment* adjust = new BNRegisterStackAdjustment[regStackAdjust.size()];
+ size_t i = 0;
+ for (auto& j : regStackAdjust)
+ {
+ adjust[i].regStack = j.first;
+ adjust[i].adjustment = j.second.GetValue();
+ adjust[i].confidence = j.second.GetConfidence();
+ i++;
+ }
+ BNSetUserFunctionRegisterStackAdjustments(m_object, adjust, regStackAdjust.size());
+ delete[] adjust;
+}
+
+
void Function::SetClobberedRegisters(const Confidence<std::set<uint32_t>>& clobbered)
{
BNRegisterSetWithConfidence regs;
@@ -743,7 +825,7 @@ map<int64_t, vector<VariableNameAndType>> Function::GetStackLayout()
result[vars[i].var.storage].push_back(var);
}
- BNFreeVariableList(vars, count);
+ BNFreeVariableNameAndTypeList(vars, count);
return result;
}
@@ -811,7 +893,7 @@ map<Variable, VariableNameAndType> Function::GetVariables()
result[vars[i].var] = var;
}
- BNFreeVariableList(vars, count);
+ BNFreeVariableNameAndTypeList(vars, count);
return result;
}