use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class ControlFlowDeobfuscator method split.
/**
* Add gotos at the end of blocks without terminal instructions
*
* @param code
*/
private void split(Code code) {
Instructions ins = code.getInstructions();
Exceptions exceptions = code.getExceptions();
ControlFlowGraph graph = new ControlFlowGraph.Builder().build(code);
List<Exception> exc = new ArrayList<>(exceptions.getExceptions());
// Must clear this before ins.clear() runs
exceptions.clear();
ins.clear();
// insert jumps where blocks flow into others
for (Block block : graph.getBlocks()) {
if (block.getFlowsInto() == null) {
continue;
}
Block into = block.getFlowsInto();
assert into.getFlowsFrom() == block;
Instruction first = into.getInstructions().get(0);
Label label;
if (!(first instanceof Label)) {
label = new Label(null);
into.addInstruction(0, label);
} else {
label = (Label) first;
}
Goto g = new Goto(null, label);
block.addInstruction(g);
block.setFlowsInto(null);
into.setFlowsFrom(null);
++insertedJump;
}
// Readd instructions from modified blocks
for (Block block : graph.getBlocks()) {
for (Instruction i : block.getInstructions()) {
assert i.getInstructions() == null;
// I shouldn't have to do this here
i.setInstructions(ins);
ins.addInstruction(i);
}
}
// Readd exceptions
for (Exception ex : exc) {
exceptions.add(ex);
}
}
use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class FieldInliner method findFieldIns.
private void findFieldIns() {
for (ClassFile cf : group.getClasses()) {
for (Method m : cf.getMethods()) {
Code code = m.getCode();
if (code == null)
continue;
for (Instruction i : code.getInstructions().getInstructions()) {
if (!(i instanceof FieldInstruction))
continue;
FieldInstruction sf = (FieldInstruction) i;
if (sf.getMyField() == null)
continue;
fieldInstructions.put(sf.getMyField(), sf);
}
}
}
}
use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class FieldInliner method inlineUse.
public int inlineUse() {
int count = 0;
for (Field f : fields) {
// replace getfield with constant push
List<FieldInstruction> fins = fieldInstructions.get(f).stream().filter(f2 -> f2 instanceof GetFieldInstruction).collect(Collectors.toList());
Object value = f.getValue();
for (FieldInstruction fin : fins) {
// remove fin, add push constant
Instruction i = (Instruction) fin;
Instruction pushIns = new LDC(i.getInstructions(), value);
List<Instruction> instructions = i.getInstructions().getInstructions();
int idx = instructions.indexOf(i);
assert idx != -1;
i.getInstructions().remove(i);
instructions.add(idx, pushIns);
++count;
}
f.getClassFile().removeField(f);
}
return count;
}
use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class IllegalStateExceptions method findInteresting.
/* find if, new, ..., athrow, replace with goto */
private void findInteresting(ClassGroup group) {
for (ClassFile cf : group.getClasses()) {
for (Method m : cf.getMethods()) {
Code c = m.getCode();
if (c == null)
continue;
Instructions instructions = c.getInstructions();
List<Instruction> ilist = instructions.getInstructions();
for (int i = 0; i < ilist.size(); ++i) {
Instruction ins = ilist.get(i);
if (// the if
!(ins instanceof ComparisonInstruction))
continue;
Instruction ins2 = ilist.get(i + 1);
if (!(ins2 instanceof New))
continue;
New new2 = (New) ins2;
net.runelite.asm.pool.Class clazz = new2.getNewClass();
if (!clazz.getName().contains("java/lang/IllegalStateException"))
continue;
interesting.add(ins);
}
}
}
}
use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class PacketHandlerOrder method insertPacketLength.
private void insertPacketLength(ClassGroup group, PacketTypeFinder ptf) {
PacketLengthFinder pfl = new PacketLengthFinder(group, ptf);
pfl.find();
GetStatic getArray = pfl.getGetArray();
// instruction to store packet length
PutStatic ps = pfl.getStore();
Instructions instructions = ps.getInstructions();
List<Instruction> ins = instructions.getInstructions();
Label getArrayLabel = instructions.createLabelFor(getArray);
Label storeLabel = instructions.createLabelFor(ps);
int idx = ins.indexOf(getArray);
assert idx != -1;
// to go before label, which must exist
--idx;
net.runelite.asm.pool.Field field = new net.runelite.asm.pool.Field(new net.runelite.asm.pool.Class(findClient(group).getName()), RUNELITE_PACKET, Type.BOOLEAN);
instructions.addInstruction(idx++, new GetStatic(instructions, field));
instructions.addInstruction(idx++, new IfEq(instructions, getArrayLabel));
// 2 byte length
instructions.addInstruction(idx++, new LDC(instructions, -2));
instructions.addInstruction(idx++, new Goto(instructions, storeLabel));
}
Aggregations