Making Tiny Executable

Generating custom "msvcrt.lib"

Step 1. Check if "C:\Windows\System32\msvcrt.dll" exists

Step 2. Move "msvcrt.dll" to "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin"

Step 3. Run dumpbin.exe as administrator

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin> dumpbin /exports msvcrt.dll > msvcrt.exp

Step 4. "msvcrt.exp" is newly created.

Step 5. Open "msvcrt.exp" with notepad and look for a low where no value exists in RVA column

Step 6. Fill the empty space with any value and remove header and footer of data table.

Step 7. Save "msvcrt.exp"

Step 8. Run Python script to create "msvcrt.def" file

import time
fdef = open("msvcrt.def", "w")
fdef.write("EXPORT\n")
with open("msvcrt.exp", "r") as fexp:
	while True:
		line = fexp.readline()
		if len(line) == 0:
			break;
		tokens = line.split()
		fdef.write(tokens[3] + "\n")
close(fexp)
close(fdef)

Step 9. "msvcrt.def" is newly created.

Step 10. Run lib.exe

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin> lib /def:msvcrt.def /out:custom_msvcrt.lib /machine:x86

Step 11. "custom_msvcrt.lib" is newly created.

Step 12. Link "custom_msvcrt.lib" with your project

  • Project Property Pages > Configuration Properties > Linker > Input > Additional Dependencies:
    Remove all libs except "kernel32.lib" and add "custom_msvcrt.lib"
  • Project Property Pages > Configuration Properties > Linker > Input > Ignore All Default Libraries:
    Set "Yes (/NODEFAULTLIB)"