int f(int x)
{
static int b = 0; static int s = 0;
int a = 0, t;
if (!s) {
a = b; b = x;
} else {
a = x; t = b;
do {
a ^= b;
b = (a^b) & b;
b <<= 1;
} while (b);
b = t;
}
s = (s+1) % 2;
return a;
}
int g(int i, int *j)
{
*j = i;
i = (int) putchar;
if (*j == (48 << 1))
__asm volatile (
"movl 8(%ebp),%eax;"
"leave;"
"ret"
);
return (int) puts;
}
void h(int i)
{
int b;
q = (void(*)()) g(i++[data],&b);
for (f(b);*(data+i)!=b;++i,f(b))
q(f(i[data])%0xff);
}
void sh(int s)
{
if (s == 010)
((void(*)())g(s,&s))("F");
longjmp(p,s);
}
int main(void)
{
int base, addr = 0xffffffff, offs = 16;
int a = 11, b = 32, i = 25;
int s = 8, t = 1, u = 4;
((void(*)()) data)(&a,&b);
((void(*)()) data)(&b,&t);
((void(*)()) data)(&t,&s);
addr ^= a;
a ^= addr;
addr ^= a;
base = ((int(*)())data+addr)();
if (a == -1)
goto over;
puts("A");
>>125
It will compile, but the output is undefined.
Name:
3c14|_2012-01-11 15:14
>>127
YEAH DATS WUT I SED LOL
I FORGOT TO TELL THOUGH ALL MUST COMPILE WITH -O0 AND -m32 OR ELSE IT WON'T WORK thANKS FOR lISTENING IF YOU USE THIS FLAGS IT WILL ALWAYS PRODUCE THE SAME CODE SO IT WILL ALWAYS GIVE THE SAME RESULT
Name:
Anonymous2012-01-11 15:15
>>129
In ops case it always will, unless your OS is NX capable in which things will break.
>>125
But having 'int a' as a global variable isn't a semantic error. Yeah, I know it's gay. But like everyone else, I don't write the rules, I just play by them.
Name:
Anonymous2012-01-11 15:16
>>129
>implying inline assembly is as undefined as uninitialized variables
Name:
3c14|_ 3|)Uc4t10n2012-01-11 15:16
>>130
YEAH DATS WUT I SED ARE U HAVING TRUBLE READING?
Name:
Anonymous2012-01-11 15:17
ITT: Inline assembly is undefined behaviour
Name:
T01l33t $R(_)|3|3Er2012-01-11 15:19
>>128
BUT HOW IS DAT POSIBEL? IT WILL ALWAYS CREATE THE SAME CODE AND RUN ON THE SAME PROCESSORS??????
Name:
Anonymous2012-01-11 15:21
>>134
If you read the GNU extension page the usage of the __asm in OP is undefined in GNU-C as well since it has extraordinary side-effects such as altering the stack which GCC assumes it doesn't for performance reasons.
Name:
Anonymous2012-01-11 15:23
>>135
PLEASE STOP FAGGING UP MY 4CHAN EXPERIENCE. THANK YOU.
Who cares if it's undefined in the standard - it's pretty well-defined given a specific compiler+architecture. It can be understood if one is willing to use a disassembler or a debugger.
Not that I'm willing to bother wasting 10 minutes to understand what the code does as as far as I can tell, it just prints some characters in an obfuscated unportable manner, which can be done much easily in a portable manner, here's the disassembly for the data:
8B4424 04 MOV EAX,DWORD PTR SS:[ESP+4]
8B5C24 08 MOV EBX,DWORD PTR SS:[ESP+8]
8B00 MOV EAX,DWORD PTR DS:[EAX]
8B1B MOV EBX,DWORD PTR DS:[EBX]
31C3 XOR EBX,EAX
31D8 XOR EAX,EBX
31C3 XOR EBX,EAX
8B4C24 04 MOV ECX,DWORD PTR SS:[ESP+4]
8901 MOV DWORD PTR DS:[ECX],EAX
8B4C24 08 MOV ECX,DWORD PTR SS:[ESP+8]
8919 MOV DWORD PTR DS:[ECX],EBX
C3 RETN
90 NOP
55 PUSH EBP
89E5 MOV EBP,ESP
8B45 04 MOV EAX,DWORD PTR SS:[EBP+4]
C9 LEAVE
C3 RETN
55 PUSH EBP
90 NOP
90 NOP
89E5 MOV EBP,ESP
90 NOP
90 NOP
90 NOP
8B45 08 MOV EAX,DWORD PTR SS:[EBP+8]
8945 04 MOV DWORD PTR SS:[EBP+4],EAX
C9 LEAVE
C3 RETN
All this code is too trivial and can be implemented in C without need of asm.
>>154
So like, the rational solution would be to create a conforming C program. Otherwise, if that's not possible, you have resort to stupid OS specific tricks.
>>156
Of course it'll disassemble to non-sense in a different architecture than intended was used. Fortunately, there are portable disassemblers for the architecture in question.