How can I create an executable .exe PE file manually?

后端 未结 7 1411
谎友^
谎友^ 2021-01-30 22:48

All texts on how to create a compiler stop after explaining lexers and parsers. They don\'t explain how to create the machine code. I want to understand the end-to-end process.<

相关标签:
7条回答
  • 2021-01-30 23:49

    Nice question! I don't have much expertise on this specific question, but this is how I would start:

    1. PE or ELF does not create pure machine code. It also contains some header info etc. Read more: Writing custom data to executable files in Windows and Linux

    2. I assume you are looking for how does ELF/PE file hold the machine code, you can get that from this question (using objdump): How do you extract only contents of an ELF section

    3. Now, if you want to know how the content part is generated in the first place, i.e. how is the machine code generated, then that's the task of the compiler's code generation.

    4. Try out some resource editor like ResourceEditor to understand the exe or simply ildasm.

    PS: These are mostly Unix solutions, but I am sure, PE should be doing something fundamentally similar.

    I think the best way to approach it will be first try to analyze how existing PE/ELFs work, basically reverse engineering. And to do that, Unix machine will be a good point to start. And then do your magic :)

    Not same but a similar question here.

    Update:

    I generated an object dump out of a sample c code. Now, I assume that's what you are targeting right? You need to know do you generate this file (a.out)?

    https://gist.github.com/1329947

    Take a look at this image, a life time of a c code.

    enter image description here

    Source Now, just to be clear, you are looking to implement the final step, i.e. conversion of object code to executable code?

    0 讨论(0)
提交回复
热议问题