Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Tested with Intel Atom, Core 2 Duo, Core 2 Quad, Xeon and AMD Athlon 64 X2
- * Tested with gcc4.1.2 gcc4.4.3, gcc4.4.1, gcc4.4.5 and gcc4.6.1
- * Compile with: gcc -O0 -m32
- *
- * Relies on compiler specific behaviour (casting from object pointer to
- * function pointer), which is undefined in standard C, but GCC does it
- * anyway. It also relies on architecture specifics (IA-32/x86), and is
- * generally "bad" C. Does not work with any other compiler than GCC.
- *
- * OSes that doesn't support POSIX signals or OSes that support NX won't
- * be able to run this.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <signal.h>
- #include <setjmp.h>
- #define k putchar
- jmp_buf p;
- void h(int);
- void (*q)();
- const char *data =
- "\x8b\x44\x24\x04\x8b\x5c\x24\x08"
- "\x8b\x00\x8b\x1b\x31\xc3\x31\xd8"
- "\x31\xc3\x8b\x4c\x24\x04\x89\x01"
- "\x8b\x4c\x24\x08\x89\x19\xc3\x90"
- "\x55\x89\xe5\x8b\x45\x04\xc9\xc3"
- "\x55\x90\x90\x89\xe5\x90\x90\x90"
- "\x8b\x45\x08\x89\x45\x04\xc9\xc3"
- "\x60\xe8\x05\x0c\x0c\x0f\xcc\xc0"
- "\x17\x0f\x12\x0c\x04\xc1\x60\x00"
- "\x20\x47\x4f\x54\x4f\x00\x43\x4f"
- "\x4e\x53\x49\x44\x45\x52\x45\x44"
- "\x00\x48\x41\x52\x4d\x46\x55\x4c"
- "\x20\x00\x69\x6e\x73\x74\x61\x6c"
- "\x6c\x20\x67\x65\x6e\x74\x6f\x6f";
- int f(int x)
- {
- static int b = 0, 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;
- return a;
- }
- int g(int i, int *j)
- {
- asm volatile (
- "movl %0,%%eax;"
- "movl %%eax,%3;"
- "movl %1,%%eax;"
- "movl %%eax,%2"
- : "=r" (i), "=r" (*j)
- : "r" (i), "r" (&k)
- : "%eax" );
- if (*j == (1<<3))
- asm volatile (
- "movl %0,%%eax;"
- "movl %%eax,%1;"
- : "=r" (i)
- : "r" (&h)
- : "%eax" );
- return i;
- }
- 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]) % 255);
- q((f(b) & ~255) | 10);
- }
- void sh(int s)
- {
- if (s == 010)
- ((void(*)())g(s,&s))(0110); longjmp(p,s);
- longjmp(p,11);
- }
- int main()
- {
- int base, addr = 0xffffffff, offs = 16;
- int a = 11, b = 32, s = 8, t = 1, u = 4;
- signal(a,sh); signal(u,sh);
- signal((a+t)/2,sh); signal(s+t,sh);
- if (setjmp(p)) goto end;
- q = (void(*)()) data;
- q(&a,&b); q(&b,&t); q(&t,&s);
- a^=addr; addr^=a; a^=addr;
- base = ((int(*)()) (q+addr))();
- if (a == -1) goto label;
- base = (1<<3) | ((f(addr) + f(offs)) & ~0xff);
- h(base+addr+offs);
- exit(0);
- label:
- signal(t,sh);
- if ((s = setjmp(p)) == t)
- ((int(*)(int)) (data+addr+(offs/2)))(base);
- else if (!s) {
- g(0x30, a == -1 ? &a : &b);
- s = a / (b-1);
- puts(&(0142)[data]);
- *((int*) 0x0) = 0xffffffff;
- }
- puts("ewd does not approve!");
- end: exit(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement