Search in sources :

Example 1 with InvokeInstruction

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

the class PacketWriteDeobfuscator method visit.

public void visit(InstructionContext ctx) {
    if (isEnd(ctx)) {
        end();
        return;
    }
    if (ctx.getInstruction().getType() != INVOKEVIRTUAL) {
        return;
    }
    InvokeInstruction ii = (InvokeInstruction) ctx.getInstruction();
    if (ii.getMethods().contains(rw.getWriteOpcode())) {
        end();
        PacketWrite write = start();
        write.putOpcode = ctx;
        return;
    }
    PacketWrite write = cur;
    if (write == null) {
        return;
    }
    if (!ii.getMethod().getClazz().getName().equals(rw.getWriteOpcode().getClassFile().getSuperName())) {
        return;
    }
    write.writes.add(ctx);
}
Also used : InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction)

Example 2 with InvokeInstruction

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

the class GetPathTransformer method transform.

private void transform(Method m) {
    int count = 0;
    if (m.getCode() == null) {
        return;
    }
    for (Instruction i : m.getCode().getInstructions().getInstructions()) {
        if (i instanceof InvokeInstruction) {
            InvokeInstruction ii = (InvokeInstruction) i;
            if (ii.getMethod().getName().equals("getPath")) {
                if (++count == 2) {
                    removeInvoke(i);
                    done = true;
                    break;
                }
            }
        }
    }
}
Also used : InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) Instruction(net.runelite.asm.attributes.code.Instruction)

Example 3 with InvokeInstruction

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

the class MappingExecutorUtil method resolve.

public static InstructionContext resolve(InstructionContext ctx, // pushed from ctx
StackContext from) {
    if (ctx.getInstruction() instanceof SetFieldInstruction) {
        StackContext s = ctx.getPops().get(0);
        return resolve(s.getPushed(), s);
    }
    if (ctx.getInstruction() instanceof ConversionInstruction) {
        // assume it pops one and pushes one
        StackContext s = ctx.getPops().get(0);
        return resolve(s.getPushed(), s);
    }
    if (ctx.getInstruction() instanceof DupInstruction) {
        DupInstruction d = (DupInstruction) ctx.getInstruction();
        StackContext s = d.getOriginal(from);
        return resolve(s.getPushed(), s);
    }
    if (ctx.getInstruction() instanceof ArrayLoad) {
        // might be multidimensional array
        // the array
        StackContext s = ctx.getPops().get(1);
        return resolve(s.getPushed(), s);
    }
    if (ctx.getInstruction() instanceof LVTInstruction) {
        LVTInstruction lvt = (LVTInstruction) ctx.getInstruction();
        Variables variables = ctx.getVariables();
        if (lvt.store()) {
            // is this right?
            StackContext s = ctx.getPops().get(0);
            return resolve(s.getPushed(), s);
        } else {
            // variable being loaded
            VariableContext vctx = variables.get(lvt.getVariableIndex());
            assert vctx != null;
            InstructionContext storedCtx = vctx.getInstructionWhichStored();
            if (storedCtx == null)
                // initial parameter
                return ctx;
            if (vctx.isIsParameter()) {
                // this storedCtx is the invoke instruction which called this method.
                assert storedCtx.getInstruction() instanceof InvokeInstruction;
                // In PME non static functions are never stepped into/aren't inline obfuscated
                assert storedCtx.getInstruction() instanceof InvokeStatic;
                // Figure out parameter index from variable index.
                // signature of current method
                Signature sig = ctx.getFrame().getMethod().getDescriptor();
                int paramIndex = 0;
                for (int lvtIndex = 0; /* static */
                paramIndex < sig.size(); lvtIndex += sig.getTypeOfArg(paramIndex++).getSize()) if (lvtIndex == lvt.getVariableIndex())
                    break;
                assert paramIndex < sig.size();
                // Get stack context that was popped by the invoke
                // pops[0] is the first thing popped, which is the last parameter.
                StackContext sctx = storedCtx.getPops().get(sig.size() - 1 - paramIndex);
                return resolve(sctx.getPushed(), sctx);
            }
            return resolve(storedCtx, null);
        }
    }
    if (ctx.getInstruction() instanceof InvokeStatic) {
        if (from.returnSource != null) {
            return resolve(from.returnSource.getPushed(), from.returnSource);
        }
    }
    return ctx;
}
Also used : ArrayLoad(net.runelite.asm.attributes.code.instruction.types.ArrayLoad) InstructionContext(net.runelite.asm.execution.InstructionContext) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) ConversionInstruction(net.runelite.asm.attributes.code.instruction.types.ConversionInstruction) DupInstruction(net.runelite.asm.attributes.code.instruction.types.DupInstruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) VariableContext(net.runelite.asm.execution.VariableContext) Variables(net.runelite.asm.execution.Variables) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) StackContext(net.runelite.asm.execution.StackContext) Signature(net.runelite.asm.signature.Signature) InvokeStatic(net.runelite.asm.attributes.code.instructions.InvokeStatic)

Example 4 with InvokeInstruction

use of net.runelite.asm.attributes.code.instruction.types.InvokeInstruction 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 5 with InvokeInstruction

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

the class UnusedMethods method run.

private void run(Method method) {
    Code code = method.getCode();
    if (code == null) {
        return;
    }
    for (Instruction i : code.getInstructions().getInstructions()) {
        if (!(i instanceof InvokeInstruction)) {
            continue;
        }
        InvokeInstruction ii = (InvokeInstruction) i;
        methods.addAll(ii.getMethods());
    }
}
Also used : InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code)

Aggregations

InvokeInstruction (net.runelite.asm.attributes.code.instruction.types.InvokeInstruction)15 Instruction (net.runelite.asm.attributes.code.Instruction)10 LVTInstruction (net.runelite.asm.attributes.code.instruction.types.LVTInstruction)8 ArrayList (java.util.ArrayList)5 Method (net.runelite.asm.Method)5 InstructionContext (net.runelite.asm.execution.InstructionContext)5 Signature (net.runelite.asm.signature.Signature)5 Code (net.runelite.asm.attributes.Code)4 List (java.util.List)3 ClassFile (net.runelite.asm.ClassFile)3 Field (net.runelite.asm.Field)3 Type (net.runelite.asm.Type)3 PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)3 InvokeStatic (net.runelite.asm.attributes.code.instructions.InvokeStatic)3 StackContext (net.runelite.asm.execution.StackContext)3 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ClassGroup (net.runelite.asm.ClassGroup)2 InstructionType (net.runelite.asm.attributes.code.InstructionType)2