From c4bf4f65dfab9e3b8a1702d046ffef34230ce29c Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 7 Feb 2016 14:27:19 -0500 Subject: [PATCH] Actually I think I can just stop the frame if it crashes. This runs forever for some reason. --- .../rename/MappingExecutorUtil.java | 53 ++++++++++++++++++- .../rename/ParallelExecutorMapping.java | 7 ++- .../net/runelite/deob/execution/Frame.java | 3 +- .../execution/ParallellMappingExecutor.java | 13 +++++ .../deobfuscators/rename/MapStaticTest.java | 53 ++++++++++--------- 5 files changed, 102 insertions(+), 27 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 47a657b53b..b39f88673e 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/rename/MappingExecutorUtil.java +++ b/src/main/java/net/runelite/deob/deobfuscators/rename/MappingExecutorUtil.java @@ -115,7 +115,57 @@ public class MappingExecutorUtil if (!mi1.isSame(p1, p2)) { - throw new MappingException(); + p1.getFrame().stop(); + p2.getFrame().stop(); + continue; +// if (!hit) +// { +// hit = true; +// +// throw new MappingException(); +// } +// +// System.out.println("ERROR mapping " + p1 + " to " + p2); +// +// // methods don't map. find common static method and back out. +// +// Frame c1 = p1.getFrame(), c2 = p2.getFrame(); +// +// while (c1 != null && c1.otherStatic == null) +// c1 = c1.returnTo; +// +// while (c2 != null && c2.otherStatic == null) +// c2 = c2.returnTo; +// +// // otherStatic would point to the original frame of the method, which the other might not be. we don't +// // care just compare the method. +// if (c1 == null || c2 == null || c1.otherStatic.getMethod() != c2.getMethod() || c2.otherStatic.getMethod() != c1.getMethod()) +// { +// throw new MappingException(); +// } +// +// // c1/c2 are top frames of static methods that we can't map. +// // return out of frames +// c1 = c1.returnTo; +// c2 = c2.returnTo; +// +// if (c1 == null || c2 == null) +// throw new MappingException(); +// +// // Back execution out to c1 and c2. +// // When something is stepped into, the calling frame is removed. +// // Remove all frames from the respective method, add frame from good method to continue +// parallel.removeFramesFromMethod(p1.getFrame().getMethod()); +// parallel.removeFramesFromMethod(p2.getFrame().getMethod()); +// +// assert c1.other == null; +// assert c2.other == null; +// +// c1.other = c2; +// c2.other = c1; +// +// parallel.addFrame(c1, c2); +// continue; } mi1.map(mappings, p1, p2); @@ -125,6 +175,7 @@ public class MappingExecutorUtil return mappings; } + //static boolean hit; public static boolean isMappable(InvokeInstruction ii) { diff --git a/src/main/java/net/runelite/deob/deobfuscators/rename/ParallelExecutorMapping.java b/src/main/java/net/runelite/deob/deobfuscators/rename/ParallelExecutorMapping.java index 2e3c2c3d6e..4bcf495e8e 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/rename/ParallelExecutorMapping.java +++ b/src/main/java/net/runelite/deob/deobfuscators/rename/ParallelExecutorMapping.java @@ -12,9 +12,14 @@ public class ParallelExecutorMapping private List order = new ArrayList<>(); public Method m1, m2; + public void merge(ParallelExecutorMapping other) + { + map.putAll(other.map); // is this right? + } + public void map(Object one, Object two) { - assert !map.containsKey(one) || map.get(one) == two; + //assert !map.containsKey(one) || map.get(one) == two; if (map.containsKey(one)) return; diff --git a/src/main/java/net/runelite/deob/execution/Frame.java b/src/main/java/net/runelite/deob/execution/Frame.java index 8984ee7267..ebff443f7e 100644 --- a/src/main/java/net/runelite/deob/execution/Frame.java +++ b/src/main/java/net/runelite/deob/execution/Frame.java @@ -48,7 +48,7 @@ public class Frame variables = new Variables(code.getMaxLocals()); // don't cache method contexts per execution // need to allow the same method to execute multiple times - // when called from multiple places to allow graph building + // when called from multiple places to allow graph building //XXX there no longer is a graph ctx = new MethodContext(execution); nonStatic = method; } @@ -144,6 +144,7 @@ public class Frame ffs.remove(this); this.created = other.created; this.forking = other.forking; + this.otherStatic = other.otherStatic; } public Frame dup() diff --git a/src/main/java/net/runelite/deob/execution/ParallellMappingExecutor.java b/src/main/java/net/runelite/deob/execution/ParallellMappingExecutor.java index ae4ff07ca3..b43691a025 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.HashSet; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import net.runelite.deob.Method; import net.runelite.deob.attributes.code.instruction.types.ReturnInstruction; import net.runelite.deob.attributes.code.instructions.InvokeStatic; @@ -407,4 +408,16 @@ public class ParallellMappingExecutor return f.returnTo; } + + public void removeFramesFromMethod(Method m) + { + e.frames = e.frames.stream().filter(f -> f.getMethod() != m).collect(Collectors.toList()); + e2.frames = e2.frames.stream().filter(f -> f.getMethod() != m).collect(Collectors.toList()); + } + + public void addFrame(Frame f1, Frame f2) + { + e.frames.add(0, f1); + e2.frames.add(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 ed0ff0ac57..be632f7e7c 100644 --- a/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java +++ b/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java @@ -114,8 +114,8 @@ public class MapStaticTest ClassGroup group1 = JarUtil.loadJar(new File(JAR1)); ClassGroup group2 = JarUtil.loadJar(new File(JAR2)); - Method m1 = group1.findClass("class183").findMethod("method3685"); - Method m2 = group2.findClass("class183").findMethod("method3560"); + Method m1 = group1.findClass("client").findMethod("vmethod3096"); + Method m2 = group2.findClass("client").findMethod("vmethod2975"); HashMap all = new HashMap(); List pmes = new ArrayList<>(); @@ -163,33 +163,38 @@ public class MapStaticTest HashMap all = new HashMap(); map(all, pmes, m1, m2); } - int fields = 0, staticMethod = 0, method = 0, total = 0; + + ParallelExecutorMapping finalm = new ParallelExecutorMapping(); for (ParallelExecutorMapping pme : pmes) - for (Entry e : pme.getMap().entrySet()) + finalm.merge(pme); + + int fields = 0, staticMethod = 0, method = 0, total = 0; + for (Entry e : finalm.getMap().entrySet()) + { + System.out.println(e.getKey() + " <-> " + e.getValue()); + + Object o = e.getKey(); + if (o instanceof Field) + ++fields; + else if (o instanceof Method) { - System.out.println(e.getKey() + " <-> " + e.getValue()); + Method m = (Method) o; - Object o = e.getKey(); - if (o instanceof Field) - ++fields; - else if (o instanceof Method) - { - Method m = (Method) o; - - if (m.isStatic()) - ++staticMethod; - else - ++method; - } - - ++total; + if (m.isStatic()) + ++staticMethod; + else + ++method; } + + ++total; + } System.out.println("Total " + total + ". " + fields + " fields, " + staticMethod + " static methods, " + method + " methods"); -// for (Method m : group1.findClass("client").getMethods().getMethods()) -// { -// if (!all.containsKey(m) && !m.isStatic()) -// System.out.println("missing " + m); -// } + + for (Method m : group1.findClass("client").getMethods().getMethods()) + { + if (!finalm.getMap().containsKey(m) && !m.isStatic()) + System.out.println("missing " + m); + } } public List getInitialMethods(ClassGroup group)