From bf73e15c3fa4b49663e1160211fe529ad1f1ecef Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Fri, 14 Dec 2018 20:16:54 +0300 Subject: [PATCH] Added wrap. Fixed NeverDecomp. --- .../gravit/launchserver/asm/AntiDecomp.java | 56 ------------------- .../manangers/BuildHookManager.java | 15 +++++ modules | 2 +- 3 files changed, 16 insertions(+), 57 deletions(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/asm/AntiDecomp.java b/LaunchServer/src/main/java/ru/gravit/launchserver/asm/AntiDecomp.java index ed81f8f3..2ec6b426 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/asm/AntiDecomp.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/asm/AntiDecomp.java @@ -19,55 +19,6 @@ public class AntiDecomp { Throwable.class, Exception.class, Error.class, InternalError.class, RuntimeException.class, NullPointerException.class, AssertionError.class, NoClassDefFoundError.class, IOException.class, NoSuchFieldException.class, SecurityException.class, InvocationTargetException.class }; - private static class ObfClassVisitor extends ClassVisitor { - private Random r = new SecureRandom(); - private ObfClassVisitor(ClassVisitor classVisitor) { - super(Opcodes.ASM7, classVisitor); - } - - @Override - public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { - return new AdviceAdapter(Opcodes.ASM7, super.visitMethod(access, name, desc, signature, exceptions), access, - name, desc) { - - @Override - public void onMethodEnter() { - antiDecomp(); - } - - public void antiDecomp() { - Label lbl1 = super.newLabel(), lbl15 = super.newLabel(), lbl2 = super.newLabel(), - lbl25 = super.newLabel(); - - // try-catch блок с lbl1 до lbl2 с переходом на lbl2 при java/lang/Exception - this.visitException(lbl1, lbl2, lbl2); - - // lbl1: iconst_0 - super.visitLabel(lbl1); - super.visitInsn(ICONST_0); - // lbl15: pop; goto lbl25 - super.visitLabel(lbl15); - super.visitInsn(POP); - this.jumpLabel(lbl25); - // lbl2: pop; pop2 - super.visitLabel(lbl2); - super.visitInsn(POP); - super.visitInsn(POP2); - // lbl25: - super.visitLabel(lbl25); - } - - public void visitException(Label st, Label en, Label h) { - super.visitTryCatchBlock(st, en, h, Type.getInternalName(exceptionsL[r.nextInt(exceptionsL.length-1)])); - } - - public void jumpLabel(Label to) { - super.visitJumpInsn(GOTO, to); - } - }; - } - } - private static class AObfClassVisitor extends ClassVisitor { private Random r = new SecureRandom(); private AObfClassVisitor(ClassVisitor classVisitor) { @@ -134,11 +85,4 @@ public static byte[] antiDecomp(final byte[] input, ClassMetadataReader reader) cr.accept(new AObfClassVisitor(cw), ClassReader.SKIP_DEBUG | ClassReader.EXPAND_FRAMES); return cw.toByteArray(); } - - public static byte[] expAntiDecomp(byte[] input, ClassMetadataReader reader) { - ClassReader cr = new ClassReader(input); - ClassWriter cw = new SafeClassWriter(reader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); - cr.accept(new ObfClassVisitor(cw), ClassReader.SKIP_DEBUG | ClassReader.EXPAND_FRAMES); - return cw.toByteArray(); - } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/BuildHookManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/BuildHookManager.java index 983f5ac7..81c47339 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/BuildHookManager.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/BuildHookManager.java @@ -4,10 +4,12 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.function.BiFunction; import java.util.zip.ZipOutputStream; import ru.gravit.launcher.AutogenConfig; import ru.gravit.launcher.modules.TestClientModule; +import ru.gravit.launchserver.asm.ClassMetadataReader; import ru.gravit.launchserver.binary.BuildContext; import ru.gravit.launchserver.binary.JAConfigurator; import ru.gravit.launchserver.binary.JARLauncherBinary; @@ -28,6 +30,11 @@ public static interface Transformer { byte[] transform(byte[] input, String classname, JARLauncherBinary data); } + @FunctionalInterface + public static interface ReaderTransformer { + byte[] transform(byte[] input, String classname, ClassMetadataReader data); + } + private boolean BUILDRUNTIME; private final Set POST_HOOKS; private final Set POST_PROGUARDRUN_HOOKS; @@ -161,4 +168,12 @@ public void registerPreHook(BuildHook hook) { public void setBuildRuntime(boolean runtime) { BUILDRUNTIME = runtime; } + + public static Transformer wrap(BiFunction func) { + return (code, name, binaryCls) -> func.apply(code, binaryCls.reader); + } + + public static Transformer wrap(ReaderTransformer func) { + return (code, name, binaryCls) -> func.transform(code, name, binaryCls.reader); + } } diff --git a/modules b/modules index b956ffe0..c4705248 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit b956ffe0479d6b7b8c28c6f16864e516f45b307d +Subproject commit c4705248d6e6576294a9ff62edd4dd263b682533