From e46230c39d3a0eee7965da308c6db916cf6d0c39 Mon Sep 17 00:00:00 2001 From: IotaBread Date: Thu, 4 Apr 2024 00:39:41 -0300 Subject: [PATCH] Remove `InterpreterPair`, fix a crash with ASM 9.7 --- .../enigma/impl/analysis/InterpreterPair.java | 118 ------------------ .../analysis/index/IndexReferenceVisitor.java | 26 ++-- 2 files changed, 12 insertions(+), 132 deletions(-) delete mode 100644 enigma/src/main/java/org/quiltmc/enigma/impl/analysis/InterpreterPair.java diff --git a/enigma/src/main/java/org/quiltmc/enigma/impl/analysis/InterpreterPair.java b/enigma/src/main/java/org/quiltmc/enigma/impl/analysis/InterpreterPair.java deleted file mode 100644 index 93ee6ffca..000000000 --- a/enigma/src/main/java/org/quiltmc/enigma/impl/analysis/InterpreterPair.java +++ /dev/null @@ -1,118 +0,0 @@ -package org.quiltmc.enigma.impl.analysis; - -import org.quiltmc.enigma.api.Enigma; -import org.objectweb.asm.Type; -import org.objectweb.asm.tree.AbstractInsnNode; -import org.objectweb.asm.tree.analysis.AnalyzerException; -import org.objectweb.asm.tree.analysis.Interpreter; -import org.objectweb.asm.tree.analysis.Value; - -import java.util.List; -import java.util.Objects; - -public class InterpreterPair extends Interpreter> { - private final Interpreter left; - private final Interpreter right; - - public InterpreterPair(Interpreter left, Interpreter right) { - super(Enigma.ASM_VERSION); - this.left = left; - this.right = right; - } - - @Override - public PairValue newValue(Type type) { - return this.pair( - this.left.newValue(type), - this.right.newValue(type) - ); - } - - @Override - public PairValue newOperation(AbstractInsnNode insn) throws AnalyzerException { - return this.pair( - this.left.newOperation(insn), - this.right.newOperation(insn) - ); - } - - @Override - public PairValue copyOperation(AbstractInsnNode insn, PairValue value) throws AnalyzerException { - return this.pair( - this.left.copyOperation(insn, value.left), - this.right.copyOperation(insn, value.right) - ); - } - - @Override - public PairValue unaryOperation(AbstractInsnNode insn, PairValue value) throws AnalyzerException { - return this.pair( - this.left.unaryOperation(insn, value.left), - this.right.unaryOperation(insn, value.right) - ); - } - - @Override - public PairValue binaryOperation(AbstractInsnNode insn, PairValue value1, PairValue value2) throws AnalyzerException { - return this.pair( - this.left.binaryOperation(insn, value1.left, value2.left), - this.right.binaryOperation(insn, value1.right, value2.right) - ); - } - - @Override - public PairValue ternaryOperation(AbstractInsnNode insn, PairValue value1, PairValue value2, PairValue value3) throws AnalyzerException { - return this.pair( - this.left.ternaryOperation(insn, value1.left, value2.left, value3.left), - this.right.ternaryOperation(insn, value1.right, value2.right, value3.right) - ); - } - - @Override - public PairValue naryOperation(AbstractInsnNode insn, List> values) throws AnalyzerException { - return this.pair( - this.left.naryOperation(insn, values.stream().map(PairValue::left).toList()), - this.right.naryOperation(insn, values.stream().map(PairValue::right).toList()) - ); - } - - @Override - public void returnOperation(AbstractInsnNode insn, PairValue value, PairValue expected) throws AnalyzerException { - this.left.returnOperation(insn, value.left, expected.left); - this.right.returnOperation(insn, value.right, expected.right); - } - - @Override - public PairValue merge(PairValue value1, PairValue value2) { - return this.pair( - this.left.merge(value1.left, value2.left), - this.right.merge(value1.right, value2.right) - ); - } - - private PairValue pair(V left, W right) { - if (left == null && right == null) { - return null; - } - - return new PairValue<>(left, right); - } - - public record PairValue(V left, W right) implements Value { - public PairValue { - if (left == null && right == null) { - throw new IllegalArgumentException("should use null rather than pair of nulls"); - } - } - - @Override - public boolean equals(Object o) { - return o instanceof InterpreterPair.PairValue pairValue && Objects.equals(this.left, pairValue.left) && Objects.equals(this.right, pairValue.right); - } - - @Override - public int getSize() { - return (this.left == null ? this.right : this.left).getSize(); - } - } -} diff --git a/enigma/src/main/java/org/quiltmc/enigma/impl/analysis/index/IndexReferenceVisitor.java b/enigma/src/main/java/org/quiltmc/enigma/impl/analysis/index/IndexReferenceVisitor.java index 174870e28..5dcd5a09e 100644 --- a/enigma/src/main/java/org/quiltmc/enigma/impl/analysis/index/IndexReferenceVisitor.java +++ b/enigma/src/main/java/org/quiltmc/enigma/impl/analysis/index/IndexReferenceVisitor.java @@ -5,7 +5,6 @@ import org.quiltmc.enigma.api.analysis.index.jar.EntryIndex; import org.quiltmc.enigma.api.analysis.index.jar.InheritanceIndex; import org.quiltmc.enigma.impl.analysis.IndexSimpleVerifier; -import org.quiltmc.enigma.impl.analysis.InterpreterPair; import org.quiltmc.enigma.impl.analysis.MethodNodeWithAction; import org.quiltmc.enigma.api.analysis.ReferenceTargetType; import org.quiltmc.enigma.api.analysis.index.jar.JarIndexer; @@ -30,8 +29,6 @@ import org.objectweb.asm.tree.analysis.Analyzer; import org.objectweb.asm.tree.analysis.AnalyzerException; import org.objectweb.asm.tree.analysis.BasicValue; -import org.objectweb.asm.tree.analysis.SourceInterpreter; -import org.objectweb.asm.tree.analysis.SourceValue; import java.util.List; @@ -67,18 +64,19 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si }); } - private static class MethodInterpreter extends InterpreterPair { + // TODO: IndexSimpleVerifier might have issues + private static class MethodInterpreter extends IndexSimpleVerifier { private final MethodDefEntry callerEntry; private final JarIndexer indexer; MethodInterpreter(MethodDefEntry callerEntry, JarIndexer indexer, EntryIndex entryIndex, InheritanceIndex inheritanceIndex) { - super(new IndexSimpleVerifier(entryIndex, inheritanceIndex), new SourceInterpreter()); + super(entryIndex, inheritanceIndex); this.callerEntry = callerEntry; this.indexer = indexer; } @Override - public PairValue newOperation(AbstractInsnNode insn) throws AnalyzerException { + public BasicValue newOperation(AbstractInsnNode insn) throws AnalyzerException { if (insn.getOpcode() == Opcodes.GETSTATIC) { FieldInsnNode field = (FieldInsnNode) insn; this.indexer.indexFieldReference(this.callerEntry, FieldEntry.parse(field.owner, field.name, field.desc), ReferenceTargetType.none()); @@ -97,7 +95,7 @@ public PairValue newOperation(AbstractInsnNode insn) th } @Override - public PairValue unaryOperation(AbstractInsnNode insn, PairValue value) throws AnalyzerException { + public BasicValue unaryOperation(AbstractInsnNode insn, BasicValue value) throws AnalyzerException { if (insn.getOpcode() == Opcodes.PUTSTATIC) { FieldInsnNode field = (FieldInsnNode) insn; this.indexer.indexFieldReference(this.callerEntry, FieldEntry.parse(field.owner, field.name, field.desc), ReferenceTargetType.none()); @@ -124,7 +122,7 @@ public PairValue unaryOperation(AbstractInsnNode insn, } @Override - public PairValue binaryOperation(AbstractInsnNode insn, PairValue value1, PairValue value2) throws AnalyzerException { + public BasicValue binaryOperation(AbstractInsnNode insn, BasicValue value1, BasicValue value2) throws AnalyzerException { if (insn.getOpcode() == Opcodes.PUTFIELD) { FieldInsnNode field = (FieldInsnNode) insn; FieldEntry fieldEntry = FieldEntry.parse(field.owner, field.name, field.desc); @@ -135,7 +133,7 @@ public PairValue binaryOperation(AbstractInsnNode insn, } @Override - public PairValue naryOperation(AbstractInsnNode insn, List> values) throws AnalyzerException { + public BasicValue naryOperation(AbstractInsnNode insn, List values) throws AnalyzerException { if (insn.getOpcode() == Opcodes.INVOKEINTERFACE || insn.getOpcode() == Opcodes.INVOKESPECIAL || insn.getOpcode() == Opcodes.INVOKEVIRTUAL) { MethodInsnNode methodInsn = (MethodInsnNode) insn; this.indexer.indexMethodReference(this.callerEntry, MethodEntry.parse(methodInsn.owner, methodInsn.name, methodInsn.desc), this.getReferenceTargetType(values.get(0), insn)); @@ -178,16 +176,16 @@ public PairValue naryOperation(AbstractInsnNode insn, L return super.naryOperation(insn, values); } - private ReferenceTargetType getReferenceTargetType(PairValue target, AbstractInsnNode insn) throws AnalyzerException { - if (target.left() == BasicValue.UNINITIALIZED_VALUE) { + private ReferenceTargetType getReferenceTargetType(BasicValue target, AbstractInsnNode insn) throws AnalyzerException { + if (target == BasicValue.UNINITIALIZED_VALUE) { return ReferenceTargetType.uninitialized(); } - if (target.left().getType().getSort() == Type.OBJECT) { - return ReferenceTargetType.classType(new ClassEntry(target.left().getType().getInternalName())); + if (target.getType().getSort() == Type.OBJECT) { + return ReferenceTargetType.classType(new ClassEntry(target.getType().getInternalName())); } - if (target.left().getType().getSort() == Type.ARRAY) { + if (target.getType().getSort() == Type.ARRAY) { return ReferenceTargetType.classType(new ClassEntry("java/lang/Object")); }