B2R2-org/B2R2
GitHub: B2R2-org/B2R2
B2R2 是一个用 F# 编写的跨平台二进制分析算法与工具集合,提供从指令解析到控制流恢复的全链路前端能力。
Stars: 448 | Forks: 65




[](https://www.nuget.org/packages/B2R2.RearEnd.Launcher/)
# B2R2
B2R2 是一组用于**二进制分析**的实用算法、函数和工具的集合,完全使用 F# 编写(在 .NET 术语中,即纯托管代码)。
B2R2 以《星球大战》中著名的虚构机器人 [R2-D2](https://en.wikipedia.org/wiki/R2-D2) 命名。实际上,B2R2 的原名是 *B2-R2*,但我们决定改用 *B2R2* 这个名字,因为 .NET 不允许在标识符(或命名空间)中使用连字符 (-)。这个名字本质上代表了“二进制”或“二”:“二进制”本身就意味着“两种”状态。“B”和“2”代表“二进制”,而“R”代表 *逆向工程*。
## B2R2?
1. B2R2 *对分析友好*:它是用 F# 编写的,F# 提供了编写程序分析器所需的所有语法特性,例如模式匹配、代数数据类型等。
2. B2R2 *速度快*:它拥有一个用于二进制分析的快速高效的前端引擎,该引擎以[函数优先](https://en.wikipedia.org/wiki/F_Sharp_(programming_language)) 的方式编写。因此,它天然支持针对各种二进制分析任务(例如指令提升、CFG 恢复等)的*纯并行处理*。
3. B2R2 *易于上手*:B2R2 完全不存在依赖地狱问题,因为它是一个完全托管的库。您所需要做的就是安装 [.NET SDK](https://dotnet.microsoft.com/download),然后就可以开始了!原生的 [IntelliSense](https://docs.microsoft.com/en-us/visualstudio/ide/using-intellisense) 支持是另一个加分项!
4. B2R2 *与操作系统无关*:只要 .NET Core 支持,它就能在 Linux、Mac、Windows 等系统上运行。
5. B2R2 *具备互操作性*:它不局限于特定的语言。从理论上讲,您可以在任何 [CLI 支持的语言](https://en.wikipedia.org/wiki/List_of_CLI_languages) 中使用 B2R2 API。
## 功能特性?
B2R2 支持指令解析、二进制反汇编、汇编、控制流恢复等功能。B2R2 还附带了几个类似于 readelf 和 objdump 的用户级命令行工具,尽管我们的工具是与平台无关的。B2R2 目前支持四种二进制文件格式:ELF、PE、Mach-O 和 WebAssembly。
以下是我们目前支持的功能列表。其中一些仍在开发中,但我们期待您的贡献!在确保您已阅读我们的[贡献指南](CONTRIBUTING.md) 之后,请随时提交 PR。
## 依赖项?
B2R2 依赖于极少量的外部 .NET 库,我们的设计原则是使用最少数量的库。以下是我们所使用的库列表。
- [System.IO.Hashing](https://www.nuget.org/packages/System.IO.Hashing)
- [FSharp.Compiler.Service](https://www.nuget.org/packages/FSharp.Compiler.Service)
- [FParsec](https://www.nuget.org/packages/FParsec)
- [BenchmarkDotNet](https://www.nuget.org/packages/BenchmarkDotNet/)
## API 文档
我们目前使用 [fsdocs](https://github.com/fsprojects/FSharp.Formatting/) 来生成我们的文档:https://b2r2.org/B2R2/。
## 示例
让我们尝试使用 B2R2 API。
1. 首先我们创建一个空目录 `DIRNAME`:
mkdir DIRNAME
cd DIRNAME
2. 然后我们使用 `dotnet` 命令行创建一个空的控制台项目:
$ dotnet new console -lang F#
3. 将我们的 NuGet 包 *B2R2.FrontEnd* 添加到项目中:
$ dotnet add package B2R2.FrontEnd.API
4. 使用您喜欢的编辑器修改 `Program.fs` 文件,如下所示:
open B2R2
open B2R2.FrontEnd
[]
let main argv =
let isa = ISA "amd64"
let bytes = [| 0x65uy; 0xffuy; 0x15uy; 0x10uy; 0x00uy; 0x00uy; 0x00uy |]
let hdl = BinHandle(bytes, isa)
let lifter = hdl.NewLiftingUnit()
let ins = lifter.ParseInstruction 0UL // parse the instruction at offset 0
lifter.LiftInstruction ins |> printfn "%A"
0
5. 然后我们只需键入:`dotnet run` 来运行它。您将在控制台中看到提升后的 IR 语句。就是这样!您刚刚只用了几行 F# 代码就提升了一条 Intel 指令!
## 构建
构建 B2R2 既有趣又简单。您所需要做的就是安装 .NET 9 SDK 或更高版本。是的,就是这样!
- 要在发布模式下构建 B2R2,请在源代码根目录中输入 ```dotnet build -c Release```。
- 要在调试模式下构建 B2R2,请在源代码根目录中输入 ```dotnet build```。
如需更多信息,请访问 F#官方网站以获取有关安装 F# 开发环境的更多提示:http://fsharp.org/。
## 致谢
KAIST [SoftSec 实验室](https://softsec.kaist.ac.kr/) 的成员与 KAIST 的[网络安全研究中心](http://csrc.kaist.ac.kr/)
(CSRC) 合作开发了 B2R2。完整列表请参见[作者](AUTHORS.md)。
## 引用
如果您计划在自己的研究中使用 B2R2。请考虑引用我们的[论文](https://softsec.kaist.ac.kr/~sangkilc/papers/jung-bar19.pdf):
```
@INPROCEEDINGS{jung:bar:2019,
author = {Minkyu Jung and Soomin Kim and HyungSeok Han and Jaeseung Choi and Sang Kil Cha},
title = {{B2R2}: Building an Efficient Front-End for Binary Analysis},
booktitle = {Proceedings of the NDSS Workshop on Binary Analysis Research},
year = 2019
}
```
## 发表文献
以下是使用我们研究成果的论文。如果您想添加您的论文,请创建一个 PR。
- EVMpress: Precise Type Inference for Next-Generation EVM Decompilation, CBT 2025 [(PDF)](https://softsec.kaist.ac.kr/~sangkilc/papers/kim-cbt25.pdf)
- Towards Sound Reassembly of Modern x86-64 Binaries, ASPLOS 2025 [(PDF)](https://softsec.kaist.ac.kr/~sangkilc/papers/kim-asplos25.pdf)
- PoE: A Domain-Specific Language for Exploitation, SVCC 2024 [(PDF)](https://softsec.kaist.ac.kr/~sangkilc/papers/kim-svcc24.pdf)
- FunProbe: Probing Functions from Binary Code through Probabilistic Analysis, FSE 2023 [(PDF)](https://softsec.kaist.ac.kr/~sangkilc/papers/kim-fse23.pdf)
- How'd Security Benefit Reverse Engineers? The Implication of Intel CET on Function Identification, DSN 2022 [(PDF)](https://softsec.kaist.ac.kr/~sangkilc/papers/kim-dsn2022.pdf)
- Smartian: Enhancing Smart Contract Fuzzing with Static and Dynamic Data-Flow Analyses, ASE 2021 [(PDF)](https://softsec.kaist.ac.kr/~jschoi/data/ase2021.pdf)
- NTFuzz: Enabling Type-Aware Kernel Fuzzing on Windows with Static Binary Analysis, Oakland 2021 [(PDF)](https://softsec.kaist.ac.kr/~jschoi/data/oakland2021.pdf)
| CPU | 文档 | 指令解析 | 反汇编 | 提升 | CFG 恢复 | 汇编 |
|---|---|---|---|---|---|---|
| x86 | :full_moon: | :full_moon: | :full_moon: | :full_moon: | :full_moon: | :full_moon: |
| x86-64 | :full_moon: | :full_moon: | :full_moon: | :full_moon: | :full_moon: | :full_moon: |
| ARMv7 | :full_moon: | :full_moon: | :full_moon: | :full_moon: | :first_quarter_moon: | :new_moon: |
| ARMv8 (AArch64) | :full_moon: | :full_moon: | :full_moon: | :full_moon: | :first_quarter_moon: | :new_moon: |
| MIPS32 | :full_moon: | :full_moon: | :full_moon: | :full_moon: | :first_quarter_moon: | :new_moon: |
| MIPS64 | :full_moon: | :full_moon: | :full_moon: | :full_moon: | :first_quarter_moon: | :new_moon: |
| EVM | :full_moon: | :full_moon: | :full_moon: | :full_moon: | :full_moon: | :new_moon: |
| TMS320C6000 | :full_moon: | :full_moon: | :full_moon: | :new_moon: | :first_quarter_moon: | :new_moon: |
| AVR | :full_moon: | :full_moon: | :full_moon: | :full_moon: | :first_quarter_moon: | :new_moon: |
| PA-RISC | :full_moon: | :full_moon: | :full_moon: | :new_moon: | :first_quarter_moon: | :new_moon: |
| PPC32 | :full_moon: | :full_moon: | :full_moon: | :full_moon: | :first_quarter_moon: | :new_moon: |
| SPARC | :full_moon: | :full_moon: | :full_moon: | :full_moon: | :first_quarter_moon: | :new_moon: |
| SH4 | :full_moon: | :full_moon: | :full_moon: | :new_moon: | :first_quarter_moon: | :new_moon: |
| RISC-V | :full_moon: | :full_moon: | :full_moon: | :full_moon: | :first_quarter_moon: | :new_moon: |
| S390 | :full_moon: | :full_moon: | :full_moon: | :new_moon: | :first_quarter_moon: | :new_moon: |
标签:B2R2, DAST, DNS解析, F#, Findomain, TLS抓取, 二进制分析, 云安全监控, 云安全运维, 云资产清单, 函数式编程, 可配置连接, 多人体追踪, 开源项目, 恶意软件分析, 指令提升, 控制流图恢复, 程序分析, 算法库, 编译器前端, 网络安全, 软件安全, 逆向工程, 隐私保护, 静态分析