init of deob

This commit is contained in:
Adam
2014-11-30 20:35:37 -05:00
commit 41681f94a5
30 changed files with 933 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
package info.sigterm.deob.attributes;
import info.sigterm.deob.Attributes;
import java.io.DataInputStream;
import java.io.IOException;
public class Attribute
{
private Attributes attributes;
private AttributeType type;
private int length;
Attribute(Attributes attr, AttributeType type) throws IOException
{
this.attributes = attr;
this.type = type;
DataInputStream is = attr.getStream();
this.length = is.readInt();
}
public Attributes getAttributes()
{
return attributes;
}
public int getLength()
{
return length;
}
}

View File

@@ -0,0 +1,36 @@
package info.sigterm.deob.attributes;
public enum AttributeType
{
CONSTANT_VALUE("ConstantValue", ConstantValue.class),
CODE("Code", Code.class),
UNKNOWN(null, Unknown.class);
private String name;
private Class<? extends Attribute> clazz;
AttributeType(String name, Class<? extends Attribute> clazz)
{
this.name = name;
this.clazz = clazz;
}
public String getName()
{
return name;
}
public Class<? extends Attribute> getAttributeClass()
{
return clazz;
}
public static AttributeType findType(String name)
{
for (AttributeType t : AttributeType.values())
if (t.getName() != null && t.getName().equals(name))
return t;
return UNKNOWN;
}
}

View File

@@ -0,0 +1,31 @@
package info.sigterm.deob.attributes;
import info.sigterm.deob.Attributes;
import info.sigterm.deob.attributes.code.Exceptions;
import java.io.DataInputStream;
import java.io.IOException;
public class Code extends Attribute
{
private int maxStack;
private int maxLocals;
private Exceptions exceptions;
private Attributes attributes;
public Code(Attributes attributes) throws IOException
{
super(attributes, AttributeType.CODE);
DataInputStream is = attributes.getStream();
maxStack = is.readUnsignedShort();
maxLocals = is.readUnsignedShort();
int codeLen = is.readInt();
is.skip(codeLen);
exceptions = new Exceptions(this);
attributes = new Attributes(this);
}
}

View File

@@ -0,0 +1,19 @@
package info.sigterm.deob.attributes;
import info.sigterm.deob.Attributes;
import java.io.DataInputStream;
import java.io.IOException;
public class ConstantValue extends Attribute
{
private int constantVlaueIndex;
public ConstantValue(Attributes attributes) throws IOException
{
super(attributes, AttributeType.CONSTANT_VALUE);
DataInputStream is = attributes.getStream();
constantVlaueIndex = is.readUnsignedShort();
}
}

View File

@@ -0,0 +1,34 @@
package info.sigterm.deob.attributes;
import info.sigterm.deob.Attributes;
import java.io.DataInputStream;
import java.io.IOException;
public class Unknown extends Attribute
{
private byte[] data;
public Unknown(Attributes attributes) throws IOException
{
super(attributes, AttributeType.UNKNOWN);
int len = this.getLength();
DataInputStream is = attributes.getStream();
data = new byte[len];
int read = 0;
while (read < len)
{
int i = is.read(data, read, len - read);
if (i < 0)
throw new IOException("EOF");
read += i;
}
assert read == len;
}
}

View File

@@ -0,0 +1,26 @@
package info.sigterm.deob.attributes.code;
import java.io.DataInputStream;
import java.io.IOException;
class Exception
{
private Exceptions exceptions;
private int startPc;
private int endPc;
private int handlerPc;
private int catchType;
Exception(Exceptions exceptions) throws IOException
{
this.exceptions = exceptions;
DataInputStream is = exceptions.getCode().getAttributes().getStream();
startPc = is.readUnsignedShort();
endPc = is.readUnsignedShort();
handlerPc = is.readUnsignedShort();
catchType = is.readUnsignedShort();
}
}

View File

@@ -0,0 +1,30 @@
package info.sigterm.deob.attributes.code;
import info.sigterm.deob.attributes.Code;
import java.io.DataInputStream;
import java.io.IOException;
public class Exceptions
{
private Code code;
private Exception[] exceptions;
public Exceptions(Code code) throws IOException
{
this.code = code;
DataInputStream is = code.getAttributes().getStream();
int count = is.readUnsignedShort();
exceptions = new Exception[count];
for (int i = 0; i < count; ++i)
exceptions[i] = new Exception(this);
}
public Code getCode()
{
return code;
}
}