0

I recently tried to create the absolutely minimum sized binary in C with VC++.

To accomplish this I removed the C runtime library support in the settings and used this instead of the regular old main with the CRT setup that comes before it.

This is my source file:

int WinMainCRTStartup() {
return 0;
}

I also went around and removed anything that I could find that injected anything inside the outputted binary. There were a few things that I didn't understand why they were there.

This is the output:

MZ..................... @...................... ....................... !..L.!This program cann t be run in DOS mode... $.............d...d...d ..l...d...f...d.Rich..d ....................... PE..L......X.........." ....................... . ....@................ .........0............@ ....................... ....................... ....................... . ..p.................. ....................... ....................... .........text.......... .................... .. .rdata....... ......... ............@..@....... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ................3...... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ....................... .......X........Q...p . p..........X........... . .............X....... @.... .............X... ................RSDS.. ?..N............C:\Users\vlind\Desktop\minimumexe\Release\minimumexe.pd ....................... GCTL.........text$mn... . ..p....rdata..p ..... .rdata$zzzdbg.......... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ....................... ........

I'm really interested in knowing what's exactly inside this executable and why. And what is the purpose of each part. What is .rdata for example? Why is there a path to a .pd file?...

I'll dump the linker flags and compiler flags as well if anyone happens to need them to answer the question.

Compiler:

/GS- /TC /GL /analyze- /W4 /Gy /Zc:wchar_t /Zi /Gm- /O2 /Ob2 /Fd"Release\vc140.pdb" /Zc:inline /fp:fast /D "_MBCS" /errorReport:prompt /WX- /Zc:forScope /Gd /Oy- /Oi /MD /Fa"Release\" /nologo /Fo"Release\" /C /Fp"Release\minimumexe.pch"

Linker:

/OUT:"C:\Users\vlind\Desktop\minimumexe\Release\minimumexe.exe" /MANIFEST:NO /LTCG:incremental /NXCOMPAT /HEAP:"0"",0" /PDB:"C:\Users\vlind\Desktop\minimumexe\Release\minimumexe.pdb" /DYNAMICBASE "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /LARGEADDRESSAWARE /DEBUG /LTCG:STATUS /MACHINE:X86 /WINMD:NO /OPT:REF /SAFESEH:NO /PGD:"C:\Users\vlind\Desktop\minimumexe\Release\minimumexe.pgd" /SUBSYSTEM:WINDOWS /MANIFESTUAC:NO /OPT:ICF /ERRORREPORT:PROMPT /CLRUNMANAGEDCODECHECK:NO /NOLOGO /VERBOSE /NODEFAULTLIB /TLBID:1

vlind
  • 629
  • 6
  • 16
  • 1
    Read [this](https://msdn.microsoft.com/en-us/library/ms809762.aspx) *Inside a PE32 Executable*. – t0mm13b Nov 05 '16 at 15:29
  • Possible duplicate of [How is code stored in the EXE format?](http://stackoverflow.com/questions/14630852/how-is-code-stored-in-the-exe-format) – Marcus Müller Nov 05 '16 at 15:29
  • 1
    For starters, try getting rid of your `/Zi` and `/DEBUG` flags. Those generate debug info, which you're sticking in some PDB/PGD, which it looks like the path to those files are being stored in your .exe. – Cornstalks Nov 05 '16 at 15:34
  • Did you try to use `strip.exe` a MinGW tool to reduce the size of your exe ? – J. Piquard Nov 05 '16 at 16:41

0 Answers0