gpt4 book ai didi

windows - 使用 NASM 编译 Windows 可执行文件

转载 作者:行者123 更新时间:2023-12-03 11:08:00 24 4
gpt4 key购买 nike

我想使用 NASM 编译 Win32 可执行文件,但我不知道怎么做。是否有任何必要的 header 告诉 Windows 此文件是可执行文件?

此外,谁能告诉我 Windows 如何知道这是一个表单应用程序还是一个控制台应用程序?

最佳答案

问题 1:

I wanted to compile Win32 executables using NASM, but I didn't know how.

编译:

nasm -f win32 测试.asm -o 测试.o

ld test.o -o test.exe

来源: http://ccm.net/faq/1559-compiling-an-assembly-program-with-nasm

问题 2:

Is there any necessary headers that tells Windows this file is executable?

文件扩展名表示一个可执行文件。通过读取此文件的 PE 文件结构,“Windows”能够获取正确加载和执行文件所需的所有信息。

问题 3:

Also, can anyone tell me how Windows know if this is a form application or a console application?

读这个:

On a more technical note, the only difference between a Console and a Windows executable is one byte in the PE header of the exe file. Toggling this byte manually (e.g. using a hex editor) converts the application type. This is a well-published hack that is used to create console applications in VB6 (where this type of application was not explicitly supported).

To determine and change the subsystem type of an application, you need to read parts of the PE header. The address of the subsystem data is not fixed though, because it's part of the optional file header whose position is determined by an address stored in the DOS file header (in the member e_lfanew). This address actually points to the _IMAGE_NT_HEADERS record which, in turn, includes the IMAGE_OPTIONAL_HEADER32 structure. This has an int161) member called Subsystem. The member's value is 2 for a Windows application and 3 for a console application. Other subsystems exist (in particular, POSIX and kernel). I've written a small VB6 application to change the subsystem of an application, which can be downloaded from ActiveVB as source code.

来源: Difference between Windows and Console application

关于windows - 使用 NASM 编译 Windows 可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33247785/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com