You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
3.7 KiB
Markdown

# Java Decompilers Reference
## Recommended Decompilers
### 1. CFR (Class File Reader) - Recommended
**Best for**: Modern Java (Java 8+), lambda expressions, enums
- **Download**: https://github.com/leibnitz27/cfr/releases
- **Version**: 0.152
- **Usage**: `java -jar cfr.jar MyClass.class`
**Key features**:
- Excellent Java 8+ support
- Handles modern language features
- Active development
- Command-line interface
### 2. Procyon
**Best for**: Complex generics, enum switch maps
- **Download**: https://github.com/mstrobel/procyon/releases
- **Usage**: `java -jar procyon-decompiler.jar MyClass.class`
### 3. Fernflower
**Best for**: IntelliJ IDEA integration
- **Built into**: IntelliJ IDEA
- **Standalone**: https://github.com/fesh0r/fernflower
- **Usage**: `java -jar fernflower.jar MyClass.class output/`
### 4. JD-GUI
**Best for**: Quick GUI browsing
- **Download**: http://java-decompiler.github.io/
- **Features**: Graphical interface, export source
- **Usage**: Open .class or .jar file in GUI
### 5. JADX
**Best for**: Android DEX/Android bytecode
- **Download**: https://github.com/skylot/jadx
- **Features**: GUI and CLI, Android support
## Decompiler Comparison
| Feature | CFR | Procyon | Fernflower | JD-GUI |
|---------|-----|---------|------------|--------|
| Java 8+ | ✅ | ✅ | ✅ | ⚠️ |
| Lambda | ✅ | ✅ | ✅ | ❌ |
| Enum | ✅ | ✅ | ✅ | ⚠️ |
| Generics | ✅ | ✅ | ✅ | ⚠️ |
| Speed | Fast | Medium | Fast | Fast |
| CLI | ✅ | ✅ | ✅ | ❌ |
| GUI | ❌ | ❌ | ❌ | ✅ |
## CFR Usage Examples
### Basic Decompilation
```bash
# Single file
java -jar cfr.jar MyClass.class
# Output to directory
java -jar cfr.jar MyClass.class --outputdir ./src
# Multiple files
java -jar cfr.jar *.class --outputdir ./src
```
### Advanced Options
```bash
# Decode lambda expressions
java -jar cfr.jar MyClass.class --decodelambdas true
# Remove boilerplate
java -jar cfr.jar MyClass.class --removeboilerplate true
# Handle obfuscated code
java -jar cfr.jar MyClass.class --renamedupmembers true
# Add classpath for dependencies
java -jar cfr.jar MyClass.class --extraclasspath ./lib/*.jar
```
### Batch Processing
```bash
# Decompile all classes in directory
find ./classes -name "*.class" -exec java -jar cfr.jar {} --outputdir ./src \;
# Using xargs for efficiency
find ./classes -name "*.class" | xargs -I {} java -jar cfr.jar {} --outputdir ./src
```
## Troubleshooting
### Common Errors
**ClassFormatError**
- Cause: Corrupted or invalid class file
- Solution: Verify file integrity, re-download if possible
**UnsupportedClassVersionError**
- Cause: Class compiled with newer Java version
- Solution: Use matching or newer Java version to decompile
**NoClassDefFoundError**
- Cause: Missing dependency classes
- Solution: Add dependencies to classpath with `--extraclasspath`
**OutOfMemoryError**
- Cause: Large class file or complex code
- Solution: Increase heap size: `java -Xmx2g -jar cfr.jar ...`
### Performance Tips
1. **Batch processing**: Use xargs or scripts for multiple files
2. **Memory**: Set appropriate heap size for large projects
3. **Parallel**: Process multiple files in parallel
4. **Filtering**: Skip test classes if not needed
## Post-Decompilation
After decompiling:
1. **Verify**: Check output file count matches input
2. **Review**: Spot-check complex files for accuracy
3. **Organize**: Move to proper Maven/Gradle structure
4. **Fix**: Address any decompilation artifacts
5. **Compile**: Test with `mvn compile`
## Resources
- CFR GitHub: https://github.com/leibnitz27/cfr
- Procyon GitHub: https://github.com/mstrobel/procyon
- Fernflower GitHub: https://github.com/fesh0r/fernflower
- JD-GUI: http://java-decompiler.github.io/
- JADX GitHub: https://github.com/skylot/jadx