Some thinking about exceptions
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
package info.sigterm.deob.execution;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import info.sigterm.deob.Method;
|
||||
import info.sigterm.deob.attributes.Code;
|
||||
import info.sigterm.deob.attributes.code.Exception;
|
||||
import info.sigterm.deob.attributes.code.Instruction;
|
||||
import info.sigterm.deob.attributes.code.Instructions;
|
||||
|
||||
@@ -39,6 +42,11 @@ public class Frame
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
public Method getMethod()
|
||||
{
|
||||
return method;
|
||||
}
|
||||
|
||||
public Stack getStack()
|
||||
{
|
||||
@@ -102,4 +110,14 @@ public class Frame
|
||||
assert offset != 0;
|
||||
pc += offset;
|
||||
}
|
||||
|
||||
public void jumpAbsolute(int pc)
|
||||
{
|
||||
this.pc = pc;
|
||||
}
|
||||
|
||||
public Collection<Exception> getExceptionHandlers()
|
||||
{
|
||||
return method.getCode().getExceptions().getHandlersForPc(this.pc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@ package info.sigterm.deob.execution;
|
||||
|
||||
import info.sigterm.deob.ClassFile;
|
||||
import info.sigterm.deob.Method;
|
||||
import info.sigterm.deob.attributes.code.Exception;
|
||||
import info.sigterm.deob.attributes.code.Instruction;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Path
|
||||
@@ -112,9 +114,29 @@ public class Path
|
||||
currentFrame.executing = false;
|
||||
}
|
||||
|
||||
public void throwException(ObjectInstance exception)
|
||||
public void throwException(Instruction ins, ObjectInstance exception)
|
||||
{
|
||||
System.out.println("XXX throw " + exception);
|
||||
//XXX
|
||||
ArrayList<Exception> exceptions = new ArrayList<Exception>();
|
||||
|
||||
/* collect all existing exception handlers */
|
||||
for (Frame f : frames)
|
||||
{
|
||||
Collection<Exception> handlers = f.getExceptionHandlers();
|
||||
exceptions.addAll(handlers);
|
||||
}
|
||||
|
||||
for (Exception handler : exceptions)
|
||||
{
|
||||
/* jump to handler */
|
||||
Method handlerMethod = handler.getExceptions().getCode().getAttributes().getMethod();
|
||||
|
||||
Path other = this.dup();
|
||||
/* walk up the frames until we find the one which holds the exception handler */
|
||||
while (handlerMethod != other.getCurrentFrame().getMethod())
|
||||
other.returnFrame();
|
||||
|
||||
/* handler pc is absolute from the beginning instruction */
|
||||
other.getCurrentFrame().jumpAbsolute(handler.getHandlerPc());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user