Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Small file size - Visual Studio

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Deltron Z
Expert Cheater
Reputation: 1

Joined: 14 Jun 2009
Posts: 164

PostPosted: Sun Sep 26, 2010 4:40 pm    Post subject: Small file size - Visual Studio Reply with quote

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
View user's profile Send private message
smartz993
I post too much
Reputation: 2

Joined: 20 Jun 2006
Posts: 2013
Location: USA

PostPosted: Sun Sep 26, 2010 11:35 pm    Post subject: Reply with quote

Project Properties->Linker->Advanced->Entry Point - Set to whatever your main function is.

Compile in release mode.

tada.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Mon Sep 27, 2010 9:27 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Deltron Z
Expert Cheater
Reputation: 1

Joined: 14 Jun 2009
Posts: 164

PostPosted: Mon Sep 27, 2010 10:05 am    Post subject: Reply with quote

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. Rolling Eyes
I've created a 1KB program that pop-ups a message box. Smile it can be reduced more, I guess, but that's enough.
Thanks. Razz

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
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Mon Sep 27, 2010 1:36 pm    Post subject: Reply with quote

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
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Mon Sep 27, 2010 3:03 pm    Post subject: Reply with quote

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
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Tue Sep 28, 2010 12:43 pm    Post subject: Reply with quote

/nodefaultlibs. Or ignore default libs as in written option in the linker preferences
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites