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 


Quick C++ question, involving linkers, porn and whores.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Tue Jul 10, 2007 12:26 am    Post subject: Quick C++ question, involving linkers, porn and whores. Reply with quote

I've seen examples of stupidly small C++ programs, that seemingly abuse the linker settings.

Curious I look and find something boasting a mere 1kb size. All it is, is a simple messagebox and it the linker gets this.

/FILEALIGN:512 /MERGE:.data=.text /MERGE:.rdata=.text /SECTION:.text,EWR /IGNORE:4078

I get what it does, but... what's the catch? What bad can come from fucking with this shit?

edit: woop

did my research and it seems that the program incorporates necessary parts of the c runtime library into the .exe, aka static linking. We can use our own function however to bypass this, but doing so we miss out on some things like fopen and you have to use the Win32 api to get around it. All in all, my exe size went from 48, to 3 and rars to a mere 768 bytes. So while dicking with the linker settings can shave off a few KB's, a good bit of bloat comes from this.

It's easy to do too.
Back to top
View user's profile Send private message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Tue Jul 10, 2007 9:38 am    Post subject: Reply with quote

well without the RT it's just like writing an assembly program. you can even get to 1.0 kb (minimum PE size) with /O1 if you really care.

I don't use any of those settings, you don't need a static C runtime either, just link to the msvcrt.lib that comes with MASM and whenever you call a C runtime function it imports it from msvcrt.dll, there goes all of the bloat! Very Happy

oh and you have to write your own main, but that's real easy.

merging sections is bad, they're seperate for a reason (different permissions, ex: data can be read/written but not executed, code can be executed but not read/written...)
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Tue Jul 10, 2007 10:29 am    Post subject: Reply with quote

appalsap wrote:
I don't use any of those settings, you don't need a static C runtime either, just link to the msvcrt.lib that comes with MASM and whenever you call a C runtime function it imports it from msvcrt.dll, there goes all of the bloat! Very Happy


I'll be sure to look into doing that, as it sounds like a good solution. Smile Thanks for all the info.

...and it sure is nice to be able to use the Win32 api without having to jump through hoops like you have to in .NET.
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