Advertisement
enfiskutensykkel

Obscure

Oct 1st, 2013
2,135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.59 KB | None | 0 0
  1. /*
  2.  * Tested with Intel Atom, Core 2 Duo, Core 2 Quad, Xeon and AMD Athlon 64 X2
  3.  * Tested with gcc4.1.2 gcc4.4.3, gcc4.4.1, gcc4.4.5 and gcc4.6.1
  4.  * Compile with: gcc -O0 -m32
  5.  *
  6.  * Relies on compiler specific behaviour (casting from object pointer to
  7.  * function pointer), which is undefined in standard C, but GCC does it
  8.  * anyway. It also relies on architecture specifics (IA-32/x86), and is
  9.  * generally "bad" C. Does not work with any other compiler than GCC.
  10.  *
  11.  * OSes that doesn't support POSIX signals or OSes that support NX won't
  12.  * be able to run this.
  13.  */
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <signal.h>
  17. #include <setjmp.h>
  18. #define k putchar
  19. jmp_buf p;
  20. void h(int);
  21. void (*q)();
  22.  
  23. const char *data =
  24.         "\x8b\x44\x24\x04\x8b\x5c\x24\x08"
  25.         "\x8b\x00\x8b\x1b\x31\xc3\x31\xd8"
  26.         "\x31\xc3\x8b\x4c\x24\x04\x89\x01"
  27.         "\x8b\x4c\x24\x08\x89\x19\xc3\x90"
  28.         "\x55\x89\xe5\x8b\x45\x04\xc9\xc3"
  29.         "\x55\x90\x90\x89\xe5\x90\x90\x90"
  30.         "\x8b\x45\x08\x89\x45\x04\xc9\xc3"
  31.         "\x60\xe8\x05\x0c\x0c\x0f\xcc\xc0"
  32.         "\x17\x0f\x12\x0c\x04\xc1\x60\x00"
  33.         "\x20\x47\x4f\x54\x4f\x00\x43\x4f"
  34.         "\x4e\x53\x49\x44\x45\x52\x45\x44"
  35.         "\x00\x48\x41\x52\x4d\x46\x55\x4c"
  36.         "\x20\x00\x69\x6e\x73\x74\x61\x6c"
  37.         "\x6c\x20\x67\x65\x6e\x74\x6f\x6f";
  38.  
  39. int f(int x)
  40. {
  41.         static int b = 0, s = 0;
  42.         int a = 0, t;
  43.         if (!s) {
  44.                 a = b; b = x;
  45.         } else {
  46.                 a = x; t = b;
  47.                 do {
  48.                         a ^= b;
  49.                         b = (a^b) & b;
  50.                         b <<= 1;
  51.                 } while (b);
  52.                 b = t;
  53.         }
  54.         s = (-~s) & 1;
  55.         return a;
  56. }
  57.  
  58. int g(int i, int *j)
  59. {
  60.         asm volatile (
  61.                         "movl %0,%%eax;"
  62.                         "movl %%eax,%3;"
  63.                         "movl %1,%%eax;"
  64.                         "movl %%eax,%2"
  65.                         : "=r" (i), "=r" (*j)
  66.                         : "r" (i), "r" (&k)
  67.                         : "%eax" );
  68.         if (*j == (1<<3))  
  69.                 asm volatile (
  70.                                 "movl %0,%%eax;"
  71.                                 "movl %%eax,%1;"
  72.                                 : "=r" (i)
  73.                                 : "r" (&h)
  74.                                 : "%eax" );
  75.         return i;
  76. }
  77.  
  78. void h(int i)
  79. {
  80.         int b; q = (void(*)()) g(i++[data], &b);
  81.         for (f(b); *(data+i) != b; ++i, f(b))
  82.                 q(f(i[data]) % 255);
  83.         q((f(b) & ~255) | 10);
  84. }
  85.  
  86. void sh(int s)
  87. {
  88.         if (s == 010)
  89.                 ((void(*)())g(s,&s))(0110); longjmp(p,s);
  90.         longjmp(p,11);
  91. }
  92.  
  93. int main()
  94. {
  95.         int base, addr = 0xffffffff, offs = 16;
  96.         int a = 11, b = 32, s = 8, t = 1, u = 4;
  97.         signal(a,sh); signal(u,sh);
  98.         signal((a+t)/2,sh); signal(s+t,sh);
  99.         if (setjmp(p)) goto end;
  100.  
  101.         q = (void(*)()) data;
  102.         q(&a,&b); q(&b,&t); q(&t,&s);
  103.         a^=addr; addr^=a; a^=addr;
  104.         base = ((int(*)()) (q+addr))();
  105.  
  106.         if (a == -1) goto label;
  107.         base = (1<<3) | ((f(addr) + f(offs)) & ~0xff);
  108.         h(base+addr+offs);
  109.         exit(0);
  110.  
  111. label:
  112.         signal(t,sh);
  113.  
  114.         if ((s = setjmp(p)) == t)
  115.                 ((int(*)(int)) (data+addr+(offs/2)))(base);
  116.         else if (!s) {
  117.                 g(0x30, a == -1 ? &a : &b);
  118.                 s = a / (b-1);
  119.                 puts(&(0142)[data]);
  120.                 *((int*) 0x0) = 0xffffffff;
  121.         }
  122.  
  123.         puts("ewd does not approve!");
  124. end: exit(1);
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement