Jump to content
Tuts 4 You

Archived

This topic is now archived and is closed to further replies.

Zer0Flag

Reduce your C++ executable size

Recommended Posts

Zer0Flag

Hello All,

I wrote a little paper about reducing the file size of a cpp project. Covers some basic stuff like removing cruntime, merging sections etc.. Hope it helps someone and of course if you have improvements, other techniques or found bugs then feel free to write me.

~Zer0Flag

Decrease_WinCppProject_FileSize.pdf

Share this post


Link to post
Share on other sites
Aguila

I have bookmarked this thread: http://forum.tuts4you.com/topic/20209-msvc2008-removing-msvc-framework-code/

There is some more information.

What I learned: Using "pragma"s to tweak the output file is much better, because you can combine it with DEFINES. You can fast switch it on or off -> useful for debugging because sometimes this causes some problems.

Share this post


Link to post
Share on other sites
atom0s

Just a heads up with your PDF; the option to choose between Multithreaded-DLL and Multithreaded are not present in Express editions of Visual Studio. This is a non-free feature that is only present in the paid versions.

Share this post


Link to post
Share on other sites
accede

Your us /O1 or /O2 i see but if your us /Oxs=Full optimation + small code it makes the result are littel bit more smaller.

If your us the command line tools like (cl,link,lib) your can make the result very small.

Her an bsp:


cl /c /Oxs /W3 mrcore.c
cl /c /Oxs /W3 mrarth0.c
cl /c /Oxs /W3 mrarth1.c
cl /c /Oxs /W3 mrarth2.c
cl /c /Oxs /W3 mralloc.c
cl /c /Oxs /W3 mrsmall.c
cl /c /Oxs /W3 mrio1.c
cl /c /Oxs /W3 mrio2.c
cl /c /Oxs /W3 mrgcd.c
cl /c /Oxs /W3 mrjack.c
cl /c /Oxs /W3 mrxgcd.c
cl /c /Oxs /W3 mrarth3.c
cl /c /Oxs /W3 mrbits.c
cl /c /Oxs /W3 mrrand.c
cl /c /Oxs /W3 mrprime.c
cl /c /Oxs /W3 mrcrt.c
cl /c /Oxs /W3 mrscrt.c
cl /c /Oxs /W3 mrmonty.c
cl /c /Oxs /W3 mrpower.c
cl /c /Oxs /W3 mrsroot.c
cl /c /Oxs /W3 mrcurve.c
cl /c /Oxs /W3 mrfast.c
cl /c /Oxs /W3 mrlucas.c
cl /c /Oxs /W3 mrzzn2.c
cl /c /Oxs /W3 mrzzn2b.c
cl /c /Oxs /W3 mrzzn3.c
cl /c /Oxs /W3 mrzzn4.c
cl /c /Oxs /W3 mrshs.c
cl /c /Oxs /W3 mrshs256.c
cl /c /Oxs /W3 mrshs512.c
cl /c /Oxs /W3 mraes.c
cl /c /Oxs /W3 mrgcm.c
cl /c /Oxs /W3 mrstrong.c
cl /c /Oxs /W3 mrbrick.c
cl /c /Oxs /W3 mrebrick.c
cl /c /Oxs /W3 mrgf2m.c
cl /c /Oxs /W3 mrec2m.c
cl /c /Oxs /W3 mrecn2.c
cl /c /Oxs /W3 mrflash.c
cl /c /Oxs /W3 mrfrnd.c
cl /c /Oxs /W3 mrdouble.c
cl /c /Oxs /W3 mrround.c
cl /c /Oxs /W3 mrbuild.c
cl /c /Oxs /W3 mrflsh1.c
cl /c /Oxs /W3 mrpi.c
cl /c /Oxs /W3 mrflsh2.c
cl /c /Oxs /W3 mrflsh3.c
cl /c /Oxs /W3 mrflsh4.c
cl /c /Oxs /W3 mrkcm.c
cl /c /Oxs /W3 mrcomba2.c
copy mrmuldv.w64 mrmuldv.c
cl /c /Oxs /W3 mrmuldv.c

The result for this is about 361kb for the lib.

If your make the same with vc with out the command line tools your get for the same lib this result:

1 - 2 mb

Share this post


Link to post
Share on other sites
R4ndom

I had been working on a tutorial for this very subject for a couple weeks now, and after seeing your article (which is very good, btw) I decided to finish mine. It is more detailed than yours (I wanted to see how the various options affected the actual disassembly in OllyDBG) and the pictures have been translated to English. Hope you enjoy...


/>http://thelegendofrandom.com/blog/archives/2231

Share this post


Link to post
Share on other sites
hmi222

@Zer0Flag

Thanx for this excellent tutorial.

Will test in detail.

Btw. did yu test to use crinkler with the shrinked exe?

Share this post


Link to post
Share on other sites
Zer0Flag

@hmi222

Thanks, no I didnĀ“t test any packer to see if it get even smaller. Since the goal of this was to show how you can decrease the file size using compiler and linker settings. But you can use ASM to shrink it until you reach 92bytes or something. If you are interested in this you should take a look in google for "tiny pe".

~Zer0Flag

Share this post


Link to post
Share on other sites

×