diff options
| author | Rusty Wagner <rusty@vector35.com> | 2018-08-30 22:11:22 -0400 |
|---|---|---|
| committer | Rusty Wagner <rusty@vector35.com> | 2018-08-30 22:11:22 -0400 |
| commit | acf28440dc4e8d805a057b6271a73e0d4e8c9e4f (patch) | |
| tree | ba61688a1dddbce6d66735c538e4204621fc0498 | |
| parent | 20e06506a3d96c7327ca5d729ab01e8c2a7cff3c (diff) | |
Allow negative stack offsets for functions like alloca_probe
| -rw-r--r-- | binaryninjaapi.h | 18 | ||||
| -rw-r--r-- | binaryninjacore.h | 22 | ||||
| -rw-r--r-- | function.cpp | 36 | ||||
| -rw-r--r-- | lowlevelilinstruction.cpp | 6 | ||||
| -rw-r--r-- | lowlevelilinstruction.h | 6 | ||||
| -rw-r--r-- | python/function.py | 20 | ||||
| -rw-r--r-- | python/types.py | 2 | ||||
| -rw-r--r-- | type.cpp | 10 |
8 files changed, 63 insertions, 57 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index b5c2867b..722edcd3 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -2111,7 +2111,7 @@ namespace BinaryNinja void SetConst(const Confidence<bool>& cnst); void SetVolatile(const Confidence<bool>& vltl); void SetTypeName(const QualifiedName& name); - Confidence<size_t> GetStackAdjustment() const; + Confidence<int64_t> GetStackAdjustment() const; uint64_t GetElementCount() const; uint64_t GetOffset() const; @@ -2152,7 +2152,7 @@ namespace BinaryNinja static Ref<Type> FunctionType(const Confidence<Ref<Type>>& returnValue, const Confidence<Ref<CallingConvention>>& callingConvention, const std::vector<FunctionParameter>& params, const Confidence<bool>& varArg = Confidence<bool>(false, 0), - const Confidence<size_t>& stackAdjust = Confidence<size_t>(0, 0)); + const Confidence<int64_t>& stackAdjust = Confidence<int64_t>(0, 0)); static std::string GenerateAutoTypeId(const std::string& source, const QualifiedName& name); static std::string GenerateAutoDemangledTypeId(const QualifiedName& name); @@ -2437,7 +2437,7 @@ namespace BinaryNinja Confidence<Ref<CallingConvention>> GetCallingConvention() const; Confidence<std::vector<Variable>> GetParameterVariables() const; Confidence<bool> HasVariableArguments() const; - Confidence<size_t> GetStackAdjustment() const; + Confidence<int64_t> GetStackAdjustment() const; std::map<uint32_t, Confidence<int32_t>> GetRegisterStackAdjustments() const; Confidence<std::set<uint32_t>> GetClobberedRegisters() const; @@ -2448,7 +2448,7 @@ namespace BinaryNinja void SetAutoParameterVariables(const Confidence<std::vector<Variable>>& vars); void SetAutoHasVariableArguments(const Confidence<bool>& varArgs); void SetAutoCanReturn(const Confidence<bool>& returns); - void SetAutoStackAdjustment(const Confidence<size_t>& stackAdjust); + void SetAutoStackAdjustment(const Confidence<int64_t>& stackAdjust); void SetAutoRegisterStackAdjustments(const std::map<uint32_t, Confidence<int32_t>>& regStackAdjust); void SetAutoClobberedRegisters(const Confidence<std::set<uint32_t>>& clobbered); @@ -2459,7 +2459,7 @@ namespace BinaryNinja void SetParameterVariables(const Confidence<std::vector<Variable>>& vars); void SetHasVariableArguments(const Confidence<bool>& varArgs); void SetCanReturn(const Confidence<bool>& returns); - void SetStackAdjustment(const Confidence<size_t>& stackAdjust); + void SetStackAdjustment(const Confidence<int64_t>& stackAdjust); void SetRegisterStackAdjustments(const std::map<uint32_t, Confidence<int32_t>>& regStackAdjust); void SetClobberedRegisters(const Confidence<std::set<uint32_t>>& clobbered); @@ -2491,18 +2491,18 @@ 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 SetAutoCallStackAdjustment(Architecture* arch, uint64_t addr, const Confidence<int64_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 SetUserCallStackAdjustment(Architecture* arch, uint64_t addr, const Confidence<int64_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); + Confidence<int64_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); bool IsCallInstruction(Architecture* arch, uint64_t addr); @@ -2875,7 +2875,7 @@ namespace BinaryNinja ExprId JumpTo(ExprId dest, const std::vector<BNLowLevelILLabel*>& targets, const ILSourceLocation& loc = ILSourceLocation()); ExprId Call(ExprId dest, const ILSourceLocation& loc = ILSourceLocation()); - ExprId CallStackAdjust(ExprId dest, size_t adjust, const std::map<uint32_t, int32_t>& regStackAdjust, + ExprId CallStackAdjust(ExprId dest, int64_t adjust, const std::map<uint32_t, int32_t>& regStackAdjust, const ILSourceLocation& loc = ILSourceLocation()); ExprId TailCall(ExprId dest, const ILSourceLocation& loc = ILSourceLocation()); ExprId CallSSA(const std::vector<SSARegister>& output, ExprId dest, const std::vector<ExprId>& params, diff --git a/binaryninjacore.h b/binaryninjacore.h index 21b04bfa..b15ceabd 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -1304,6 +1304,12 @@ extern "C" uint8_t confidence; }; + struct BNOffsetWithConfidence + { + int64_t value; + uint8_t confidence; + }; + struct BNMemberScopeWithConfidence { BNMemberScope value; @@ -2397,7 +2403,7 @@ extern "C" BINARYNINJACOREAPI BNParameterVariablesWithConfidence BNGetFunctionParameterVariables(BNFunction* func); BINARYNINJACOREAPI void BNFreeParameterVariables(BNParameterVariablesWithConfidence* vars); BINARYNINJACOREAPI BNBoolWithConfidence BNFunctionHasVariableArguments(BNFunction* func); - BINARYNINJACOREAPI BNSizeWithConfidence BNGetFunctionStackAdjustment(BNFunction* func); + BINARYNINJACOREAPI BNOffsetWithConfidence BNGetFunctionStackAdjustment(BNFunction* func); BINARYNINJACOREAPI BNRegisterStackAdjustment* BNGetFunctionRegisterStackAdjustments(BNFunction* func, size_t* count); BINARYNINJACOREAPI void BNFreeRegisterStackAdjustments(BNRegisterStackAdjustment* adjustments); BINARYNINJACOREAPI BNRegisterSetWithConfidence BNGetFunctionClobberedRegisters(BNFunction* func); @@ -2409,7 +2415,7 @@ extern "C" BINARYNINJACOREAPI void BNSetAutoFunctionParameterVariables(BNFunction* func, BNParameterVariablesWithConfidence* vars); BINARYNINJACOREAPI void BNSetAutoFunctionHasVariableArguments(BNFunction* func, BNBoolWithConfidence* varArgs); BINARYNINJACOREAPI void BNSetAutoFunctionCanReturn(BNFunction* func, BNBoolWithConfidence* returns); - BINARYNINJACOREAPI void BNSetAutoFunctionStackAdjustment(BNFunction* func, BNSizeWithConfidence* stackAdjust); + BINARYNINJACOREAPI void BNSetAutoFunctionStackAdjustment(BNFunction* func, BNOffsetWithConfidence* stackAdjust); BINARYNINJACOREAPI void BNSetAutoFunctionRegisterStackAdjustments(BNFunction* func, BNRegisterStackAdjustment* adjustments, size_t count); BINARYNINJACOREAPI void BNSetAutoFunctionClobberedRegisters(BNFunction* func, BNRegisterSetWithConfidence* regs); @@ -2420,7 +2426,7 @@ extern "C" BINARYNINJACOREAPI void BNSetUserFunctionParameterVariables(BNFunction* func, BNParameterVariablesWithConfidence* vars); BINARYNINJACOREAPI void BNSetUserFunctionHasVariableArguments(BNFunction* func, BNBoolWithConfidence* varArgs); BINARYNINJACOREAPI void BNSetUserFunctionCanReturn(BNFunction* func, BNBoolWithConfidence* returns); - BINARYNINJACOREAPI void BNSetUserFunctionStackAdjustment(BNFunction* func, BNSizeWithConfidence* stackAdjust); + BINARYNINJACOREAPI void BNSetUserFunctionStackAdjustment(BNFunction* func, BNOffsetWithConfidence* stackAdjust); BINARYNINJACOREAPI void BNSetUserFunctionRegisterStackAdjustments(BNFunction* func, BNRegisterStackAdjustment* adjustments, size_t count); BINARYNINJACOREAPI void BNSetUserFunctionClobberedRegisters(BNFunction* func, BNRegisterSetWithConfidence* regs); @@ -2513,9 +2519,9 @@ extern "C" BINARYNINJACOREAPI void BNFreeIndirectBranchList(BNIndirectBranchInfo* branches); BINARYNINJACOREAPI void BNSetAutoCallStackAdjustment(BNFunction* func, BNArchitecture* arch, uint64_t addr, - size_t adjust, uint8_t confidence); + int64_t adjust, uint8_t confidence); BINARYNINJACOREAPI void BNSetUserCallStackAdjustment(BNFunction* func, BNArchitecture* arch, uint64_t addr, - size_t adjust, uint8_t confidence); + int64_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, @@ -2525,7 +2531,7 @@ extern "C" 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 BNOffsetWithConfidence 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, @@ -3027,7 +3033,7 @@ extern "C" BINARYNINJACOREAPI BNType* BNCreateArrayType(BNTypeWithConfidence* type, uint64_t elem); BINARYNINJACOREAPI BNType* BNCreateFunctionType(BNTypeWithConfidence* returnValue, BNCallingConventionWithConfidence* callingConvention, BNFunctionParameter* params, - size_t paramCount, BNBoolWithConfidence* varArg, BNSizeWithConfidence* stackAdjust); + size_t paramCount, BNBoolWithConfidence* varArg, BNOffsetWithConfidence* stackAdjust); BINARYNINJACOREAPI BNType* BNNewTypeReference(BNType* type); BINARYNINJACOREAPI BNType* BNDuplicateType(BNType* type); BINARYNINJACOREAPI char* BNGetTypeAndName(BNType* type, BNQualifiedName* name); @@ -3060,7 +3066,7 @@ extern "C" BINARYNINJACOREAPI void BNTypeSetMemberAccess(BNType* type, BNMemberAccessWithConfidence* access); BINARYNINJACOREAPI void BNTypeSetConst(BNType* type, BNBoolWithConfidence* cnst); BINARYNINJACOREAPI void BNTypeSetVolatile(BNType* type, BNBoolWithConfidence* vltl); - BINARYNINJACOREAPI BNSizeWithConfidence BNGetTypeStackAdjustment(BNType* type); + BINARYNINJACOREAPI BNOffsetWithConfidence BNGetTypeStackAdjustment(BNType* type); BINARYNINJACOREAPI char* BNGetTypeString(BNType* type, BNPlatform* platform); BINARYNINJACOREAPI char* BNGetTypeStringBeforeName(BNType* type, BNPlatform* platform); diff --git a/function.cpp b/function.cpp index 35fe4123..167a6285 100644 --- a/function.cpp +++ b/function.cpp @@ -538,10 +538,10 @@ Confidence<bool> Function::HasVariableArguments() const } -Confidence<size_t> Function::GetStackAdjustment() const +Confidence<int64_t> Function::GetStackAdjustment() const { - BNSizeWithConfidence sc = BNGetFunctionStackAdjustment(m_object); - return Confidence<size_t>(sc.value, sc.confidence); + BNOffsetWithConfidence oc = BNGetFunctionStackAdjustment(m_object); + return Confidence<int64_t>(oc.value, oc.confidence); } @@ -643,12 +643,12 @@ void Function::SetAutoCanReturn(const Confidence<bool>& returns) } -void Function::SetAutoStackAdjustment(const Confidence<size_t>& stackAdjust) +void Function::SetAutoStackAdjustment(const Confidence<int64_t>& stackAdjust) { - BNSizeWithConfidence sc; - sc.value = stackAdjust.GetValue(); - sc.confidence = stackAdjust.GetConfidence(); - BNSetAutoFunctionStackAdjustment(m_object, &sc); + BNOffsetWithConfidence oc; + oc.value = stackAdjust.GetValue(); + oc.confidence = stackAdjust.GetConfidence(); + BNSetAutoFunctionStackAdjustment(m_object, &oc); } @@ -757,12 +757,12 @@ void Function::SetCanReturn(const Confidence<bool>& returns) } -void Function::SetStackAdjustment(const Confidence<size_t>& stackAdjust) +void Function::SetStackAdjustment(const Confidence<int64_t>& stackAdjust) { - BNSizeWithConfidence sc; - sc.value = stackAdjust.GetValue(); - sc.confidence = stackAdjust.GetConfidence(); - BNSetUserFunctionStackAdjustment(m_object, &sc); + BNOffsetWithConfidence oc; + oc.value = stackAdjust.GetValue(); + oc.confidence = stackAdjust.GetConfidence(); + BNSetUserFunctionStackAdjustment(m_object, &oc); } @@ -1026,7 +1026,7 @@ vector<IndirectBranchInfo> Function::GetIndirectBranchesAt(Architecture* arch, u } -void Function::SetAutoCallStackAdjustment(Architecture* arch, uint64_t addr, const Confidence<size_t>& adjust) +void Function::SetAutoCallStackAdjustment(Architecture* arch, uint64_t addr, const Confidence<int64_t>& adjust) { BNSetAutoCallStackAdjustment(m_object, arch->GetObject(), addr, adjust.GetValue(), adjust.GetConfidence()); } @@ -1057,7 +1057,7 @@ void Function::SetAutoCallRegisterStackAdjustment(Architecture* arch, uint64_t a } -void Function::SetUserCallStackAdjustment(Architecture* arch, uint64_t addr, const Confidence<size_t>& adjust) +void Function::SetUserCallStackAdjustment(Architecture* arch, uint64_t addr, const Confidence<int64_t>& adjust) { BNSetUserCallStackAdjustment(m_object, arch->GetObject(), addr, adjust.GetValue(), adjust.GetConfidence()); } @@ -1088,10 +1088,10 @@ void Function::SetUserCallRegisterStackAdjustment(Architecture* arch, uint64_t a } -Confidence<size_t> Function::GetCallStackAdjustment(Architecture* arch, uint64_t addr) +Confidence<int64_t> Function::GetCallStackAdjustment(Architecture* arch, uint64_t addr) { - BNSizeWithConfidence result = BNGetCallStackAdjustment(m_object, arch->GetObject(), addr); - return Confidence<size_t>(result.value, result.confidence); + BNOffsetWithConfidence result = BNGetCallStackAdjustment(m_object, arch->GetObject(), addr); + return Confidence<int64_t>(result.value, result.confidence); } diff --git a/lowlevelilinstruction.cpp b/lowlevelilinstruction.cpp index 5f5dc397..9ceef260 100644 --- a/lowlevelilinstruction.cpp +++ b/lowlevelilinstruction.cpp @@ -2498,11 +2498,11 @@ int64_t LowLevelILInstruction::GetVector() const } -size_t LowLevelILInstruction::GetStackAdjustment() const +int64_t LowLevelILInstruction::GetStackAdjustment() const { size_t operandIndex; if (GetOperandIndexForUsage(StackAdjustmentLowLevelOperandUsage, operandIndex)) - return (size_t)GetRawOperandAsInteger(operandIndex); + return GetRawOperandAsInteger(operandIndex); throw LowLevelILInstructionAccessException(); } @@ -3163,7 +3163,7 @@ ExprId LowLevelILFunction::Call(ExprId dest, const ILSourceLocation& loc) } -ExprId LowLevelILFunction::CallStackAdjust(ExprId dest, size_t adjust, +ExprId LowLevelILFunction::CallStackAdjust(ExprId dest, int64_t adjust, const std::map<uint32_t, int32_t>& regStackAdjust, const ILSourceLocation& loc) { vector<size_t> list; diff --git a/lowlevelilinstruction.h b/lowlevelilinstruction.h index e845bcd0..365575f8 100644 --- a/lowlevelilinstruction.h +++ b/lowlevelilinstruction.h @@ -712,7 +712,7 @@ namespace BinaryNinja template <BNLowLevelILOperation N> uint32_t GetIntrinsic() const { return As<N>().GetIntrinsic(); } template <BNLowLevelILOperation N> int64_t GetConstant() const { return As<N>().GetConstant(); } template <BNLowLevelILOperation N> int64_t GetVector() const { return As<N>().GetVector(); } - template <BNLowLevelILOperation N> size_t GetStackAdjustment() const { return As<N>().GetStackAdjustment(); } + template <BNLowLevelILOperation N> int64_t GetStackAdjustment() const { return As<N>().GetStackAdjustment(); } template <BNLowLevelILOperation N> size_t GetTarget() const { return As<N>().GetTarget(); } template <BNLowLevelILOperation N> size_t GetTrueTarget() const { return As<N>().GetTrueTarget(); } template <BNLowLevelILOperation N> size_t GetFalseTarget() const { return As<N>().GetFalseTarget(); } @@ -776,7 +776,7 @@ namespace BinaryNinja uint32_t GetIntrinsic() const; int64_t GetConstant() const; int64_t GetVector() const; - size_t GetStackAdjustment() const; + int64_t GetStackAdjustment() const; size_t GetTarget() const; size_t GetTrueTarget() const; size_t GetFalseTarget() const; @@ -1104,7 +1104,7 @@ namespace BinaryNinja template <> struct LowLevelILInstructionAccessor<LLIL_CALL_STACK_ADJUST>: public LowLevelILInstructionBase { LowLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(0); } - size_t GetStackAdjustment() const { return (size_t)GetRawOperandAsInteger(1); } + int64_t GetStackAdjustment() const { return GetRawOperandAsInteger(1); } std::map<uint32_t, int32_t> GetRegisterStackAdjustments() const { return GetRawOperandAsRegisterStackAdjustments(2); } }; template <> struct LowLevelILInstructionAccessor<LLIL_TAILCALL>: public LowLevelILInstructionBase diff --git a/python/function.py b/python/function.py index 295eec7e..6da86196 100644 --- a/python/function.py +++ b/python/function.py @@ -704,13 +704,13 @@ class Function(object): @stack_adjustment.setter def stack_adjustment(self, value): - sc = core.BNSizeWithConfidence() - sc.value = int(value) + oc = core.BNOffsetWithConfidence() + oc.value = int(value) if hasattr(value, 'confidence'): - sc.confidence = value.confidence + oc.confidence = value.confidence else: - sc.confidence = types.max_confidence - core.BNSetUserFunctionStackAdjustment(self.handle, sc) + oc.confidence = types.max_confidence + core.BNSetUserFunctionStackAdjustment(self.handle, oc) @property def reg_stack_adjustments(self): @@ -1262,13 +1262,13 @@ class Function(object): core.BNSetAutoFunctionCanReturn(self.handle, bc) def set_auto_stack_adjustment(self, value): - sc = core.BNSizeWithConfidence() - sc.value = int(value) + oc = core.BNOffsetWithConfidence() + oc.value = int(value) if hasattr(value, 'confidence'): - sc.confidence = value.confidence + oc.confidence = value.confidence else: - sc.confidence = types.max_confidence - core.BNSetAutoFunctionStackAdjustment(self.handle, sc) + oc.confidence = types.max_confidence + core.BNSetAutoFunctionStackAdjustment(self.handle, oc) def set_auto_reg_stack_adjustments(self, value): adjust = (core.BNRegisterStackAdjustment * len(value))() diff --git a/python/types.py b/python/types.py index 12e7733f..b0db5f33 100644 --- a/python/types.py +++ b/python/types.py @@ -630,7 +630,7 @@ class Type(object): elif not isinstance(stack_adjust, SizeWithConfidence): stack_adjust = SizeWithConfidence(stack_adjust) - stack_adjust_conf = core.BNSizeWithConfidence() + stack_adjust_conf = core.BNOffsetWithConfidence() stack_adjust_conf.value = stack_adjust.value stack_adjust_conf.confidence = stack_adjust.confidence @@ -435,10 +435,10 @@ uint64_t Type::GetOffset() const } -Confidence<size_t> Type::GetStackAdjustment() const +Confidence<int64_t> Type::GetStackAdjustment() const { - BNSizeWithConfidence result = BNGetTypeStackAdjustment(m_object); - return Confidence<size_t>(result.value, result.confidence); + BNOffsetWithConfidence result = BNGetTypeStackAdjustment(m_object); + return Confidence<int64_t>(result.value, result.confidence); } @@ -654,7 +654,7 @@ Ref<Type> Type::ArrayType(const Confidence<Ref<Type>>& type, uint64_t elem) Ref<Type> Type::FunctionType(const Confidence<Ref<Type>>& returnValue, const Confidence<Ref<CallingConvention>>& callingConvention, const std::vector<FunctionParameter>& params, const Confidence<bool>& varArg, - const Confidence<size_t>& stackAdjust) + const Confidence<int64_t>& stackAdjust) { BNTypeWithConfidence returnValueConf; returnValueConf.type = returnValue->GetObject(); @@ -680,7 +680,7 @@ Ref<Type> Type::FunctionType(const Confidence<Ref<Type>>& returnValue, varArgConf.value = varArg.GetValue(); varArgConf.confidence = varArg.GetConfidence(); - BNSizeWithConfidence stackAdjustConf; + BNOffsetWithConfidence stackAdjustConf; stackAdjustConf.value = stackAdjust.GetValue(); stackAdjustConf.confidence = stackAdjust.GetConfidence(); |
