使用 NASM 编译 windows 个可执行文件

Compile windows executables with NASM

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

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

问题一:

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

编译:

nasm -f win32 test.asm -o test.o

ld test.o -o test.exe

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

问题二:

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

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

问题三:

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