Hard to follow, exception removal and unused block (only from the now

removed exceptions from what I can tell)
This commit is contained in:
Adam
2015-05-10 16:42:47 -04:00
parent 2edf9d2117
commit fa3e9c0262
14 changed files with 181 additions and 8 deletions

View File

@@ -14,7 +14,7 @@ public class Exception
private int startPc;
private int endPc;
private int handlerPc;
private Class cacheType;
private Class catchType;
public Exception(Exceptions exceptions) throws IOException
{
@@ -26,7 +26,16 @@ public class Exception
startPc = is.readUnsignedShort();
endPc = is.readUnsignedShort();
handlerPc = is.readUnsignedShort();
cacheType = pool.getClass(is.readUnsignedShort());
catchType = pool.getClass(is.readUnsignedShort());
Instruction ins = exceptions.getCode().getInstructions().findInstruction(handlerPc);
ins.exce.add(this);
}
protected void remove()
{
Instruction ins = exceptions.getCode().getInstructions().findInstruction(handlerPc);
ins.exce.remove(this);
}
public void write(DataOutputStream out) throws IOException
@@ -36,7 +45,7 @@ public class Exception
out.writeShort(startPc);
out.writeShort(endPc);
out.writeShort(handlerPc);
out.writeShort(cacheType == null ? 0 : pool.make(cacheType));
out.writeShort(catchType == null ? 0 : pool.make(catchType));
}
public Exceptions getExceptions()
@@ -58,4 +67,9 @@ public class Exception
{
return handlerPc;
}
public Class getCatchType()
{
return catchType;
}
}

View File

@@ -26,6 +26,12 @@ public class Exceptions
exceptions.add(new Exception(this));
}
public void remove(Exception e)
{
e.remove();
exceptions.remove(e);
}
public void write(DataOutputStream out) throws IOException
{
out.writeShort(exceptions.size());
@@ -38,9 +44,14 @@ public class Exceptions
return code;
}
public Collection<Exception> getHandlersForPc(int pc)
public List<Exception> getExceptions()
{
ArrayList<Exception> matches = new ArrayList<Exception>();
return exceptions;
}
public List<Exception> getHandlersForPc(int pc)
{
List<Exception> matches = new ArrayList<>();
for (Exception e : exceptions)
{

View File

@@ -6,6 +6,7 @@ import info.sigterm.deob.execution.Frame;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public abstract class Instruction
{
@@ -15,8 +16,9 @@ public abstract class Instruction
private int pc; // offset into method this instructions resides at
protected int length = 1; // length of this instruction
private ArrayList<Instruction> jump = new ArrayList<Instruction>(); // instructions which this instruction jumps to
private ArrayList<Instruction> from = new ArrayList<Instruction>(); // instructions which jump to this instruction
public List<Instruction> jump = new ArrayList<>(), // instructions which this instruction jumps to
from = new ArrayList<>(); // instructions which jump to this instruction
public List<Exception> exce = new ArrayList<>(); // exception handlers which start here
public Instruction(Instructions instructions, InstructionType type, int pc)
{
@@ -25,6 +27,16 @@ public abstract class Instruction
this.pc = pc;
}
protected void remove()
{
for (Instruction i : jump)
i.from.remove(this);
jump.clear();
assert from.isEmpty();
assert exce.isEmpty();
}
public void write(DataOutputStream out, int pc) throws IOException
{
out.writeByte(type.getCode());
@@ -78,4 +90,10 @@ public abstract class Instruction
}
public abstract void execute(Frame e);
/* does this terminate a block? */
public boolean isTerminal()
{
return false;
}
}

View File

@@ -55,6 +55,12 @@ public class Instructions
return instructions;
}
public void remove(Instruction ins)
{
ins.remove();
instructions.remove(ins);
}
public void write(DataOutputStream out) throws IOException
{
ByteArrayOutputStream b = new ByteArrayOutputStream();

View File

@@ -21,4 +21,10 @@ public class AThrow extends Instruction
ObjectInstance exception = (ObjectInstance) e.getStack().pop();
e.getPath().throwException(this, exception);
}
@Override
public boolean isTerminal()
{
return true;
}
}

View File

@@ -40,4 +40,10 @@ public class Goto extends Instruction
{
e.jump(offset);
}
@Override
public boolean isTerminal()
{
return true;
}
}

View File

@@ -40,4 +40,10 @@ public class GotoW extends Instruction
{
e.jump(offset);
}
@Override
public boolean isTerminal()
{
return true;
}
}

View File

@@ -83,4 +83,10 @@ public class LookupSwitch extends Instruction
Path p = e.getPath().dup();
p.getCurrentFrame().jump(def);
}
@Override
public boolean isTerminal()
{
return true;
}
}

View File

@@ -20,4 +20,10 @@ public class Return extends Instruction
Object ret = e.getStack().pop();
e.getPath().returnFrame(this, ret);
}
@Override
public boolean isTerminal()
{
return true;
}
}

View File

@@ -79,4 +79,10 @@ public class TableSwitch extends Instruction
Path p = e.getPath().dup();
p.getCurrentFrame().jump(def);
}
@Override
public boolean isTerminal()
{
return true;
}
}

View File

@@ -20,4 +20,10 @@ public class VReturn extends Instruction
// XXX exceptions?
e.getPath().returnFrame();
}
@Override
public boolean isTerminal()
{
return true;
}
}