首页 > 解决方案 > GDB 是否支持演绎内存扫描,例如 Cheat Engine?

问题描述

当您没有目标程序的源代码时,在内存中查找变量位置的最佳方法之一是扫描进程的内存以查找其当前值并记下包含该值的所有地址。然后,做一些事情来改变值,并检查该列表中的每个地址,消除那些没有新值的地址。冲洗并重复。

这种技术非常适合寻找各种值,我认为它是必不可少的。最知名的工具称为作弊引擎,因为它最常用于黑客游戏。但它当然也适用于其他类型的软件。

出于某种原因,很多调试器,甚至是为二进制分析而设计的调试器,都没有这个功能。我想知道的是 GDB 是否可以进行这种类型的扫描。我还没有看到它的选项,但是拥有它会非常有用,并且它在 GDB 中运行良好。(我可以很容易地看到它正在实现,您通过在 C 语法中指定数据类型来初始化扫描,然后通过指定要为每个地址评估的布尔表达式(通过表示指向该地址的指针的变量)来过滤地址的命令数据类型。)

如果 GDB 中不存在此功能,是否有现有的 fork 或补丁来添加该功能?我知道我可以使用其他工具,但 GDB 得到了许多不同目标的广泛支持,而其他软件不一定支持这些目标。

标签: memorygdbreverse-engineeringcheat-engine

解决方案


我想知道的是 GDB 是否可以进行这种类型的扫描。

(gdb) help find
Search memory for a sequence of bytes.
Usage:
find [/SIZE-CHAR] [/MAX-COUNT] START-ADDRESS, END-ADDRESS, EXPR1 [, EXPR2 ...]
find [/SIZE-CHAR] [/MAX-COUNT] START-ADDRESS, +LENGTH, EXPR1 [, EXPR2 ...]
SIZE-CHAR is one of b,h,w,g for 8,16,32,64 bit values respectively,
and if not specified the size is taken from the type of the expression
in the current language.
Note that this means for example that in the case of C-like languages
a search for an untyped 0x42 will search for "(int) 0x42"
which is typically four bytes, and a search for a string "hello" will
include the trailing '\0'.  The null terminator can be removed from
searching by using casts, e.g.: {char[5]}"hello".

The address of the last match is stored as the value of "$_".
Convenience variable "$numfound" is set to the number of matches.

推荐阅读