From 66e99605965069d43b0dfd1fea38ef1cd959d2de Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 13 Feb 2016 17:07:01 -0500 Subject: [PATCH] this wont work because exception handlers arent run so it wont see all returns --- .../rename/MappingExecutorUtil.java | 29 ++++- .../net/runelite/deob/execution/Frame.java | 3 + .../deob/execution/MethodContext.java | 4 +- .../deobfuscators/rename/MapStaticTest.java | 101 +++++++++--------- 4 files changed, 84 insertions(+), 53 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 127c567092..13b4b2d579 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/rename/MappingExecutorUtil.java +++ b/src/main/java/net/runelite/deob/deobfuscators/rename/MappingExecutorUtil.java @@ -11,11 +11,13 @@ import net.runelite.deob.attributes.code.instruction.types.DupInstruction; import net.runelite.deob.attributes.code.instruction.types.InvokeInstruction; import net.runelite.deob.attributes.code.instruction.types.LVTInstruction; import net.runelite.deob.attributes.code.instruction.types.MappableInstruction; +import net.runelite.deob.attributes.code.instruction.types.ReturnInstruction; import net.runelite.deob.attributes.code.instruction.types.SetFieldInstruction; import net.runelite.deob.attributes.code.instructions.InvokeStatic; import net.runelite.deob.execution.Execution; import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; +import net.runelite.deob.execution.MethodContext; import net.runelite.deob.execution.ParallellMappingExecutor; import net.runelite.deob.execution.StackContext; import net.runelite.deob.execution.VariableContext; @@ -86,6 +88,9 @@ public class MappingExecutorUtil frame.other = frame2; frame2.other = frame; + MethodContext ctx1 = frame.getMethodCtx(), + ctx2 = frame2.getMethodCtx(); + ParallellMappingExecutor parallel = new ParallellMappingExecutor(e, e2); ParallelExecutorMapping mappings = new ParallelExecutorMapping(m1.getMethods().getClassFile().getGroup(), m2.getMethods().getClassFile().getGroup()); @@ -184,9 +189,31 @@ public class MappingExecutorUtil e.paused = e2.paused = false; } +// if (mappings.getMap().isEmpty() == false) +// { +// checkReturns(m1, ctx1); +// } + return mappings; } - //static boolean hit; + + private static boolean checkReturns(Method method, MethodContext ctx) + { + List ins = method.getCode().getInstructions().getInstructions().stream().filter(i -> i instanceof ReturnInstruction).collect(Collectors.toList()); + List exc = ctx.instructions.stream().map(i -> i.getInstruction()).collect(Collectors.toList()); + + for (Instruction i : ins) + { + if (!exc.contains(i)) + { + return false; + } + } + + return true; + } + + //private static boolean containsMappableInstruction public static boolean isMappable(InvokeInstruction ii) { diff --git a/src/main/java/net/runelite/deob/execution/Frame.java b/src/main/java/net/runelite/deob/execution/Frame.java index ebff443f7e..09ff882a32 100644 --- a/src/main/java/net/runelite/deob/execution/Frame.java +++ b/src/main/java/net/runelite/deob/execution/Frame.java @@ -236,9 +236,12 @@ public class Frame } InstructionContext ictx = this.instructions.get(this.instructions.size() - 1); + assert ictx.getInstruction() == oldCur; execution.contexts.put(oldCur, ictx); + this.ctx.instructions.add(ictx); + execution.executed.add(oldCur); processExceptions(oldCur); diff --git a/src/main/java/net/runelite/deob/execution/MethodContext.java b/src/main/java/net/runelite/deob/execution/MethodContext.java index fa97ec80d3..bf842c7848 100644 --- a/src/main/java/net/runelite/deob/execution/MethodContext.java +++ b/src/main/java/net/runelite/deob/execution/MethodContext.java @@ -1,7 +1,8 @@ package net.runelite.deob.execution; +import java.util.ArrayList; import java.util.Collection; -import net.runelite.deob.Field; +import java.util.List; import net.runelite.deob.attributes.code.Instruction; import org.apache.commons.collections4.map.MultiValueMap; @@ -9,6 +10,7 @@ public class MethodContext { private Execution execution; private MultiValueMap visited = new MultiValueMap<>(); + public List instructions = new ArrayList<>(); public MethodContext(Execution execution) { 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 a833c2446e..d86d56b567 100644 --- a/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java +++ b/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java @@ -117,8 +117,8 @@ public class MapStaticTest ClassGroup group1 = JarUtil.loadJar(new File(JAR1)); ClassGroup group2 = JarUtil.loadJar(new File(JAR2)); - Method m1 = group1.findClass("client").findMethod("method273"); - Method m2 = group2.findClass("client").findMethod("method235"); + Method m1 = group1.findClass("client").findMethod("method585"); + Method m2 = group2.findClass("class44").findMethod("method930"); HashMap all = new HashMap(); List pmes = new ArrayList<>(); @@ -200,15 +200,15 @@ public class MapStaticTest assert m1s.size() == m2s.size(); List pmes = new ArrayList<>(); - for (int i = 0; i < m1s.size(); ++i) - { - Method m1 = m1s.get(i), m2 = m2s.get(i); - - assert m1.getPoolMethod().equals(m2.getPoolMethod()); - - HashMap all = new HashMap(); - map(all, pmes, m1, m2); - } +// for (int i = 0; i < m1s.size(); ++i) +// { +// Method m1 = m1s.get(i), m2 = m2s.get(i); +// +// assert m1.getPoolMethod().equals(m2.getPoolMethod()); +// +// HashMap all = new HashMap(); +// map(all, pmes, m1, m2); +// } ParallelExecutorMapping finalm = new ParallelExecutorMapping(group1, group2); for (ParallelExecutorMapping pme : pmes) @@ -246,10 +246,20 @@ public class MapStaticTest // ClassGroup two = JarUtil.loadJar(new File(JAR2)); List pmes = new ArrayList<>(); - for (int i = 0; i < 250; ++i) + for (int i = -1; i < 250; ++i) { - ClassFile c1 = one.findClass("class" + i); - ClassFile c2 = two.findClass("class" + i); + ClassFile c1, c2; + + if (i == -1) + { + c1 = one.findClass("client"); + c2 = two.findClass("client"); + } + else + { + c1 = one.findClass("class" + i); + c2 = two.findClass("class" + i); + } if (c1 == null || c2 == null) continue; @@ -258,20 +268,22 @@ public class MapStaticTest msm.map(c1, c2); Multimap map = msm.getMap(); - for (Method m : msm.getMap().keySet()) + for (Method m : map.keySet()) { - Collection methods = msm.getMap().get(m); + Collection methods = map.get(m); for (Method other : methods) { - ParallelExecutorMapping pme = MappingExecutorUtil.map(m, other); - - if (pme.getMap().isEmpty()) - continue; - - pme.map(m, other); - - pmes.add(pme); + HashMap all = new HashMap(); + map(all, pmes, m, other); +// ParallelExecutorMapping pme = MappingExecutorUtil.map(m, other); +// +// if (pme.getMap().isEmpty()) +// continue; +// +// pme.map(m, other); +// +// pmes.add(pme); } //HashMap all = new HashMap(); //map(all, pmes, e.getKey(), e.getValue()); @@ -305,17 +317,17 @@ public class MapStaticTest { for (Method other : methods) { - ParallelExecutorMapping pme = MappingExecutorUtil.map(m, other); + HashMap all = new HashMap(); + map(all, pmes, m, other); - if (pme.getMap().isEmpty()) - continue; - -// HashMap all = new HashMap(); -// map(all, pmes, m, other); - pme.map(m, other); - - pmes.add(pme); - //System.out.println(m + " " + other + " " + pme.getMap().size()); +// ParallelExecutorMapping pme = MappingExecutorUtil.map(m, other); +// +// if (pme.getMap().isEmpty()) +// continue; +// +// pme.map(m, other); +// +// pmes.add(pme); } } } @@ -378,25 +390,12 @@ public class MapStaticTest if (m1.getName().equals("vmethod3096")) return; - if (m1.getName().equals("method32")) - { - int i=5; - } + ParallelExecutorMapping mappings = MappingExecutorUtil.map(m1, m2); - ParallelExecutorMapping -// try -// { - mappings = MappingExecutorUtil.map(m1, m2); -// } -// catch (Throwable ex) -// { -// ex.printStackTrace(); -// System.err.println("Error mapping " + m1 + " to " + m2); -// //if (test) -// // throw ex; -// return; -// } + if (mappings.getMap().isEmpty()) + return; + mappings.map(m1, m2); result.add(mappings); for (Entry e : mappings.getMap().entrySet())