本文介绍了如何使用十六进制编辑器在 Linux 中制作可执行的 ELF 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是好奇.这显然不是实际编程的一个很好的解决方案,但假设我想在 Bless(一个十六进制编辑器)中制作一个可执行文件.

Just curious. This obviously isn't a very good solution for actual programming, but say I wanted to make an executable in Bless (a hex editor).

我的架构是 x86.我可以制作什么非常简单的程序?你好世界?无限循环?类似于这个问题,但在Linux中.

My architecture is x86. What's a very simple program I can make? A hello world? An infinite loop? Similar to this question, but in Linux.

推荐答案

正如我在评论中提到的,您实际上将为可执行文件编写自己的 elf-header,以消除不需要的部分.还有几个必需的部分.Muppetlabs-TinyPrograms 上的文档很好地解释了这个过程.为了好玩,这里有几个例子:

As mentioned in my comment, you will essentially be writing your own elf-header for the executable eliminating the unneeded sections. There are still several required sections. The documentation at Muppetlabs-TinyPrograms does a fair job explaining this process. For fun, here are a couple of examples:

相当于/bin/true(45 字节):

00000000  7F 45 4C 46 01 00 00 00  00 00 00 00 00 00 49 25  |.ELF..........I%|
00000010  02 00 03 00 1A 00 49 25  1A 00 49 25 04 00 00 00  |......I%..I%....|
00000020  5B 5F F2 AE 40 22 5F FB  CD 80 20 00 01           |[_..@"_... ..|
0000002d

您的经典Hello World!"(160 字节):

00000000  7f 45 4c 46 01 01 01 03  00 00 00 00 00 00 00 00  |.ELF............|
00000010  02 00 03 00 01 00 00 00  74 80 04 08 34 00 00 00  |........t...4...|
00000020  00 00 00 00 00 00 00 00  34 00 20 00 02 00 28 00  |........4. ...(.|
00000030  00 00 00 00 01 00 00 00  74 00 00 00 74 80 04 08  |........t...t...|
00000040  74 80 04 08 1f 00 00 00  1f 00 00 00 05 00 00 00  |t...............|
00000050  00 10 00 00 01 00 00 00  93 00 00 00 93 90 04 08  |................|
00000060  93 90 04 08 0d 00 00 00  0d 00 00 00 06 00 00 00  |................|
00000070  00 10 00 00 b8 04 00 00  00 bb 01 00 00 00 b9 93  |................|
00000080  90 04 08 ba 0d 00 00 00  cd 80 b8 01 00 00 00 31  |...............1|
00000090  db cd 80 48 65 6c 6c 6f  20 77 6f 72 6c 64 21 0a  |...Hello world!.|
000000a0

不要忘记使它们可执行...

Don't forget to make them executable...

这篇关于如何使用十六进制编辑器在 Linux 中制作可执行的 ELF 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-11 09:44