Skip to content

Commit 7362c70

Browse files
committed
[功能] 支持 --decompile 参数反编译指定类 @4ra1n
1 parent 118ecc6 commit 7362c70

File tree

178 files changed

+34962
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

178 files changed

+34962
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 1.2.0
2+
3+
更新日志:
4+
5+
- [功能] 支持 `--decompile` 参数反编译指定类 @4ra1n
6+
17
## 1.1.0
28

39
更新日志:

README.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
> [English Version](README_EN.md)
2424
25-
[更新日志](CHANGLOG.md)
25+
[更新日志](CHANGELOG.md)
2626

2727
## 📖 简介
2828

@@ -47,6 +47,7 @@
4747
- 📦 **Spring Boot / WAR 支持** — 嵌套 JAR 解析、类名修正,完美适配 Fat JAR
4848
- 🛡️ **安全防护** — 内置 Zip Slip 路径穿越攻击防御,损坏类文件自动容错
4949
- 🔌 **双模式使用** — 既可作为 CLI 工具独立运行,也可作为 Java 库集成到项目中
50+
- 🔓 **内置反编译** — 集成 FernFlower 反编译引擎,支持 CLI 直接反编译指定类并输出源码
5051

5152
## 🚀 快速开始
5253

@@ -76,6 +77,11 @@ java -jar jar-analyzer-engine.jar --jar /path/to/app.jar
7677
# 分析目录下所有 JAR
7778
java -jar jar-analyzer-engine.jar --jar /path/to/libs/
7879

80+
# 反编译指定类(需先 build 或指定 --jar 自动 build)
81+
java -jar jar-analyzer-engine.jar --decompile com.example.MyClass
82+
83+
# 首次使用,自动 build + 反编译
84+
java -jar jar-analyzer-engine.jar --jar /path/to/app.jar --decompile com.example.MyClass
7985
```
8086

8187
分析完成后将在当前目录生成 SQLite 数据库文件 `jar-analyzer.db`,可使用任何 SQLite 客户端工具查询。分析过程中的临时文件存放在 `jar-analyzer-temp` 目录中,分析完成后可手动删除。
@@ -101,6 +107,7 @@ java -jar jar-analyzer-engine.jar --jar /path/to/libs/
101107
| `--white-list <text>` | `-w` || 类/包白名单(内联文本) |
102108
| `--black-list-file <file>` ||| 从文件读取黑名单 |
103109
| `--white-list-file <file>` ||| 从文件读取白名单 |
110+
| `--decompile <class>` | `-d` || 反编译指定类并输出源码到控制台(如 `com.example.MyClass`|
104111
| `--help` | `-h` || 显示帮助信息 |
105112

106113
## 📚 参数详解
@@ -198,6 +205,28 @@ java -jar jar-analyzer-engine.jar --jar springboot-app.jar --inner-jars --fix-cl
198205
java -jar jar-analyzer-engine.jar --jar app.jar --no-fix-impl
199206
```
200207

208+
### `--decompile` / `-d`(反编译模式)
209+
210+
指定一个类的全限定名,引擎会从 `jar-analyzer-temp` 临时目录中查找对应的 class 文件,使用内置的 FernFlower 反编译引擎将其反编译为 Java 源码,并输出到控制台。
211+
212+
支持的类名格式:
213+
- 点分隔:`com.example.service.UserService`
214+
- 斜杠分隔:`com/example/service/UserService`
215+
216+
引擎会自动处理以下情况:
217+
- **Spring Boot Fat JAR**:自动搜索 `BOOT-INF/classes/` 前缀
218+
- **WAR 文件**:自动搜索 `WEB-INF/classes/` 前缀
219+
- **内部类**:自动包含 `$` 内部类文件一起反编译
220+
- **模糊匹配**:找不到类时会搜索 temp 目录给出 "Did you mean?" 候选建议
221+
222+
```bash
223+
# 已 build 过(temp 目录存在),直接反编译
224+
java -jar jar-analyzer-engine.jar --decompile com.example.MyClass
225+
226+
# 首次使用,自动 build + 反编译
227+
java -jar jar-analyzer-engine.jar --jar app.jar --decompile com.example.MyClass
228+
```
229+
201230
### 黑白名单过滤
202231

203232
通过黑白名单可以控制哪些类参与分析,减少不必要的分析范围,加速分析过程。
@@ -472,6 +501,19 @@ java -jar jar-analyzer-engine.jar \
472501
--rt /usr/lib/jvm/java-8-openjdk/jre/lib/rt.jar
473502
```
474503

504+
### 6. 反编译指定类查看源码
505+
506+
```bash
507+
# 分析 + 反编译一步完成
508+
java -jar jar-analyzer-engine.jar \
509+
--jar app.jar \
510+
--decompile com.example.service.UserService
511+
512+
# 已 build 过,直接反编译
513+
java -jar jar-analyzer-engine.jar \
514+
--decompile com.example.service.UserService
515+
```
516+
475517
## 🤖 与 AI 集成进行代码审计
476518

477519
生成的 SQLite 数据库天然适合与 AI 工具结合使用,以下是推荐的工作流:
@@ -578,6 +620,9 @@ jar-analyzer-engine/
578620
│ │ ├── mapper/ # MyBatis Mapper 接口 (15个)
579621
│ │ └── reference/ # 核心数据模型
580622
│ ├── entity/ # 数据库实体类 (18个)
623+
│ ├── decompile/ # 反编译模块
624+
│ │ ├── DecompileEngine.java # FernFlower 反编译封装
625+
│ │ └── LRUCache.java # 反编译结果 LRU 缓存
581626
│ └── analyze/spring/ # Spring 框架分析
582627
│ ├── SpringService.java # Spring 分析入口
583628
│ └── asm/ # Spring 注解 ASM 访问器

README_EN.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ The engine is built on the **ASM bytecode analysis framework** and uses a **mult
4545
- 📦 **Spring Boot / WAR Support** — Nested JAR parsing and class name correction, perfectly adapted for Fat JARs
4646
- 🛡️ **Security Protection** — Built-in Zip Slip path traversal attack defense with automatic error tolerance for corrupted class files
4747
- 🔌 **Dual-Mode Usage** — Works as both a standalone CLI tool and an embeddable Java library
48+
- 🔓 **Built-in Decompilation** — Integrated FernFlower decompiler engine, supports CLI decompilation of specific classes with source code output
4849

4950
## 🚀 Quick Start
5051

@@ -74,6 +75,11 @@ java -jar jar-analyzer-engine.jar --jar /path/to/app.jar
7475
# Analyze all JARs in a directory
7576
java -jar jar-analyzer-engine.jar --jar /path/to/libs/
7677

78+
# Decompile a specific class (requires prior build or --jar for auto build)
79+
java -jar jar-analyzer-engine.jar --decompile com.example.MyClass
80+
81+
# First time use: auto build + decompile
82+
java -jar jar-analyzer-engine.jar --jar /path/to/app.jar --decompile com.example.MyClass
7783
```
7884

7985
After analysis, a SQLite database file `jar-analyzer.db` will be generated in the current directory and can be queried with any SQLite client tool. Temporary files during analysis are stored in the `jar-analyzer-temp` directory, which can be manually deleted after analysis completes.
@@ -99,6 +105,7 @@ After analysis, a SQLite database file `jar-analyzer.db` will be generated in th
99105
| `--white-list <text>` | `-w` | None | Class/package whitelist (inline text) |
100106
| `--black-list-file <file>` || None | Read blacklist from file |
101107
| `--white-list-file <file>` || None | Read whitelist from file |
108+
| `--decompile <class>` | `-d` | None | Decompile a specific class and print source to console (e.g. `com.example.MyClass`) |
102109
| `--help` | `-h` || Display help information |
103110

104111
## 📚 Argument Details
@@ -196,6 +203,28 @@ Enabling `--no-fix-impl` disables this behavior, keeping only the **literal dire
196203
java -jar jar-analyzer-engine.jar --jar app.jar --no-fix-impl
197204
```
198205

206+
### `--decompile` / `-d` (Decompile Mode)
207+
208+
Specify a fully-qualified class name, and the engine will locate the corresponding class file in the `jar-analyzer-temp` directory, decompile it to Java source code using the built-in FernFlower decompiler, and output the result to the console.
209+
210+
Supported class name formats:
211+
- Dot-separated: `com.example.service.UserService`
212+
- Slash-separated: `com/example/service/UserService`
213+
214+
The engine automatically handles:
215+
- **Spring Boot Fat JAR**: Searches under `BOOT-INF/classes/` prefix
216+
- **WAR files**: Searches under `WEB-INF/classes/` prefix
217+
- **Inner classes**: Automatically includes `$` inner class files for decompilation
218+
- **Fuzzy matching**: When the class is not found, searches the temp directory and provides "Did you mean?" suggestions
219+
220+
```bash
221+
# Already built (temp directory exists), decompile directly
222+
java -jar jar-analyzer-engine.jar --decompile com.example.MyClass
223+
224+
# First time use: auto build + decompile
225+
java -jar jar-analyzer-engine.jar --jar app.jar --decompile com.example.MyClass
226+
```
227+
199228
### Blacklist & Whitelist Filtering
200229

201230
Blacklists and whitelists allow you to control which classes participate in analysis, reducing unnecessary analysis scope and speeding up the process.
@@ -473,6 +502,19 @@ java -jar jar-analyzer-engine.jar \
473502
--rt /usr/lib/jvm/java-8-openjdk/jre/lib/rt.jar
474503
```
475504

505+
### 6. Decompile a Specific Class
506+
507+
```bash
508+
# Analyze + decompile in one step
509+
java -jar jar-analyzer-engine.jar \
510+
--jar app.jar \
511+
--decompile com.example.service.UserService
512+
513+
# Already built, decompile directly
514+
java -jar jar-analyzer-engine.jar \
515+
--decompile com.example.service.UserService
516+
```
517+
476518
## 🤖 AI Integration for Code Auditing
477519

478520
The generated SQLite database is naturally suited for use with AI tools. Here is the recommended workflow:
@@ -579,6 +621,9 @@ jar-analyzer-engine/
579621
│ │ ├── mapper/ # MyBatis Mapper interfaces (15)
580622
│ │ └── reference/ # Core data models
581623
│ ├── entity/ # Database entity classes (18)
624+
│ ├── decompile/ # Decompilation module
625+
│ │ ├── DecompileEngine.java # FernFlower decompiler wrapper
626+
│ │ └── LRUCache.java # Decompilation result LRU cache
582627
│ └── analyze/spring/ # Spring framework analysis
583628
│ ├── SpringService.java # Spring analysis entry point
584629
│ └── asm/ # Spring annotation ASM visitors

0 commit comments

Comments
 (0)