debugging, idr, exception handler execution support
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
package info.sigterm.deob.attributes.code.instruction.types;
|
||||
|
||||
import info.sigterm.deob.Method;
|
||||
import info.sigterm.deob.pool.PoolEntry;
|
||||
|
||||
public interface InvokeInstruction
|
||||
{
|
||||
public void removeParameter(int idx);
|
||||
|
||||
public PoolEntry getMethod();
|
||||
}
|
||||
|
||||
@@ -6,7 +6,11 @@ import info.sigterm.deob.attributes.code.Instructions;
|
||||
import info.sigterm.deob.execution.Frame;
|
||||
import info.sigterm.deob.execution.InstructionContext;
|
||||
import info.sigterm.deob.execution.Stack;
|
||||
import info.sigterm.deob.execution.StackContext;
|
||||
import info.sigterm.deob.execution.Type;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class AThrow extends Instruction
|
||||
{
|
||||
@@ -21,13 +25,38 @@ public class AThrow extends Instruction
|
||||
InstructionContext ins = new InstructionContext(this, frame);
|
||||
Stack stack = frame.getStack();
|
||||
|
||||
// XXX this actually clears the stack and puts only the value on, after jumping to the handler
|
||||
//StackContext value = stack.pop();
|
||||
//ins.pop(value);
|
||||
// get exception
|
||||
StackContext exception = stack.pop();
|
||||
ins.pop(exception);
|
||||
|
||||
// Clear stack
|
||||
while (stack.getSize() > 0)
|
||||
{
|
||||
StackContext value = stack.pop();
|
||||
ins.pop(value);
|
||||
}
|
||||
|
||||
// push exception back
|
||||
exception = new StackContext(ins, exception.getType());
|
||||
stack.push(exception);
|
||||
|
||||
// jump to instruction handlers that can catch exceptions here
|
||||
for (info.sigterm.deob.attributes.code.Exception e : this.getInstructions().getCode().getExceptions().getExceptions())
|
||||
{
|
||||
Instruction start = e.getStart(),
|
||||
end = e.getEnd();
|
||||
|
||||
// [start, end)
|
||||
if (this.getPc() >= start.getPc() && this.getPc() < end.getPc())
|
||||
{
|
||||
Frame f = frame.dup();
|
||||
f.jumpAbsolute(e.getHandler().getPc());
|
||||
}
|
||||
}
|
||||
|
||||
frame.addInstructionContext(ins);
|
||||
|
||||
frame.throwException(null);//value.getType());
|
||||
frame.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -36,17 +36,35 @@ public class CheckCast extends Instruction
|
||||
|
||||
@Override
|
||||
public void execute(Frame frame)
|
||||
{
|
||||
Frame other = frame.dup();
|
||||
Stack stack = other.getStack();
|
||||
|
||||
InstructionContext ins = new InstructionContext(this, other);
|
||||
|
||||
StackContext what = stack.pop();
|
||||
|
||||
ins.pop(what);
|
||||
|
||||
other.throwException(new Type("java.lang.ClassCastException"));
|
||||
{
|
||||
// jump to instruction handlers that can catch exceptions here
|
||||
for (info.sigterm.deob.attributes.code.Exception e : this.getInstructions().getCode().getExceptions().getExceptions())
|
||||
{
|
||||
Instruction start = e.getStart(),
|
||||
end = e.getEnd();
|
||||
|
||||
// [start, end)
|
||||
if (this.getPc() >= start.getPc() && this.getPc() < end.getPc())
|
||||
{
|
||||
Frame f = frame.dup();
|
||||
Stack stack = f.getStack();
|
||||
|
||||
InstructionContext ins = new InstructionContext(this, f);
|
||||
|
||||
while (stack.getSize() > 0)
|
||||
{
|
||||
StackContext what = stack.pop();
|
||||
ins.pop(what);
|
||||
}
|
||||
|
||||
// push exception back
|
||||
StackContext exception = new StackContext(ins, new Type("java/lang/Exception"));
|
||||
stack.push(exception);
|
||||
|
||||
f.addInstructionContext(ins);
|
||||
|
||||
f.jumpAbsolute(e.getHandler().getPc());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -56,6 +56,8 @@ public class If0 extends Instruction implements JumpingInstruction
|
||||
|
||||
ins.pop(one);
|
||||
|
||||
frame.addInstructionContext(ins);
|
||||
|
||||
Frame other = frame.dup();
|
||||
other.jump(offset);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import info.sigterm.deob.execution.Type;
|
||||
import info.sigterm.deob.pool.InterfaceMethod;
|
||||
import info.sigterm.deob.pool.Method;
|
||||
import info.sigterm.deob.pool.NameAndType;
|
||||
import info.sigterm.deob.pool.PoolEntry;
|
||||
import info.sigterm.deob.signature.Signature;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
@@ -77,6 +78,8 @@ public class InvokeInterface extends Instruction implements InvokeInstruction
|
||||
StackContext object = stack.pop();
|
||||
ins.pop(object);
|
||||
|
||||
handleExceptions(frame);
|
||||
|
||||
if (!method.getNameAndType().isVoid())
|
||||
{
|
||||
StackContext ctx = new StackContext(ins, new Type(method.getNameAndType().getDescriptor().getReturnValue()).toStackType());
|
||||
@@ -85,6 +88,32 @@ public class InvokeInterface extends Instruction implements InvokeInstruction
|
||||
|
||||
frame.addInstructionContext(ins);
|
||||
}
|
||||
|
||||
private void handleExceptions(Frame frame)
|
||||
{
|
||||
// jump to instruction handlers that can catch exceptions here
|
||||
for (info.sigterm.deob.attributes.code.Exception e : this.getInstructions().getCode().getExceptions().getExceptions())
|
||||
{
|
||||
Instruction start = e.getStart(),
|
||||
end = e.getEnd();
|
||||
|
||||
// [start, end)
|
||||
if (this.getPc() >= start.getPc() && this.getPc() < end.getPc())
|
||||
{
|
||||
Frame f = frame.dup();
|
||||
Stack stack = f.getStack();
|
||||
|
||||
while (stack.getSize() > 0)
|
||||
stack.pop();
|
||||
|
||||
InstructionContext ins = new InstructionContext(this, f);
|
||||
StackContext ctx = new StackContext(ins, new Type("java/lang/Exception"));
|
||||
stack.push(ctx);
|
||||
|
||||
f.jumpAbsolute(e.getHandler().getPc());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeParameter(int idx)
|
||||
@@ -99,4 +128,10 @@ public class InvokeInterface extends Instruction implements InvokeInstruction
|
||||
// create new method pool object
|
||||
method = new InterfaceMethod(method.getPool(), clazz, new NameAndType(nat.getPool(), nat.getName(), sig));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PoolEntry getMethod()
|
||||
{
|
||||
return method;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import info.sigterm.deob.execution.StackContext;
|
||||
import info.sigterm.deob.execution.Type;
|
||||
import info.sigterm.deob.pool.Method;
|
||||
import info.sigterm.deob.pool.NameAndType;
|
||||
import info.sigterm.deob.pool.PoolEntry;
|
||||
import info.sigterm.deob.signature.Signature;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
@@ -72,6 +73,8 @@ public class InvokeSpecial extends Instruction implements InvokeInstruction
|
||||
StackContext object = stack.pop();
|
||||
ins.pop(object);
|
||||
|
||||
handleExceptions(frame);
|
||||
|
||||
if (!method.getNameAndType().isVoid())
|
||||
{
|
||||
StackContext ctx = new StackContext(ins, new Type(method.getNameAndType().getDescriptor().getReturnValue()).toStackType());
|
||||
@@ -80,6 +83,32 @@ public class InvokeSpecial extends Instruction implements InvokeInstruction
|
||||
|
||||
frame.addInstructionContext(ins);
|
||||
}
|
||||
|
||||
private void handleExceptions(Frame frame)
|
||||
{
|
||||
// jump to instruction handlers that can catch exceptions here
|
||||
for (info.sigterm.deob.attributes.code.Exception e : this.getInstructions().getCode().getExceptions().getExceptions())
|
||||
{
|
||||
Instruction start = e.getStart(),
|
||||
end = e.getEnd();
|
||||
|
||||
// [start, end)
|
||||
if (this.getPc() >= start.getPc() && this.getPc() < end.getPc())
|
||||
{
|
||||
Frame f = frame.dup();
|
||||
Stack stack = f.getStack();
|
||||
|
||||
while (stack.getSize() > 0)
|
||||
stack.pop();
|
||||
|
||||
InstructionContext ins = new InstructionContext(this, f);
|
||||
StackContext ctx = new StackContext(ins, new Type("java/lang/Exception"));
|
||||
stack.push(ctx);
|
||||
|
||||
f.jumpAbsolute(e.getHandler().getPc());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDesc(Frame frame)
|
||||
@@ -100,4 +129,10 @@ public class InvokeSpecial extends Instruction implements InvokeInstruction
|
||||
// create new method pool object
|
||||
method = new Method(method.getPool(), clazz, new NameAndType(nat.getPool(), nat.getName(), sig));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PoolEntry getMethod()
|
||||
{
|
||||
return method;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import info.sigterm.deob.execution.StackContext;
|
||||
import info.sigterm.deob.execution.Type;
|
||||
import info.sigterm.deob.pool.Method;
|
||||
import info.sigterm.deob.pool.NameAndType;
|
||||
import info.sigterm.deob.pool.PoolEntry;
|
||||
import info.sigterm.deob.signature.Signature;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
@@ -69,6 +70,8 @@ public class InvokeStatic extends Instruction implements InvokeInstruction
|
||||
ins.pop(arg);
|
||||
}
|
||||
|
||||
handleExceptions(frame);
|
||||
|
||||
if (!method.getNameAndType().isVoid())
|
||||
{
|
||||
StackContext ctx = new StackContext(ins, new Type(method.getNameAndType().getDescriptor().getReturnValue()).toStackType());
|
||||
@@ -78,6 +81,32 @@ public class InvokeStatic extends Instruction implements InvokeInstruction
|
||||
frame.addInstructionContext(ins);
|
||||
}
|
||||
|
||||
private void handleExceptions(Frame frame)
|
||||
{
|
||||
// jump to instruction handlers that can catch exceptions here
|
||||
for (info.sigterm.deob.attributes.code.Exception e : this.getInstructions().getCode().getExceptions().getExceptions())
|
||||
{
|
||||
Instruction start = e.getStart(),
|
||||
end = e.getEnd();
|
||||
|
||||
// [start, end)
|
||||
if (this.getPc() >= start.getPc() && this.getPc() < end.getPc())
|
||||
{
|
||||
Frame f = frame.dup();
|
||||
Stack stack = f.getStack();
|
||||
|
||||
while (stack.getSize() > 0)
|
||||
stack.pop();
|
||||
|
||||
InstructionContext ins = new InstructionContext(this, f);
|
||||
StackContext ctx = new StackContext(ins, new Type("java/lang/Exception"));
|
||||
stack.push(ctx);
|
||||
|
||||
f.jumpAbsolute(e.getHandler().getPc());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDesc(Frame frame)
|
||||
{
|
||||
@@ -97,4 +126,10 @@ public class InvokeStatic extends Instruction implements InvokeInstruction
|
||||
// create new method pool object
|
||||
method = new Method(method.getPool(), clazz, new NameAndType(nat.getPool(), nat.getName(), sig));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PoolEntry getMethod()
|
||||
{
|
||||
return method;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import info.sigterm.deob.execution.StackContext;
|
||||
import info.sigterm.deob.execution.Type;
|
||||
import info.sigterm.deob.pool.Method;
|
||||
import info.sigterm.deob.pool.NameAndType;
|
||||
import info.sigterm.deob.pool.PoolEntry;
|
||||
import info.sigterm.deob.signature.Signature;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
@@ -73,6 +74,8 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction
|
||||
StackContext object = stack.pop();
|
||||
ins.pop(object);
|
||||
|
||||
handleExceptions(frame);
|
||||
|
||||
if (!method.getNameAndType().isVoid())
|
||||
{
|
||||
StackContext ctx = new StackContext(ins, new Type(method.getNameAndType().getDescriptor().getReturnValue()).toStackType());
|
||||
@@ -82,6 +85,32 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction
|
||||
frame.addInstructionContext(ins);
|
||||
}
|
||||
|
||||
private void handleExceptions(Frame frame)
|
||||
{
|
||||
// jump to instruction handlers that can catch exceptions here
|
||||
for (info.sigterm.deob.attributes.code.Exception e : this.getInstructions().getCode().getExceptions().getExceptions())
|
||||
{
|
||||
Instruction start = e.getStart(),
|
||||
end = e.getEnd();
|
||||
|
||||
// [start, end)
|
||||
if (this.getPc() >= start.getPc() && this.getPc() < end.getPc())
|
||||
{
|
||||
Frame f = frame.dup();
|
||||
Stack stack = f.getStack();
|
||||
|
||||
while (stack.getSize() > 0)
|
||||
stack.pop();
|
||||
|
||||
InstructionContext ins = new InstructionContext(this, f);
|
||||
StackContext ctx = new StackContext(ins, new Type("java/lang/Exception"));
|
||||
stack.push(ctx);
|
||||
|
||||
f.jumpAbsolute(e.getHandler().getPc());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeParameter(int idx)
|
||||
{
|
||||
@@ -95,4 +124,10 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction
|
||||
// create new method pool object
|
||||
method = new Method(method.getPool(), clazz, new NameAndType(nat.getPool(), nat.getName(), sig));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PoolEntry getMethod()
|
||||
{
|
||||
return method;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user