我有一项任务是使用 GDB 计算提供给我的程序的密码。我在跟踪程序的程序集转储(到目前为止)方面做得很好,但我一直在理解 cmpb
指令系统。我已经在各自的寄存器中记录了值,但是当 cmpb
时,我不知道寄存器中的值发生了什么。叫做。我读过其他主题,例如 understand cmpb and loops in assembly language但仍然让我头疼。
这是我的终端 session 的片段:
0x0804844a <+6>: mov $0x0,%eax
0x0804844f <+11>: cmpb $0x0,(%edx) // $edx has "something\n"
0x08048452 <+14>: je 0x804845d <s+25> // skipped since it's not equal to $0x0
0x08048454 <+16>: add $0x1,%eax // adding "something\n" to $0x1
=> 0x08048457 <+19>: cmpb $0x0,(%edx,%eax,1) //what is the result here???
0x0804845b <+23>: jne 0x8048454 <s+16>
现在在我上面提到的链接中,它指出
"takes a byte that EDX+EAX points to and compares it to zero. EDX serves as the string base pointer, EAX is the index. Scale is 1 because we're working with bytes. Think of the whole loop this way: for(eax=0; edx[eax] != 0; eax++)."
但究竟是什么字节?
我的意思是,如果 $edx
==“某物\n”和$eax
== 0x1
(我知道这一点是因为当我调用 $eax
的内容时它指出 <Address 0x1 out of bounds>
,然后比较什么字节和/或结果会是什么?
最佳答案
第一个 cmp 指令:
cmpb $0x0,(%edx)
测试字符串是否为空。如果为空,则不进入循环。
下一条cmp指令
cmpb $0x0,(%edx,%eax,1)
检查 0 是否在由 edx 和 eax 寄存器的总和 + 1 构成的地址中。eax
不包含任何地址,但充当偏移量。基地址是%edx
最后%eax
包含字符串长度。
关于cmpb 使用 GDB,需要帮助理解预期的响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47004953/