diff --git a/src/main/java/net/runelite/deob/Method.java b/src/main/java/net/runelite/deob/Method.java index 1243bf3f90..a29ba9a7fe 100644 --- a/src/main/java/net/runelite/deob/Method.java +++ b/src/main/java/net/runelite/deob/Method.java @@ -56,7 +56,7 @@ public class Method @Override public String toString() { - return this.getMethods().getClassFile().getName() + "." + this.name + this.arguments; + return (this.isStatic() ? "static " : "") + this.getMethods().getClassFile().getName() + "." + this.name + this.arguments; } public void write(DataOutputStream out) throws IOException diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeStatic.java b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeStatic.java index 9116cad69e..ee1080a6e2 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeStatic.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeStatic.java @@ -105,7 +105,7 @@ public class InvokeStatic extends Instruction implements InvokeInstruction // add possible method call to execution Execution execution = frame.getExecution(); - Frame f = execution.invoke(ins, method); + execution.invoke(ins, method); } frame.addInstructionContext(ins); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/PutField.java b/src/main/java/net/runelite/deob/attributes/code/instructions/PutField.java index ddb551b4ea..da534bebe2 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/PutField.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/PutField.java @@ -16,6 +16,7 @@ import net.runelite.deob.pool.NameAndType; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import net.runelite.deob.Method; public class PutField extends Instruction implements SetFieldInstruction { @@ -26,6 +27,13 @@ public class PutField extends Instruction implements SetFieldInstruction { super(instructions, type, pc); } + + @Override + public String toString() + { + Method m = this.getInstructions().getCode().getAttributes().getMethod(); + return "putfield " + myField + " in " + m; + } @Override public void load(DataInputStream is) throws IOException diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/PutStatic.java b/src/main/java/net/runelite/deob/attributes/code/instructions/PutStatic.java index 627107b28d..c3d316b60b 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/PutStatic.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/PutStatic.java @@ -16,6 +16,7 @@ import net.runelite.deob.pool.NameAndType; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import net.runelite.deob.Method; public class PutStatic extends Instruction implements SetFieldInstruction { @@ -27,6 +28,13 @@ public class PutStatic extends Instruction implements SetFieldInstruction super(instructions, type, pc); } + @Override + public String toString() + { + Method m = this.getInstructions().getCode().getAttributes().getMethod(); + return "putstatic " + myField + " in " + m; + } + @Override public void load(DataInputStream is) throws IOException { diff --git a/src/main/java/net/runelite/deob/deobfuscators/rename/graph/Vertex.java b/src/main/java/net/runelite/deob/deobfuscators/rename/graph/Vertex.java index 0fdc7d4106..087afdd793 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/rename/graph/Vertex.java +++ b/src/main/java/net/runelite/deob/deobfuscators/rename/graph/Vertex.java @@ -31,7 +31,7 @@ public class Vertex private final Object object; private VertexType type; - private final Map edges = new HashMap<>(); + private final Set edges = new HashSet<>(); private Collection mightBe; private Vertex is; @@ -107,8 +107,8 @@ public class Vertex public void addEdge(Edge edge) { - Edge c = edges.get(edge); - if (c != null) + if (edges.contains(edge)) + //if (c != null) { // if (edge.getIns() instanceof SetFieldInstruction && !edgeFrom.contains(edge.getIns())) // { @@ -118,12 +118,13 @@ public class Vertex return; } - edges.put(edge, edge); + edges.add(edge); + //edges.put(edge, edge); } public Set getEdges() { - return edges.keySet(); + return edges; } public void merge(Collection maybe) @@ -295,21 +296,21 @@ public class Vertex if (this.getType() != other.getType()) return false; - if (this.getEdges().size() != other.getEdges().size()) - return false; - - for (EdgeType e : EdgeType.values()) - { - // for each edge of this type, it must be equal with just one of the others - - if (this.edgesOf(e) != other.edgesOf(e))// || - //this.solvedEdgesOfType(e) != other.solvedEdgesOfType(e)) - { - int thise = edgesOf(e), othere = other.edgesOf(e); - int thisse = this.solvedEdgesOfType(e), otherse = other.solvedEdgesOfType(e); - return false; - } - } +// if (this.getEdges().size() != other.getEdges().size()) +// return false; +// +// for (EdgeType e : EdgeType.values()) +// { +// // for each edge of this type, it must be equal with just one of the others +// +// if (this.edgesOf(e) != other.edgesOf(e))// || +// //this.solvedEdgesOfType(e) != other.solvedEdgesOfType(e)) +// { +// int thise = edgesOf(e), othere = other.edgesOf(e); +// int thisse = this.solvedEdgesOfType(e), otherse = other.solvedEdgesOfType(e); +// return false; +// } +// } // must be 1->1 // map v -> possibles @@ -424,7 +425,7 @@ public class Vertex private int edgesOf(EdgeType type) { int t = 0; - for (Edge e : this.edges.values()) + for (Edge e : this.edges) if (e.getType() == type) ++t; return t; @@ -432,6 +433,6 @@ public class Vertex private int solvedEdgesOfType(EdgeType type) { - return (int) edges.values().stream().filter(e -> e.getType() == type).filter(e -> e.getTo().getOther() != null).count(); + return (int) edges.stream().filter(e -> e.getType() == type).filter(e -> e.getTo().getOther() != null).count(); } } diff --git a/src/main/java/net/runelite/deob/execution/Execution.java b/src/main/java/net/runelite/deob/execution/Execution.java index 1fb7a7573a..ce387ee35f 100644 --- a/src/main/java/net/runelite/deob/execution/Execution.java +++ b/src/main/java/net/runelite/deob/execution/Execution.java @@ -37,7 +37,6 @@ public class Execution public Set executed = new HashSet<>(); // executed instructions private MultiValueMap invokes = new MultiValueMap<>(); public MultiValueMap contexts = new MultiValueMap<>(); - private Map methodContexts = new HashMap<>(); private boolean buildGraph; // if true the frame graph is built and execution hasJumped also compares previous instructions private Graph graph = new Graph(); @@ -91,6 +90,8 @@ public class Execution private boolean hasInvoked(InstructionContext from, Method to) { + // this is wrong because the called of the method of from + // might be different, for building graph Collection methods = invokes.getCollection(from); if (methods != null && methods.contains(to)) return true; @@ -150,17 +151,6 @@ public class Execution { return contexts.getCollection(i); } - - public MethodContext getMethodContext(Method m) - { - MethodContext c = methodContexts.get(m); - if (c != null) - return c; - - c = new MethodContext(this); - methodContexts.put(m, c); - return c; - } public boolean isBuildGraph() { diff --git a/src/main/java/net/runelite/deob/execution/Frame.java b/src/main/java/net/runelite/deob/execution/Frame.java index 71016044c6..bdb8de836b 100644 --- a/src/main/java/net/runelite/deob/execution/Frame.java +++ b/src/main/java/net/runelite/deob/execution/Frame.java @@ -27,8 +27,7 @@ public class Frame private List instructions = new ArrayList<>(); // instructions executed in this frame private MethodContext ctx; protected Method nonStatic; // next non static method up the stack - public Field lastField; - public Frame staticReturn; + private Frame caller; public Frame(Execution execution, Method method) { @@ -39,7 +38,10 @@ public class Frame stack = new Stack(code.getMaxStack()); variables = new Variables(code.getMaxLocals()); - ctx = execution.getMethodContext(method); + // 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 + ctx = new MethodContext(execution); nonStatic = method; } @@ -70,6 +72,7 @@ public class Frame { this.nonStatic = ctx.getFrame().nonStatic; } + caller = ctx.getFrame(); // initialize LVT. the last argument is popped first, and is at arguments[0] List pops = ctx.getPops(); @@ -105,8 +108,7 @@ public class Frame this.variables = new Variables(other.variables); this.ctx = other.ctx; this.nonStatic = other.nonStatic; - this.lastField = other.lastField; - this.staticReturn = other.staticReturn; + this.caller = other.caller; } public Frame dup() @@ -223,12 +225,6 @@ public class Frame break; execution.buildGraph(this, oldCur, ictx); - if (oldCur instanceof SetFieldInstruction) - { - SetFieldInstruction sfi = (SetFieldInstruction) oldCur; - if (sfi.getMyField() != null) - this.lastField = sfi.getMyField(); - } if (oldCur == cur) {