Skip to content

Instantly share code, notes, and snippets.

@SiD3W4y
Created September 17, 2017 13:11
Show Gist options
  • Save SiD3W4y/d91359ff28560f7a6bb5374ce1862cd9 to your computer and use it in GitHub Desktop.
Save SiD3W4y/d91359ff28560f7a6bb5374ce1862cd9 to your computer and use it in GitHub Desktop.
Simple tutorial on Reverse Engineering and understanding assembly
#include <stdio.h>
int main()
{
int a = 2;
int b = 4;
int c = a + b + 3;
printf("Resultat %d\n",c);
return 0;
}
push rbp
mov rbp, rsp
sub rsp, 0x20
lea rdi, str.Resultat__d_n ; 0x754 ; "Resultat %d\n"
mov dword [local_4h], 0 ; local_XX sont les variables sur le stack
mov dword [local_8h], 2 ; ici on a local_8h = 2 donc local_8h est notre variable a
mov dword [local_ch], 4 ; ici ont peut voir que cette variable est b
mov eax, dword [local_8h] ; on a eax = a
add eax, dword [local_ch] ; et ici eax += b
add eax, 3 ; Et pour finir eax += 3 (si on reprend tout on a donc -> eax = local_8h + local_ch + 3 soit eax = a + b + 3
mov dword [local_10h], eax ; Et ici on met le resultat dans local_10h, ce qui est la variable c
mov esi, dword [local_10h] ; Dans esi on a l'arg c (local_10h)
mov al, 0
call sym.imp.printf ; La convention de call est System V, les args sont donc dans RDI,RSI,RDX ...
; Il se trouve que RDI = addresse de notre string format et esi = rsi = variable c
; On peut donc determiner que la fonction est printf("Resultat %d\n",c);
xor esi, esi ; ESI = 0
mov dword [local_14h], eax ; Valeur de retour de printf stockée dans local_14h
mov eax, esi ; eax est la valeur de retour de notre fonction
add rsp, 0x20
pop rbp
ret ; Comme eax = 0 on a donc return 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment