GDB:打印内存地址的值

时间:2017-05-09 05:21:25

标签: gdb

根据https://www.ethicalhacker.net/columns/heffner/intro-to-assembly-and-reverse-engineering

mov 0xffffffb4,0x1
  

将数字1移动到0xffffffb4。

所以,我决定自己测试一下。 在GDB中,x是打印内存地址值的命令。 但是,当我跑

x 0x00000000004004fc

我没有得到133(十进制)或85(十六进制)

的值

相反,我得到的是0x85f445c7。知道这是什么意思吗?

me@box:~/c$ gdb -q test
Reading symbols from test...done.
(gdb) l
1       #include <stdio.h>
2
3       int main(){
4               int a = 1;
5               int b = 13;
6               int c = 133;
7               printf("Value of C : %d\n",c);
8               return 0;
9       }
(gdb) b 7
Breakpoint 1 at 0x400503: file test.c, line 7.
(gdb) r
Starting program: /home/me/c/test 

Breakpoint 1, main () at test.c:7
7               printf("Value of C : %d\n",c);
(gdb) 

拆卸

(gdb) disas
Dump of assembler code for function main:
   0x00000000004004e6 <+0>:     push   %rbp
   0x00000000004004e7 <+1>:     mov    %rsp,%rbp
   0x00000000004004ea <+4>:     sub    $0x10,%rsp
   0x00000000004004ee <+8>:     movl   $0x1,-0x4(%rbp)
   0x00000000004004f5 <+15>:    movl   $0xd,-0x8(%rbp)
   0x00000000004004fc <+22>:    movl   $0x85,-0xc(%rbp)
=> 0x0000000000400503 <+29>:    mov    -0xc(%rbp),%eax
   0x0000000000400506 <+32>:    mov    %eax,%esi
   0x0000000000400508 <+34>:    mov    $0x4005a4,%edi
   0x000000000040050d <+39>:    mov    $0x0,%eax
   0x0000000000400512 <+44>:    callq  0x4003c0 <printf@plt>
   0x0000000000400517 <+49>:    mov    $0x0,%eax
   0x000000000040051c <+54>:    leaveq 
   0x000000000040051d <+55>:    retq   
End of assembler dump.
(gdb) x 0x00000000004004fc
0x4004fc <main+22>:     0x85f445c7
(gdb)

1 个答案:

答案 0 :(得分:0)

; DRTL

要在GDB中打印值,请使用print或(缩写为p)命令。

在您的命令中

x 0x00000000004004fc

您错过了p命令。您必须将xp命令对一起使用,以十六进制格式打印值,如下所示:

(gdb) p/x 0x00000000004004fc

如果内存地址是指向某些结构的指针,则必须在使用指针之前强制转换内存位置。例如,

struct node {
  int data;
  struct node *next
};

是某种结构,您具有该结构指针的地址,然后要查看该内存位置的内容,您必须使用

(gdb) p *(struct node *) 0x00000000004004fc
相关问题