Metadata-Version: 2.4
Name: ida-batch-decompile
Version: 0.2.3
Summary: Batch decompiler for binary files using IDA Pro's idat command-line tool
Author-email: kamille-bidan123 <lometsj@live.com>
License: MIT
Project-URL: Homepage, https://github.com/kamille-bidan123/ida2c_auto
Project-URL: Repository, https://github.com/kamille-bidan123/ida2c_auto.git
Project-URL: Issues, https://github.com/kamille-bidan123/ida2c_auto/issues
Keywords: ida,idapro,decompiler,binary,reverse-engineering
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
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.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Security
Classifier: Topic :: Software Development :: Disassemblers
Requires-Python: >=3.7
Description-Content-Type: text/markdown

# IDA Pro 批量反编译工具

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

## 功能特性

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

## 依赖

- IDA Pro 6.9+（推荐 9.0+）
- Python 3.x
- `file` 命令行工具（用于检测二进制文件类型）

## 安装

直接克隆或下载本仓库即可，无需安装额外依赖：

```bash
git clone https://github.com/yourorg/ida-batch-decompile.git
cd ida-batch-decompile
```

## 使用方法

### 命令行方式

```bash
# 查看帮助
python -m ida_batch_decompile --help

# 反编译整个目录
python -m ida_batch_decompile -i <输入目录> -o <输出目录> -p <idat路径>

# 反编译单个文件
python -m ida_batch_decompile -i ./hello -o ./output -p /path/to/idat

# 指定并行进程数和超时时间
python -m ida_batch_decompile -i ./binaries -o ./output -p /path/to/idat -j 8 -t 600
```

### 必填参数

| 参数 | 说明 |
|------|------|
| `-i, --input-dir` | 输入目录或单个二进制文件路径 |
| `-o, --output-dir` | C 文件输出目录 |
| `-p, --idat-path` | idat 可执行文件路径 |

### 可选参数

| 参数 | 说明 | 默认值 |
|------|------|--------|
| `-j, --jobs` | 并行处理的进程数 | 4 |
| `-t, --timeout` | 每个文件的超时时间（秒） | 300 |
| `-v, --verbose` | 显示详细输出 | 否 |
| `-h, --help` | 显示帮助信息 | - |
| `--version` | 显示版本号 | - |

### 示例

```bash
# 处理目录中的所有二进制文件
python -m ida_batch_decompile -i ./binaries -o ./output -p /Applications/IDA\\ Professional\\ 9.1.app/Contents/MacOS/idat

# 处理单个文件
python -m ida_batch_decompile -i ./hello -o ./output -p /Applications/IDA\\ Professional\\ 9.1.app/Contents/MacOS/idat

# 使用 8 个并行进程
python -m ida_batch_decompile -i ./binaries -o ./output -p /path/to/idat -j 8

# 增加超时时间（处理大型文件）
python -m ida_batch_decompile -i ./binaries -o ./output -p /path/to/idat -t 600

# 显示详细处理过程
python -m ida_batch_decompile -i ./binaries -o ./output -p /path/to/idat -v
```

## 输出格式

生成的 C 文件格式如下：

```c
/*
 * File: hello_decompiled.c
 * Generated from: hello
 * Generated at: 2024-01-15 10:30:00
 * Total functions: 15
 */

#include <stdint.h>
#include <stddef.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;
}
```

- 输出文件以 `原文件名_decompiled.c` 命名
- 每个函数包含地址和顺序信息的注释
- 使用 `=` 分隔不同函数

## 实现原理

工具使用 IDA Pro 的 `idaapi.decompile()` API：

1. 使用 `idat -A` 以自动模式加载二进制文件
2. 等待 IDA 自动分析完成
3. 执行 IDAPython 脚本调用 `decompile()` 反编译所有函数
4. 将所有函数的 C 代码合并到一个文件中

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

## 注意事项

- 确保 IDA Pro 已正确安装且 `idat` 可执行文件存在
- 某些保护/混淆的二进制文件可能无法完整反编译
- 处理大型文件时可能需要增加超时时间
- 并行处理时请注意系统资源限制
- idat 路径需要根据你的 IDA Pro 安装位置调整
- macOS 用户注意：如果 IDA Pro 位于 `/Applications` 目录，可能需要添加执行权限

## 许可证

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