繁体   English   中英

在 GDB 中取消引用双指针(指向值的指针的指针)

[英]Dereference a double pointer (a pointer to a pointer to a value) in GDB

我正在编写一个脚本来对可执行文件进行逆向工程。 我有一种情况,其中 RAX 是一个指向值的指针,而该值本身是一个指向对象的指针。 反过来,该对象的第一个值是一个指向字符串的指针。 可视化应该清除它:

RAX
 |
 | points to
 |
 V
Value on the stack
 |
 | points to
 |
 V
The start of an object (std::vector<std::string)
 |
 | the very first value of that object points to
 |
 V
A string in memory

我想访问内存中的字符串。 我如何用一个命令做到这一点?

这是我如何做到的:

# Dereference RAX to get the value on the stack
(gdb) x/gx $rax         
0x7fffffffe0d0: 0x0000555555598700  

# Dereference the value on the stack to get the start of the object                        
(gdb) x/gx *((uint64_t*)$rax)            
0x555555598700: 0x0000555555578ea0    

# Dereference the start of the object because it points to a string
(gdb) x/s *((uint64_t*)*((uint64_t*)$rax))
0x555555578ea0: "/root/.ssh/id_rsa"       

我必须将值转换为uint64_t ,否则 GDB 会认为它是 32 位值(我正在使用 64 位可执行文件)。

此外,还有一个指向向量对象开始后 4 个字节的字符串的指针。 这是我访问该字符串的方式:

x/s *((uint64_t*)*((uint64_t*)$rax) + 4)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM