more or less promising
This commit is contained in:
@@ -195,46 +195,46 @@ public class Rename2
|
||||
return fields;
|
||||
}
|
||||
|
||||
private void mapOneFrame(ClassGroup group, Execution e)
|
||||
{
|
||||
for (ClassFile cf : group.getClasses())
|
||||
{
|
||||
for (Method m : cf.getMethods().getMethods())
|
||||
{
|
||||
if (m.isStatic())
|
||||
continue;
|
||||
|
||||
List<Frame> frames = e.processedFrames.stream().filter(f -> f.getMethod() == m).collect(Collectors.toList());
|
||||
|
||||
if (frames.size() != 1)
|
||||
continue;
|
||||
|
||||
int count = 0;
|
||||
for (InstructionContext i : frames.get(0).getInstructions())
|
||||
{
|
||||
if (i.getInstruction() instanceof SetFieldInstruction)
|
||||
{
|
||||
SetFieldInstruction sfi = (SetFieldInstruction) i.getInstruction();
|
||||
|
||||
Field f = sfi.getMyField();
|
||||
if (f == null)
|
||||
continue;
|
||||
|
||||
Vertex methodVertex = e.getGraph().getVertexFor(m),
|
||||
fieldVertex = e.getGraph().getVertexFor(f);
|
||||
|
||||
Edge edge = new FieldEdge(i.getInstruction(), methodVertex, fieldVertex, EdgeType.SETFIELD, count);
|
||||
e.getGraph().addEdge(edge);
|
||||
|
||||
edge = new FieldEdge(i.getInstruction(), fieldVertex, methodVertex, EdgeType.SETFIELD_FROM, count);
|
||||
e.getGraph().addEdge(edge);
|
||||
|
||||
++count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// private void mapOneFrame(ClassGroup group, Execution e)
|
||||
// {
|
||||
// for (ClassFile cf : group.getClasses())
|
||||
// {
|
||||
// for (Method m : cf.getMethods().getMethods())
|
||||
// {
|
||||
// if (m.isStatic())
|
||||
// continue;
|
||||
//
|
||||
// List<Frame> frames = e.processedFrames.stream().filter(f -> f.getMethod() == m).collect(Collectors.toList());
|
||||
//
|
||||
// if (frames.size() != 1)
|
||||
// continue;
|
||||
//
|
||||
// int count = 0;
|
||||
// for (InstructionContext i : frames.get(0).getInstructions())
|
||||
// {
|
||||
// if (i.getInstruction() instanceof SetFieldInstruction)
|
||||
// {
|
||||
// SetFieldInstruction sfi = (SetFieldInstruction) i.getInstruction();
|
||||
//
|
||||
// Field f = sfi.getMyField();
|
||||
// if (f == null)
|
||||
// continue;
|
||||
//
|
||||
// Vertex methodVertex = e.getGraph().getVertexFor(m),
|
||||
// fieldVertex = e.getGraph().getVertexFor(f);
|
||||
//
|
||||
// Edge edge = new FieldEdge(i.getInstruction(), methodVertex, fieldVertex, EdgeType.SETFIELD, count);
|
||||
// e.getGraph().addEdge(edge);
|
||||
//
|
||||
// edge = new FieldEdge(i.getInstruction(), fieldVertex, methodVertex, EdgeType.SETFIELD_FROM, count);
|
||||
// e.getGraph().addEdge(edge);
|
||||
//
|
||||
// ++count;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
private void solve()
|
||||
{
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
package net.runelite.deob.deobfuscators.rename.graph;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import net.runelite.deob.attributes.code.Instruction;
|
||||
import net.runelite.deob.attributes.code.instruction.types.DupInstruction;
|
||||
import net.runelite.deob.execution.InstructionContext;
|
||||
import net.runelite.deob.execution.StackContext;
|
||||
|
||||
public class Edge
|
||||
{
|
||||
private final Instruction ins; // craetor
|
||||
private final InstructionContext ins;
|
||||
private final Vertex from, to;
|
||||
private final EdgeType type;
|
||||
private int weight;
|
||||
|
||||
public Edge(Instruction ins, Vertex from, Vertex to, EdgeType type)
|
||||
public Edge(InstructionContext ins, Vertex from, Vertex to, EdgeType type)
|
||||
{
|
||||
this.ins = ins;
|
||||
this.from = from;
|
||||
@@ -20,7 +23,7 @@ public class Edge
|
||||
assert from.getGraph() == to.getGraph();
|
||||
}
|
||||
|
||||
public Instruction getIns()
|
||||
public InstructionContext getIns()
|
||||
{
|
||||
return ins;
|
||||
}
|
||||
@@ -102,9 +105,40 @@ public class Edge
|
||||
if (this.type != other.type)
|
||||
return false;
|
||||
|
||||
if (this.type == EdgeType.SETFIELD)
|
||||
{
|
||||
if (!compareSetField(other.getIns()))
|
||||
return false;
|
||||
}
|
||||
// if (this.weight != other.weight)
|
||||
// return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private InstructionContext handleDup(InstructionContext i, StackContext sctx)
|
||||
{
|
||||
DupInstruction d = (DupInstruction) i.getInstruction();
|
||||
return d.getOriginal(sctx).getPushed();
|
||||
}
|
||||
|
||||
private boolean compareSetField(InstructionContext other)
|
||||
{
|
||||
InstructionContext thisp = ins.getPops().get(0).getPushed(),
|
||||
otherp = other.getPops().get(0).getPushed();
|
||||
|
||||
if (thisp.getInstruction() instanceof DupInstruction)
|
||||
{
|
||||
thisp = handleDup(thisp, ins.getPops().get(0));
|
||||
}
|
||||
if (otherp.getInstruction() instanceof DupInstruction)
|
||||
{
|
||||
otherp = handleDup(otherp, other.getPops().get(0));
|
||||
}
|
||||
|
||||
Class[] c1 = thisp.getInstruction().getClass().getInterfaces(),
|
||||
c2 = otherp.getInstruction().getClass().getInterfaces();
|
||||
|
||||
return Arrays.equals(c1, c2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package net.runelite.deob.deobfuscators.rename.graph;
|
||||
|
||||
import net.runelite.deob.attributes.code.Instruction;
|
||||
import net.runelite.deob.execution.InstructionContext;
|
||||
|
||||
public class FieldEdge extends Edge
|
||||
{
|
||||
private int id;
|
||||
|
||||
public FieldEdge(Instruction ins, Vertex from, Vertex to, EdgeType type, int id)
|
||||
public FieldEdge(InstructionContext ins, Vertex from, Vertex to, EdgeType type, int id)
|
||||
{
|
||||
super(ins, from, to, type);
|
||||
this.id = id;
|
||||
|
||||
@@ -2,13 +2,13 @@ package net.runelite.deob.deobfuscators.rename.graph;
|
||||
|
||||
import java.util.Objects;
|
||||
import net.runelite.deob.Method;
|
||||
import net.runelite.deob.attributes.code.Instruction;
|
||||
import net.runelite.deob.execution.InstructionContext;
|
||||
|
||||
public class MethodEdge extends Edge
|
||||
{
|
||||
private final Method method;
|
||||
|
||||
public MethodEdge(Instruction i, Vertex from, Vertex to, EdgeType type, Method method)
|
||||
public MethodEdge(InstructionContext i, Vertex from, Vertex to, EdgeType type, Method method)
|
||||
{
|
||||
super(i, from, to, type);
|
||||
this.method = method;
|
||||
|
||||
@@ -36,7 +36,7 @@ public class Vertex
|
||||
private Collection<Vertex> mightBe;
|
||||
private Vertex is;
|
||||
|
||||
private Set<Instruction> edgeFrom = new HashSet<>();
|
||||
//private Set<Instruction> edgeFrom = new HashSet<>();
|
||||
|
||||
public Vertex(Graph graph, Object object)
|
||||
{
|
||||
@@ -110,11 +110,11 @@ public class Vertex
|
||||
Edge c = edges.get(edge);
|
||||
if (c != null)
|
||||
{
|
||||
if (edge.getIns() instanceof SetFieldInstruction && !edgeFrom.contains(edge.getIns()))
|
||||
{
|
||||
edgeFrom.add(edge.getIns());
|
||||
c.increase();
|
||||
}
|
||||
// if (edge.getIns() instanceof SetFieldInstruction && !edgeFrom.contains(edge.getIns()))
|
||||
// {
|
||||
// edgeFrom.add(edge.getIns());
|
||||
// c.increase();
|
||||
// }
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -217,8 +217,8 @@ public class Execution
|
||||
|
||||
for (Method m : methods)
|
||||
{
|
||||
graph.addEdge(new Edge(i, graph.getVertexFor(frame.nonStatic), graph.getVertexFor(m), EdgeType.INVOKE));
|
||||
graph.addEdge(new Edge(i, graph.getVertexFor(m), graph.getVertexFor(frame.nonStatic), EdgeType.INVOKED_FROM));
|
||||
graph.addEdge(new Edge(ctx, graph.getVertexFor(frame.nonStatic), graph.getVertexFor(m), EdgeType.INVOKE));
|
||||
graph.addEdge(new Edge(ctx, graph.getVertexFor(m), graph.getVertexFor(frame.nonStatic), EdgeType.INVOKED_FROM));
|
||||
}
|
||||
}
|
||||
else if (i instanceof FieldInstruction)
|
||||
@@ -228,64 +228,10 @@ public class Execution
|
||||
if (fi.getMyField() == null)
|
||||
return;
|
||||
|
||||
//int id = frame.getMethodCtx().fcount++;
|
||||
EdgeType type = fi instanceof GetFieldInstruction ? EdgeType.GETFIELD : EdgeType.SETFIELD;
|
||||
graph.addEdge(new Edge(i, graph.getVertexFor(frame.nonStatic), graph.getVertexFor(fi.getMyField()), type));
|
||||
graph.addEdge(new Edge(ctx, graph.getVertexFor(frame.nonStatic), graph.getVertexFor(fi.getMyField()), type));
|
||||
EdgeType typeRev = fi instanceof GetFieldInstruction ? EdgeType.GETFIELD_FROM : EdgeType.SETFIELD_FROM;
|
||||
graph.addEdge(new Edge(i, graph.getVertexFor(fi.getMyField()), graph.getVertexFor(frame.nonStatic), typeRev));
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
// if (fi instanceof SetFieldInstruction)
|
||||
// {
|
||||
// StackContext sctx = ctx.getPops().get(0);
|
||||
// if (sctx.getPushed().getInstruction() instanceof GetFieldInstruction)
|
||||
// {
|
||||
// GetFieldInstruction gfi = (GetFieldInstruction) sctx.getPushed().getInstruction();
|
||||
//
|
||||
// if (gfi.getMyField() != null)
|
||||
// {
|
||||
// // XXX dup edges
|
||||
// graph.addEdge(new MethodEdge(i, graph.getVertexFor(fi.getMyField()), graph.getVertexFor(gfi.getMyField()), EdgeType.FIELD_ASSIGNMENT_FIELD, frame.nonStatic));
|
||||
// graph.addEdge(new MethodEdge(i, graph.getVertexFor(gfi.getMyField()), graph.getVertexFor(fi.getMyField()), EdgeType.FIELD_ASSIGNMENT_FIELD_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));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
graph.addEdge(new Edge(ctx, graph.getVertexFor(fi.getMyField()), graph.getVertexFor(frame.nonStatic), typeRev));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user