A console application always spawns a console(it can detach an existing console using FreeConsole). A windows application, on the other hand, does not spawn a console. It can still attach to an existant console or create a new one using AllocaConsole
.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 locate the address of the subsystem data since it's part of the optional header whose position is dtermined by an address 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 int16 member called Subsystem.Subsystem = 2, Windows application
Subsystem = 3, Console application
沒有留言:
張貼留言