From 35ca054da8288b57bb6ad882e31634a0e5a50537 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 13 Jan 2016 18:02:36 -0500 Subject: [PATCH] mappable test seems to not work well, I think because of static methods --- .../code/instructions/IfACmpNe.java | 27 +++++++++++++++ .../code/instructions/IfNonNull.java | 25 ++++++++++++++ .../rename/MappingExecutorUtil.java | 1 + .../deobfuscators/rename/MapStaticTest.java | 33 +++++++++++-------- 4 files changed, 73 insertions(+), 13 deletions(-) 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 index d07673659e..1a0b9e2747 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IfACmpNe.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IfACmpNe.java @@ -2,6 +2,9 @@ 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; +import net.runelite.deob.execution.StackContext; public class IfACmpNe extends If { @@ -9,4 +12,28 @@ public class IfACmpNe extends If { super(instructions, type, pc); } + + @Override + public boolean isSame(InstructionContext thisIc, InstructionContext otherIc) + { + if (super.isSame(thisIc, otherIc)) + return true; + + if (otherIc.getInstruction() instanceof IfNonNull) + { + StackContext s1 = thisIc.getPops().get(0), + s2 = thisIc.getPops().get(1); + + if (s1.getPushed().getInstruction() instanceof AConstNull) + { + return true; + } + if (s2.getPushed().getInstruction() instanceof AConstNull) + { + return true; + } + } + + return false; + } } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IfNonNull.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IfNonNull.java index 6f3a304065..bc30320a8b 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IfNonNull.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IfNonNull.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.execution.InstructionContext; +import net.runelite.deob.execution.StackContext; public class IfNonNull extends If0 { @@ -10,4 +12,27 @@ public class IfNonNull 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 IfACmpNe) + { + StackContext s1 = otherIc.getPops().get(0), + s2 = otherIc.getPops().get(1); + + if (s1.getPushed().getInstruction() instanceof AConstNull) + { + return true; + } + if (s2.getPushed().getInstruction() instanceof AConstNull) + { + return true; + } + } + + return false; + } } diff --git a/src/main/java/net/runelite/deob/deobfuscators/rename/MappingExecutorUtil.java b/src/main/java/net/runelite/deob/deobfuscators/rename/MappingExecutorUtil.java index 21324889a7..0cdc87ed59 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/rename/MappingExecutorUtil.java +++ b/src/main/java/net/runelite/deob/deobfuscators/rename/MappingExecutorUtil.java @@ -18,6 +18,7 @@ import net.runelite.deob.util.JarUtil; public class MappingExecutorUtil { + // won't work with static funcs etc public static boolean isMappable(Method m1, Method m2) { assert (m1.getCode() == null) == (m2.getCode() == null); 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 75aaab1b9f..9de4bf9fff 100644 --- a/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java +++ b/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java @@ -20,17 +20,24 @@ public class MapStaticTest { "class222.method4086", "class222.method3957" } }; - //@Test - public void testMappable() throws IOException - { - 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"), -// group2.findClass("class99").findMethod("method2149") -// )); - } +// @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")); +// +// for (String[] s : methods) +// { +// String[] one = s[0].split("\\."), two = s[1].split("\\."); +// +// Method m1 = group1.findClass(one[0]).findMethod(one[1]); +// Method m2 = group2.findClass(two[0]).findMethod(two[1]); +// +// Assert.assertTrue(MappingExecutorUtil.isMappable( +// m1, m2 +// )); +// } +// } //@Test public void testAll() throws IOException @@ -55,8 +62,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("class222").findMethod("method4086"); - Method m2 = group2.findClass("class222").findMethod("method3957"); + Method m1 = group1.findClass("class40").findMethod("method851"); + Method m2 = group2.findClass("class40").findMethod("method803"); ParallelExecutorMapping mappings = MappingExecutorUtil.map(m1, m2); }