Skip to content

Instantly share code, notes, and snippets.

@ak1t0
Last active August 29, 2015 14:05
Show Gist options
  • Save ak1t0/fea2a794f96b1aa740a4 to your computer and use it in GitHub Desktop.
Save ak1t0/fea2a794f96b1aa740a4 to your computer and use it in GitHub Desktop.
Hacking:美しき策謀 0x200 @ubuntu 14.04 32bit
#include <stdio.h>
int main()
{
int i;
for (i = 0; i < 10; i++) // 10回繰り返す
{
printf("Hello, world!\n"); // 文字列を出力する
}
return 0; // プログラムが問題なく終了したことをOSに知らせる
}
(gdb) disas main
Dump of assembler code for function main:
0x0804841d <+0>: push ebp
//ebp の値をスタックに積み上げ
0x0804841e <+1>: mov ebp,esp
//esp の値を ebp へ
0x08048420 <+3>: and esp,0xfffffff0
0x08048423 <+6>: sub esp,0x20
0x08048426 <+9>: mov DWORD PTR [esp+0x1c],0x0
//int i = 0;
0x0804842e <+17>: jmp 0x8048441 <main+36>
//ループ条件チェック(0x08048441 <+36> → 0x08048446 <+41>)
0x08048430 <+19>: mov DWORD PTR [esp],0x80484e0
//esp に文字列のメモリアドレスを
0x08048437 <+26>: call 0x80482f0 <puts@plt>
//printf を呼ぶ
0x0804843c <+31>: add DWORD PTR [esp+0x1c],0x1
//i++
0x08048441 <+36>: cmp DWORD PTR [esp+0x1c],0x9
//i < 10 かどうか
0x08048446 <+41>: jle 0x8048430 <main+19>
//i < 10 なら pritf(0x08048430 <+19> → 0x08048437 <+26>) へ jump
0x08048448 <+43>: mov eax,0x0
0x0804844d <+48>: leave
0x0804844e <+49>: ret
End of assembler dump.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment