 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Tue Jul 10, 2007 12:26 am Post subject: Quick C++ question, involving linkers, porn and whores. |
|
|
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 |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Tue Jul 10, 2007 9:38 am Post subject: |
|
|
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!
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 |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Tue Jul 10, 2007 10:29 am Post subject: |
|
|
| 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!  |
I'll be sure to look into doing that, as it sounds like a good solution. 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 |
|
 |
|
|
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
|
|