Use more descriptive names in Block (+lombok)

This commit is contained in:
Lucwousin
2020-07-16 03:48:05 +02:00
parent 29105c9501
commit 42affee0f0
4 changed files with 27 additions and 78 deletions

View File

@@ -99,7 +99,7 @@ public class Annotation extends AnnotationVisitor implements Comparable<Annotati
public Object getValue() public Object getValue()
{ {
return data.get("value"); return get("value");
} }
public String getValueString() public String getValueString()

View File

@@ -26,9 +26,13 @@ package net.runelite.deob.deobfuscators.cfg;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import lombok.Getter;
import lombok.Setter;
import net.runelite.asm.attributes.code.Instruction; import net.runelite.asm.attributes.code.Instruction;
import net.runelite.asm.attributes.code.Label; import net.runelite.asm.attributes.code.Label;
@Getter
@Setter
public class Block public class Block
{ {
private int id = -1; private int id = -1;
@@ -37,64 +41,44 @@ public class Block
/** /**
* blocks which jump here * blocks which jump here
*/ */
private final List<Block> pred = new ArrayList<>(); private final List<Block> preds = new ArrayList<>();
/** /**
* blocks which this jumps to * blocks which this jumps to
*/ */
private final List<Block> succ = new ArrayList<>(); private final List<Block> succs = new ArrayList<>();
/** /**
* block which flows directly into this block * block which flows directly into this block
*/ */
private Block from; private Block pred;
/** /**
* block which this directly flows into * block which this directly flows into
*/ */
private Block into; private Block succ;
/** /**
* instructions in this block * instructions in this block
*/ */
private final List<Instruction> instructions = new ArrayList<>(); private final List<Instruction> instructions = new ArrayList<>();
public int getId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
public boolean isJumptarget()
{
return jumptarget;
}
public void setJumptarget(boolean jumptarget)
{
this.jumptarget = jumptarget;
}
@Override @Override
public String toString() public String toString()
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("Block ID ").append(id).append("\n"); sb.append("Block ID ").append(id).append("\n");
if (from != null) if (pred != null)
{ {
sb.append(" flows from ").append(from.id).append("\n"); sb.append(" flows from ").append(pred.id).append("\n");
} }
for (Instruction i : instructions) for (Instruction i : instructions)
{ {
sb.append(" ").append(i.toString()).append("\n"); sb.append(" ").append(i.toString()).append("\n");
} }
if (into != null) if (succ != null)
{ {
sb.append(" flows into ").append(into.id).append("\n"); sb.append(" flows into ").append(succ.id).append("\n");
} }
sb.append("\n"); sb.append("\n");
return sb.toString(); return sb.toString();
@@ -112,57 +96,22 @@ public class Block
instructions.add(i); instructions.add(i);
} }
public List<Instruction> getInstructions()
{
return instructions;
}
public void addPrev(Block block) public void addPrev(Block block)
{ {
if (!pred.contains(block)) if (!preds.contains(block))
{ {
pred.add(block); preds.add(block);
} }
} }
public List<Block> getPred()
{
return pred;
}
public void addNext(Block block) public void addNext(Block block)
{ {
if (!succ.contains(block)) if (!succs.contains(block))
{ {
succ.add(block); succs.add(block);
} }
} }
public List<Block> getSucc()
{
return succ;
}
public Block getFrom()
{
return from;
}
public void setFrom(Block from)
{
this.from = from;
}
public Block getInto()
{
return into;
}
public void setInto(Block into)
{
this.into = into;
}
static int compare(Block a, Block b) static int compare(Block a, Block b)
{ {
final int l1 = a.getLineNumber(); final int l1 = a.getLineNumber();

View File

@@ -90,12 +90,12 @@ public class ControlFlowDeobfuscator implements Deobfuscator
ins.addInstruction(i); ins.addInstruction(i);
i.setInstructions(ins); i.setInstructions(ins);
} }
if (b.getInto() != null && b.getInstructions().size() > 0) if (b.getSucc() != null && b.getInstructions().size() > 0)
{ {
final var i = b.getInstructions().get(b.getInstructions().size() - 1); final var i = b.getInstructions().get(b.getInstructions().size() - 1);
if (!i.isTerminal()) if (!i.isTerminal())
{ {
final var next = b.getInto(); final var next = b.getSucc();
var maybeLabel = next.getInstructions().get(0); var maybeLabel = next.getInstructions().get(0);
if (!(maybeLabel instanceof Label)) if (!(maybeLabel instanceof Label))
{ {

View File

@@ -73,11 +73,11 @@ public class ControlFlowGraph
: cur.getInstructions().get(cur.getInstructions().size() - 1); : cur.getInstructions().get(cur.getInstructions().size() - 1);
if (last == null || !last.isTerminal()) if (last == null || !last.isTerminal())
{ {
assert next.getFrom() == null; assert next.getPred() == null;
assert cur.getInto() == null; assert cur.getSucc() == null;
// previous block flows directly into next // previous block flows directly into next
next.setFrom(cur); next.setPred(cur);
cur.setInto(next); cur.setSucc(next);
} }
cur = next; cur = next;
} }
@@ -99,7 +99,7 @@ public class ControlFlowGraph
} }
} }
assert head.getFrom() == null; assert head.getPred() == null;
} }
List<Block> topologicalSort() List<Block> topologicalSort()
@@ -112,10 +112,10 @@ public class ControlFlowGraph
private static void walk(Block cur, List<Block> order, Set<Block> done) private static void walk(Block cur, List<Block> order, Set<Block> done)
{ {
Block dirsucc = cur.getInto(); Block dirsucc = cur.getSucc();
if (dirsucc != null && done.add(dirsucc)) if (dirsucc != null && done.add(dirsucc))
walk(cur.getInto(), order, done); walk(cur.getSucc(), order, done);
List<Block> succs = cur.getSucc(); List<Block> succs = cur.getSuccs();
succs.sort(Block::compare); succs.sort(Block::compare);
for (Block succ : succs) for (Block succ : succs)
if (done.add(succ)) if (done.add(succ))