Skip to main content

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() API 生成高质量的 C 代码
  • 支持并行处理
  • 自动等待分析完成
  • 支持 Mach-O、ELF、PE 等格式

依赖

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

安装

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

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

使用方法

命令行方式

# 查看帮助
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 显示版本号 -

示例

# 处理目录中的所有二进制文件
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 文件格式如下:

/*
 * 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 的使用协议。

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.2.3.tar.gz (12.6 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.2.3-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ida_batch_decompile-0.2.3.tar.gz
  • Upload date:
  • Size: 12.6 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.2.3.tar.gz
Algorithm Hash digest
SHA256 b571e2de715a0c7565dcdf4f187fc34484b9708df75144977a29b89742980239
MD5 a354f8b5d3bd5c8c4a371d5e2a713412
BLAKE2b-256 fa5a93eef8f6b7363a48898d826bac17bb2d7fa1120fb567f58e7eae76b78526

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ida_batch_decompile-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6efff69dcacbf266e8b83391c199d996331a70f8744322d18c5d05e72fba298c
MD5 283ca01f2d32642a5a519f9f86240e65
BLAKE2b-256 681fff3a5eebd7784633fb013fab5c512e7e65a073f8cfc0bcee14f2141d0e4c

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