Skip to content

Commit

Permalink
Fix the crash with newer asm versions by explicitly expanding and rec…
Browse files Browse the repository at this point in the history
…omputing stack frames
  • Loading branch information
eigenraven committed Jan 25, 2023
1 parent adb4297 commit f0038f8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/main/java/ru/fewizz/idextender/asm/IETransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/ru/fewizz/idextender/asm/Name.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ru.fewizz.idextender.asm;

import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.*;

public enum Name {
Expand Down Expand Up @@ -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() {
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/ru/fewizz/idextender/asm/transformer/SelfHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,32 @@ 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;
}

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;
}

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;
}
Expand Down

0 comments on commit f0038f8

Please sign in to comment.