Search in sources :

Example 11 with Goto

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));
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) Goto(net.runelite.asm.attributes.code.instructions.Goto) Label(net.runelite.asm.attributes.code.Label) Instructions(net.runelite.asm.attributes.code.Instructions) IfEq(net.runelite.asm.attributes.code.instructions.IfEq) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) ReturnInstruction(net.runelite.asm.attributes.code.instruction.types.ReturnInstruction) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) GetStatic(net.runelite.asm.attributes.code.instructions.GetStatic)

Example 12 with Goto

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;
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) JumpingInstruction(net.runelite.asm.attributes.code.instruction.types.JumpingInstruction) Goto(net.runelite.asm.attributes.code.instructions.Goto) Instructions(net.runelite.asm.attributes.code.Instructions) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) JumpingInstruction(net.runelite.asm.attributes.code.instruction.types.JumpingInstruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) ComparisonInstruction(net.runelite.asm.attributes.code.instruction.types.ComparisonInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) If(net.runelite.asm.attributes.code.instructions.If)

Aggregations

Instruction (net.runelite.asm.attributes.code.Instruction)12 Goto (net.runelite.asm.attributes.code.instructions.Goto)12 Instructions (net.runelite.asm.attributes.code.Instructions)11 Label (net.runelite.asm.attributes.code.Label)9 LVTInstruction (net.runelite.asm.attributes.code.instruction.types.LVTInstruction)6 ComparisonInstruction (net.runelite.asm.attributes.code.instruction.types.ComparisonInstruction)5 InvokeInstruction (net.runelite.asm.attributes.code.instruction.types.InvokeInstruction)5 JumpingInstruction (net.runelite.asm.attributes.code.instruction.types.JumpingInstruction)5 PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)5 IfEq (net.runelite.asm.attributes.code.instructions.IfEq)5 LDC (net.runelite.asm.attributes.code.instructions.LDC)5 ArrayList (java.util.ArrayList)4 ClassGroup (net.runelite.asm.ClassGroup)4 SetFieldInstruction (net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction)4 If (net.runelite.asm.attributes.code.instructions.If)4 Execution (net.runelite.asm.execution.Execution)4 Deobfuscator (net.runelite.deob.Deobfuscator)4 Code (net.runelite.asm.attributes.Code)3 GetFieldInstruction (net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction)3 MappableInstruction (net.runelite.asm.attributes.code.instruction.types.MappableInstruction)3