Some branching/jumping

This commit is contained in:
Adam
2014-12-05 16:26:07 -05:00
parent ea556bef32
commit ea366191ea
44 changed files with 571 additions and 124 deletions

View File

@@ -3,6 +3,7 @@ package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
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.Stack;
@@ -19,8 +20,8 @@ public class AALoad extends Instruction
Stack stack = frame.getStack();
int index = (int) stack.pop();
Object[] array = (Object[]) stack.pop();
ArrayInstance array = (ArrayInstance) stack.pop();
stack.push(array[index]);
stack.push(array.get(index));
}
}

View File

@@ -3,7 +3,9 @@ package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
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
@@ -18,10 +20,10 @@ public class AAStore extends Instruction
{
Stack stack = frame.getStack();
Object value = stack.pop();
ObjectInstance value = (ObjectInstance) stack.pop();
int index = (int) stack.pop();
Object[] array = (Object[]) stack.pop();
ArrayInstance array = (ArrayInstance) stack.pop();
array[index] = value;
array.put(value, index);
}
}

View File

@@ -3,6 +3,7 @@ package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.execution.Frame;
import java.io.DataInputStream;
import java.io.IOException;
@@ -20,4 +21,10 @@ public class ALoad extends Instruction
length += 1;
}
@Override
public void execute(Frame frame)
{
Object obj = frame.getVariables().get(index);
frame.getStack().push(obj);
}
}

View File

@@ -1,8 +1,13 @@
package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.ClassFile;
import info.sigterm.deob.attributes.code.Instruction;
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.ClassInstance;
import info.sigterm.deob.execution.Frame;
import info.sigterm.deob.pool.Class;
import java.io.DataInputStream;
import java.io.IOException;
@@ -20,4 +25,24 @@ public class ANewArray extends Instruction
length += 2;
}
@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();
ClassFile cf = thisClass.getGroup().findClass(clazz.getName());
if (cf == null)
{
frame.getStack().push(null);
return;
}
ClassInstance type = frame.getPath().getClassInstance(cf);
ArrayInstance array = frame.getPath().createArray(type, count);
frame.getStack().push(array);
}
}

View File

@@ -3,6 +3,7 @@ package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.execution.Frame;
import java.io.DataInputStream;
import java.io.IOException;
@@ -20,4 +21,9 @@ public class BiPush extends Instruction
length += 1;
}
@Override
public void execute(Frame frame)
{
frame.getStack().push((int) b);
}
}

View File

@@ -1,8 +1,13 @@
package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.ClassFile;
import info.sigterm.deob.ConstantPool;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.execution.Frame;
import info.sigterm.deob.execution.ObjectInstance;
import info.sigterm.deob.pool.Class;
import java.io.DataInputStream;
import java.io.IOException;
@@ -20,4 +25,30 @@ public class CheckCast extends Instruction
length += 2;
}
@Override
public void execute(Frame e)
{
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)
{
e.getStack().push(null);
return;
}
ClassFile otherClass = thisClass.getGroup().findClass(clazz.getName());
boolean instanceOf = obj.getType().getClassFile().instanceOf(otherClass);
if (!instanceOf)
{
// XXX throw
}
e.getStack().push(obj);
}
}

View File

@@ -3,6 +3,7 @@ package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.execution.Frame;
import java.io.DataInputStream;
import java.io.IOException;
@@ -20,4 +21,10 @@ public class DLoad extends Instruction
length += 1;
}
@Override
public void execute(Frame frame)
{
double d = (double) frame.getVariables().get(index);
frame.getStack().push(d);
}
}

View File

@@ -3,6 +3,7 @@ package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.execution.Frame;
import java.io.DataInputStream;
import java.io.IOException;
@@ -20,4 +21,10 @@ public class DStore extends Instruction
length += 1;
}
@Override
public void execute(Frame frame)
{
double d = (double) frame.getStack().pop();
frame.getVariables().set(index, d);
}
}

View File

@@ -3,6 +3,7 @@ package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.execution.Frame;
import java.io.DataInputStream;
import java.io.IOException;
@@ -20,4 +21,10 @@ public class FLoad extends Instruction
length += 1;
}
@Override
public void execute(Frame frame)
{
float f = (float) frame.getVariables().get(index);
frame.getStack().push(f);
}
}

View File

@@ -3,6 +3,7 @@ package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.execution.Frame;
import java.io.DataInputStream;
import java.io.IOException;
@@ -20,4 +21,10 @@ public class FStore extends Instruction
length += 1;
}
@Override
public void execute(Frame frame)
{
float f = (float) frame.getStack().pop();
frame.getVariables().set(index, f);
}
}

View File

@@ -1,8 +1,15 @@
package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.ClassFile;
import info.sigterm.deob.ConstantPool;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.execution.FieldInstance;
import info.sigterm.deob.execution.Frame;
import info.sigterm.deob.execution.ObjectInstance;
import info.sigterm.deob.pool.Field;
import info.sigterm.deob.pool.NameAndType;
import java.io.DataInputStream;
import java.io.IOException;
@@ -20,4 +27,19 @@ public class GetField extends Instruction
length += 2;
}
@Override
public void execute(Frame frame)
{
ObjectInstance object = (ObjectInstance) frame.getStack().pop();
ClassFile thisClass = this.getInstructions().getCode().getAttributes().getClassFile();
ConstantPool pool = thisClass.getPool();
Field entry = (Field) pool.getEntry(index);
NameAndType nat = entry.getNameAndType();
FieldInstance field = object.getField(nat);
frame.getStack().push(field.getValue());
}
}

View File

@@ -3,15 +3,16 @@ package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.execution.Frame;
import java.io.DataInputStream;
import java.io.IOException;
public class Branch extends Instruction
public class Goto extends Instruction
{
private short offset;
public Branch(Instructions instructions, InstructionType type, int pc) throws IOException
public Goto(Instructions instructions, InstructionType type, int pc) throws IOException
{
super(instructions, type, pc);
@@ -25,4 +26,10 @@ public class Branch extends Instruction
{
this.addJump(offset);
}
@Override
public void execute(Frame e)
{
e.jump(offset);
}
}

View File

@@ -3,6 +3,7 @@ package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.execution.Frame;
import java.io.DataInputStream;
import java.io.IOException;
@@ -25,4 +26,10 @@ public class GotoW extends Instruction
{
this.addJump(offset);
}
@Override
public void execute(Frame e)
{
e.jump(offset);
}
}

View File

@@ -3,6 +3,7 @@ package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.execution.Frame;
import java.io.DataInputStream;
import java.io.IOException;
@@ -22,4 +23,11 @@ public class IInc extends Instruction
length += 2;
}
@Override
public void execute(Frame frame)
{
int i = (int) frame.getVariables().get(index);
i += inc;
frame.getVariables().set(index, i);
}
}

View File

@@ -3,6 +3,7 @@ package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.execution.Frame;
import java.io.DataInputStream;
import java.io.IOException;
@@ -20,4 +21,10 @@ public class ILoad extends Instruction
length += 1;
}
@Override
public void execute(Frame frame)
{
int i = (int) frame.getVariables().get(index);
frame.getStack().push(i);
}
}

View File

@@ -0,0 +1,41 @@
package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.execution.Frame;
import info.sigterm.deob.execution.Path;
import java.io.DataInputStream;
import java.io.IOException;
public class If extends Instruction
{
private short offset;
public If(Instructions instructions, InstructionType type, int pc) throws IOException
{
super(instructions, type, pc);
DataInputStream is = instructions.getCode().getAttributes().getStream();
offset = is.readShort();
length += 2;
}
@Override
public void buildJumpGraph()
{
this.addJump(offset);
}
@Override
public void execute(Frame e)
{
e.getStack().pop();
e.getStack().pop();
Path other = e.getPath().dup();
Frame frame = other.getCurrentFrame();
frame.jump(offset);
}
}

View File

@@ -3,21 +3,23 @@ package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.execution.Frame;
import info.sigterm.deob.execution.Path;
import java.io.DataInputStream;
import java.io.IOException;
public class JSR_W extends Instruction
public class If0 extends Instruction
{
private int offset;
private short offset;
public JSR_W(Instructions instructions, InstructionType type, int pc) throws IOException
public If0(Instructions instructions, InstructionType type, int pc) throws IOException
{
super(instructions, type, pc);
DataInputStream is = instructions.getCode().getAttributes().getStream();
offset = is.readInt();
length += 4;
offset = is.readShort();
length += 2;
}
@Override
@@ -25,4 +27,14 @@ public class JSR_W extends Instruction
{
this.addJump(offset);
}
@Override
public void execute(Frame e)
{
e.getStack().pop();
Path other = e.getPath().dup();
Frame frame = other.getCurrentFrame();
frame.jump(offset);
}
}

View File

@@ -1,23 +0,0 @@
package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import java.io.DataInputStream;
import java.io.IOException;
public class IfNonNull extends Instruction
{
private int index;
public IfNonNull(Instructions instructions, InstructionType type, int pc) throws IOException
{
super(instructions, type, pc);
DataInputStream is = instructions.getCode().getAttributes().getStream();
index = is.readUnsignedShort();
length += 2;
}
}

View File

@@ -1,23 +0,0 @@
package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import java.io.DataInputStream;
import java.io.IOException;
public class IfNull extends Instruction
{
private int index;
public IfNull(Instructions instructions, InstructionType type, int pc) throws IOException
{
super(instructions, type, pc);
DataInputStream is = instructions.getCode().getAttributes().getStream();
index = is.readUnsignedShort();
length += 2;
}
}

View File

@@ -1,8 +1,13 @@
package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.ClassFile;
import info.sigterm.deob.ConstantPool;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.execution.Frame;
import info.sigterm.deob.execution.ObjectInstanceBase;
import info.sigterm.deob.pool.Class;
import java.io.DataInputStream;
import java.io.IOException;
@@ -20,4 +25,24 @@ public class InstanceOf extends Instruction
length += 2;
}
@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)
{
e.getStack().push(0);
return;
}
ClassFile otherClass = thisClass.getGroup().findClass(clazz.getName());
boolean instanceOf = obj.getType().getClassFile().instanceOf(otherClass);
e.getStack().push(instanceOf ? 1 : 0);
}
}

View File

@@ -1,8 +1,11 @@
package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.ClassFile;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.execution.Frame;
import info.sigterm.deob.pool.PoolEntry;
import java.io.DataInputStream;
import java.io.IOException;
@@ -20,4 +23,11 @@ public class LDC extends Instruction
length += 1;
}
@Override
public void execute(Frame frame)
{
ClassFile thisClass = this.getInstructions().getCode().getAttributes().getClassFile();
PoolEntry entry = thisClass.getPool().getEntry(index);
frame.getStack().push(entry.getObject());
}
}

View File

@@ -1,8 +1,11 @@
package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.ClassFile;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.execution.Frame;
import info.sigterm.deob.pool.PoolEntry;
import java.io.DataInputStream;
import java.io.IOException;
@@ -20,4 +23,11 @@ public class LDC2_W extends Instruction
length += 2;
}
@Override
public void execute(Frame frame)
{
ClassFile thisClass = this.getInstructions().getCode().getAttributes().getClassFile();
PoolEntry entry = thisClass.getPool().getEntry(index);
frame.getStack().push(entry.getObject());
}
}

View File

@@ -1,8 +1,11 @@
package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.ClassFile;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.execution.Frame;
import info.sigterm.deob.pool.PoolEntry;
import java.io.DataInputStream;
import java.io.IOException;
@@ -20,4 +23,11 @@ public class LDC_W extends Instruction
length += 2;
}
@Override
public void execute(Frame frame)
{
ClassFile thisClass = this.getInstructions().getCode().getAttributes().getClassFile();
PoolEntry entry = thisClass.getPool().getEntry(index);
frame.getStack().push(entry.getObject());
}
}

View File

@@ -3,6 +3,7 @@ package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.execution.Frame;
import java.io.DataInputStream;
import java.io.IOException;
@@ -20,4 +21,10 @@ public class LLoad extends Instruction
length += 1;
}
@Override
public void execute(Frame frame)
{
long l = (long) frame.getVariables().get(index);
frame.getStack().push(l);
}
}

View File

@@ -3,6 +3,7 @@ package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.execution.Frame;
import java.io.DataInputStream;
import java.io.IOException;
@@ -20,4 +21,10 @@ public class LStore extends Instruction
length += 1;
}
@Override
public void execute(Frame frame)
{
long l = (long) frame.getStack().pop();
frame.getVariables().set(index, l);
}
}

View File

@@ -0,0 +1,19 @@
package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.execution.Frame;
public class MonitorEnter extends Instruction
{
public MonitorEnter(Instructions instructions, InstructionType type, int pc)
{
super(instructions, type, pc);
}
@Override
public void execute(Frame frame)
{
}
}

View File

@@ -0,0 +1,19 @@
package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.execution.Frame;
public class MonitorExit extends Instruction
{
public MonitorExit(Instructions instructions, InstructionType type, int pc)
{
super(instructions, type, pc);
}
@Override
public void execute(Frame frame)
{
}
}

View File

@@ -1,23 +0,0 @@
package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import java.io.DataInputStream;
import java.io.IOException;
public class Ret extends Instruction
{
private int index;
public Ret(Instructions instructions, InstructionType type, int pc) throws IOException
{
super(instructions, type, pc);
DataInputStream is = instructions.getCode().getAttributes().getStream();
index = is.readByte();
length += 1;
}
}

View File

@@ -3,6 +3,7 @@ package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.execution.Frame;
import java.io.DataInputStream;
import java.io.IOException;
@@ -20,4 +21,9 @@ public class SiPush extends Instruction
length += 2;
}
@Override
public void execute(Frame frame)
{
frame.getStack().push(s);
}
}