Jump to content
Tuts 4 You

reduce exe size in visual studio


Dickyb0b

Recommended Posts

Posted (edited)

i cant seem to reduce my exe size that was built with VS 2010, ive followed many guides and everytime my file is 51kb and all it does is MessageBoxA


 


I have followed this guide from start to finish


 


http://linkyzer0.com/papers/Decrease_WinCppProject_FileSize.pdf


 


what am i doing wrong ?


Edited by Dickyb0b
Posted

Attached picture illustration, source, binary and msvc 2010 project to build small exe
MessageBox sample = 552 bytes
 

 

what am i doing wrong ?

 

Also, don't use MSVC common names like WinMain/Main as Entry.

makemesmall all.rar

  • Like 1
Posted

Some things you can do to alter the size of the exe:

- Use a different runtime. There are a handful of small runtimes for C/C++ you can find and use on the net instead of the MSVC runtime.

- Do not statically link to the runtime. (Requires the end-user of your application to have the needed runtime files already installed then.)

- Use a non-standard entry point as Insid3Code mentioned. (Keep in mind you may have to end up loading the runtime you use yourself if do this!)

- Avoid or limit the use of third-party libraries.

- Avoid statically linking to third-party libraries that you use. (Again you will need to distribute the .dll files needed for that lib then.)

- Avoid CRT specific functions. Use API calls instead. (For example memcpy can be done via an API with CopyMemory.)

- Adjust the compiler settings. (Optimizations and such can help reduce the code size if configured for it.)

- Merging sections can sometimes help reduce the size of your exe.

- Adjust the section alignment of the file.

- Avoid convenience libraries like MFC, wxWidgets and so on and code the UI via API by hand.

- Use some of the helper defines to remove header inclusion bloat (see below).

#define NOCOMM // Removes serial communication API includes and such.#define WIN32_LEAN_AND_MEAN // Removes various API such as cryptography, DDE, RPC, Shell, and Windows Sockets.#define VC_EXTRALEAN // Defines both the above definitions as well as a ton more.
Posted

 

- Adjust the section alignment of the file.

 

I forgot to mention that changing alignment produce a binary that will not work if:

Launch 32bit binary on X64 system = Fail

Launch 32bit binary on X86 system = Work

 

Launch 64bit binary on X64 system = Work

 

 

Also, trying to reduce a binary a bit exaggerated can lead to a false positive AV detection.

Posted

#define NOCOMM/WIN32_LEAN_AND_MEAN/VC_EXTRALEAN are there to improve build speed times -  they will not make an .exe any larger/smaller.Also, the c++ compiler will add an unneccessary xor eax, eax after the MessageBox call in insidecode's example. In other compilers you can use void main() instead of int main() to get rid of that, but not VS. Remove that and adjust the file will decrease another whole TWO BYTES !!!!! More practical to just use a C compiler though.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...