From 4af665e58f76b7f65d06336a5177621db5dfb294 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 25 Nov 2015 18:55:45 -0600 Subject: [PATCH] 576 methods --- .../deobfuscators/rename/ConstantWrapper.java | 51 +++++++++++++++ .../deobfuscators/rename/FieldWrapper.java | 6 +- .../deobfuscators/rename/InstructionList.java | 38 ++++++----- .../deob/deobfuscators/rename/Rename2.java | 63 +++++++++++++------ .../deob/deobfuscators/rename/graph/Edge.java | 6 +- .../deobfuscators/rename/graph/Vertex.java | 33 ++++++++-- 6 files changed, 153 insertions(+), 44 deletions(-) create mode 100644 src/main/java/net/runelite/deob/deobfuscators/rename/ConstantWrapper.java diff --git a/src/main/java/net/runelite/deob/deobfuscators/rename/ConstantWrapper.java b/src/main/java/net/runelite/deob/deobfuscators/rename/ConstantWrapper.java new file mode 100644 index 0000000000..a62b2e3d3e --- /dev/null +++ b/src/main/java/net/runelite/deob/deobfuscators/rename/ConstantWrapper.java @@ -0,0 +1,51 @@ +package net.runelite.deob.deobfuscators.rename; + +import java.util.Objects; +import net.runelite.deob.attributes.code.instruction.types.PushConstantInstruction; + +public class ConstantWrapper +{ + private Object object; + private PushConstantInstruction pci; + + public ConstantWrapper(Object object, PushConstantInstruction pci) + { + this.object = object; + this.pci = pci; + } + + @Override + public String toString() + { + return "constant " + object.getClass().getName() + " " + object + " from instruction " + pci; + } + + @Override + public int hashCode() + { + int hash = 3; + hash = 53 * hash + Objects.hashCode(this.object); + return hash; + } + + @Override + public boolean equals(Object obj) + { + if (obj == null) + { + return false; + } + if (getClass() != obj.getClass()) + { + return false; + } + final ConstantWrapper other = (ConstantWrapper) obj; + if (!Objects.equals(this.object, other.object)) + { + return false; + } + return true; + } + + +} diff --git a/src/main/java/net/runelite/deob/deobfuscators/rename/FieldWrapper.java b/src/main/java/net/runelite/deob/deobfuscators/rename/FieldWrapper.java index 546d66e643..9aa6b69ca3 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/rename/FieldWrapper.java +++ b/src/main/java/net/runelite/deob/deobfuscators/rename/FieldWrapper.java @@ -7,6 +7,8 @@ import net.runelite.deob.signature.Type; public class FieldWrapper { + private static final int FIELD_MASK = Field.ACC_FINAL | Field.ACC_STATIC; + private FieldInstruction fi; public Field field; private Type type; @@ -31,7 +33,7 @@ public class FieldWrapper { int hash = 3; hash = 29 * hash + Objects.hashCode(this.type); - hash = 29 * hash + this.accessFlags; + hash = 29 * hash + (this.accessFlags & FIELD_MASK); return hash; } @@ -51,7 +53,7 @@ public class FieldWrapper { return false; } - if (this.accessFlags != other.accessFlags) + if ((this.accessFlags & FIELD_MASK) != (other.accessFlags & FIELD_MASK)) { return false; } diff --git a/src/main/java/net/runelite/deob/deobfuscators/rename/InstructionList.java b/src/main/java/net/runelite/deob/deobfuscators/rename/InstructionList.java index e8ae859f7e..fb831abc4e 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/rename/InstructionList.java +++ b/src/main/java/net/runelite/deob/deobfuscators/rename/InstructionList.java @@ -9,13 +9,12 @@ import net.runelite.deob.Field; import net.runelite.deob.Method; import net.runelite.deob.attributes.code.Instruction; import net.runelite.deob.attributes.code.instruction.types.GetFieldInstruction; +import net.runelite.deob.attributes.code.instruction.types.InvokeInstruction; import net.runelite.deob.attributes.code.instruction.types.PushConstantInstruction; import net.runelite.deob.attributes.code.instruction.types.SetFieldInstruction; -import net.runelite.deob.attributes.code.instructions.InvokeVirtual; -import net.runelite.deob.deobfuscators.arithmetic.DMath; +import net.runelite.deob.attributes.code.instructions.InvokeStatic; import net.runelite.deob.pool.PoolEntry; import net.runelite.deob.signature.Signature; -import net.runelite.deob.signature.Type; public class InstructionList { @@ -32,14 +31,18 @@ public class InstructionList sig2 = HashMultiset.create(); // check signatures and field types - instructions.stream().filter(i -> i instanceof InvokeVirtual).forEach(i -> { - InvokeVirtual iv = (InvokeVirtual) i; + instructions.stream().filter(i -> i instanceof InvokeInstruction).forEach(i -> { + assert !(i instanceof InvokeStatic); + + InvokeInstruction iv = (InvokeInstruction) i; for (Method m : iv.getMethods()) sig1.add(m.getDescriptor()); }); - other.instructions.stream().filter(i -> i instanceof InvokeVirtual).forEach(i -> { - InvokeVirtual iv = (InvokeVirtual) i; + other.instructions.stream().filter(i -> i instanceof InvokeInstruction).forEach(i -> { + assert !(i instanceof InvokeStatic); + + InvokeInstruction iv = (InvokeInstruction) i; for (Method m : iv.getMethods()) sig2.add(m.getDescriptor()); }); @@ -104,7 +107,7 @@ public class InstructionList if (!ms1.equals(ms2)) return false; - Set constants1 = new HashSet<>(), + Set constants1 = new HashSet<>(), constants2 = new HashSet<>(); instructions.stream().filter(i -> i instanceof PushConstantInstruction).forEach(i -> { @@ -113,10 +116,9 @@ public class InstructionList Object o = e.getObject(); if (o instanceof Integer || o instanceof Long) - if (DMath.isBig((Number) o)) - return; + return; - constants1.add(o); + constants1.add(new ConstantWrapper(o, pci)); }); other.instructions.stream().filter(i -> i instanceof PushConstantInstruction).forEach(i -> { @@ -125,14 +127,22 @@ public class InstructionList Object o = e.getObject(); if (o instanceof Integer || o instanceof Long) - if (DMath.isBig((Number) o)) - return; + return; - constants2.add(o); + constants2.add(new ConstantWrapper(o, pci)); }); if (!constants1.equals(constants2)) + { + for (ConstantWrapper o : constants1) + { + if (!constants2.contains(o)) + { + System.out.println(o); + } + } return false; + } return true; } 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 96049ba1ec..0c4e1095e4 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/rename/Rename2.java +++ b/src/main/java/net/runelite/deob/deobfuscators/rename/Rename2.java @@ -167,10 +167,11 @@ public class Rename2 Vertex v = e.getTo(); // end of edge in g1 - Method m = (Method) v.getObject(); - if (m.getName().equals("vmethod3054")) + boolean b = false; + if (s.toString().equals("Vertex{object=class0.()V}") && + v.toString().equals("Vertex{object=class207.()V}")) { - int i = 5; + b = true; } List l = new ArrayList<>(); @@ -179,12 +180,6 @@ public class Rename2 if (e2.getTo().getOther() != null) continue; // skip solved edges - if (e.getTo().toString().equals("Vertex{object=client.vmethod3054()V}") - && e2.getTo().toString().equals("Vertex{object=client.vmethod2973()V}")) - { - int i= 5; - } - if (!e.getTo().couldBeEqual(e2.getTo())) { System.out.println(e.getTo() + " != " + e2.getTo()); @@ -225,19 +220,26 @@ public class Rename2 System.out.println(eone.getGraph()); System.out.println(etwo.getGraph()); - for (int i = 0; i < Math.min(one.getClasses().size(), two.getClasses().size()); ++i) + for (int i = 0; i < 250; ++i) + //for (int i = 0; i < Math.min(one.getClasses().size(), two.getClasses().size()); ++i) { - ClassFile c1 = one.getClasses().get(i); - ClassFile c2 = two.getClasses().get(i); + ClassFile c1 = one.findClass("class" + i); + ClassFile c2 = two.findClass("class" + i); - Map m1 = this.find(one.getClasses().get(i)); - Map m2 = this.find(two.getClasses().get(i)); + if (c1 == null || c2 == null) + continue; + + //Map m1 = this.find(c1); + //Map m2 = this.find(c2); // mapClassMethods(m1, m2); mapDeobfuscatedMethods(c1, c2); } + ClassFile cf1 = one.findClass("client"), cf2 = two.findClass("client"); + mapDeobfuscatedMethods(cf1, cf2); + //List fl1 = getClientFields(one, eone); //List fl2 = getClientFields(two, etwo); @@ -285,12 +287,33 @@ public class Rename2 System.out.println("methods " +g1.solved(VertexType.METHOD)); System.out.println("f " +g1.solved(VertexType.FIELD)); - NameMappings col = buildCollisionMap(one, two); - rename(col, two); + Vertex stored = null; + for (Vertex v : g1.getVerticies()) + { + if (v.getOther() == null) + continue; + + if (!v.toString().equals("Vertex{object=class0.()V}")) + continue; + + assert stored == null; + stored = v; + + for (Edge e : v.getEdges()) + { + if (e.getTo().getOther() == null) + { + System.out.println("Edge " + e + " on vertex " + v + " is unsolved"); + } + } + } - NameMappings mappings = buildMappings(one, two); // two -> one - - show(mappings); +// NameMappings col = buildCollisionMap(one, two); +// rename(col, two); +// +// NameMappings mappings = buildMappings(one, two); // two -> one +// +// show(mappings); System.out.println("Solved methods "+ g1.solved(VertexType.METHOD) + ", total " + g1.getVerticies().size()); @@ -305,7 +328,7 @@ public class Rename2 Logger.getLogger(Rename2.class.getName()).log(Level.SEVERE, null, ex); } - return mappings; + return null; } private void show(NameMappings mappings) diff --git a/src/main/java/net/runelite/deob/deobfuscators/rename/graph/Edge.java b/src/main/java/net/runelite/deob/deobfuscators/rename/graph/Edge.java index 1e9e895b0c..4125c73674 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/rename/graph/Edge.java +++ b/src/main/java/net/runelite/deob/deobfuscators/rename/graph/Edge.java @@ -93,9 +93,9 @@ public class Edge { if (this.type != other.type) return false; - - if (this.weight != other.weight) - return false; + + //if (this.weight != other.weight) + // return false; return true; } 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 7a15008c0b..c501260a86 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 @@ -23,6 +23,9 @@ import org.apache.commons.collections4.CollectionUtils; public class Vertex { + private static final int FIELD_MASK = Field.ACC_FINAL | Field.ACC_STATIC; + private static final int METHOD_MASK = Method.ACC_ABSTRACT | Method.ACC_FINAL | Method.ACC_STATIC | Method.ACC_SYNCHRONIZED; + private Graph graph; private final Object object; private VertexType type; @@ -118,20 +121,36 @@ public class Vertex public void merge(Collection maybe) { - // mightBe and maybe + boolean b = false; + if (this.toString().equals("Vertex{object=class207.()V}")) + { + b = true; + } if (mightBe == null) mightBe = maybe; else + { + int old = mightBe.size(); mightBe = CollectionUtils.intersection(mightBe, maybe); + if (old == 1 && mightBe.isEmpty()) + { + int i = 6; + } + } } public void finish() { + if (this.toString().equals("Vertex{object=class207.()V}")) + { + int i =5; + } + if (mightBe == null) return; - if (mightBe != null && mightBe.size() == 2) + if (mightBe != null && mightBe.size() > 1) { System.out.println("Can't decide for " + this); @@ -168,6 +187,11 @@ public class Vertex assert is == null; assert other.graph != graph; + Method thism = (Method) object; + Method otherm = (Method) other.object; + + assert thism.getMethods().getClassFile().getName().equals(otherm.getMethods().getClassFile().getName()); + this.is = other; } @@ -255,7 +279,7 @@ public class Vertex if (!m1.getDescriptor().equals(m2.getDescriptor())) return false; - if (m1.getAccessFlags() != m2.getAccessFlags()) + if ((m1.getAccessFlags() & METHOD_MASK) != (m2.getAccessFlags() & METHOD_MASK)) return false; if ((m1.getCode() == null) != (m2.getCode() == null)) @@ -277,8 +301,7 @@ public class Vertex if (!f1.getType().equals(f2.getType())) return false; - access flags can change sometimes from non public to public like 2726 -> 2738 - if (f1.isStatic() != f2.isStatic() || f1.getAccessFlags() != f2.getAccessFlags()) + if ((f1.getAccessFlags() & FIELD_MASK) != (f2.getAccessFlags() & FIELD_MASK)) return false; if (!f1.isStatic())