Batch decompiler for binary files using IDA Pro's idat command-line tool
Project description
IDA Pro 批量反编译工具
使用 IDA Pro 的命令行工具 idat 配合 IDAPython 批量反编译二进制文件,生成干净的 C 代码。
功能特性
- 扫描目录并自动识别可执行文件和共享库
- 使用 Hex-Rays
decompile_manyAPI 生成高质量的 C 代码 - 支持并行处理
- 自动等待分析完成
- 支持 Mach-O、ELF、PE 等格式
依赖
- IDA Pro 6.9+(推荐 9.0+)
- Python 3.x
安装
使用 pip 安装
# 从 PyPI 安装
pip install ida-batch-decompile
# 从源码安装
pip install .
使用方法
作为 Python 库使用
安装后,你可以将此工具作为 Python 库导入使用:
from ida_batch_decompile import IDABatchDecompiler, BinaryScanner
# 创建反编译器实例
decompiler = IDABatchDecompiler(
idat_path="/Applications/IDA Professional 9.1.app/Contents/MacOS/idat",
output_dir="./output",
jobs=4,
timeout=300,
verbose=True
)
# 方式 1: 反编译单个文件
result = decompiler.decompile_binary("./binaries/hello")
if result[0]:
print(f"成功: {result[1]}")
else:
print(f"失败: {result[1]}")
# 方式 2: 反编译整个目录
results = decompiler.decompile_directory("./binaries")
for path, (success, msg) in results.items():
print(f"{path}: {'成功' if success else '失败'} - {msg}")
# 方式 3: 批量反编译指定文件列表
files = ["./binaries/hello", "./binaries/libutil.so"]
results = decompiler.decompile_batch(files, parallel=True)
# 使用 BinaryScanner 扫描二进制文件
scanner = BinaryScanner()
binaries = scanner.scan_directory(Path("./binaries"))
print(f"找到 {len(binaries)} 个二进制文件")
API 文档
IDABatchDecompiler
IDABatchDecompiler(
idat_path: str = "/Applications/IDA Professional 9.1.app/Contents/MacOS/idat",
output_dir: str = "./output",
jobs: int = 4,
timeout: int = 300,
verbose: bool = False
)
方法:
| 方法 | 说明 | 返回值 |
|---|---|---|
decompile_binary(path) |
反编译单个文件 | (bool, str) |
decompile_directory(dir) |
反编译目录中所有二进制文件 | Dict[str, Tuple[bool, str]] |
decompile_batch(paths, parallel) |
批量反编译指定文件 | Dict[str, Tuple[bool, str]] |
BinaryScanner
BinaryScanner()
方法:
| 方法 | 说明 | 返回值 |
|---|---|---|
scan_directory(dir) |
扫描目录中的二进制文件 | List[Path] |
find_binaries(dir) |
查找二进制文件 | List[Path] |
is_binary_file(path) |
检查是否为二进制文件 | bool |
detect_file_type(path) |
检测文件类型 | Optional[Tuple[str, str]] |
scan_and_group(dir) |
扫描并按类型分组 | Dict[str, List[Path]] |
命令行方式
# 扫描目录并批量反编译
ida-decompile -i <输入目录> -o <输出目录>
# 指定 idat 路径
ida-decompile \
-i /path/to/binaries \
-o ./output \
-p /path/to/idat
# 详细输出
ida-decompile -i ./binaries -o ./output -v
完整参数
| 参数 | 说明 |
|---|---|
-i, --input-dir |
要扫描的输入目录或单个二进制文件 |
-o, --output-dir |
C 文件输出目录 |
-p, --idat-path |
idat 可执行文件路径 |
-j, --jobs |
并行处理的进程数 (默认: 4) |
-t, --timeout |
每个文件的超时时间,单位秒 (默认: 300) |
-v, --verbose |
显示详细输出 |
-h, --help |
显示帮助信息 |
示例
# 处理单个文件
ida-decompile -i ./hello -o ./output
# 处理整个目录
ida-decompile -i ./binaries -o ./decompiled
# 使用 8 个并行进程
ida-decompile -i ./binaries -o ./output -j 8
# 增加超时时间(处理大型文件)
ida-decompile -i ./binaries -o ./output -t 600
输出格式
生成的 C 文件格式如下:
/* This file was generated by the Hex-Rays decompiler version 9.1.0.250226.
Copyright (c) 2007-2021 Hex-Rays <info@hex-rays.com>
Detected compiler: GNU C++
*/
#include <defs.h>
//-------------------------------------------------------------------------
// Function declarations
int __fastcall main(int argc, const char **argv, const char **envp);
int printf(const char *, ...);
//----- (0000000100000460) ----------------------------------------------------
int __fastcall main(int argc, const char **argv, const char **envp)
{
printf("Hello, World!\n");
return 0;
}
输出文件以原二进制文件名命名,例如 hello → hello.c。
实现原理
工具使用 ida_hexrays.decompile_many() API:
- 使用
idat -A以自动模式加载二进制文件 - 等待 IDA 自动分析完成
- 调用
decompile_many()导出所有函数的 C 代码 - 保存为
.c文件
这与 IDA GUI 的"导出 C 代码"功能使用相同的底层 API,因此输出质量相同。
注意事项
- 确保 IDA Pro 已正确安装且
idat可执行文件存在 - 某些保护/混淆的二进制文件可能无法完整反编译
- 处理大型文件时可能需要增加超时时间
- 并行处理时请注意系统资源限制
- idat 路径需要根据你的 IDA Pro 安装位置调整
许可证
本工具仅供学习和研究使用。请遵守 IDA Pro 的使用协议。
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ida_batch_decompile-0.2.4.tar.gz.
File metadata
- Download URL: ida_batch_decompile-0.2.4.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0abde550039dab7959b1850861f02de97a78f1491b8bcbb1fe3d0b119793519a
|
|
| MD5 |
fa80de865576f90c1abdfd3bcd89bb8f
|
|
| BLAKE2b-256 |
0696724bde0bc2306c9020bc9644cc6f2b1a2537bea36824cc9df7013ea6f9fc
|
File details
Details for the file ida_batch_decompile-0.2.4-py3-none-any.whl.
File metadata
- Download URL: ida_batch_decompile-0.2.4-py3-none-any.whl
- Upload date:
- Size: 14.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ac673652077338ed664a5837aadc2b30e1d7d25636704e7af67c4a5a4b2b0dd
|
|
| MD5 |
c09f4aa3a2a9278ac3469780d4e87c8a
|
|
| BLAKE2b-256 |
b3bd9020d2052e4e8ee3b7c10575b0ff373fc60bc44f997be2301993640bf252
|