From 3b4ea9ce0ded10d6e36597b4ed43a9766a26b536 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 13 Jan 2016 14:58:15 -0500 Subject: [PATCH] More tests --- .../attributes/code/instructions/If0.java | 50 +++++++++++++++---- .../attributes/code/instructions/IfEq.java | 28 +++++++++++ .../attributes/code/instructions/IfNe.java | 18 +++++++ .../execution/ParallellMappingExecutor.java | 4 +- .../deobfuscators/rename/MapStaticTest.java | 7 +-- 5 files changed, 93 insertions(+), 14 deletions(-) diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/If0.java b/src/main/java/net/runelite/deob/attributes/code/instructions/If0.java index 865ebee32f..dbb6c11e2a 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/If0.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/If0.java @@ -17,6 +17,7 @@ import java.util.Arrays; import java.util.List; import net.runelite.deob.attributes.code.instruction.types.MappableInstruction; import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping; +import net.runelite.deob.execution.Execution; public abstract class If0 extends Instruction implements JumpingInstruction, ComparisonInstruction, MappableInstruction { @@ -97,17 +98,10 @@ public abstract class If0 extends Instruction implements JumpingInstruction, Com return Arrays.asList(to); } + // duplicated from If @Override - public final/*XXX tmp*/ void map(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other) + public void map(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other) { - InstructionContext one = ctx.getPops().get(0).getPushed().resolve(ctx.getPops().get(0)), - two = other.getPops().get(0).getPushed().resolve(other.getPops().get(0)); - - // we can map these if they are getfield instructions? - - // this is already checked before this - //assert ctx.getInstruction().getClass().equals(other.getInstruction().getClass()); - Frame branch1 = ctx.getBranches().get(0), branch2 = other.getBranches().get(0); @@ -118,6 +112,44 @@ public abstract class If0 extends Instruction implements JumpingInstruction, Com branch2.other = branch1; } + // duplicated from If + protected void mapOtherBranch(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other) + { + Frame f1 = ctx.getFrame(), + f2 = other.getFrame(), + branch1 = ctx.getBranches().get(0), + branch2 = other.getBranches().get(0); + + assert branch1.other == null; + assert branch2.other == null; + + // currently f1 <-> f2 + assert f1.other == f2; + assert f2.other == f1; + + // change to f1 <-> branch2, f2 <-> branch1 + + f1.other = branch2; + branch2.other = f1; + + f2.other = branch1; + branch1.other = f2; + + // switch frame order in executor frame list + + Execution e = f1.getExecution(), + e2 = f2.getExecution(); + + int i = e2.frames.indexOf(f2), + i2 = e2.frames.indexOf(branch2); + + e2.frames.remove(i); + e2.frames.add(i, branch2); + + e2.frames.remove(i2); + e2.frames.add(i2, f2); + } + @Override public boolean isSame(InstructionContext thisIc, InstructionContext otherIc) { diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IfEq.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IfEq.java index f210fbd0a4..51a7bbec72 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IfEq.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IfEq.java @@ -2,6 +2,8 @@ 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.deobfuscators.rename.ParallelExecutorMapping; +import net.runelite.deob.execution.InstructionContext; public class IfEq extends If0 { @@ -10,4 +12,30 @@ public class IfEq extends If0 super(instructions, type, pc); } + @Override + public boolean isSame(InstructionContext thisIc, InstructionContext otherIc) + { + if (super.isSame(thisIc, otherIc)) + return true; + + if (otherIc.getInstruction() instanceof IfNe) + { + return true; + } + + return false; + } + + @Override + public void map(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other) + { + if (other.getInstruction() instanceof IfNe) + { + super.mapOtherBranch(mapping, ctx, other); + } + else + { + super.map(mapping, ctx, other); + } + } } 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 8c953103cb..77632d57be 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 @@ -4,6 +4,7 @@ import net.runelite.deob.attributes.code.InstructionType; import net.runelite.deob.attributes.code.Instructions; import net.runelite.deob.attributes.code.instruction.types.MappableInstruction; import net.runelite.deob.attributes.code.instruction.types.PushConstantInstruction; +import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.StackContext; @@ -47,7 +48,24 @@ public class IfNe extends If0 } } } + else if (otherIc.getInstruction() instanceof IfEq) + { + return true; + } return false; } + + @Override + public void map(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other) + { + if (other.getInstruction() instanceof IfEq) + { + super.mapOtherBranch(mapping, ctx, other); + } + else + { + super.map(mapping, ctx, other); + } + } } diff --git a/src/main/java/net/runelite/deob/execution/ParallellMappingExecutor.java b/src/main/java/net/runelite/deob/execution/ParallellMappingExecutor.java index e9a04bfc54..1a722bc9cb 100644 --- a/src/main/java/net/runelite/deob/execution/ParallellMappingExecutor.java +++ b/src/main/java/net/runelite/deob/execution/ParallellMappingExecutor.java @@ -30,12 +30,12 @@ public class ParallellMappingExecutor assert f1.other == f2; assert f2.other == f1; - assert f1.isExecuting() == f2.isExecuting(); + //assert f1.isExecuting() == f2.isExecuting(); // this will happen because conditional branches will create their frame // before realizing its already executed it before, so it will set the frame // as not executing - if (!f1.isExecuting()) + if (!f1.isExecuting() || !f2.isExecuting()) { assert e.frames.get(0) == f1; assert e2.frames.get(0) == f2; 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 503188f7b3..75aaab1b9f 100644 --- a/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java +++ b/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java @@ -16,7 +16,8 @@ public class MapStaticTest { "class146.vmethod3158", "class146.vmethod3070" }, { "class166.method3315", "class166.method3254" }, { "class167.method3406", "class167.method3296" }, - { "client.method585", "class44.method930" } + { "client.method585", "class44.method930" }, + { "class222.method4086", "class222.method3957" } }; //@Test @@ -54,8 +55,8 @@ public class MapStaticTest ClassGroup group1 = JarUtil.loadJar(new File("d:/rs/07/adamin1.jar")); ClassGroup group2 = JarUtil.loadJar(new File("d:/rs/07/adamin2.jar")); - Method m1 = group1.findClass("client").findMethod("method585"); - Method m2 = group2.findClass("class44").findMethod("method930"); + Method m1 = group1.findClass("class222").findMethod("method4086"); + Method m2 = group2.findClass("class222").findMethod("method3957"); ParallelExecutorMapping mappings = MappingExecutorUtil.map(m1, m2); }