doesn't work. graph stuff doesnt like ids of 0. and i need to reuse ids sometimes for some instructions, oops.
This commit is contained in:
@@ -3,10 +3,14 @@ package net.runelite.deob.deobfuscators.rename;
|
||||
import edu.ucla.sspace.graph.Graph;
|
||||
import edu.ucla.sspace.graph.isomorphism.IsomorphismTester;
|
||||
import edu.ucla.sspace.graph.isomorphism.TypedVF2IsomorphismTester;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import net.runelite.deob.ClassGroup;
|
||||
import net.runelite.deob.Method;
|
||||
@@ -23,6 +27,9 @@ public class Rename
|
||||
// old -> new object mapping
|
||||
private Map<Object, Object> objMap = new HashMap<>();
|
||||
|
||||
// methods which have been processed in the original
|
||||
private Set<Method> processed = new HashSet<>();
|
||||
|
||||
private boolean compare(Frame f1, Frame f2)
|
||||
{
|
||||
Graph g1 = f1.getGraph(), g2 = f2.getGraph();
|
||||
@@ -36,11 +43,11 @@ public class Rename
|
||||
|
||||
for (Entry<Integer, Integer> e : mapping.entrySet())
|
||||
{
|
||||
if (e.getKey() == null || e.getValue() == null)
|
||||
{
|
||||
assert e.getKey() == e.getValue();
|
||||
continue;
|
||||
}
|
||||
// if (e.getKey() == null || e.getValue() == null)
|
||||
// {
|
||||
// assert e.getKey() == e.getValue();
|
||||
// continue;
|
||||
// }
|
||||
|
||||
Instruction i1 = map1.get(e.getKey());
|
||||
Instruction i2 = map2.get(e.getValue());
|
||||
@@ -55,7 +62,7 @@ public class Rename
|
||||
{
|
||||
Method m1 = ii1.getMethods().get(i), m2 = ii2.getMethods().get(i);
|
||||
|
||||
assert objMap.containsKey(m1) == false || objMap.get(m1) == m2;
|
||||
// assert objMap.containsKey(m1) == false || objMap.get(m1) == m2;
|
||||
objMap.put(m1, m2);
|
||||
}
|
||||
|
||||
@@ -71,25 +78,73 @@ 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());
|
||||
|
||||
outer:
|
||||
for (Frame fr1 : f1)
|
||||
for (Frame fr2 : f2)
|
||||
if (compare(fr1, fr2))
|
||||
return;
|
||||
{
|
||||
compare(fr1, fr2);
|
||||
//if (compare(fr1, fr2))
|
||||
// break outer;
|
||||
}
|
||||
|
||||
System.out.println("end");
|
||||
//return;
|
||||
}
|
||||
public void run(ClassGroup one, ClassGroup two)
|
||||
{
|
||||
eone = new Execution(one);
|
||||
eone.populateInitialMethods();
|
||||
List<Method> initial1 = eone.getInitialMethods().stream().sorted((m1, m2) -> m1.getName().compareTo(m2.getName())).collect(Collectors.toList());
|
||||
eone.run();
|
||||
|
||||
etwo = new Execution(two);
|
||||
etwo.populateInitialMethods();
|
||||
List<Method> initial2 = etwo.getInitialMethods().stream().sorted((m1, m2) -> m1.getName().compareTo(m2.getName())).collect(Collectors.toList());
|
||||
etwo.run();
|
||||
|
||||
assert initial1.size() == initial2.size();
|
||||
|
||||
for (int i = 0; i < initial1.size(); ++i)
|
||||
{
|
||||
Method m1 = initial1.get(i), m2 = initial2.get(i);
|
||||
|
||||
objMap.put(m1, m2);
|
||||
}
|
||||
|
||||
// process(
|
||||
// initial1.get(0).getMethod(),
|
||||
// initial2.get(0).getMethod()
|
||||
// );
|
||||
// processed.add(initial1.get(0).getMethod());
|
||||
process(
|
||||
one.findClass("client").findMethod("init"),
|
||||
two.findClass("client").findMethod("init")
|
||||
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 (Entry<Object, Object> e : objMap.entrySet())
|
||||
{
|
||||
Method m1 = (Method) e.getKey();
|
||||
Method m2 = (Method) e.getValue();
|
||||
|
||||
System.out.println("FINAL " + m1.getMethods().getClassFile().getName() + "." + m1.getName() + " -> " + m2.getMethods().getClassFile().getName() + "." + m2.getName());
|
||||
}
|
||||
|
||||
System.out.println("done");
|
||||
}
|
||||
|
||||
@@ -40,8 +40,10 @@ public class Execution
|
||||
this.encryption = encryption;
|
||||
}
|
||||
|
||||
public void populateInitialMethods()
|
||||
public List<Method> getInitialMethods()
|
||||
{
|
||||
List<Method> methods = new ArrayList<>();
|
||||
|
||||
group.buildClassGraph(); // required when looking up methods
|
||||
|
||||
for (ClassFile cf : group.getClasses())
|
||||
@@ -56,12 +58,28 @@ public class Execution
|
||||
continue;
|
||||
}
|
||||
|
||||
Frame frame = new Frame(this, m);
|
||||
frame.initialize();
|
||||
addFrame(frame); // I guess this method name is overriding a jre interface (init, run, ?).
|
||||
methods.add(m); // I guess this method name is overriding a jre interface (init, run, ?).
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return methods;
|
||||
}
|
||||
|
||||
public void populateInitialMethods()
|
||||
{
|
||||
for (Method m : this.getInitialMethods())
|
||||
{
|
||||
if (m.getCode() == null)
|
||||
{
|
||||
methods.add(m);
|
||||
continue;
|
||||
}
|
||||
|
||||
Frame frame = new Frame(this, m);
|
||||
frame.initialize();
|
||||
addFrame(frame); // I guess this method name is overriding a jre interface (init, run, ?).
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasInvoked(InstructionContext from, Method to)
|
||||
|
||||
@@ -33,6 +33,7 @@ public class Frame
|
||||
|
||||
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;
|
||||
|
||||
@@ -278,6 +279,21 @@ public class Frame
|
||||
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)
|
||||
@@ -302,16 +318,18 @@ public class Frame
|
||||
|
||||
if (prevVertex == -1)
|
||||
{
|
||||
int id = ids.get();
|
||||
graph.add(id);
|
||||
int id = getIdFor(i);
|
||||
//int id = ids.get();
|
||||
//graph.add(id);
|
||||
prevVertex = id;
|
||||
this.idMap.put(id, i);
|
||||
//this.idMap.put(id, i);
|
||||
return;
|
||||
}
|
||||
|
||||
int id = ids.get();
|
||||
graph.add(id);
|
||||
idMap.put(id, i);
|
||||
int id = getIdFor(i);
|
||||
//int id = ids.get();
|
||||
//graph.add(id);
|
||||
//idMap.put(id, i);
|
||||
|
||||
DirectedEdge edge = new SimpleDirectedEdge(prevVertex, id);
|
||||
graph.add(edge);
|
||||
|
||||
@@ -2,7 +2,7 @@ package net.runelite.deob.util;
|
||||
|
||||
public class IdGen
|
||||
{
|
||||
private volatile int cur;
|
||||
private volatile int cur = 1;
|
||||
|
||||
public synchronized int get()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user