Package org.jf.dexlib2.iface.instruction

Examples of org.jf.dexlib2.iface.instruction.Instruction


        ClassPath classPath = ClassPath.fromClassPath(ImmutableList.<String>of(), ImmutableList.<String>of(), dexFile,
                15);
        InlineMethodResolver inlineMethodResolver = new CustomInlineMethodResolver(classPath, "Lblah;->blah()V");
        MethodAnalyzer methodAnalyzer = new MethodAnalyzer(classPath, method, inlineMethodResolver);

        Instruction deodexedInstruction = methodAnalyzer.getInstructions().get(0);
        Assert.assertEquals(Opcode.INVOKE_STATIC, deodexedInstruction.getOpcode());

        MethodReference methodReference = (MethodReference)((Instruction35c)deodexedInstruction).getReference();
        Assert.assertEquals(method, methodReference);
    }
View Full Code Here


        List<? extends Instruction> instructions =
                Lists.newArrayList(implBuilder.getMethodImplementation().getInstructions());

        Assert.assertEquals(instructions.size(), 1);

        Instruction instruction = instructions.get(0);

        Assert.assertEquals(instruction.getOpcode(), Opcode.ARRAY_PAYLOAD);
    }
View Full Code Here

        ClassPath classPath = ClassPath.fromClassPath(ImmutableList.<String>of(), ImmutableList.<String>of(), dexFile,
                15);
        InlineMethodResolver inlineMethodResolver = new CustomInlineMethodResolver(classPath, "Lblah;->blah()V");
        MethodAnalyzer methodAnalyzer = new MethodAnalyzer(classPath, method, inlineMethodResolver);

        Instruction deodexedInstruction = methodAnalyzer.getInstructions().get(0);
        Assert.assertEquals(Opcode.INVOKE_DIRECT, deodexedInstruction.getOpcode());

        MethodReference methodReference = (MethodReference)((Instruction35c)deodexedInstruction).getReference();
        Assert.assertEquals(method, methodReference);
    }
View Full Code Here

        List<? extends Instruction> instructions =
                Lists.newArrayList(implBuilder.getMethodImplementation().getInstructions());

        Assert.assertEquals(instructions.size(), 3);

        Instruction instruction = instructions.get(0);
        Assert.assertEquals(instruction.getOpcode(), Opcode.MOVE);

        instruction = instructions.get(1);
        Assert.assertEquals(instruction.getOpcode(), Opcode.NOP);

        instruction = instructions.get(2);
        Assert.assertEquals(instruction.getOpcode(), Opcode.ARRAY_PAYLOAD);
    }
View Full Code Here

            packedSwitchMap = new SparseIntArray(0);
            sparseSwitchMap = new SparseIntArray(0);
            instructionOffsetMap = new InstructionOffsetMap(instructions);

            for (int i=0; i<instructions.size(); i++) {
                Instruction instruction = instructions.get(i);

                Opcode opcode = instruction.getOpcode();
                if (opcode == Opcode.PACKED_SWITCH) {
                    boolean valid = true;
                    int codeOffset = instructionOffsetMap.getInstructionCodeOffset(i);
                    int targetOffset = codeOffset + ((OffsetInstruction)instruction).getCodeOffset();
                    try {
View Full Code Here

        }

        //TODO: does dalvik let you pad with multiple nops?
        //TODO: does dalvik let a switch instruction point to a non-payload instruction?

        Instruction instruction = instructions.get(targetIndex);
        if (instruction.getOpcode() != type) {
            // maybe it's pointing to a NOP padding instruction. Look at the next instruction
            if (instruction.getOpcode() == Opcode.NOP) {
                targetIndex += 1;
                if (targetIndex < instructions.size()) {
                    instruction = instructions.get(targetIndex);
                    if (instruction.getOpcode() == type) {
                        return instructionOffsetMap.getInstructionCodeOffset(targetIndex);
                    }
                }
            }
            throw new InvalidSwitchPayload(targetOffset);
View Full Code Here

    }

    private void addInstructionMethodItems(List<MethodItem> methodItems) {
        int currentCodeAddress = 0;
        for (int i=0; i<instructions.size(); i++) {
            Instruction instruction = instructions.get(i);

            MethodItem methodItem = InstructionMethodItemFactory.makeInstructionFormatMethodItem(this,
                    currentCodeAddress, instruction);

            methodItems.add(methodItem);

            if (i != instructions.size() - 1) {
                methodItems.add(new BlankMethodItem(currentCodeAddress));
            }

            if (classDef.options.addCodeOffsets) {
                methodItems.add(new MethodItem(currentCodeAddress) {

                    @Override
                    public double getSortOrder() {
                        return -1000;
                    }

                    @Override
                    public boolean writeTo(IndentingWriter writer) throws IOException {
                        writer.write("#@");
                        writer.printUnsignedLongAsHex(codeAddress & 0xFFFFFFFFL);
                        return true;
                    }
                });
            }

            if (!classDef.options.noAccessorComments && (instruction instanceof ReferenceInstruction)) {
                Opcode opcode = instruction.getOpcode();

                if (opcode.referenceType == ReferenceType.METHOD) {
                    MethodReference methodReference = null;
                    try {
                        methodReference = (MethodReference)((ReferenceInstruction)instruction).getReference();
                    } catch (InvalidItemIndex ex) {
                        // just ignore it for now. We'll deal with it later, when processing the instructions
                        // themselves
                    }

                    if (methodReference != null &&
                            SyntheticAccessorResolver.looksLikeSyntheticAccessor(methodReference.getName())) {
                        SyntheticAccessorResolver.AccessedMember accessedMember =
                                classDef.options.syntheticAccessorResolver.getAccessedMember(methodReference);
                        if (accessedMember != null) {
                            methodItems.add(new SyntheticAccessCommentMethodItem(accessedMember, currentCodeAddress));
                        }
                    }
                }
            }

            currentCodeAddress += instruction.getCodeUnits();
        }
    }
View Full Code Here

            opcodeValue = reader.peekUshort();
        }

        Opcode opcode = reader.dexBuf.getOpcodes().getOpcodeByValue(opcodeValue);

        Instruction instruction = buildInstruction(reader.dexBuf, opcode, reader.getOffset());
        reader.moveRelative(instruction.getCodeUnits()*2);
        return instruction;
    }
View Full Code Here

                        Opcode.NOP,
                        Opcode.NOP,
                        Opcode.NOP,
                        Opcode.PACKED_SWITCH});

        OffsetInstruction gotoInstruction = (OffsetInstruction)instructions.get(0);
        Assert.assertEquals(12, gotoInstruction.getCodeOffset());

        PackedSwitchPayload payload = (PackedSwitchPayload)instructions.get(2);
        Assert.assertEquals(3, payload.getSwitchElements().size());
        Assert.assertEquals(-16, payload.getSwitchElements().get(0).getOffset());
        Assert.assertEquals(-2, payload.getSwitchElements().get(1).getOffset());
        Assert.assertEquals(-1, payload.getSwitchElements().get(2).getOffset());

        OffsetInstruction referent = (OffsetInstruction)instructions.get(7);
        Assert.assertEquals(-14, referent.getCodeOffset());
    }
View Full Code Here

                        Opcode.NOP,
                        Opcode.NOP,
                        Opcode.NOP,
                        Opcode.SPARSE_SWITCH});

        OffsetInstruction gotoInstruction = (OffsetInstruction)instructions.get(0);
        Assert.assertEquals(16, gotoInstruction.getCodeOffset());

        SparseSwitchPayload payload = (SparseSwitchPayload)instructions.get(2);
        Assert.assertEquals(3, payload.getSwitchElements().size());
        Assert.assertEquals(-20, payload.getSwitchElements().get(0).getOffset());
        Assert.assertEquals(-2, payload.getSwitchElements().get(1).getOffset());
        Assert.assertEquals(-1, payload.getSwitchElements().get(2).getOffset());

        OffsetInstruction referent = (OffsetInstruction)instructions.get(7);
        Assert.assertEquals(-18, referent.getCodeOffset());
    }
View Full Code Here

TOP

Related Classes of org.jf.dexlib2.iface.instruction.Instruction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.