use of net.runelite.asm.attributes.code.Instructions in project runelite by runelite.
the class ModArith method insertGetterSetterMuls.
private void insertGetterSetterMuls(Encryption encr) {
// before setfield insert imul * getter
for (ClassFile cf : group.getClasses()) {
for (Method m : cf.getMethods()) {
Code code = m.getCode();
if (code == null) {
continue;
}
Instructions ins = code.getInstructions();
List<Instruction> ilist = ins.getInstructions();
for (int i = 0; i < ilist.size(); ++i) {
Instruction in = ilist.get(i);
if (in instanceof SetFieldInstruction) {
SetFieldInstruction sfi = (SetFieldInstruction) in;
Field f = sfi.getMyField();
if (f == null) {
continue;
}
Pair p = encr.getField(f.getPoolField());
if (p == null) {
continue;
}
// insert imul
if (p.getType() == Integer.class) {
ilist.add(i++, new LDC(ins, (int) p.getter));
ilist.add(i++, new IMul(ins));
} else if (p.getType() == Long.class) {
ilist.add(i++, new LDC(ins, (long) p.getter));
ilist.add(i++, new LMul(ins));
} else {
throw new IllegalStateException();
}
} else if (in instanceof GetFieldInstruction) {
GetFieldInstruction sfi = (GetFieldInstruction) in;
Field f = sfi.getMyField();
if (f == null) {
continue;
}
Pair p = encr.getField(f.getPoolField());
if (p == null) {
continue;
}
// imul
if (p.getType() == Integer.class) {
ilist.add(++i, new LDC(ins, (int) p.setter));
ilist.add(++i, new IMul(ins));
} else if (p.getType() == Long.class) {
ilist.add(++i, new LDC(ins, (long) p.setter));
ilist.add(++i, new LMul(ins));
} else {
throw new IllegalStateException();
}
}
}
}
}
}
use of net.runelite.asm.attributes.code.Instructions in project runelite by runelite.
the class ControlFlowDeobfuscator method runJumpLabel.
/**
* remove jumps followed immediately by the label they are jumping to
*
* @param code
*/
private void runJumpLabel(Code code) {
Instructions ins = code.getInstructions();
List<Instruction> instructions = ins.getInstructions();
for (int i = 0; i < instructions.size() - 1; ++i) {
Instruction i1 = instructions.get(i), i2 = instructions.get(i + 1);
if (!(i1 instanceof Goto)) {
continue;
}
Goto g = (Goto) i1;
assert g.getJumps().size() == 1;
if (g.getJumps().get(0) != i2) {
continue;
}
// remove jump
ins.remove(i1);
++removedJumps;
// i now points to i2, so next loop we go to next instruction
}
}
use of net.runelite.asm.attributes.code.Instructions 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.Instructions 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.Instructions 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);
}
}
}
}
Aggregations