1
This SO上的問題/答案顯示瞭如何使用GDB更改內存中的值,但在給出的示例中,它選擇了一個地址來設置先前未使用的值選擇地址以更改內存中的值
例如,返回值更改爲22,筆者確實
set {unsigned char}0x00000000004004b9 = 22
然而,爲什麼會這個地址0x00000000004004b9
是地址改變?如果你查看disas/r
的輸出,地址0x00000000004004b9
沒有被使用,那麼爲什麼使用這個設置爲22?我試圖瞭解如何知道哪個地址需要更改爲(在本例中)更改返回值,如果disas/r
的輸出沒有顯示它。
代碼
$ cat t.c
int main()
{
return 42;
}
$ gcc t.c && ./a.out; echo $?
42
$ gdb --write -q ./a.out
(gdb) disas/r main
Dump of assembler code for function main:
0x00000000004004b4 <+0>: 55 push %rbp
0x00000000004004b5 <+1>: 48 89 e5 mov %rsp,%rbp
0x00000000004004b8 <+4>: b8 2a 00 00 00 mov $0x2a,%eax
0x00000000004004bd <+9>: 5d pop %rbp
0x00000000004004be <+10>: c3 retq
End of assembler dump.
(gdb) set {unsigned char}0x00000000004004b9 = 22
(gdb) disas/r main
Dump of assembler code for function main:
0x00000000004004b4 <+0>: 55 push %rbp
0x00000000004004b5 <+1>: 48 89 e5 mov %rsp,%rbp
0x00000000004004b8 <+4>: b8 16 00 00 00 mov $0x16,%eax <<< ---changed
0x00000000004004bd <+9>: 5d pop %rbp
0x00000000004004be <+10>: c3 retq
End of assembler dump.
(gdb) q
$ ./a.out; echo $?
22 <<<--- Just as desired