From 4d86c9bcda572665e1806fbd0a0b071d80aa736e Mon Sep 17 00:00:00 2001 From: EpicPlayerA10 Date: Mon, 14 Oct 2024 14:47:49 +0200 Subject: [PATCH] Pass context and scope directly to transformer. Add Transformer#scopedClasses for easier usage --- CONTRIBUTING.md | 16 +- .../deobfuscator/api/context/Context.java | 7 +- .../api/helper/FramedInstructionsStream.java | 7 +- .../api/transformer/ComposedTransformer.java | 6 +- .../api/transformer/Transformer.java | 54 ++++- .../VersionedComposedTransformer.java | 7 +- .../TestSandboxSecurityTransformer.java | 6 +- .../allatori/AllatoriStringTransformer.java | 10 +- .../clean/AnnotationCleanTransformer.java | 41 ++-- .../clean/ClassDebugInfoCleanTransformer.java | 15 +- .../clean/InvalidMethodCleanTransformer.java | 6 +- .../clean/LineNumberCleanTransformer.java | 23 +- .../LocalVariableNamesCleanTransformer.java | 6 +- .../clean/ParametersInfoCleanTransformer.java | 6 +- .../impl/clean/SignatureCleanTransformer.java | 17 +- .../ThrowsExceptionCleanTransformer.java | 6 +- .../clean/TryCatchBlockCleanTransformer.java | 6 +- .../UnknownAttributeCleanTransformer.java | 6 +- .../peephole/DeadCodeCleanTransformer.java | 10 +- .../clean/peephole/JsrInlinerTransformer.java | 6 +- .../clean/peephole/NopCleanTransformer.java | 7 +- .../PopUnUsedLocalVariablesTransformer.java | 6 +- .../peephole/UnUsedLabelCleanTransformer.java | 6 +- .../UselessGotosCleanTransformer.java | 6 +- .../peephole/UselessPopCleanTransformer.java | 6 +- .../exploit/WebExploitRemoveTransformer.java | 10 +- .../impl/hp888/HP888PackerTransformer.java | 12 +- .../impl/hp888/HP888StringTransformer.java | 7 +- .../pool/InlineLocalVariablesTransformer.java | 6 +- .../InlineStaticArrayFieldTransformer.java | 4 +- .../pool/InlineStaticFieldTransformer.java | 16 +- .../universal/AccessRepairTransformer.java | 212 +++++++++--------- .../AnnotationFilterTransformer.java | 96 ++++---- .../RecoverSyntheticsTransformer.java | 6 +- .../universal/TryCatchRepairTransformer.java | 6 +- .../flow/CleanRedundantJumpsTransformer.java | 6 +- .../CleanRedundantSwitchesTransformer.java | 6 +- .../MathBinaryOperationsTransformer.java | 6 +- .../MathUnaryOperationsTransformer.java | 6 +- .../MethodCallsOnLiteralsTransformer.java | 6 +- .../ZelixLongEncryptionMPCTransformer.java | 19 +- .../impl/zkm/ZelixParametersTransformer.java | 9 +- .../impl/zkm/ZelixStringTransformer.java | 10 +- ...elixUselessTryCatchRemoverTransformer.java | 6 +- 44 files changed, 332 insertions(+), 409 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index df2477ac..3c527c48 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -91,8 +91,8 @@ import uwu.narumi.deobfuscator.api.transformer.Transformer; public class SomeTransformer extends Transformer { @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - context.classes(scope).forEach(classWrapper -> classWrapper.methods().forEach(methodNode -> { + protected void transform() throws Exception { + classes().forEach(classWrapper -> classWrapper.methods().forEach(methodNode -> { // Code here })); } @@ -109,8 +109,8 @@ import java.util.Arrays; public class SomeTransformer extends Transformer { @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - context.classes(scope).forEach(classWrapper -> classWrapper.methods().forEach(methodNode -> { + protected void transform() throws Exception { + classes().forEach(classWrapper -> classWrapper.methods().forEach(methodNode -> { // Iterate over all LDC instructions in the method Arrays.stream(methodNode.instructions.toArray()) @@ -143,8 +143,8 @@ import java.util.Arrays; public class SomeTransformer extends Transformer { @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - context.classes(scope).forEach(classWrapper -> classWrapper.methods().forEach(methodNode -> { + protected void transform() throws Exception { + classes().forEach(classWrapper -> classWrapper.methods().forEach(methodNode -> { MethodContext methodContext = MethodContext.framed(classWrapper, methodNode); // Find all System.out.println calls and replace the string with "Bye, World!" @@ -189,8 +189,8 @@ import uwu.narumi.deobfuscator.api.transformer.Transformer; public class SomeTransformer extends Transformer { @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - FramedInstructionsStream.of(scope, context) + protected void transform() throws Exception { + FramedInstructionsStream.of(this) .editInstructionsStream(stream -> stream.filter(insn -> insn.getOpcode() == INVOKEVIRTUAL)) // Match only INVOKEVIRTUAL instructions .forEach(insnContext -> { MethodInsnNode methodInsn = (MethodInsnNode) insnContext.insn(); diff --git a/deobfuscator-api/src/main/java/uwu/narumi/deobfuscator/api/context/Context.java b/deobfuscator-api/src/main/java/uwu/narumi/deobfuscator/api/context/Context.java index 559e3261..318291e3 100644 --- a/deobfuscator-api/src/main/java/uwu/narumi/deobfuscator/api/context/Context.java +++ b/deobfuscator-api/src/main/java/uwu/narumi/deobfuscator/api/context/Context.java @@ -2,11 +2,11 @@ import java.util.*; import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.jetbrains.annotations.UnmodifiableView; import uwu.narumi.deobfuscator.api.asm.ClassWrapper; import uwu.narumi.deobfuscator.api.execution.SandBox; import uwu.narumi.deobfuscator.api.classpath.Classpath; @@ -93,10 +93,11 @@ public Stream stream(ClassWrapper scope) { .filter(classWrapper -> scope == null || classWrapper.name().equals(scope.name())); } - public List classes(ClassWrapper scope) { + @UnmodifiableView + public List scopedClasses(ClassWrapper scope) { return classes.values().stream() .filter(classWrapper -> scope == null || classWrapper.name().equals(scope.name())) - .collect(Collectors.toList()); + .toList(); } public Optional get(String name) { diff --git a/deobfuscator-api/src/main/java/uwu/narumi/deobfuscator/api/helper/FramedInstructionsStream.java b/deobfuscator-api/src/main/java/uwu/narumi/deobfuscator/api/helper/FramedInstructionsStream.java index 1a380e41..c2ae0b42 100644 --- a/deobfuscator-api/src/main/java/uwu/narumi/deobfuscator/api/helper/FramedInstructionsStream.java +++ b/deobfuscator-api/src/main/java/uwu/narumi/deobfuscator/api/helper/FramedInstructionsStream.java @@ -7,6 +7,7 @@ import uwu.narumi.deobfuscator.api.asm.InsnContext; import uwu.narumi.deobfuscator.api.asm.MethodContext; import uwu.narumi.deobfuscator.api.context.Context; +import uwu.narumi.deobfuscator.api.transformer.Transformer; import java.util.Arrays; import java.util.function.Consumer; @@ -18,6 +19,10 @@ * iterate over classes and methods ASYNC, and instructions SYNC. This can really speed up computing frames for methods. */ public class FramedInstructionsStream { + public static FramedInstructionsStream of(Transformer transformer) { + return of(transformer.scope(), transformer.context()); + } + public static FramedInstructionsStream of(ClassWrapper scope, Context context) { return new FramedInstructionsStream(scope, context); } @@ -61,7 +66,7 @@ public FramedInstructionsStream forceSync() { public void forEach(Consumer consumer) { // Iterate over classes in parallel - this.classesStreamModifier.apply(this.forceSync ? this.context.classes(this.scope).stream() : this.context.classes(this.scope).parallelStream()) + this.classesStreamModifier.apply(this.forceSync ? this.context.scopedClasses(this.scope).stream() : this.context.scopedClasses(this.scope).parallelStream()) // Iterate over methods in parallel .forEach(classWrapper -> this.methodsStreamModifier.apply(this.forceSync ? classWrapper.methods().stream() : classWrapper.methods().parallelStream()) .forEach(methodNode -> { diff --git a/deobfuscator-api/src/main/java/uwu/narumi/deobfuscator/api/transformer/ComposedTransformer.java b/deobfuscator-api/src/main/java/uwu/narumi/deobfuscator/api/transformer/ComposedTransformer.java index 90655414..44dc2f6c 100644 --- a/deobfuscator-api/src/main/java/uwu/narumi/deobfuscator/api/transformer/ComposedTransformer.java +++ b/deobfuscator-api/src/main/java/uwu/narumi/deobfuscator/api/transformer/ComposedTransformer.java @@ -4,8 +4,6 @@ import java.util.function.Supplier; import org.jetbrains.annotations.Nullable; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; public class ComposedTransformer extends Transformer { @@ -23,9 +21,9 @@ public ComposedTransformer(boolean rerunOnChange, Supplier... trans } @Override - protected void transform(ClassWrapper scope, Context context) { + protected void transform() { transformers.forEach(transformerSupplier -> { - boolean changed = Transformer.transform(transformerSupplier, scope, context); + boolean changed = Transformer.transform(transformerSupplier, scope(), context()); if (changed) { this.markChange(); } diff --git a/deobfuscator-api/src/main/java/uwu/narumi/deobfuscator/api/transformer/Transformer.java b/deobfuscator-api/src/main/java/uwu/narumi/deobfuscator/api/transformer/Transformer.java index b7249c37..15becd85 100644 --- a/deobfuscator-api/src/main/java/uwu/narumi/deobfuscator/api/transformer/Transformer.java +++ b/deobfuscator-api/src/main/java/uwu/narumi/deobfuscator/api/transformer/Transformer.java @@ -2,7 +2,9 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.UnmodifiableView; import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.MethodNode; import org.objectweb.asm.tree.analysis.Analyzer; @@ -14,12 +16,15 @@ import uwu.narumi.deobfuscator.api.exception.TransformerException; import uwu.narumi.deobfuscator.api.helper.AsmHelper; +import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Supplier; public abstract class Transformer extends AsmHelper implements Opcodes { + protected static final Logger LOGGER = LogManager.getLogger(); - protected static final Logger LOGGER = LogManager.getLogger(Transformer.class); + private Context context = null; + private ClassWrapper scope = null; // Internal variables private boolean hasRan = false; @@ -37,11 +42,8 @@ public boolean shouldRerunOnChange() { /** * Do the transformation. If you implement it you MUST use {@link Transformer#markChange()} somewhere - * - * @param scope You can choose the class transform or set it to null to transform all classes - * @param context The context */ - protected abstract void transform(ClassWrapper scope, Context context) throws Exception; + protected abstract void transform() throws Exception; /** * Marks that transformer changed something. You MUST use it somewhere in your transformer. @@ -62,6 +64,40 @@ public String name() { return this.getClass().getSimpleName(); } + /** + * Get classes for processing + */ + @UnmodifiableView + protected List scopedClasses() { + return this.context.scopedClasses(this.scope); + } + + private void ensureInitialized() { + if (this.context == null) { + throw new IllegalStateException("Transformer is not initialized"); + } + } + + @NotNull + public Context context() { + ensureInitialized(); + return context; + } + + @Nullable + public ClassWrapper scope() { + ensureInitialized(); + return scope; + } + + /** + * Init transformer + */ + private void init(Context context, ClassWrapper scope) { + this.context = context; + this.scope = scope; + } + /** * Run the transformer * @@ -92,14 +128,16 @@ private static boolean transform( throw new IllegalArgumentException("transformerSupplier tried to reuse transformer instance. You must pass a new instance of transformer"); } - LOGGER.info("-------------------------------------"); + // Initialize transformer + transformer.init(context, scope); + LOGGER.info("-------------------------------------"); LOGGER.info("Running {} transformer", transformer.name()); long start = System.currentTimeMillis(); // Run the transformer! try { - transformer.transform(scope, context); + transformer.transform(); } catch (TransformerException e) { LOGGER.error("! {}: {}", transformer.name(), e.getMessage()); return false; @@ -141,7 +179,7 @@ private static boolean transform( * Verifies if the bytecode is valid */ private static void verifyBytecode(@Nullable ClassWrapper scope, Context context) throws IllegalStateException { - for (ClassWrapper classWrapper : context.classes(scope)) { + for (ClassWrapper classWrapper : context.scopedClasses(scope)) { for (MethodNode methodNode : classWrapper.methods()) { Analyzer analyzer = new Analyzer<>(new BasicVerifier()); try { diff --git a/deobfuscator-api/src/main/java/uwu/narumi/deobfuscator/api/transformer/VersionedComposedTransformer.java b/deobfuscator-api/src/main/java/uwu/narumi/deobfuscator/api/transformer/VersionedComposedTransformer.java index 301b2e57..959c57be 100644 --- a/deobfuscator-api/src/main/java/uwu/narumi/deobfuscator/api/transformer/VersionedComposedTransformer.java +++ b/deobfuscator-api/src/main/java/uwu/narumi/deobfuscator/api/transformer/VersionedComposedTransformer.java @@ -4,9 +4,6 @@ import java.util.Map; import java.util.function.Supplier; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; - public abstract class VersionedComposedTransformer extends Transformer { private final String version; @@ -18,7 +15,7 @@ public VersionedComposedTransformer(String version) { private boolean changed = false; @Override - protected void transform(ClassWrapper scope, Context context) { + protected void transform() { Map>> transformers = transformersByVersions(); if (!transformers.containsKey(version)) { throw new IllegalArgumentException(String.format("Version '%s' not found!", version)); @@ -26,7 +23,7 @@ protected void transform(ClassWrapper scope, Context context) { transformers .get(version) - .forEach(transformer -> changed |= Transformer.transform(transformer, scope, context)); + .forEach(transformer -> changed |= Transformer.transform(transformer, scope(), context())); if (changed) { markChange(); diff --git a/deobfuscator-impl/src/test/java/uwu/narumi/deobfuscator/transformer/TestSandboxSecurityTransformer.java b/deobfuscator-impl/src/test/java/uwu/narumi/deobfuscator/transformer/TestSandboxSecurityTransformer.java index 50c6d011..f0bb1733 100644 --- a/deobfuscator-impl/src/test/java/uwu/narumi/deobfuscator/transformer/TestSandboxSecurityTransformer.java +++ b/deobfuscator-impl/src/test/java/uwu/narumi/deobfuscator/transformer/TestSandboxSecurityTransformer.java @@ -2,8 +2,6 @@ import dev.xdark.ssvm.execution.VMException; import dev.xdark.ssvm.mirror.type.InstanceClass; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.execution.SandBox; import uwu.narumi.deobfuscator.api.transformer.Transformer; @@ -11,8 +9,8 @@ public class TestSandboxSecurityTransformer extends Transformer { @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - SandBox sandBox = context.getSandBox(); + protected void transform() throws Exception { + SandBox sandBox = context().getSandBox(); InstanceClass clazz = sandBox.getHelper().loadClass("sandbox.TestSandboxSecurity"); assertThrows(VMException.class, () -> { diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/allatori/AllatoriStringTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/allatori/AllatoriStringTransformer.java index 5d55db1b..81494596 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/allatori/AllatoriStringTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/allatori/AllatoriStringTransformer.java @@ -4,8 +4,6 @@ import org.objectweb.asm.tree.IntInsnNode; import org.objectweb.asm.tree.LdcInsnNode; import org.objectweb.asm.tree.MethodInsnNode; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.transformer.Transformer; import java.util.ArrayList; @@ -27,8 +25,8 @@ public AllatoriStringTransformer(boolean strong) { /* Written by https://github.com/Lampadina17 | 06/08/2024 */ /* use UniversalNumberTransformer before this transformer to decrypt keys */ @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - context.classes(scope).forEach(classWrapper -> { + protected void transform() throws Exception { + scopedClasses().forEach(classWrapper -> { classWrapper.methods().forEach(methodNode -> { AtomicBoolean isDecryptor = new AtomicBoolean(false); @@ -67,7 +65,7 @@ protected void transform(ClassWrapper scope, Context context) throws Exception { }); /* Decrypt all strings */ - context.classes(scope).forEach(classWrapper -> { + scopedClasses().forEach(classWrapper -> { classWrapper.methods().forEach(methodNode -> { Arrays.stream(methodNode.instructions.toArray()).forEach(node -> { if (node instanceof LdcInsnNode ldc && ldc.cst instanceof String && node.getNext() instanceof MethodInsnNode next && next.getOpcode() == INVOKESTATIC) { @@ -98,7 +96,7 @@ protected void transform(ClassWrapper scope, Context context) throws Exception { }); }); }); - LOGGER.info("Decrypted {} strings in {} classes", this.getChangesCount(), context.classes().size()); + LOGGER.info("Decrypted {} strings in {} classes", this.getChangesCount(), scopedClasses().size()); } public class DecryptionMethod { diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/AnnotationCleanTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/AnnotationCleanTransformer.java index 8fad6eef..006dabbe 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/AnnotationCleanTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/AnnotationCleanTransformer.java @@ -1,38 +1,27 @@ package uwu.narumi.deobfuscator.core.other.impl.clean; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.transformer.Transformer; public class AnnotationCleanTransformer extends Transformer { @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - context - .classes(scope) - .forEach( - classWrapper -> { - classWrapper.classNode().invisibleAnnotations = null; - classWrapper.classNode().invisibleAnnotations = null; + protected void transform() throws Exception { + scopedClasses().forEach(classWrapper -> { + classWrapper.classNode().invisibleAnnotations = null; + classWrapper.classNode().invisibleAnnotations = null; - classWrapper - .methods() - .forEach( - methodNode -> { - methodNode.invisibleAnnotations = null; - methodNode.visibleAnnotations = null; - methodNode.invisibleParameterAnnotations = null; - methodNode.visibleParameterAnnotations = null; - }); + classWrapper.methods().forEach(methodNode -> { + methodNode.invisibleAnnotations = null; + methodNode.visibleAnnotations = null; + methodNode.invisibleParameterAnnotations = null; + methodNode.visibleParameterAnnotations = null; + }); - classWrapper - .fields() - .forEach( - fieldNode -> { - fieldNode.invisibleAnnotations = null; - fieldNode.visibleAnnotations = null; - }); - }); + classWrapper.fields().forEach(fieldNode -> { + fieldNode.invisibleAnnotations = null; + fieldNode.visibleAnnotations = null; + }); + }); // There is always a change markChange(); diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/ClassDebugInfoCleanTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/ClassDebugInfoCleanTransformer.java index 47d117c5..70320209 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/ClassDebugInfoCleanTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/ClassDebugInfoCleanTransformer.java @@ -1,20 +1,15 @@ package uwu.narumi.deobfuscator.core.other.impl.clean; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.transformer.Transformer; public class ClassDebugInfoCleanTransformer extends Transformer { @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - context - .classes(scope) - .forEach( - classWrapper -> { - classWrapper.classNode().sourceDebug = null; - classWrapper.classNode().sourceFile = null; - }); + protected void transform() throws Exception { + scopedClasses().forEach(classWrapper -> { + classWrapper.classNode().sourceDebug = null; + classWrapper.classNode().sourceFile = null; + }); // There is always a change markChange(); diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/InvalidMethodCleanTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/InvalidMethodCleanTransformer.java index 573cb982..a18a743d 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/InvalidMethodCleanTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/InvalidMethodCleanTransformer.java @@ -4,8 +4,6 @@ import org.objectweb.asm.tree.analysis.Analyzer; import org.objectweb.asm.tree.analysis.AnalyzerException; import org.objectweb.asm.tree.analysis.BasicInterpreter; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.transformer.Transformer; /** @@ -14,8 +12,8 @@ public class InvalidMethodCleanTransformer extends Transformer { @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - context.classes(scope).parallelStream().forEach(classWrapper -> { + protected void transform() throws Exception { + scopedClasses().parallelStream().forEach(classWrapper -> { var iterator = classWrapper.methods().iterator(); while (iterator.hasNext()) { MethodNode methodNode = iterator.next(); diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/LineNumberCleanTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/LineNumberCleanTransformer.java index fb257637..64529a0d 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/LineNumberCleanTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/LineNumberCleanTransformer.java @@ -1,24 +1,21 @@ package uwu.narumi.deobfuscator.core.other.impl.clean; import java.util.Arrays; + import org.objectweb.asm.tree.LineNumberNode; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.transformer.Transformer; public class LineNumberCleanTransformer extends Transformer { @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - context.classes(scope).stream() - .flatMap(classWrapper -> classWrapper.methods().stream()) - .forEach( - methodNode -> - Arrays.stream(methodNode.instructions.toArray()) - .filter(node -> node instanceof LineNumberNode) - .forEach(node -> { - methodNode.instructions.remove(node); - this.markChange(); - })); + protected void transform() throws Exception { + scopedClasses().forEach(classWrapper -> classWrapper.methods().forEach(methodNode -> { + Arrays.stream(methodNode.instructions.toArray()) + .filter(node -> node instanceof LineNumberNode) + .forEach(node -> { + methodNode.instructions.remove(node); + this.markChange(); + }); + })); } } diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/LocalVariableNamesCleanTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/LocalVariableNamesCleanTransformer.java index 59845383..aee46f6d 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/LocalVariableNamesCleanTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/LocalVariableNamesCleanTransformer.java @@ -1,7 +1,5 @@ package uwu.narumi.deobfuscator.core.other.impl.clean; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.transformer.Transformer; /** @@ -10,8 +8,8 @@ public class LocalVariableNamesCleanTransformer extends Transformer { @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - context.classes(scope).stream() + protected void transform() throws Exception { + scopedClasses().stream() .flatMap(classWrapper -> classWrapper.methods().stream()) .forEach(methodNode -> { methodNode.localVariables = null; diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/ParametersInfoCleanTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/ParametersInfoCleanTransformer.java index 7338125d..aaae906a 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/ParametersInfoCleanTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/ParametersInfoCleanTransformer.java @@ -1,7 +1,5 @@ package uwu.narumi.deobfuscator.core.other.impl.clean; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.transformer.Transformer; /** @@ -9,8 +7,8 @@ */ public class ParametersInfoCleanTransformer extends Transformer { @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - context.classes(scope).stream() + protected void transform() throws Exception { + scopedClasses().stream() .flatMap(classWrapper -> classWrapper.methods().stream()) .forEach(methodNode -> { methodNode.parameters = null; diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/SignatureCleanTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/SignatureCleanTransformer.java index fbce9012..03bf9283 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/SignatureCleanTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/SignatureCleanTransformer.java @@ -1,21 +1,16 @@ package uwu.narumi.deobfuscator.core.other.impl.clean; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.transformer.Transformer; public class SignatureCleanTransformer extends Transformer { @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - context - .classes(scope) - .forEach( - classWrapper -> { - classWrapper.classNode().signature = null; - classWrapper.methods().forEach(methodNode -> methodNode.signature = null); - classWrapper.fields().forEach(fieldNode -> fieldNode.signature = null); - }); + protected void transform() throws Exception { + scopedClasses().forEach(classWrapper -> { + classWrapper.classNode().signature = null; + classWrapper.methods().forEach(methodNode -> methodNode.signature = null); + classWrapper.fields().forEach(fieldNode -> fieldNode.signature = null); + }); // There is always a change this.markChange(); diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/ThrowsExceptionCleanTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/ThrowsExceptionCleanTransformer.java index 47809b55..9adfc87d 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/ThrowsExceptionCleanTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/ThrowsExceptionCleanTransformer.java @@ -1,7 +1,5 @@ package uwu.narumi.deobfuscator.core.other.impl.clean; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.transformer.Transformer; /** @@ -9,8 +7,8 @@ */ public class ThrowsExceptionCleanTransformer extends Transformer { @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - context.classes(scope).stream() + protected void transform() throws Exception { + scopedClasses().stream() .flatMap(classWrapper -> classWrapper.methods().stream()) .forEach(methodNode -> { methodNode.exceptions = null; diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/TryCatchBlockCleanTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/TryCatchBlockCleanTransformer.java index bdc2ca45..c815f9c4 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/TryCatchBlockCleanTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/TryCatchBlockCleanTransformer.java @@ -1,14 +1,12 @@ package uwu.narumi.deobfuscator.core.other.impl.clean; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.transformer.Transformer; public class TryCatchBlockCleanTransformer extends Transformer { @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - context.classes(scope).stream() + protected void transform() throws Exception { + scopedClasses().stream() .flatMap(classWrapper -> classWrapper.methods().stream()) .forEach(methodNode -> { methodNode.tryCatchBlocks = null; diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/UnknownAttributeCleanTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/UnknownAttributeCleanTransformer.java index 9b1e03d8..008aa120 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/UnknownAttributeCleanTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/UnknownAttributeCleanTransformer.java @@ -1,8 +1,6 @@ package uwu.narumi.deobfuscator.core.other.impl.clean; import org.objectweb.asm.Attribute; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.transformer.Transformer; public class UnknownAttributeCleanTransformer extends Transformer { @@ -10,8 +8,8 @@ public class UnknownAttributeCleanTransformer extends Transformer { private boolean changed = false; @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - context.classes(scope).forEach(classWrapper -> { + protected void transform() throws Exception { + scopedClasses().forEach(classWrapper -> { if (classWrapper.classNode().attrs != null) { changed |= classWrapper.classNode().attrs.removeIf(Attribute::isUnknown); } diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/peephole/DeadCodeCleanTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/peephole/DeadCodeCleanTransformer.java index f22289e7..4037bf3c 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/peephole/DeadCodeCleanTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/peephole/DeadCodeCleanTransformer.java @@ -4,21 +4,15 @@ import org.objectweb.asm.tree.analysis.Analyzer; import org.objectweb.asm.tree.analysis.AnalyzerException; import org.objectweb.asm.tree.analysis.Frame; -import org.objectweb.asm.tree.analysis.OriginalSourceValue; import org.objectweb.asm.tree.analysis.SourceInterpreter; import org.objectweb.asm.tree.analysis.SourceValue; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; -import uwu.narumi.deobfuscator.api.helper.AsmHelper; import uwu.narumi.deobfuscator.api.transformer.Transformer; -import java.util.Map; - public class DeadCodeCleanTransformer extends Transformer { @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - context.classes(scope).parallelStream().forEach(classWrapper -> classWrapper.methods().parallelStream().forEach(methodNode -> { + protected void transform() throws Exception { + scopedClasses().parallelStream().forEach(classWrapper -> classWrapper.methods().parallelStream().forEach(methodNode -> { // We want to use here the traditional analyzer. We want the true dead code. Analyzer analyzer = new Analyzer<>(new SourceInterpreter()); try { diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/peephole/JsrInlinerTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/peephole/JsrInlinerTransformer.java index f9015b6b..19846d1b 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/peephole/JsrInlinerTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/peephole/JsrInlinerTransformer.java @@ -2,8 +2,6 @@ import org.objectweb.asm.commons.JSRInlinerAdapter; import org.objectweb.asm.tree.MethodNode; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.transformer.Transformer; import java.util.Arrays; @@ -13,8 +11,8 @@ */ public class JsrInlinerTransformer extends Transformer { @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - context.classes(scope).forEach(classWrapper -> { + protected void transform() throws Exception { + scopedClasses().forEach(classWrapper -> { for (int i = 0; i < classWrapper.methods().size(); i++) { MethodNode methodNode = classWrapper.methods().get(i); diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/peephole/NopCleanTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/peephole/NopCleanTransformer.java index 0ea04f6e..a98390ae 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/peephole/NopCleanTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/peephole/NopCleanTransformer.java @@ -1,15 +1,14 @@ package uwu.narumi.deobfuscator.core.other.impl.clean.peephole; import java.util.Arrays; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; + import uwu.narumi.deobfuscator.api.transformer.Transformer; public class NopCleanTransformer extends Transformer { @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - context.classes(scope).stream() + protected void transform() throws Exception { + scopedClasses().stream() .flatMap(classWrapper -> classWrapper.methods().stream()) .forEach( methodNode -> diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/peephole/PopUnUsedLocalVariablesTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/peephole/PopUnUsedLocalVariablesTransformer.java index f1875e6b..0774d161 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/peephole/PopUnUsedLocalVariablesTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/peephole/PopUnUsedLocalVariablesTransformer.java @@ -5,10 +5,8 @@ import org.objectweb.asm.tree.VarInsnNode; import org.objectweb.asm.tree.analysis.Frame; import org.objectweb.asm.tree.analysis.OriginalSourceValue; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; import uwu.narumi.deobfuscator.api.asm.InsnContext; import uwu.narumi.deobfuscator.api.asm.MethodContext; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.transformer.Transformer; import java.util.ArrayList; @@ -17,8 +15,8 @@ public class PopUnUsedLocalVariablesTransformer extends Transformer { @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - context.classes(scope).forEach(classWrapper -> classWrapper.methods().forEach(methodNode -> { + protected void transform() throws Exception { + scopedClasses().forEach(classWrapper -> classWrapper.methods().forEach(methodNode -> { MethodContext methodContext = MethodContext.framed(classWrapper, methodNode); List varStoresInUse = new ArrayList<>(); diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/peephole/UnUsedLabelCleanTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/peephole/UnUsedLabelCleanTransformer.java index 9111c8ef..a811135d 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/peephole/UnUsedLabelCleanTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/peephole/UnUsedLabelCleanTransformer.java @@ -5,15 +5,13 @@ import java.util.Set; import java.util.stream.Stream; import org.objectweb.asm.tree.*; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.transformer.Transformer; public class UnUsedLabelCleanTransformer extends Transformer { @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - context.classes(scope).stream() + protected void transform() throws Exception { + scopedClasses().stream() .flatMap(classWrapper -> classWrapper.methods().stream()) .forEach( methodNode -> { diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/peephole/UselessGotosCleanTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/peephole/UselessGotosCleanTransformer.java index 0e3de404..b0e8fab5 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/peephole/UselessGotosCleanTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/peephole/UselessGotosCleanTransformer.java @@ -6,8 +6,6 @@ import org.objectweb.asm.tree.LookupSwitchInsnNode; import org.objectweb.asm.tree.MethodNode; import org.objectweb.asm.tree.TableSwitchInsnNode; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.transformer.Transformer; import java.util.Arrays; @@ -26,8 +24,8 @@ public class UselessGotosCleanTransformer extends Transformer { @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - context.classes(scope).forEach(classWrapper -> classWrapper.methods().forEach(methodNode -> { + protected void transform() throws Exception { + scopedClasses().forEach(classWrapper -> classWrapper.methods().forEach(methodNode -> { for (AbstractInsnNode insn : methodNode.instructions.toArray()) { if (insn.getOpcode() == GOTO) { JumpInsnNode jumpInsn = (JumpInsnNode) insn; diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/peephole/UselessPopCleanTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/peephole/UselessPopCleanTransformer.java index b6747b21..f7d50bb4 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/peephole/UselessPopCleanTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/clean/peephole/UselessPopCleanTransformer.java @@ -3,9 +3,7 @@ import org.objectweb.asm.tree.AbstractInsnNode; import org.objectweb.asm.tree.MethodNode; import org.objectweb.asm.tree.analysis.OriginalSourceValue; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; import uwu.narumi.deobfuscator.api.asm.InsnContext; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.helper.FramedInstructionsStream; import uwu.narumi.deobfuscator.api.transformer.Transformer; @@ -21,8 +19,8 @@ public UselessPopCleanTransformer() { private final List poppedDups = new ArrayList<>(); @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - FramedInstructionsStream.of(scope, context) + protected void transform() throws Exception { + FramedInstructionsStream.of(this) .editInstructionsStream(stream -> stream.filter(insn -> insn.getOpcode() == POP || insn.getOpcode() == POP2)) .forEach(insnContext -> { boolean success = tryRemovePop(insnContext); diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/exploit/WebExploitRemoveTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/exploit/WebExploitRemoveTransformer.java index 09daadbb..c8f73ad3 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/exploit/WebExploitRemoveTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/exploit/WebExploitRemoveTransformer.java @@ -1,7 +1,5 @@ package uwu.narumi.deobfuscator.core.other.impl.exploit; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.transformer.Transformer; public class WebExploitRemoveTransformer extends Transformer { @@ -9,11 +7,11 @@ public class WebExploitRemoveTransformer extends Transformer { private boolean changed = false; @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - changed |= context.getClasses().entrySet().removeIf(entry -> entry.getKey().contains("")); - changed |= context.getFiles().entrySet().removeIf(entry -> entry.getKey().contains("")); + protected void transform() throws Exception { + changed |= context().getClasses().entrySet().removeIf(entry -> entry.getKey().contains("")); + changed |= context().getFiles().entrySet().removeIf(entry -> entry.getKey().contains("")); - context.classes().forEach(classWrapper -> { + scopedClasses().forEach(classWrapper -> { changed |= classWrapper.methods().removeIf(methodNode -> methodNode.name.contains("")); changed |= classWrapper.fields().removeIf(fieldNode -> fieldNode.name.contains("") || fieldNode.desc.contains("")); }); diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/hp888/HP888PackerTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/hp888/HP888PackerTransformer.java index dd1fc309..d8e0e700 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/hp888/HP888PackerTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/hp888/HP888PackerTransformer.java @@ -1,9 +1,7 @@ package uwu.narumi.deobfuscator.core.other.impl.hp888; import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassWriter; import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.helper.ClassHelper; import uwu.narumi.deobfuscator.api.transformer.Transformer; @@ -31,14 +29,14 @@ public HP888PackerTransformer(String encryptedClassFilesSuffix) { } @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { + protected void transform() throws Exception { Set filesToRemove = new HashSet<>(); HashMap newClasses = new HashMap<>(); AtomicReference key = new AtomicReference<>(); /* Firstly you must use HP888StringTransformer, so key would be decrypted, and it only searches in loader classes so don't tell me its bad searching. */ - context.classes().stream().map(ClassWrapper::classNode).forEach(classNode -> classNode.methods.forEach(methodNode -> methodNode.instructions.forEach(abstractInsnNode -> { + scopedClasses().stream().map(ClassWrapper::classNode).forEach(classNode -> classNode.methods.forEach(methodNode -> methodNode.instructions.forEach(abstractInsnNode -> { if (abstractInsnNode.isString() && abstractInsnNode.asString().endsWith("==")) { // Find base64 key key.set(abstractInsnNode.asString()); @@ -53,7 +51,7 @@ protected void transform(ClassWrapper scope, Context context) throws Exception { // Decrypt encrypted classes Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(Base64.getDecoder().decode(key.get()), "AES")); - context.getFiles().forEach((file, bytes) -> { + context().getFiles().forEach((file, bytes) -> { if (file.endsWith(encryptedClassFilesSuffix)) { String cleanFileName = file.replace(encryptedClassFilesSuffix, "").replace(".", "/"); filesToRemove.add(file); @@ -71,9 +69,9 @@ protected void transform(ClassWrapper scope, Context context) throws Exception { }); // Put all new classes - context.getClasses().putAll(newClasses); + context().getClasses().putAll(newClasses); // Cleanup - filesToRemove.forEach(context.getFiles()::remove); + filesToRemove.forEach(context().getFiles()::remove); } } diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/hp888/HP888StringTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/hp888/HP888StringTransformer.java index b7e98d25..78452f97 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/hp888/HP888StringTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/hp888/HP888StringTransformer.java @@ -10,7 +10,6 @@ import uwu.narumi.deobfuscator.api.asm.matcher.impl.MethodMatch; import uwu.narumi.deobfuscator.api.asm.matcher.impl.OpcodeMatch; import uwu.narumi.deobfuscator.api.asm.matcher.impl.StringMatch; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.transformer.Transformer; import java.util.ArrayList; @@ -33,8 +32,8 @@ public class HP888StringTransformer extends Transformer { ); @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - context.classes().forEach(classWrapper -> { + protected void transform() throws Exception { + scopedClasses().forEach(classWrapper -> { List toRemove = new ArrayList<>(); // Find all encrypted strings @@ -59,7 +58,7 @@ protected void transform(ClassWrapper scope, Context context) throws Exception { Type classForConstantPoolType = (Type) constantPoolClassLdc.cst; // Prepare data for decryption - ClassWrapper classForConstantPool = context.getClasses().get(classForConstantPoolType.getInternalName()); + ClassWrapper classForConstantPool = context().getClasses().get(classForConstantPoolType.getInternalName()); int constantPoolSize = classForConstantPool.getConstantPool().getSize(); String class0 = classWrapper.name(); String class1 = classWrapper.name(); diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/pool/InlineLocalVariablesTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/pool/InlineLocalVariablesTransformer.java index ca0b306a..70551a6c 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/pool/InlineLocalVariablesTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/pool/InlineLocalVariablesTransformer.java @@ -3,8 +3,6 @@ import org.objectweb.asm.tree.AbstractInsnNode; import org.objectweb.asm.tree.VarInsnNode; import org.objectweb.asm.tree.analysis.OriginalSourceValue; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.helper.FramedInstructionsStream; import uwu.narumi.deobfuscator.api.transformer.Transformer; @@ -13,8 +11,8 @@ */ public class InlineLocalVariablesTransformer extends Transformer { @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - FramedInstructionsStream.of(scope, context) + protected void transform() throws Exception { + FramedInstructionsStream.of(this) .editInstructionsStream(stream -> stream.filter(AbstractInsnNode::isVarLoad)) .forEach(insnContext -> { VarInsnNode varInsn = (VarInsnNode) insnContext.insn(); diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/pool/InlineStaticArrayFieldTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/pool/InlineStaticArrayFieldTransformer.java index d724cd0f..9c7af93a 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/pool/InlineStaticArrayFieldTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/pool/InlineStaticArrayFieldTransformer.java @@ -18,8 +18,8 @@ // TODO: Rewrite it entirely public class InlineStaticArrayFieldTransformer extends Transformer { @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - + protected void transform() throws Exception { + throw new UnsupportedOperationException("Not implemented yet"); } // private static final Object NULL = new Object(); diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/pool/InlineStaticFieldTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/pool/InlineStaticFieldTransformer.java index 17e3d2f2..1f23d977 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/pool/InlineStaticFieldTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/pool/InlineStaticFieldTransformer.java @@ -2,14 +2,10 @@ import org.objectweb.asm.tree.AbstractInsnNode; import org.objectweb.asm.tree.FieldInsnNode; -import org.objectweb.asm.tree.InsnNode; -import org.objectweb.asm.tree.analysis.BasicInterpreter; import org.objectweb.asm.tree.analysis.BasicValue; import org.objectweb.asm.tree.analysis.Frame; import org.objectweb.asm.tree.analysis.OriginalSourceValue; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; import uwu.narumi.deobfuscator.api.asm.FieldRef; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.helper.AsmHelper; import uwu.narumi.deobfuscator.api.helper.MethodHelper; import uwu.narumi.deobfuscator.api.transformer.Transformer; @@ -26,12 +22,12 @@ public class InlineStaticFieldTransformer extends Transformer { @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { + protected void transform() throws Exception { List notConstantFields = new ArrayList<>(); Map staticConstantFields = new HashMap<>(); // Find all static constant fields - context.classes(scope).forEach(classWrapper -> findClInit(classWrapper.classNode()).ifPresent(clInit -> { + scopedClasses().forEach(classWrapper -> findClInit(classWrapper.classNode()).ifPresent(clInit -> { var frames = MethodHelper.analyzeSource(classWrapper.classNode(), clInit); Arrays.stream(clInit.instructions.toArray()) @@ -64,7 +60,7 @@ protected void transform(ClassWrapper scope, Context context) throws Exception { })); // Also account for FieldNode#value - context.classes(scope).forEach(classWrapper -> { + scopedClasses().forEach(classWrapper -> { classWrapper.classNode().fields.forEach(fieldNode -> { if (fieldNode.value != null) { FieldRef fieldRef = FieldRef.of(classWrapper.classNode(), fieldNode); @@ -78,7 +74,7 @@ protected void transform(ClassWrapper scope, Context context) throws Exception { }); // Check if these static fields aren't modified outside clinit - context.classes(scope).forEach(classWrapper -> classWrapper.methods().stream() + scopedClasses().forEach(classWrapper -> classWrapper.methods().stream() .filter(methodNode -> !methodNode.name.equals("")) .forEach(methodNode -> { Arrays.stream(methodNode.instructions.toArray()) @@ -93,7 +89,7 @@ protected void transform(ClassWrapper scope, Context context) throws Exception { // Replace static fields accesses with corresponding values List inlinedFields = new ArrayList<>(); - context.classes(scope).forEach(classWrapper -> classWrapper.methods().forEach(methodNode -> { + scopedClasses().forEach(classWrapper -> classWrapper.methods().forEach(methodNode -> { Arrays.stream(methodNode.instructions.toArray()) .filter(insn -> insn.getOpcode() == GETSTATIC) .map(FieldInsnNode.class::cast) @@ -115,7 +111,7 @@ protected void transform(ClassWrapper scope, Context context) throws Exception { })); // Remove fields that were inlined - context.classes(scope).parallelStream().forEach(classWrapper -> { + scopedClasses().parallelStream().forEach(classWrapper -> { // Remove field classWrapper.classNode().fields.removeIf(fieldNode -> inlinedFields.contains(FieldRef.of(classWrapper.classNode(), fieldNode))); diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/AccessRepairTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/AccessRepairTransformer.java index ba8fe5f9..a2bbc721 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/AccessRepairTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/AccessRepairTransformer.java @@ -1,137 +1,125 @@ package uwu.narumi.deobfuscator.core.other.impl.universal; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.transformer.Transformer; public class AccessRepairTransformer extends Transformer { private final int[] CLASS = { - ACC_STATIC, - ACC_SYNCHRONIZED, - ACC_OPEN, - ACC_TRANSITIVE, - ACC_VOLATILE, - ACC_BRIDGE, - ACC_STATIC_PHASE, - ACC_VARARGS, - ACC_TRANSIENT, - ACC_NATIVE, - ACC_STRICT, - ACC_SYNTHETIC + ACC_STATIC, + ACC_SYNCHRONIZED, + ACC_OPEN, + ACC_TRANSITIVE, + ACC_VOLATILE, + ACC_BRIDGE, + ACC_STATIC_PHASE, + ACC_VARARGS, + ACC_TRANSIENT, + ACC_NATIVE, + ACC_STRICT, + ACC_SYNTHETIC }; private final int[] METHOD = { - ACC_SUPER, - ACC_OPEN, - ACC_TRANSITIVE, - ACC_VOLATILE, - ACC_STATIC_PHASE, - ACC_TRANSIENT, - ACC_INTERFACE, - ACC_ANNOTATION, - ACC_ENUM, - ACC_MODULE, - ACC_RECORD, - ACC_SYNTHETIC, - ACC_BRIDGE + ACC_SUPER, + ACC_OPEN, + ACC_TRANSITIVE, + ACC_VOLATILE, + ACC_STATIC_PHASE, + ACC_TRANSIENT, + ACC_INTERFACE, + ACC_ANNOTATION, + ACC_ENUM, + ACC_MODULE, + ACC_RECORD, + ACC_SYNTHETIC, + ACC_BRIDGE }; private final int[] FIELD = { - ACC_SUPER, - ACC_SYNCHRONIZED, - ACC_OPEN, - ACC_TRANSITIVE, - ACC_BRIDGE, - ACC_STATIC_PHASE, - ACC_VARARGS, - ACC_NATIVE, - ACC_INTERFACE, - ACC_ABSTRACT, - ACC_STRICT, - ACC_ANNOTATION, - ACC_MODULE, - ACC_RECORD, - ACC_SYNTHETIC + ACC_SUPER, + ACC_SYNCHRONIZED, + ACC_OPEN, + ACC_TRANSITIVE, + ACC_BRIDGE, + ACC_STATIC_PHASE, + ACC_VARARGS, + ACC_NATIVE, + ACC_INTERFACE, + ACC_ABSTRACT, + ACC_STRICT, + ACC_ANNOTATION, + ACC_MODULE, + ACC_RECORD, + ACC_SYNTHETIC }; private final int[] PARAMETER = { - ACC_PUBLIC, - ACC_PRIVATE, - ACC_PROTECTED, - ACC_STATIC, - ACC_SUPER, - ACC_SYNCHRONIZED, - ACC_OPEN, - ACC_TRANSITIVE, - ACC_VOLATILE, - ACC_BRIDGE, - ACC_STATIC_PHASE, - ACC_VARARGS, - ACC_TRANSIENT, - ACC_NATIVE, - ACC_INTERFACE, - ACC_ABSTRACT, - ACC_STRICT, - ACC_ANNOTATION, - ACC_ENUM, - ACC_MODULE, - ACC_RECORD, - ACC_DEPRECATED, - ACC_SYNTHETIC + ACC_PUBLIC, + ACC_PRIVATE, + ACC_PROTECTED, + ACC_STATIC, + ACC_SUPER, + ACC_SYNCHRONIZED, + ACC_OPEN, + ACC_TRANSITIVE, + ACC_VOLATILE, + ACC_BRIDGE, + ACC_STATIC_PHASE, + ACC_VARARGS, + ACC_TRANSIENT, + ACC_NATIVE, + ACC_INTERFACE, + ACC_ABSTRACT, + ACC_STRICT, + ACC_ANNOTATION, + ACC_ENUM, + ACC_MODULE, + ACC_RECORD, + ACC_DEPRECATED, + ACC_SYNTHETIC }; @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - context - .classes(scope) - .forEach( - classWrapper -> { - int classAccess = classWrapper.classNode().access; - for (int access : CLASS) { - if (isAccess(classAccess, access)) { - classAccess &= ~access; - this.markChange(); - } - } - classWrapper.classNode().access = classAccess; + protected void transform() throws Exception { + scopedClasses().forEach(classWrapper -> { + int classAccess = classWrapper.classNode().access; + for (int access : CLASS) { + if (isAccess(classAccess, access)) { + classAccess &= ~access; + this.markChange(); + } + } + classWrapper.classNode().access = classAccess; - classWrapper - .methods() - .forEach( - methodNode -> { - for (int access : METHOD) { - if (isAccess(methodNode.access, access)) { - methodNode.access &= ~access; - this.markChange(); - } - } + classWrapper.methods().forEach(methodNode -> { + for (int access : METHOD) { + if (isAccess(methodNode.access, access)) { + methodNode.access &= ~access; + this.markChange(); + } + } - if (methodNode.parameters != null) - methodNode.parameters.forEach( - parameterNode -> { - for (int access : PARAMETER) { - if (isAccess(parameterNode.access, access)) { - parameterNode.access &= ~access; - this.markChange(); - } - } - }); - }); + if (methodNode.parameters != null) + methodNode.parameters.forEach(parameterNode -> { + for (int access : PARAMETER) { + if (isAccess(parameterNode.access, access)) { + parameterNode.access &= ~access; + this.markChange(); + } + } + }); + }); - classWrapper - .fields() - .forEach( - fieldNode -> { - for (int access : FIELD) { - if (isAccess(fieldNode.access, access)) { - fieldNode.access &= ~access; - this.markChange(); - } - } - }); + classWrapper.fields().forEach(fieldNode -> { + for (int access : FIELD) { + if (isAccess(fieldNode.access, access)) { + fieldNode.access &= ~access; + this.markChange(); + } + } + }); - // TODO: Module maybe? - }); + // TODO: Module maybe? + }); } } diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/AnnotationFilterTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/AnnotationFilterTransformer.java index 47bac486..98956aec 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/AnnotationFilterTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/AnnotationFilterTransformer.java @@ -2,9 +2,8 @@ import java.util.List; import java.util.function.Predicate; + import org.objectweb.asm.tree.AnnotationNode; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.transformer.Transformer; public class AnnotationFilterTransformer extends Transformer { @@ -22,58 +21,47 @@ public class AnnotationFilterTransformer extends Transformer { private boolean changed = false; @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - context - .classes(scope) - .forEach( - classWrapper -> { - if (classWrapper.classNode().invisibleAnnotations != null) - changed |= classWrapper - .classNode() - .invisibleAnnotations - .removeIf(ANNOTATION_NODE_PREDICATE); - - if (classWrapper.classNode().visibleAnnotations != null) - changed |= classWrapper.classNode().visibleAnnotations.removeIf(ANNOTATION_NODE_PREDICATE); - - classWrapper - .methods() - .forEach( - methodNode -> { - if (methodNode.invisibleAnnotations != null) - changed |= methodNode.invisibleAnnotations.removeIf(ANNOTATION_NODE_PREDICATE); - - if (methodNode.visibleAnnotations != null) - changed |= methodNode.visibleAnnotations.removeIf(ANNOTATION_NODE_PREDICATE); - - if (methodNode.invisibleParameterAnnotations != null) - for (List invisibleParameterAnnotation : - methodNode.invisibleParameterAnnotations) { - if (invisibleParameterAnnotation == null) continue; - - changed |= invisibleParameterAnnotation.removeIf(ANNOTATION_NODE_PREDICATE); - } - - if (methodNode.visibleParameterAnnotations != null) - for (List visibleParameterAnnotation : - methodNode.visibleParameterAnnotations) { - if (visibleParameterAnnotation == null) continue; - - changed |= visibleParameterAnnotation.removeIf(ANNOTATION_NODE_PREDICATE); - } - }); - - classWrapper - .fields() - .forEach( - fieldNode -> { - if (fieldNode.invisibleAnnotations != null) - changed |= fieldNode.invisibleAnnotations.removeIf(ANNOTATION_NODE_PREDICATE); - - if (fieldNode.visibleAnnotations != null) - changed |= fieldNode.visibleAnnotations.removeIf(ANNOTATION_NODE_PREDICATE); - }); - }); + protected void transform() throws Exception { + scopedClasses().forEach(classWrapper -> { + if (classWrapper.classNode().invisibleAnnotations != null) + changed |= classWrapper + .classNode() + .invisibleAnnotations + .removeIf(ANNOTATION_NODE_PREDICATE); + + if (classWrapper.classNode().visibleAnnotations != null) + changed |= classWrapper.classNode().visibleAnnotations.removeIf(ANNOTATION_NODE_PREDICATE); + + classWrapper.methods().forEach(methodNode -> { + if (methodNode.invisibleAnnotations != null) + changed |= methodNode.invisibleAnnotations.removeIf(ANNOTATION_NODE_PREDICATE); + + if (methodNode.visibleAnnotations != null) + changed |= methodNode.visibleAnnotations.removeIf(ANNOTATION_NODE_PREDICATE); + + if (methodNode.invisibleParameterAnnotations != null) + for (List invisibleParameterAnnotation : methodNode.invisibleParameterAnnotations) { + if (invisibleParameterAnnotation == null) continue; + + changed |= invisibleParameterAnnotation.removeIf(ANNOTATION_NODE_PREDICATE); + } + + if (methodNode.visibleParameterAnnotations != null) + for (List visibleParameterAnnotation : methodNode.visibleParameterAnnotations) { + if (visibleParameterAnnotation == null) continue; + + changed |= visibleParameterAnnotation.removeIf(ANNOTATION_NODE_PREDICATE); + } + }); + + classWrapper.fields().forEach(fieldNode -> { + if (fieldNode.invisibleAnnotations != null) + changed |= fieldNode.invisibleAnnotations.removeIf(ANNOTATION_NODE_PREDICATE); + + if (fieldNode.visibleAnnotations != null) + changed |= fieldNode.visibleAnnotations.removeIf(ANNOTATION_NODE_PREDICATE); + }); + }); if (changed) { markChange(); diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/RecoverSyntheticsTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/RecoverSyntheticsTransformer.java index 7a30e908..24a5df62 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/RecoverSyntheticsTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/RecoverSyntheticsTransformer.java @@ -1,13 +1,11 @@ package uwu.narumi.deobfuscator.core.other.impl.universal; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.transformer.Transformer; public class RecoverSyntheticsTransformer extends Transformer { @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - context.classes(scope).forEach(classWrapper -> { + protected void transform() throws Exception { + scopedClasses().forEach(classWrapper -> { classWrapper.methods().forEach(methodNode -> { // Recover by name if (methodNode.name.startsWith("lambda$")) { diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/TryCatchRepairTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/TryCatchRepairTransformer.java index 1cc6be75..df541863 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/TryCatchRepairTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/TryCatchRepairTransformer.java @@ -1,16 +1,14 @@ package uwu.narumi.deobfuscator.core.other.impl.universal; import org.objectweb.asm.tree.LabelNode; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.transformer.Transformer; // TODO: Will probably shit itself public class TryCatchRepairTransformer extends Transformer { @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - context.classes(scope).forEach(classWrapper -> classWrapper.methods().forEach(methodNode -> { + protected void transform() throws Exception { + scopedClasses().forEach(classWrapper -> classWrapper.methods().forEach(methodNode -> { methodNode.tryCatchBlocks.removeIf(tryCatchBlock -> { LabelNode start = tryCatchBlock.start; LabelNode handler = tryCatchBlock.handler; diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/flow/CleanRedundantJumpsTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/flow/CleanRedundantJumpsTransformer.java index 7ddbcc9e..118c966e 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/flow/CleanRedundantJumpsTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/flow/CleanRedundantJumpsTransformer.java @@ -2,8 +2,6 @@ import org.objectweb.asm.tree.JumpInsnNode; import org.objectweb.asm.tree.MethodNode; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.helper.AsmMathHelper; import uwu.narumi.deobfuscator.api.helper.FramedInstructionsStream; import uwu.narumi.deobfuscator.api.transformer.Transformer; @@ -12,8 +10,8 @@ public class CleanRedundantJumpsTransformer extends Transformer { @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - FramedInstructionsStream.of(scope, context).forEach(insnContext -> { + protected void transform() throws Exception { + FramedInstructionsStream.of(this).forEach(insnContext -> { if (!(insnContext.insn() instanceof JumpInsnNode jumpInsn)) return; Optional optIfResult = AsmMathHelper.predictIf(jumpInsn, insnContext.frame()); diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/flow/CleanRedundantSwitchesTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/flow/CleanRedundantSwitchesTransformer.java index 3e66ecc0..98af7a4a 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/flow/CleanRedundantSwitchesTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/flow/CleanRedundantSwitchesTransformer.java @@ -4,8 +4,6 @@ import org.objectweb.asm.tree.LabelNode; import org.objectweb.asm.tree.LookupSwitchInsnNode; import org.objectweb.asm.tree.TableSwitchInsnNode; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.helper.AsmMathHelper; import uwu.narumi.deobfuscator.api.helper.FramedInstructionsStream; import uwu.narumi.deobfuscator.api.transformer.Transformer; @@ -18,8 +16,8 @@ public class CleanRedundantSwitchesTransformer extends Transformer { @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - FramedInstructionsStream.of(scope, context).forEach(insnContext -> { + protected void transform() throws Exception { + FramedInstructionsStream.of(this).forEach(insnContext -> { if (insnContext.insn().getOpcode() == LOOKUPSWITCH) { LookupSwitchInsnNode lookupSwitchInsn = (LookupSwitchInsnNode) insnContext.insn(); diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/number/MathBinaryOperationsTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/number/MathBinaryOperationsTransformer.java index 7ac99eba..dadb41c6 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/number/MathBinaryOperationsTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/number/MathBinaryOperationsTransformer.java @@ -2,8 +2,6 @@ import org.objectweb.asm.tree.AbstractInsnNode; import org.objectweb.asm.tree.analysis.OriginalSourceValue; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.helper.AsmHelper; import uwu.narumi.deobfuscator.api.helper.AsmMathHelper; import uwu.narumi.deobfuscator.api.helper.FramedInstructionsStream; @@ -15,8 +13,8 @@ public class MathBinaryOperationsTransformer extends Transformer { @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - FramedInstructionsStream.of(scope, context) + protected void transform() throws Exception { + FramedInstructionsStream.of(this) .editInstructionsStream(stream -> stream.filter(insn -> AsmMathHelper.isMathBinaryOperation(insn.getOpcode()))) .forEach(insnContext -> { // Get instructions from stack that are passed diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/number/MathUnaryOperationsTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/number/MathUnaryOperationsTransformer.java index 3fe8acec..fc18dab3 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/number/MathUnaryOperationsTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/number/MathUnaryOperationsTransformer.java @@ -2,8 +2,6 @@ import org.objectweb.asm.tree.AbstractInsnNode; import org.objectweb.asm.tree.analysis.OriginalSourceValue; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.helper.AsmHelper; import uwu.narumi.deobfuscator.api.helper.AsmMathHelper; import uwu.narumi.deobfuscator.api.helper.FramedInstructionsStream; @@ -14,8 +12,8 @@ */ public class MathUnaryOperationsTransformer extends Transformer { @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - FramedInstructionsStream.of(scope, context) + protected void transform() throws Exception { + FramedInstructionsStream.of(this) .editInstructionsStream(stream -> stream.filter(insn -> AsmMathHelper.isMathUnaryOperation(insn.getOpcode()))) .forEach(insnContext -> { // Get instructions from stack that are passed diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/number/MethodCallsOnLiteralsTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/number/MethodCallsOnLiteralsTransformer.java index 830f231f..efb85df5 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/number/MethodCallsOnLiteralsTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/universal/number/MethodCallsOnLiteralsTransformer.java @@ -1,8 +1,6 @@ package uwu.narumi.deobfuscator.core.other.impl.universal.number; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; import uwu.narumi.deobfuscator.api.asm.matcher.Match; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.helper.AsmMathHelper; import uwu.narumi.deobfuscator.api.helper.FramedInstructionsStream; import uwu.narumi.deobfuscator.api.transformer.Transformer; @@ -13,8 +11,8 @@ public class MethodCallsOnLiteralsTransformer extends Transformer { @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - FramedInstructionsStream.of(scope, context).forEach(insnContext -> { + protected void transform() throws Exception { + FramedInstructionsStream.of(this).forEach(insnContext -> { // Transform method calls on literals for (Match mathMatch : AsmMathHelper.METHOD_CALLS_ON_LITERALS) { if (mathMatch.matches(insnContext)) { diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/zkm/ZelixLongEncryptionMPCTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/zkm/ZelixLongEncryptionMPCTransformer.java index 8f250956..cb4302b7 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/zkm/ZelixLongEncryptionMPCTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/zkm/ZelixLongEncryptionMPCTransformer.java @@ -1,14 +1,11 @@ package uwu.narumi.deobfuscator.core.other.impl.zkm; -import dev.xdark.ssvm.execution.VMException; import dev.xdark.ssvm.invoke.Argument; import dev.xdark.ssvm.mirror.type.InstanceClass; import dev.xdark.ssvm.value.ObjectValue; -import org.objectweb.asm.tree.AbstractInsnNode; import org.objectweb.asm.tree.MethodInsnNode; import org.objectweb.asm.tree.MethodNode; import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.asm.InsnContext; import uwu.narumi.deobfuscator.api.asm.MethodContext; import uwu.narumi.deobfuscator.api.asm.matcher.Match; import uwu.narumi.deobfuscator.api.asm.matcher.MatchContext; @@ -104,24 +101,24 @@ public ZelixLongEncryptionMPCTransformer(Map classInitOrder) { } @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { + protected void transform() throws Exception { // Firstly, process the manual list of class initialization order for (var entry : classInitOrder.entrySet()) { - ClassWrapper first = context.getClasses().get(entry.getKey()); - ClassWrapper second = context.getClasses().get(entry.getValue()); + ClassWrapper first = context().getClasses().get(entry.getKey()); + ClassWrapper second = context().getClasses().get(entry.getValue()); - decryptEncryptedLongs(context, first); - decryptEncryptedLongs(context, second); + decryptEncryptedLongs(context(), first); + decryptEncryptedLongs(context(), second); } // Decrypt longs - context.classes(scope).forEach(classWrapper -> { - decryptEncryptedLongs(context, classWrapper); + scopedClasses().forEach(classWrapper -> { + decryptEncryptedLongs(context(), classWrapper); }); // Remove decrypter classes if (sandBox != null) { - sandBox.getUsedCustomClasses().forEach(clazz -> context.getClasses().remove(clazz.getInternalName())); + sandBox.getUsedCustomClasses().forEach(clazz -> context().getClasses().remove(clazz.getInternalName())); } } diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/zkm/ZelixParametersTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/zkm/ZelixParametersTransformer.java index eeefd634..73f1018d 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/zkm/ZelixParametersTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/zkm/ZelixParametersTransformer.java @@ -7,8 +7,6 @@ import org.objectweb.asm.tree.MethodNode; import org.objectweb.asm.tree.TypeInsnNode; import org.objectweb.asm.tree.VarInsnNode; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.asm.InsnContext; import uwu.narumi.deobfuscator.api.asm.MethodContext; import uwu.narumi.deobfuscator.api.asm.matcher.Match; import uwu.narumi.deobfuscator.api.asm.matcher.MatchContext; @@ -16,7 +14,6 @@ import uwu.narumi.deobfuscator.api.asm.matcher.impl.NumberMatch; import uwu.narumi.deobfuscator.api.asm.matcher.impl.OpcodeMatch; import uwu.narumi.deobfuscator.api.asm.matcher.impl.StackMatch; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.helper.AsmHelper; import uwu.narumi.deobfuscator.api.helper.MethodHelper; import uwu.narumi.deobfuscator.api.transformer.Transformer; @@ -85,8 +82,8 @@ public class ZelixParametersTransformer extends Transformer { ); @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - context.classes(scope).forEach(classWrapper -> classWrapper.methods().stream() + protected void transform() throws Exception { + scopedClasses().forEach(classWrapper -> classWrapper.methods().stream() .filter(methodNode -> methodNode.desc.startsWith("([Ljava/lang/Object;)")) .forEach(methodNode -> { MethodContext methodContext = MethodContext.framed(classWrapper, methodNode); @@ -102,7 +99,7 @@ protected void transform(ClassWrapper scope, Context context) throws Exception { if (shouldReplaceArgumentTypes) { // Update method arguments String desc = Type.getMethodDescriptor(Type.getReturnType(methodNode.desc), newArgumentTypes.toArray(new Type[0])); - AsmHelper.updateMethodDescriptor(context, methodContext, desc); + AsmHelper.updateMethodDescriptor(context(), methodContext, desc); // Replace local variables indexes with the corresponding ones fixLocalVariableIndexes(methodNode, newVarIndexes); diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/zkm/ZelixStringTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/zkm/ZelixStringTransformer.java index f73e9d0a..896e1d0d 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/zkm/ZelixStringTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/zkm/ZelixStringTransformer.java @@ -1,8 +1,6 @@ package uwu.narumi.deobfuscator.core.other.impl.zkm; import org.objectweb.asm.tree.*; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.transformer.Transformer; import java.util.ArrayList; @@ -22,8 +20,8 @@ public class ZelixStringTransformer extends Transformer { /* Written by https://github.com/Lampadina17 | OG 19/07/2024, Rewritten 09/08/2024 */ @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - context.classes(scope).forEach(classWrapper -> { + protected void transform() throws Exception { + scopedClasses().forEach(classWrapper -> { /* Extract key type 1 from hardcoded xor encryption */ classWrapper.methods().stream() .filter(methodNode -> methodNode.desc.equals("(Ljava/lang/String;)[C")) @@ -96,7 +94,7 @@ protected void transform(ClassWrapper scope, Context context) throws Exception { }); /* Decrypt and cleanup */ - context.classes(scope).forEach(classWrapper -> { + scopedClasses().forEach(classWrapper -> { classWrapper.methods().stream() .forEach(methodNode -> { List encrypted = encryptedStrings.get(classWrapper.name()); @@ -172,7 +170,7 @@ protected void transform(ClassWrapper scope, Context context) throws Exception { } }); }); - LOGGER.info("Decrypted {} strings in {} classes", this.getChangesCount(), context.classes().size()); + LOGGER.info("Decrypted {} strings in {} classes", this.getChangesCount(), scopedClasses().size()); } /* Convert arraylist to array and shift values, when a bug transform into a feature (Key type 2) */ diff --git a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/zkm/ZelixUselessTryCatchRemoverTransformer.java b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/zkm/ZelixUselessTryCatchRemoverTransformer.java index 2e9d8e46..9d30c037 100644 --- a/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/zkm/ZelixUselessTryCatchRemoverTransformer.java +++ b/deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/zkm/ZelixUselessTryCatchRemoverTransformer.java @@ -1,7 +1,6 @@ package uwu.narumi.deobfuscator.core.other.impl.zkm; import org.objectweb.asm.tree.MethodInsnNode; -import uwu.narumi.deobfuscator.api.asm.ClassWrapper; import uwu.narumi.deobfuscator.api.asm.InsnContext; import uwu.narumi.deobfuscator.api.asm.MethodContext; import uwu.narumi.deobfuscator.api.asm.MethodRef; @@ -10,7 +9,6 @@ import uwu.narumi.deobfuscator.api.asm.matcher.group.SequenceMatch; import uwu.narumi.deobfuscator.api.asm.matcher.impl.MethodMatch; import uwu.narumi.deobfuscator.api.asm.matcher.impl.OpcodeMatch; -import uwu.narumi.deobfuscator.api.context.Context; import uwu.narumi.deobfuscator.api.transformer.Transformer; import java.util.ArrayList; @@ -51,8 +49,8 @@ public class ZelixUselessTryCatchRemoverTransformer extends Transformer { ); @Override - protected void transform(ClassWrapper scope, Context context) throws Exception { - context.classes(scope).forEach(classWrapper -> { + protected void transform() throws Exception { + scopedClasses().forEach(classWrapper -> { List instantReturnExceptionMethods = new ArrayList<>(); // Find methods that instantly returns an exception