summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--binaryninjaapi.h15
-rw-r--r--binaryninjacore.h19
-rw-r--r--function.cpp90
-rw-r--r--python/function.py88
4 files changed, 212 insertions, 0 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index 650299ed..d7535184 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -2329,6 +2329,21 @@ namespace BinaryNinja
std::vector<IndirectBranchInfo> GetIndirectBranches();
std::vector<IndirectBranchInfo> GetIndirectBranchesAt(Architecture* arch, uint64_t addr);
+ void SetAutoCallStackAdjustment(Architecture* arch, uint64_t addr, const Confidence<size_t>& adjust);
+ void SetAutoCallRegisterStackAdjustment(Architecture* arch, uint64_t addr,
+ const std::map<uint32_t, Confidence<int32_t>>& adjust);
+ void SetAutoCallRegisterStackAdjustment(Architecture* arch, uint64_t addr, uint32_t regStack,
+ const Confidence<int32_t>& adjust);
+ void SetUserCallStackAdjustment(Architecture* arch, uint64_t addr, const Confidence<size_t>& adjust);
+ void SetUserCallRegisterStackAdjustment(Architecture* arch, uint64_t addr,
+ const std::map<uint32_t, Confidence<int32_t>>& adjust);
+ void SetUserCallRegisterStackAdjustment(Architecture* arch, uint64_t addr, uint32_t regStack,
+ const Confidence<int32_t>& adjust);
+
+ Confidence<size_t> GetCallStackAdjustment(Architecture* arch, uint64_t addr);
+ std::map<uint32_t, Confidence<int32_t>> GetCallRegisterStackAdjustment(Architecture* arch, uint64_t addr);
+ Confidence<int32_t> GetCallRegisterStackAdjustment(Architecture* arch, uint64_t addr, uint32_t regStack);
+
std::vector<std::vector<InstructionTextToken>> GetBlockAnnotations(Architecture* arch, uint64_t addr);
BNIntegerDisplayType GetIntegerConstantDisplayType(Architecture* arch, uint64_t instrAddr, uint64_t value,
diff --git a/binaryninjacore.h b/binaryninjacore.h
index 945badce..a9c38ed6 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -2383,6 +2383,25 @@ extern "C"
uint64_t addr, size_t* count);
BINARYNINJACOREAPI void BNFreeIndirectBranchList(BNIndirectBranchInfo* branches);
+ BINARYNINJACOREAPI void BNSetAutoCallStackAdjustment(BNFunction* func, BNArchitecture* arch, uint64_t addr,
+ size_t adjust, uint8_t confidence);
+ BINARYNINJACOREAPI void BNSetUserCallStackAdjustment(BNFunction* func, BNArchitecture* arch, uint64_t addr,
+ size_t adjust, uint8_t confidence);
+ BINARYNINJACOREAPI void BNSetAutoCallRegisterStackAdjustment(BNFunction* func, BNArchitecture* arch, uint64_t addr,
+ BNRegisterStackAdjustment* adjust, size_t count);
+ BINARYNINJACOREAPI void BNSetUserCallRegisterStackAdjustment(BNFunction* func, BNArchitecture* arch, uint64_t addr,
+ BNRegisterStackAdjustment* adjust, size_t count);
+ BINARYNINJACOREAPI void BNSetAutoCallRegisterStackAdjustmentForRegisterStack(BNFunction* func,
+ BNArchitecture* arch, uint64_t addr, uint32_t regStack, int32_t adjust, uint8_t confidence);
+ BINARYNINJACOREAPI void BNSetUserCallRegisterStackAdjustmentForRegisterStack(BNFunction* func,
+ BNArchitecture* arch, uint64_t addr, uint32_t regStack, int32_t adjust, uint8_t confidence);
+
+ BINARYNINJACOREAPI BNSizeWithConfidence BNGetCallStackAdjustment(BNFunction* func, BNArchitecture* arch, uint64_t addr);
+ BINARYNINJACOREAPI BNRegisterStackAdjustment* BNGetCallRegisterStackAdjustment(BNFunction* func,
+ BNArchitecture* arch, uint64_t addr, size_t* count);
+ BINARYNINJACOREAPI BNRegisterStackAdjustment BNGetCallRegisterStackAdjustmentForRegisterStack(BNFunction* func,
+ BNArchitecture* arch, uint64_t addr, uint32_t regStack);
+
BINARYNINJACOREAPI BNInstructionTextLine* BNGetFunctionBlockAnnotations(BNFunction* func, BNArchitecture* arch,
uint64_t addr, size_t* count);
BINARYNINJACOREAPI void BNFreeInstructionTextLines(BNInstructionTextLine* lines, size_t count);
diff --git a/function.cpp b/function.cpp
index ba2b419e..cd9be4d5 100644
--- a/function.cpp
+++ b/function.cpp
@@ -1018,6 +1018,96 @@ vector<IndirectBranchInfo> Function::GetIndirectBranchesAt(Architecture* arch, u
}
+void Function::SetAutoCallStackAdjustment(Architecture* arch, uint64_t addr, const Confidence<size_t>& adjust)
+{
+ BNSetAutoCallStackAdjustment(m_object, arch->GetObject(), addr, adjust.GetValue(), adjust.GetConfidence());
+}
+
+
+void Function::SetAutoCallRegisterStackAdjustment(Architecture* arch, uint64_t addr,
+ const map<uint32_t, Confidence<int32_t>>& adjust)
+{
+ BNRegisterStackAdjustment* values = new BNRegisterStackAdjustment[adjust.size()];
+ size_t i = 0;
+ for (auto& j : adjust)
+ {
+ values[i].regStack = j.first;
+ values[i].adjustment = j.second.GetValue();
+ values[i].confidence = j.second.GetConfidence();
+ i++;
+ }
+ BNSetAutoCallRegisterStackAdjustment(m_object, arch->GetObject(), addr, values, adjust.size());
+ delete[] values;
+}
+
+
+void Function::SetAutoCallRegisterStackAdjustment(Architecture* arch, uint64_t addr, uint32_t regStack,
+ const Confidence<int32_t>& adjust)
+{
+ BNSetAutoCallRegisterStackAdjustmentForRegisterStack(m_object, arch->GetObject(), addr, regStack,
+ adjust.GetValue(), adjust.GetConfidence());
+}
+
+
+void Function::SetUserCallStackAdjustment(Architecture* arch, uint64_t addr, const Confidence<size_t>& adjust)
+{
+ BNSetUserCallStackAdjustment(m_object, arch->GetObject(), addr, adjust.GetValue(), adjust.GetConfidence());
+}
+
+
+void Function::SetUserCallRegisterStackAdjustment(Architecture* arch, uint64_t addr,
+ const map<uint32_t, Confidence<int32_t>>& adjust)
+{
+ BNRegisterStackAdjustment* values = new BNRegisterStackAdjustment[adjust.size()];
+ size_t i = 0;
+ for (auto& j : adjust)
+ {
+ values[i].regStack = j.first;
+ values[i].adjustment = j.second.GetValue();
+ values[i].confidence = j.second.GetConfidence();
+ i++;
+ }
+ BNSetUserCallRegisterStackAdjustment(m_object, arch->GetObject(), addr, values, adjust.size());
+ delete[] values;
+}
+
+
+void Function::SetUserCallRegisterStackAdjustment(Architecture* arch, uint64_t addr, uint32_t regStack,
+ const Confidence<int32_t>& adjust)
+{
+ BNSetUserCallRegisterStackAdjustmentForRegisterStack(m_object, arch->GetObject(), addr, regStack,
+ adjust.GetValue(), adjust.GetConfidence());
+}
+
+
+Confidence<size_t> Function::GetCallStackAdjustment(Architecture* arch, uint64_t addr)
+{
+ BNSizeWithConfidence result = BNGetCallStackAdjustment(m_object, arch->GetObject(), addr);
+ return Confidence<size_t>(result.value, result.confidence);
+}
+
+
+map<uint32_t, Confidence<int32_t>> Function::GetCallRegisterStackAdjustment(Architecture* arch, uint64_t addr)
+{
+ size_t count;
+ BNRegisterStackAdjustment* adjust = BNGetCallRegisterStackAdjustment(m_object, arch->GetObject(), addr, &count);
+
+ map<uint32_t, Confidence<int32_t>> result;
+ for (size_t i = 0; i < count; i++)
+ result[adjust[i].regStack] = Confidence<int32_t>(adjust[i].adjustment, adjust[i].confidence);
+ BNFreeRegisterStackAdjustments(adjust);
+ return result;
+}
+
+
+Confidence<int32_t> Function::GetCallRegisterStackAdjustment(Architecture* arch, uint64_t addr, uint32_t regStack)
+{
+ BNRegisterStackAdjustment result = BNGetCallRegisterStackAdjustmentForRegisterStack(m_object,
+ arch->GetObject(), addr, regStack);
+ return Confidence<int32_t>(result.adjustment, result.confidence);
+}
+
+
vector<vector<InstructionTextToken>> Function::GetBlockAnnotations(Architecture* arch, uint64_t addr)
{
size_t count;
diff --git a/python/function.py b/python/function.py
index 7607657f..664afcd0 100644
--- a/python/function.py
+++ b/python/function.py
@@ -1453,6 +1453,94 @@ class Function(object):
result = core.BNGetFunctionRegisterValueAtExit(self.handle, self.arch.get_reg_index(reg))
return RegisterValue(self.arch, result.value, confidence = result.confidence)
+ def set_auto_call_stack_adjustment(self, addr, adjust, arch=None):
+ if arch is None:
+ arch = self.arch
+ if not isinstance(adjust, types.SizeWithConfidence):
+ adjust = types.SizeWithConfidence(adjust)
+ core.BNSetAutoCallStackAdjustment(self.handle, arch.handle, addr, adjust.value, adjust.confidence)
+
+ def set_auto_call_reg_stack_adjustment(self, addr, adjust, arch=None):
+ if arch is None:
+ arch = self.arch
+ adjust_buf = (core.BNRegisterStackAdjustment * len(adjust))()
+ i = 0
+ for reg_stack in adjust.keys():
+ adjust_buf[i].regStack = arch.get_reg_stack_index(reg_stack)
+ value = adjust[reg_stack]
+ if not isinstance(value, types.RegisterStackAdjustmentWithConfidence):
+ value = types.RegisterStackAdjustmentWithConfidence(value)
+ adjust_buf[i].adjustment = value.value
+ adjust_buf[i].confidence = value.confidence
+ i += 1
+ core.BNSetAutoCallRegisterStackAdjustment(self.handle, arch.handle, addr, adjust_buf, len(adjust))
+
+ def set_auto_call_reg_stack_adjustment_for_reg_stack(self, addr, reg_stack, adjust, arch=None):
+ if arch is None:
+ arch = self.arch
+ reg_stack = arch.get_reg_stack_index(reg_stack)
+ if not isinstance(adjust, types.RegisterStackAdjustmentWithConfidence):
+ adjust = types.RegisterStackAdjustmentWithConfidence(adjust)
+ core.BNSetAutoCallRegisterStackAdjustmentForRegisterStack(self.handle, arch.handle, addr, reg_stack,
+ adjust.value, adjust.confidence)
+
+ def set_call_stack_adjustment(self, addr, adjust, arch=None):
+ if arch is None:
+ arch = self.arch
+ if not isinstance(adjust, types.SizeWithConfidence):
+ adjust = types.SizeWithConfidence(adjust)
+ core.BNSetUserCallStackAdjustment(self.handle, arch.handle, addr, adjust.value, adjust.confidence)
+
+ def set_call_reg_stack_adjustment(self, addr, adjust, arch=None):
+ if arch is None:
+ arch = self.arch
+ adjust_buf = (core.BNRegisterStackAdjustment * len(adjust))()
+ i = 0
+ for reg_stack in adjust.keys():
+ adjust_buf[i].regStack = arch.get_reg_stack_index(reg_stack)
+ value = adjust[reg_stack]
+ if not isinstance(value, types.RegisterStackAdjustmentWithConfidence):
+ value = types.RegisterStackAdjustmentWithConfidence(value)
+ adjust_buf[i].adjustment = value.value
+ adjust_buf[i].confidence = value.confidence
+ i += 1
+ core.BNSetUserCallRegisterStackAdjustment(self.handle, arch.handle, addr, adjust_buf, len(adjust))
+
+ def set_call_reg_stack_adjustment_for_reg_stack(self, addr, reg_stack, adjust, arch=None):
+ if arch is None:
+ arch = self.arch
+ reg_stack = arch.get_reg_stack_index(reg_stack)
+ if not isinstance(adjust, types.RegisterStackAdjustmentWithConfidence):
+ adjust = types.RegisterStackAdjustmentWithConfidence(adjust)
+ core.BNSetUserCallRegisterStackAdjustmentForRegisterStack(self.handle, arch.handle, addr, reg_stack,
+ adjust.value, adjust.confidence)
+
+ def get_call_stack_adjustment(self, addr, arch=None):
+ if arch is None:
+ arch = self.arch
+ result = core.BNGetCallStackAdjustment(self.handle, arch.handle, addr)
+ return types.SizeWithConfidence(result.value, confidence = result.confidence)
+
+ def get_call_reg_stack_adjustment(self, addr, arch=None):
+ if arch is None:
+ arch = self.arch
+ count = ctypes.c_ulonglong()
+ adjust = core.BNGetCallRegisterStackAdjustment(self.handle, arch.handle, addr, count)
+ result = {}
+ for i in xrange(0, count.value):
+ result[arch.get_reg_stack_name(adjust[i].regStack)] = types.RegisterStackAdjustmentWithConfidence(
+ adjust[i].adjustment, confidence = adjust[i].confidence)
+ core.BNFreeRegisterStackAdjustments(adjust)
+ return result
+
+ def get_call_reg_stack_adjustment_for_reg_stack(self, addr, reg_stack, arch=None):
+ if arch is None:
+ arch = self.arch
+ reg_stack = arch.get_reg_stack_index(reg_stack)
+ adjust = core.BNGetCallRegisterStackAdjustmentForRegisterStack(self.handle, arch.handle, addr, reg_stack)
+ result = types.RegisterStackAdjustmentWithConfidence(adjust.adjustment, confidence = adjust.confidence)
+ return result
+
class AdvancedFunctionAnalysisDataRequestor(object):
def __init__(self, func = None):