Dickyb0b Posted March 1, 2015 Posted March 1, 2015 (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 March 1, 2015 by Dickyb0b
Insid3Code Posted March 1, 2015 Posted March 1, 2015 Attached picture illustration, source, binary and msvc 2010 project to build small exeMessageBox sample = 552 bytes what am i doing wrong ? Also, don't use MSVC common names like WinMain/Main as Entry.makemesmall all.rar 1
atom0s Posted March 1, 2015 Posted March 1, 2015 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.
Insid3Code Posted March 2, 2015 Posted March 2, 2015 - 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.
simple Posted March 3, 2015 Posted March 3, 2015 #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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now