> For the complete documentation index, see [llms.txt](https://firmianay.gitbook.io/ctf-all-in-one/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://firmianay.gitbook.io/ctf-all-in-one/5_advanced/5.2_dyn_binary_instrumentation/5.2.2_dynamorio.md).

# 5.2.2 DynamoRio

## 使用指南

在程序运行时对程序动态插桩，以实现源代码的内存语意修改。

### 需求

对于我们插桩的所有mov指令都会执行`if some_memory_region() insert_logic()`，来确保能执行到我们的逻辑。但是显然的缺点是LLC的memory hierarchy被破坏，这样无法模拟真实的内存访问。这也是和gem5模拟器最大的区别。

### 收集数据

你可以在`clients/drcachesim/analyzer_multi.cpp`中简单的收集到任意内存state的counter信息。需要在`clients/drcachesim/tools/`中创建一个工具类，记录插桩的时机，内存状态跳转和简单的内存tiering的大小。由于记录prefetching的时机比较难控制，我们需要在`clients/drcachesim/tracer/`中创建一个工具类，记录prefetching的时机。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://firmianay.gitbook.io/ctf-all-in-one/5_advanced/5.2_dyn_binary_instrumentation/5.2.2_dynamorio.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
