Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. _start:
  2. xor eax, eax
  3. xor ebx, ebx
  4. xor ecx, ecx
  5. xor edx, edx
  6.  
  7. jmp two
  8.  
  9. # open file 'filename', then call read
  10. one:
  11. pop ebx
  12. movb al, 0x5 # sys_open
  13. int 0x80 #sys_open('filename', 0), 0 for RD_ONLY, 1 for WR_ONLY, 2 for RD_WR
  14.  
  15. mov esi, eax
  16.  
  17. read:
  18. movb al, 0x3 # sys_read
  19. mov ebx, esi # move fd to ebx
  20. lea ecx, [esp]
  21. movb dl, 0x1 #read 1 byte
  22. int 0x80
  23.  
  24. # If (read null byte (\x00) or error)
  25. # exit
  26. xor ebx, ebx
  27. cmp eax, ebx
  28. jle exit
  29. # else
  30. # write this byte (character)
  31. write:
  32. movb al, 0x4 # sys_write
  33. movb bl, 0x1 # write 1 byte
  34. movb dl, 0x1
  35. int 0x80 #now, ecx is still [esp], no need to assign 1 more time => save memory
  36.  
  37. jmp read # This instruction causes loop until we read null byte
  38.  
  39. exit:
  40. movb al, 0x1 # sys_exit
  41. xor ebx, ebx # sys_exit(0)
  42. int 0x80
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement