tuvior/Talaria
GitHub: tuvior/Talaria
一个 Python 编写的 Hermes 字节码反汇编与汇编工具,支持直接处理 APK,用于 React Native 应用逆向分析与安全研究。
Stars: 0 | Forks: 0
# Talaria
Hermes 字节码的飞翼工具。
**Talaria** 是一个 Python 命令行工具和库,用于反汇编、编辑, 以及汇编由 **React Native** 应用程序使用的 Hermes 字节码包。 **Talaria** 得名于墨丘利(罗马神话中对应赫尔墨斯的神)的飞鞋。 ## Hermes 字节码支持 **Talaria** 支持如下所列的 Hermes 字节码(**HBC**)版本。Hermes 并不 为每个字节码版本单独发布面向终端用户的文档;最接近的权威参考是定义了 字节码文件格式和操作码列表的 Hermes 源文件。一般背景信息可在 [React Native Hermes 指南](https://reactnative.dev/docs/hermes) 和 [Bundled Hermes 架构说明](https://reactnative.dev/architecture/bundled-hermes) 中找到。 | HBC 版本 | 操作码 | Talaria 元数据 | 上游参考 | 测试 fixture | | --- | ---: | --- | --- | --- | | 59 | 177 | [`hbc59`](src/talaria/hbc/hbc59) | [`facebook/hermes@v0.1.0`](https://github.com/facebook/hermes/tree/v0.1.0/include/hermes/BCGen/HBC) | [`bundle`](src/talaria/hbc/hbc59/example/index.android.bundle) | | 62 | 177 | [`hbc62`](src/talaria/hbc/hbc62) | [`facebook/hermes@v0.2.1`](https://github.com/facebook/hermes/tree/v0.2.1/include/hermes/BCGen/HBC) | [`bundle`](src/talaria/hbc/hbc62/example/index.android.bundle) | | 74 | 180 | [`hbc74`](src/talaria/hbc/hbc74) | [`facebook/hermes@v0.5.0`](https://github.com/facebook/hermes/tree/v0.5.0/include/hermes/BCGen/HBC) | [`bundle`](src/talaria/hbc/hbc74/example/index.android.bundle) | | 76 | 180 | [`hbc76`](src/talaria/hbc/hbc76) | [`facebook/hermes@v0.7.0`](https://github.com/facebook/hermes/tree/v0.7.0/include/hermes/BCGen/HBC) | [`bundle`](src/talaria/hbc/hbc76/example/index.android.bundle) | | 84 | 199 | [`hbc84`](src/talaria/hbc/hbc84) | [`facebook/hermes@v0.8.1`](https://github.com/facebook/hermes/tree/v0.8.1/include/hermes/BCGen/HBC) | [`bundle`](src/talaria/hbc/hbc84/example/index.android.bundle) | | 85 | 201 | [`hbc85`](src/talaria/hbc/hbc85) | [`facebook/hermes@RN 0.69`](https://github.com/facebook/hermes/tree/hermes-2022-05-20-RNv0.69.0-ee8941b8874132b8f83e4486b63ed5c19fc3f111/include/hermes/BCGen/HBC) | [`bundle`](src/talaria/hbc/hbc85/example/index.android.bundle) | | 90 | 204 | [`hbc90`](src/talaria/hbc/hbc90) | [`facebook/hermes@RN 0.71`](https://github.com/facebook/hermes/tree/hermes-2024-04-26-RNv0.71.19-b34632e6c603fb375ac4c8f423b2ee9cc45bed97/include/hermes/BCGen/HBC) | [`bundle`](src/talaria/hbc/hbc90/example/index.android.bundle) | | 94 | 206 | [`hbc94`](src/talaria/hbc/hbc94) | [`facebook/hermes@RN 0.72`](https://github.com/facebook/hermes/tree/hermes-2024-04-29-RNv0.72.14-3815fec63d1a6667ca3195160d6e12fee6a0d8d5/include/hermes/BCGen/HBC) | [`bundle`](src/talaria/hbc/hbc94/example/index.android.bundle) | | 96 | 206 | [`hbc96`](src/talaria/hbc/hbc96) | [`facebook/hermes@RN 0.73`](https://github.com/facebook/hermes/tree/hermes-2024-04-29-RNv0.73.8-644c8be78af1eae7c138fa4093fb87f0f4f8db85/include/hermes/BCGen/HBC) | [`bundle`](src/talaria/hbc/hbc96/example/index.android.bundle) | | 98 | 219 | [`hbc98`](src/talaria/hbc/hbc98) | [`facebook/hermes@hermes-v250829098.0.10`](https://github.com/facebook/hermes/tree/hermes-v250829098.0.10/include/hermes/BCGen/HBC) | [`bundle`](src/talaria/hbc/hbc98/example/index.android.bundle) | 不支持的 bundle 版本会在解析前明确报错。源标签 注册表位于 [`specs.json`](src/talaria/hbc/specs.json) 中,其中包括 用于生成 fixture 的编译器包。HBC 84, 85, 90, 94, 96 和 98 的 fixture 是从 [`hbc_fixture.js`](tests/fixtures/hbc_fixture.js) 编译而来的。 HBC 59 和 62 保留了样本 bundle,因为匹配的 npm 包没有 附带可用的 Linux `hermesc` 二进制文件;HBC 74 和 76 是保留的样本 bundle,它们已根据其源代码时代的元数据进行了验证。 ## 安装 ``` python -m pip install talaria ``` ## 用法 ``` talaria disasm index.android.bundle workspace/ talaria asm workspace/ index.android.bundle ``` 对于包含常规 React Native bundle 路径的 APK: ``` talaria apk disasm app.apk app-workspace/ # 编辑 app-workspace/tasm/functions.tasm talaria apk asm app-workspace/ ``` `talaria apk disasm` 会运行 `apktool d -r`,因此 APK 的资源会保持原样。 解码后的 APK 目录树会被写入 `app-workspace/apk`,而 TASM 工作区 会被写入 `app-workspace/tasm`。`talaria apk asm` 会更新 `app-workspace/apk/assets/index.android.bundle`。 使用 `talaria --help` 可获取完整的命令参考。 ## 工作区格式 `talaria disasm` 会写入一个 Talaria 工作区: - `talaria.json`:工作区清单和格式版本 - `bundle.json`:重新汇编所需的原始 Hermes 字节码元数据 - `strings.json`:可编辑的字符串表视图 - `functions.tasm`:Talaria 汇编文本 `functions.tasm` 中的函数块使用受 smali 启发的面向行的语法: ``` .function @45154 .name "?anon_0_" .params 1 .registers 12 .symbols 0 .hints kind generator_body wrapped_by fn@45153 exported_as "resetTrialStarted" yield_points :L002f flags generator_state_machine reads_environment .end hints StartGenerator ResumeGenerator r0, r1 JmpTrue :L002f, r1 LoadConstUndefined r1 CompleteGenerator Ret r1 :L002f CompleteGenerator Ret r0 .end function ``` 常见的操作数形式包括:用 `r0` 表示寄存器,用纯整数表示操作码类型的 无符号立即数,用 `i32:-1` 表示有符号立即数,用 `s@18 "value"` 表示可编辑的 字符串表引用,用 `fn@4` 表示函数引用,以及使用诸如 `:L002f` 之类的标签 来表示分支目标。缓存槽和类似的常见操作数会使用 诸如 `cache:2`、`slot:0`、`param:1` 和 `argc:3` 这样的别名进行渲染。 可选的 `.hints` 块包含为逆向工程生成的注释。汇编器会忽略提示; 编辑或移除它们不会改变字节码。每条提示行以一个键开头,后跟相应的值。 允许重复的键。当前的提示涵盖了常见的结构,例如父 闭包、Metro 模块工厂、导出 getter、方法、async/generator 包装器、选择器/投影器关系、回调、捕获的环境 槽、依赖导入、属性写入以及紧凑标志。 ## VS Code 语法高亮 此仓库包含一个用于 `functions.tasm` 和其他 `.tasm` 文件的本地 VS Code 语言扩展。 从 `talaria` 仓库的根目录安装它: ``` mkdir -p ~/.vscode/extensions ln -s "$PWD/vscode/talaria-tasm" ~/.vscode/extensions/talaria-tasm ``` 重新加载 VS Code,然后打开一个 `.tasm` 文件。如果 VS Code 没有自动检测到 语言,请从语言模式选择器中选择 `Talaria TASM`。 要通过复制而非符号链接的方式进行安装: ``` mkdir -p ~/.vscode/extensions/talaria-tasm cp -R vscode/talaria-tasm/. ~/.vscode/extensions/talaria-tasm/ ``` ## 开发 ``` python -m pip install -e ".[dev]" python -m pytest python tools/check_hbc_specs.py python -m ruff check src/talaria/cli.py src/talaria/commands.py tools tests ``` 字节码解析器是由位于 `src/talaria/hbc/hbc*/data` 下的带版本的 Hermes 结构和 操作码元数据驱动的。在更新任何 `BytecodeList.def` 或 `opcode.json` 文件后,请使用 `tools/check_hbc_specs.py`。标签:Click, HBC, Hermes, Python, React Native, SOC Prime, VPS部署, Wayback Machine, 云资产清单, 代码分析, 凭证管理, 反汇编, 字节码, 安全规则引擎, 开发工具, 恶意代码分析, 无后门, 汇编, 目录枚举, 移动安全, 移动应用安全, 网络信息收集, 解析器, 软件分析, 逆向工具, 逆向工程, 配置文件