Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import uwu.narumi.deobfuscator.api.classpath.InheritanceClassWriter;
import uwu.narumi.deobfuscator.api.inheritance.InheritanceGraph;

import static org.objectweb.asm.Opcodes.ACC_ENUM;

public class ClassWrapper {

protected static final Logger LOGGER = LogManager.getLogger(ClassWrapper.class);
Expand Down Expand Up @@ -123,6 +125,10 @@ public String canonicalName() {
return classNode.name.replace('/', '.');
}

public boolean isEnumClass() {
return (classNode.access & ACC_ENUM) != 0;
}

/**
* Compiles class to bytes.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.jetbrains.annotations.Unmodifiable;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.analysis.Frame;
import org.objectweb.asm.tree.analysis.OriginalSourceValue;
Expand All @@ -15,19 +16,24 @@
*/
public class MethodContext {
private final ClassWrapper classWrapper;
private final ClassNode classNode; // for copied method without classWrapper
private final MethodNode methodNode;
private final FramesProvider framesProvider;
// Lazily initialized
private Map<AbstractInsnNode, Frame<OriginalSourceValue>> frames = null;
// Lazily initialized
private Map<AbstractInsnNode, Set<AbstractInsnNode>> consumersMap = null;

private MethodContext(
ClassWrapper classWrapper,
MethodNode methodNode,
FramesProvider framesProvider
) {
private MethodContext(ClassWrapper classWrapper, MethodNode methodNode, FramesProvider framesProvider) {
this.classWrapper = classWrapper;
this.classNode = classWrapper.classNode();
this.methodNode = methodNode;
this.framesProvider = framesProvider;
}

private MethodContext(ClassNode classNode, MethodNode methodNode, FramesProvider framesProvider) {
this.classWrapper = null;
this.classNode = classNode;
this.methodNode = methodNode;
this.framesProvider = framesProvider;
}
Expand All @@ -46,6 +52,13 @@ public MethodNode methodNode() {
return methodNode;
}

/**
* Class node
*/
public ClassNode classNode() {
return classNode;
}

/**
* Frames of the method
*/
Expand Down Expand Up @@ -86,4 +99,8 @@ public static MethodContext of(ClassWrapper classWrapper, MethodNode methodNode)
public static MethodContext of(ClassWrapper classWrapper, MethodNode methodNode, FramesProvider framesProvider) {
return new MethodContext(classWrapper, methodNode, framesProvider);
}

public static MethodContext of(ClassNode classNode, MethodNode methodNode) {
return new MethodContext(classNode, methodNode, MethodHelper::analyzeSource);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ public void addRawClass(byte[] bytes) {
classesInfo.putIfAbsent(className, classNode);
}

public void removeRawClass(ClassNode classNode) {
String className = classNode.name;

compiledClasses.remove(className);
classesInfo.remove(className);
}

@Override
public byte @Nullable [] getClass(String name) {
return compiledClasses.get(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public List<ClassWrapper> scopedClasses(ClassWrapper scope) {
.toList();
}

public void addCompiledClass(String pathInJar, byte[] bytes) {
public ClassWrapper addCompiledClass(String pathInJar, byte[] bytes) {
try {
// Fix class bytes
bytes = ClassHelper.fixClass(bytes);
Expand All @@ -120,9 +120,17 @@ public void addCompiledClass(String pathInJar, byte[] bytes) {
this.classesMap.putIfAbsent(classWrapper.name(), classWrapper);

this.compiledClasses.addRawClass(bytes);
return classWrapper;
} catch (InvalidClassException e) {
LOGGER.error("Failed to load class {}", pathInJar);
}

return null;
}

public void removeCompiledClass(ClassWrapper classWrapper) {
this.classesMap.remove(classWrapper.name());
this.compiledClasses.removeRawClass(classWrapper.classNode());
}

public void addFile(String path, byte[] bytes) {
Expand Down
4 changes: 2 additions & 2 deletions deobfuscator-impl/src/test/java/Bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public static void main(String[] args) {
.continueOnError()
.classWriterFlags(ClassWriter.COMPUTE_FRAMES)
.build()
).start();
).start();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import uwu.narumi.deobfuscator.core.other.impl.universal.StringBuilderTransformer;
import uwu.narumi.deobfuscator.core.other.impl.universal.UniversalNumberTransformer;
import uwu.narumi.deobfuscator.base.TestDeobfuscationBase;
import uwu.narumi.deobfuscator.core.other.impl.zkm.ZelixStringTransformer;
import uwu.narumi.deobfuscator.transformer.TestSandboxSecurityTransformer;

import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import uwu.narumi.deobfuscator.core.other.impl.zkm.ZelixFieldFlowTransformer;
import uwu.narumi.deobfuscator.core.other.impl.zkm.ZelixLongEncryptionMPCTransformer;
import uwu.narumi.deobfuscator.core.other.impl.zkm.ZelixParametersTransformer;
import uwu.narumi.deobfuscator.core.other.impl.zkm.ZelixStringTransformer;
import uwu.narumi.deobfuscator.core.other.impl.zkm.ZelixUselessTryCatchRemoverTransformer;

import java.util.HashMap;
Expand Down
Loading