Metadata-Version: 2.4
Name: ida-batch-decompile
Version: 0.1.0
Summary: IDA Pro batch decompiler tool - use idat to batch decompile binary files to C code
Author: IDA2C Auto
License: MIT
Project-URL: Homepage, https://github.com/yourorg/ida-batch-decompile
Project-URL: Documentation, https://github.com/yourorg/ida-batch-decompile#readme
Project-URL: Repository, https://github.com/yourorg/ida-batch-decompile.git
Project-URL: Issues, https://github.com/yourorg/ida-batch-decompile/issues
Keywords: ida,ida-pro,decompiler,reverse-engineering,idaapi,hex-rays
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Software Development :: Disassemblers
Classifier: Topic :: Security
Requires-Python: >=3.7
Description-Content-Type: text/markdown

# IDA Pro 批量反编译工具

使用 IDA Pro 的命令行工具 `idat` 配合 IDAPython 批量反编译二进制文件，生成干净的 C 代码。

## 功能特性

- 扫描目录并自动识别可执行文件和共享库
- 使用 Hex-Rays `decompile_many` API 生成高质量的 C 代码
- 支持并行处理
- 自动等待分析完成
- 支持 Mach-O、ELF、PE 等格式

## 依赖

- IDA Pro 6.9+（推荐 9.0+）
- Python 3.x

## 安装

将工具放入你的 IDA Pro 目录，确保 `idat` 可执行文件可访问。

## 使用方法

### 基本用法

```bash
# 扫描目录并批量反编译
python3 idb_batch_decompile.py -i <输入目录> -o <输出目录>

# 指定 idat 路径
python3 idb_batch_decompile.py \
  -i /path/to/binaries \
  -o ./output \
  -p "/Applications/IDA Professional 9.1.app/Contents/MacOS/idat"

# 详细输出
python3 idb_batch_decompile.py -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` | 显示帮助信息 |

### 示例

```bash
# 处理单个文件
python3 idb_batch_decompile.py -i ./hello -o ./output

# 处理整个目录
python3 idb_batch_decompile.py -i ./binaries -o ./decompiled

# 使用 8 个并行进程
python3 idb_batch_decompile.py -i ./binaries -o ./output -j 8

# 增加超时时间（处理大型文件）
python3 idb_batch_decompile.py -i ./binaries -o ./output -t 600
```

## 输出格式

生成的 C 文件格式如下：

```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`。

## 目录结构

```
ida2c_auto/
├── idb_batch_decompile.py    # 主工具脚本
├── idapython_export_c.py     # IDAPython 导出脚本
├── README.md                 # 本文件
├── test_code/                # 测试文件目录
│   ├── hello.c
│   ├── math_lib.c
│   ├── string_utils.c
│   └── ...
└── test_output/              # 测试输出目录
    ├── hello.c
    ├── math_lib.c
    ├── string_utils.c
    └── ...
```

## 实现原理

工具使用 `ida_hexrays.decompile_many()` API：

1. 使用 `idat -A` 以自动模式加载二进制文件
2. 等待 IDA 自动分析完成
3. 调用 `decompile_many()` 导出所有函数的 C 代码
4. 保存为 `.c` 文件

这与 IDA GUI 的"导出 C 代码"功能使用相同的底层 API，因此输出质量相同。

## 注意事项

- 确保 IDA Pro 已正确安装且 `idat` 可执行文件存在
- 某些保护/混淆的二进制文件可能无法完整反编译
- 处理大型文件时可能需要增加超时时间
- 并行处理时请注意系统资源限制

## 许可证

本工具仅供学习和研究使用。请遵守 IDA Pro 的使用协议。
