Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a C++ EXE larger (artificially)

I want to make a dummy Win32 EXE file that is much larger than it should be. So by default a boiler plate Win32 EXE file is 80 KB. I want a 5 MB one for testing some other utilities.

The first idea is to add a resource, but as it turns out embedded resources are not the same as 5 MB of code when it comes to memory allocation. I am thinking I can reference a large library and end up with a huge EXE file? If not, perhaps scripting a few thousand similar methods like AddNum1, AddNum2, etc., etc.?

Any simple ideas are very appreciated.

like image 874
Phil Avatar asked Oct 01 '10 15:10

Phil


3 Answers

What about simply defining a large static char array?

char const bigarray[5*1024*1024] = { 1 };

See also my other answer in this thread where I suggest statically linking to big libraries. This surely will pull in real code if you just reference enough code of the libraries.

EDIT: Added a non-zero initialization, as data containing zeros only is treated in an optimized fashion by the compiler/linker.

EDIT: Added reference to my other answer.

EDIT: Added const qualifier, so bigarray will be placed amongst code by many compilers.

like image 129
Peter G. Avatar answered Sep 28 '22 02:09

Peter G.


char big[5*1024*1024] = {1};

You need to initialize it to something other than 0 or the compiler/linker may optimize it.

like image 30
Ferruccio Avatar answered Sep 28 '22 02:09

Ferruccio


If it's the file size you want to increase then append a text file to the end of the exe of the required size.

I used to do this when customers would complain of small exes. They didn't realize that small exes are just as professional as larger exes. In fact in some languages there is a bloat() command to increase the size of exes, usually in BASIC compilers.

EDIT: Found an old link to a piece of code that people use: http://www.purebasic.fr/english/viewtopic.php?f=12&t=38994

An example: https://softwareengineering.stackexchange.com/questions/2051/what-is-the-craziest-stupidest-silliest-thing-a-client-boss-asked-you-to-do/2698#2698

like image 22
Gary Willoughby Avatar answered Sep 28 '22 01:09

Gary Willoughby