Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .X64
- START SEGMENT USE64 para public 'text'
- PUBLIC _start
- ASSUME cs:START
- ASSUME ds:BSS
- ;----------------------------------------;
- ; Program to copy two arbitrary ;
- ; buffers ;
- ;----------------------------------------;
- _start PROC NEAR ;
- ;-- get current program brk ;
- mov rax, 12 ; SYS_BRK
- mov rdi, 0 ; invalid adress
- syscall ;
- mov QWORD PTR [OLD_PROGRAM_BRK], rax ; store the old program break
- ;-- Allocate memory -----------------;
- mov rdi, rax ; rbx = current break
- mov rax, 12 ; SYS_BRK
- add rdi, 20000 ; reserve 20000 bytes
- syscall ;
- mov QWORD PTR [PROGRAM_BRK], rax ; store the new program break
- ;////////////////////////////////////////;
- ;-- setup a loop --------------------;
- mov rdx, 100000000 ; 100000000 iterations
- @@LOOP: ;
- ;-- copy the memory -----------------;
- pop rax ; get buffer pointer
- mov rdi, QWORD PTR [OLD_PROGRAM_BRK] ; set source
- mov rsi, rdi ;
- add rsi, 10000 ; set destination
- push rax ; preserve rax for next loop
- mov rax, 10000 ; amount to copy
- call _COPY ; copy memory
- ;-- loop head -----------------------;
- dec rdx ;
- and rdx, rdx ; is edx zero?
- jnz @@LOOP ; if not, loop
- ;////////////////////////////////////////;
- ;-- exit ----------------------------; when done looping, stop
- mov rax, 1 ;
- int 80h ;
- _start ENDP ;
- ;========================================;
- ;----------------------------------------;
- ; MEMCPY ;
- ;-input----------------------------------;
- ; esi -> source buf ;
- ; esd -> dest buf ;
- ; eax -> size ;
- ;----------------------------------------;
- _COPY PROC NEAR ;
- mov rcx, rax ;
- and rax, 03h ; rax %= 4; find out how many bytes are left after copying 8packs
- sub rcx, rax ; only iterate as many times as possible
- shr rcx, 2 ; divide by 4 since we are copying 4 bytes at once
- rep movsd ; copy as many bytes as possible in packs of 4
- mov rcx, rax ; copy the rest
- rep movsb ;
- ret ;
- _COPY ENDP ;
- ;========================================;
- START ENDS
- BSS SEGMENT '_bss'
- PROGRAM_BRK DQ ?
- OLD_PROGRAM_BRK DQ ?
- BSS ENDS
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement