“调用 0x80482f0”?只需要澄清“hello world”中的一行代码即可。 x86 汇编中的程序
“调用 0x80482f0
”?只需要 x86 程序集中“hello world”程序中一行代码的帮助。
注意:我在编程/调试时运行 ubuntu linux,使用 gcc 作为编译器,使用 gdb 作为调试器。
我正在阅读黑客:利用的艺术 V2 并且我编译了这个 C 程序:
1 #include <stdio.h>
2
3 int main()
4 {
5 int i;
6 for(i=0; i<10; i++)
7 {
8 printf("Hello, world\n");
9 }
10 return 0;
到汇编中的这个程序中:
0x080483b4 <+0>: push ebp
0x080483b5 <+1>: mov ebp,esp
0x080483b7 <+3>: and esp,0xfffffff0
0x080483ba <+6>: sub esp,0x20
0x080483bd <+9>: mov DWORD PTR [esp+0x1c],0x0
0x080483c5 <+17>: jmp 0x80483d8 <main+36>
0x080483c7 <+19>: mov DWORD PTR [esp],0x80484b0
0x080483ce <+26>: call 0x80482f0 <puts@plt>
=> 0x080483d3 <+31>: add DWORD PTR [esp+0x1c],0x1
0x080483d8 <+36>: cmp DWORD PTR [esp+0x1c],0x9
0x080483dd <+41>: jle 0x80483c7 <main+19>
0x080483df <+43>: mov eax,0x0
0x080483e4 <+48>: leave
0x080483e5 <+49>: ret
现在..我理解这个程序的每个部分,直到它到达:
0x080483ce <+26>: call 0x80482f0 <puts@plt>
我不知道的部分理解是..如果“Hello, world\n”存储在0x80484b0,然后该地址存储到ESP的地址中,为什么:
0x080483ce <+26>: call 0x80482f0 <puts@plt>
引用0x80482f0,而不是[esp]或只需“0x80484b0”即可将“Hello, world\n”打印到屏幕上?我使用了 gdb,我无法弄清楚 0x80482f0 到底引用了什么。任何帮助都会非常
感谢(记住,我刚刚开始接触这些东西,所以我是个菜鸟)
也..我复制并粘贴了反汇编的主文件为了方便起见,从 gdb 中调用了函数,如果您需要更多信息,请询问。如果你想为我解释一下这个命令,那就太好了,因为我之前只使用过“int 80h”来将内容打印到屏幕上
"call 0x80482f0 <puts@plt>
"? Just need help with one line of code in a 'hello world' program in x86 assembly.
NOTE: i'm running ubuntu linux while programming/debugging this, using gcc as the compiler and gdb for the debugger.
I am reading Hacking: The art of Exploitation V2 and I compiled this C program:
1 #include <stdio.h>
2
3 int main()
4 {
5 int i;
6 for(i=0; i<10; i++)
7 {
8 printf("Hello, world\n");
9 }
10 return 0;
into this program in assembly:
0x080483b4 <+0>: push ebp
0x080483b5 <+1>: mov ebp,esp
0x080483b7 <+3>: and esp,0xfffffff0
0x080483ba <+6>: sub esp,0x20
0x080483bd <+9>: mov DWORD PTR [esp+0x1c],0x0
0x080483c5 <+17>: jmp 0x80483d8 <main+36>
0x080483c7 <+19>: mov DWORD PTR [esp],0x80484b0
0x080483ce <+26>: call 0x80482f0 <puts@plt>
=> 0x080483d3 <+31>: add DWORD PTR [esp+0x1c],0x1
0x080483d8 <+36>: cmp DWORD PTR [esp+0x1c],0x9
0x080483dd <+41>: jle 0x80483c7 <main+19>
0x080483df <+43>: mov eax,0x0
0x080483e4 <+48>: leave
0x080483e5 <+49>: ret
now.. i understand every portion of this program, until it gets to:
0x080483ce <+26>: call 0x80482f0 <puts@plt>
what i do not understand is.. if "Hello, world\n" is stored at 0x80484b0, and that address is then stored into the address at ESP, why does the:
0x080483ce <+26>: call 0x80482f0 <puts@plt>
refer to 0x80482f0, instead of [esp] or just "0x80484b0" to print "Hello, world\n" to the screen? i used gdb and i cannot figure out what exactly is being referenced with 0x80482f0.. any help would be great
thanks (and remember, im just starting out with this stuff, so im a noob)
also.. i copy and pasted the disassembled main function from gdb for convenience, if you need any more info, just ask. and if you would like to explain that one command for me, that would be great as well because i've only used "int 80h"'s for printing stuff to the screen before
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
0x80482f0
是puts
函数的地址。更准确地说,它指向 中的puts()
条目程序链接器表 (PLT) - 基本上只是一堆JMP中的一些例程>
(它是比这更复杂一点,但这对于本次讨论并不重要)。puts
函数在堆栈上查找其参数 - 即在[esp]
处。您可能想知道
puts()
调用来自哪里 - 这里的编译器足够聪明,可以看到您在调用printf()< 时实际上没有使用任何格式字符串参数/code>,并将该调用替换为对(速度稍快)
puts()
的调用。如果您仔细观察,您会发现它还从字符串中删除了换行符,因为puts()
在打印给定的字符串后附加了一个换行符。0x80482f0
is the address of theputs
function. To be more precise, it points to the entry forputs()
in the program linker table (PLT) - basically just a bunch ofJMP <some routine in a so-library>
s (it's a little more complex than that, but that's not important for this discussion). Theputs
function looks for its argument on the stack - ie, at[esp]
.You may be wondering where that
puts()
call came from - the compiler here was smart enough to see that you didn't actually use any format string parameters in your call toprintf()
, and replaced that call with a call to the (somewhat faster)puts()
. If you'll look closely, you'll see that it also removed the newline from your string, becauseputs()
appends a newline after printing the string it is given.