Allow pool to be dynamically rebuilt

This commit is contained in:
Adam
2015-05-09 17:00:30 -04:00
parent 0d21d49d2d
commit 4af719032d
45 changed files with 597 additions and 333 deletions

View File

@@ -10,7 +10,6 @@ public abstract class Attribute
private Attributes attributes;
private AttributeType type;
private int length;
public int nameIndex;
Attribute(Attributes attr, AttributeType type) throws IOException
{
@@ -21,7 +20,7 @@ public abstract class Attribute
this.length = is.readInt();
}
public void write(DataOutputStream out) throws IOException
public final void write(DataOutputStream out) throws IOException
{
ByteArrayOutputStream bout = new ByteArrayOutputStream();
writeAttr(new DataOutputStream(bout));

View File

@@ -8,7 +8,6 @@ public enum AttributeType
private String name;
private Class<? extends Attribute> clazz;
public int nameIndex;
AttributeType(String name, Class<? extends Attribute> clazz)
{

View File

@@ -9,6 +9,8 @@ import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;
public class Attributes
{
@@ -17,8 +19,7 @@ public class Attributes
private Method method;
private Code code;
private int count;
private Attribute[] attributes;
private List<Attribute> attributes = new ArrayList<>();
public Attributes(ClassFile cf) throws IOException
{
@@ -87,22 +88,20 @@ public class Attributes
{
DataInputStream is = getStream();
count = is.readUnsignedShort();
attributes = new Attribute[count];
int count = is.readUnsignedShort();
for (int i = 0; i < count; ++i)
{
int nameIndex = is.readUnsignedShort();
UTF8 name = (UTF8) getClassFile().getPool().getEntry(nameIndex);
String name = this.getClassFile().getPool().getUTF8(is.readUnsignedShort());
AttributeType type = AttributeType.findType(name.getValue());
AttributeType type = AttributeType.findType(name);
try
{
Constructor<? extends Attribute> con = type.getAttributeClass().getConstructor(new Class[] { Attributes.class });
Attribute attr = con.newInstance(this);
attr.nameIndex = nameIndex;
attributes[i] = attr;
if (type != AttributeType.UNKNOWN)
attributes.add(attr);
}
catch (Exception ex)
{
@@ -113,10 +112,10 @@ public class Attributes
public void write(DataOutputStream out) throws IOException
{
out.writeShort(count);
out.writeShort(attributes.size());
for (Attribute a : attributes)
{
out.writeShort(a.nameIndex);
out.writeShort(this.getClassFile().getPool().makeUTF8(a.getType().getName()));
a.write(out);
}
}

View File

@@ -29,6 +29,17 @@ public class Code extends Attribute
exceptions = new Exceptions(this);
this.attributes = new Attributes(this);
}
@Override
public void writeAttr(DataOutputStream out) throws IOException
{
out.writeShort(maxStack);
out.writeShort(maxLocals);
instructions.write(out);
exceptions.write(out);
attributes.write(out);
}
public int getMaxStack()
{
@@ -59,15 +70,4 @@ public class Code extends Attribute
{
instructions.buildCallGraph();
}
@Override
public void writeAttr(DataOutputStream out) throws IOException
{
out.writeShort(maxStack);
out.writeShort(maxLocals);
instructions.write(out);
exceptions.write(out);
attributes.write(out);
}
}

View File

@@ -8,24 +8,24 @@ import java.io.IOException;
public class ConstantValue extends Attribute
{
private int constantValueIndex;
private PoolEntry value;
public ConstantValue(Attributes attributes) throws IOException
{
super(attributes, AttributeType.CONSTANT_VALUE);
DataInputStream is = attributes.getStream();
constantValueIndex = is.readUnsignedShort();
value = this.getAttributes().getClassFile().getPool().getEntry(is.readUnsignedShort());
}
public PoolEntry getValue()
{
return this.getAttributes().getClassFile().getPool().getEntry(constantValueIndex);
return value;
}
@Override
public void writeAttr(DataOutputStream out) throws IOException
{
out.writeShort(constantValueIndex);
out.writeShort(this.getAttributes().getClassFile().getPool().make(value));
}
}

View File

@@ -1,6 +1,7 @@
package info.sigterm.deob.attributes.code;
import info.sigterm.deob.ConstantPool;
import info.sigterm.deob.pool.Class;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@@ -13,26 +14,29 @@ public class Exception
private int startPc;
private int endPc;
private int handlerPc;
private int catchType;
private Class cacheType;
public Exception(Exceptions exceptions) throws IOException
{
this.exceptions = exceptions;
DataInputStream is = exceptions.getCode().getAttributes().getStream();
ConstantPool pool = exceptions.getCode().getAttributes().getClassFile().getPool();
startPc = is.readUnsignedShort();
endPc = is.readUnsignedShort();
handlerPc = is.readUnsignedShort();
catchType = is.readUnsignedShort();
cacheType = pool.getClass(is.readUnsignedShort());
}
public void write(DataOutputStream out) throws IOException
{
ConstantPool pool = exceptions.getCode().getAttributes().getClassFile().getPool();
out.writeShort(startPc);
out.writeShort(endPc);
out.writeShort(handlerPc);
out.writeShort(catchType);
out.writeShort(cacheType == null ? 0 : pool.make(cacheType));
}
public Exceptions getExceptions()

View File

@@ -1,18 +1,18 @@
package info.sigterm.deob.attributes.code;
import info.sigterm.deob.attributes.Code;
import info.sigterm.deob.execution.ObjectInstance;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class Exceptions
{
private Code code;
private Exception[] exceptions;
private List<Exception> exceptions = new ArrayList<Exception>();
public Exceptions(Code code) throws IOException
{
@@ -21,15 +21,14 @@ public class Exceptions
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);
exceptions.add(new Exception(this));
}
public void write(DataOutputStream out) throws IOException
{
out.writeShort(exceptions.length);
out.writeShort(exceptions.size());
for (Exception e : exceptions)
e.write(out);
}

View File

@@ -1,5 +1,6 @@
package info.sigterm.deob.attributes.code;
import info.sigterm.deob.ConstantPool;
import info.sigterm.deob.execution.Frame;
import java.io.DataOutputStream;
@@ -33,6 +34,11 @@ public abstract class Instruction
{
return instructions;
}
public ConstantPool getPool()
{
return instructions.getCode().getAttributes().getClassFile().getPool();
}
public int getPc()
{

View File

@@ -5,7 +5,6 @@ import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.execution.ArrayInstance;
import info.sigterm.deob.execution.Frame;
import info.sigterm.deob.execution.ObjectInstance;
import info.sigterm.deob.execution.Stack;
public class AAStore extends Instruction

View File

@@ -1,6 +1,5 @@
package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.Method;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;

View File

@@ -15,14 +15,14 @@ import java.io.IOException;
public class ANewArray extends Instruction
{
private int index;
private Class clazz;
public ANewArray(Instructions instructions, InstructionType type, int pc) throws IOException
{
super(instructions, type, pc);
DataInputStream is = instructions.getCode().getAttributes().getStream();
index = is.readUnsignedShort();
clazz = this.getPool().getClass(is.readUnsignedShort());
length += 2;
}
@@ -30,14 +30,14 @@ public class ANewArray extends Instruction
public void write(DataOutputStream out, int pc) throws IOException
{
super.write(out, pc);
out.writeShort(index);
out.writeShort(this.getPool().make(clazz));
}
@Override
public void execute(Frame frame)
{
ClassFile thisClass = this.getInstructions().getCode().getAttributes().getClassFile();
Class clazz = (Class) thisClass.getPool().getEntry(index);
int count = (int) frame.getStack().pop();

View File

@@ -15,14 +15,14 @@ import java.io.IOException;
public class CheckCast extends Instruction
{
private int index;
private Class clazz;
public CheckCast(Instructions instructions, InstructionType type, int pc) throws IOException
{
super(instructions, type, pc);
DataInputStream is = instructions.getCode().getAttributes().getStream();
index = is.readUnsignedShort();
clazz = this.getPool().getClass(is.readUnsignedShort());
length += 2;
}
@@ -30,7 +30,7 @@ public class CheckCast extends Instruction
public void write(DataOutputStream out, int pc) throws IOException
{
super.write(out, pc);
out.writeShort(index);
out.writeShort(this.getPool().make(clazz));
}
@Override
@@ -39,7 +39,6 @@ public class CheckCast extends Instruction
ClassFile thisClass = this.getInstructions().getCode().getAttributes().getClassFile();
ConstantPool pool = thisClass.getPool();
Class clazz = (Class) pool.getEntry(index);
ObjectInstance obj = (ObjectInstance) e.getStack().pop();
if (obj == null)

View File

@@ -17,14 +17,14 @@ import java.io.IOException;
public class GetField extends Instruction
{
private int index;
private Field field;
public GetField(Instructions instructions, InstructionType type, int pc) throws IOException
{
super(instructions, type, pc);
DataInputStream is = instructions.getCode().getAttributes().getStream();
index = is.readUnsignedShort();
field = this.getPool().getField(is.readUnsignedShort());
length += 2;
}
@@ -32,7 +32,7 @@ public class GetField extends Instruction
public void write(DataOutputStream out, int pc) throws IOException
{
super.write(out, pc);
out.writeShort(index);
out.writeShort(this.getPool().make(field));
}
@Override
@@ -43,9 +43,8 @@ public class GetField extends Instruction
ClassFile thisClass = this.getInstructions().getCode().getAttributes().getClassFile();
ConstantPool pool = thisClass.getPool();
Field entry = (Field) pool.getEntry(index);
NameAndType nat = entry.getNameAndType();
NameAndType nat = field.getNameAndType();
if (object == null)
{

View File

@@ -18,14 +18,14 @@ import java.io.IOException;
public class GetStatic extends Instruction
{
private int index;
private Field field;
public GetStatic(Instructions instructions, InstructionType type, int pc) throws IOException
{
super(instructions, type, pc);
DataInputStream is = instructions.getCode().getAttributes().getStream();
index = is.readUnsignedShort();
field = this.getPool().getField(is.readUnsignedShort());
length += 2;
}
@@ -33,7 +33,7 @@ public class GetStatic extends Instruction
public void write(DataOutputStream out, int pc) throws IOException
{
super.write(out, pc);
out.writeShort(index);
out.writeShort(this.getPool().make(field));
}
@Override
@@ -41,11 +41,8 @@ public class GetStatic extends Instruction
{
ClassFile thisClass = this.getInstructions().getCode().getAttributes().getClassFile();
ConstantPool pool = thisClass.getPool();
Field entry = (Field) pool.getEntry(index);
Class clazz = entry.getClassEntry();
NameAndType nat = entry.getNameAndType();
Class clazz = field.getClassEntry();
NameAndType nat = field.getNameAndType();
ClassFile cf = thisClass.getGroup().findClass(clazz.getName());
if (cf == null)
@@ -65,11 +62,8 @@ public class GetStatic extends Instruction
@Override
public void buildInstructionGraph()
{
ConstantPool pool = this.getInstructions().getCode().getAttributes().getClassFile().getPool();
Field entry = (Field) pool.getEntry(index);
Class clazz = entry.getClassEntry();
NameAndType nat = entry.getNameAndType();
Class clazz = field.getClassEntry();
NameAndType nat = field.getNameAndType();
ClassFile cf = this.getInstructions().getCode().getAttributes().getClassFile().getGroup().findClass(clazz.getName());
if (cf == null)

View File

@@ -15,14 +15,14 @@ import java.io.IOException;
public class InstanceOf extends Instruction
{
private int index;
private Class clazz;
public InstanceOf(Instructions instructions, InstructionType type, int pc) throws IOException
{
super(instructions, type, pc);
DataInputStream is = instructions.getCode().getAttributes().getStream();
index = is.readUnsignedShort();
clazz = this.getPool().getClass(is.readUnsignedShort());
length += 2;
}
@@ -30,16 +30,13 @@ public class InstanceOf extends Instruction
public void write(DataOutputStream out, int pc) throws IOException
{
super.write(out, pc);
out.writeShort(index);
out.writeShort(this.getPool().make(clazz));
}
@Override
public void execute(Frame e)
{
ClassFile thisClass = this.getInstructions().getCode().getAttributes().getClassFile();
ConstantPool pool = thisClass.getPool();
Class clazz = (Class) pool.getEntry(index);
ObjectInstanceBase obj = (ObjectInstanceBase) e.getStack().pop();
if (obj == null)

View File

@@ -18,7 +18,7 @@ import java.io.IOException;
public class InvokeInterface extends Instruction
{
private int index;
private InterfaceMethod method;
private int count;
public InvokeInterface(Instructions instructions, InstructionType type, int pc) throws IOException
@@ -26,7 +26,7 @@ public class InvokeInterface extends Instruction
super(instructions, type, pc);
DataInputStream is = instructions.getCode().getAttributes().getStream();
index = is.readUnsignedShort();
method = this.getPool().getInterfaceMethod(is.readUnsignedShort());
count = is.readUnsignedByte();
is.skip(1);
length += 4;
@@ -36,19 +36,14 @@ public class InvokeInterface extends Instruction
public void write(DataOutputStream out, int pc) throws IOException
{
super.write(out, pc);
out.writeShort(index);
out.writeShort(this.getPool().make(method));
out.writeByte(count);
out.writeByte(0);
}
@Override
public void buildCallGraph()
{
ClassFile thisClass = this.getInstructions().getCode().getAttributes().getClassFile();
ConstantPool pool = thisClass.getPool();
InterfaceMethod method = (InterfaceMethod) pool.getEntry(index);
{
info.sigterm.deob.pool.Class clazz = method.getClassEntry();
NameAndType nat = method.getNameAndType();
@@ -64,12 +59,7 @@ public class InvokeInterface extends Instruction
@Override
public void execute(Frame e)
{
ClassFile thisClass = this.getInstructions().getCode().getAttributes().getClassFile();
ConstantPool pool = thisClass.getPool();
InterfaceMethod method = (InterfaceMethod) pool.getEntry(index);
{
ObjectInstance object = (ObjectInstance) e.getStack().pop();
ClassInstance objectType = object.getType();

View File

@@ -10,7 +10,6 @@ import info.sigterm.deob.execution.Frame;
import info.sigterm.deob.execution.ObjectInstance;
import info.sigterm.deob.pool.Method;
import info.sigterm.deob.pool.NameAndType;
import info.sigterm.deob.pool.PoolEntry;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@@ -18,14 +17,14 @@ import java.io.IOException;
public class InvokeSpecial extends Instruction
{
private int index;
private Method method;
public InvokeSpecial(Instructions instructions, InstructionType type, int pc) throws IOException
{
super(instructions, type, pc);
DataInputStream is = instructions.getCode().getAttributes().getStream();
index = is.readUnsignedShort();
method = this.getPool().getMethod(is.readUnsignedShort());
length += 2;
}
@@ -33,17 +32,12 @@ public class InvokeSpecial extends Instruction
public void write(DataOutputStream out, int pc) throws IOException
{
super.write(out, pc);
out.writeShort(index);
out.writeShort(this.getPool().make(method));
}
@Override
public void buildCallGraph()
{
ClassFile thisClass = this.getInstructions().getCode().getAttributes().getClassFile();
ConstantPool pool = thisClass.getPool();
Method method = (Method) pool.getEntry(index);
info.sigterm.deob.pool.Class clazz = method.getClassEntry();
NameAndType nat = method.getNameAndType();
@@ -61,10 +55,6 @@ public class InvokeSpecial extends Instruction
@Override
public void execute(Frame e)
{
ClassFile thisClass = this.getInstructions().getCode().getAttributes().getClassFile();
ConstantPool pool = thisClass.getPool();
Method method = (Method) pool.getEntry(index);
int count = method.getNameAndType().getNumberOfArgs();
ObjectInstance object = (ObjectInstance) e.getStack().pop();
@@ -89,10 +79,7 @@ public class InvokeSpecial extends Instruction
@Override
public String getDesc(Frame frame)
{
ClassFile thisClass = this.getInstructions().getCode().getAttributes().getClassFile();
Method method = (Method) thisClass.getPool().getEntry(index);
{
return "invokespecial " + method.getNameAndType().getDescriptor() + " on " + method.getClassEntry().getName();
}
}

View File

@@ -15,14 +15,14 @@ import java.io.IOException;
public class InvokeStatic extends Instruction
{
private int index;
private Method method;
public InvokeStatic(Instructions instructions, InstructionType type, int pc) throws IOException
{
super(instructions, type, pc);
DataInputStream is = instructions.getCode().getAttributes().getStream();
index = is.readUnsignedShort();
method = this.getPool().getMethod(is.readUnsignedShort());
length += 2;
}
@@ -30,17 +30,12 @@ public class InvokeStatic extends Instruction
public void write(DataOutputStream out, int pc) throws IOException
{
super.write(out, pc);
out.writeShort(index);
out.writeShort(this.getPool().make(method));
}
@Override
public void buildCallGraph()
{
ClassFile thisClass = this.getInstructions().getCode().getAttributes().getClassFile();
ConstantPool pool = thisClass.getPool();
Method method = (Method) pool.getEntry(index);
{
info.sigterm.deob.pool.Class clazz = method.getClassEntry();
NameAndType nat = method.getNameAndType();
@@ -60,8 +55,6 @@ public class InvokeStatic extends Instruction
{
ClassFile thisClass = this.getInstructions().getCode().getAttributes().getClassFile();
ConstantPool pool = thisClass.getPool();
Method method = (Method) pool.getEntry(index);
info.sigterm.deob.pool.Class clazz = method.getClassEntry();
ClassFile otherClass = thisClass.getGroup().findClass(clazz.getName());

View File

@@ -17,14 +17,14 @@ import java.io.IOException;
public class InvokeVirtual extends Instruction
{
private int index;
private Method method;
public InvokeVirtual(Instructions instructions, InstructionType type, int pc) throws IOException
{
super(instructions, type, pc);
DataInputStream is = instructions.getCode().getAttributes().getStream();
index = is.readUnsignedShort();
method = this.getPool().getMethod(is.readUnsignedShort());
length += 2;
}
@@ -32,17 +32,12 @@ public class InvokeVirtual extends Instruction
public void write(DataOutputStream out, int pc) throws IOException
{
super.write(out, pc);
out.writeShort(index);
out.writeShort(this.getPool().make(method));
}
@Override
public void buildCallGraph()
{
ClassFile thisClass = this.getInstructions().getCode().getAttributes().getClassFile();
ConstantPool pool = thisClass.getPool();
Method method = (Method) pool.getEntry(index);
{
info.sigterm.deob.pool.Class clazz = method.getClassEntry();
NameAndType nat = method.getNameAndType();
@@ -61,10 +56,6 @@ public class InvokeVirtual extends Instruction
@Override
public void execute(Frame e)
{
ClassFile thisClass = this.getInstructions().getCode().getAttributes().getClassFile();
ConstantPool pool = thisClass.getPool();
Method method = (Method) pool.getEntry(index);
int count = method.getNameAndType().getNumberOfArgs();
Object[] args = new Object[count + 1];

View File

@@ -13,14 +13,14 @@ import java.io.IOException;
public class LDC extends Instruction
{
private int index;
private Object value;
public LDC(Instructions instructions, InstructionType type, int pc) throws IOException
{
super(instructions, type, pc);
DataInputStream is = instructions.getCode().getAttributes().getStream();
index = is.readByte();
value = this.getPool().get(is.readUnsignedByte());
length += 1;
}
@@ -28,14 +28,12 @@ public class LDC extends Instruction
public void write(DataOutputStream out, int pc) throws IOException
{
super.write(out, pc);
out.writeByte(index);
out.writeByte(this.getPool().make(value));
}
@Override
public void execute(Frame frame)
{
ClassFile thisClass = this.getInstructions().getCode().getAttributes().getClassFile();
PoolEntry entry = thisClass.getPool().getEntry(index);
frame.getStack().push(this, entry.getObject());
frame.getStack().push(this, value);
}
}

View File

@@ -13,14 +13,14 @@ import java.io.IOException;
public class LDC2_W extends Instruction
{
private int index;
private Object value;
public LDC2_W(Instructions instructions, InstructionType type, int pc) throws IOException
{
super(instructions, type, pc);
DataInputStream is = instructions.getCode().getAttributes().getStream();
index = is.readUnsignedShort();
value = this.getPool().get(is.readUnsignedShort());
length += 2;
}
@@ -28,14 +28,12 @@ public class LDC2_W extends Instruction
public void write(DataOutputStream out, int pc) throws IOException
{
super.write(out, pc);
out.writeShort(index);
out.writeShort(this.getPool().make(value));
}
@Override
public void execute(Frame frame)
{
ClassFile thisClass = this.getInstructions().getCode().getAttributes().getClassFile();
PoolEntry entry = thisClass.getPool().getEntry(index);
frame.getStack().push(this, entry.getObject());
frame.getStack().push(this, value);
}
}

View File

@@ -13,14 +13,14 @@ import java.io.IOException;
public class LDC_W extends Instruction
{
private int index;
private Object value;
public LDC_W(Instructions instructions, InstructionType type, int pc) throws IOException
{
super(instructions, type, pc);
DataInputStream is = instructions.getCode().getAttributes().getStream();
index = is.readUnsignedShort();
value = this.getPool().get(is.readUnsignedShort());
length += 2;
}
@@ -28,24 +28,19 @@ public class LDC_W extends Instruction
public void write(DataOutputStream out, int pc) throws IOException
{
super.write(out, pc);
out.writeShort(index);
out.writeShort(this.getPool().make(value));
}
@Override
public void execute(Frame frame)
{
ClassFile thisClass = this.getInstructions().getCode().getAttributes().getClassFile();
PoolEntry entry = thisClass.getPool().getEntry(index);
frame.getStack().push(this, entry.getObject());
frame.getStack().push(this, value);
}
@Override
public String getDesc(Frame frame)
{
ClassFile thisClass = this.getInstructions().getCode().getAttributes().getClassFile();
PoolEntry entry = thisClass.getPool().getEntry(index);
return "ldc_w " + entry.getObject();
return "ldc_w " + value;
}
}

View File

@@ -14,7 +14,7 @@ import java.io.IOException;
public class MultiANewArray extends Instruction
{
private int index;
private Class clazz;
private int dimensions;
public MultiANewArray(Instructions instructions, InstructionType type, int pc) throws IOException
@@ -22,7 +22,7 @@ public class MultiANewArray extends Instruction
super(instructions, type, pc);
DataInputStream is = instructions.getCode().getAttributes().getStream();
index = is.readUnsignedShort();
clazz = this.getPool().getClass(is.readUnsignedShort());
dimensions = is.readUnsignedByte();
length += 3;
}
@@ -31,7 +31,7 @@ public class MultiANewArray extends Instruction
public void write(DataOutputStream out, int pc) throws IOException
{
super.write(out, pc);
out.writeShort(index);
out.writeShort(this.getPool().make(clazz));
out.writeByte(dimensions);
}
@@ -41,7 +41,6 @@ public class MultiANewArray extends Instruction
Stack stack = e.getStack();
ClassFile thisClass = this.getInstructions().getCode().getAttributes().getClassFile();
Class clazz = (Class) thisClass.getPool().getEntry(index);
// XXX primive type/array type ? [[I [[Lmyclass; etc
ClassFile cf = thisClass.getGroup().findClass(clazz.getName());

View File

@@ -15,14 +15,14 @@ import java.io.IOException;
public class New extends Instruction
{
private int index;
private Class clazz;
public New(Instructions instructions, InstructionType type, int pc) throws IOException
{
super(instructions, type, pc);
DataInputStream is = instructions.getCode().getAttributes().getStream();
index = is.readUnsignedShort();
clazz = this.getPool().getClass(is.readUnsignedShort());
length += 2;
}
@@ -30,14 +30,13 @@ public class New extends Instruction
public void write(DataOutputStream out, int pc) throws IOException
{
super.write(out, pc);
out.writeShort(index);
out.writeShort(this.getPool().make(clazz));
}
@Override
public void execute(Frame e)
{
ClassFile thisClass = this.getInstructions().getCode().getAttributes().getClassFile();
Class clazz = (Class) thisClass.getPool().getEntry(index);
ClassFile cf = thisClass.getGroup().findClass(clazz.getName());
if (cf == null)
{

View File

@@ -17,14 +17,14 @@ import java.io.IOException;
public class PutField extends Instruction
{
private int index;
private Field field;
public PutField(Instructions instructions, InstructionType type, int pc) throws IOException
{
super(instructions, type, pc);
DataInputStream is = instructions.getCode().getAttributes().getStream();
index = is.readUnsignedShort();
field = this.getPool().getField(is.readUnsignedShort());
length += 2;
}
@@ -32,17 +32,13 @@ public class PutField extends Instruction
public void write(DataOutputStream out, int pc) throws IOException
{
super.write(out, pc);
out.writeShort(index);
out.writeShort(this.getPool().make(field));
}
@Override
public void execute(Frame e)
{
ClassFile thisClass = this.getInstructions().getCode().getAttributes().getClassFile();
ConstantPool pool = thisClass.getPool();
Field entry = (Field) pool.getEntry(index);
NameAndType nat = entry.getNameAndType();
NameAndType nat = field.getNameAndType();
ObjectInstance object = (ObjectInstance) e.getStack().pop();
Object value = e.getStack().pop();

View File

@@ -18,14 +18,14 @@ import java.io.IOException;
public class PutStatic extends Instruction
{
private int index;
private Field field;
public PutStatic(Instructions instructions, InstructionType type, int pc) throws IOException
{
super(instructions, type, pc);
DataInputStream is = instructions.getCode().getAttributes().getStream();
index = is.readUnsignedShort();
field = this.getPool().getField(is.readUnsignedShort());
length += 2;
}
@@ -33,7 +33,7 @@ public class PutStatic extends Instruction
public void write(DataOutputStream out, int pc) throws IOException
{
super.write(out, pc);
out.writeShort(index);
out.writeShort(this.getPool().make(field));
}
@Override
@@ -41,10 +41,8 @@ public class PutStatic extends Instruction
{
ClassFile thisClass = this.getInstructions().getCode().getAttributes().getClassFile();
ConstantPool pool = thisClass.getPool();
Field entry = (Field) pool.getEntry(index);
Class clazz = entry.getClassEntry();
NameAndType nat = entry.getNameAndType();
Class clazz = field.getClassEntry();
NameAndType nat = field.getNameAndType();
Object value = e.getStack().pop();