Search in sources :

Example 6 with DupInstruction

use of net.runelite.asm.attributes.code.instruction.types.DupInstruction in project runelite by runelite.

the class DupDeobfuscator method visit.

private void visit(InstructionContext i) {
    if (!(i.getInstruction() instanceof DupInstruction)) {
        return;
    }
    DupInstruction di = (DupInstruction) i.getInstruction();
    // stack values being duplicated
    List<StackContext> sctxs = di.getDuplicated(i);
    for (StackContext sctx : sctxs) {
        InstructionContext ic = sctx.getPushed();
        if (ic.getInstruction() instanceof IMul) {
            if (i.getInstruction() instanceof Dup) {
                logger.debug("Dup instruction {} duplicates multiplication result {}", i, ic);
                undup(i);
                ++count;
                return;
            }
            if (i.getInstruction() instanceof Dup_X1) {
                logger.debug("Dup_X1 instruction {} duplicates multiplication result {}", i, ic);
                undup_x1(i);
                ++count;
                return;
            }
            logger.warn("Dup instruction {} pops imul", i);
        } else if (ic.getInstruction() instanceof LMul) {
            if (i.getInstruction() instanceof Dup2_X1) {
                logger.debug("Dup_X2 instruction {} duplicates multiplication result {}", i, ic);
                undup2_x1(i);
                ++count;
                return;
            }
            logger.warn("Dup instruction {} pops lmul", i);
        }
    }
    // find if mul pops anything duplicated
    sctxs = di.getCopies(i);
    for (StackContext sctx : sctxs) {
        for (InstructionContext ic : sctx.getPopped()) {
            if (ic.getInstruction() instanceof IMul) {
                if (i.getInstruction() instanceof Dup) {
                    logger.debug("imul {} pops dup instruction {}", ic, i);
                    undup(i);
                    ++count;
                    return;
                }
                if (i.getInstruction() instanceof Dup_X1) {
                    logger.debug("imul {} pops dup x1 instruction {}", ic, i);
                    undup_x1(i);
                    ++count;
                    return;
                }
                logger.warn("imul pops dup instruction {}", i);
            } else if (ic.getInstruction() instanceof LMul) {
                if (i.getInstruction() instanceof Dup2_X1) {
                    logger.debug("imul {} pops dup2 x1 instruction {}", ic, i);
                    undup2_x1(i);
                    ++count;
                    return;
                }
                logger.warn("lmul pops dup instruction {}", i);
            }
        }
    }
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) Dup2_X1(net.runelite.asm.attributes.code.instructions.Dup2_X1) StackContext(net.runelite.asm.execution.StackContext) Dup_X1(net.runelite.asm.attributes.code.instructions.Dup_X1) DupInstruction(net.runelite.asm.attributes.code.instruction.types.DupInstruction) IMul(net.runelite.asm.attributes.code.instructions.IMul) LMul(net.runelite.asm.attributes.code.instructions.LMul) Dup(net.runelite.asm.attributes.code.instructions.Dup)

Aggregations

DupInstruction (net.runelite.asm.attributes.code.instruction.types.DupInstruction)6 InstructionContext (net.runelite.asm.execution.InstructionContext)5 StackContext (net.runelite.asm.execution.StackContext)5 LVTInstruction (net.runelite.asm.attributes.code.instruction.types.LVTInstruction)3 SetFieldInstruction (net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction)2 Swap (net.runelite.asm.attributes.code.instructions.Swap)2 VariableContext (net.runelite.asm.execution.VariableContext)2 Variables (net.runelite.asm.execution.Variables)2 Instruction (net.runelite.asm.attributes.code.Instruction)1 ArrayLoad (net.runelite.asm.attributes.code.instruction.types.ArrayLoad)1 ConversionInstruction (net.runelite.asm.attributes.code.instruction.types.ConversionInstruction)1 GetFieldInstruction (net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction)1 InvokeInstruction (net.runelite.asm.attributes.code.instruction.types.InvokeInstruction)1 PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)1 BiPush (net.runelite.asm.attributes.code.instructions.BiPush)1 Dup (net.runelite.asm.attributes.code.instructions.Dup)1 Dup2_X1 (net.runelite.asm.attributes.code.instructions.Dup2_X1)1 Dup_X1 (net.runelite.asm.attributes.code.instructions.Dup_X1)1 IAdd (net.runelite.asm.attributes.code.instructions.IAdd)1 IInc (net.runelite.asm.attributes.code.instructions.IInc)1