Some branching/jumping
This commit is contained in:
23
src/main/java/info/sigterm/deob/execution/ArrayInstance.java
Normal file
23
src/main/java/info/sigterm/deob/execution/ArrayInstance.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package info.sigterm.deob.execution;
|
||||
|
||||
|
||||
public class ArrayInstance extends ObjectInstanceBase
|
||||
{
|
||||
private ObjectInstance[] array;
|
||||
|
||||
public ArrayInstance(Path path, ClassInstance type, int len)
|
||||
{
|
||||
super(path, type);
|
||||
this.array = new ObjectInstance[len];
|
||||
}
|
||||
|
||||
public void put(ObjectInstance obj, int idx)
|
||||
{
|
||||
array[idx] = obj;
|
||||
}
|
||||
|
||||
public ObjectInstance get(int idx)
|
||||
{
|
||||
return array[idx];
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public class ClassInstance
|
||||
Attributes attributes = field.getAttributes();
|
||||
ConstantValue cv = (ConstantValue) attributes.findType(AttributeType.CONSTANT_VALUE);
|
||||
|
||||
StaticFieldInstance fi = new StaticFieldInstance(field, cv);
|
||||
StaticFieldInstance fi = new StaticFieldInstance(this, field, cv);
|
||||
this.fields.add(fi);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,4 +20,9 @@ public class Execution
|
||||
Path p = new Path(this);
|
||||
p.init(method, args);
|
||||
}
|
||||
|
||||
public void addPath(Path p)
|
||||
{
|
||||
paths.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
27
src/main/java/info/sigterm/deob/execution/FieldInstance.java
Normal file
27
src/main/java/info/sigterm/deob/execution/FieldInstance.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package info.sigterm.deob.execution;
|
||||
|
||||
import info.sigterm.deob.Field;
|
||||
|
||||
public class FieldInstance
|
||||
{
|
||||
private ObjectInstance object;
|
||||
private Field field;
|
||||
private Object value;
|
||||
|
||||
public FieldInstance(ObjectInstance object, Field field, Object value)
|
||||
{
|
||||
this.object = object;
|
||||
this.field = field;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Field getField()
|
||||
{
|
||||
return field;
|
||||
}
|
||||
|
||||
public Object getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,15 @@ package info.sigterm.deob.execution;
|
||||
|
||||
import info.sigterm.deob.Method;
|
||||
import info.sigterm.deob.attributes.Code;
|
||||
import info.sigterm.deob.attributes.code.Instruction;
|
||||
import info.sigterm.deob.attributes.code.Instructions;
|
||||
|
||||
public class Frame
|
||||
{
|
||||
private Path path;
|
||||
private Method method;
|
||||
private boolean executing = true;
|
||||
private int pc;
|
||||
private Stack stack;
|
||||
private Variables variables;
|
||||
|
||||
@@ -36,12 +40,38 @@ public class Frame
|
||||
return variables;
|
||||
}
|
||||
|
||||
public void init(Method method, Object[] args)
|
||||
public void init(Object[] args)
|
||||
{
|
||||
for (Object o : args)
|
||||
stack.push(o);
|
||||
|
||||
Code code = method.getCode();
|
||||
code.execute(this);
|
||||
execute();
|
||||
}
|
||||
|
||||
public void execute()
|
||||
{
|
||||
Instructions ins = method.getCode().getInstructions();
|
||||
while (executing)
|
||||
{
|
||||
int oldPc = pc;
|
||||
|
||||
Instruction i = ins.findInstruction(pc);
|
||||
i.execute(this);
|
||||
|
||||
if (oldPc == pc)
|
||||
{
|
||||
pc += i.getLength();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* jump */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void jump(int offset)
|
||||
{
|
||||
assert offset != 0;
|
||||
pc += offset;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,42 @@
|
||||
package info.sigterm.deob.execution;
|
||||
|
||||
public class ObjectInstance
|
||||
import info.sigterm.deob.Field;
|
||||
import info.sigterm.deob.Fields;
|
||||
import info.sigterm.deob.attributes.AttributeType;
|
||||
import info.sigterm.deob.attributes.Attributes;
|
||||
import info.sigterm.deob.attributes.ConstantValue;
|
||||
import info.sigterm.deob.pool.NameAndType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ObjectInstance extends ObjectInstanceBase
|
||||
{
|
||||
private ClassInstance type;
|
||||
private ArrayList<FieldInstance> fields = new ArrayList<FieldInstance>();
|
||||
|
||||
public ObjectInstance(Path path, ClassInstance type)
|
||||
{
|
||||
super(path, type);
|
||||
|
||||
/* create fields */
|
||||
Fields fields = type.getClassFile().getFields();
|
||||
for (Field field : fields.getFields())
|
||||
{
|
||||
if ((field.getAccessFlags() & Field.ACC_STATIC) != 0)
|
||||
continue;
|
||||
|
||||
Attributes attributes = field.getAttributes();
|
||||
ConstantValue cv = (ConstantValue) attributes.findType(AttributeType.CONSTANT_VALUE);
|
||||
|
||||
FieldInstance fi = new FieldInstance(this, field, cv.getValue().getObject());
|
||||
this.fields.add(fi);
|
||||
}
|
||||
}
|
||||
|
||||
public FieldInstance getField(NameAndType nat)
|
||||
{
|
||||
for (FieldInstance f : fields)
|
||||
if (f.getField().getName().equals(nat.getName()) && f.getField().getDescriptor().equals(nat.getDescriptor()))
|
||||
return f;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package info.sigterm.deob.execution;
|
||||
|
||||
|
||||
public abstract class ObjectInstanceBase
|
||||
{
|
||||
private Path path;
|
||||
private ClassInstance type;
|
||||
|
||||
public ObjectInstanceBase(Path path, ClassInstance type)
|
||||
{
|
||||
this.path = path;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public ClassInstance getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
}
|
||||
@@ -9,12 +9,22 @@ public class Path
|
||||
{
|
||||
private Execution execution;
|
||||
private ArrayList<ClassInstance> classes = new ArrayList<ClassInstance>();
|
||||
private ArrayList<ObjectInstance> objects = new ArrayList<ObjectInstance>();
|
||||
private java.util.Stack<Frame> frames = new java.util.Stack<Frame>(); // current execution frames
|
||||
|
||||
public Path(Execution execution)
|
||||
{
|
||||
this.execution = execution;
|
||||
}
|
||||
|
||||
private Path(Path other)
|
||||
{
|
||||
this.execution = other.execution;
|
||||
this.classes = new ArrayList<ClassInstance>(other.classes);
|
||||
this.objects = new ArrayList<ObjectInstance>(other.objects);
|
||||
this.frames = new java.util.Stack<Frame>();
|
||||
this.frames.addAll(other.frames);
|
||||
}
|
||||
|
||||
public Execution getExecution()
|
||||
{
|
||||
@@ -37,11 +47,35 @@ public class Path
|
||||
|
||||
return cl;
|
||||
}
|
||||
|
||||
public ObjectInstance createObject(ClassInstance type)
|
||||
{
|
||||
ObjectInstance obj = new ObjectInstance(this, type);
|
||||
objects.add(obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
public ArrayInstance createArray(ClassInstance type, int len)
|
||||
{
|
||||
return new ArrayInstance(this, type, len);
|
||||
}
|
||||
|
||||
public Frame getCurrentFrame()
|
||||
{
|
||||
return frames.peek();
|
||||
}
|
||||
|
||||
public void init(Method method, Object[] args)
|
||||
{
|
||||
Frame f = new Frame(this, method);
|
||||
frames.push(f);
|
||||
f.init(method, args);
|
||||
f.init(args);
|
||||
}
|
||||
|
||||
public Path dup()
|
||||
{
|
||||
Path other = new Path(this);
|
||||
execution.addPath(other);
|
||||
return other;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,13 @@ import info.sigterm.deob.attributes.ConstantValue;
|
||||
|
||||
public class StaticFieldInstance
|
||||
{
|
||||
private ClassInstance clazz;
|
||||
private Field field;
|
||||
private ConstantValue value;
|
||||
|
||||
public StaticFieldInstance(Field field, ConstantValue value)
|
||||
public StaticFieldInstance(ClassInstance clazz, Field field, ConstantValue value)
|
||||
{
|
||||
this.clazz = clazz;
|
||||
this.field = field;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user