Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ASM errors when decompiling files obfuscated by Binscure, ESkid and others #72

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ dependencies {
implementation("com.github.leibnitz27:cfr") { isChanging = true }
implementation("ch.qos.logback:logback-classic")

implementation("com.github.Col-E:CAFED00D:1.8.0")

externalLib("fernflower-15-05-20")
}
5 changes: 5 additions & 0 deletions core/src/main/java/me/nov/threadtear/io/Conversion.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.nio.file.Files;

import me.nov.threadtear.logging.LogWrapper;
import me.nov.threadtear.util.asm.SignatureValidator;
import org.objectweb.asm.*;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.util.TraceClassVisitor;
Expand Down Expand Up @@ -41,6 +42,10 @@ public static ClassNode toNode(final byte[] bytez) {
LogWrapper.logger.error("Failed to load class ", e2);
}
}

// validate signatures
SignatureValidator.validateSignatures(cn);

return cn;
}

Expand Down
10 changes: 10 additions & 0 deletions core/src/main/java/me/nov/threadtear/io/JarIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import java.util.stream.Stream;
import java.util.zip.ZipException;

import me.coley.cafedude.ClassFile;
import me.coley.cafedude.io.ClassFileReader;
import me.coley.cafedude.io.ClassFileWriter;
import me.nov.threadtear.logging.LogWrapper;
import org.apache.commons.io.IOUtils;
import org.objectweb.asm.tree.ClassNode;
Expand All @@ -29,8 +32,15 @@ private static ArrayList<Clazz> readEntry(JarFile jar, JarEntry en, ArrayList<Cl
String name = en.getName();
try (InputStream jis = jar.getInputStream(en)) {
byte[] bytes = IOUtils.toByteArray(jis);

if (isClassFile(bytes)) {
try {
// process bytes using CAFED00D

ClassFileReader reader = new ClassFileReader();
ClassFile classFile = reader.read(bytes);
bytes = new ClassFileWriter().write(classFile);

final ClassNode cn = Conversion.toNode(bytes);
if (cn != null && (cn.superName != null || (cn.name != null && cn.name.equals("java/lang/Object")))) {
classes.add(new Clazz(cn, en, jar));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package me.nov.threadtear.util.asm;

import org.objectweb.asm.Opcodes;
import org.objectweb.asm.signature.SignatureReader;
import org.objectweb.asm.signature.SignatureVisitor;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.LocalVariableNode;
import org.objectweb.asm.tree.MethodNode;

public final class SignatureValidator {

private SignatureValidator() {
throw new UnsupportedOperationException("Utility class cannot be instantiated.");
}

public static void validateSignatures(ClassNode classNode) {
parseOr(classNode.signature, () -> classNode.signature = null);

for(MethodNode methodNode : classNode.methods) {
parseOr(methodNode.signature, () -> methodNode.signature = null);

for(LocalVariableNode localVariableNode : methodNode.localVariables) {
parseOr(localVariableNode.signature, () -> localVariableNode.signature = null);
}
}

for(FieldNode fieldNode : classNode.fields) {
parseOr(fieldNode.signature, () -> fieldNode.signature = null);
}
}

private static void parseOr(String signature, Runnable runnable) {
SignatureReader signatureReader = new SignatureReader(signature);
try {
signatureReader.accept(new SignatureVisitor(Opcodes.ASM9) {});
} catch (Exception ignored) {
runnable.run();
}
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ commons-configuration2.version = 2.7
commons-beanutils.version = 1.9.4
darklaf.version = 2.6.1
darklaf.extensions.version = 0.3.4
asm.version = 9.1
asm.version = 9.2
cfr.version = -SNAPSHOT
rsyntaxtextarea.version = 3.1.1
jgraphx.version = v4.0.0
Expand Down