From ed13e972cc74e1c50ddf692930e22ef5e01e1b96 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 31 Mar 2016 21:27:18 -0400 Subject: [PATCH] Make idiv mappable --- .../attributes/code/instructions/IDiv.java | 59 ++++++++++++++++++- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/runelite/asm/attributes/code/instructions/IDiv.java b/src/main/java/net/runelite/asm/attributes/code/instructions/IDiv.java index 6e923a61be..680fe201d6 100644 --- a/src/main/java/net/runelite/asm/attributes/code/instructions/IDiv.java +++ b/src/main/java/net/runelite/asm/attributes/code/instructions/IDiv.java @@ -1,15 +1,20 @@ package net.runelite.asm.attributes.code.instructions; +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 IDiv extends Instruction +public class IDiv extends Instruction implements MappableInstruction { public IDiv(Instructions instructions, InstructionType type, int pc) { @@ -46,7 +51,57 @@ public class IDiv extends Instruction stack.push(ctx); ins.push(ctx); - + frame.addInstructionContext(ins); } + + @Override + public void map(ParallelExecutorMapping mappings, InstructionContext ctx, InstructionContext other) + { + StackContext s1 = ctx.getPops().get(0), + s2 = ctx.getPops().get(1); + + StackContext o1 = other.getPops().get(0), + o2 = other.getPops().get(1); + + InstructionContext i1 = MappingExecutorUtil.resolve(s1.getPushed(), s1); + InstructionContext i2 = MappingExecutorUtil.resolve(s2.getPushed(), s2); + + InstructionContext io1 = MappingExecutorUtil.resolve(o1.getPushed(), o1); + InstructionContext io2 = MappingExecutorUtil.resolve(o2.getPushed(), o2); + + if (i1.getInstruction() instanceof GetFieldInstruction && io1.getInstruction() instanceof GetFieldInstruction) + { + GetFieldInstruction f1 = (GetFieldInstruction) i1.getInstruction(); + GetFieldInstruction f2 = (GetFieldInstruction) io1.getInstruction(); + + Field fi1 = f1.getMyField(), fi2 = f2.getMyField(); + + if (fi1 != null && fi2 != null) + mappings.map(fi1, fi2); + } + + if (i2.getInstruction() instanceof GetFieldInstruction && io2.getInstruction() instanceof GetFieldInstruction) + { + GetFieldInstruction f1 = (GetFieldInstruction) i2.getInstruction(); + GetFieldInstruction f2 = (GetFieldInstruction) io2.getInstruction(); + + Field fi1 = f1.getMyField(), fi2 = f2.getMyField(); + + if (fi1 != null && fi2 != null) + mappings.map(fi1, fi2); + } + } + + @Override + public boolean isSame(InstructionContext thisIc, InstructionContext otherIc) + { + return this.getClass() == otherIc.getInstruction().getClass(); + } + + @Override + public boolean canMap(InstructionContext thisIc) + { + return true; + } }