I'm starting to learn amd86_64 calling convention and how it calls params and clean the stack but the concept hasn't sunk in yet, so i would like to get a help reading the params as this might clear the confusion for me in the future. I used the same function on a different processor architecture before but i'm sure the signature has changed by the devs because I tried to call it same as before but it crashes every time, here's the old signature:
void(*DrawText)(int, float x, float y, int color, const char * text)
Here's the assembly for the function in amd86_64 starting from the caller function:
push rbp mov rbp, rsp push r15 push r14 push r13 push r12 push rbx sub rsp, 178h lea rdi, [rbp+var_108] mov esi, 1 xor edx, edx call sub_937750 lea rax, dword_1885C10 vcvtsi2ss xmm0, xmm0, dword ptr [rax+54h] vmovss [rbp+var_164], xmm0 vcvtsi2ss xmm0, xmm0, dword ptr [rax+58h] vmovss [rbp+var_168], xmm0 lea rsi, a30f_1 vmovss xmm0, dword ptr cs:qword_10799B8 xor edi, edi call sub_A0E930 lea rcx, qword_17FAB50 mov rcx, [rcx] cmp byte ptr [rcx+2E87h], 0 jnz loc_4994 cmp byte ptr [rcx+2E81h], 0 jz loc_4994 mov eax, eax vcvtsi2ss xmm0, xmm0, rax vmovss xmm1, [rbp+var_168] vsubss xmm0, xmm1, xmm0 lea rax, unk_1871D60 vmovss xmm2, dword ptr [rax] vxorps xmm1, xmm1, xmm1 vucomiss xmm2, xmm1 jbe loc_3E5E vmovss xmm1, dword ptr cs:qword_10799B8 vdivss xmm1, xmm1, xmm2 vmovss [rbp+var_16C], xmm1 vcvtss2sd xmm2, xmm2, xmm2 lea rdi, [rbp+var_108] lea rdx, a62fFps mov eax, 0FF0000FFh mov ecx, 0FF00FFFFh mov r14d, 0FF00FF00h vucomiss xmm1, dword ptr cs:qword_10799B8+4 cmova r14d, ecx vaddss xmm1, xmm1, dword ptr cs:qword_10799B8+8 vucomiss xmm1, dword ptr cs:qword_10799B8+0Ch cmova r14d, eax vmovss [rbp+var_168], xmm0 vmovss xmm1, [rbp+var_164] mov esi, r14d mov al, 3 call DrawText
Here's what I gathered so far (not sure if it's right though), 1st arg is a pointer
lea rdi, [rbp+var_108] 2nd and 3rd are floats which is the positioning coordinates:
vmovss xmm1, dword ptr cs:qword_10799B8 vdivss xmm1, xmm1, xmm2 vmovss [rbp+var_16C], xmm1 vcvtss2sd xmm2, xmm2, xmm2
4th and 6th are int's (hex code for rgb colors I assume)
mov esi, r14d and
mov ecx, 0FF00FFFFh the 5th arg is a char pointer
lea rdx, a62fFps. The function doesn't return anything so i'm sure it's a void.
void(*DrawText)(int *, float x, float y, int color, int, const char * text)
I tried to call this way but it also crashes, please let me know if I got something wrong and explain stuff because i'm little newbee when it comes to assembly.
Note: This is not a PLEASE DO IT FOR ME question but rather explain how do I read the params properly, I don't mind posting the final result at the end of the answer though.