Skip to content

Commit 0031a94

Browse files
Col-EItzSomebody
authored andcommitted
Fix cases where runtime classes like 'java.awt.bla' were not found, leading to bad frame generation
1 parent 9f64166 commit 0031a94

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/main/java/com/javadeobfuscator/deobfuscator/Deobfuscator.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.apache.commons.io.IOUtils;
4848
import org.objectweb.asm.ClassReader;
4949
import org.objectweb.asm.ClassWriter;
50+
import org.objectweb.asm.Opcodes;
5051
import org.objectweb.asm.commons.JSRInlinerAdapter;
5152
import org.objectweb.asm.tree.AbstractInsnNode;
5253
import org.objectweb.asm.tree.ClassNode;
@@ -64,6 +65,7 @@ public class Deobfuscator {
6465

6566
private final Configuration configuration;
6667

68+
private final Set<String> missingRefs = new HashSet<>();
6769
private final Map<String, ClassNode> classpath = new HashMap<>();
6870
private final Map<String, ClassNode> libraries = new HashMap<>();
6971
private final Map<String, ClassNode> classes = new HashMap<>();
@@ -480,6 +482,11 @@ public boolean runFromConfig(TransformerConfig config) throws Throwable {
480482

481483
public ClassNode assureLoaded(String ref) {
482484
ClassNode clazz = classpath.get(ref);
485+
// Attempt to fetch from runtime, cases like 'java/awt/bla' can be loaded this way
486+
if (clazz == null) {
487+
clazz = pullFromRuntime(ref);
488+
}
489+
// Still missing, cannot recover
483490
if (clazz == null) {
484491
throw new NoClassInPathException(ref);
485492
}
@@ -496,6 +503,23 @@ public ClassNode assureLoadedElseRemove(String referencer, String ref) {
496503
return clazz;
497504
}
498505

506+
private ClassNode pullFromRuntime(String ref) {
507+
try {
508+
if (!missingRefs.contains(ref)) {
509+
// Realistically we do not need the method bodies at all, can skip.
510+
ClassNode node = new ClassNode(Opcodes.ASM9);
511+
new ClassReader(ref).accept(node, ClassReader.SKIP_CODE);
512+
classpath.put(ref, node);
513+
return node;
514+
}
515+
} catch (IOException ex) {
516+
// Ignored, plenty of cases where ref will not exist at runtime.
517+
// Cache missing value so that we don't try again later.
518+
missingRefs.add(ref);
519+
}
520+
return null;
521+
}
522+
499523
public void loadHierachy() {
500524
Set<String> processed = new HashSet<>();
501525
LinkedList<ClassNode> toLoad = new LinkedList<>(this.classes.values());

0 commit comments

Comments
 (0)