Some fixes.

This commit is contained in:
Adam
2015-12-12 12:30:12 -05:00
parent 24aecb8828
commit 540c1ac5af
7 changed files with 50 additions and 47 deletions

View File

@@ -56,7 +56,7 @@ public class Method
@Override
public String toString()
{
return this.getMethods().getClassFile().getName() + "." + this.name + this.arguments;
return (this.isStatic() ? "static " : "") + this.getMethods().getClassFile().getName() + "." + this.name + this.arguments;
}
public void write(DataOutputStream out) throws IOException

View File

@@ -105,7 +105,7 @@ public class InvokeStatic extends Instruction implements InvokeInstruction
// add possible method call to execution
Execution execution = frame.getExecution();
Frame f = execution.invoke(ins, method);
execution.invoke(ins, method);
}
frame.addInstructionContext(ins);

View File

@@ -16,6 +16,7 @@ import net.runelite.deob.pool.NameAndType;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.runelite.deob.Method;
public class PutField extends Instruction implements SetFieldInstruction
{
@@ -26,6 +27,13 @@ public class PutField extends Instruction implements SetFieldInstruction
{
super(instructions, type, pc);
}
@Override
public String toString()
{
Method m = this.getInstructions().getCode().getAttributes().getMethod();
return "putfield " + myField + " in " + m;
}
@Override
public void load(DataInputStream is) throws IOException

View File

@@ -16,6 +16,7 @@ import net.runelite.deob.pool.NameAndType;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.runelite.deob.Method;
public class PutStatic extends Instruction implements SetFieldInstruction
{
@@ -27,6 +28,13 @@ public class PutStatic extends Instruction implements SetFieldInstruction
super(instructions, type, pc);
}
@Override
public String toString()
{
Method m = this.getInstructions().getCode().getAttributes().getMethod();
return "putstatic " + myField + " in " + m;
}
@Override
public void load(DataInputStream is) throws IOException
{

View File

@@ -31,7 +31,7 @@ public class Vertex
private final Object object;
private VertexType type;
private final Map<Edge, Edge> edges = new HashMap<>();
private final Set<Edge> edges = new HashSet<>();
private Collection<Vertex> mightBe;
private Vertex is;
@@ -107,8 +107,8 @@ public class Vertex
public void addEdge(Edge edge)
{
Edge c = edges.get(edge);
if (c != null)
if (edges.contains(edge))
//if (c != null)
{
// if (edge.getIns() instanceof SetFieldInstruction && !edgeFrom.contains(edge.getIns()))
// {
@@ -118,12 +118,13 @@ public class Vertex
return;
}
edges.put(edge, edge);
edges.add(edge);
//edges.put(edge, edge);
}
public Set<Edge> getEdges()
{
return edges.keySet();
return edges;
}
public void merge(Collection<Vertex> maybe)
@@ -295,21 +296,21 @@ public class Vertex
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;
}
}
// 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
@@ -424,7 +425,7 @@ public class Vertex
private int edgesOf(EdgeType type)
{
int t = 0;
for (Edge e : this.edges.values())
for (Edge e : this.edges)
if (e.getType() == type)
++t;
return t;
@@ -432,6 +433,6 @@ public class Vertex
private int solvedEdgesOfType(EdgeType type)
{
return (int) edges.values().stream().filter(e -> e.getType() == type).filter(e -> e.getTo().getOther() != null).count();
return (int) edges.stream().filter(e -> e.getType() == type).filter(e -> e.getTo().getOther() != null).count();
}
}

View File

@@ -37,7 +37,6 @@ public class Execution
public Set<Instruction> executed = new HashSet<>(); // executed instructions
private MultiValueMap<InstructionContext, Method> invokes = new MultiValueMap<>();
public MultiValueMap<Instruction, InstructionContext> contexts = new MultiValueMap<>();
private Map<Method, MethodContext> methodContexts = new HashMap<>();
private boolean buildGraph; // if true the frame graph is built and execution hasJumped also compares previous instructions
private Graph graph = new Graph();
@@ -91,6 +90,8 @@ public class Execution
private boolean hasInvoked(InstructionContext from, Method to)
{
// this is wrong because the called of the method of from
// might be different, for building graph
Collection<Method> methods = invokes.getCollection(from);
if (methods != null && methods.contains(to))
return true;
@@ -150,17 +151,6 @@ 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(this);
methodContexts.put(m, c);
return c;
}
public boolean isBuildGraph()
{

View File

@@ -27,8 +27,7 @@ public class Frame
private List<InstructionContext> instructions = new ArrayList<>(); // instructions executed in this frame
private MethodContext ctx;
protected Method nonStatic; // next non static method up the stack
public Field lastField;
public Frame staticReturn;
private Frame caller;
public Frame(Execution execution, Method method)
{
@@ -39,7 +38,10 @@ public class Frame
stack = new Stack(code.getMaxStack());
variables = new Variables(code.getMaxLocals());
ctx = execution.getMethodContext(method);
// don't cache method contexts per execution
// need to allow the same method to execute multiple times
// when called from multiple places to allow graph building
ctx = new MethodContext(execution);
nonStatic = method;
}
@@ -70,6 +72,7 @@ public class Frame
{
this.nonStatic = ctx.getFrame().nonStatic;
}
caller = ctx.getFrame();
// initialize LVT. the last argument is popped first, and is at arguments[0]
List<StackContext> pops = ctx.getPops();
@@ -105,8 +108,7 @@ public class Frame
this.variables = new Variables(other.variables);
this.ctx = other.ctx;
this.nonStatic = other.nonStatic;
this.lastField = other.lastField;
this.staticReturn = other.staticReturn;
this.caller = other.caller;
}
public Frame dup()
@@ -223,12 +225,6 @@ public class Frame
break;
execution.buildGraph(this, oldCur, ictx);
if (oldCur instanceof SetFieldInstruction)
{
SetFieldInstruction sfi = (SetFieldInstruction) oldCur;
if (sfi.getMyField() != null)
this.lastField = sfi.getMyField();
}
if (oldCur == cur)
{