From b8169440293560d3912eb412d7d8cb36424f4e29 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 25 Jan 2016 14:43:55 -0500 Subject: [PATCH] hm this is horrible --- .../rename/MappingExecutorUtil.java | 7 +- .../runelite/deob/execution/Execution.java | 9 --- .../execution/ParallellMappingExecutor.java | 64 ++++++++++++++++--- .../deobfuscators/rename/MapStaticTest.java | 44 ++++++------- 4 files changed, 82 insertions(+), 42 deletions(-) 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 c55c7b9cf3..d537daffca 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/rename/MappingExecutorUtil.java +++ b/src/main/java/net/runelite/deob/deobfuscators/rename/MappingExecutorUtil.java @@ -17,7 +17,7 @@ import net.runelite.deob.execution.ParallellMappingExecutor; public class MappingExecutorUtil { - // won't work with static funcs etc + // won't work with static funcs etc. this is all wrong. XXX public static boolean isMappable(Method m1, Method m2) { assert (m1.getCode() == null) == (m2.getCode() == null); @@ -101,7 +101,10 @@ public class MappingExecutorUtil MappableInstruction mi1 = (MappableInstruction) p1.getInstruction(), mi2 = (MappableInstruction) p2.getInstruction(); - assert mi1.isSame(p1, p2); + if (!mi1.isSame(p1, p2)) + { + assert mi1.isSame(p1, p2); + } //assert p1.getInstruction().getClass().equals(p2.getInstruction().getClass()); mi1.map(mappings, p1, p2); diff --git a/src/main/java/net/runelite/deob/execution/Execution.java b/src/main/java/net/runelite/deob/execution/Execution.java index fbce0073d3..58aaa7b9a3 100644 --- a/src/main/java/net/runelite/deob/execution/Execution.java +++ b/src/main/java/net/runelite/deob/execution/Execution.java @@ -150,15 +150,6 @@ public class Execution System.out.println("Processed " + fcount + " frames"); } -// public InstructionContext getPaused() -// { -// if (frames.isEmpty()) -// return null; -// -// Frame f = frames.get(0); -// return f.getInstructions().get(f.getInstructions().size() - 1); -// } - public Collection getInstructonContexts(Instruction i) { return contexts.getCollection(i); diff --git a/src/main/java/net/runelite/deob/execution/ParallellMappingExecutor.java b/src/main/java/net/runelite/deob/execution/ParallellMappingExecutor.java index 85a18febce..7e8cafd653 100644 --- a/src/main/java/net/runelite/deob/execution/ParallellMappingExecutor.java +++ b/src/main/java/net/runelite/deob/execution/ParallellMappingExecutor.java @@ -3,6 +3,7 @@ package net.runelite.deob.execution; import java.util.List; import net.runelite.deob.Method; import net.runelite.deob.attributes.code.instruction.types.ReturnInstruction; +import net.runelite.deob.attributes.code.instructions.InvokeSpecial; import net.runelite.deob.attributes.code.instructions.InvokeStatic; import net.runelite.deob.deobfuscators.rename.MappingExecutorUtil; @@ -17,6 +18,7 @@ public class ParallellMappingExecutor this.e2 = two; } + boolean step1 = true, step2 = true; public boolean step() { assert e.frames.size() == e2.frames.size(); @@ -48,8 +50,10 @@ public class ParallellMappingExecutor } // step frame - f1.execute(); - f2.execute(); + if (step1) + f1.execute(); + if (step2) + f2.execute(); f1 = popStack(f1); f2 = popStack(f2); @@ -83,17 +87,57 @@ public class ParallellMappingExecutor return step(); } + Frame oldf1 = f1, oldf2 = f2; if (MappingExecutorUtil.isInlineable(p1.getInstruction()) && !MappingExecutorUtil.isInlineable(p2.getInstruction())) { f1 = stepInto(f1); - f1 = popStack(f1); - p1 = f1.getInstructions().get(f1.getInstructions().size() - 1); + try + { + step2 = false; + return step(); + } + finally + { + step2 = true; + } + //f1 = popStack(f1); + //p1 = f1.getInstructions().get(f1.getInstructions().size() - 1); } else if (MappingExecutorUtil.isInlineable(p2.getInstruction()) && !MappingExecutorUtil.isInlineable(p1.getInstruction())) { f2 = stepInto(f2); - f2 = popStack(f2); - p2 = f2.getInstructions().get(f2.getInstructions().size() - 1); + //f2 = popStack(f2); + //p2 = f2.getInstructions().get(f2.getInstructions().size() - 1); + try + { + step1 = false; + return step(); + } + finally + { + step1 = true; + } + } + else if (MappingExecutorUtil.isInlineable(p1.getInstruction()) && MappingExecutorUtil.isInlineable(p2.getInstruction())) + { + // p1s func might equal p2s func + + // step into both at once, and insert to beginning of e.frames + + // when two funcs exit at once, map them then (if static?) + +// f1 = stepInto(f1); +// f1 = popStack(f1); +// p1 = f1.getInstructions().get(f1.getInstructions().size() - 1); +// +// f2 = stepInto(f2); +// f2 = popStack(f2); +// p2 = f2.getInstructions().get(f2.getInstructions().size() - 1); + } + + if (p1.getInstruction() instanceof InvokeSpecial && p2.getInstruction() instanceof InvokeStatic) + { + int i = 5; } assert e.paused; @@ -124,8 +168,10 @@ public class ParallellMappingExecutor InvokeStatic is = (InvokeStatic) i.getInstruction(); List methods = is.getMethods(); - if (methods.isEmpty()) // not my method - return null; + + assert methods.size() == 1; + //if (methods.isEmpty()) // not my method + // return null; Method to = is.getMethods().get(0); @@ -145,7 +191,7 @@ public class ParallellMappingExecutor f2.returnTo = new Frame(f); // where to go when we're done // step new frame - f2.execute(); + //f2.execute(); return 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 140321b6ae..1ff2667e49 100644 --- a/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java +++ b/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java @@ -34,7 +34,7 @@ public class MapStaticTest { "client.init", "client.init" }, { "class162.method3270", "class86.method2020" }, { "class29.method711", "class36.method742" }, - { "class72.run", "class72.run" }, + //{ "class72.run", "class72.run" }, }; // @Test @@ -57,30 +57,30 @@ public class MapStaticTest // } //@Test -// public void testAll() 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]); -// -// ParallelExecutorMapping mappings = MappingExecutorUtil.map(m1, m2); -// } -// } - - //@Test - public void test() throws IOException + public void testAll() throws IOException { 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("class72").findMethod("run"); - Method m2 = group2.findClass("class72").findMethod("run"); + 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]); + + ParallelExecutorMapping mappings = MappingExecutorUtil.map(m1, m2); + } + } + + @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")); + + Method m1 = group1.findClass("client").findMethod("vmethod3054"); + Method m2 = group2.findClass("client").findMethod("vmethod2973"); ParallelExecutorMapping mappings = MappingExecutorUtil.map(m1, m2); @@ -91,7 +91,7 @@ public class MapStaticTest } } - @Test + //@Test public void testDeep() throws IOException { ClassGroup group1 = JarUtil.loadJar(new File("d:/rs/07/adamin1.jar"));