---
name: decompile-classes
description: Decompile Java .class files back to source code. Use when user wants to restore compiled Java projects, reverse engineer class files, or convert bytecode to readable Java source.
version: 1.0.0
---

# Java Class Decompilation Guide

This skill guides the decompilation of Java .class files back to readable source code.

## When to Use

- User has compiled .class files without source code
- User wants to restore a Java project from compiled artifacts
- User needs to understand legacy compiled code
- User wants to reverse engineer a Java application

## Decompilation Process

### Step 1: Assess the Project

Before decompiling, gather information:

```bash
# Count class files
find <classes_dir> -name "*.class" | wc -l

# List package structure
find <classes_dir> -name "*.class" | sed 's|/[^/]*\.class$||' | sort -u

# Check for inner classes
find <classes_dir> -name "*\$*.class" | wc -l
```

### Step 2: Download CFR Decompiler

CFR is the recommended decompiler for modern Java:

```bash
# Download to plugin scripts directory
curl -L -o scripts/cfr.jar https://github.com/leibnitz27/cfr/releases/download/0.152/cfr-0.152.jar
```

### Step 3: Run Batch Decompilation

Use the decompile script:

```bash
bash C:/Users/K/.claude/plugins/cache/claude-plugins-official/plugin-dev/9eae436aa296/scripts/decompile.sh <input_dir> <output_dir>
```

Or decompile individual files:

```bash
java -jar cfr.jar MyClass.class --outputdir ./src
```

### Step 4: Handle Decompilation Issues

Common issues and solutions:

| Issue | Solution |
|-------|----------|
| Enum classes | CFR handles these well by default |
| Lambda expressions | Use `--decodelambdas true` |
| Inner classes | CFR outputs them as separate files |
| Obfuscated code | Use `--renamedupmembers true` |
| Missing dependencies | Add classpath with `--extraclasspath` |

### Step 5: Verify Decompiled Code

After decompilation:

1. Check file count matches original
2. Look for decompilation errors in output
3. Verify package structure is preserved
4. Spot-check complex classes for correctness

## CFR Command Options

```
java -jar cfr.jar <input> [options]

Options:
  --outputdir <dir>     Output directory
  --silent              Suppress progress output
  --decodelambdas       Decode lambda expressions
  --decodestringswitch  Decode string switches
  --decodeswitch        Decode switch statements
  --renamedupmembers    Rename duplicate members
  --removeboilerplate   Remove boilerplate code
  --removeinnerclasses  Remove inner class references
  --showinferredlambdaithrows  Show inferred lambda throws
  --extraclasspath <path>  Additional classpath for dependencies
```

## Post-Decompilation

After successful decompilation:

1. Run `analyze-structure` to understand the project
2. Run `generate-project` to create Maven/Gradle structure
3. Run `analyze-dependencies` to map dependencies
4. Review and fix any decompilation artifacts

## Tips

- **Large projects**: Process in batches to manage memory
- **Error recovery**: CFR is resilient, but check output for errors
- **Naming conflicts**: Inner classes may cause naming issues
- **Encoding**: Ensure UTF-8 for Chinese/Unicode content
- **Dependencies**: Some classes may reference external JARs
