views:

786

answers:

3

As a precursor to writing a compiler I'm trying to understand the Windows (32-bit) Portable Executable format. In particular I'd like to see an example of a bare-bones executable which does nothing except load correctly, run and exit.

I've tried writing and compiling a simple C main function which does nothing but the resulting .exe is ~22KB and contains many imports from KERNEL32.DLL (presumably used by LIBC to set up environment, heaps etc.). Even the DOS Header could probably be smaller (it currently prints the default 'This program cannot be run in DOS mode').

What is the structure of the smallest possible Windows 32-bit executable?

Update: The smallest possible Windows EXE is 97 bytes and can be downloaded from here.

+10  A: 

This guy has written a good article. Too much to replicate here.

Nick Fortescue
Thanks for the upvote and accept when you'd just found it. You're a gentleman.
Nick Fortescue
+3  A: 

The seminal reference is to LibCTiny, a replacement for the normal C library. I've on a number of occasions built useful helper apps under 4KB with it.

MSalters
+1  A: 

Here is another link to a "tiny executable". It isn't as small as the tiniest exe version, but it does go through the process of how to shrink your executable footprint, using the VS tools and no hand ASM coding. It is a pretty good write up.

adahnert