Chapter 5 - BasicReversing/5.2 FunctionCall.md
You should be able to follow this lesson without the binary, but if you want to compile your own version of the code we will be reversing here is the code:
#include <iostream>
int main() {
printf("Printing with printf(). Here is some data: %d, %d, %f, %p, %d, %f, %f\n", 4, 2, 1.0f, (void*)0xFFF7865, 1498, 87.003f, 99123.34);
return 0;
}
Let's take a look at a function call. In this case the function being called is printf().
When this function is run, it prints the following to the console:
Printing with printf(). Here is some data: 4, 2, 1.000000, 000000000FFF7865, 1498, 87.002998, 99123.340000
We know these parameters are being passed to printf() because the parameters are set before CALL <testing.printf>.
Printing with printf(). Here is some data: %d, %d, %f, %p, %d, %f, %f\n". This is our format string for printf(). Don't forget that this format string is a parameter to printf().RDX - 0x2 which is 0x2.Now the registers used for passing parameters are used, so the program will have to use the stack.
MOV QWORD PTR SS:[RSP + 0x20], 0xFFF7865. This is the value of "000000000FFF7865" that gets printed.MOV DWORD PTR SS:[RSP + 0x28], 0x5DA. 0x5DA is hexadecimal for 1498.MOVUPS XMMWORD PTR SS:[RSP + 0x30], XMM0. Remember that the XMM registers can hold two values. XMM0 contains both 87.002998 and 99123.34.At this point the printf() function is called. printf() will now take these parameters and use them as it needs to.
There you go, that's a function call. If you can understand what was just covered then you shouldn't have much issue understanding any other function call you encounter. Remember, if you aren't reversing 64-bit Windows the calling convention might be different.