如何手动编写和执行Windows .exe(使用十六进制编辑器的机器代码)? [英] How to write and executable Windows .exe manually (machine code with Hex editor)?

查看:138
本文介绍了如何手动编写和执行Windows .exe(使用十六进制编辑器的机器代码)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何仅使用十六进制编辑器编写像Hello World程序一样简单的内容.我知道我可以在接近机器的水平上使用汇编语言和汇编语言,但是我只想尝试在诸如Hello World这样的玩具示例中真正编写机器代码.

I'd like to know how is it possible to write something as simple as an Hello World program just by using an Hex Editor. I know that I could use an assembler and assembly language to this at a near machine level but I just want to experiment with really writing machine code in a toy example such as Hello World.

这可能是我可以在DOSBox上运行的简单DOS .COM文件.但是,如果有人可以提供一个.EXE文件的示例以直接在我的Windows PC上运行它,那就太好了.

This could be a simple DOS .COM file that I can run on DOSBox. But it would be nice if someone could provide an example for an .EXE file for running it directly on my Windows PC.

这仅仅是出于好奇.不.我不打算直接用二进制机器代码编写程序(我什至通常不编写汇编代码,大部分时间我只是使用C/C ++作为我最底层的工具).我只想看看是否有可能这样做,因为可能有人在计算机的早期就必须这样做.

This is just pure curiosity. No... I'm not thinking of writing programs directly in binary machine code (I don't even usually write assembly code, I just use C/C++ as my most low level tools most of the time). I just want to see if that's possible to do it, because probably someone had to do it in the very early days of computers.

P.S .: 我知道围绕此主题也有类似的问题,但没有一个提供有效的示例.我只想要一个简单的示例,以便可以帮助我理解编译器和汇编器如何生成可执行文件.我的意思是...过去某些程序最初一定是有人手工完成的.同样,对于Windows EXE格式,Microsoft必须有人编写了第一个工具来生成该格式以及Windows本身读取并执行该格式的方式.

P.S.: I know that there are similar questions about this topic around but none provide a working example. I just want a simple example so that it can help me understand how compilers and assemblers generate an executable file. I mean... someone must have done this by hand in the past for the very first programs. Also, for the Windows EXE format there must have been someone at Microsoft that wrote the first tools to generate the format and the way that Windows itself reads it and then executes it.

推荐答案

There's a quite minimalistic but fully working (on Win7, too) exe on corkami/wiki/PE101, every byte of it is explained in the nice graphic. You can type it all by hand in a hex editor, but the paddings may make that a little tedious.

关于历史,是的,Microsoft的某人发明了exe格式(旧的DOS MZ exe格式),然后他(或Microsoft的其他人)为其编写了一个加载程序和一个链接器,这通常使将编译器(目标文件")输出到可执行文件中.可能(甚至有可能,我会说)第一个exe程序是手工编写的,毕竟它们只是用于测试新的加载程序.

As for the history, yes someone at Microsoft invented the exe format (the old DOS MZ exe format) and he (or someone else at Microsoft) wrote a loader for it and a linker, which is the thing that traditionally turns the output of a compiler ("object files") into executable files. It's possible (and even likely, I would say) that the first exe programs were written by hand, after all they were only meant to test the new loader.

后来,Microsoft将AT& T的COFF格式扩展为PE格式,PE格式仍具有MZ头,并且通常(但可以选择不在corkami示例中,它可以是任何东西)包括一个小的DOS程序只是打印消息此程序无法在DOS模式下运行".

Later, AT&T's COFF format was extended by Microsoft to the PE format, which still has the MZ header and typically (but optionally, it's not in the corkami example, and it can be anything really) includes a small DOS program just to print the message "This program cannot be run in DOS mode".

这篇关于如何手动编写和执行Windows .exe(使用十六进制编辑器的机器代码)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆