custom_calling_convention
summary: implement a custom calling convention
- description:
The Delphi LStrCatN variadic function is unusual in the sense that it is variadic, purges the bytes from the stack, and the number of bytes to purge is held in EDX. This example shows how to add support for such ad-hoc calling conventions.
You can test this example with the IDB at ../idbs/delphi6_lstrcatn.i64
keywords: types
level: intermediate
Attributes
Classes
Module Contents
- custom_calling_convention.EAX = 0
- custom_calling_convention.EDX = 2
- custom_calling_convention.REGARGS
- class custom_calling_convention.delphi_LStrCatN_cc
Bases:
ida_typeinf.custom_callcnv_t- name = '__lstrcatn'
the name is used as a keyword in the function prototype
- flags
- abibits
abibits to be used for the calling convention
- validate_func(fti)
Validate a function prototype. This function is used during parsing or deserializing a function prototype to verify semantic limitations of the prototype (for example, returning arrays is forbidden in C)
- Parameters:
fti – function prototype
reterr – buffer for error message
- calc_retloc(fti)
Calculate the location of the return value. This function must fill fti->retloc.
- Parameters:
fti – function prototype
- Returns:
success
- calc_arglocs(fti)
Calculate the argument locations. This function must fill all fti->at(i).argloc instances. It may be called for variadic functions too, in calc_varglocs fails.
- Parameters:
fti – function prototype
- Returns:
success
- find_edx_value(call_ea, blk)
- find_varargs(fti, call_ea, blk)
Discover variadic arguments. This function is called only for variadic functions. It is currently used by the decompiler.
- Parameters:
fti – function prototype. find_varargs() should append the discovered variadic arguments to it.
call_ea – address of the call instruction
blk – microcode block with the call instruction
- Returns:
>0 - total number of arguments after the call <0 - failure ==0 - means to use the standard algorithm to discover variadic args
- calc_varglocs(fti, regs, stkargs, nfixed)
Calculate the argument locations for a variadic function. This function must fill all fti->at(i).argloc instances and provide more detailed info about registers and stkargs.
- Parameters:
fti – function prototype
regs – buffer for hidden register arguments, may be nullptr
stkargs – buffer for hidden stack arguments, may be nullptr
nfixed – number of fixed arguments
- Returns:
success
- get_cc_regs(callregs)
Retrieve generic information about call registers.
- get_stkarg_area_info(stkarg_area_info)
Retrieve generic information about stack arguments.
- calc_purged_bytes(fti, call_ea)
Calculate the number of purged bytes
- Parameters:
fti – function prototype
call_ea – address of the call instruction (not used yet)
- decorate_name(name, should_decorate, cc, ftype)
Function to be overloaded for custom calling conventions.
Decorate a function name. Some compilers decorate names depending on the calling convention. This function provides the means to handle it for custom callcnvs. Please note that this is about name decoration (C), not name mangling (C++).
- custom_calling_convention.ccid