diff --git a/src/main/java/net/runelite/deob/attributes/code/InstructionType.java b/src/main/java/net/runelite/deob/attributes/code/InstructionType.java index 07b265b596..094a0d570a 100644 --- a/src/main/java/net/runelite/deob/attributes/code/InstructionType.java +++ b/src/main/java/net/runelite/deob/attributes/code/InstructionType.java @@ -121,12 +121,14 @@ import net.runelite.deob.attributes.code.instructions.IStore_3; import net.runelite.deob.attributes.code.instructions.ISub; import net.runelite.deob.attributes.code.instructions.IUShR; import net.runelite.deob.attributes.code.instructions.IXor; -import net.runelite.deob.attributes.code.instructions.IfCmpEq; +import net.runelite.deob.attributes.code.instructions.IfACmpEq; +import net.runelite.deob.attributes.code.instructions.IfACmpNe; +import net.runelite.deob.attributes.code.instructions.IfICmpEq; import net.runelite.deob.attributes.code.instructions.IfCmpGe; import net.runelite.deob.attributes.code.instructions.IfCmpGt; import net.runelite.deob.attributes.code.instructions.IfCmpLe; import net.runelite.deob.attributes.code.instructions.IfCmpLt; -import net.runelite.deob.attributes.code.instructions.IfCmpNe; +import net.runelite.deob.attributes.code.instructions.IfICmpNe; import net.runelite.deob.attributes.code.instructions.IfEq; import net.runelite.deob.attributes.code.instructions.IfGe; import net.runelite.deob.attributes.code.instructions.IfGt; @@ -353,14 +355,14 @@ public enum InstructionType IFGE(0x9c, "ifge", IfGe.class), IFGT(0x9d, "ifgt", IfGt.class), IFLE(0x9e, "ifle", IfLe.class), - IF_ICMPEQ(0x9f, "if_icmpeq", IfCmpEq.class), - IF_ICMPNE(0xa0, "if_icmpne", IfCmpNe.class), + IF_ICMPEQ(0x9f, "if_icmpeq", IfICmpEq.class), + IF_ICMPNE(0xa0, "if_icmpne", IfICmpNe.class), IF_ICMPLT(0xa1, "if_cmplt", IfCmpLt.class), IF_ICMPGE(0xa2, "if_icmpge", IfCmpGe.class), IF_ICMPGT(0xa3, "if_icmpgt", IfCmpGt.class), IF_ICMPLE(0xa4, "if_icmple", IfCmpLe.class), - IF_ACMPEQ(0xa5, "if_acmpeq", IfCmpEq.class), - IF_ACMPNE(0xa6, "if_acmpne", IfCmpNe.class), + IF_ACMPEQ(0xa5, "if_acmpeq", IfACmpEq.class), + IF_ACMPNE(0xa6, "if_acmpne", IfACmpNe.class), GOTO(0xa7, "goto", Goto.class), TABLESWITCH(0xaa, "tableswitch", TableSwitch.class), LOOKUPSWITCH(0xab, "lookupswitch", LookupSwitch.class), diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/If.java b/src/main/java/net/runelite/deob/attributes/code/instructions/If.java index 41807608b2..d85eda9ef5 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/If.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/If.java @@ -99,13 +99,15 @@ public abstract class If extends Instruction implements JumpingInstruction, Comp @Override public final/*XXX tmp*/ void map(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other) { - InstructionContext oneLhs = ctx.getPops().get(0).getPushed().resolve(ctx.getPops().get(0)), - oneRhs = ctx.getPops().get(1).getPushed().resolve(ctx.getPops().get(1)), - - twoLhs = other.getPops().get(0).getPushed().resolve(other.getPops().get(0)), - twoRhs = other.getPops().get(1).getPushed().resolve(other.getPops().get(1)); +// InstructionContext oneLhs = ctx.getPops().get(0).getPushed().resolve(ctx.getPops().get(0)), +// oneRhs = ctx.getPops().get(1).getPushed().resolve(ctx.getPops().get(1)), +// +// twoLhs = other.getPops().get(0).getPushed().resolve(other.getPops().get(0)), +// twoRhs = other.getPops().get(1).getPushed().resolve(other.getPops().get(1)); - assert ctx.getInstruction().getClass().equals(other.getInstruction().getClass()); + // if we get here weve assedted isSame(ctx, other). but they might not be the same instruction. + // need to do something so branching can be always done right, eg ifeq vs ifne + //assert ctx.getInstruction().getClass().equals(other.getInstruction().getClass()); Frame branch1 = ctx.getBranches().get(0), branch2 = other.getBranches().get(0); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IfCmpEq.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IfACmpEq.java similarity index 57% rename from src/main/java/net/runelite/deob/attributes/code/instructions/IfCmpEq.java rename to src/main/java/net/runelite/deob/attributes/code/instructions/IfACmpEq.java index 7cd2710209..9cf68576d8 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IfCmpEq.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IfACmpEq.java @@ -2,11 +2,10 @@ package net.runelite.deob.attributes.code.instructions; import net.runelite.deob.attributes.code.InstructionType; import net.runelite.deob.attributes.code.Instructions; -import net.runelite.deob.execution.InstructionContext; -public class IfCmpEq extends If +public class IfACmpEq extends If { - public IfCmpEq(Instructions instructions, InstructionType type, int pc) + public IfACmpEq(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IfACmpNe.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IfACmpNe.java new file mode 100644 index 0000000000..d07673659e --- /dev/null +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IfACmpNe.java @@ -0,0 +1,12 @@ +package net.runelite.deob.attributes.code.instructions; + +import net.runelite.deob.attributes.code.InstructionType; +import net.runelite.deob.attributes.code.Instructions; + +public class IfACmpNe extends If +{ + public IfACmpNe(Instructions instructions, InstructionType type, int pc) + { + super(instructions, type, pc); + } +} diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IfICmpEq.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IfICmpEq.java new file mode 100644 index 0000000000..6d37698835 --- /dev/null +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IfICmpEq.java @@ -0,0 +1,48 @@ +package net.runelite.deob.attributes.code.instructions; + +import net.runelite.deob.attributes.code.InstructionType; +import net.runelite.deob.attributes.code.Instructions; +import net.runelite.deob.attributes.code.instruction.types.PushConstantInstruction; +import net.runelite.deob.execution.InstructionContext; +import net.runelite.deob.execution.StackContext; + +public class IfICmpEq extends If +{ + public IfICmpEq(Instructions instructions, InstructionType type, int pc) + { + super(instructions, type, pc); + } + + private static boolean isZero(StackContext s) + { + if (s.getPushed().getInstruction() instanceof PushConstantInstruction) + { + PushConstantInstruction pc = (PushConstantInstruction) s.getPushed().getInstruction(); + Object o = pc.getConstant().getObject(); + + if (o instanceof Integer && (int) o == 0) + return true; + } + + return false; + } + + @Override + public boolean isSame(InstructionContext thisIc, InstructionContext otherIc) + { + if (super.isSame(thisIc, otherIc)) + return true; + + // check for other being ifeq and this has a constant 0 + if (otherIc.getInstruction() instanceof IfEq) + { + StackContext s1 = thisIc.getPops().get(0), + s2 = thisIc.getPops().get(1); + + if (isZero(s1) || isZero(s2)) + return true; + } + + return false; + } +} diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IfCmpNe.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IfICmpNe.java similarity index 66% rename from src/main/java/net/runelite/deob/attributes/code/instructions/IfCmpNe.java rename to src/main/java/net/runelite/deob/attributes/code/instructions/IfICmpNe.java index f1d2eaa1b0..58df149994 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IfCmpNe.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IfICmpNe.java @@ -3,9 +3,9 @@ package net.runelite.deob.attributes.code.instructions; import net.runelite.deob.attributes.code.InstructionType; import net.runelite.deob.attributes.code.Instructions; -public class IfCmpNe extends If +public class IfICmpNe extends If { - public IfCmpNe(Instructions instructions, InstructionType type, int pc) + public IfICmpNe(Instructions instructions, InstructionType type, int pc) { super(instructions, type, pc); } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IfNe.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IfNe.java index b8ebe87fba..8c953103cb 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IfNe.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IfNe.java @@ -20,7 +20,7 @@ public class IfNe extends If0 if (super.isSame(thisIc, otherIc)) return true; - if (otherIc.getInstruction() instanceof IfCmpNe) + if (otherIc.getInstruction() instanceof IfICmpNe) { // check for one side being 0 StackContext s1 = otherIc.getPops().get(0), diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IfNull.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IfNull.java index 239ace8a75..fae7a20b43 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IfNull.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IfNull.java @@ -18,7 +18,7 @@ public class IfNull extends If0 if (super.isSame(thisIc, otherIc)) return true; - if (otherIc.getInstruction() instanceof IfCmpEq) + if (otherIc.getInstruction() instanceof IfACmpEq) { StackContext s1 = otherIc.getPops().get(0), s2 = otherIc.getPops().get(1); diff --git a/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java b/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java index 0e65a0e7ec..fea8f47f35 100644 --- a/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java +++ b/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java @@ -13,8 +13,8 @@ public class MapStaticTest //@Test public void testMappable() throws IOException { - ClassGroup group1 = JarUtil.loadJar(new File("d:/rs/07/adamin1.jar")); - ClassGroup group2 = JarUtil.loadJar(new File("d:/rs/07/adamin2.jar")); + ClassGroup group1 = JarUtil.loadJar(new File("c:/rs/adamin1.jar")); + ClassGroup group2 = JarUtil.loadJar(new File("c:/rs/adamin2.jar")); // Assert.assertTrue(MappingExecutorUtil.isMappable( // group1.findClass("class99").findMethod("method2220"), @@ -25,8 +25,8 @@ public class MapStaticTest @Test public void test() throws IOException { - ClassGroup group1 = JarUtil.loadJar(new File("d:/rs/07/adamin1.jar")); - ClassGroup group2 = JarUtil.loadJar(new File("d:/rs/07/adamin2.jar")); + ClassGroup group1 = JarUtil.loadJar(new File("c:/rs/adamin1.jar")); + ClassGroup group2 = JarUtil.loadJar(new File("c:/rs/adamin2.jar")); Method m1 = group1.findClass("client").findMethod("vmethod3054"); Method m2 = group2.findClass("client").findMethod("vmethod2973");