This does 326 methods.
This commit is contained in:
@@ -32,14 +32,14 @@ public class Rename
|
||||
|
||||
private boolean compare(Frame f1, Frame f2)
|
||||
{
|
||||
Graph g1 = f1.getGraph(), g2 = f2.getGraph();
|
||||
Graph g1 = f1.getMethodCtx().getGraph(), g2 = f2.getMethodCtx().getGraph();
|
||||
|
||||
IsomorphismTester isoTest = new TypedVF2IsomorphismTester();
|
||||
if (!isoTest.areIsomorphic(g1, g2))
|
||||
return false;
|
||||
|
||||
Map<Integer, Integer> mapping = isoTest.findIsomorphism(g1, g2);
|
||||
Map<Integer, Instruction> map1 = f1.getIdMap(), map2 = f2.getIdMap();
|
||||
Map<Integer, Instruction> map1 = f1.getMethodCtx().getIdMap(), map2 = f2.getMethodCtx().getIdMap();
|
||||
|
||||
for (Entry<Integer, Integer> e : mapping.entrySet())
|
||||
{
|
||||
@@ -78,17 +78,26 @@ public class Rename
|
||||
List<Frame> f1 = eone.processedFrames.stream().filter(f -> f.getMethod() == one).collect(Collectors.toList());
|
||||
List<Frame> f2 = etwo.processedFrames.stream().filter(f -> f.getMethod() == two).collect(Collectors.toList());
|
||||
|
||||
Frame p1 = null, p2 = null;
|
||||
outer:
|
||||
for (Frame fr1 : f1)
|
||||
for (Frame fr2 : f2)
|
||||
{
|
||||
if (p1 == null) p1 = fr1;
|
||||
if (p2 == null) p2 = fr2;
|
||||
|
||||
assert fr1.getMethodCtx() == p1.getMethodCtx();
|
||||
assert fr2.getMethodCtx() == p2.getMethodCtx();
|
||||
}
|
||||
|
||||
for (Frame fr1 : f1)
|
||||
for (Frame fr2 : f2)
|
||||
{
|
||||
compare(fr1, fr2);
|
||||
//if (compare(fr1, fr2))
|
||||
// break outer;
|
||||
break;
|
||||
}
|
||||
|
||||
System.out.println("end");
|
||||
//return;
|
||||
}
|
||||
public void run(ClassGroup one, ClassGroup two)
|
||||
{
|
||||
@@ -108,6 +117,8 @@ public class Rename
|
||||
{
|
||||
Method m1 = initial1.get(i), m2 = initial2.get(i);
|
||||
|
||||
assert m1.getName().equals(m2.getName());
|
||||
|
||||
objMap.put(m1, m2);
|
||||
}
|
||||
|
||||
@@ -116,27 +127,27 @@ public class Rename
|
||||
// initial2.get(0).getMethod()
|
||||
// );
|
||||
// processed.add(initial1.get(0).getMethod());
|
||||
process(
|
||||
one.findClass("class143").findMethod("run"),
|
||||
two.findClass("class143").findMethod("run")
|
||||
);
|
||||
// process(
|
||||
// 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 (;;)
|
||||
{
|
||||
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<Object, Object> e : objMap.entrySet())
|
||||
{
|
||||
@@ -146,6 +157,6 @@ public class Rename
|
||||
System.out.println("FINAL " + m1.getMethods().getClassFile().getName() + "." + m1.getName() + " -> " + m2.getMethods().getClassFile().getName() + "." + m2.getName());
|
||||
}
|
||||
|
||||
System.out.println("done");
|
||||
System.out.println("done count " + objMap.size());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,10 @@ import net.runelite.deob.attributes.code.Instruction;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import net.runelite.deob.deobfuscators.arithmetic.Encryption;
|
||||
import org.apache.commons.collections4.map.MultiValueMap;
|
||||
@@ -24,6 +26,7 @@ public class Execution
|
||||
private MultiValueMap<InstructionContext, Method> invokes = new MultiValueMap<>();
|
||||
private Encryption encryption;
|
||||
public MultiValueMap<Instruction, InstructionContext> contexts = new MultiValueMap<>();
|
||||
private Map<Method, MethodContext> methodContexts = new HashMap<>();
|
||||
|
||||
public Execution(ClassGroup group)
|
||||
{
|
||||
@@ -128,4 +131,15 @@ 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(m);
|
||||
methodContexts.put(m, c);
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,15 +29,7 @@ public class Frame
|
||||
private Stack stack;
|
||||
private Variables variables;
|
||||
private List<InstructionContext> instructions = new ArrayList<>(); // instructions executed in this frame
|
||||
private MultiValueMap<InstructionContext, Instruction> visited = new MultiValueMap<>(); // shared
|
||||
|
||||
private IdGen ids = new IdGen();
|
||||
private Map<Integer, Instruction> idMap = new HashMap<>();
|
||||
private Map<Instruction, Integer> insMap = new HashMap<>();
|
||||
private Graph graph = new SparseDirectedGraph(); // shared.
|
||||
private int prevVertex = -1;
|
||||
|
||||
public static long num;
|
||||
private MethodContext ctx;
|
||||
|
||||
public Frame(Execution execution, Method method)
|
||||
{
|
||||
@@ -48,6 +40,7 @@ public class Frame
|
||||
|
||||
stack = new Stack(code.getMaxStack());
|
||||
variables = new Variables(code.getMaxLocals());
|
||||
ctx = execution.getMethodContext(method);
|
||||
}
|
||||
|
||||
public void initialize()
|
||||
@@ -87,7 +80,7 @@ public class Frame
|
||||
{
|
||||
StackContext argument = pops.remove(0);
|
||||
|
||||
variables.set(lvtOffset, new VariableContext(ctx, argument));//new Type(nat.getDescriptor().getTypeOfArg(i)).toStackType()));
|
||||
variables.set(lvtOffset, new VariableContext(ctx, argument));
|
||||
lvtOffset += nat.getDescriptor().getTypeOfArg(i).getSlots();
|
||||
}
|
||||
|
||||
@@ -105,12 +98,7 @@ public class Frame
|
||||
this.cur = other.cur;
|
||||
this.stack = new Stack(other.stack);
|
||||
this.variables = new Variables(other.variables);
|
||||
this.visited = other.visited;
|
||||
|
||||
this.ids = other.ids;
|
||||
this.idMap = other.idMap;
|
||||
this.graph = other.graph;
|
||||
this.prevVertex = other.prevVertex;
|
||||
this.ctx = other.ctx;
|
||||
}
|
||||
|
||||
public Frame dup()
|
||||
@@ -149,6 +137,11 @@ public class Frame
|
||||
{
|
||||
return variables;
|
||||
}
|
||||
|
||||
public MethodContext getMethodCtx()
|
||||
{
|
||||
return ctx;
|
||||
}
|
||||
|
||||
public void addInstructionContext(InstructionContext i)
|
||||
{
|
||||
@@ -201,7 +194,7 @@ public class Frame
|
||||
if (!executing)
|
||||
break;
|
||||
|
||||
buildGraph(oldCur);
|
||||
ctx.buildGraph(oldCur);
|
||||
|
||||
if (oldCur == cur)
|
||||
{
|
||||
@@ -244,23 +237,13 @@ public class Frame
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasJumped(InstructionContext from, Instruction to)
|
||||
{
|
||||
Collection<Instruction> i = visited.getCollection(from);
|
||||
if (i != null && i.contains(to))
|
||||
return true;
|
||||
|
||||
visited.put(from, to);
|
||||
return false;
|
||||
}
|
||||
|
||||
public void jump(InstructionContext from, Instruction to)
|
||||
{
|
||||
assert to != null;
|
||||
assert to.getInstructions() == method.getCode().getInstructions();
|
||||
assert method.getCode().getInstructions().getInstructions().contains(to);
|
||||
|
||||
if (hasJumped(from, to))
|
||||
if (ctx.hasJumped(from, to))
|
||||
{
|
||||
executing = false;
|
||||
return;
|
||||
@@ -268,72 +251,4 @@ public class Frame
|
||||
|
||||
cur = to;
|
||||
}
|
||||
|
||||
public Graph getGraph()
|
||||
{
|
||||
return graph;
|
||||
}
|
||||
|
||||
public Map<Integer, Instruction> getIdMap()
|
||||
{
|
||||
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)
|
||||
{
|
||||
InvokeInstruction ii = (InvokeInstruction) i;
|
||||
|
||||
List<Method> methods = ii.getMethods();
|
||||
if (methods.isEmpty())
|
||||
return;
|
||||
}
|
||||
// else if (i instanceof FieldInstruction)
|
||||
// {
|
||||
// FieldInstruction fi = (FieldInstruction) i;
|
||||
//
|
||||
// if (fi.getMyField() == null)
|
||||
// return;
|
||||
// }
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (prevVertex == -1)
|
||||
{
|
||||
int id = getIdFor(i);
|
||||
//int id = ids.get();
|
||||
//graph.add(id);
|
||||
prevVertex = id;
|
||||
//this.idMap.put(id, i);
|
||||
return;
|
||||
}
|
||||
|
||||
int id = getIdFor(i);
|
||||
//int id = ids.get();
|
||||
//graph.add(id);
|
||||
//idMap.put(id, i);
|
||||
|
||||
DirectedEdge edge = new SimpleDirectedEdge(prevVertex, id);
|
||||
graph.add(edge);
|
||||
|
||||
prevVertex = id;
|
||||
}
|
||||
}
|
||||
|
||||
113
src/main/java/net/runelite/deob/execution/MethodContext.java
Normal file
113
src/main/java/net/runelite/deob/execution/MethodContext.java
Normal file
@@ -0,0 +1,113 @@
|
||||
package net.runelite.deob.execution;
|
||||
|
||||
import edu.ucla.sspace.graph.DirectedEdge;
|
||||
import edu.ucla.sspace.graph.Graph;
|
||||
import edu.ucla.sspace.graph.SimpleDirectedEdge;
|
||||
import edu.ucla.sspace.graph.SparseDirectedGraph;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.runelite.deob.Method;
|
||||
import net.runelite.deob.attributes.code.Instruction;
|
||||
import net.runelite.deob.attributes.code.instruction.types.InvokeInstruction;
|
||||
import net.runelite.deob.util.IdGen;
|
||||
import org.apache.commons.collections4.map.MultiValueMap;
|
||||
|
||||
public class MethodContext
|
||||
{
|
||||
private Method method;
|
||||
|
||||
private MultiValueMap<InstructionContext, Instruction> visited = new MultiValueMap<>();
|
||||
private IdGen ids = new IdGen();
|
||||
private Map<Integer, Instruction> idMap = new HashMap<>();
|
||||
private Map<Instruction, Integer> insMap = new HashMap<>();
|
||||
private Graph graph = new SparseDirectedGraph();
|
||||
private int prevVertex = -1;
|
||||
|
||||
public MethodContext(Method method)
|
||||
{
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public Map<Integer, Instruction> getIdMap()
|
||||
{
|
||||
return idMap;
|
||||
}
|
||||
|
||||
public Graph getGraph()
|
||||
{
|
||||
return graph;
|
||||
}
|
||||
|
||||
protected boolean hasJumped(InstructionContext from, Instruction to)
|
||||
{
|
||||
Collection<Instruction> i = visited.getCollection(from);
|
||||
if (i != null && i.contains(to))
|
||||
return true;
|
||||
|
||||
visited.put(from, to);
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
protected void buildGraph(Instruction i)
|
||||
{
|
||||
if (i instanceof InvokeInstruction)
|
||||
{
|
||||
InvokeInstruction ii = (InvokeInstruction) i;
|
||||
|
||||
List<Method> methods = ii.getMethods();
|
||||
if (methods.isEmpty())
|
||||
return;
|
||||
}
|
||||
// else if (i instanceof FieldInstruction)
|
||||
// {
|
||||
// FieldInstruction fi = (FieldInstruction) i;
|
||||
//
|
||||
// if (fi.getMyField() == null)
|
||||
// return;
|
||||
// }
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (prevVertex == -1)
|
||||
{
|
||||
int id = getIdFor(i);
|
||||
//int id = ids.get();
|
||||
//graph.add(id);
|
||||
prevVertex = id;
|
||||
//this.idMap.put(id, i);
|
||||
return;
|
||||
}
|
||||
|
||||
int id = getIdFor(i);
|
||||
//int id = ids.get();
|
||||
//graph.add(id);
|
||||
//idMap.put(id, i);
|
||||
|
||||
if (id == prevVertex)
|
||||
return;
|
||||
|
||||
DirectedEdge edge = new SimpleDirectedEdge(prevVertex, id);
|
||||
graph.add(edge);
|
||||
|
||||
prevVertex = id;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user