Skip to main content

IDA Pro batch decompiler tool - use idat to batch decompile binary files to C code

Project description

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 可执行文件可访问。

使用方法

基本用法

# 扫描目录并批量反编译
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 显示帮助信息

示例

# 处理单个文件
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 文件格式如下:

/* 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;
}

输出文件以原二进制文件名命名,例如 hellohello.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 的使用协议。

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

ida_batch_decompile-0.1.0.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ida_batch_decompile-0.1.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file ida_batch_decompile-0.1.0.tar.gz.

File metadata

  • Download URL: ida_batch_decompile-0.1.0.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for ida_batch_decompile-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0b416c6e42cc1c082e9064826d34c1fd74a150e67a15f598788fb8b81db97630
MD5 ec2a9cfb7108c6da070d66b89e8e0d18
BLAKE2b-256 f12d5d0f441762143dce71375a3eba8cbb7309c000fb642d7d5b95ee4c15ddd1

See more details on using hashes here.

File details

Details for the file ida_batch_decompile-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ida_batch_decompile-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 31bfca017f00464ba33838ec969cef6ea77719fc3a885cca6dc21aa4fcb0c05f
MD5 79493754bef5fe97c4141fb2dc1c6c9f
BLAKE2b-256 c938e0606a0ceb9d9eb7bedc6e5adceb41fc0070d111d3a50b65f64e90daf382

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page