Executor work

This commit is contained in:
Adam
2015-01-26 00:40:54 -05:00
parent a998491133
commit 55dca4fa9b
148 changed files with 512 additions and 194 deletions

View File

@@ -20,4 +20,9 @@ public class ArrayInstance extends ObjectInstanceBase
{
return array[idx];
}
public int getLength()
{
return array.length;
}
}

View File

@@ -1,5 +1,6 @@
package info.sigterm.deob.execution;
import info.sigterm.deob.ClassFile;
import info.sigterm.deob.ClassGroup;
import info.sigterm.deob.Method;
@@ -15,10 +16,13 @@ public class Execution
this.group = group;
}
public void run(Method method, Object... args)
public void run(ClassFile cf, Method method, Object... args)
{
Path p = new Path(this);
p.invoke(method, args);
ClassInstance instance = p.getClassInstance(cf);
ObjectInstance object = p.createObject(instance);
p.invoke(method, object);
}
public void addPath(Path p)

View File

@@ -9,7 +9,7 @@ public class Frame
{
private Path path;
private Method method;
private boolean executing = true;
boolean executing = true;
private int pc;
private Stack stack;
private Variables variables;
@@ -48,7 +48,16 @@ public class Frame
int oldPc = pc;
Instruction i = ins.findInstruction(pc);
i.execute(this);
try
{
i.execute(this);
}
catch (Throwable ex)
{
System.err.println("Error executing instruction in " + method.getName() + " " + method.getDescriptor() + " in class " + method.getMethods().getClassFile().getName() + " at pc " + pc);
throw ex;
}
if (oldPc == pc)
{

View File

@@ -2,6 +2,7 @@ package info.sigterm.deob.execution;
import info.sigterm.deob.ClassFile;
import info.sigterm.deob.Method;
import info.sigterm.deob.attributes.code.Instruction;
import java.util.ArrayList;
@@ -72,7 +73,7 @@ public class Path
return other;
}
public void invoke(Method method, Object[] args)
public void invoke(Method method, Object... args)
{
Frame f = new Frame(this, method);
Variables vars = f.getVariables();
@@ -81,4 +82,24 @@ public class Path
frames.push(f);
f.execute();
}
public void returnFrame(Instruction i, Object value)
{
returnFrame();
Frame prevFrame = getCurrentFrame();
prevFrame.getStack().push(i, value);
}
public void returnFrame()
{
Frame currentFrame = frames.pop();
currentFrame.executing = false;
}
public void throwException(ObjectInstance exception)
{
System.out.println("throw " + exception);
//XXX
}
}

View File

@@ -1,21 +1,28 @@
package info.sigterm.deob.execution;
import info.sigterm.deob.attributes.code.Instruction;
public class Stack
{
private int size;
private Object[] stack;
private Instruction[] ins;
public Stack(int sz)
{
stack = new Object[sz];
ins = new Instruction[sz];
}
public void push(Object obj)
public void push(Instruction i, Object obj)
{
if (size == stack.length)
throw new RuntimeException("Stack overflow");
stack[size++] = obj;
stack[size] = obj;
ins[size] = i;
++size;
}
public Object pop()

View File

@@ -13,7 +13,8 @@ public class StaticFieldInstance
{
this.clazz = clazz;
this.field = field;
this.value = value.getValue().getObject();
if (value != null)
this.value = value.getValue().getObject();
}
public Field getField()