Skip to content

Commit 46352cc

Browse files
Make SSVM use java 8 runtime classes (#112)
* Make SSVM use java 8 runtime classes * change log level so it would be seen in tests * println * allow rtJarPath to be passed as property * typo * add readme
1 parent f45d172 commit 46352cc

File tree

9 files changed

+662
-11
lines changed

9 files changed

+662
-11
lines changed

README.md

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,39 @@ A deobfuscator for java
66
## ✅ How to run deobfuscator
77
If you want to use this deobfuscator, you need to start it from your IDE manually.
88

9+
### Prerequisites
10+
**Important:** You need TWO different Java installations:
11+
- **[Java 17](https://adoptium.net/temurin/releases/?version=17)** - Required for the project to compile and run
12+
- **[Java 8](https://adoptium.net/temurin/releases/?version=8)** - Required for the sandbox (SSVM) to work properly
13+
14+
### Instructions
915
1. Clone this repository and open it in IntelliJ
10-
2. Make sure that you have selected [Java 17 (Temurin)](https://adoptium.net/temurin/releases/?version=17) in `Project Structure` -> `SDK`
11-
3. Place your obfuscated jar inside the root project directory. For example in `work/obf-test.jar`
12-
4. Navigate to class [`Bootstrap.java`](./deobfuscator-impl/src/test/java/Bootstrap.java)
13-
5. In this class edit the deobfuscator configuration
14-
- `inputJar` - Your obfuscated jar file that you placed in step 1
16+
2. Make sure that you have selected [Java 17](https://adoptium.net/temurin/releases/?version=17) in `Project Structure` -> `SDK`
17+
3. Install [Java 8](https://adoptium.net/temurin/releases/?version=8) if you don't have it already
18+
4. Place your obfuscated jar inside the root project directory. For example in `work/obf-test.jar`
19+
5. Navigate to class [`Bootstrap.java`](./deobfuscator-impl/src/test/java/Bootstrap.java)
20+
6. In this class edit the deobfuscator configuration
21+
- `inputJar` - Your obfuscated jar file that you placed in step 4
1522
- `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.
16-
6. Run this class manually from your IDE. You can use our pre-configured IntelliJ task named `Bootstrap`.
23+
7. Run this class manually from your IDE. You can use our pre-configured IntelliJ task named `Bootstrap`.
1724

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

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

30+
## ❓ FAQ
31+
32+
**Q: Sandbox doesn't work / "rt.jar is required for sandbox to run" error**
33+
34+
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:
35+
- Make sure you have [Java 8](https://adoptium.net/temurin/releases/?version=8) installed
36+
- You can manually set it via system property: `-DrtJarPath="path/to/rt.jar"`
37+
- Or specify it in your Bootstrap configuration: `.rtJarPath(Path.of("path/to/rt.jar"))`
38+
- Common rt.jar locations (may vary based on installation):
39+
- Oracle JDK 8: `C:/Program Files/Java/jdk1.8.0_202/jre/lib/rt.jar`
40+
- Eclipse Adoptium JDK 8: `C:/Program Files/Eclipse Adoptium/jdk-8.0.462.8-hotspot/jre/lib/rt.jar`
41+
2342
## Links
2443

2544
<a href="https://discord.gg/tRU27KtPAZ"><img src="https://discordapp.com/api/guilds/900083350314811432/widget.png?style=banner2"/></a>

deobfuscator-api/src/main/java/uwu/narumi/deobfuscator/api/context/DeobfuscatorOptions.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package uwu.narumi.deobfuscator.api.context;
22

3+
import org.apache.logging.log4j.LogManager;
4+
import org.apache.logging.log4j.Logger;
35
import org.intellij.lang.annotations.MagicConstant;
46
import org.jetbrains.annotations.Contract;
57
import org.jetbrains.annotations.Nullable;
68
import org.objectweb.asm.ClassWriter;
9+
import uwu.narumi.deobfuscator.api.environment.JavaEnv;
10+
import uwu.narumi.deobfuscator.api.environment.JavaInstall;
11+
import uwu.narumi.deobfuscator.api.execution.SandBox;
712
import uwu.narumi.deobfuscator.api.transformer.Transformer;
813

914
import java.io.IOException;
@@ -15,6 +20,7 @@
1520
import java.util.ArrayList;
1621
import java.util.HashSet;
1722
import java.util.List;
23+
import java.util.Optional;
1824
import java.util.Set;
1925
import java.util.function.Supplier;
2026

@@ -25,6 +31,7 @@ public record DeobfuscatorOptions(
2531
@Nullable Path inputJar,
2632
List<ExternalFile> externalFiles,
2733
Set<Path> libraries,
34+
@Nullable Path rtJarPath,
2835

2936
@Nullable Path outputJar,
3037
@Nullable Path outputDir,
@@ -53,11 +60,15 @@ public record ExternalFile(Path path, String pathInJar) {
5360
* Builder for {@link DeobfuscatorOptions}
5461
*/
5562
public static class Builder {
63+
private static final Logger LOGGER = LogManager.getLogger();
64+
5665
// Inputs
5766
@Nullable
5867
private Path inputJar = null;
5968
private final List<ExternalFile> externalFiles = new ArrayList<>();
6069
private final Set<Path> libraries = new HashSet<>();
70+
@Nullable
71+
private Path rtJarPath = null;
6172

6273
// Outputs
6374
@Nullable
@@ -161,6 +172,18 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
161172
return this;
162173
}
163174

175+
/**
176+
* Path to rt.jar from Java 8 binaries. Required for sandbox to work properly.
177+
* Examples:
178+
* - Oracle JDK 8: <code>C:/Program Files/Java/jdk1.8.0_202/jre/lib/rt.jar</code>
179+
* - Eclipse Adoptium JDK 8: <code>C:/Program Files/Eclipse Adoptium/jdk-8.0.462.8-hotspot/jre/lib/rt.jar</code>
180+
*/
181+
@Contract("_ -> this")
182+
public DeobfuscatorOptions.Builder rtJarPath(@Nullable Path rtJarPath) {
183+
this.rtJarPath = rtJarPath;
184+
return this;
185+
}
186+
164187
/**
165188
* Output jar for deobfuscated classes. Automatically filled when input jar is set
166189
*/
@@ -255,6 +278,30 @@ public DeobfuscatorOptions.Builder skipFiles() {
255278
return this;
256279
}
257280

281+
/**
282+
* Try to find rt.jar from Java 8 installation
283+
*/
284+
@Nullable
285+
private Path findRtJarPath() {
286+
String userDefinedRtJarPath = System.getProperty("rtJarPath");
287+
if (userDefinedRtJarPath != null) {
288+
return Path.of(userDefinedRtJarPath);
289+
}
290+
291+
Optional<JavaInstall> javaInstall = JavaEnv.getJavaInstalls().stream()
292+
.filter(javaInstall1 -> javaInstall1.version() == 8)
293+
.findFirst();
294+
295+
if (javaInstall.isPresent()) {
296+
JavaInstall install = javaInstall.get();
297+
Path possibleRtJarPath = install.javaExecutable().getParent().getParent().resolve("jre").resolve("lib").resolve("rt.jar");
298+
if (Files.exists(possibleRtJarPath)) {
299+
return possibleRtJarPath;
300+
}
301+
}
302+
return null;
303+
}
304+
258305
/**
259306
* Build immutable {@link DeobfuscatorOptions} with options verification
260307
*/
@@ -269,12 +316,23 @@ public DeobfuscatorOptions build() {
269316
if (this.outputJar != null && this.outputDir != null) {
270317
throw new IllegalStateException("Output jar and output dir cannot be set at the same time");
271318
}
319+
// Try to auto-detect rt.jar path
320+
if (this.rtJarPath == null) {
321+
Path rtJar = findRtJarPath();
322+
if (rtJar != null) {
323+
System.out.println("Auto-detected rt.jar path: " + rtJar);
324+
this.rtJarPath = rtJar;
325+
} else {
326+
LOGGER.warn("Failed to auto-detect rt.jar path. Please provide path to rt.jar from Java 8 binaries, otherwise sandbox will not work.");
327+
}
328+
}
272329

273330
return new DeobfuscatorOptions(
274331
// Input
275332
inputJar,
276333
externalFiles,
277334
libraries,
335+
rtJarPath,
278336
// Output
279337
outputJar,
280338
outputDir,

0 commit comments

Comments
 (0)