From 139b31f2acffc60137900ceafb848165b20a7d2c Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 16 Nov 2015 19:48:51 -0500 Subject: [PATCH] seemed promising. doesn't really help. --- .../deob/deobfuscators/rename/Rename.java | 20 +++--- .../runelite/deob/execution/Execution.java | 14 ++-- .../net/runelite/deob/execution/MIKey.java | 51 +++++++++++++ .../deob/execution/MethodContext.java | 72 ++++--------------- 4 files changed, 83 insertions(+), 74 deletions(-) create mode 100644 src/main/java/net/runelite/deob/execution/MIKey.java 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 122c832fc0..facc9a3d16 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/rename/Rename.java +++ b/src/main/java/net/runelite/deob/deobfuscators/rename/Rename.java @@ -45,7 +45,7 @@ public class Rename } Map mapping = isoTest.findIsomorphism(g1, g2); - Map map1 = f1.getMethodCtx().getIdMap(), map2 = f2.getMethodCtx().getIdMap(); + Map> map1 = f1.getMethodCtx().getIdMap(), map2 = f2.getMethodCtx().getIdMap(); for (Entry e : mapping.entrySet()) { @@ -55,24 +55,26 @@ public class Rename // continue; // } - Instruction i1 = map1.get(e.getKey()); - Instruction i2 = map2.get(e.getValue()); + List i1 = map1.get(e.getKey()); + List i2 = map2.get(e.getValue()); - assert i1.getClass() == i2.getClass(); + //assert i1.getClass() == i2.getClass(); - InvokeInstruction ii1 = (InvokeInstruction) i1, ii2 = (InvokeInstruction) i2; + //InvokeInstruction ii1 = (InvokeInstruction) i1, ii2 = (InvokeInstruction) i2; - assert ii1.getMethods().size() == ii2.getMethods().size(); + //assert ii1.getMethods().size() == ii2.getMethods().size(); - for (int i = 0; i < ii1.getMethods().size(); ++i) + assert i1.size() == i2.size(); + + for (int i = 0; i < i1.size(); ++i) { - Method m1 = ii1.getMethods().get(i), m2 = ii2.getMethods().get(i); + Method m1 = i1.get(i), m2 = i2.get(i); // assert objMap.containsKey(m1) == false || objMap.get(m1) == m2; objMap.put(m1, m2); } - System.out.println("MATCH " + ii1.getMethods().get(0).getName() + " -> " + ii2.getMethods().get(0).getName()); + System.out.println("MATCH " + i1.get(0).getName() + " -> " + i2.get(0).getName()); } return true; diff --git a/src/main/java/net/runelite/deob/execution/Execution.java b/src/main/java/net/runelite/deob/execution/Execution.java index 62a1774b06..ee5ec36dc5 100644 --- a/src/main/java/net/runelite/deob/execution/Execution.java +++ b/src/main/java/net/runelite/deob/execution/Execution.java @@ -24,7 +24,7 @@ public class Execution processedFrames = new LinkedList<>(); public Set methods = new HashSet<>(); // all methods public Set executed = new HashSet<>(); // executed instructions - private MultiValueMap invokes = new MultiValueMap<>(); + private MultiValueMap invokes = new MultiValueMap<>(); private Encryption encryption; public MultiValueMap contexts = new MultiValueMap<>(); private Map methodContexts = new HashMap<>(); @@ -101,11 +101,13 @@ public class Execution private boolean hasInvoked(InstructionContext from, Method to) { - Collection methods = invokes.getCollection(from); + Frame frame = from.getFrame(); + MIKey key = new MIKey(frame.prevVertex.intValue(), from); + Collection methods = invokes.getCollection(key); if (methods != null && methods.contains(to)) return true; - invokes.put(from, to); + invokes.put(key, to); return false; } @@ -119,8 +121,8 @@ public class Execution if (!this.isFollowInvokes() && !to.isStatic()) return; -// if (hasInvoked(from, to)) -// return; + if (hasInvoked(from, to)) + return; Frame f = new Frame(this, to); f.initialize(from); @@ -151,11 +153,9 @@ public class Execution assert frames.get(0) == frame; frames.remove(0); processedFrames.add(frame); - System.out.println(fcount + "/" + frames.size()); } else { - System.out.println("deferring"); // another frame takes priority } } diff --git a/src/main/java/net/runelite/deob/execution/MIKey.java b/src/main/java/net/runelite/deob/execution/MIKey.java new file mode 100644 index 0000000000..af50cfe09a --- /dev/null +++ b/src/main/java/net/runelite/deob/execution/MIKey.java @@ -0,0 +1,51 @@ +package net.runelite.deob.execution; + +import java.util.Objects; + +class MIKey +{ + private int prevVertex; + private InstructionContext ictx; + + public MIKey(int prevVertex, InstructionContext ictx) + { + this.prevVertex = prevVertex; + this.ictx = ictx; + } + + @Override + public int hashCode() + { + int hash = 7; + hash = 97 * hash + this.prevVertex; + hash = 97 * hash + Objects.hashCode(this.ictx); + return hash; + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + if (obj == null) + { + return false; + } + if (getClass() != obj.getClass()) + { + return false; + } + final MIKey other = (MIKey) obj; + if (this.prevVertex != other.prevVertex) + { + return false; + } + if (!Objects.equals(this.ictx, other.ictx)) + { + return false; + } + return true; + } +} diff --git a/src/main/java/net/runelite/deob/execution/MethodContext.java b/src/main/java/net/runelite/deob/execution/MethodContext.java index 5a644748f0..db12a572af 100644 --- a/src/main/java/net/runelite/deob/execution/MethodContext.java +++ b/src/main/java/net/runelite/deob/execution/MethodContext.java @@ -17,61 +17,13 @@ import net.runelite.deob.util.IdGen; import org.apache.commons.collections4.map.MultiValueMap; import org.apache.commons.lang3.mutable.MutableInt; -class MIKey -{ - private int prevVertex; - private InstructionContext ictx; - - public MIKey(int prevVertex, InstructionContext ictx) - { - this.prevVertex = prevVertex; - this.ictx = ictx; - } - - @Override - public int hashCode() - { - int hash = 7; - hash = 97 * hash + this.prevVertex; - hash = 97 * hash + Objects.hashCode(this.ictx); - return hash; - } - - @Override - public boolean equals(Object obj) - { - if (this == obj) - { - return true; - } - if (obj == null) - { - return false; - } - if (getClass() != obj.getClass()) - { - return false; - } - final MIKey other = (MIKey) obj; - if (this.prevVertex != other.prevVertex) - { - return false; - } - if (!Objects.equals(this.ictx, other.ictx)) - { - return false; - } - return true; - } -} - public class MethodContext { private Execution execution; private MultiValueMap visited = new MultiValueMap<>(); private IdGen ids = new IdGen(); - private Map idMap = new HashMap<>(); - private Map insMap = new HashMap<>(); + private Map> idMap = new HashMap<>(); + private Map, Integer> insMap = new HashMap<>(); private Graph graph = new SparseDirectedGraph(); public MethodContext(Execution execution) @@ -79,7 +31,7 @@ public class MethodContext this.execution = execution; } - public Map getIdMap() + public Map> getIdMap() { return idMap; } @@ -101,11 +53,13 @@ public class MethodContext return false; } - private int getIdFor(Instruction i) + private int getIdFor(List i) { if (insMap.containsKey(i)) return insMap.get(i); + assert idMap.values().contains(i) == false; + int id = ids.get(); //graph.add(id); @@ -121,6 +75,7 @@ public class MethodContext if (!execution.isBuildGraph()) return; + List methods; if (i instanceof InvokeInstruction) { if (i instanceof InvokeStatic) @@ -128,7 +83,7 @@ public class MethodContext InvokeInstruction ii = (InvokeInstruction) i; - List methods = ii.getMethods(); + methods = ii.getMethods(); if (methods.isEmpty()) return; } @@ -146,7 +101,7 @@ public class MethodContext if (frame.prevVertex.intValue() == -1) { - int id = getIdFor(i); + int id = getIdFor(methods); //int id = ids.get(); //graph.add(id); frame.prevVertex.setValue(id); @@ -154,7 +109,7 @@ public class MethodContext return; } - int id = getIdFor(i); + int id = getIdFor(methods); //int id = ids.get(); //graph.add(id); //idMap.put(id, i); @@ -162,9 +117,10 @@ public class MethodContext if (frame.prevVertex.intValue() == id) return; - InvokeInstruction from = (InvokeInstruction) this.idMap.get(frame.prevVertex.intValue()), to = (InvokeInstruction) this.idMap.get(id); - System.out.println("Added edge " + from.getMethods().get(0).getMethods().getClassFile().getName() + "." + from.getMethods().get(0).getName() + - " to " + to.getMethods().get(0).getMethods().getClassFile().getName() + "." + to.getMethods().get(0).getName()); + List from = this.idMap.get(frame.prevVertex.intValue()), to = this.idMap.get(id); + System.out.println("Added edge " + from.get(0).getMethods().getClassFile().getName() + "." + from.get(0).getName() + + " to " + to.get(0).getMethods().getClassFile().getName() + "." + to.get(0).getName() + + " (" + frame.prevVertex.intValue() + " -> " + id + ")"); DirectedEdge edge = new SimpleDirectedEdge(frame.prevVertex.intValue(), id); graph.add(edge);