From 5cbd36a25c572e2bdaf60822c2449185db705b9e Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 29 Nov 2015 20:49:03 -0500 Subject: [PATCH] Solved methods 940, solved fields 1084, unsolved methods 173, unsolved fields 1211. also included jars i am using --- .../deob/deobfuscators/rename/Rename2.java | 8 ++ .../deobfuscators/rename/graph/Vertex.java | 91 ++++++++++++++++++- .../runelite/deob/execution/Execution.java | 64 ++++++------- 3 files changed, 129 insertions(+), 34 deletions(-) diff --git a/src/main/java/net/runelite/deob/deobfuscators/rename/Rename2.java b/src/main/java/net/runelite/deob/deobfuscators/rename/Rename2.java index b561a2ee1c..c7eb8dc90f 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/rename/Rename2.java +++ b/src/main/java/net/runelite/deob/deobfuscators/rename/Rename2.java @@ -428,6 +428,14 @@ public class Rename2 //rename(mappings, two); +// for (Vertex v : g1.getVerticies()) +// { +// if (v.getOther() != null) +// System.out.println(v.getObject() + " -> " + v.getOther().getOther()); +// else +// System.out.println(v.getObject() + " -> unk"); +// } + try { JarUtil.saveJar(two, new File("d:/rs/07/adamout.jar")); 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 14807d9330..48eef4dd79 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 @@ -279,15 +279,86 @@ public class Vertex return il1.couldBeEqual(il2); } + private static boolean recurse = true; public boolean couldBeEqual(Vertex other) { assert this != other; assert graph != other.graph; - assert is == null; - assert other.is == null; +// assert is == null; + //assert other.is == null; + + if (this.getOther() != null || other.getOther() != null) + { + return this.getOther() == other && other.getOther() == this; + } 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; + } + } + + // must be 1->1 + // map v -> possibles + // start with the ones with the least possibilities + +// if (recurse) +// { +// Set others = new HashSet<>(other.getEdges()); +// for (Edge e : edges.values()) +// { +// Vertex v = e.getTo(); +// +// boolean found = false; +// List lv = new ArrayList(); +// for (Edge e2 : others) +// { +// Vertex v2 = e2.getTo(); +// lv.add(v2); +// +// recurse = false; +// if (v.couldBeEqual(v2)) +// // if (e.couldBeEqual(e2)) +// { +// recurse = true; +// // others.remove(e2); +// found = true; +// break; +// } +// recurse = true; +// } +// +// if (!found) +// { +// Vertex v2 = null; +// for (Vertex vt : lv) +// if (vt.getObject() instanceof Method) +// { +// Method m = (Method) vt.getObject(); +// if (m.getName().equals("vmethod2975")) +// { +// v2 = vt; +// break; +// } +// } +// //v.couldBeEqual(v2); +// return false; +// } +// } +// } if (this.getType() == VertexType.METHOD) { @@ -336,6 +407,8 @@ public class Vertex return false; } + // compare other edges, + ConstantValue cf1 = (ConstantValue) f1.getAttributes().findType(AttributeType.CONSTANT_VALUE); ConstantValue cf2 = (ConstantValue) f2.getAttributes().findType(AttributeType.CONSTANT_VALUE); @@ -347,4 +420,18 @@ public class Vertex return true; } + + private int edgesOf(EdgeType type) + { + int t = 0; + for (Edge e : this.edges.values()) + if (e.getType() == type) + ++t; + return t; + } + + private int solvedEdgesOfType(EdgeType type) + { + return (int) edges.values().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 d0d6571642..35d062f153 100644 --- a/src/main/java/net/runelite/deob/execution/Execution.java +++ b/src/main/java/net/runelite/deob/execution/Execution.java @@ -236,8 +236,8 @@ public class Execution if (fi instanceof SetFieldInstruction && frame.lastField != null) { - graph.addEdge(new MethodEdge(i, graph.getVertexFor(fi.getMyField()), graph.getVertexFor(frame.lastField), EdgeType.PREV_FIELD, frame.nonStatic)); - graph.addEdge(new MethodEdge(i, graph.getVertexFor(frame.lastField), graph.getVertexFor(fi.getMyField()), EdgeType.PREV_FIELD_FROM, frame.nonStatic)); + //graph.addEdge(new MethodEdge(i, graph.getVertexFor(fi.getMyField()), graph.getVertexFor(frame.lastField), EdgeType.PREV_FIELD, frame.nonStatic)); + //graph.addEdge(new MethodEdge(i, graph.getVertexFor(frame.lastField), graph.getVertexFor(fi.getMyField()), EdgeType.PREV_FIELD_FROM, frame.nonStatic)); } // if (fi instanceof SetFieldInstruction) @@ -256,36 +256,36 @@ public class Execution // } // } - // associated fields - for (InstructionContext ic : getInsInExpr(ctx, new HashSet<>())) - { - Instruction i2 = (Instruction) ic.getInstruction(); - - if (i2 instanceof FieldInstruction) - { - FieldInstruction fi2 = (FieldInstruction) i2; - - if (fi2.getMyField() == null) - continue; - - // these are within the context of a method - graph.addEdge(new MethodEdge(i2, graph.getVertexFor(fi.getMyField()), graph.getVertexFor(fi2.getMyField()), EdgeType.FIELD_ASSOCIATION, frame.nonStatic)); - graph.addEdge(new MethodEdge(i2, graph.getVertexFor(fi2.getMyField()), graph.getVertexFor(fi.getMyField()), EdgeType.FIELD_ASSOCIATION_FROM, frame.nonStatic)); - } - else if (i2 instanceof InvokeInstruction) - { - InvokeInstruction ii2 = (InvokeInstruction) i2; - - if (ii2 instanceof InvokeStatic) - continue; - - for (Method m : ii2.getMethods()) - { - graph.addEdge(new MethodEdge(i2, graph.getVertexFor(fi.getMyField()), graph.getVertexFor(m), EdgeType.METHOD_ASSOCIATION, frame.nonStatic)); - graph.addEdge(new MethodEdge(i2, graph.getVertexFor(m), graph.getVertexFor(fi.getMyField()), EdgeType.METHOD_ASSOCIATION_FROM, frame.nonStatic)); - } - } - } +// // associated fields +// for (InstructionContext ic : getInsInExpr(ctx, new HashSet<>())) +// { +// Instruction i2 = (Instruction) ic.getInstruction(); +// +// if (i2 instanceof FieldInstruction) +// { +// FieldInstruction fi2 = (FieldInstruction) i2; +// +// if (fi2.getMyField() == null) +// continue; +// +// // these are within the context of a method +// graph.addEdge(new MethodEdge(i2, graph.getVertexFor(fi.getMyField()), graph.getVertexFor(fi2.getMyField()), EdgeType.FIELD_ASSOCIATION, frame.nonStatic)); +// graph.addEdge(new MethodEdge(i2, graph.getVertexFor(fi2.getMyField()), graph.getVertexFor(fi.getMyField()), EdgeType.FIELD_ASSOCIATION_FROM, frame.nonStatic)); +// } +// else if (i2 instanceof InvokeInstruction) +// { +// InvokeInstruction ii2 = (InvokeInstruction) i2; +// +// if (ii2 instanceof InvokeStatic) +// continue; +// +// for (Method m : ii2.getMethods()) +// { +// graph.addEdge(new MethodEdge(i2, graph.getVertexFor(fi.getMyField()), graph.getVertexFor(m), EdgeType.METHOD_ASSOCIATION, frame.nonStatic)); +// graph.addEdge(new MethodEdge(i2, graph.getVertexFor(m), graph.getVertexFor(fi.getMyField()), EdgeType.METHOD_ASSOCIATION_FROM, frame.nonStatic)); +// } +// } +// } } }