在断点上运行命令而不停止

逆向工程 数据库
2021-06-12 06:55:58

我想在我的以下自动化.gdbinit

break boost::uuids::detail::sha1::process_bytes

# When execution stops at the above breakpoint,
# I want to display the contents of `rcx` as a string:
x/s $rcx
c  # do not stop here

我如何自动执行此操作?

更新:这是一个更好的.gdbinit例子:

# Our custom-built libcurl, with debugging symbols enabled:
set environment LD_PRELOAD=./curl/curl-7.34.0/lib/.libs/libcurl.so

# File that connects to the evil server:
file ./evil

# Make sure we get notified when it connects!
break curl_easy_setopt
commands $bpnum
clear curl_easy_setopt  # to avoid recursion
call curl_easy_setopt(curl, CURLOPT_VERBOSE)
continue
end

这与邪恶的二进制文件挂钩,当它初始化其卷曲句柄时,我们将其设置为详细信息,以便我们获得大量关于正在发生的事情的输出。

谢谢你的回答。

1个回答

很容易。在您的情况下,您最可能想要的是commands可用于创建在遇到断点时运行的“例程”。对于您的情况大致:

break boost::uuids::detail::sha1::process_bytes
commands 1
x/s $rcx
continue
end

问题是您需要对断点编号进行硬编码。根据 GDB 版本,您可以使用$bpnum便捷变量解决此问题所以:

break boost::uuids::detail::sha1::process_bytes
commands $bpnum
x/s $rcx
continue
end

另请参阅关于最后一个例子。

注意:根据调用此方法的频率以及 GDB 是否可以使用硬件断点,使用此方法可能会对 CPU 造成很大负担。


您还可以使用条件形式的断点。在此处查看实际的权威参考表格如下所示:

break ... if cond

如果您知道断点编号,您还可以设置独立于设置断点的条件。使用info break获得断点的号码,然后使用,作为bnum在:

condition bnum expression