Loading...
Searching...
No Matches
CallingConvention

Detailed Description

Classes

struct  BinaryNinja::CallLayout
class  BinaryNinja::CallingConvention
class  BinaryNinja::CoreCallingConvention

Class Documentation

◆ BinaryNinja::CallLayout

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< ValueLocationparameters
std::optional< ValueLocationreturnValue
int64_t stackAdjustment = 0
std::map< uint32_t, int32_t > registerStackAdjustments

Member Function Documentation

◆ FromAPIObject()

CallLayout CallLayout::FromAPIObject ( BNCallLayout * layout)
static

◆ ToAPIObject()

BNCallLayout CallLayout::ToAPIObject ( ) const

◆ FreeAPIObject()

void CallLayout::FreeAPIObject ( BNCallLayout * layout)
static

Member Data Documentation

◆ parameters

std::vector<ValueLocation> BinaryNinja::CallLayout::parameters

◆ returnValue

std::optional<ValueLocation> BinaryNinja::CallLayout::returnValue

◆ stackAdjustment

int64_t BinaryNinja::CallLayout::stackAdjustment = 0

◆ registerStackAdjustments

std::map<uint32_t, int32_t> BinaryNinja::CallLayout::registerStackAdjustments

◆ BinaryNinja::CallingConvention

class BinaryNinja::CallingConvention

Public Member Functions

Ref< ArchitectureGetArchitecture () 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< VariableGetReturnedIndirectReturnValuePointer ()
 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 > &params, 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< ValueLocationGetParameterLocations (BinaryView *view, const std::optional< ValueLocation > &returnValue, const std::vector< FunctionParameter > &params, 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< VariableGetParameterOrderingForVariables (BinaryView *view, const std::map< Variable, Ref< Type > > &params)
 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 > &params)
 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 > &params, 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< ValueLocationGetDefaultParameterLocations (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.
std::vector< VariableGetDefaultParameterOrderingForVariables (const std::map< Variable, Ref< Type > > &params)
 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 > &params)
 Default implementation of GetRegisterStackAdjustments.
Public Member Functions inherited from BinaryNinja::CoreRefCountObject< BNCallingConvention, BNNewCallingConventionReference, BNFreeCallingConvention >
 CoreRefCountObject ()
virtual ~CoreRefCountObject ()
BNCallingConventionGetObject () 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 BNValueLocationGetParameterLocationsCallback (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 BNVariableGetParameterOrderingForVariablesCallback (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
BNCallingConventionm_object

Constructor & Destructor Documentation

◆ CallingConvention() [1/2]

CallingConvention::CallingConvention ( BNCallingConvention * cc)
protected

◆ CallingConvention() [2/2]

BinaryNinja::CallingConvention::CallingConvention ( Architecture * arch,
const std::string & name )
protected

Member Function Documentation

◆ FreeCallback()

void CallingConvention::FreeCallback ( void * ctxt)
staticprotected

◆ GetCallerSavedRegistersCallback()

uint32_t * CallingConvention::GetCallerSavedRegistersCallback ( void * ctxt,
size_t * count )
staticprotected

◆ GetCalleeSavedRegistersCallback()

uint32_t * CallingConvention::GetCalleeSavedRegistersCallback ( void * ctxt,
size_t * count )
staticprotected

◆ GetIntegerArgumentRegistersCallback()

uint32_t * CallingConvention::GetIntegerArgumentRegistersCallback ( void * ctxt,
size_t * count )
staticprotected

◆ GetFloatArgumentRegistersCallback()

uint32_t * CallingConvention::GetFloatArgumentRegistersCallback ( void * ctxt,
size_t * count )
staticprotected

◆ GetRequiredArgumentRegistersCallback()

uint32_t * CallingConvention::GetRequiredArgumentRegistersCallback ( void * ctxt,
size_t * count )
staticprotected

◆ GetRequiredClobberedRegistersCallback()

uint32_t * CallingConvention::GetRequiredClobberedRegistersCallback ( void * ctxt,
size_t * count )
staticprotected

◆ FreeRegisterListCallback()

void CallingConvention::FreeRegisterListCallback ( void * ctxt,
uint32_t * regs,
size_t len )
staticprotected

◆ AreArgumentRegistersSharedIndexCallback()

bool CallingConvention::AreArgumentRegistersSharedIndexCallback ( void * ctxt)
staticprotected

◆ AreArgumentRegistersUsedForVarArgsCallback()

bool CallingConvention::AreArgumentRegistersUsedForVarArgsCallback ( void * ctxt)
staticprotected

◆ IsStackReservedForArgumentRegistersCallback()

bool CallingConvention::IsStackReservedForArgumentRegistersCallback ( void * ctxt)
staticprotected

◆ IsStackAdjustedOnReturnCallback()

bool CallingConvention::IsStackAdjustedOnReturnCallback ( void * ctxt)
staticprotected

◆ IsEligibleForHeuristicsCallback()

bool CallingConvention::IsEligibleForHeuristicsCallback ( void * ctxt)
staticprotected

◆ GetIntegerReturnValueRegisterCallback()

uint32_t CallingConvention::GetIntegerReturnValueRegisterCallback ( void * ctxt)
staticprotected

◆ GetHighIntegerReturnValueRegisterCallback()

uint32_t CallingConvention::GetHighIntegerReturnValueRegisterCallback ( void * ctxt)
staticprotected

◆ GetFloatReturnValueRegisterCallback()

uint32_t CallingConvention::GetFloatReturnValueRegisterCallback ( void * ctxt)
staticprotected

◆ GetGlobalPointerRegistersCallback()

uint32_t * CallingConvention::GetGlobalPointerRegistersCallback ( void * ctxt,
size_t * count )
staticprotected

◆ GetImplicitlyDefinedRegistersCallback()

uint32_t * CallingConvention::GetImplicitlyDefinedRegistersCallback ( void * ctxt,
size_t * count )
staticprotected

◆ GetIncomingRegisterValueCallback()

void CallingConvention::GetIncomingRegisterValueCallback ( void * ctxt,
uint32_t reg,
BNFunction * func,
BNRegisterValue * result )
staticprotected

◆ GetIncomingFlagValueCallback()

void CallingConvention::GetIncomingFlagValueCallback ( void * ctxt,
uint32_t reg,
BNFunction * func,
BNRegisterValue * result )
staticprotected

◆ GetIncomingVariableForParameterVariableCallback()

void CallingConvention::GetIncomingVariableForParameterVariableCallback ( void * ctxt,
const BNVariable * var,
BNFunction * func,
BNVariable * result )
staticprotected

◆ GetParameterVariableForIncomingVariableCallback()

void CallingConvention::GetParameterVariableForIncomingVariableCallback ( void * ctxt,
const BNVariable * var,
BNFunction * func,
BNVariable * result )
staticprotected

◆ IsReturnTypeRegisterCompatibleCallback()

bool CallingConvention::IsReturnTypeRegisterCompatibleCallback ( void * ctxt,
BNBinaryView * view,
BNType * type )
staticprotected

◆ GetIndirectReturnValueLocationCallback()

void CallingConvention::GetIndirectReturnValueLocationCallback ( void * ctxt,
BNVariable * outVar )
staticprotected

◆ GetReturnedIndirectReturnValuePointerCallback()

bool CallingConvention::GetReturnedIndirectReturnValuePointerCallback ( void * ctxt,
BNVariable * outVar )
staticprotected

◆ IsArgumentTypeRegisterCompatibleCallback()

bool CallingConvention::IsArgumentTypeRegisterCompatibleCallback ( void * ctxt,
BNBinaryView * view,
BNType * type )
staticprotected

◆ IsNonRegisterArgumentIndirectCallback()

bool CallingConvention::IsNonRegisterArgumentIndirectCallback ( void * ctxt,
BNBinaryView * view,
BNType * type )
staticprotected

◆ AreStackArgumentsNaturallyAlignedCallback()

bool CallingConvention::AreStackArgumentsNaturallyAlignedCallback ( void * ctxt)
staticprotected

◆ AreStackArgumentsPushedLeftToRightCallback()

bool CallingConvention::AreStackArgumentsPushedLeftToRightCallback ( void * ctxt)
staticprotected

◆ GetCallLayoutCallback()

void CallingConvention::GetCallLayoutCallback ( void * ctxt,
BNBinaryView * view,
BNReturnValue * returnValue,
BNFunctionParameter * params,
size_t paramCount,
bool hasPermittedRegs,
uint32_t * permittedRegs,
size_t permittedRegCount,
BNCallLayout * result )
staticprotected

◆ FreeCallLayoutCallback()

void CallingConvention::FreeCallLayoutCallback ( void * ctxt,
BNCallLayout * layout )
staticprotected

◆ GetReturnValueLocationCallback()

void CallingConvention::GetReturnValueLocationCallback ( void * ctxt,
BNBinaryView * view,
BNReturnValue * returnValue,
BNValueLocation * outLocation )
staticprotected

◆ FreeValueLocationCallback()

void CallingConvention::FreeValueLocationCallback ( void * ctxt,
BNValueLocation * location )
staticprotected

◆ GetParameterLocationsCallback()

BNValueLocation * CallingConvention::GetParameterLocationsCallback ( void * ctxt,
BNBinaryView * view,
BNValueLocation * returnValue,
BNFunctionParameter * params,
size_t paramCount,
bool hasPermittedRegs,
uint32_t * permittedRegs,
size_t permittedRegCount,
size_t * outLocationCount )
staticprotected

◆ FreeParameterLocationsCallback()

void CallingConvention::FreeParameterLocationsCallback ( void * ctxt,
BNValueLocation * locations,
size_t count )
staticprotected

◆ GetParameterOrderingForVariablesCallback()

BNVariable * CallingConvention::GetParameterOrderingForVariablesCallback ( void * ctxt,
BNBinaryView * view,
BNVariable * vars,
BNType ** types,
size_t paramCount,
size_t * outCount )
staticprotected

◆ FreeVariableListCallback()

void CallingConvention::FreeVariableListCallback ( void * ctxt,
BNVariable * vars,
size_t count )
staticprotected

◆ GetStackAdjustmentForLocationsCallback()

int64_t CallingConvention::GetStackAdjustmentForLocationsCallback ( void * ctxt,
BNBinaryView * view,
BNValueLocation * returnValue,
BNValueLocation * locations,
BNType ** types,
size_t paramCount )
staticprotected

◆ GetRegisterStackAdjustmentsCallback()

size_t CallingConvention::GetRegisterStackAdjustmentsCallback ( void * ctxt,
BNBinaryView * view,
BNValueLocation * returnValue,
BNValueLocation * params,
size_t paramCount,
uint32_t ** outRegs,
int32_t ** outAdjust )
staticprotected

◆ FreeRegisterStackAdjustmentsCallback()

void CallingConvention::FreeRegisterStackAdjustmentsCallback ( void * ctxt,
uint32_t * regs,
int32_t * adjust,
size_t count )
staticprotected

◆ GetArchitecture()

Ref< Architecture > CallingConvention::GetArchitecture ( ) const

Get the architecture this calling convention applies to.

Returns
The architecture this calling convention applies to

◆ GetName()

string CallingConvention::GetName ( ) const

Get the name of this calling convention.

Returns
The name of this calling convention

◆ GetCallerSavedRegisters()

vector< uint32_t > CallingConvention::GetCallerSavedRegisters ( )
virtual

Gets the list of registers that are not preserved across a call (caller-saved / volatile registers).

Returns
The list of caller-saved register indices

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ GetCalleeSavedRegisters()

vector< uint32_t > CallingConvention::GetCalleeSavedRegisters ( )
virtual

Gets the list of registers that a callee must preserve across a call (callee-saved / non-volatile registers).

Returns
The list of callee-saved register indices

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ GetIntegerArgumentRegisters()

vector< uint32_t > CallingConvention::GetIntegerArgumentRegisters ( )
virtual

Gets the registers used to pass integer and pointer arguments, in the order they are used.

Returns
The ordered list of integer argument register indices

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ GetFloatArgumentRegisters()

vector< uint32_t > CallingConvention::GetFloatArgumentRegisters ( )
virtual

Gets the registers used to pass floating point arguments, in the order they are used.

Returns
The ordered list of floating point argument register indices

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ GetRequiredArgumentRegisters()

vector< uint32_t > CallingConvention::GetRequiredArgumentRegisters ( )
virtual

Gets the set of registers that must be arguments for heuristic calling convention detection to consider this calling convention as a valid option.

Returns
The set of registers that must be arguments

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ GetRequiredClobberedRegisters()

vector< uint32_t > CallingConvention::GetRequiredClobberedRegisters ( )
virtual

Gets the set of registers that must be clobbered for heuristic calling convention detection to consider this calling convention as a valid option.

Returns
The set of registers that must be clobbered

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ AreArgumentRegistersSharedIndex()

bool CallingConvention::AreArgumentRegistersSharedIndex ( )
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.

Returns
Whether argument registers share a single index

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ AreArgumentRegistersUsedForVarArgs()

bool CallingConvention::AreArgumentRegistersUsedForVarArgs ( )
virtual

Whether argument registers are used to pass variadic arguments.

Returns
Whether argument registers are used for variadic arguments

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ IsStackReservedForArgumentRegisters()

bool CallingConvention::IsStackReservedForArgumentRegisters ( )
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).

Returns
Whether stack space is reserved for argument registers

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ IsStackAdjustedOnReturn()

bool CallingConvention::IsStackAdjustedOnReturn ( )
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).

Returns
Whether the stack is adjusted by the callee on return

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ IsEligibleForHeuristics()

bool CallingConvention::IsEligibleForHeuristics ( )
virtual

Whether this calling convention may be selected by heuristic calling convention detection.

Returns
Whether this calling convention is eligible for heuristics

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ GetIntegerReturnValueRegister()

virtual uint32_t BinaryNinja::CallingConvention::GetIntegerReturnValueRegister ( )
pure virtual

Gets the register that holds the integer return value.

Returns
The integer return value register index

Implemented in BinaryNinja::CoreCallingConvention.

◆ GetHighIntegerReturnValueRegister()

uint32_t CallingConvention::GetHighIntegerReturnValueRegister ( )
virtual

Gets the register that holds the high part of an integer return value that is too large to fit in a single register.

Returns
The high integer return value register index, or BN_INVALID_REGISTER if there is none

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ GetFloatReturnValueRegister()

uint32_t CallingConvention::GetFloatReturnValueRegister ( )
virtual

Gets the register that holds the floating point return value.

Returns
The floating point return value register index, or BN_INVALID_REGISTER if there is none

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ GetGlobalPointerRegister()

uint32_t CallingConvention::GetGlobalPointerRegister ( )
virtual
Deprecated
Use GetGlobalPointerRegisters instead. New calling convention implementations should override GetGlobalPointerRegisters.
Returns
The global pointer register index, or BN_INVALID_REGISTER if there is none

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ GetGlobalPointerRegisters()

vector< uint32_t > CallingConvention::GetGlobalPointerRegisters ( )
virtual

◆ GetImplicitlyDefinedRegisters()

vector< uint32_t > CallingConvention::GetImplicitlyDefinedRegisters ( )
virtual

Gets the registers that are implicitly given a known value on function entry by this calling convention.

Returns
The list of implicitly defined register indices
See also
GetIncomingRegisterValue

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ GetIncomingRegisterValue()

RegisterValue CallingConvention::GetIncomingRegisterValue ( uint32_t reg,
Function * func )
virtual

Gets the known value of a register on entry to a function.

Parameters
regRegister index
funcFunction being analyzed
Returns
The incoming value of the register

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ GetIncomingFlagValue()

RegisterValue CallingConvention::GetIncomingFlagValue ( uint32_t flag,
Function * func )
virtual

Gets the known value of a flag on entry to a function.

Parameters
flagFlag index
funcFunction being analyzed
Returns
The incoming value of the flag

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ GetIncomingVariableForParameterVariable()

Variable CallingConvention::GetIncomingVariableForParameterVariable ( const Variable & var,
Function * func )
virtual

Gets the incoming variable that corresponds to the given parameter variable.

This is the inverse of GetParameterVariableForIncomingVariable.

Parameters
varParameter variable
funcFunction being analyzed
Returns
The incoming variable corresponding to the parameter variable
See also
GetParameterVariableForIncomingVariable

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ GetParameterVariableForIncomingVariable()

Variable CallingConvention::GetParameterVariableForIncomingVariable ( const Variable & var,
Function * func )
virtual

Gets the parameter variable that corresponds to the given incoming variable.

This is the inverse of GetIncomingVariableForParameterVariable.

Parameters
varIncoming variable
funcFunction being analyzed
Returns
The parameter variable corresponding to the incoming variable
See also
GetIncomingVariableForParameterVariable

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ IsReturnTypeRegisterCompatible()

bool CallingConvention::IsReturnTypeRegisterCompatible ( BinaryView * view,
Type * type )
virtual

Whether a value of the given type can be returned in registers, as opposed to being returned indirectly through memory.

Parameters
viewBinaryView providing type information
typeReturn type to check
Returns
Whether the return type is register compatible
See also
GetIndirectReturnValueLocation

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ DefaultIsReturnTypeRegisterCompatible()

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.

Parameters
typeReturn type to check
Returns
Whether the return type is register compatible

◆ GetIndirectReturnValueLocation()

Variable CallingConvention::GetIndirectReturnValueLocation ( )
virtual

Gets the location used to pass the hidden pointer argument for return values that are returned indirectly through memory.

Returns
The location of the indirect return value pointer
See also
IsReturnTypeRegisterCompatible

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ GetDefaultIndirectReturnValueLocation()

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.

Returns
The location of the indirect return value pointer

◆ GetReturnedIndirectReturnValuePointer()

std::optional< Variable > CallingConvention::GetReturnedIndirectReturnValuePointer ( )
virtual

Gets the location in which the hidden indirect return value pointer is returned to the caller, for calling conventions that return it.

Returns
The location the indirect return value pointer is returned in, or std::nullopt if it is not returned

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ IsArgumentTypeRegisterCompatible()

bool CallingConvention::IsArgumentTypeRegisterCompatible ( BinaryView * view,
Type * type )
virtual

Whether a value of the given type can be passed as an argument in registers.

Parameters
viewBinaryView providing type information
typeArgument type to check
Returns
Whether the argument type is register compatible

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ DefaultIsArgumentTypeRegisterCompatible()

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.

Parameters
typeArgument type to check
Returns
Whether the argument type is register compatible

◆ IsNonRegisterArgumentIndirect()

bool CallingConvention::IsNonRegisterArgumentIndirect ( BinaryView * view,
Type * type )
virtual

Whether an argument that cannot be passed in registers is passed indirectly by pointer as opposed to being passed directly on the stack.

Parameters
viewBinaryView providing type information
typeArgument type to check
Returns
Whether the non-register argument is passed indirectly by pointer

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ AreStackArgumentsNaturallyAligned()

bool CallingConvention::AreStackArgumentsNaturallyAligned ( )
virtual

Whether arguments passed on the stack are aligned to their natural alignment.

If false, arguments are aligned to the address size.

Returns
Whether stack arguments are naturally aligned

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ AreStackArgumentsPushedLeftToRight()

bool CallingConvention::AreStackArgumentsPushedLeftToRight ( )
virtual

Whether arguments passed on the stack are pushed left-to-right, as opposed to the more common right-to-left order.

Returns
Whether stack arguments are pushed left-to-right

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ GetCallLayout()

CallLayout CallingConvention::GetCallLayout ( BinaryView * view,
const ReturnValue & returnValue,
const std::vector< FunctionParameter > & params,
const std::optional< std::set< uint32_t > > & permittedRegs = std::nullopt )
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.

Parameters
viewBinaryView providing type information
returnValueReturn value of the call
paramsParameters of the call
permittedRegsOptional set of register indices that argument passing is restricted to; if not provided, the calling convention's default registers are used
Returns
The computed call layout

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ GetReturnValueLocation()

ValueLocation CallingConvention::GetReturnValueLocation ( BinaryView * view,
const ReturnValue & returnValue )
virtual

Computes the location of the return value for the given return value type and location structure.

The default implementation calls GetDefaultReturnValueLocation.

Parameters
viewBinaryView providing type information
returnValueReturn value to compute the location for
Returns
The location of the return value

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ GetParameterLocations()

vector< ValueLocation > CallingConvention::GetParameterLocations ( BinaryView * view,
const std::optional< ValueLocation > & returnValue,
const std::vector< FunctionParameter > & params,
const std::optional< std::set< uint32_t > > & permittedRegs = std::nullopt )
virtual

Computes the locations of the parameters for a call with the given return value and parameters.

The default implementation calls GetDefaultParameterLocations.

Parameters
viewBinaryView providing type information
returnValueOptional location of the return value, which may affect parameter placement (for example, when an indirect return pointer consumes an argument register)
paramsParameters of the call
permittedRegsOptional set of register indices that argument passing is restricted to; if not provided, the calling convention's default registers are used
Returns
The locations of the parameters, in order

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ GetParameterOrderingForVariables()

std::vector< Variable > CallingConvention::GetParameterOrderingForVariables ( BinaryView * view,
const std::map< Variable, Ref< Type > > & params )
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.

Parameters
viewBinaryView providing type information
paramsMap of parameter variables to their types
Returns
The parameter variables in the order they are passed

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ GetStackAdjustmentForLocations()

int64_t CallingConvention::GetStackAdjustmentForLocations ( BinaryView * view,
const std::optional< ValueLocation > & returnValue,
const std::vector< ValueLocation > & locations,
const std::vector< Ref< Type > > & types )
virtual

Computes the stack adjustment applied on return for a call with the given return value and parameter locations.

The default implementation calls GetDefaultStackAdjustmentForLocations.

Parameters
viewBinaryView providing type information
returnValueOptional location of the return value
locationsLocations of the parameters
typesTypes of the parameters, corresponding to locations
Returns
The stack adjustment in bytes
See also
IsStackAdjustedOnReturn

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ GetRegisterStackAdjustments()

std::map< uint32_t, int32_t > CallingConvention::GetRegisterStackAdjustments ( BinaryView * view,
const std::optional< ValueLocation > & returnValue,
const std::vector< ValueLocation > & params )
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.

Parameters
viewBinaryView providing type information
returnValueOptional location of the return value
paramsLocations of the parameters
Returns
A map from register stack index to its adjustment

Reimplemented in BinaryNinja::CoreCallingConvention.

◆ GetDefaultCallLayout()

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.

Parameters
viewBinaryView providing type information
returnValueReturn value of the call
paramsParameters of the call
permittedRegsOptional set of register indices that argument passing is restricted to; if not provided, the calling convention's default registers are used
Returns
The computed call layout

◆ GetDefaultReturnValueLocation()

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.

Parameters
viewBinaryView providing type information
returnValueReturn value to compute the location for
Returns
The location of the return value

◆ GetDefaultParameterLocations()

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.

Parameters
viewBinaryView providing type information
returnValueOptional location of the return value
paramsParameters of the call
permittedRegsOptional set of register indices that argument passing is restricted to; if not provided, the calling convention's default registers are used
Returns
The locations of the parameters, in order

◆ GetDefaultParameterOrderingForVariables()

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.

Parameters
paramsMap of parameter variables to their types
Returns
The parameter variables in the order they are passed

◆ GetDefaultStackAdjustmentForLocations()

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.

Parameters
returnValueOptional location of the return value
locationsLocations of the parameters
typesTypes of the parameters, corresponding to locations
Returns
The stack adjustment in bytes

◆ GetDefaultRegisterStackAdjustments()

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.

Parameters
returnValueOptional location of the return value
paramsLocations of the parameters
Returns
A map from register stack index to its adjustment

◆ BinaryNinja::CoreCallingConvention

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< VariableGetReturnedIndirectReturnValuePointer () 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 > &params, 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< ValueLocationGetParameterLocations (BinaryView *view, const std::optional< ValueLocation > &returnValue, const std::vector< FunctionParameter > &params, 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< VariableGetParameterOrderingForVariables (BinaryView *view, const std::map< Variable, Ref< Type > > &params) 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 > &params) 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< ArchitectureGetArchitecture () 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 > &params, 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< ValueLocationGetDefaultParameterLocations (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.
std::vector< VariableGetDefaultParameterOrderingForVariables (const std::map< Variable, Ref< Type > > &params)
 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 > &params)
 Default implementation of GetRegisterStackAdjustments.
Public Member Functions inherited from BinaryNinja::CoreRefCountObject< BNCallingConvention, BNNewCallingConventionReference, BNFreeCallingConvention >
 CoreRefCountObject ()
virtual ~CoreRefCountObject ()
BNCallingConventionGetObject () 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
BNCallingConventionm_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 BNValueLocationGetParameterLocationsCallback (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 BNVariableGetParameterOrderingForVariablesCallback (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)

Constructor & Destructor Documentation

◆ CoreCallingConvention()

CoreCallingConvention::CoreCallingConvention ( BNCallingConvention * cc)

Member Function Documentation

◆ GetCallerSavedRegisters()

vector< uint32_t > CoreCallingConvention::GetCallerSavedRegisters ( )
overridevirtual

Gets the list of registers that are not preserved across a call (caller-saved / volatile registers).

Returns
The list of caller-saved register indices

Reimplemented from BinaryNinja::CallingConvention.

◆ GetCalleeSavedRegisters()

vector< uint32_t > CoreCallingConvention::GetCalleeSavedRegisters ( )
overridevirtual

Gets the list of registers that a callee must preserve across a call (callee-saved / non-volatile registers).

Returns
The list of callee-saved register indices

Reimplemented from BinaryNinja::CallingConvention.

◆ GetIntegerArgumentRegisters()

vector< uint32_t > CoreCallingConvention::GetIntegerArgumentRegisters ( )
overridevirtual

Gets the registers used to pass integer and pointer arguments, in the order they are used.

Returns
The ordered list of integer argument register indices

Reimplemented from BinaryNinja::CallingConvention.

◆ GetFloatArgumentRegisters()

vector< uint32_t > CoreCallingConvention::GetFloatArgumentRegisters ( )
overridevirtual

Gets the registers used to pass floating point arguments, in the order they are used.

Returns
The ordered list of floating point argument register indices

Reimplemented from BinaryNinja::CallingConvention.

◆ GetRequiredArgumentRegisters()

vector< uint32_t > CoreCallingConvention::GetRequiredArgumentRegisters ( )
overridevirtual

Gets the set of registers that must be arguments for heuristic calling convention detection to consider this calling convention as a valid option.

Returns
The set of registers that must be arguments

Reimplemented from BinaryNinja::CallingConvention.

◆ GetRequiredClobberedRegisters()

vector< uint32_t > CoreCallingConvention::GetRequiredClobberedRegisters ( )
overridevirtual

Gets the set of registers that must be clobbered for heuristic calling convention detection to consider this calling convention as a valid option.

Returns
The set of registers that must be clobbered

Reimplemented from BinaryNinja::CallingConvention.

◆ AreArgumentRegistersSharedIndex()

bool CoreCallingConvention::AreArgumentRegistersSharedIndex ( )
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.

Returns
Whether argument registers share a single index

Reimplemented from BinaryNinja::CallingConvention.

◆ AreArgumentRegistersUsedForVarArgs()

bool CoreCallingConvention::AreArgumentRegistersUsedForVarArgs ( )
overridevirtual

Whether argument registers are used to pass variadic arguments.

Returns
Whether argument registers are used for variadic arguments

Reimplemented from BinaryNinja::CallingConvention.

◆ IsStackReservedForArgumentRegisters()

bool CoreCallingConvention::IsStackReservedForArgumentRegisters ( )
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).

Returns
Whether stack space is reserved for argument registers

Reimplemented from BinaryNinja::CallingConvention.

◆ IsStackAdjustedOnReturn()

bool CoreCallingConvention::IsStackAdjustedOnReturn ( )
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).

Returns
Whether the stack is adjusted by the callee on return

Reimplemented from BinaryNinja::CallingConvention.

◆ IsEligibleForHeuristics()

bool CoreCallingConvention::IsEligibleForHeuristics ( )
overridevirtual

Whether this calling convention may be selected by heuristic calling convention detection.

Returns
Whether this calling convention is eligible for heuristics

Reimplemented from BinaryNinja::CallingConvention.

◆ GetIntegerReturnValueRegister()

uint32_t CoreCallingConvention::GetIntegerReturnValueRegister ( )
overridevirtual

Gets the register that holds the integer return value.

Returns
The integer return value register index

Implements BinaryNinja::CallingConvention.

◆ GetHighIntegerReturnValueRegister()

uint32_t CoreCallingConvention::GetHighIntegerReturnValueRegister ( )
overridevirtual

Gets the register that holds the high part of an integer return value that is too large to fit in a single register.

Returns
The high integer return value register index, or BN_INVALID_REGISTER if there is none

Reimplemented from BinaryNinja::CallingConvention.

◆ GetFloatReturnValueRegister()

uint32_t CoreCallingConvention::GetFloatReturnValueRegister ( )
overridevirtual

Gets the register that holds the floating point return value.

Returns
The floating point return value register index, or BN_INVALID_REGISTER if there is none

Reimplemented from BinaryNinja::CallingConvention.

◆ GetGlobalPointerRegister()

uint32_t CoreCallingConvention::GetGlobalPointerRegister ( )
overridevirtual
Deprecated
Use GetGlobalPointerRegisters instead. New calling convention implementations should override GetGlobalPointerRegisters.

Reimplemented from BinaryNinja::CallingConvention.

◆ GetGlobalPointerRegisters()

vector< uint32_t > CoreCallingConvention::GetGlobalPointerRegisters ( )
overridevirtual

Reimplemented from BinaryNinja::CallingConvention.

◆ GetImplicitlyDefinedRegisters()

vector< uint32_t > CoreCallingConvention::GetImplicitlyDefinedRegisters ( )
overridevirtual

Gets the registers that are implicitly given a known value on function entry by this calling convention.

Returns
The list of implicitly defined register indices
See also
GetIncomingRegisterValue

Reimplemented from BinaryNinja::CallingConvention.

◆ GetIncomingRegisterValue()

RegisterValue CoreCallingConvention::GetIncomingRegisterValue ( uint32_t reg,
Function * func )
overridevirtual

Gets the known value of a register on entry to a function.

Parameters
regRegister index
funcFunction being analyzed
Returns
The incoming value of the register

Reimplemented from BinaryNinja::CallingConvention.

◆ GetIncomingFlagValue()

RegisterValue CoreCallingConvention::GetIncomingFlagValue ( uint32_t flag,
Function * func )
overridevirtual

Gets the known value of a flag on entry to a function.

Parameters
flagFlag index
funcFunction being analyzed
Returns
The incoming value of the flag

Reimplemented from BinaryNinja::CallingConvention.

◆ GetIncomingVariableForParameterVariable()

Variable CoreCallingConvention::GetIncomingVariableForParameterVariable ( const Variable & var,
Function * func )
overridevirtual

Gets the incoming variable that corresponds to the given parameter variable.

This is the inverse of GetParameterVariableForIncomingVariable.

Parameters
varParameter variable
funcFunction being analyzed
Returns
The incoming variable corresponding to the parameter variable
See also
GetParameterVariableForIncomingVariable

Reimplemented from BinaryNinja::CallingConvention.

◆ GetParameterVariableForIncomingVariable()

Variable CoreCallingConvention::GetParameterVariableForIncomingVariable ( const Variable & var,
Function * func )
overridevirtual

Gets the parameter variable that corresponds to the given incoming variable.

This is the inverse of GetIncomingVariableForParameterVariable.

Parameters
varIncoming variable
funcFunction being analyzed
Returns
The parameter variable corresponding to the incoming variable
See also
GetIncomingVariableForParameterVariable

Reimplemented from BinaryNinja::CallingConvention.

◆ IsReturnTypeRegisterCompatible()

bool CoreCallingConvention::IsReturnTypeRegisterCompatible ( BinaryView * view,
Type * type )
overridevirtual

Whether a value of the given type can be returned in registers, as opposed to being returned indirectly through memory.

Parameters
viewBinaryView providing type information
typeReturn type to check
Returns
Whether the return type is register compatible
See also
GetIndirectReturnValueLocation

Reimplemented from BinaryNinja::CallingConvention.

◆ GetIndirectReturnValueLocation()

Variable CoreCallingConvention::GetIndirectReturnValueLocation ( )
overridevirtual

Gets the location used to pass the hidden pointer argument for return values that are returned indirectly through memory.

Returns
The location of the indirect return value pointer
See also
IsReturnTypeRegisterCompatible

Reimplemented from BinaryNinja::CallingConvention.

◆ GetReturnedIndirectReturnValuePointer()

std::optional< Variable > CoreCallingConvention::GetReturnedIndirectReturnValuePointer ( )
overridevirtual

Gets the location in which the hidden indirect return value pointer is returned to the caller, for calling conventions that return it.

Returns
The location the indirect return value pointer is returned in, or std::nullopt if it is not returned

Reimplemented from BinaryNinja::CallingConvention.

◆ IsArgumentTypeRegisterCompatible()

bool CoreCallingConvention::IsArgumentTypeRegisterCompatible ( BinaryView * view,
Type * type )
overridevirtual

Whether a value of the given type can be passed as an argument in registers.

Parameters
viewBinaryView providing type information
typeArgument type to check
Returns
Whether the argument type is register compatible

Reimplemented from BinaryNinja::CallingConvention.

◆ IsNonRegisterArgumentIndirect()

bool CoreCallingConvention::IsNonRegisterArgumentIndirect ( BinaryView * view,
Type * type )
overridevirtual

Whether an argument that cannot be passed in registers is passed indirectly by pointer as opposed to being passed directly on the stack.

Parameters
viewBinaryView providing type information
typeArgument type to check
Returns
Whether the non-register argument is passed indirectly by pointer

Reimplemented from BinaryNinja::CallingConvention.

◆ AreStackArgumentsNaturallyAligned()

bool CoreCallingConvention::AreStackArgumentsNaturallyAligned ( )
overridevirtual

Whether arguments passed on the stack are aligned to their natural alignment.

If false, arguments are aligned to the address size.

Returns
Whether stack arguments are naturally aligned

Reimplemented from BinaryNinja::CallingConvention.

◆ AreStackArgumentsPushedLeftToRight()

bool CoreCallingConvention::AreStackArgumentsPushedLeftToRight ( )
overridevirtual

Whether arguments passed on the stack are pushed left-to-right, as opposed to the more common right-to-left order.

Returns
Whether stack arguments are pushed left-to-right

Reimplemented from BinaryNinja::CallingConvention.

◆ GetCallLayout()

CallLayout CoreCallingConvention::GetCallLayout ( BinaryView * view,
const ReturnValue & returnValue,
const std::vector< FunctionParameter > & params,
const std::optional< std::set< uint32_t > > & permittedRegs = std::nullopt )
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.

Parameters
viewBinaryView providing type information
returnValueReturn value of the call
paramsParameters of the call
permittedRegsOptional set of register indices that argument passing is restricted to; if not provided, the calling convention's default registers are used
Returns
The computed call layout

Reimplemented from BinaryNinja::CallingConvention.

◆ GetReturnValueLocation()

ValueLocation CoreCallingConvention::GetReturnValueLocation ( BinaryView * view,
const ReturnValue & returnValue )
overridevirtual

Computes the location of the return value for the given return value type and location structure.

The default implementation calls GetDefaultReturnValueLocation.

Parameters
viewBinaryView providing type information
returnValueReturn value to compute the location for
Returns
The location of the return value

Reimplemented from BinaryNinja::CallingConvention.

◆ GetParameterLocations()

vector< ValueLocation > CoreCallingConvention::GetParameterLocations ( BinaryView * view,
const std::optional< ValueLocation > & returnValue,
const std::vector< FunctionParameter > & params,
const std::optional< std::set< uint32_t > > & permittedRegs = std::nullopt )
overridevirtual

Computes the locations of the parameters for a call with the given return value and parameters.

The default implementation calls GetDefaultParameterLocations.

Parameters
viewBinaryView providing type information
returnValueOptional location of the return value, which may affect parameter placement (for example, when an indirect return pointer consumes an argument register)
paramsParameters of the call
permittedRegsOptional set of register indices that argument passing is restricted to; if not provided, the calling convention's default registers are used
Returns
The locations of the parameters, in order

Reimplemented from BinaryNinja::CallingConvention.

◆ GetParameterOrderingForVariables()

std::vector< Variable > CoreCallingConvention::GetParameterOrderingForVariables ( BinaryView * view,
const std::map< Variable, Ref< Type > > & params )
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.

Parameters
viewBinaryView providing type information
paramsMap of parameter variables to their types
Returns
The parameter variables in the order they are passed

Reimplemented from BinaryNinja::CallingConvention.

◆ GetStackAdjustmentForLocations()

int64_t CoreCallingConvention::GetStackAdjustmentForLocations ( BinaryView * view,
const std::optional< ValueLocation > & returnValue,
const std::vector< ValueLocation > & locations,
const std::vector< Ref< Type > > & types )
overridevirtual

Computes the stack adjustment applied on return for a call with the given return value and parameter locations.

The default implementation calls GetDefaultStackAdjustmentForLocations.

Parameters
viewBinaryView providing type information
returnValueOptional location of the return value
locationsLocations of the parameters
typesTypes of the parameters, corresponding to locations
Returns
The stack adjustment in bytes
See also
IsStackAdjustedOnReturn

Reimplemented from BinaryNinja::CallingConvention.

◆ GetRegisterStackAdjustments()

std::map< uint32_t, int32_t > CoreCallingConvention::GetRegisterStackAdjustments ( BinaryView * view,
const std::optional< ValueLocation > & returnValue,
const std::vector< ValueLocation > & params )
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.

Parameters
viewBinaryView providing type information
returnValueOptional location of the return value
paramsLocations of the parameters
Returns
A map from register stack index to its adjustment

Reimplemented from BinaryNinja::CallingConvention.