Build jump graph
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
package info.sigterm.deob.attributes.code;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Instruction
|
||||
{
|
||||
private Instructions instructions;
|
||||
private InstructionType type;
|
||||
private int pc;
|
||||
protected int length = 1;
|
||||
|
||||
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 Instruction(Instructions instructions, InstructionType type, int pc)
|
||||
{
|
||||
@@ -14,8 +20,27 @@ public class Instruction
|
||||
this.pc = pc;
|
||||
}
|
||||
|
||||
public int getPc()
|
||||
{
|
||||
return pc;
|
||||
}
|
||||
|
||||
public int getLength()
|
||||
{
|
||||
return length;
|
||||
}
|
||||
|
||||
protected void addJump(int offset)
|
||||
{
|
||||
Instruction other = instructions.findInstruction(pc + offset);
|
||||
assert other != null;
|
||||
assert other != this;
|
||||
|
||||
this.jump.add(other);
|
||||
other.from.add(this);
|
||||
}
|
||||
|
||||
public void buildJumpGraph()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,10 +43,26 @@ public class Instructions
|
||||
}
|
||||
|
||||
assert pc == length;
|
||||
|
||||
buildJumpGraph();
|
||||
}
|
||||
|
||||
private void buildJumpGraph()
|
||||
{
|
||||
for (Instruction i : instructions)
|
||||
i.buildJumpGraph();
|
||||
}
|
||||
|
||||
public Code getCode()
|
||||
{
|
||||
return code;
|
||||
}
|
||||
|
||||
public Instruction findInstruction(int pc)
|
||||
{
|
||||
for (Instruction i : instructions)
|
||||
if (i.getPc() == pc)
|
||||
return i;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,4 +20,9 @@ public class Branch extends Instruction
|
||||
length += 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildJumpGraph()
|
||||
{
|
||||
this.addJump(offset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,4 +20,9 @@ public class GotoW extends Instruction
|
||||
length += 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildJumpGraph()
|
||||
{
|
||||
this.addJump(offset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,4 +20,9 @@ public class JSR_W extends Instruction
|
||||
length += 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildJumpGraph()
|
||||
{
|
||||
this.addJump(offset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,4 +37,12 @@ public class LookupSwitch extends Instruction
|
||||
|
||||
length += tableSkip + 8 + (count * 8);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildJumpGraph()
|
||||
{
|
||||
for (int i : branch)
|
||||
this.addJump(i);
|
||||
this.addJump(def);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,4 +35,12 @@ public class TableSwitch extends Instruction
|
||||
|
||||
length += tableSkip + 12 + (count * 4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildJumpGraph()
|
||||
{
|
||||
for (int i : jumps)
|
||||
this.addJump(i);
|
||||
this.addJump(def);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user