(addr, length, prot)
Only x86_64.
Only x86_64.
Only x86_64 .
def mprotect(addr, length, prot):
    '''Only x86_64.'''
    saved_rax = pwndbg.regs.rax
    saved_rbx = pwndbg.regs.rbx
    saved_rcx = pwndbg.regs.rcx
    saved_rdx = pwndbg.regs.rdx
    saved_rip = pwndbg.regs.rip

    prot_int = prot_str_to_val(prot)
    gdb.execute('set $rax={}'.format(SYS_MPROTECT))
    gdb.execute('set $rbx={}'.format(addr))
    gdb.execute('set $rcx={}'.format(length))
    gdb.execute('set $rdx={}'.format(prot_int))

    saved_instruction_2bytes = pwndbg.memory.read(pwndbg.regs.rip, 2)

    # int 0x80
    pwndbg.memory.write(pwndbg.regs.rip, b'\xcd\x80')

    # execute syscall
    gdb.execute('stepi')

    print('mprotect returned {}'.format(pwndbg.regs.rax))

    # restore registers and memory
    pwndbg.memory.write(saved_rip, saved_instruction_2bytes)

    gdb.execute('set $rax={}'.format(saved_rax))
    gdb.execute('set $rbx={}'.format(saved_rbx))
    gdb.execute('set $rcx={}'.format(saved_rcx))
    gdb.execute('set $rdx={}'.format(saved_rdx))
    gdb.execute('set $rip={}'.format(saved_rip))

    pwndbg.regs.rax = saved_rax
    pwndbg.regs.rbx = saved_rbx
    pwndbg.regs.rcx = saved_rcx
    pwndbg.regs.rdx = saved_rdx
    pwndbg.regs.rip = saved_rip
def mprotect ( addr , length , prot ) : saved_rax = pwndbg . regs . rax saved_rbx = pwndbg . regs . rbx saved_rcx = pwndbg . regs . rcx saved_rdx = pwndbg . regs . rdx saved_rip = pwndbg . regs . rip prot_int = prot_str_to_val ( prot ) gdb . execute ( 'set $rax={}' . format ( SYS_MPROTECT ) ) gdb . execute ( 'set $rbx={}' . format ( addr ) ) gdb . execute ( 'set $rcx={}' . format ( length ) ) gdb . execute ( 'set $rdx={}' . format ( prot_int ) ) saved_instruction_2bytes = pwndbg . memory . read ( pwndbg . regs . rip , 2 ) # int 0x80 pwndbg . memory . write ( pwndbg . regs . rip , b'\xcd\x80' ) # execute syscall gdb . execute ( 'stepi' ) print ( 'mprotect returned {}' . format ( pwndbg . regs . rax ) ) # restore registers and memory pwndbg . memory . write ( saved_rip , saved_instruction_2bytes ) gdb . execute ( 'set $rax={}' . format ( saved_rax ) ) gdb . execute ( 'set $rbx={}' . format ( saved_rbx ) ) gdb . execute ( 'set $rcx={}' . format ( saved_rcx ) ) gdb . execute ( 'set $rdx={}' . format ( saved_rdx ) ) gdb . execute ( 'set $rip={}' . format ( saved_rip ) ) pwndbg . regs . rax = saved_rax pwndbg . regs . rbx = saved_rbx pwndbg . regs . rcx = saved_rcx pwndbg . regs . rdx = saved_rdx pwndbg . regs . rip = saved_rip