Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,39 @@ A deobfuscator for java
## ✅ How to run deobfuscator
If you want to use this deobfuscator, you need to start it from your IDE manually.

### Prerequisites
**Important:** You need TWO different Java installations:
- **[Java 17](https://adoptium.net/temurin/releases/?version=17)** - Required for the project to compile and run
- **[Java 8](https://adoptium.net/temurin/releases/?version=8)** - Required for the sandbox (SSVM) to work properly

### Instructions
1. Clone this repository and open it in IntelliJ
2. Make sure that you have selected [Java 17 (Temurin)](https://adoptium.net/temurin/releases/?version=17) in `Project Structure` -> `SDK`
3. Place your obfuscated jar inside the root project directory. For example in `work/obf-test.jar`
4. Navigate to class [`Bootstrap.java`](./deobfuscator-impl/src/test/java/Bootstrap.java)
5. In this class edit the deobfuscator configuration
- `inputJar` - Your obfuscated jar file that you placed in step 1
2. Make sure that you have selected [Java 17](https://adoptium.net/temurin/releases/?version=17) in `Project Structure` -> `SDK`
3. Install [Java 8](https://adoptium.net/temurin/releases/?version=8) if you don't have it already
4. Place your obfuscated jar inside the root project directory. For example in `work/obf-test.jar`
5. Navigate to class [`Bootstrap.java`](./deobfuscator-impl/src/test/java/Bootstrap.java)
6. In this class edit the deobfuscator configuration
- `inputJar` - Your obfuscated jar file that you placed in step 4
- `transformers` - Pick transformers that you want to run. You can find them in [`deobfuscator-transformers`](./deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other) module.
6. Run this class manually from your IDE. You can use our pre-configured IntelliJ task named `Bootstrap`.
7. Run this class manually from your IDE. You can use our pre-configured IntelliJ task named `Bootstrap`.

![tak](./assets/run-deobfuscator.gif)

## 🔧 Contributing
Contributions are welcome! See [CONTRIBUTING.md](./CONTRIBUTING.md) for a project introduction and some basics about java bytecode.

## ❓ FAQ

**Q: Sandbox doesn't work / "rt.jar is required for sandbox to run" error**

A: The sandbox requires rt.jar from **[Java 8](https://adoptium.net/temurin/releases/?version=8)** installation. The deobfuscator will try to auto-detect it, but if it fails:
- Make sure you have [Java 8](https://adoptium.net/temurin/releases/?version=8) installed
- You can manually set it via system property: `-DrtJarPath="path/to/rt.jar"`
- Or specify it in your Bootstrap configuration: `.rtJarPath(Path.of("path/to/rt.jar"))`
- Common rt.jar locations (may vary based on installation):
- Oracle JDK 8: `C:/Program Files/Java/jdk1.8.0_202/jre/lib/rt.jar`
- Eclipse Adoptium JDK 8: `C:/Program Files/Eclipse Adoptium/jdk-8.0.462.8-hotspot/jre/lib/rt.jar`

## Links

<a href="https://discord.gg/tRU27KtPAZ"><img src="https://discordapp.com/api/guilds/900083350314811432/widget.png?style=banner2"/></a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package uwu.narumi.deobfuscator.api.context;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.intellij.lang.annotations.MagicConstant;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Nullable;
import org.objectweb.asm.ClassWriter;
import uwu.narumi.deobfuscator.api.environment.JavaEnv;
import uwu.narumi.deobfuscator.api.environment.JavaInstall;
import uwu.narumi.deobfuscator.api.execution.SandBox;
import uwu.narumi.deobfuscator.api.transformer.Transformer;

import java.io.IOException;
Expand All @@ -15,6 +20,7 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Supplier;

Expand All @@ -25,6 +31,7 @@ public record DeobfuscatorOptions(
@Nullable Path inputJar,
List<ExternalFile> externalFiles,
Set<Path> libraries,
@Nullable Path rtJarPath,

@Nullable Path outputJar,
@Nullable Path outputDir,
Expand Down Expand Up @@ -53,11 +60,15 @@ public record ExternalFile(Path path, String pathInJar) {
* Builder for {@link DeobfuscatorOptions}
*/
public static class Builder {
private static final Logger LOGGER = LogManager.getLogger();

// Inputs
@Nullable
private Path inputJar = null;
private final List<ExternalFile> externalFiles = new ArrayList<>();
private final Set<Path> libraries = new HashSet<>();
@Nullable
private Path rtJarPath = null;

// Outputs
@Nullable
Expand Down Expand Up @@ -161,6 +172,18 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
return this;
}

/**
* Path to rt.jar from Java 8 binaries. Required for sandbox to work properly.
* Examples:
* - Oracle JDK 8: <code>C:/Program Files/Java/jdk1.8.0_202/jre/lib/rt.jar</code>
* - Eclipse Adoptium JDK 8: <code>C:/Program Files/Eclipse Adoptium/jdk-8.0.462.8-hotspot/jre/lib/rt.jar</code>
*/
@Contract("_ -> this")
public DeobfuscatorOptions.Builder rtJarPath(@Nullable Path rtJarPath) {
this.rtJarPath = rtJarPath;
return this;
}

/**
* Output jar for deobfuscated classes. Automatically filled when input jar is set
*/
Expand Down Expand Up @@ -255,6 +278,30 @@ public DeobfuscatorOptions.Builder skipFiles() {
return this;
}

/**
* Try to find rt.jar from Java 8 installation
*/
@Nullable
private Path findRtJarPath() {
String userDefinedRtJarPath = System.getProperty("rtJarPath");
if (userDefinedRtJarPath != null) {
return Path.of(userDefinedRtJarPath);
}

Optional<JavaInstall> javaInstall = JavaEnv.getJavaInstalls().stream()
.filter(javaInstall1 -> javaInstall1.version() == 8)
.findFirst();

if (javaInstall.isPresent()) {
JavaInstall install = javaInstall.get();
Path possibleRtJarPath = install.javaExecutable().getParent().getParent().resolve("jre").resolve("lib").resolve("rt.jar");
if (Files.exists(possibleRtJarPath)) {
return possibleRtJarPath;
}
}
return null;
}

/**
* Build immutable {@link DeobfuscatorOptions} with options verification
*/
Expand All @@ -269,12 +316,23 @@ public DeobfuscatorOptions build() {
if (this.outputJar != null && this.outputDir != null) {
throw new IllegalStateException("Output jar and output dir cannot be set at the same time");
}
// Try to auto-detect rt.jar path
if (this.rtJarPath == null) {
Path rtJar = findRtJarPath();
if (rtJar != null) {
System.out.println("Auto-detected rt.jar path: " + rtJar);
this.rtJarPath = rtJar;
} else {
LOGGER.warn("Failed to auto-detect rt.jar path. Please provide path to rt.jar from Java 8 binaries, otherwise sandbox will not work.");
}
}

return new DeobfuscatorOptions(
// Input
inputJar,
externalFiles,
libraries,
rtJarPath,
// Output
outputJar,
outputDir,
Expand Down
Loading