這只是顯示由C函數生成的彙編代碼。如果您註釋掉C行,並在中間添加一些換行符,它會變得更清晰。
// void myfun1(char *str) {
push ebp
mov ebp,esp
// char buffer[16];
sub esp,0x18 // Allocate space for buffer and function args.
// strcpy(buffer, str);
mov eax,DWORDPTR [ebp+8] // Load the str parameter into eax.
mov DWORD PTR [esp+4],eax // Set str as the second argument to strcpy.
lea eax,[ebp-16] // Load the address of the buffer into eax.
mov DWORD PTR [esp],eax // Set the address as the first argument to strcpy.
call 0x80482c4 <[email protected]> // Call strcpy.
// myfun2(buffer);
lea eax,[ebp-16] // Load the address of the buffer into eax.
mov DWORD PTR [esp],eax // Set the address as the first argument to myfunc.
call 0x80483b4 <myfun2> // Call myfunc.
// }
leave
ret
這與我期望通常生成C代碼有點不同。在調用函數之前,您通常會將參數推入堆棧,而此代碼已預先在堆棧中創建空間,然後將參數移至堆棧。
爲了更好地理解ebp和esp引用,它有助於構建堆棧的外觀。
ebp+08 The str parameter
ebp+04 The return address
ebp+00 The saved copy of ebp <- ebp
ebp-04 Space for buffer
ebp-08 Space for buffer
ebp-12 Space for buffer
ebp-16 Space for buffer
esp+04 ebp-20 Second function argument
esp+00 ebp-24 First function argument <- esp
當函數被調用時,STR參數壓入堆棧,加調用代碼的返回地址。該函數然後保存ebp的副本,並將ebp設置爲指向堆棧上的該位置。最後它爲緩衝區(16字節)加上空間,並在函數調用中使用兩個參數(另外8個字節)。
看起來像字符串複製給我。將字符串複製到指定的緩衝區。而不是這個C混入了組裝,而不是純粹的組裝? – Gray
是的,它與C混合..你是對的! – Rebecca
這是哪個編譯器的工作原理?視覺?數字? –