如何一次性保护跨越多个页面的存储区域?

哥哥

我正在尝试取消保护跨越几页的一块内存区域。我正在使用此代码来取消保护内存的一页,但是我需要一次取消保护几页的权限,因为在访问其他页面时遇到段错误,但是我手头有一个起始地址和一个结束地址,但是下面的函数可以使用起始地址,rdi并赋予我对当前页面的写访问权,我如何利用结束地址r15,以便可以对rdi -> r15存储页面进行写访问

例如:一次访问从rdi= 0x4012a0到r15= 0x402340地址的页面上的写访问

call getpagesize
; rax has 0x1000
mov rcx, rax
; save rax for later use when passing to mprotect
sub rcx, 0x1
not rcx
mov rdi, %1
and rdi, rcx
; AND them and the result will be stored in rcx
; rdi must hold the page_start address
mov rsi, rax
; rsi must have the page length
mov rdx, 0x7
; read+write+exec = 0x7
call mprotect
布伦丹

这不太正确:

; rsi must have the page length

rsimprotect()调用的第二个参数,应该是您要更改的区域的长度。如果要使区域的长度大于一页,则需要rsi大于从中获得的值call getpagesize

特别; 也许您想要更多类似的东西:

    call getpagesize
    ; rax has 0x1000
    mov rcx, rax
    ; save rax for later use when passing to mprotect
    sub rcx, 0x1
    not rcx
    mov rdi, %1
    and rdi, rcx
    ; AND them and the result will be stored in rcx
    ; rdi must hold the page_start address

    mov rsi, r15      ;rsi = end
    sub rsi,rdi       ;rsi = end - aligned_start = length

    mov rdx, 0x7
    ; read+write+exec = 0x7
    call mprotect

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章