Fixed bug what I get at morning.

This commit is contained in:
zaxar163 2018-12-13 16:20:04 +03:00
parent 9f09eb405d
commit c0cf0475ce
No known key found for this signature in database
GPG key ID: E3B309DD3852DE06

View file

@ -1,6 +1,7 @@
package ru.gravit.launchserver.asm; package ru.gravit.launchserver.asm;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.Random; import java.util.Random;
@ -16,9 +17,10 @@
public class AntiDecomp { public class AntiDecomp {
private static final Class<?>[] exceptionsL = { private static final Class<?>[] exceptionsL = {
Throwable.class, Exception.class, Error.class, InternalError.class, RuntimeException.class, NullPointerException.class, Throwable.class, Exception.class, Error.class, InternalError.class, RuntimeException.class, NullPointerException.class,
AssertionError.class, NoClassDefFoundError.class, IOException.class, NoSuchFieldException.class AssertionError.class, NoClassDefFoundError.class, IOException.class, NoSuchFieldException.class, SecurityException.class, InvocationTargetException.class
}; };
private static class ObfClassVisitor extends ClassVisitor { private static class ObfClassVisitor extends ClassVisitor {
private Random r = new SecureRandom();
private ObfClassVisitor(ClassVisitor classVisitor) { private ObfClassVisitor(ClassVisitor classVisitor) {
super(Opcodes.ASM7, classVisitor); super(Opcodes.ASM7, classVisitor);
} }
@ -27,7 +29,6 @@ private ObfClassVisitor(ClassVisitor classVisitor) {
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { 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, return new AdviceAdapter(Opcodes.ASM7, super.visitMethod(access, name, desc, signature, exceptions), access,
name, desc) { name, desc) {
private Random r = new SecureRandom();
@Override @Override
public void onMethodEnter() { public void onMethodEnter() {
@ -48,9 +49,10 @@ public void antiDecomp() {
super.visitLabel(lbl15); super.visitLabel(lbl15);
super.visitInsn(POP); super.visitInsn(POP);
this.jumpLabel(lbl25); this.jumpLabel(lbl25);
// lbl2: pop; // lbl2: pop; pop2
super.visitLabel(lbl2); super.visitLabel(lbl2);
super.visitInsn(POP); super.visitInsn(POP);
super.visitInsn(POP2);
// lbl25: // lbl25:
super.visitLabel(lbl25); super.visitLabel(lbl25);
} }
@ -67,6 +69,7 @@ public void jumpLabel(Label to) {
} }
private static class AObfClassVisitor extends ClassVisitor { private static class AObfClassVisitor extends ClassVisitor {
private Random r = new SecureRandom();
private AObfClassVisitor(ClassVisitor classVisitor) { private AObfClassVisitor(ClassVisitor classVisitor) {
super(Opcodes.ASM7, classVisitor); super(Opcodes.ASM7, classVisitor);
} }
@ -75,7 +78,6 @@ private AObfClassVisitor(ClassVisitor classVisitor) {
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { 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, return new AdviceAdapter(Opcodes.ASM7, super.visitMethod(access, name, desc, signature, exceptions), access,
name, desc) { name, desc) {
private Random r = new SecureRandom();
@Override @Override
public void onMethodEnter() { public void onMethodEnter() {
@ -129,14 +131,14 @@ private AntiDecomp() {
public static byte[] antiDecomp(final byte[] input, ClassMetadataReader reader) { public static byte[] antiDecomp(final byte[] input, ClassMetadataReader reader) {
ClassReader cr = new ClassReader(input); ClassReader cr = new ClassReader(input);
ClassWriter cw = new SafeClassWriter(reader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); ClassWriter cw = new SafeClassWriter(reader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
cr.accept(new AObfClassVisitor(cw), ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES); cr.accept(new AObfClassVisitor(cw), ClassReader.SKIP_DEBUG | ClassReader.EXPAND_FRAMES);
return cw.toByteArray(); return cw.toByteArray();
} }
public static byte[] expAntiDecomp(byte[] input, ClassMetadataReader reader) { public static byte[] expAntiDecomp(byte[] input, ClassMetadataReader reader) {
ClassReader cr = new ClassReader(input); ClassReader cr = new ClassReader(input);
ClassWriter cw = new SafeClassWriter(reader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); ClassWriter cw = new SafeClassWriter(reader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
cr.accept(new ObfClassVisitor(cw), ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES); cr.accept(new ObfClassVisitor(cw), ClassReader.SKIP_DEBUG | ClassReader.EXPAND_FRAMES);
return cw.toByteArray(); return cw.toByteArray();
} }
} }