Advertisement
Guest User

Untitled

a guest
Sep 1st, 2014
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
GDB 1.02 KB | None | 0 0
  1. section .data
  2.         msg db 'Anus!', 0x0A
  3.         file db 'anus_out'
  4.  
  5. section .text
  6.         global _start
  7.  
  8. _start:
  9.         ;; SYS_OPEN
  10.         mov rax, 2    ; System call, sys_open
  11.         mov rdi, file ; 1st arg, filename
  12.         mov rsi, 1    ; 2nd arg, flag: O_WRONLY
  13.         mov rdx, 0    ; 3rd arg, mode NULL
  14.         syscall
  15.  
  16.         ;; Jump if failed      
  17.         cmp rax, 0
  18.         jng _open_fail
  19.  
  20.         mov rbx, rax  ; Store the fd
  21.  
  22.         ;; SYS_WRITE
  23.         mov rax, 1    ; System call, sys_write
  24.         mov rdi, rbx  ; 1st arg, writing fd
  25.         mov rsi, msg  ; 2nd arg, message
  26.         mov rdx, 6    ; 3rd arg, length
  27.         syscall
  28.  
  29.         ;; Jump if failed
  30.         cmp rax, 0
  31.         jng _write_fail
  32.  
  33.         ;; SYS_CLOSE
  34.         mov rax, 3
  35.         mov rdi, rbx
  36.         syscall
  37.  
  38.         mov rdi, 0
  39.         jmp _exit
  40.  
  41. _open_fail:
  42.         mov rdi, -1
  43.         jmp _exit
  44.  
  45. _write_fail:
  46.         mov rdi, -2
  47.         jmp _exit
  48.  
  49. _exit:
  50.         mov rax, 60
  51.         syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement