Classes | |
| struct | BinaryNinja::CallLayout |
| class | BinaryNinja::CallingConvention |
| class | BinaryNinja::CoreCallingConvention |
| struct BinaryNinja::CallLayout |
Public Member Functions | |
| BNCallLayout | ToAPIObject () const |
Static Public Member Functions | |
| static CallLayout | FromAPIObject (BNCallLayout *layout) |
| static void | FreeAPIObject (BNCallLayout *layout) |
Public Attributes | |
| std::vector< ValueLocation > | parameters |
| std::optional< ValueLocation > | returnValue |
| int64_t | stackAdjustment = 0 |
| std::map< uint32_t, int32_t > | registerStackAdjustments |
|
static |
| BNCallLayout CallLayout::ToAPIObject | ( | ) | const |
|
static |
| std::vector<ValueLocation> BinaryNinja::CallLayout::parameters |
| std::optional<ValueLocation> BinaryNinja::CallLayout::returnValue |
| int64_t BinaryNinja::CallLayout::stackAdjustment = 0 |
| std::map<uint32_t, int32_t> BinaryNinja::CallLayout::registerStackAdjustments |
| class BinaryNinja::CallingConvention |
Public Member Functions | |
| Ref< Architecture > | GetArchitecture () const |
| Get the architecture this calling convention applies to. | |
| std::string | GetName () const |
| Get the name of this calling convention. | |
| virtual std::vector< uint32_t > | GetCallerSavedRegisters () |
| Gets the list of registers that are not preserved across a call (caller-saved / volatile registers). | |
| virtual std::vector< uint32_t > | GetCalleeSavedRegisters () |
| Gets the list of registers that a callee must preserve across a call (callee-saved / non-volatile registers). | |
| virtual std::vector< uint32_t > | GetIntegerArgumentRegisters () |
| Gets the registers used to pass integer and pointer arguments, in the order they are used. | |
| virtual std::vector< uint32_t > | GetFloatArgumentRegisters () |
| Gets the registers used to pass floating point arguments, in the order they are used. | |
| virtual std::vector< uint32_t > | GetRequiredArgumentRegisters () |
| Gets the set of registers that must be arguments for heuristic calling convention detection to consider this calling convention as a valid option. | |
| virtual std::vector< uint32_t > | GetRequiredClobberedRegisters () |
| Gets the set of registers that must be clobbered for heuristic calling convention detection to consider this calling convention as a valid option. | |
| virtual bool | AreArgumentRegistersSharedIndex () |
| Whether the integer and floating point argument registers share a single argument index. | |
| virtual bool | AreArgumentRegistersUsedForVarArgs () |
| Whether argument registers are used to pass variadic arguments. | |
| virtual bool | IsStackReservedForArgumentRegisters () |
| Whether stack space is reserved by the caller for the register arguments (for example, the shadow/home space used by the Windows x64 calling convention). | |
| virtual bool | IsStackAdjustedOnReturn () |
| Whether the callee adjusts the stack to remove the arguments before returning (as in stdcall), rather than leaving the caller to clean up the stack (as in cdecl). | |
| virtual bool | IsEligibleForHeuristics () |
| Whether this calling convention may be selected by heuristic calling convention detection. | |
| virtual uint32_t | GetIntegerReturnValueRegister ()=0 |
| Gets the register that holds the integer return value. | |
| virtual uint32_t | GetHighIntegerReturnValueRegister () |
| Gets the register that holds the high part of an integer return value that is too large to fit in a single register. | |
| virtual uint32_t | GetFloatReturnValueRegister () |
| Gets the register that holds the floating point return value. | |
| virtual uint32_t | GetGlobalPointerRegister () |
| virtual std::vector< uint32_t > | GetGlobalPointerRegisters () |
| virtual std::vector< uint32_t > | GetImplicitlyDefinedRegisters () |
| Gets the registers that are implicitly given a known value on function entry by this calling convention. | |
| virtual RegisterValue | GetIncomingRegisterValue (uint32_t reg, Function *func) |
| Gets the known value of a register on entry to a function. | |
| virtual RegisterValue | GetIncomingFlagValue (uint32_t flag, Function *func) |
| Gets the known value of a flag on entry to a function. | |
| virtual Variable | GetIncomingVariableForParameterVariable (const Variable &var, Function *func) |
| Gets the incoming variable that corresponds to the given parameter variable. | |
| virtual Variable | GetParameterVariableForIncomingVariable (const Variable &var, Function *func) |
| Gets the parameter variable that corresponds to the given incoming variable. | |
| virtual bool | IsReturnTypeRegisterCompatible (BinaryView *view, Type *type) |
| Whether a value of the given type can be returned in registers, as opposed to being returned indirectly through memory. | |
| bool | DefaultIsReturnTypeRegisterCompatible (Type *type) |
| Default implementation of IsReturnTypeRegisterCompatible. | |
| virtual Variable | GetIndirectReturnValueLocation () |
| Gets the location used to pass the hidden pointer argument for return values that are returned indirectly through memory. | |
| Variable | GetDefaultIndirectReturnValueLocation () |
| Default implementation of GetIndirectReturnValueLocation. | |
| virtual std::optional< Variable > | GetReturnedIndirectReturnValuePointer () |
| Gets the location in which the hidden indirect return value pointer is returned to the caller, for calling conventions that return it. | |
| virtual bool | IsArgumentTypeRegisterCompatible (BinaryView *view, Type *type) |
| Whether a value of the given type can be passed as an argument in registers. | |
| bool | DefaultIsArgumentTypeRegisterCompatible (Type *type) |
| Default implementation of IsArgumentTypeRegisterCompatible. | |
| virtual bool | IsNonRegisterArgumentIndirect (BinaryView *view, Type *type) |
| Whether an argument that cannot be passed in registers is passed indirectly by pointer as opposed to being passed directly on the stack. | |
| virtual bool | AreStackArgumentsNaturallyAligned () |
| Whether arguments passed on the stack are aligned to their natural alignment. | |
| virtual bool | AreStackArgumentsPushedLeftToRight () |
| Whether arguments passed on the stack are pushed left-to-right, as opposed to the more common right-to-left order. | |
| virtual CallLayout | GetCallLayout (BinaryView *view, const ReturnValue &returnValue, const std::vector< FunctionParameter > ¶ms, const std::optional< std::set< uint32_t > > &permittedRegs=std::nullopt) |
| Computes the complete call layout (parameter locations, return value location, and stack adjustments) for a call with the given return value and parameters. | |
| virtual ValueLocation | GetReturnValueLocation (BinaryView *view, const ReturnValue &returnValue) |
| Computes the location of the return value for the given return value type and location structure. | |
| virtual std::vector< ValueLocation > | GetParameterLocations (BinaryView *view, const std::optional< ValueLocation > &returnValue, const std::vector< FunctionParameter > ¶ms, const std::optional< std::set< uint32_t > > &permittedRegs=std::nullopt) |
| Computes the locations of the parameters for a call with the given return value and parameters. | |
| virtual std::vector< Variable > | GetParameterOrderingForVariables (BinaryView *view, const std::map< Variable, Ref< Type > > ¶ms) |
| Computes the order in which the given parameter variables are passed. | |
| virtual int64_t | GetStackAdjustmentForLocations (BinaryView *view, const std::optional< ValueLocation > &returnValue, const std::vector< ValueLocation > &locations, const std::vector< Ref< Type > > &types) |
| Computes the stack adjustment applied on return for a call with the given return value and parameter locations. | |
| virtual std::map< uint32_t, int32_t > | GetRegisterStackAdjustments (BinaryView *view, const std::optional< ValueLocation > &returnValue, const std::vector< ValueLocation > ¶ms) |
| Computes the per-register-stack adjustments (for architectures with register stacks, such as the x87 floating point stack) for a call with the given return value and parameter locations. | |
| CallLayout | GetDefaultCallLayout (BinaryView *view, const ReturnValue &returnValue, const std::vector< FunctionParameter > ¶ms, const std::optional< std::set< uint32_t > > &permittedRegs=std::nullopt) |
| Default implementation of GetCallLayout. | |
| ValueLocation | GetDefaultReturnValueLocation (BinaryView *view, const ReturnValue &returnValue) |
| Default implementation of GetReturnValueLocation. | |
| std::vector< ValueLocation > | GetDefaultParameterLocations (BinaryView *view, const std::optional< ValueLocation > &returnValue, const std::vector< FunctionParameter > ¶ms, const std::optional< std::set< uint32_t > > &permittedRegs=std::nullopt) |
| Default implementation of GetParameterLocations. | |
| std::vector< Variable > | GetDefaultParameterOrderingForVariables (const std::map< Variable, Ref< Type > > ¶ms) |
| Default implementation of GetParameterOrderingForVariables. | |
| int64_t | GetDefaultStackAdjustmentForLocations (const std::optional< ValueLocation > &returnValue, const std::vector< ValueLocation > &locations, const std::vector< Ref< Type > > &types) |
| Default implementation of GetStackAdjustmentForLocations. | |
| std::map< uint32_t, int32_t > | GetDefaultRegisterStackAdjustments (const std::optional< ValueLocation > &returnValue, const std::vector< ValueLocation > ¶ms) |
| Default implementation of GetRegisterStackAdjustments. | |
| Public Member Functions inherited from BinaryNinja::CoreRefCountObject< BNCallingConvention, BNNewCallingConventionReference, BNFreeCallingConvention > | |
| CoreRefCountObject () | |
| virtual | ~CoreRefCountObject () |
| BNCallingConvention * | GetObject () const |
| void | AddRef () |
| void | Release () |
| void | AddRefForRegistration () |
| void | ReleaseForRegistration () |
| void | AddRefForCallback () |
| void | ReleaseForCallback () |
Protected Member Functions | |
| CallingConvention (BNCallingConvention *cc) | |
| CallingConvention (Architecture *arch, const std::string &name) | |
Static Protected Member Functions | |
| static void | FreeCallback (void *ctxt) |
| static uint32_t * | GetCallerSavedRegistersCallback (void *ctxt, size_t *count) |
| static uint32_t * | GetCalleeSavedRegistersCallback (void *ctxt, size_t *count) |
| static uint32_t * | GetIntegerArgumentRegistersCallback (void *ctxt, size_t *count) |
| static uint32_t * | GetFloatArgumentRegistersCallback (void *ctxt, size_t *count) |
| static uint32_t * | GetRequiredArgumentRegistersCallback (void *ctxt, size_t *count) |
| static uint32_t * | GetRequiredClobberedRegistersCallback (void *ctxt, size_t *count) |
| static void | FreeRegisterListCallback (void *ctxt, uint32_t *regs, size_t len) |
| static bool | AreArgumentRegistersSharedIndexCallback (void *ctxt) |
| static bool | AreArgumentRegistersUsedForVarArgsCallback (void *ctxt) |
| static bool | IsStackReservedForArgumentRegistersCallback (void *ctxt) |
| static bool | IsStackAdjustedOnReturnCallback (void *ctxt) |
| static bool | IsEligibleForHeuristicsCallback (void *ctxt) |
| static uint32_t | GetIntegerReturnValueRegisterCallback (void *ctxt) |
| static uint32_t | GetHighIntegerReturnValueRegisterCallback (void *ctxt) |
| static uint32_t | GetFloatReturnValueRegisterCallback (void *ctxt) |
| static uint32_t * | GetGlobalPointerRegistersCallback (void *ctxt, size_t *count) |
| static uint32_t * | GetImplicitlyDefinedRegistersCallback (void *ctxt, size_t *count) |
| static void | GetIncomingRegisterValueCallback (void *ctxt, uint32_t reg, BNFunction *func, BNRegisterValue *result) |
| static void | GetIncomingFlagValueCallback (void *ctxt, uint32_t reg, BNFunction *func, BNRegisterValue *result) |
| static void | GetIncomingVariableForParameterVariableCallback (void *ctxt, const BNVariable *var, BNFunction *func, BNVariable *result) |
| static void | GetParameterVariableForIncomingVariableCallback (void *ctxt, const BNVariable *var, BNFunction *func, BNVariable *result) |
| static bool | IsReturnTypeRegisterCompatibleCallback (void *ctxt, BNBinaryView *view, BNType *type) |
| static void | GetIndirectReturnValueLocationCallback (void *ctxt, BNVariable *outVar) |
| static bool | GetReturnedIndirectReturnValuePointerCallback (void *ctxt, BNVariable *outVar) |
| static bool | IsArgumentTypeRegisterCompatibleCallback (void *ctxt, BNBinaryView *view, BNType *type) |
| static bool | IsNonRegisterArgumentIndirectCallback (void *ctxt, BNBinaryView *view, BNType *type) |
| static bool | AreStackArgumentsNaturallyAlignedCallback (void *ctxt) |
| static bool | AreStackArgumentsPushedLeftToRightCallback (void *ctxt) |
| static void | GetCallLayoutCallback (void *ctxt, BNBinaryView *view, BNReturnValue *returnValue, BNFunctionParameter *params, size_t paramCount, bool hasPermittedRegs, uint32_t *permittedRegs, size_t permittedRegCount, BNCallLayout *result) |
| static void | FreeCallLayoutCallback (void *ctxt, BNCallLayout *layout) |
| static void | GetReturnValueLocationCallback (void *ctxt, BNBinaryView *view, BNReturnValue *returnValue, BNValueLocation *outLocation) |
| static void | FreeValueLocationCallback (void *ctxt, BNValueLocation *location) |
| static BNValueLocation * | GetParameterLocationsCallback (void *ctxt, BNBinaryView *view, BNValueLocation *returnValue, BNFunctionParameter *params, size_t paramCount, bool hasPermittedRegs, uint32_t *permittedRegs, size_t permittedRegCount, size_t *outLocationCount) |
| static void | FreeParameterLocationsCallback (void *ctxt, BNValueLocation *locations, size_t count) |
| static BNVariable * | GetParameterOrderingForVariablesCallback (void *ctxt, BNBinaryView *view, BNVariable *vars, BNType **types, size_t paramCount, size_t *outCount) |
| static void | FreeVariableListCallback (void *ctxt, BNVariable *vars, size_t count) |
| static int64_t | GetStackAdjustmentForLocationsCallback (void *ctxt, BNBinaryView *view, BNValueLocation *returnValue, BNValueLocation *locations, BNType **types, size_t paramCount) |
| static size_t | GetRegisterStackAdjustmentsCallback (void *ctxt, BNBinaryView *view, BNValueLocation *returnValue, BNValueLocation *params, size_t paramCount, uint32_t **outRegs, int32_t **outAdjust) |
| static void | FreeRegisterStackAdjustmentsCallback (void *ctxt, uint32_t *regs, int32_t *adjust, size_t count) |
Additional Inherited Members | |
| Public Attributes inherited from BinaryNinja::CoreRefCountObject< BNCallingConvention, BNNewCallingConventionReference, BNFreeCallingConvention > | |
| std::atomic< int > | m_refs |
| bool | m_registeredRef |
| BNCallingConvention * | m_object |
|
protected |
|
protected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
| Ref< Architecture > CallingConvention::GetArchitecture | ( | ) | const |
Get the architecture this calling convention applies to.
| string CallingConvention::GetName | ( | ) | const |
Get the name of this calling convention.
|
virtual |
Gets the list of registers that are not preserved across a call (caller-saved / volatile registers).
Reimplemented in BinaryNinja::CoreCallingConvention.
|
virtual |
Gets the list of registers that a callee must preserve across a call (callee-saved / non-volatile registers).
Reimplemented in BinaryNinja::CoreCallingConvention.
|
virtual |
Gets the registers used to pass integer and pointer arguments, in the order they are used.
Reimplemented in BinaryNinja::CoreCallingConvention.
|
virtual |
Gets the registers used to pass floating point arguments, in the order they are used.
Reimplemented in BinaryNinja::CoreCallingConvention.
|
virtual |
Gets the set of registers that must be arguments for heuristic calling convention detection to consider this calling convention as a valid option.
Reimplemented in BinaryNinja::CoreCallingConvention.
|
virtual |
Gets the set of registers that must be clobbered for heuristic calling convention detection to consider this calling convention as a valid option.
Reimplemented in BinaryNinja::CoreCallingConvention.
|
virtual |
Whether the integer and floating point argument registers share a single argument index.
When true, the Nth argument consumes the Nth slot of both the integer and float register lists regardless of its type. When false, integer and float arguments are assigned from their respective register lists independently.
Reimplemented in BinaryNinja::CoreCallingConvention.
|
virtual |
Whether argument registers are used to pass variadic arguments.
Reimplemented in BinaryNinja::CoreCallingConvention.
|
virtual |
Whether stack space is reserved by the caller for the register arguments (for example, the shadow/home space used by the Windows x64 calling convention).
Reimplemented in BinaryNinja::CoreCallingConvention.
|
virtual |
Whether the callee adjusts the stack to remove the arguments before returning (as in stdcall), rather than leaving the caller to clean up the stack (as in cdecl).
Reimplemented in BinaryNinja::CoreCallingConvention.
|
virtual |
Whether this calling convention may be selected by heuristic calling convention detection.
Reimplemented in BinaryNinja::CoreCallingConvention.
|
pure virtual |
Gets the register that holds the integer return value.
Implemented in BinaryNinja::CoreCallingConvention.
|
virtual |
Gets the register that holds the high part of an integer return value that is too large to fit in a single register.
Reimplemented in BinaryNinja::CoreCallingConvention.
|
virtual |
Gets the register that holds the floating point return value.
Reimplemented in BinaryNinja::CoreCallingConvention.
|
virtual |
Reimplemented in BinaryNinja::CoreCallingConvention.
|
virtual |
Reimplemented in BinaryNinja::CoreCallingConvention.
|
virtual |
Gets the registers that are implicitly given a known value on function entry by this calling convention.
Reimplemented in BinaryNinja::CoreCallingConvention.
|
virtual |
Gets the known value of a register on entry to a function.
| reg | Register index |
| func | Function being analyzed |
Reimplemented in BinaryNinja::CoreCallingConvention.
|
virtual |
Gets the known value of a flag on entry to a function.
| flag | Flag index |
| func | Function being analyzed |
Reimplemented in BinaryNinja::CoreCallingConvention.
|
virtual |
Gets the incoming variable that corresponds to the given parameter variable.
This is the inverse of GetParameterVariableForIncomingVariable.
| var | Parameter variable |
| func | Function being analyzed |
Reimplemented in BinaryNinja::CoreCallingConvention.
|
virtual |
Gets the parameter variable that corresponds to the given incoming variable.
This is the inverse of GetIncomingVariableForParameterVariable.
| var | Incoming variable |
| func | Function being analyzed |
Reimplemented in BinaryNinja::CoreCallingConvention.
|
virtual |
Whether a value of the given type can be returned in registers, as opposed to being returned indirectly through memory.
| view | BinaryView providing type information |
| type | Return type to check |
Reimplemented in BinaryNinja::CoreCallingConvention.
| bool CallingConvention::DefaultIsReturnTypeRegisterCompatible | ( | Type * | type | ) |
Default implementation of IsReturnTypeRegisterCompatible.
The default implementation allows register returns for types that fit in a single register, have a size equal to two registers when GetHighIntegerReturnValueRegister is a valid register, or are a floating point type when GetFloatReturnValueRegister is a valid register.
| type | Return type to check |
|
virtual |
Gets the location used to pass the hidden pointer argument for return values that are returned indirectly through memory.
Reimplemented in BinaryNinja::CoreCallingConvention.
| Variable CallingConvention::GetDefaultIndirectReturnValueLocation | ( | ) |
Default implementation of GetIndirectReturnValueLocation.
The default location is the first integer argument register, or the first stack slot if there are no integer argument registers.
|
virtual |
Gets the location in which the hidden indirect return value pointer is returned to the caller, for calling conventions that return it.
Reimplemented in BinaryNinja::CoreCallingConvention.
|
virtual |
Whether a value of the given type can be passed as an argument in registers.
| view | BinaryView providing type information |
| type | Argument type to check |
Reimplemented in BinaryNinja::CoreCallingConvention.
| bool CallingConvention::DefaultIsArgumentTypeRegisterCompatible | ( | Type * | type | ) |
Default implementation of IsArgumentTypeRegisterCompatible.
The default implementation allows register arguments for types that fit in a single register, or are a floating point type when GetFloatArgumentRegisters has valid registers.
| type | Argument type to check |
|
virtual |
Whether an argument that cannot be passed in registers is passed indirectly by pointer as opposed to being passed directly on the stack.
| view | BinaryView providing type information |
| type | Argument type to check |
Reimplemented in BinaryNinja::CoreCallingConvention.
|
virtual |
Whether arguments passed on the stack are aligned to their natural alignment.
If false, arguments are aligned to the address size.
Reimplemented in BinaryNinja::CoreCallingConvention.
|
virtual |
Whether arguments passed on the stack are pushed left-to-right, as opposed to the more common right-to-left order.
Reimplemented in BinaryNinja::CoreCallingConvention.
|
virtual |
Computes the complete call layout (parameter locations, return value location, and stack adjustments) for a call with the given return value and parameters.
It is recommended to only override this method if the calling convention behavior cannot be modeled with GetReturnValueLocation and/or GetParameterLocations.
The default implementation calls GetDefaultCallLayout.
When calling this function to query the layout of a function, the return value and parameters should have their named type references dereferenced before passing them to this function. Calling the functions BinaryView::DerefReturnValueNamedTypeRefs and BinaryView::DerefParameterNamedTypeRefs will perform this dereferencing.
| view | BinaryView providing type information |
| returnValue | Return value of the call |
| params | Parameters of the call |
| permittedRegs | Optional set of register indices that argument passing is restricted to; if not provided, the calling convention's default registers are used |
Reimplemented in BinaryNinja::CoreCallingConvention.
|
virtual |
Computes the location of the return value for the given return value type and location structure.
The default implementation calls GetDefaultReturnValueLocation.
| view | BinaryView providing type information |
| returnValue | Return value to compute the location for |
Reimplemented in BinaryNinja::CoreCallingConvention.
|
virtual |
Computes the locations of the parameters for a call with the given return value and parameters.
The default implementation calls GetDefaultParameterLocations.
| view | BinaryView providing type information |
| returnValue | Optional location of the return value, which may affect parameter placement (for example, when an indirect return pointer consumes an argument register) |
| params | Parameters of the call |
| permittedRegs | Optional set of register indices that argument passing is restricted to; if not provided, the calling convention's default registers are used |
Reimplemented in BinaryNinja::CoreCallingConvention.
|
virtual |
Computes the order in which the given parameter variables are passed.
Used by the heuristic calling convention detection to create a function type from a list of parameter variables.
The default implementation calls GetDefaultParameterOrderingForVariables.
| view | BinaryView providing type information |
| params | Map of parameter variables to their types |
Reimplemented in BinaryNinja::CoreCallingConvention.
|
virtual |
Computes the stack adjustment applied on return for a call with the given return value and parameter locations.
The default implementation calls GetDefaultStackAdjustmentForLocations.
| view | BinaryView providing type information |
| returnValue | Optional location of the return value |
| locations | Locations of the parameters |
| types | Types of the parameters, corresponding to locations |
Reimplemented in BinaryNinja::CoreCallingConvention.
|
virtual |
Computes the per-register-stack adjustments (for architectures with register stacks, such as the x87 floating point stack) for a call with the given return value and parameter locations.
The default implementation calls GetDefaultRegisterStackAdjustments.
| view | BinaryView providing type information |
| returnValue | Optional location of the return value |
| params | Locations of the parameters |
Reimplemented in BinaryNinja::CoreCallingConvention.
| CallLayout CallingConvention::GetDefaultCallLayout | ( | BinaryView * | view, |
| const ReturnValue & | returnValue, | ||
| const std::vector< FunctionParameter > & | params, | ||
| const std::optional< std::set< uint32_t > > & | permittedRegs = std::nullopt ) |
Default implementation of GetCallLayout.
The default implementation uses GetReturnValueLocation, GetParameterLocations, GetStackAdjustmentForLocations, and GetRegisterStackAdjustments to compute the layout.
| view | BinaryView providing type information |
| returnValue | Return value of the call |
| params | Parameters of the call |
| permittedRegs | Optional set of register indices that argument passing is restricted to; if not provided, the calling convention's default registers are used |
| ValueLocation CallingConvention::GetDefaultReturnValueLocation | ( | BinaryView * | view, |
| const ReturnValue & | returnValue ) |
Default implementation of GetReturnValueLocation.
The default implementation checks IsReturnTypeRegisterCompatible and places the return value in registers if it can, or uses an indirect return by pointer if not. If an indirect return is required, then GetIndirectReturnValueLocation and GetReturnedIndirectReturnValuePointer are used to provide the location of the indirect return value.
| view | BinaryView providing type information |
| returnValue | Return value to compute the location for |
| vector< ValueLocation > CallingConvention::GetDefaultParameterLocations | ( | BinaryView * | view, |
| const std::optional< ValueLocation > & | returnValue, | ||
| const std::vector< FunctionParameter > & | params, | ||
| const std::optional< std::set< uint32_t > > & | permittedRegs = std::nullopt ) |
Default implementation of GetParameterLocations.
The default implementation uses GetIntegerArgumentRegisters, GetFloatArgumentRegisters, AreArgumentRegistersSharedIndex, IsStackReservedForArgumentRegisters, IsArgumentTypeRegisterCompatible, IsNonRegisterArgumentIndirect, AreStackArgumentsNaturallyAligned, and AreStackArgumentsPushedLeftToRight to compute the parameter layout.
This function is usually sufficient unless the calling convention has unusual parameter passing behavior. Most calling conventions can be defined per-argument using the methods listed above.
| view | BinaryView providing type information |
| returnValue | Optional location of the return value |
| params | Parameters of the call |
| permittedRegs | Optional set of register indices that argument passing is restricted to; if not provided, the calling convention's default registers are used |
| std::vector< Variable > CallingConvention::GetDefaultParameterOrderingForVariables | ( | const std::map< Variable, Ref< Type > > & | params | ) |
Default implementation of GetParameterOrderingForVariables.
The default implementation first checks AreArgumentRegistersSharedIndex to see if the parameter ordering is well defined. If the arguments do not share an index, it places all integer arguments before the floating point arguments. Arguments that are not passed in a normal location are placed last.
| params | Map of parameter variables to their types |
| int64_t CallingConvention::GetDefaultStackAdjustmentForLocations | ( | const std::optional< ValueLocation > & | returnValue, |
| const std::vector< ValueLocation > & | locations, | ||
| const std::vector< Ref< Type > > & | types ) |
Default implementation of GetStackAdjustmentForLocations.
The default implementation first checks IsStackAdjustedOnReturn, and returns zero if that returns false. Otherwise, it checks the stack parameter locations and AreStackArgumentsNaturallyAligned to compute the stack adjustment necessary to cover all parameters.
| returnValue | Optional location of the return value |
| locations | Locations of the parameters |
| types | Types of the parameters, corresponding to locations |
| std::map< uint32_t, int32_t > CallingConvention::GetDefaultRegisterStackAdjustments | ( | const std::optional< ValueLocation > & | returnValue, |
| const std::vector< ValueLocation > & | params ) |
Default implementation of GetRegisterStackAdjustments.
The default implementation compares the register stack slots used by the parameters and the return value to compute the adjustments.
| returnValue | Optional location of the return value |
| params | Locations of the parameters |
| class BinaryNinja::CoreCallingConvention |
Public Member Functions | |
| CoreCallingConvention (BNCallingConvention *cc) | |
| virtual std::vector< uint32_t > | GetCallerSavedRegisters () override |
| Gets the list of registers that are not preserved across a call (caller-saved / volatile registers). | |
| virtual std::vector< uint32_t > | GetCalleeSavedRegisters () override |
| Gets the list of registers that a callee must preserve across a call (callee-saved / non-volatile registers). | |
| virtual std::vector< uint32_t > | GetIntegerArgumentRegisters () override |
| Gets the registers used to pass integer and pointer arguments, in the order they are used. | |
| virtual std::vector< uint32_t > | GetFloatArgumentRegisters () override |
| Gets the registers used to pass floating point arguments, in the order they are used. | |
| virtual std::vector< uint32_t > | GetRequiredArgumentRegisters () override |
| Gets the set of registers that must be arguments for heuristic calling convention detection to consider this calling convention as a valid option. | |
| virtual std::vector< uint32_t > | GetRequiredClobberedRegisters () override |
| Gets the set of registers that must be clobbered for heuristic calling convention detection to consider this calling convention as a valid option. | |
| virtual bool | AreArgumentRegistersSharedIndex () override |
| Whether the integer and floating point argument registers share a single argument index. | |
| virtual bool | AreArgumentRegistersUsedForVarArgs () override |
| Whether argument registers are used to pass variadic arguments. | |
| virtual bool | IsStackReservedForArgumentRegisters () override |
| Whether stack space is reserved by the caller for the register arguments (for example, the shadow/home space used by the Windows x64 calling convention). | |
| virtual bool | IsStackAdjustedOnReturn () override |
| Whether the callee adjusts the stack to remove the arguments before returning (as in stdcall), rather than leaving the caller to clean up the stack (as in cdecl). | |
| virtual bool | IsEligibleForHeuristics () override |
| Whether this calling convention may be selected by heuristic calling convention detection. | |
| virtual uint32_t | GetIntegerReturnValueRegister () override |
| Gets the register that holds the integer return value. | |
| virtual uint32_t | GetHighIntegerReturnValueRegister () override |
| Gets the register that holds the high part of an integer return value that is too large to fit in a single register. | |
| virtual uint32_t | GetFloatReturnValueRegister () override |
| Gets the register that holds the floating point return value. | |
| virtual uint32_t | GetGlobalPointerRegister () override |
| virtual std::vector< uint32_t > | GetGlobalPointerRegisters () override |
| virtual std::vector< uint32_t > | GetImplicitlyDefinedRegisters () override |
| Gets the registers that are implicitly given a known value on function entry by this calling convention. | |
| virtual RegisterValue | GetIncomingRegisterValue (uint32_t reg, Function *func) override |
| Gets the known value of a register on entry to a function. | |
| virtual RegisterValue | GetIncomingFlagValue (uint32_t flag, Function *func) override |
| Gets the known value of a flag on entry to a function. | |
| virtual Variable | GetIncomingVariableForParameterVariable (const Variable &var, Function *func) override |
| Gets the incoming variable that corresponds to the given parameter variable. | |
| virtual Variable | GetParameterVariableForIncomingVariable (const Variable &var, Function *func) override |
| Gets the parameter variable that corresponds to the given incoming variable. | |
| virtual bool | IsReturnTypeRegisterCompatible (BinaryView *view, Type *type) override |
| Whether a value of the given type can be returned in registers, as opposed to being returned indirectly through memory. | |
| virtual Variable | GetIndirectReturnValueLocation () override |
| Gets the location used to pass the hidden pointer argument for return values that are returned indirectly through memory. | |
| virtual std::optional< Variable > | GetReturnedIndirectReturnValuePointer () override |
| Gets the location in which the hidden indirect return value pointer is returned to the caller, for calling conventions that return it. | |
| virtual bool | IsArgumentTypeRegisterCompatible (BinaryView *view, Type *type) override |
| Whether a value of the given type can be passed as an argument in registers. | |
| virtual bool | IsNonRegisterArgumentIndirect (BinaryView *view, Type *type) override |
| Whether an argument that cannot be passed in registers is passed indirectly by pointer as opposed to being passed directly on the stack. | |
| virtual bool | AreStackArgumentsNaturallyAligned () override |
| Whether arguments passed on the stack are aligned to their natural alignment. | |
| virtual bool | AreStackArgumentsPushedLeftToRight () override |
| Whether arguments passed on the stack are pushed left-to-right, as opposed to the more common right-to-left order. | |
| virtual CallLayout | GetCallLayout (BinaryView *view, const ReturnValue &returnValue, const std::vector< FunctionParameter > ¶ms, const std::optional< std::set< uint32_t > > &permittedRegs=std::nullopt) override |
| Computes the complete call layout (parameter locations, return value location, and stack adjustments) for a call with the given return value and parameters. | |
| virtual ValueLocation | GetReturnValueLocation (BinaryView *view, const ReturnValue &returnValue) override |
| Computes the location of the return value for the given return value type and location structure. | |
| virtual std::vector< ValueLocation > | GetParameterLocations (BinaryView *view, const std::optional< ValueLocation > &returnValue, const std::vector< FunctionParameter > ¶ms, const std::optional< std::set< uint32_t > > &permittedRegs=std::nullopt) override |
| Computes the locations of the parameters for a call with the given return value and parameters. | |
| virtual std::vector< Variable > | GetParameterOrderingForVariables (BinaryView *view, const std::map< Variable, Ref< Type > > ¶ms) override |
| Computes the order in which the given parameter variables are passed. | |
| virtual int64_t | GetStackAdjustmentForLocations (BinaryView *view, const std::optional< ValueLocation > &returnValue, const std::vector< ValueLocation > &locations, const std::vector< Ref< Type > > &types) override |
| Computes the stack adjustment applied on return for a call with the given return value and parameter locations. | |
| virtual std::map< uint32_t, int32_t > | GetRegisterStackAdjustments (BinaryView *view, const std::optional< ValueLocation > &returnValue, const std::vector< ValueLocation > ¶ms) override |
| Computes the per-register-stack adjustments (for architectures with register stacks, such as the x87 floating point stack) for a call with the given return value and parameter locations. | |
| Public Member Functions inherited from BinaryNinja::CallingConvention | |
| Ref< Architecture > | GetArchitecture () const |
| Get the architecture this calling convention applies to. | |
| std::string | GetName () const |
| Get the name of this calling convention. | |
| bool | DefaultIsReturnTypeRegisterCompatible (Type *type) |
| Default implementation of IsReturnTypeRegisterCompatible. | |
| Variable | GetDefaultIndirectReturnValueLocation () |
| Default implementation of GetIndirectReturnValueLocation. | |
| bool | DefaultIsArgumentTypeRegisterCompatible (Type *type) |
| Default implementation of IsArgumentTypeRegisterCompatible. | |
| CallLayout | GetDefaultCallLayout (BinaryView *view, const ReturnValue &returnValue, const std::vector< FunctionParameter > ¶ms, const std::optional< std::set< uint32_t > > &permittedRegs=std::nullopt) |
| Default implementation of GetCallLayout. | |
| ValueLocation | GetDefaultReturnValueLocation (BinaryView *view, const ReturnValue &returnValue) |
| Default implementation of GetReturnValueLocation. | |
| std::vector< ValueLocation > | GetDefaultParameterLocations (BinaryView *view, const std::optional< ValueLocation > &returnValue, const std::vector< FunctionParameter > ¶ms, const std::optional< std::set< uint32_t > > &permittedRegs=std::nullopt) |
| Default implementation of GetParameterLocations. | |
| std::vector< Variable > | GetDefaultParameterOrderingForVariables (const std::map< Variable, Ref< Type > > ¶ms) |
| Default implementation of GetParameterOrderingForVariables. | |
| int64_t | GetDefaultStackAdjustmentForLocations (const std::optional< ValueLocation > &returnValue, const std::vector< ValueLocation > &locations, const std::vector< Ref< Type > > &types) |
| Default implementation of GetStackAdjustmentForLocations. | |
| std::map< uint32_t, int32_t > | GetDefaultRegisterStackAdjustments (const std::optional< ValueLocation > &returnValue, const std::vector< ValueLocation > ¶ms) |
| Default implementation of GetRegisterStackAdjustments. | |
| Public Member Functions inherited from BinaryNinja::CoreRefCountObject< BNCallingConvention, BNNewCallingConventionReference, BNFreeCallingConvention > | |
| CoreRefCountObject () | |
| virtual | ~CoreRefCountObject () |
| BNCallingConvention * | GetObject () const |
| void | AddRef () |
| void | Release () |
| void | AddRefForRegistration () |
| void | ReleaseForRegistration () |
| void | AddRefForCallback () |
| void | ReleaseForCallback () |
Additional Inherited Members | |
| Public Attributes inherited from BinaryNinja::CoreRefCountObject< BNCallingConvention, BNNewCallingConventionReference, BNFreeCallingConvention > | |
| std::atomic< int > | m_refs |
| bool | m_registeredRef |
| BNCallingConvention * | m_object |
| Protected Member Functions inherited from BinaryNinja::CallingConvention | |
| CallingConvention (BNCallingConvention *cc) | |
| CallingConvention (Architecture *arch, const std::string &name) | |
| Static Protected Member Functions inherited from BinaryNinja::CallingConvention | |
| static void | FreeCallback (void *ctxt) |
| static uint32_t * | GetCallerSavedRegistersCallback (void *ctxt, size_t *count) |
| static uint32_t * | GetCalleeSavedRegistersCallback (void *ctxt, size_t *count) |
| static uint32_t * | GetIntegerArgumentRegistersCallback (void *ctxt, size_t *count) |
| static uint32_t * | GetFloatArgumentRegistersCallback (void *ctxt, size_t *count) |
| static uint32_t * | GetRequiredArgumentRegistersCallback (void *ctxt, size_t *count) |
| static uint32_t * | GetRequiredClobberedRegistersCallback (void *ctxt, size_t *count) |
| static void | FreeRegisterListCallback (void *ctxt, uint32_t *regs, size_t len) |
| static bool | AreArgumentRegistersSharedIndexCallback (void *ctxt) |
| static bool | AreArgumentRegistersUsedForVarArgsCallback (void *ctxt) |
| static bool | IsStackReservedForArgumentRegistersCallback (void *ctxt) |
| static bool | IsStackAdjustedOnReturnCallback (void *ctxt) |
| static bool | IsEligibleForHeuristicsCallback (void *ctxt) |
| static uint32_t | GetIntegerReturnValueRegisterCallback (void *ctxt) |
| static uint32_t | GetHighIntegerReturnValueRegisterCallback (void *ctxt) |
| static uint32_t | GetFloatReturnValueRegisterCallback (void *ctxt) |
| static uint32_t * | GetGlobalPointerRegistersCallback (void *ctxt, size_t *count) |
| static uint32_t * | GetImplicitlyDefinedRegistersCallback (void *ctxt, size_t *count) |
| static void | GetIncomingRegisterValueCallback (void *ctxt, uint32_t reg, BNFunction *func, BNRegisterValue *result) |
| static void | GetIncomingFlagValueCallback (void *ctxt, uint32_t reg, BNFunction *func, BNRegisterValue *result) |
| static void | GetIncomingVariableForParameterVariableCallback (void *ctxt, const BNVariable *var, BNFunction *func, BNVariable *result) |
| static void | GetParameterVariableForIncomingVariableCallback (void *ctxt, const BNVariable *var, BNFunction *func, BNVariable *result) |
| static bool | IsReturnTypeRegisterCompatibleCallback (void *ctxt, BNBinaryView *view, BNType *type) |
| static void | GetIndirectReturnValueLocationCallback (void *ctxt, BNVariable *outVar) |
| static bool | GetReturnedIndirectReturnValuePointerCallback (void *ctxt, BNVariable *outVar) |
| static bool | IsArgumentTypeRegisterCompatibleCallback (void *ctxt, BNBinaryView *view, BNType *type) |
| static bool | IsNonRegisterArgumentIndirectCallback (void *ctxt, BNBinaryView *view, BNType *type) |
| static bool | AreStackArgumentsNaturallyAlignedCallback (void *ctxt) |
| static bool | AreStackArgumentsPushedLeftToRightCallback (void *ctxt) |
| static void | GetCallLayoutCallback (void *ctxt, BNBinaryView *view, BNReturnValue *returnValue, BNFunctionParameter *params, size_t paramCount, bool hasPermittedRegs, uint32_t *permittedRegs, size_t permittedRegCount, BNCallLayout *result) |
| static void | FreeCallLayoutCallback (void *ctxt, BNCallLayout *layout) |
| static void | GetReturnValueLocationCallback (void *ctxt, BNBinaryView *view, BNReturnValue *returnValue, BNValueLocation *outLocation) |
| static void | FreeValueLocationCallback (void *ctxt, BNValueLocation *location) |
| static BNValueLocation * | GetParameterLocationsCallback (void *ctxt, BNBinaryView *view, BNValueLocation *returnValue, BNFunctionParameter *params, size_t paramCount, bool hasPermittedRegs, uint32_t *permittedRegs, size_t permittedRegCount, size_t *outLocationCount) |
| static void | FreeParameterLocationsCallback (void *ctxt, BNValueLocation *locations, size_t count) |
| static BNVariable * | GetParameterOrderingForVariablesCallback (void *ctxt, BNBinaryView *view, BNVariable *vars, BNType **types, size_t paramCount, size_t *outCount) |
| static void | FreeVariableListCallback (void *ctxt, BNVariable *vars, size_t count) |
| static int64_t | GetStackAdjustmentForLocationsCallback (void *ctxt, BNBinaryView *view, BNValueLocation *returnValue, BNValueLocation *locations, BNType **types, size_t paramCount) |
| static size_t | GetRegisterStackAdjustmentsCallback (void *ctxt, BNBinaryView *view, BNValueLocation *returnValue, BNValueLocation *params, size_t paramCount, uint32_t **outRegs, int32_t **outAdjust) |
| static void | FreeRegisterStackAdjustmentsCallback (void *ctxt, uint32_t *regs, int32_t *adjust, size_t count) |
| CoreCallingConvention::CoreCallingConvention | ( | BNCallingConvention * | cc | ) |
|
overridevirtual |
Gets the list of registers that are not preserved across a call (caller-saved / volatile registers).
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Gets the list of registers that a callee must preserve across a call (callee-saved / non-volatile registers).
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Gets the registers used to pass integer and pointer arguments, in the order they are used.
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Gets the registers used to pass floating point arguments, in the order they are used.
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Gets the set of registers that must be arguments for heuristic calling convention detection to consider this calling convention as a valid option.
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Gets the set of registers that must be clobbered for heuristic calling convention detection to consider this calling convention as a valid option.
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Whether the integer and floating point argument registers share a single argument index.
When true, the Nth argument consumes the Nth slot of both the integer and float register lists regardless of its type. When false, integer and float arguments are assigned from their respective register lists independently.
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Whether argument registers are used to pass variadic arguments.
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Whether stack space is reserved by the caller for the register arguments (for example, the shadow/home space used by the Windows x64 calling convention).
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Whether the callee adjusts the stack to remove the arguments before returning (as in stdcall), rather than leaving the caller to clean up the stack (as in cdecl).
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Whether this calling convention may be selected by heuristic calling convention detection.
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Gets the register that holds the integer return value.
Implements BinaryNinja::CallingConvention.
|
overridevirtual |
Gets the register that holds the high part of an integer return value that is too large to fit in a single register.
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Gets the register that holds the floating point return value.
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Gets the registers that are implicitly given a known value on function entry by this calling convention.
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Gets the known value of a register on entry to a function.
| reg | Register index |
| func | Function being analyzed |
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Gets the known value of a flag on entry to a function.
| flag | Flag index |
| func | Function being analyzed |
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Gets the incoming variable that corresponds to the given parameter variable.
This is the inverse of GetParameterVariableForIncomingVariable.
| var | Parameter variable |
| func | Function being analyzed |
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Gets the parameter variable that corresponds to the given incoming variable.
This is the inverse of GetIncomingVariableForParameterVariable.
| var | Incoming variable |
| func | Function being analyzed |
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Whether a value of the given type can be returned in registers, as opposed to being returned indirectly through memory.
| view | BinaryView providing type information |
| type | Return type to check |
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Gets the location used to pass the hidden pointer argument for return values that are returned indirectly through memory.
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Gets the location in which the hidden indirect return value pointer is returned to the caller, for calling conventions that return it.
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Whether a value of the given type can be passed as an argument in registers.
| view | BinaryView providing type information |
| type | Argument type to check |
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Whether an argument that cannot be passed in registers is passed indirectly by pointer as opposed to being passed directly on the stack.
| view | BinaryView providing type information |
| type | Argument type to check |
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Whether arguments passed on the stack are aligned to their natural alignment.
If false, arguments are aligned to the address size.
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Whether arguments passed on the stack are pushed left-to-right, as opposed to the more common right-to-left order.
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Computes the complete call layout (parameter locations, return value location, and stack adjustments) for a call with the given return value and parameters.
It is recommended to only override this method if the calling convention behavior cannot be modeled with GetReturnValueLocation and/or GetParameterLocations.
The default implementation calls GetDefaultCallLayout.
When calling this function to query the layout of a function, the return value and parameters should have their named type references dereferenced before passing them to this function. Calling the functions BinaryView::DerefReturnValueNamedTypeRefs and BinaryView::DerefParameterNamedTypeRefs will perform this dereferencing.
| view | BinaryView providing type information |
| returnValue | Return value of the call |
| params | Parameters of the call |
| permittedRegs | Optional set of register indices that argument passing is restricted to; if not provided, the calling convention's default registers are used |
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Computes the location of the return value for the given return value type and location structure.
The default implementation calls GetDefaultReturnValueLocation.
| view | BinaryView providing type information |
| returnValue | Return value to compute the location for |
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Computes the locations of the parameters for a call with the given return value and parameters.
The default implementation calls GetDefaultParameterLocations.
| view | BinaryView providing type information |
| returnValue | Optional location of the return value, which may affect parameter placement (for example, when an indirect return pointer consumes an argument register) |
| params | Parameters of the call |
| permittedRegs | Optional set of register indices that argument passing is restricted to; if not provided, the calling convention's default registers are used |
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Computes the order in which the given parameter variables are passed.
Used by the heuristic calling convention detection to create a function type from a list of parameter variables.
The default implementation calls GetDefaultParameterOrderingForVariables.
| view | BinaryView providing type information |
| params | Map of parameter variables to their types |
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Computes the stack adjustment applied on return for a call with the given return value and parameter locations.
The default implementation calls GetDefaultStackAdjustmentForLocations.
| view | BinaryView providing type information |
| returnValue | Optional location of the return value |
| locations | Locations of the parameters |
| types | Types of the parameters, corresponding to locations |
Reimplemented from BinaryNinja::CallingConvention.
|
overridevirtual |
Computes the per-register-stack adjustments (for architectures with register stacks, such as the x87 floating point stack) for a call with the given return value and parameter locations.
The default implementation calls GetDefaultRegisterStackAdjustments.
| view | BinaryView providing type information |
| returnValue | Optional location of the return value |
| params | Locations of the parameters |
Reimplemented from BinaryNinja::CallingConvention.