运行结果是“you are a pig!”
时间:2008-06-07 08:31:27
来源:论坛整理 作者: 编辑:chinaitzhe
#ifdef __cplusplus
extern "C"
#endif
const int main[]=
{
0x68909090,(int)(main 5),
0xb8909090,(int)puts,
0xc358d0ff,0x20756f59,
0x20657261,0x69702061,
0X0f212067,0x0000000a
};
帮忙解释下这段代码是什么意思。运行结果是“you are a pig!”,不知道为什么会这样,能不能讲下原理或流程?谢了,另外,0x68909090,0xb8909090 这些十六进制数是怎么变成字母的?
网友回复:
- Assembly code
Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ 08048400 <main>: 8048400: 90 nop 8048401: 90 nop 8048402: 90 nop 8048403: 68 14 84 04 08 push $0x8048414 ; push the string to the stack as the first parameter of puts 8048408: 90 nop 8048409: 90 nop 804840a: 90 nop 804840b: b8 54 82 04 08 mov $0x8048254,陎 ; set eax to puts 8048410: ff d0 call *陎 ; call puts 8048412: 58 pop 陎 8048413: c3 ret
网友回复:这段源代码,实际上是把一些指令,按照整数的方式保存。
而x86是little-endian,所以在4字节之内,所有的字节顺序都是反的。
- C/C code
Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ #include <stdio.h> #ifdef __cplusplus extern "C" #endif const int main[]= { 0x68909090, // 3个nop指令90 (int)(main 5), // main相当于指针,main 5就指向了其后的第20个字节,这就是汇编码里0x14的由来。main自己的地址是0x08048400,加上20就是0x08048414 0xb8909090, // 3个nop指令90 (int)puts, // 链接的时候,ld把puts的地址找来填到mov指令里。 0xc358d0ff, // 这里有3条指令:call *陎 ; pop 陎; ret 0x20756f59, // main 5就是这里,也就是最后打出来的字符串。注重字节顺序是反的。4个字符是:空格、u、o、Y 0x20657261, // 空格、e、r、a 0x69702061, // i、p、空格、a 0X0f212067, // '\r'、!、空格、g 0x0000000a // '\0'、'\0'、'\0'、'\n' };
网友回复:0f不是\r,是这个字符?
\r是0d
网友回复:非常感谢,讲得很具体。
关键字:运行,结果是,pig,
上一篇:为什么程序无故修改数据成员
下一篇:下面没有链接了











文章评论
共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面