strcpy在组装中是什么意思? void myfun1(char*str){ 推ebp 电动汽车 字符缓冲区[16]; 副esp,0x18 strcpy(缓冲区,str); mov eax,DWORDPTR[ebp+8] mov DWORD PTR[esp+4],eax lea eax,[ebp-16] mov DWORD PTR[esp],eax 呼叫0x80482c4 myfun2(缓冲区); lea eax,[ebp-16] mov DWORD PTR[esp],eax 致电0x80483b4 } 离开 ret
如果你们中有人能帮我解释一下这个代码。。我是汇编中的乞丐。这似乎是C代码,汇编一行一行地混合在一起,完全按照前一行所说的做。请注意,这样做没有任何意义。其中一种语言应该被注释掉strcpy在组装中是什么意思? void myfun1(char*str){ 推ebp 电动汽车 字符缓冲区[16]; 副esp,0x18 strcpy(缓冲区,str); mov eax,DWORDPTR[ebp+8] mov DWORD PTR[esp+4],eax lea eax,[ebp-16] mov DWORD PTR[esp],eax 呼叫0x80482c4 myfun2(缓冲区); lea eax,[ebp-16] mov DWORD PTR[esp],eax 致电0x80483b4 } 离开 ret,c,assembly,inline-assembly,C,Assembly,Inline Assembly,如果你们中有人能帮我解释一下这个代码。。我是汇编中的乞丐。这似乎是C代码,汇编一行一行地混合在一起,完全按照前一行所说的做。请注意,这样做没有任何意义。其中一种语言应该被注释掉 void myfun1(char *str) { push ebp mov ebp,esp char buffer[16]; sub esp,0x18 strcpy(buffer, str); mov eax,DWORDPTR [ebp+8] mov DWORD PTR [esp+4],eax lea eax,[ebp-
void myfun1(char *str) {
push ebp
mov ebp,esp
char buffer[16];
sub esp,0x18
strcpy(buffer, str);
mov eax,DWORDPTR [ebp+8]
mov DWORD PTR [esp+4],eax
lea eax,[ebp-16]
mov DWORD PTR [esp],eax
call 0x80482c4 <strcpy@plt>
myfun2(buffer);
lea eax,[ebp-16]
mov DWORD PTR [esp],eax
call 0x80483b4 <myfun2>
}
leave
ret
void myfun1(char*str){//C
推ebp//ASM
电动汽车//-
字符缓冲区[16];//C
子esp,0x18//ASM
strcpy(缓冲区,str);//C
mov eax,DWORDPTR[ebp+8]//ASM
mov DWORD PTR[esp+4],eax//-
lea eax,[ebp-16]//-
mov DWORD PTR[esp],eax//-
呼叫0x80482c4//-
myfun2(缓冲区);//C
lea eax[ebp-16]//ASM
mov DWORD PTR[esp],eax//-
致电0x80483b4//-
}//C
离开//ASM
ret//-
原来的C函数是:
void myfun1(char *str) { //C
push ebp //ASM
mov ebp,esp //-
char buffer[16]; //C
sub esp,0x18 //ASM
strcpy(buffer, str); //C
mov eax,DWORDPTR [ebp+8] //ASM
mov DWORD PTR [esp+4],eax //-
lea eax,[ebp-16] //-
mov DWORD PTR [esp],eax //-
call 0x80482c4 <strcpy@plt> //-
myfun2(buffer); //C
lea eax,[ebp-16] //ASM
mov DWORD PTR [esp],eax //-
call 0x80483b4 <myfun2> //-
} //C
leave //ASM
ret //-
您在语句周围看到的程序集只是编译器为每个语句生成的程序集。例如,使用myfun2(缓冲区)
调用myfun2会生成以下汇编指令:
void myfun1(char *str) {
char buffer[16];
strcpy(buffer, str);
myfun2(buffer);
}
leaeax[ebp-16];将缓冲区地址(ebp-16处的局部变量)加载到eax中
mov DWORD PTR[esp],eax;“推送”堆栈上的地址作为参数-堆栈指针已在前面进行了调整
调用0x80483b4;调用函数
只要编译后的代码有足够的信息将汇编语句映射回源代码行,反汇编程序就可以生成这样的输出。这只是显示C函数生成的汇编代码。如果您注释掉C行,并在它们之间添加一些换行符,将会更清楚地了解发生了什么
lea eax,[ebp-16] ; load the address of buffer (local variable at ebp-16) into eax
mov DWORD PTR [esp],eax ; "push" the address on the stack as parameter - stack pointer has already been adjusted earlier
call 0x80483b4 <myfun2> ; call the function
//void myfun1(char*str){
推ebp
电动汽车
//字符缓冲区[16];
子esp,0x18//为缓冲区和函数参数分配空间。
//strcpy(缓冲区,str);
mov eax,DWORDPTR[ebp+8]//将str参数加载到eax中。
mov DWORD PTR[esp+4],eax//将str设置为strcpy的第二个参数。
leaeax,[ebp-16]//将缓冲区的地址加载到eax中。
mov DWORD PTR[esp],eax//将地址设置为strcpy的第一个参数。
调用0x80482c4//调用strcpy。
//myfun2(缓冲区);
leaeax,[ebp-16]//将缓冲区的地址加载到eax中。
mov DWORD PTR[esp],eax//将地址设置为myfunc的第一个参数。
调用0x80483b4//调用myfunc。
// }
离开
ret
这与我通常期望生成C代码的方式有些不同。您通常会在调用函数之前将参数推送到堆栈上,而这段代码事先在堆栈上留出了空间,然后将参数移到堆栈上
为了更好地理解ebp和esp引用,有助于构建堆栈的外观
// 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 <strcpy@plt> // 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
ebp+08 str参数
ebp+04返回地址
ebp+00保存的ebp副本在我看来像字符串副本。将字符串复制到指定的缓冲区。这不是混合了汇编的C,不是纯汇编吗?是的,它混合了C。。你说得对!这是在哪个编译器上工作?视觉的?数字?你什么意思。。我是一个装配新手!看起来更像是我为考试而学习的函数的反汇编,这段代码是我的医生写的,我试图弄清楚它的意思,但仍然没有从中得到要点。。所以我需要有人能给我解释一下。。提前感谢大家如果你擅长汇编,请你逐行为我解释一下代码中的汇编语言行。。谢谢好的,我已经记录了我的答案中的示例-一般来说,您需要特别熟悉堆栈和堆栈框架概念,以了解参数是如何传递给函数的。谷歌搜索堆栈帧和基指针。是的,我熟悉堆栈帧和基指针。。我几乎能理解你向我解释的!。。谢谢!没有问题-请随意投票支持我们的任何答案:-)非常感谢James,这真的很有帮助=)你怎么知道DWORDPTR[ebp+8]是str?
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