> 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.3_valgrind.md).

# 5.2.3 Valgrind

* [简介](#简介)
* [使用方法](#使用方法)
* [VEX IR](#vex-ir)
* [参考资料](#参考资料)

## 简介

Valgrind 是一个用于内存调试、内存泄漏检测以及性能分析的动态二进制插桩工具。Valgrind 由 core 以及基于 core 的其他调试工具组成。core 类似于一个框架，它模拟了一个 CPU 环境，并提供服务给其他工具，而其他工具以插件的形式利用 core 提供的服务完成各种特定的任务。

## 使用方法

## VEX IR

VEX IR 是 Valgrind 所使用的中间表示，供 DBI 使用，后来这一部分被分离出去作为 libVEX，libVEX 负责将机器码转换成 VEX IR，转换结果存放在 cache 中。

顺便，再简单提一下其他的类似用途的 IR 还有：BAP、REIL、LLVM、TCG 等。

## 参考资料

* [Valgrind: A Framework for Heavyweight Dynamic Binary Instrumentation](http://valgrind.org/docs/valgrind2007.pdf)
* [Optimizing Binary Code Produced by Valgrind](https://pdfs.semanticscholar.org/6761/acf36975d38fd5f616cb4798bfa3a92cbfa3.pdf)
* [libvex\_ir.h](https://github.com/angr/vex/blob/dev/pub/libvex_ir.h)
