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,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

@@ -0,0 +1,106 @@
package info.sigterm.deob.attributes;
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;
import java.io.IOException;
import java.lang.reflect.Constructor;
public class Attributes
{
private ClassFile classFile;
private Field field;
private Method method;
private Code code;
private int count;
private Attribute[] attributes;
public Attributes(ClassFile cf) throws IOException
{
classFile = cf;
load();
}
public Attributes(Field f) throws IOException
{
field = f;
load();
}
public Attributes(Method m) throws IOException
{
method = m;
load();
}
public Attributes(Code c) throws IOException
{
code = c;
load();
}
public Attribute findType(AttributeType type)
{
for (Attribute a : attributes)
if (a.getType() == type)
return a;
return null;
}
public ClassFile getClassFile()
{
if (classFile != null)
return classFile;
if (field != null)
return field.getFields().getClassFile();
if (method != null)
return method.getMethods().getClassFile();
if (code != null)
return code.getAttributes().getClassFile();
return null;
}
public DataInputStream getStream()
{
return getClassFile().getStream();
}
private void load() throws IOException
{
DataInputStream is = getStream();
count = is.readUnsignedShort();
attributes = new Attribute[count];
for (int i = 0; i < count; ++i)
{
int nameIndex = is.readUnsignedShort();
UTF8 name = (UTF8) getClassFile().getPool().getEntry(nameIndex);
AttributeType type = AttributeType.findType(name.getValue());
try
{
Constructor<? extends Attribute> con = type.getAttributeClass().getConstructor(new Class[] { Attributes.class });
Attribute attr = con.newInstance(this);
attributes[i] = attr;
}
catch (Exception ex)
{
throw new IOException(ex);
}
}
}
}

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;
}
}