Some thinking about execution

This commit is contained in:
Adam
2014-12-01 14:37:19 -05:00
parent 0d50085e03
commit 228f650b6c
14 changed files with 131 additions and 18 deletions

View File

@@ -1,5 +1,6 @@
package info.sigterm.deob;
import info.sigterm.deob.attributes.Attributes;
import info.sigterm.deob.pool.Class;
import info.sigterm.deob.pool.UTF8;
@@ -81,7 +82,6 @@ public class ClassFile
if (other == null)
return; // inherits from a class not in my group
assert other != null;
assert other != this;
this.parent = other;

View File

@@ -1,9 +1,11 @@
package info.sigterm.deob;
import info.sigterm.deob.attributes.Attributes;
import java.io.DataInputStream;
import java.io.IOException;
class Field
public class Field
{
private Fields fields;

View File

@@ -1,9 +1,13 @@
package info.sigterm.deob;
import info.sigterm.deob.attributes.AttributeType;
import info.sigterm.deob.attributes.Attributes;
import info.sigterm.deob.attributes.Code;
import java.io.DataInputStream;
import java.io.IOException;
class Method
public class Method
{
private Methods methods;
@@ -28,4 +32,9 @@ class Method
{
return methods;
}
public Code getCode()
{
return (Code) attributes.findType(AttributeType.CODE);
}
}

View File

@@ -1,7 +1,5 @@
package info.sigterm.deob.attributes;
import info.sigterm.deob.Attributes;
import java.io.DataInputStream;
import java.io.IOException;
@@ -25,6 +23,11 @@ public class Attribute
return attributes;
}
public AttributeType getType()
{
return type;
}
public int getLength()
{
return length;

View File

@@ -1,8 +1,8 @@
package info.sigterm.deob;
package info.sigterm.deob.attributes;
import info.sigterm.deob.attributes.Attribute;
import info.sigterm.deob.attributes.AttributeType;
import info.sigterm.deob.attributes.Code;
import info.sigterm.deob.ClassFile;
import info.sigterm.deob.Field;
import info.sigterm.deob.Method;
import info.sigterm.deob.pool.UTF8;
import java.io.DataInputStream;
@@ -19,21 +19,21 @@ public class Attributes
private int count;
private Attribute[] attributes;
Attributes(ClassFile cf) throws IOException
public Attributes(ClassFile cf) throws IOException
{
classFile = cf;
load();
}
Attributes(Field f) throws IOException
public Attributes(Field f) throws IOException
{
field = f;
load();
}
Attributes(Method m) throws IOException
public Attributes(Method m) throws IOException
{
method = m;
@@ -47,6 +47,14 @@ public class Attributes
load();
}
public Attribute findType(AttributeType type)
{
for (Attribute a : attributes)
if (a.getType() == type)
return a;
return null;
}
public ClassFile getClassFile()
{
if (classFile != null)

View File

@@ -1,6 +1,5 @@
package info.sigterm.deob.attributes;
import info.sigterm.deob.Attributes;
import info.sigterm.deob.attributes.code.Exceptions;
import info.sigterm.deob.attributes.code.Instructions;
@@ -29,4 +28,14 @@ public class Code extends Attribute
exceptions = new Exceptions(this);
attributes = new Attributes(this);
}
public int getMaxStack()
{
return getMaxStack();
}
public int getMaxLocals()
{
return maxLocals;
}
}

View File

@@ -1,7 +1,5 @@
package info.sigterm.deob.attributes;
import info.sigterm.deob.Attributes;
import java.io.DataInputStream;
import java.io.IOException;

View File

@@ -1,7 +1,5 @@
package info.sigterm.deob.attributes;
import info.sigterm.deob.Attributes;
import java.io.DataInputStream;
import java.io.IOException;

View File

@@ -1,5 +1,7 @@
package info.sigterm.deob.attributes.code;
import info.sigterm.deob.execution.Execution;
import java.util.ArrayList;
public class Instruction
@@ -43,4 +45,8 @@ public class Instruction
public void buildJumpGraph()
{
}
public void execute(Execution e)
{
}
}

View File

@@ -19,5 +19,4 @@ public class InvokeStatic extends Instruction
index = is.readUnsignedShort();
length += 2;
}
}

View File

@@ -0,0 +1,19 @@
package info.sigterm.deob.execution;
import info.sigterm.deob.ClassGroup;
import info.sigterm.deob.pool.Method;
public class Execution
{
private ClassGroup group;
private java.util.Stack<Frame> frames = new java.util.Stack<Frame>();
public Execution(ClassGroup group)
{
this.group = group;
}
public void run(Method method, Object... args)
{
}
}

View File

@@ -0,0 +1,23 @@
package info.sigterm.deob.execution;
import info.sigterm.deob.Method;
import info.sigterm.deob.attributes.Code;
public class Frame
{
private Execution execution;
private Method method;
private Stack stack;
private Variables variables;
public Frame(Execution execution, Method method)
{
Code code = method.getCode();
this.execution = execution;
this.method = method;
stack = new Stack(code.getMaxStack());
variables = new Variables(code.getMaxLocals());
}
}

View File

@@ -0,0 +1,28 @@
package info.sigterm.deob.execution;
public class Stack
{
private int size;
private Object[] stack;
public Stack(int sz)
{
stack = new Object[sz];
}
public void push(Object obj)
{
if (size == stack.length)
throw new RuntimeException("Stack overflow");
stack[size++] = obj;
}
public Object pop()
{
if (size <= 0)
throw new RuntimeException("Stack underflow");
return stack[--size];
}
}

View File

@@ -0,0 +1,11 @@
package info.sigterm.deob.execution;
public class Variables
{
private Object variables;
public Variables(int sz)
{
variables = new Object[sz];
}
}