SHARE
TWEET

Untitled

a guest Nov 17th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define __NR_exit 60
  2. #define __NR_write 1
  3.  
  4. typedef long ssize_t;
  5. typedef unsigned long size_t;
  6.  
  7. int __attribute__((section("df323323f2"))) errno = 0;
  8.  
  9. const int looooool = 0;
  10.  
  11. static unsigned long
  12. errno_munge(unsigned long r)
  13. {
  14.     if ((long)r < 0 && (long)r > -4096) {
  15.         errno = -r;
  16.         return (unsigned long)-1;
  17.     } else {
  18.         return r;
  19.     }
  20. }
  21.  
  22. unsigned long
  23. _syscall1(int sysnr, unsigned long arg)
  24. {
  25.     unsigned long res;
  26.     asm ("syscall\n"
  27.          : "=a" (res)
  28.          : "0" (sysnr), "D" (arg)
  29.          : "memory");
  30.     return errno_munge(res);
  31. }
  32.  
  33. unsigned long
  34. _syscall3(int sysnr, unsigned long arg1, unsigned long arg2, unsigned long arg3)
  35. {
  36.     unsigned long res;
  37.     asm ("syscall\n"
  38.          : "=a" (res)
  39.          : "0" (sysnr), "D" (arg1), "S" (arg2), "d" (arg3)
  40.          : "memory");
  41.     return errno_munge(res);
  42. }
  43.  
  44. void
  45. exit(int code)
  46. {
  47.     _syscall1(__NR_exit, code);
  48. }
  49.  
  50. ssize_t
  51. write(int fd, const void *buf, size_t sz)
  52. {
  53.     return _syscall3(__NR_write, fd, (unsigned long)buf, sz);
  54. }
  55.  
  56. int
  57. main(int argc, char *argv[])
  58. {
  59.     write(1, "HELLO WORLD\n", sizeof("HELLO WORLD\n"));
  60.     return argc;
  61. }
  62.  
  63. void _start()
  64.     __asm__("pop %rdi");
  65.     __asm__("movq %rsp, %rsi");
  66.     __asm__("lea -8(%rsp),%rsp");
  67.     __asm__("call main");
  68.     __asm__("mov %rax, %rdi");
  69.     __asm__("call exit");
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top