gpt4 book ai didi

汇编 - 试图将字节移动到内存不起作用

转载 作者:行者123 更新时间:2023-12-03 17:38:32 27 4
gpt4 key购买 nike

我试图通过更改其中的一个字节来修改存储在内存中的字符串。我为此使用了 movb,但由于某种原因,给定内存位置的字节没有改变。

在 gdb 调试器上:

14 movb %al, (%r10) # next instr
(gdb) print /d $al
$4 = 0
(gdb) print /c *$r10
$5 = 47 '/'
(gdb) s
16 mov $59, %rax
(gdb) print /c *$r10
$6 = 47 '/'



代码只是:
.globl _start
.text

_start:
call chamaexecve
variaveis:
.asciz "/bin/bashABBBBCCCC"


chamaexecve:

pop %r10
xor %rax, %rax
movb %al, (%r10) # problem happening here

mov $59, %rax
mov %rsi, %rdi
mov $0, %rsi
mov $0, %rdx

syscall

它正在编译 as -gstabs -o shellf.o shellf.s - ld -N -z execstack -o shellf shellf.o
编辑 为了确保我没有犯任何错误,我删除了可执行文件并重新编译。错误仍然存​​在。我注意到的另一件事是,如果我添加一行 movb $'r', %al在将 %al 移动到内存之前, 'r'通常打印在内存上,但由于某种原因它不适用于 $0值(value)。

我在 Linux Mint 18.1“Serena”滚动发行版 gnu assembler 2.26.1 上运行它。这是使用 x/i $rip 的打印显示当前指令:

enter image description here

编辑 2 :
在将 break 更改为 tbreak 并将 s 更改为 si 后,我看到它最终从 '/' 更改为 '\000'。那么在所有 s/break/gdb 搞砸之后可能会出现什么问题呢?

(gdb) tb 14
Temporary breakpoint 1 at 0x4000cd: file shellf.s, line 14.
(gdb) run
Starting program: /home/fabio/criação/nasm-tutorial/shellf

Temporary breakpoint 1, chamaexecve () at shellf.s:14
14 movb %al, (%r10)
(gdb) si
16 mov $59, %rax
(gdb) print /c *$rsi
Cannot access memory at address 0x0
(gdb) print /c *$r10
$1 = 0 '\000'
(gdb)

最佳答案

程序的 .text 部分是只读的,如果您想修改字符串,您需要将它放在 .data 部分中。

关于汇编 - 试图将字节移动到内存不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42238710/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com