• Welcome to Valhalla Legends Archive.
 

lockdown source

Started by Rob, July 30, 2007, 12:44 AM

Previous topic - Next topic

brew

Quote from: Yegg on August 02, 2007, 10:42 AM
What is the purpose of i ^= i? Why not just i = 0?
Because it's more efficient then MOV (takes 7 less cpu cycles) and it doesn't have to store a constant value of 0.
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

Yegg

That depends on the compiler you're using. I created some binary files from a simple C source I just wrote:

int main () {
    int i;

    i ^= i;
}


produces

00000000  8D4C2404          lea ecx,[esp+0x4]
00000004  83E4F0            and esp,byte -0x10
00000007  FF71FC            push dword [ecx-0x4]
0000000A  55                push ebp
0000000B  89E5              mov ebp,esp
0000000D  51                push ecx
0000000E  83EC10            sub esp,byte +0x10
00000011  C745F800000000    mov dword [ebp-0x8],0x0
00000018  83C410            add esp,byte +0x10
0000001B  59                pop ecx
0000001C  5D                pop ebp
0000001D  8D61FC            lea esp,[ecx-0x4]
00000020  C3                ret


and

int main () {
    int i;

    i = 0;
}


produces

00000000  8D4C2404          lea ecx,[esp+0x4]
00000004  83E4F0            and esp,byte -0x10
00000007  FF71FC            push dword [ecx-0x4]
0000000A  55                push ebp
0000000B  89E5              mov ebp,esp
0000000D  51                push ecx
0000000E  83EC10            sub esp,byte +0x10
00000011  C745F800000000    mov dword [ebp-0x8],0x0
00000018  83C410            add esp,byte +0x10
0000001B  59                pop ecx
0000001C  5D                pop ebp
0000001D  8D61FC            lea esp,[ecx-0x4]
00000020  C3                ret


You'll notice the two are identical. Perhaps there is some optimization argument gcc should be given?

brew

Wow, that's pretty gay. Some optimization that is. From now on i'm going to turn off optimizations for Visual C++. Is this a good idea?
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

Yegg

I don't know much about Visual C++. It sounds like a good idea to keep the optimizations on unless you're a pretty advanced guru with the language and software.

iago

Optimizing C code like that is almost always stupid. If you're going to do that, you'd might as well start expanding your loops out.

Seriously, let the compiler/optimizer do what it's good for.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Antarctica

Anything that will work for vb6?

UserLoser

Quote from: iago on August 02, 2007, 02:45 PM
Optimizing C code like that is almost always stupid. If you're going to do that, you'd might as well start expanding your loops out.

Seriously, let the compiler/optimizer do what it's good for.

Newby

Quote from: brew on August 02, 2007, 01:48 PM
Wow, that's pretty gay. Some optimization that is. From now on i'm going to turn off optimizations for Visual C++. Is this a good idea?

You motherfucker, I thought I had posted today because I use this avatar in other places. You confused me you bastard.
- Newby

Quote[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

Quote<TehUser> Man, I can't get Xorg to work properly.  This sucks.
<torque> you should probably kill yourself
<TehUser> I think I will.  Thanks, torque.

brew

Quote from: Newby on August 02, 2007, 06:18 PM
Quote from: brew on August 02, 2007, 01:48 PM
Wow, that's pretty gay. Some optimization that is. From now on i'm going to turn off optimizations for Visual C++. Is this a good idea?
You motherfucker, I thought I had posted today because I use this avatar in other places. You confused me you bastard.
....huh...?

Quote
Seriously, let the compiler/optimizer do what it's good for.
I say its not doing it's job good enough.
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

l2k-Shadow

How come you're using while (i < 5) i thought you said != is way more efficient.

I know you feel all leet coding in C and everything but let it go man, little things like these make no difference, let the compiler do it's work.
Quote from: replaced on November 04, 2006, 11:54 AM
I dunno wat it means, someone tell me whats ix86 and pmac?
Can someone send me a working bot source (with bnls support) to my email?  Then help me copy and paste it to my bot? ;D
Já jsem byl určenej abych tady žil,
Dával si ovar, křen a k tomu pivo pil.
Tam by ses povídaj jak prase v žitě měl,
Já nechci před nikym sednout si na prdel.

Já nejsem z USA, já nejsem z USA, já vážně nejsem z USA... a snad se proto na mě nezloběj.

Yegg

Quote from: l2k-Shadow on August 02, 2007, 07:16 PM
How come you're using while (i < 5) i thought you said != is way more efficient.

I know you feel all leet coding in C and everything but let it go man, little things like these make no difference, let the compiler do it's work.

Don't always just "let the compiler do the work".  It's educational to learn how certain parts of the compiler are actually done. brew, don't expect that those kinds of small details will improve your applications at all, because typically they won't, but it's still fun to learn little things like that. Look more into it.

raylu

Quote from: l2k-Shadow on August 02, 2007, 07:16 PM
How come you're using while (i < 5) i thought you said != is way more efficient.

I know you feel all leet coding in C and everything but let it go man, little things like these make no difference, let the compiler do it's work.
Of course! There is no middleground between pure ASM and...well, every time I think I've seen the worst solution possible, I learn something new...but you get the point.
Pie?

brew

Quote from: raylu on August 02, 2007, 08:47 PM
Quote from: l2k-Shadow on August 02, 2007, 07:16 PM
How come you're using while (i < 5) i thought you said != is way more efficient.

I know you feel all leet coding in C and everything but let it go man, little things like these make no difference, let the compiler do it's work.
Of course! There is no middleground between pure ASM and...well, every time I think I've seen the worst solution possible, I learn something new...but you get the point.
eh... MASM
I don't feel very leet coding in C...
But now when I go back to finish a project in VB i'm totally disgusted at how dumbed down it is.
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

Kp

That assembly looks grossly unoptimized.  I could have done that in two instructions:
xor eax, eax
ret


brew: considering how concerned you are about manual optimization, I find it a little surprising you have not even considered security.  Read up about buffer overflows, look at how many patches Microsoft has to issue because their programmers do not understand buffer overflows, then look at your code again.  If you still think it is OK, then I will pick it apart and explain what is wrong.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

iago

Quote from: Yegg on August 02, 2007, 08:29 PM
Don't always just "let the compiler do the work".  It's educational to learn how certain parts of the compiler are actually done. brew, don't expect that those kinds of small details will improve your applications at all, because typically they won't, but it's still fun to learn little things like that. Look more into it.
The problem is, if you make your code less readable but execute a fraction of no time faster, you lose. You're typically better off keeping your code readable rather than efficient.

That being said, efficient algorithms are important. If you bubblesort/insertionsort 100000000 items or quicksort/shellsort 100000000 items, it matters very little whether each instruction is fast or slow, the quicksort will always be faster. Algorithm choice is important in many cases.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


|