| View previous topic :: View next topic |
| Author |
Message |
Deltron Z Expert Cheater
Reputation: 1
Joined: 14 Jun 2009 Posts: 164
|
Posted: Sun Sep 26, 2010 4:40 pm Post subject: Small file size - Visual Studio |
|
|
I'm trying to make a small executable as possible, but visual studio is giving me a hard time doing so.
I've disabled runtime checks, stack cookies, eliminated unreferenced data, set optimization with favor small code, etc. but there are a few things I can't figure out.
First of all, the file generated contains "sort-of" junk code, it's some sort of initialization, calls to GetSystemTimeAsFileTime, GetTickCount, QueryPerformanceCounter, GetStartupInfo, GetCurrentProcessId, GetCurrentThreadId and such which I'm not planning to use in my program. I was wondering if there's any option that allows me to generate a small file that it's entry point is the main function, without any initializations, so whatever I write is whatever I get. I know I can edit the file or write the program in assembly, but I prefer writing it in C/C++.
I've also noticed that the program links to msvcxx.dll, depending on the visual studio version, which is the runtime library. I don't want to use the C-Runtime Library, even when I'm not using it my program links to something like 50 functions in it, and when I set the runtime library option to Multithreaded (/MT) the file size increases by 1000% (from a few KB to something between 30~70KB, it varies depending on the functions used), so I wonder how can I prevent visual studio from linking CRT to my program? I guess if I'll understand how to prevent from it adding "junk" initializations code to my program it'll answer this question as well...
|
|
| Back to top |
|
 |
smartz993 I post too much
Reputation: 2
Joined: 20 Jun 2006 Posts: 2013 Location: USA
|
Posted: Sun Sep 26, 2010 11:35 pm Post subject: |
|
|
Project Properties->Linker->Advanced->Entry Point - Set to whatever your main function is.
Compile in release mode.
tada.
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Mon Sep 27, 2010 9:27 am Post subject: |
|
|
Depending on how large your project is and what it uses function wise, you are going to start getting issues if you reset the entry point and use other tricks to force your executable to a smaller size.
Just use a packer and zip/rar/7zip/etc. your end result if you want a smaller executable in the end.
_________________
- Retired. |
|
| Back to top |
|
 |
Deltron Z Expert Cheater
Reputation: 1
Joined: 14 Jun 2009 Posts: 164
|
Posted: Mon Sep 27, 2010 10:05 am Post subject: |
|
|
| smartz993 wrote: | Project Properties->Linker->Advanced->Entry Point - Set to whatever your main function is.
Compile in release mode.
tada. |
I thought the entry point was the main function, that's weird.
I've created a 1KB program that pop-ups a message box. it can be reduced more, I guess, but that's enough.
Thanks.
The reason I don't want to use a packer is because I want to tamper the file and rebuild it, for example changing the message box's strings.
|
|
| Back to top |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Mon Sep 27, 2010 1:36 pm Post subject: |
|
|
| Deltron Z wrote: | | The reason I don't want to use a packer is because I want to tamper the file and rebuild it, for example changing the message box's strings. |
Then you might want to consider just writing the whole thing in asm.
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Mon Sep 27, 2010 3:03 pm Post subject: |
|
|
Don't count on using STL functions and keeping it tiny. msvcrt happens to be a system file though, so you can dynamically link against it.
Just keep in mind you'll need to create your own main function and handle the entry yourself. By default, your linker will look for mainCRTStartup (or WinMainCRTStartup)
You shouldn't run into issues if you stick purely to CRT functions and Win32 stuff.
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Tue Sep 28, 2010 12:43 pm Post subject: |
|
|
| /nodefaultlibs. Or ignore default libs as in written option in the linker preferences
|
|
| Back to top |
|
 |
|