use of net.runelite.asm.attributes.code.instructions.Goto in project runelite by runelite.
the class PacketWriteDeobfuscator method insert.
private void insert(ClassGroup group, PacketWrite write) {
Instructions instructions = write.putOpcode.getInstruction().getInstructions();
List<Instruction> ins = instructions.getInstructions();
InstructionContext firstWrite = write.writes.get(0);
InstructionContext lastWrite = write.writes.get(write.writes.size() - 1);
int idx = ins.indexOf(lastWrite.getInstruction());
assert idx != -1;
// past write
++idx;
Label afterWrites = instructions.createLabelFor(ins.get(idx));
// pops arg, getfield
InstructionContext beforeFirstWrite = firstWrite.getPops().get(1).getPushed();
Label putOpcode = instructions.createLabelFor(beforeFirstWrite.getInstruction(), true);
idx = ins.indexOf(beforeFirstWrite.getInstruction());
assert idx != -1;
--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, putOpcode));
Instruction before = ins.get(idx);
for (InstructionContext ctx : write.writes) {
insert(instructions, ctx, before);
}
idx = ins.indexOf(before);
instructions.addInstruction(idx++, new Goto(instructions, afterWrites));
}
use of net.runelite.asm.attributes.code.instructions.Goto in project runelite by runelite.
the class ConstantParameter method removeDeadOperations.
// remove logically dead comparisons
private int removeDeadOperations(MethodContext mctx) {
int count = 0;
for (ConstantMethodParameter cmp : parameters.values()) {
if (cmp.invalid) {
continue;
}
if (!cmp.methods.contains(mctx.getMethod())) {
continue;
}
// only annotate garbage value of last param
if (cmp.paramIndex + 1 == mctx.getMethod().getDescriptor().size()) {
annotateObfuscatedSignature(cmp);
}
for (// comparisons
Instruction ins : // comparisons
cmp.operations) {
if (ins.getInstructions() == null || ins.getInstructions().getCode().getMethod() != mctx.getMethod()) {
continue;
}
InstructionContext ctx = mctx.getInstructonContexts(ins).toArray(new InstructionContext[0])[0];
// branch that is always taken
boolean branch = cmp.result;
if (ins.getInstructions() == null) {
// ins already removed?
continue;
}
Instructions instructions = ins.getInstructions();
// remove the if
if (ctx.getInstruction() instanceof If) {
ctx.removeStack(1);
}
ctx.removeStack(0);
int idx = instructions.getInstructions().indexOf(ins);
if (idx == -1) {
// already removed?
continue;
}
++count;
Instruction to;
if (branch) {
JumpingInstruction jumpIns = (JumpingInstruction) ins;
assert jumpIns.getJumps().size() == 1;
to = jumpIns.getJumps().get(0);
} else {
// just go to next instruction
to = instructions.getInstructions().get(idx + 1);
}
assert to.getInstructions() == instructions;
assert ins != to;
assert instructions.getInstructions().contains(to);
instructions.remove(ins);
assert instructions.getInstructions().contains(to);
if (branch) {
Goto gotoins = new Goto(instructions, instructions.createLabelFor(to));
// insert goto
instructions.getInstructions().add(idx, gotoins);
}
}
}
return count;
}
Aggregations