Last active
August 29, 2015 13:58
-
-
Save inaz2/9947702 to your computer and use it in GitHub Desktop.
GCCインラインアセンブラでスタックを見る
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ gcc -masm=intel inlineasm.c | |
$ ./a.out | |
saved_ebp = 0 | |
saved_eip = b7e444d3 | |
argc = 1 | |
argv = bffff864 | |
envp = bffff86c | |
$ objdump -d a.out | sed -n '/<main>:/,/^$/p' | |
080483e4 <main>: | |
80483e4: 55 push ebp | |
80483e5: 89 e5 mov ebp,esp | |
80483e7: 57 push edi | |
80483e8: 56 push esi | |
80483e9: 53 push ebx | |
80483ea: 83 e4 f0 and esp,0xfffffff0 | |
80483ed: 83 ec 40 sub esp,0x40 | |
80483f0: 8b 75 00 mov esi,DWORD PTR [ebp+0x0] | |
80483f3: 8b 5d 04 mov ebx,DWORD PTR [ebp+0x4] | |
80483f6: 8b 4d 08 mov ecx,DWORD PTR [ebp+0x8] | |
80483f9: 8b 55 0c mov edx,DWORD PTR [ebp+0xc] | |
80483fc: 8b 45 10 mov eax,DWORD PTR [ebp+0x10] | |
80483ff: 89 74 24 2c mov DWORD PTR [esp+0x2c],esi | |
8048403: 89 5c 24 30 mov DWORD PTR [esp+0x30],ebx | |
8048407: 89 4c 24 34 mov DWORD PTR [esp+0x34],ecx | |
804840b: 89 54 24 38 mov DWORD PTR [esp+0x38],edx | |
804840f: 89 44 24 3c mov DWORD PTR [esp+0x3c],eax | |
8048413: 8b 7c 24 3c mov edi,DWORD PTR [esp+0x3c] | |
8048417: 8b 74 24 38 mov esi,DWORD PTR [esp+0x38] | |
804841b: 8b 5c 24 34 mov ebx,DWORD PTR [esp+0x34] | |
804841f: 8b 4c 24 30 mov ecx,DWORD PTR [esp+0x30] | |
8048423: 8b 54 24 2c mov edx,DWORD PTR [esp+0x2c] | |
8048427: b8 30 85 04 08 mov eax,0x8048530 | |
804842c: 89 7c 24 14 mov DWORD PTR [esp+0x14],edi | |
8048430: 89 74 24 10 mov DWORD PTR [esp+0x10],esi | |
8048434: 89 5c 24 0c mov DWORD PTR [esp+0xc],ebx | |
8048438: 89 4c 24 08 mov DWORD PTR [esp+0x8],ecx | |
804843c: 89 54 24 04 mov DWORD PTR [esp+0x4],edx | |
8048440: 89 04 24 mov DWORD PTR [esp],eax | |
8048443: e8 b8 fe ff ff call 8048300 <printf@plt> | |
8048448: b8 00 00 00 00 mov eax,0x0 | |
804844d: 8d 65 f4 lea esp,[ebp-0xc] | |
8048450: 5b pop ebx | |
8048451: 5e pop esi | |
8048452: 5f pop edi | |
8048453: 5d pop ebp | |
8048454: c3 ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() | |
{ | |
unsigned int x[5]; | |
__asm__("mov %0, [ebp]\n" | |
"mov %1, [ebp+4]\n" | |
"mov %2, [ebp+8]\n" | |
"mov %3, [ebp+12]\n" | |
"mov %4, [ebp+16]\n" | |
: "=r" (x[0]), "=r" (x[1]), "=r" (x[2]), "=r" (x[3]), "=r" (x[4]) | |
); | |
printf("saved_ebp = %x\n" | |
"saved_eip = %x\n" | |
"argc = %x\n" | |
"argv = %x\n" | |
"envp = %x\n" | |
, x[0], x[1], x[2], x[3], x[4]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment