x64dbg 或替代方案:运行选择,同时存储所有运行的操作码

逆向工程 x64dbg x86-64 汇编
2021-06-18 17:32:53

我正在尝试跟踪一个函数,但不幸的是,该函数非常庞大,并且会跳转到其他位置,这使得人类几乎不可能进行跟踪。我知道函数的入口点和出口点。我想要一种能够运行该函数并查看之后执行的所有操作码的方法,以便我稍后可以在 C++ 中手动重新创建该函数。它还可以帮助我找到函数崩溃时的确切位置(因为它将是最后执行的代码)。我已经在 x64dbg 中尝试了跟踪方法,但它不会记录我没有手动走过的操作码。

1个回答

在 Windows 上旅行调试 (TTD)是此方案的完美用例。

要使用 TTD,您需要运行提升的调试器。使用具有管理员权限的帐户从 Windows 10 商店安装WinDbg Preview,并在调试器中记录时使用该帐户。为了运行提升的调试器,选择并按住(或右键单击)开始菜单中的 WinDbg 预览图标,然后选择更多 > 以管理员身份运行。

如果您需要在没有 Windows 10 的系统上运行,我已经在 Windows 8.1/Server 2012 及更高版本上使用它,首先在 Windows 10 上安装,然后将安装的文件复制到另一个系统。由于普通管理员帐户无权访问这些文件,我使用psexec -sid cmd.exe将它们复制为 SYSTEM 帐户运行,然后使用命令复制到文件夹,例如robocopy "C:\program files\WindowsApps\Microsoft.WinDbg_1.2007.6001.0_neutral__8wekyb3d8bbwe" "C\windbgx" * /s

进行跟踪:

  1. 在 WinDbg 预览中,选择文件 > 开始调试 > 启动可执行文件(高级)。
  2. 输入您希望记录的用户模式可执行文件的路径,或选择浏览以导航到该可执行文件。
  3. 选中 Record process with Time Travel Debugging 框以在可执行文件启动时记录跟踪。

您可以设置断点,创建异常/断点/内存访问的时间线,向前/向后跟踪指令,并在执行中的任何点检查内存/注册表/反汇编。

如果您将文件从 WindowsApps 文件夹中复制出来,您还可以通过命令行以不同的方式运行它。ttd.exe 用于 amd64\ttd 和 x86\ttd 文件夹中。

以下命令行选项可用。

Usage: ttd  [options] [mode] [PID | program [<arguments>] | <package> <app>]]

Options:
 -?                Display this help.
 -help             Display this help.
 -ring             Trace to a ring buffer.
 -ringMode <mode>  Specify how to record a ring trace. Possible modes:
                   file - The ring will be in a file on disk.
                       This is the default.
                   mappedFile - The ring will be in a file, but the entire
                       file will be fully mapped in memory. This reduces the
                       I/O overhead, but the entire file is mapped in
                       contiguous address space, which may add significant
                       memory pressure to 32-bit processes.
 -maxFile <size>   Maximum size of the trace file in MB.  When in full trace
                   mode the default is 1024GB and the minimum value is 1MB.
                   When in ring buffer mode the default is 2048MB, the minimum
                   value is 1MB, and the maximum value is 32768MB.
                   The default for in-memory ring on 32-bit processes is 256MB.
 -out <file>       Specify a trace file name or a directory.  If a file, the
                   tracer will replace the first instance of '%' with a
                   version number.  By default the executable's base name with
                   a version number is used to prefix the trace file name.
 -children         Trace through family of child processes.

Modes:
 -plm              To specify a PLM app/package for tracing from launch or to
                   launch that app. These PLM apps can only be setup for 
                   tracing if specifying the plm option. See -launch
                   for the parameters required. 
                   The default name for a single app package is 'app' and 
                   must be included. 
 -launch           Launch and trace the program (default).
                   This is the only mode that uses the program arguments.
                   For -plm apps it must be specified, and you must include
                   the package and the app (-launch <package> <app>).
                   Note: This must be the last option in the command-line,
                   followed by the program + arguments or the package + app
 -attach <PID>     Attach to a running process specified by process ID.

Control:
 -stop             Stop tracing the process specified (name, PID or "all").

使用 TTD 可以实现的一些演练如下:

时间旅行调试 - 示例应用演练

时间旅行调试对象模型介绍

在 WinDbg 时间旅行轨迹中识别用户交互的位置

如果使用 Visual Studio,您还可以使用IntelliTrace 功能来记录调试跟踪。