Search in sources :

Example 1 with If0

use of net.runelite.asm.attributes.code.instructions.If0 in project runelite by runelite.

the class ModArith method getInsInExpr.

private static List<InstructionContext> getInsInExpr(InstructionContext ctx, Set<Instruction> set, boolean imul) {
    List<InstructionContext> l = new ArrayList<>();
    if (ctx == null || set.contains(ctx.getInstruction())) {
        return l;
    }
    set.add(ctx.getInstruction());
    if (imul) {
        if (!(ctx.getInstruction() instanceof IMul) & !(ctx.getInstruction() instanceof LMul)) {
            l.add(ctx);
            return l;
        }
    } else {
        // invoke and array store pops are unrelated to each other
        if (ctx.getInstruction() instanceof InvokeInstruction || ctx.getInstruction() instanceof ArrayStoreInstruction || ctx.getInstruction() instanceof ArrayLoad || ctx.getInstruction() instanceof If || ctx.getInstruction() instanceof If0 || ctx.getInstruction() instanceof LCmp || ctx.getInstruction() instanceof DivisionInstruction || ctx.getInstruction() instanceof IShR) {
            return l;
        }
        l.add(ctx);
    }
    for (StackContext s : ctx.getPops()) {
        l.addAll(getInsInExpr(s.getPushed(), set, imul));
    }
    for (StackContext s : ctx.getPushes()) {
        for (InstructionContext i : s.getPopped()) {
            l.addAll(getInsInExpr(i, set, imul));
        }
    }
    return l;
}
Also used : ArrayLoad(net.runelite.asm.attributes.code.instruction.types.ArrayLoad) InstructionContext(net.runelite.asm.execution.InstructionContext) DivisionInstruction(net.runelite.asm.attributes.code.instruction.types.DivisionInstruction) ArrayList(java.util.ArrayList) ArrayStoreInstruction(net.runelite.asm.attributes.code.instruction.types.ArrayStoreInstruction) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) If0(net.runelite.asm.attributes.code.instructions.If0) IShR(net.runelite.asm.attributes.code.instructions.IShR) StackContext(net.runelite.asm.execution.StackContext) IMul(net.runelite.asm.attributes.code.instructions.IMul) LCmp(net.runelite.asm.attributes.code.instructions.LCmp) LMul(net.runelite.asm.attributes.code.instructions.LMul) If(net.runelite.asm.attributes.code.instructions.If)

Example 2 with If0

use of net.runelite.asm.attributes.code.instructions.If0 in project runelite by runelite.

the class PacketWriteDeobfuscator method isEnd.

private boolean isEnd(InstructionContext ctx) {
    // conditions where packet write ends:
    // any invoke that isn't to the packet buffer
    // any variable assignment
    // any field assignment
    // any conditional jump
    // any return
    Instruction i = ctx.getInstruction();
    if (i instanceof InvokeInstruction) {
        InvokeInstruction ii = (InvokeInstruction) i;
        Method method = ii.getMethod();
        if (!method.getClazz().equals(rw.getSecretBuffer().getPoolClass()) && !method.getClazz().equals(rw.getBuffer().getPoolClass())) {
            return true;
        }
    }
    if (i instanceof LVTInstruction) {
        LVTInstruction lvt = (LVTInstruction) i;
        if (lvt.store()) {
            return true;
        }
    }
    if (i instanceof SetFieldInstruction) {
        return true;
    }
    if (i instanceof If || i instanceof If0) {
        return true;
    }
    if (i instanceof ReturnInstruction) {
        return true;
    }
    return false;
}
Also used : InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) ReturnInstruction(net.runelite.asm.attributes.code.instruction.types.ReturnInstruction) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) If0(net.runelite.asm.attributes.code.instructions.If0) Method(net.runelite.asm.pool.Method) 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) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) If(net.runelite.asm.attributes.code.instructions.If)

Example 3 with If0

use of net.runelite.asm.attributes.code.instructions.If0 in project runelite by runelite.

the class ConstantParameter method findDeadParameters.

private void findDeadParameters(InstructionContext ins) {
    List<ConstantMethodParameter> parameters = this.findParametersForMethod(ins.getFrame().getMethod());
    for (ConstantMethodParameter parameter : parameters) {
        int lvtIndex = parameter.lvtIndex;
        if (parameter.invalid) {
            continue;
        }
        if (ins.getInstruction() instanceof LVTInstruction) {
            LVTInstruction lvt = (LVTInstruction) ins.getInstruction();
            if (lvt.getVariableIndex() != lvtIndex) {
                continue;
            }
            if (lvt.store() || ins.getInstruction().getType() == InstructionType.IINC) {
                parameter.invalid = true;
                // value changes at some point, parameter is used
                continue;
            }
            // check what pops the parameter is a comparison
            assert ins.getPushes().size() == 1;
            StackContext sctx = ins.getPushes().get(0);
            if (sctx.getPopped().size() != 1 || !(sctx.getPopped().get(0).getInstruction() instanceof ComparisonInstruction)) {
                parameter.invalid = true;
                continue;
            }
        }
        if (!(ins.getInstruction() instanceof ComparisonInstruction)) {
            continue;
        }
        // assume that this will always be variable index #paramIndex comp with a constant.
        ComparisonInstruction comp = (ComparisonInstruction) ins.getInstruction();
        StackContext one, two = null;
        if (comp instanceof If0) {
            one = ins.getPops().get(0);
        } else if (comp instanceof If) {
            one = ins.getPops().get(0);
            two = ins.getPops().get(1);
        } else {
            throw new RuntimeException("Unknown comp ins");
        }
        // find if one is a lvt ins
        LVTInstruction lvt = null;
        StackContext other = null;
        if (one.getPushed().getInstruction() instanceof LVTInstruction) {
            lvt = (LVTInstruction) one.getPushed().getInstruction();
            other = two;
        } else if (two != null && two.getPushed().getInstruction() instanceof LVTInstruction) {
            lvt = (LVTInstruction) two.getPushed().getInstruction();
            other = one;
        }
        assert lvt == null || !lvt.store();
        if (lvt == null || lvt.getVariableIndex() != lvtIndex) {
            continue;
        }
        Number otherValue = null;
        if (// two is null for if0
        two != null) {
            if (!(other.getPushed().getInstruction() instanceof PushConstantInstruction)) {
                parameter.invalid = true;
                continue;
            }
            PushConstantInstruction pc = (PushConstantInstruction) other.getPushed().getInstruction();
            otherValue = (Number) pc.getConstant();
        }
        for (Number value : parameter.values) {
            // the result of the comparison doesn't matter, only that it always goes the same direction for every invocation
            boolean result = doLogicalComparison(value, comp, otherValue);
            // not that all ifs for a specific parameter always take the same path
            if (parameter.result != null && parameter.result != result) {
                parameter.invalid = true;
            } else {
                parameter.operations.add(ins.getInstruction());
                parameter.result = result;
            }
        }
    }
}
Also used : If0(net.runelite.asm.attributes.code.instructions.If0) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) StackContext(net.runelite.asm.execution.StackContext) ComparisonInstruction(net.runelite.asm.attributes.code.instruction.types.ComparisonInstruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) If(net.runelite.asm.attributes.code.instructions.If)

Aggregations

If (net.runelite.asm.attributes.code.instructions.If)3 If0 (net.runelite.asm.attributes.code.instructions.If0)3 InvokeInstruction (net.runelite.asm.attributes.code.instruction.types.InvokeInstruction)2 LVTInstruction (net.runelite.asm.attributes.code.instruction.types.LVTInstruction)2 StackContext (net.runelite.asm.execution.StackContext)2 ArrayList (java.util.ArrayList)1 Instruction (net.runelite.asm.attributes.code.Instruction)1 ArrayLoad (net.runelite.asm.attributes.code.instruction.types.ArrayLoad)1 ArrayStoreInstruction (net.runelite.asm.attributes.code.instruction.types.ArrayStoreInstruction)1 ComparisonInstruction (net.runelite.asm.attributes.code.instruction.types.ComparisonInstruction)1 DivisionInstruction (net.runelite.asm.attributes.code.instruction.types.DivisionInstruction)1 PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)1 ReturnInstruction (net.runelite.asm.attributes.code.instruction.types.ReturnInstruction)1 SetFieldInstruction (net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction)1 IMul (net.runelite.asm.attributes.code.instructions.IMul)1 IShR (net.runelite.asm.attributes.code.instructions.IShR)1 LCmp (net.runelite.asm.attributes.code.instructions.LCmp)1 LMul (net.runelite.asm.attributes.code.instructions.LMul)1 InstructionContext (net.runelite.asm.execution.InstructionContext)1 Method (net.runelite.asm.pool.Method)1