Cleanup block removal
This commit is contained in:
10
src/main/java/info/sigterm/deob/attributes/code/Block.java
Normal file
10
src/main/java/info/sigterm/deob/attributes/code/Block.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package info.sigterm.deob.attributes.code;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Block
|
||||
{
|
||||
public Instruction begin, end;
|
||||
public List<Instruction> instructions = new ArrayList<>();
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import java.util.List;
|
||||
public abstract class Instruction
|
||||
{
|
||||
private Instructions instructions;
|
||||
public Block block;
|
||||
private InstructionType type;
|
||||
|
||||
private int pc; // offset into method this instructions resides at
|
||||
@@ -29,6 +30,8 @@ public abstract class Instruction
|
||||
|
||||
protected void remove()
|
||||
{
|
||||
assert block == null;
|
||||
|
||||
for (Instruction i : jump)
|
||||
i.from.remove(this);
|
||||
jump.clear();
|
||||
|
||||
@@ -14,6 +14,7 @@ public class Instructions
|
||||
{
|
||||
private Code code;
|
||||
private List<Instruction> instructions = new ArrayList<>();
|
||||
private List<Block> blocks = new ArrayList<>();
|
||||
|
||||
public Instructions(Code code) throws IOException
|
||||
{
|
||||
@@ -48,6 +49,7 @@ public class Instructions
|
||||
assert pc == length;
|
||||
|
||||
buildJumpGraph();
|
||||
buildBlocks();
|
||||
}
|
||||
|
||||
public List<Instruction> getInstructions()
|
||||
@@ -55,12 +57,46 @@ public class Instructions
|
||||
return instructions;
|
||||
}
|
||||
|
||||
public List<Block> getBlocks()
|
||||
{
|
||||
return blocks;
|
||||
}
|
||||
|
||||
public void remove(Instruction ins)
|
||||
{
|
||||
ins.remove();
|
||||
instructions.remove(ins);
|
||||
}
|
||||
|
||||
public void remove(Block block)
|
||||
{
|
||||
blocks.remove(block);
|
||||
|
||||
for (Instruction i : block.instructions)
|
||||
instructions.remove(i);
|
||||
}
|
||||
|
||||
public void buildBlocks()
|
||||
{
|
||||
Block current = null;
|
||||
for (Instruction i : instructions)
|
||||
{
|
||||
if (current == null)
|
||||
{
|
||||
current = new Block();
|
||||
current.begin = i;
|
||||
}
|
||||
i.block = current;
|
||||
current.instructions.add(i);
|
||||
if (i.isTerminal())
|
||||
{
|
||||
current.end = i;
|
||||
blocks.add(current);
|
||||
current = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void write(DataOutputStream out) throws IOException
|
||||
{
|
||||
ByteArrayOutputStream b = new ByteArrayOutputStream();
|
||||
|
||||
Reference in New Issue
Block a user