From f0038f849ff241f1b63c346129e1d1ad7bd5957a Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Wed, 25 Jan 2023 12:37:23 +0000 Subject: [PATCH] Fix the crash with newer asm versions by explicitly expanding and recomputing stack frames --- .../fewizz/idextender/asm/IETransformer.java | 4 ++-- .../java/ru/fewizz/idextender/asm/Name.java | 5 +++-- .../idextender/asm/transformer/SelfHooks.java | 20 +++++++++---------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main/java/ru/fewizz/idextender/asm/IETransformer.java b/src/main/java/ru/fewizz/idextender/asm/IETransformer.java index 8533781..6919d57 100644 --- a/src/main/java/ru/fewizz/idextender/asm/IETransformer.java +++ b/src/main/java/ru/fewizz/idextender/asm/IETransformer.java @@ -25,7 +25,7 @@ public byte[] transform(final String name, final String transformedName, final b final ClassNode cn = new ClassNode(Opcodes.ASM5); final ClassReader reader = new ClassReader(bytes); final int readFlags = 0; - reader.accept(cn, 0); + reader.accept(cn, ClassReader.EXPAND_FRAMES); try { edit.getTransformer().transform(cn, IETransformer.isObfuscated); } catch (AsmTransformException t) { @@ -37,7 +37,7 @@ public byte[] transform(final String name, final String transformedName, final b "Error transforming {} with {}: {}", transformedName, edit.getName(), t2.getMessage()); throw new RuntimeException(t2); } - final ClassWriter writer = new ClassWriter(0); + final ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); try { final ClassVisitor check = new CheckClassAdapter(writer); cn.accept(check); diff --git a/src/main/java/ru/fewizz/idextender/asm/Name.java b/src/main/java/ru/fewizz/idextender/asm/Name.java index f94ef7b..57f6efe 100644 --- a/src/main/java/ru/fewizz/idextender/asm/Name.java +++ b/src/main/java/ru/fewizz/idextender/asm/Name.java @@ -1,5 +1,6 @@ package ru.fewizz.idextender.asm; +import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.*; public enum Name { @@ -245,9 +246,9 @@ public FieldInsnNode staticSet(final boolean obfuscated) { public FieldInsnNode virtualSet(final boolean obfuscated) { assert !this.desc.startsWith("("); if (obfuscated) { - return new FieldInsnNode(181, this.clazz.srg, this.srg, this.desc); + return new FieldInsnNode(Opcodes.PUTFIELD, this.clazz.srg, this.srg, this.desc); } - return new FieldInsnNode(181, this.clazz.deobf, this.deobf, this.desc); + return new FieldInsnNode(Opcodes.PUTFIELD, this.clazz.deobf, this.deobf, this.desc); } private static void translateDescs() { diff --git a/src/main/java/ru/fewizz/idextender/asm/transformer/SelfHooks.java b/src/main/java/ru/fewizz/idextender/asm/transformer/SelfHooks.java index fe706c1..d7c2a80 100644 --- a/src/main/java/ru/fewizz/idextender/asm/transformer/SelfHooks.java +++ b/src/main/java/ru/fewizz/idextender/asm/transformer/SelfHooks.java @@ -18,10 +18,10 @@ public void transform(final ClassNode cn, final boolean obfuscated) { private void transformGet(final ClassNode cn, final MethodNode method) { final InsnList code = method.instructions; code.clear(); - code.add(new VarInsnNode(25, 0)); - code.add( - new FieldInsnNode(180, Type.getArgumentTypes(method.desc)[0].getInternalName(), "block16BArray", "[S")); - code.add(new InsnNode(176)); + code.add(new VarInsnNode(Opcodes.ALOAD, 0)); + code.add(new FieldInsnNode( + Opcodes.GETFIELD, Type.getArgumentTypes(method.desc)[0].getInternalName(), "block16BArray", "[S")); + code.add(new InsnNode(Opcodes.ARETURN)); method.localVariables = null; method.maxStack = 1; } @@ -29,10 +29,10 @@ private void transformGet(final ClassNode cn, final MethodNode method) { private void transformSetBlockRefCount(final ClassNode cn, final MethodNode method, final boolean isObf) { final InsnList code = method.instructions; code.clear(); - code.add(new VarInsnNode(25, 0)); - code.add(new VarInsnNode(21, 1)); + code.add(new VarInsnNode(Opcodes.ALOAD, 0)); + code.add(new VarInsnNode(Opcodes.ILOAD, 1)); code.add(Name.ebs_blockRefCount.virtualSet(isObf)); - code.add(new InsnNode(177)); + code.add(new InsnNode(Opcodes.RETURN)); method.localVariables = null; method.maxStack = 2; } @@ -40,10 +40,10 @@ private void transformSetBlockRefCount(final ClassNode cn, final MethodNode meth private void transformSetTickRefCount(final ClassNode cn, final MethodNode method, final boolean isObf) { final InsnList code = method.instructions; code.clear(); - code.add(new VarInsnNode(25, 0)); - code.add(new VarInsnNode(21, 1)); + code.add(new VarInsnNode(Opcodes.ALOAD, 0)); + code.add(new VarInsnNode(Opcodes.ILOAD, 1)); code.add(Name.ebs_tickRefCount.virtualSet(isObf)); - code.add(new InsnNode(177)); + code.add(new InsnNode(Opcodes.RETURN)); method.localVariables = null; method.maxStack = 2; }