Search in sources :

Example 41 with Instruction

use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.

the class DupDeobfuscator method copy.

/**
 * copy the instruction which pushed sctx and insert into instructions
 * starting at index idx
 */
private int copy(StackContext sctx, Instructions instructions, int idx) {
    InstructionContext ictx = sctx.getPushed();
    if (ictx.getInstruction() instanceof DupInstruction) {
        // we only care about one path
        DupInstruction di = (DupInstruction) ictx.getInstruction();
        sctx = di.getOriginal(sctx);
        ictx = sctx.getPushed();
    }
    // the first thing popped was pushed last, so reverse
    for (StackContext s : Lists.reverse(ictx.getPops())) {
        idx = copy(s, instructions, idx);
    }
    // copy instruction
    Instruction i = ictx.getInstruction();
    logger.debug("Duplicating instruction {} at index {}", i, idx);
    i = i.clone();
    instructions.addInstruction(idx, i);
    // move on to next instruction
    return idx + 1;
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) StackContext(net.runelite.asm.execution.StackContext) DupInstruction(net.runelite.asm.attributes.code.instruction.types.DupInstruction) DupInstruction(net.runelite.asm.attributes.code.instruction.types.DupInstruction) Instruction(net.runelite.asm.attributes.code.Instruction)

Example 42 with Instruction

use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.

the class PutField method canMap.

@Override
public boolean canMap(InstructionContext thisIc) {
    StackContext value = thisIc.getPops().get(0);
    Instruction i = value.getPushed().getInstruction();
    // which are all constants, so we ignore those mappings here
    if (thisIc.getFrame().getMethod().getName().equals("<init>")) {
        if (i instanceof PushConstantInstruction || i instanceof AConstNull) {
            return false;
        }
    }
    return true;
}
Also used : PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) StackContext(net.runelite.asm.execution.StackContext) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction) Instruction(net.runelite.asm.attributes.code.Instruction)

Example 43 with Instruction

use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.

the class ExprArgOrder method hash.

private static void hash(Method method, MessageDigest sha256, InstructionContext ic) {
    Instruction i = ic.getInstruction();
    // this relies on all push constants are converted to ldc..
    sha256.update((byte) i.getType().getCode());
    if (i instanceof PushConstantInstruction) {
        PushConstantInstruction pci = (PushConstantInstruction) i;
        Object constant = pci.getConstant();
        if (constant instanceof Number) {
            long l = ((Number) constant).longValue();
            sha256.update(Longs.toByteArray(l));
        }
    } else if (i instanceof LVTInstruction) {
        int idx = ((LVTInstruction) i).getVariableIndex();
        Signature signature = method.getDescriptor();
        int lvt = method.isStatic() ? 0 : 1;
        for (Type type : signature.getArguments()) {
            if (idx == lvt) {
                // Accessing a method parameter
                sha256.update(Ints.toByteArray(idx));
                break;
            }
            lvt += type.getSize();
        }
    }
    for (StackContext sctx : ic.getPops()) {
        hash(method, sha256, sctx.getPushed());
    }
}
Also used : InstructionType(net.runelite.asm.attributes.code.InstructionType) Type(net.runelite.asm.Type) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) StackContext(net.runelite.asm.execution.StackContext) Signature(net.runelite.asm.signature.Signature) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction)

Example 44 with Instruction

use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.

the class ExprArgOrder method compare.

public static int compare(Method method, InstructionType type, InstructionContext ic1, InstructionContext ic2) {
    Instruction i1 = ic1.getInstruction();
    Instruction i2 = ic2.getInstruction();
    if (type == IF_ICMPEQ || type == IF_ICMPNE || type == IADD || type == IMUL) {
        if (!(i1 instanceof PushConstantInstruction) && (i2 instanceof PushConstantInstruction)) {
            return 1;
        }
        if (i1 instanceof PushConstantInstruction && !(i2 instanceof PushConstantInstruction)) {
            return -1;
        }
    }
    if (type == IF_ACMPEQ || type == IF_ACMPNE) {
        if (!(i1 instanceof AConstNull) && (i2 instanceof AConstNull)) {
            return 1;
        }
        if (i1 instanceof AConstNull && !(i2 instanceof AConstNull)) {
            return -1;
        }
    }
    int hash1 = hash(method, ic1);
    int hash2 = hash(method, ic2);
    if (hash1 == hash2) {
        logger.debug("Unable to differentiate {} from {}", ic1, ic2);
    }
    return Integer.compare(hash1, hash2);
}
Also used : PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) AConstNull(net.runelite.asm.attributes.code.instructions.AConstNull) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) Instruction(net.runelite.asm.attributes.code.Instruction)

Example 45 with Instruction

use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.

the class ExprArgOrder method visit.

private void visit(MethodContext ctx) {
    Instructions ins = ctx.getMethod().getCode().getInstructions();
    for (Instruction i : exprIns) {
        Expression expression = exprs.get(i);
        assert expression != null;
        if (!canRemove(ctx, ins, i)) {
            continue;
        }
        int idx = ins.getInstructions().indexOf(expression.getHead().getInstruction());
        assert idx != -1;
        // get next instruction
        Instruction next = ins.getInstructions().get(idx + 1);
        ;
        // remove expression
        remove(ins, expression.getHead());
        // sort expression
        expression.sort(ctx);
        // insert expression
        insert(ins, next, expression);
        ++count;
    }
    exprIns.clear();
    exprs.clear();
}
Also used : 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) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) Instruction(net.runelite.asm.attributes.code.Instruction)

Aggregations

Instruction (net.runelite.asm.attributes.code.Instruction)109 Instructions (net.runelite.asm.attributes.code.Instructions)69 Code (net.runelite.asm.attributes.Code)48 LDC (net.runelite.asm.attributes.code.instructions.LDC)39 LVTInstruction (net.runelite.asm.attributes.code.instruction.types.LVTInstruction)32 PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)32 ClassGroup (net.runelite.asm.ClassGroup)31 InvokeInstruction (net.runelite.asm.attributes.code.instruction.types.InvokeInstruction)29 IMul (net.runelite.asm.attributes.code.instructions.IMul)28 VReturn (net.runelite.asm.attributes.code.instructions.VReturn)28 Test (org.junit.Test)27 ILoad (net.runelite.asm.attributes.code.instructions.ILoad)25 Method (net.runelite.asm.Method)24 IStore (net.runelite.asm.attributes.code.instructions.IStore)24 Execution (net.runelite.asm.execution.Execution)23 Deobfuscator (net.runelite.deob.Deobfuscator)22 Label (net.runelite.asm.attributes.code.Label)19 ArrayList (java.util.ArrayList)17 InstructionContext (net.runelite.asm.execution.InstructionContext)17 Field (net.runelite.asm.Field)16