
B2R2 是一个完全托管的二进制分析框架,使用 F# 编写。它为逆向工程、程序分析和二进制级检查提供了丰富的算法、函数和工具。
名称 B2R2 的灵感来源于星球大战中的标志性机器人 R2-D2。最初名为 B2-R2,后来因为 .NET 标识符和命名空间不允许使用连字符,项目采用了无连字符形式 B2R2。该名称反映了项目的用途:"B" 和 "2" 暗示二进制和二态计算,而 "R" 代表逆向(reversing)。简而言之,B2R2 是为二进制逆向而构建的。
B2R2 是分析友好型的:它使用 F# 编写,这种语言凭借模式匹配、代数数据类型和表达性强的函数抽象等特性,非常适合构建程序分析器。
B2R2 是快速的:其核心二进制分析引擎专为效率而设计,采用函数优先风格编写。这使得它非常适合在常见分析任务(如指令提升和 CFG 恢复)中实现纯并行。
B2R2 是易于使用的:作为一个完全托管的库,它避免了复杂的原生依赖设置。安装 .NET SDK 后即可开始使用。原生的 IntelliSense 支持也使 API 更易于探索。
B2R2 是OS 无关的:它在 Linux、macOS 和 Windows 以及 .NET 支持的任何其他平台上均可运行。
B2R2 是可互操作的:它不局限于单一编程语言。原则上,B2R2 API 可以从任何 CLI 支持的语言 中使用。
B2R2 支持指令解析、二进制反汇编、汇编、控制流恢复以及其他用于二进制分析的核心构建模块。它还包含多个面向用户的命令行工具,可与 readelf 和 objdump 相媲美,同时保持平台无关性。B2R2 目前支持四种二进制文件格式:ELF、PE、Mach-O 和 WebAssembly。
下表总结了 B2R2 当前支持的功能。某些领域仍在开发中,欢迎贡献代码。在发起拉取请求之前,请确保阅读我们的贡献指南。
B2R2 有意保持较小的依赖体积,以使构建简单,并让核心专注于高效的算法和数据结构以进行二进制分析。核心库没有外部依赖,大多数外部库都是可选的,仅由特定组件或工具使用。以下是项目使用的外部库列表。
我们的文档使用 fsdocs 生成,可在 https://b2r2.org/B2R2/ 找到。
让我们尝试使用 B2R2 API。
首先,创建一个名为 DIRNAME 的空目录:
mkdir DIRNAME
cd DIRNAME
然后,使用 dotnet 命令行工具创建一个空的控制台项目:
$ dotnet new console -lang F#
将 NuGet 包 B2R2.FrontEnd.API 添加到项目:
$ dotnet add package B2R2.FrontEnd.API
用您喜欢的编辑器修改 Program.fs 文件,内容如下:
open B2R2
open B2R2.FrontEnd
[<EntryPoint>]
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 // 解析偏移量 0 处的指令
lifter.LiftInstruction ins |> printfn "%A"
0
输入 dotnet run 运行。您应该会在控制台中看到提升后的 IR 语句。就这样!您只用了几行 F# 代码就提升了一条 Intel 指令。
构建 B2R2 非常简单。安装 .NET 10 SDK 或更高版本,然后就可以从源代码根目录开始构建。
要以发布模式构建 B2R2,运行 dotnet build -c Release。
要以调试模式构建 B2R2,运行 dotnet build。
有关搭建 F# 开发环境的更多信息,请访问官方 F# 网站:http://fsharp.org/。
B2R2 由 KAIST 的 SoftSec 实验室 成员与 KAIST 的 网络安全研究中心 (CSRC) 合作开发。完整贡献者列表请参见 AUTHORS.md。
如果您在研究中使用 B2R2,请考虑引用我们的论文:
@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
}
B2R2 提供在线教程,涵盖使用 B2R2 的基础知识并提供动手实践示例。请通过以下链接查看:https://b2r2.org/tutorial-icst2026/。
以下是使用或基于 B2R2 的论文。如果您的工作应被收录,请发起拉取请求。
| 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: |