From be1b8f1e9865d19ce9dc5697d4a3a0245a0e7b8b Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 11 Nov 2015 14:49:12 -0500 Subject: [PATCH] various fixes to graph building. I think there is a problem with how the execution runs, where it is not exploring all paths, because I have v13 class133.method2817 -> v14 class133 method2828 and there is no edge on the rhs for method4060->method4081. I think it is from two branches jumping to a place which jumps to the same place after, with invoke instructions on both sides. --- src/main/java/net/runelite/deob/Deob.java | 2 +- .../deob/deobfuscators/rename/Rename.java | 5 +++-- .../runelite/deob/execution/Execution.java | 2 +- .../net/runelite/deob/execution/Frame.java | 4 +++- .../deob/execution/MethodContext.java | 22 ++++++------------- 5 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/main/java/net/runelite/deob/Deob.java b/src/main/java/net/runelite/deob/Deob.java index d818cb1221..8f1745b9c6 100644 --- a/src/main/java/net/runelite/deob/Deob.java +++ b/src/main/java/net/runelite/deob/Deob.java @@ -37,7 +37,7 @@ public class Deob { public static void main(String[] args) throws IOException { - //merge(); if(true) return; + merge(); if(true) return; long start = System.currentTimeMillis(); diff --git a/src/main/java/net/runelite/deob/deobfuscators/rename/Rename.java b/src/main/java/net/runelite/deob/deobfuscators/rename/Rename.java index 2883e58c91..8d0367c6e8 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/rename/Rename.java +++ b/src/main/java/net/runelite/deob/deobfuscators/rename/Rename.java @@ -3,6 +3,7 @@ package net.runelite.deob.deobfuscators.rename; import edu.ucla.sspace.graph.Graph; import edu.ucla.sspace.graph.isomorphism.IsomorphismTester; import edu.ucla.sspace.graph.isomorphism.TypedVF2IsomorphismTester; +import edu.ucla.sspace.graph.isomorphism.VF2IsomorphismTester; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -34,7 +35,7 @@ public class Rename { Graph g1 = f1.getMethodCtx().getGraph(), g2 = f2.getMethodCtx().getGraph(); - IsomorphismTester isoTest = new TypedVF2IsomorphismTester(); + IsomorphismTester isoTest = new /*Typed*/VF2IsomorphismTester(); if (!isoTest.areIsomorphic(g1, g2)) { System.out.println("Not isomorphic " + g1.size() + " " + g2.size()); @@ -152,7 +153,7 @@ public class Rename Method m = (Method) next.get(); Method m2 = (Method) objMap.get(m); - System.out.println("Scanning " + m.getName() + " -> " + m2.getName()); + System.out.println("Scanning " + m.getMethods().getClassFile().getName() + "." + m.getName() + " -> " + m2.getMethods().getClassFile().getName() + "." + m2.getName()); process(m, m2); processed.add(m); } diff --git a/src/main/java/net/runelite/deob/execution/Execution.java b/src/main/java/net/runelite/deob/execution/Execution.java index 9dbefab8c8..9f3d3f031c 100644 --- a/src/main/java/net/runelite/deob/execution/Execution.java +++ b/src/main/java/net/runelite/deob/execution/Execution.java @@ -138,7 +138,7 @@ public class Execution if (c != null) return c; - c = new MethodContext(m); + c = new MethodContext(); methodContexts.put(m, c); return c; } diff --git a/src/main/java/net/runelite/deob/execution/Frame.java b/src/main/java/net/runelite/deob/execution/Frame.java index 6f4501f6f0..4e17d7b382 100644 --- a/src/main/java/net/runelite/deob/execution/Frame.java +++ b/src/main/java/net/runelite/deob/execution/Frame.java @@ -30,6 +30,7 @@ public class Frame private Variables variables; private List instructions = new ArrayList<>(); // instructions executed in this frame private MethodContext ctx; + protected int prevVertex = -1; public Frame(Execution execution, Method method) { @@ -99,6 +100,7 @@ public class Frame this.stack = new Stack(other.stack); this.variables = new Variables(other.variables); this.ctx = other.ctx; + this.prevVertex = other.prevVertex; } public Frame dup() @@ -194,7 +196,7 @@ public class Frame if (!executing) break; - ctx.buildGraph(oldCur); + ctx.buildGraph(this, oldCur); if (oldCur == cur) { diff --git a/src/main/java/net/runelite/deob/execution/MethodContext.java b/src/main/java/net/runelite/deob/execution/MethodContext.java index df76b68c7f..f6e20e7e2b 100644 --- a/src/main/java/net/runelite/deob/execution/MethodContext.java +++ b/src/main/java/net/runelite/deob/execution/MethodContext.java @@ -16,20 +16,12 @@ import org.apache.commons.collections4.map.MultiValueMap; public class MethodContext { - private Method method; - private MultiValueMap visited = new MultiValueMap<>(); private IdGen ids = new IdGen(); private Map idMap = new HashMap<>(); private Map insMap = new HashMap<>(); private Graph graph = new SparseDirectedGraph(); - private int prevVertex = -1; - public MethodContext(Method method) - { - this.method = method; - } - public Map getIdMap() { return idMap; @@ -57,7 +49,7 @@ public class MethodContext int id = ids.get(); - graph.add(id); + //graph.add(id); this.idMap.put(id, i); this.insMap.put(i, id); @@ -65,7 +57,7 @@ public class MethodContext return id; } - protected void buildGraph(Instruction i) + protected void buildGraph(Frame frame, Instruction i) { if (i instanceof InvokeInstruction) { @@ -87,12 +79,12 @@ public class MethodContext return; } - if (prevVertex == -1) + if (frame.prevVertex == -1) { int id = getIdFor(i); //int id = ids.get(); //graph.add(id); - prevVertex = id; + frame.prevVertex = id; //this.idMap.put(id, i); return; } @@ -102,12 +94,12 @@ public class MethodContext //graph.add(id); //idMap.put(id, i); - if (id == prevVertex) + if (id == frame.prevVertex) return; - DirectedEdge edge = new SimpleDirectedEdge(prevVertex, id); + DirectedEdge edge = new SimpleDirectedEdge(frame.prevVertex, id); graph.add(edge); - prevVertex = id; + frame.prevVertex = id; } }