Home Artists Posts Import Register

Downloads

Content

Calling Conventions

  • Different conventions based on processor, OS, and language
  • Describes how arguments are passed to functions
  • Describes how values are returned from functions
  • Describes if the caller or callee cleans the stack
  • Responsible for function prologue and epilogue

Practical Calling Conventions


Windows x86 Calling Conventions

  • All arguments are widened to 32 bits (DWORD)
  • Return value is widened to 32 bits (DWORD)
  • Return values up to 32 bits are returned in EAX
  • Return values of 64 bit size (QWORD) are returned in EDX:EAX
  • Return structures are returned by reference with a pointer in EAX
  • Registers ESI, EDI, EBX, and EBP are restored (non-volatile)
  • MSDN is your friend!

Calling Convention: __cdecl

  • Default calling convention for C and C++
  • Arguments are passed on the stack (pushed right-to-left)
  • Caller is responsible for stack cleanup
  • Supports vararg (variadic) functions

MSDN calling convention documentation 


More Calling Convention Tutorials 


Practice Examples

Attached to this post is a copy of the HelloWorld PE file from our tutorial. You are encouraged to open this sample in IDA and identify the function calling conventions as well work through the varargs access in the variadic function.

Files

Assembly Calling Conventions For Reverse Engineers [Patreon Unlocked]

A practical look at x86 calling conventions from a reverse engineering perspective. We take a look at __cdecl __stdcall __fastcall __thiscall ----- OALABS DISCORD https://discord.gg/6h5Bh5AMDU OALABS PATREON https://www.patreon.com/oalabs Twitch https://www.twitch.tv/oalabslive OALABS GITHUB https://github.com/OALabs UNPACME - AUTOMATED MALWARE UNPACKING https://www.unpac.me/#/ -----

Comments

s187

wow just learnt about this grouping @16:00, awesome video btw :)