diff --git a/src/main/java/net/runelite/asm/attributes/code/instructions/LCmp.java b/src/main/java/net/runelite/asm/attributes/code/instructions/LCmp.java index 4f449181e4..97a5bf1028 100644 --- a/src/main/java/net/runelite/asm/attributes/code/instructions/LCmp.java +++ b/src/main/java/net/runelite/asm/attributes/code/instructions/LCmp.java @@ -1,15 +1,22 @@ package net.runelite.asm.attributes.code.instructions; +import java.util.ArrayList; +import java.util.List; +import net.runelite.asm.Field; import net.runelite.asm.attributes.code.Instruction; import net.runelite.asm.attributes.code.InstructionType; import net.runelite.asm.attributes.code.Instructions; +import net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction; +import net.runelite.asm.attributes.code.instruction.types.MappableInstruction; import net.runelite.asm.execution.Frame; import net.runelite.asm.execution.InstructionContext; import net.runelite.asm.execution.Stack; import net.runelite.asm.execution.StackContext; import net.runelite.asm.execution.Value; +import net.runelite.deob.deobfuscators.rename.MappingExecutorUtil; +import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping; -public class LCmp extends Instruction +public class LCmp extends Instruction implements MappableInstruction { public LCmp(Instructions instructions, InstructionType type, int pc) { @@ -48,4 +55,52 @@ public class LCmp extends Instruction return ins; } + + @Override + public void map(ParallelExecutorMapping mappings, InstructionContext ctx, InstructionContext other) + { + List f1s = getComparedFields(ctx), f2s = getComparedFields(other); + + if (f1s == null || f2s == null || f1s.size() != f2s.size()) + return; + + for (int i = 0; i < f1s.size(); ++i) + { + Field f1 = f1s.get(i), f2 = f2s.get(i); + + mappings.map(f1, f2); + } + } + + private List getComparedFields(InstructionContext ctx) + { + List fields = new ArrayList<>(); + + for (StackContext sctx : ctx.getPops()) + { + InstructionContext base = MappingExecutorUtil.resolve(sctx.getPushed(), sctx); + + if (base.getInstruction() instanceof GetFieldInstruction) + { + GetFieldInstruction gfi = (GetFieldInstruction) base.getInstruction(); + + if (gfi.getMyField() != null) + fields.add(gfi.getMyField()); + } + } + + return fields.isEmpty() ? null : fields; + } + + @Override + public boolean isSame(InstructionContext thisIc, InstructionContext otherIc) + { + return true; + } + + @Override + public boolean canMap(InstructionContext thisIc) + { + return true; + } }