Advertisement
Guest User

Untitled

a guest
May 27th, 2019
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. .X64
  2. START SEGMENT USE64 para public 'text'
  3. PUBLIC _start
  4.  
  5. ASSUME cs:START
  6. ASSUME ds:BSS
  7.  
  8. ;----------------------------------------;
  9. ; Program to copy two arbitrary ;
  10. ; buffers ;
  11. ;----------------------------------------;
  12. _start PROC NEAR ;
  13. ;-- get current program brk ;
  14. mov rax, 12 ; SYS_BRK
  15. mov rdi, 0 ; invalid adress
  16. syscall ;
  17. mov QWORD PTR [OLD_PROGRAM_BRK], rax ; store the old program break
  18. ;-- Allocate memory -----------------;
  19. mov rdi, rax ; rbx = current break
  20. mov rax, 12 ; SYS_BRK
  21. add rdi, 20000 ; reserve 20000 bytes
  22. syscall ;
  23. mov QWORD PTR [PROGRAM_BRK], rax ; store the new program break
  24. ;////////////////////////////////////////;
  25. ;-- setup a loop --------------------;
  26. mov rdx, 100000000 ; 100000000 iterations
  27. @@LOOP: ;
  28. ;-- copy the memory -----------------;
  29. pop rax ; get buffer pointer
  30. mov rdi, QWORD PTR [OLD_PROGRAM_BRK] ; set source
  31. mov rsi, rdi ;
  32. add rsi, 10000 ; set destination
  33. push rax ; preserve rax for next loop
  34. mov rax, 10000 ; amount to copy
  35. call _COPY ; copy memory
  36. ;-- loop head -----------------------;
  37. dec rdx ;
  38. and rdx, rdx ; is edx zero?
  39. jnz @@LOOP ; if not, loop
  40. ;////////////////////////////////////////;
  41. ;-- exit ----------------------------; when done looping, stop
  42. mov rax, 1 ;
  43. int 80h ;
  44. _start ENDP ;
  45. ;========================================;
  46.  
  47. ;----------------------------------------;
  48. ; MEMCPY ;
  49. ;-input----------------------------------;
  50. ; esi -> source buf ;
  51. ; esd -> dest buf ;
  52. ; eax -> size ;
  53. ;----------------------------------------;
  54. _COPY PROC NEAR ;
  55. mov rcx, rax ;
  56. and rax, 03h ; rax %= 4; find out how many bytes are left after copying 8packs
  57. sub rcx, rax ; only iterate as many times as possible
  58. shr rcx, 2 ; divide by 4 since we are copying 4 bytes at once
  59. rep movsd ; copy as many bytes as possible in packs of 4
  60. mov rcx, rax ; copy the rest
  61. rep movsb ;
  62. ret ;
  63. _COPY ENDP ;
  64. ;========================================;
  65. START ENDS
  66.  
  67. BSS SEGMENT '_bss'
  68. PROGRAM_BRK DQ ?
  69. OLD_PROGRAM_BRK DQ ?
  70. BSS ENDS
  71. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement