要获取操作码,authorhere执行以下操作:
[bodo@bakawali testbed8]$ as testshell2.s -o testshell2.o
[bodo@bakawali testbed8]$ ld testshell2.o -o testshell2
[bodo@bakawali testbed8]$ objdump -d testshell2
然后他得到三个部分(或者只提到这三个部分):
我试图以同样的方式获取十六进制操作码,但无法正确地
ld
。当然,我可以生成.o
和prog文件,例如:gcc main.o -o prog -g
但是当
objdump --prefix-addresses --show-raw-insn -Srl prog
要查看带有注释和符号的完整代码,I have many additional sections there,例如:
.init初始化
.plt公司
.text(是的,我知道,main在这里)[这里有很多部分:_start(),call_gmon_start(),u do_global_dtors_aux(),frame_dummy(),main(),u libc_csu_init(),u libc_csu fini(),u do_global_ctors_aux()]
.菲尼
我假设这些是gcc链接到运行库时引入的附加内容。我想我不需要所有的部分来调用c代码中的操作码(作者只使用这三部分),但是我的问题是我不知道我到底应该放弃哪些部分,哪些是必要的。我想这样使用它:
#include <unistd.h>
char code[] = "\x31\xed\x49\x89\x...x00\x00";
int main(int argc, char **argv)
{
/*creating a function pointer*/
int (*func)();
func = (int (*)()) code;
(int)(*func)();
return 0;
}
所以我创造了这个:
#include <unistd.h>
/*
*
*/
int main() {
char *shell[2];
shell[0] = "/bin/sh";
shell[1] = NULL;
execve(shell[0], shell, NULL);
return 0;
}
我按我说的做了拆卸。我试图使用.text main()中的操作码,这给了我分段错误,然后.text main()+另外.text _start(),结果相同。
那么,从上面的部分中选择什么,或者如何生成与三个部分一样最小化的“prog”?
最佳答案
你应该读这篇文章:http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html。
它详细地解释了创建非常小的程序所需的一切。
关于c - 如何获得C程序的最低可执行操作码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18456028/