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 ca10eb6604..8140d4c88b 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/rename/Rename.java +++ b/src/main/java/net/runelite/deob/deobfuscators/rename/Rename.java @@ -3,10 +3,14 @@ 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 java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Optional; +import java.util.Set; import java.util.stream.Collectors; import net.runelite.deob.ClassGroup; import net.runelite.deob.Method; @@ -23,6 +27,9 @@ public class Rename // old -> new object mapping private Map objMap = new HashMap<>(); + // methods which have been processed in the original + private Set processed = new HashSet<>(); + private boolean compare(Frame f1, Frame f2) { Graph g1 = f1.getGraph(), g2 = f2.getGraph(); @@ -36,11 +43,11 @@ public class Rename for (Entry e : mapping.entrySet()) { - if (e.getKey() == null || e.getValue() == null) - { - assert e.getKey() == e.getValue(); - continue; - } +// if (e.getKey() == null || e.getValue() == null) +// { +// assert e.getKey() == e.getValue(); +// continue; +// } Instruction i1 = map1.get(e.getKey()); Instruction i2 = map2.get(e.getValue()); @@ -55,7 +62,7 @@ public class Rename { Method m1 = ii1.getMethods().get(i), m2 = ii2.getMethods().get(i); - assert objMap.containsKey(m1) == false || objMap.get(m1) == m2; +// assert objMap.containsKey(m1) == false || objMap.get(m1) == m2; objMap.put(m1, m2); } @@ -71,25 +78,73 @@ public class Rename List f1 = eone.processedFrames.stream().filter(f -> f.getMethod() == one).collect(Collectors.toList()); List f2 = etwo.processedFrames.stream().filter(f -> f.getMethod() == two).collect(Collectors.toList()); + outer: for (Frame fr1 : f1) for (Frame fr2 : f2) - if (compare(fr1, fr2)) - return; + { + compare(fr1, fr2); + //if (compare(fr1, fr2)) + // break outer; + } + + System.out.println("end"); + //return; } public void run(ClassGroup one, ClassGroup two) { eone = new Execution(one); eone.populateInitialMethods(); + List initial1 = eone.getInitialMethods().stream().sorted((m1, m2) -> m1.getName().compareTo(m2.getName())).collect(Collectors.toList()); eone.run(); etwo = new Execution(two); etwo.populateInitialMethods(); + List initial2 = etwo.getInitialMethods().stream().sorted((m1, m2) -> m1.getName().compareTo(m2.getName())).collect(Collectors.toList()); etwo.run(); + assert initial1.size() == initial2.size(); + + for (int i = 0; i < initial1.size(); ++i) + { + Method m1 = initial1.get(i), m2 = initial2.get(i); + + objMap.put(m1, m2); + } + +// process( +// initial1.get(0).getMethod(), +// initial2.get(0).getMethod() +// ); +// processed.add(initial1.get(0).getMethod()); process( - one.findClass("client").findMethod("init"), - two.findClass("client").findMethod("init") + one.findClass("class143").findMethod("run"), + two.findClass("class143").findMethod("run") ); +// processed.add(one.findClass("client").findMethod("init")); + +// for (;;) +// { +// Optional next = objMap.keySet().stream() +// .filter(m -> !processed.contains(m)) +// .findAny(); +// if (!next.isPresent()) +// break; +// +// Method m = (Method) next.get(); +// Method m2 = (Method) objMap.get(m); +// +// System.out.println("Scanning " + m.getName() + " -> " + m2.getName()); +// process(m, m2); +// processed.add(m); +// } + + for (Entry e : objMap.entrySet()) + { + Method m1 = (Method) e.getKey(); + Method m2 = (Method) e.getValue(); + + System.out.println("FINAL " + m1.getMethods().getClassFile().getName() + "." + m1.getName() + " -> " + m2.getMethods().getClassFile().getName() + "." + m2.getName()); + } System.out.println("done"); } diff --git a/src/main/java/net/runelite/deob/execution/Execution.java b/src/main/java/net/runelite/deob/execution/Execution.java index a315253c1e..d630b2c1c9 100644 --- a/src/main/java/net/runelite/deob/execution/Execution.java +++ b/src/main/java/net/runelite/deob/execution/Execution.java @@ -40,8 +40,10 @@ public class Execution this.encryption = encryption; } - public void populateInitialMethods() + public List getInitialMethods() { + List methods = new ArrayList<>(); + group.buildClassGraph(); // required when looking up methods for (ClassFile cf : group.getClasses()) @@ -56,12 +58,28 @@ public class Execution continue; } - Frame frame = new Frame(this, m); - frame.initialize(); - addFrame(frame); // I guess this method name is overriding a jre interface (init, run, ?). + methods.add(m); // I guess this method name is overriding a jre interface (init, run, ?). } } } + + return methods; + } + + public void populateInitialMethods() + { + for (Method m : this.getInitialMethods()) + { + if (m.getCode() == null) + { + methods.add(m); + continue; + } + + Frame frame = new Frame(this, m); + frame.initialize(); + addFrame(frame); // I guess this method name is overriding a jre interface (init, run, ?). + } } private boolean hasInvoked(InstructionContext from, Method to) diff --git a/src/main/java/net/runelite/deob/execution/Frame.java b/src/main/java/net/runelite/deob/execution/Frame.java index b15194a01a..9bf7a90eab 100644 --- a/src/main/java/net/runelite/deob/execution/Frame.java +++ b/src/main/java/net/runelite/deob/execution/Frame.java @@ -33,6 +33,7 @@ public class Frame private IdGen ids = new IdGen(); private Map idMap = new HashMap<>(); + private Map insMap = new HashMap<>(); private Graph graph = new SparseDirectedGraph(); // shared. private int prevVertex = -1; @@ -278,6 +279,21 @@ public class Frame return idMap; } + private int getIdFor(Instruction i) + { + if (insMap.containsKey(i)) + return insMap.get(i); + + int id = ids.get(); + + graph.add(id); + + this.idMap.put(id, i); + this.insMap.put(i, id); + + return id; + } + private void buildGraph(Instruction i) { if (i instanceof InvokeInstruction) @@ -302,16 +318,18 @@ public class Frame if (prevVertex == -1) { - int id = ids.get(); - graph.add(id); + int id = getIdFor(i); + //int id = ids.get(); + //graph.add(id); prevVertex = id; - this.idMap.put(id, i); + //this.idMap.put(id, i); return; } - int id = ids.get(); - graph.add(id); - idMap.put(id, i); + int id = getIdFor(i); + //int id = ids.get(); + //graph.add(id); + //idMap.put(id, i); DirectedEdge edge = new SimpleDirectedEdge(prevVertex, id); graph.add(edge); diff --git a/src/main/java/net/runelite/deob/util/IdGen.java b/src/main/java/net/runelite/deob/util/IdGen.java index 5f001bce71..d6d8d0bf56 100644 --- a/src/main/java/net/runelite/deob/util/IdGen.java +++ b/src/main/java/net/runelite/deob/util/IdGen.java @@ -2,7 +2,7 @@ package net.runelite.deob.util; public class IdGen { - private volatile int cur; + private volatile int cur = 1; public synchronized int get() {