Search in sources :

Example 1 with Opcode

use of org.jf.dexlib2.Opcode in project atlas by alibaba.

the class MethodDefinition method findPayloadOffset.

public int findPayloadOffset(int targetOffset, Opcode type) {
    int targetIndex;
    try {
        targetIndex = instructionOffsetMap.getInstructionIndexAtCodeOffset(targetOffset);
    } catch (InvalidInstructionOffset ex) {
        throw new InvalidSwitchPayload(targetOffset);
    }
    //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);
    } else {
        return targetOffset;
    }
}
Also used : InvalidInstructionOffset(org.jf.dexlib2.util.InstructionOffsetMap.InvalidInstructionOffset) OffsetInstruction(org.jf.dexlib2.iface.instruction.OffsetInstruction) AnalyzedInstruction(org.jf.dexlib2.analysis.AnalyzedInstruction) Instruction(org.jf.dexlib2.iface.instruction.Instruction) ReferenceInstruction(org.jf.dexlib2.iface.instruction.ReferenceInstruction)

Example 2 with Opcode

use of org.jf.dexlib2.Opcode in project atlas by alibaba.

the class MethodDefinition method addInstructionMethodItems.

private void addInstructionMethodItems(List<MethodItem> methodItems) {
    int currentCodeAddress = 0;
    for (int i = 0; i < effectiveInstructions.size(); i++) {
        Instruction instruction = effectiveInstructions.get(i);
        MethodItem methodItem = InstructionMethodItemFactory.makeInstructionFormatMethodItem(this, currentCodeAddress, instruction);
        methodItems.add(methodItem);
        if (i != effectiveInstructions.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())) {
                    AccessedMember accessedMember = classDef.options.syntheticAccessorResolver.getAccessedMember(methodReference);
                    if (accessedMember != null) {
                        methodItems.add(new SyntheticAccessCommentMethodItem(accessedMember, currentCodeAddress));
                    }
                }
            }
        }
        currentCodeAddress += instruction.getCodeUnits();
    }
}
Also used : EndPrologueMethodItem(com.taobao.android.baksmali.adaptors.Debug.EndPrologueMethodItem) DebugMethodItem(com.taobao.android.baksmali.adaptors.Debug.DebugMethodItem) InvalidItemIndex(org.jf.dexlib2.dexbacked.DexBackedDexFile.InvalidItemIndex) ReferenceInstruction(org.jf.dexlib2.iface.instruction.ReferenceInstruction) Opcode(org.jf.dexlib2.Opcode) IOException(java.io.IOException) OffsetInstruction(org.jf.dexlib2.iface.instruction.OffsetInstruction) AnalyzedInstruction(org.jf.dexlib2.analysis.AnalyzedInstruction) Instruction(org.jf.dexlib2.iface.instruction.Instruction) ReferenceInstruction(org.jf.dexlib2.iface.instruction.ReferenceInstruction) AccessedMember(org.jf.dexlib2.util.SyntheticAccessorResolver.AccessedMember) IndentingWriter(org.jf.util.IndentingWriter) MethodReference(org.jf.dexlib2.iface.reference.MethodReference)

Example 3 with Opcode

use of org.jf.dexlib2.Opcode in project atlas by alibaba.

the class InsTructionsReIClassDef method reInstructions.

@Override
protected Iterable<? extends Instruction> reInstructions(Iterable<? extends Instruction> instructions) {
    final List<Instruction> reinstructions = new ArrayList<Instruction>();
    for (final Instruction instruction : instructions) {
        if (instruction instanceof ReferenceInstruction) {
            Opcode opcode = instruction.getOpcode();
            if (opcode.referenceType == ReferenceType.METHOD) {
                boolean isBasic = false;
                MethodReference methodReference = null;
                try {
                    methodReference = (MethodReference) ((ReferenceInstruction) instruction).getReference();
                    if (methodReference.getDefiningClass().contains("Ljava/lang") || methodReference.getDefiningClass().startsWith("Ljava/util/") || methodReference.getDefiningClass().startsWith("[Ljava/lang")) {
                        reinstructions.add(ImmutableInstruction.of(instruction));
                        continue;
                    }
                    String returnType = methodReference.getReturnType();
                    boolean isArray = false;
                    if (returnType.startsWith("[")) {
                        isArray = true;
                    }
                    String methodName = methodReference.getName();
                    if (methodName.equals("InitBundleInfoByVersionIfNeed")) {
                        System.out.println("InitBundleInfoByVersionIfNeed");
                    }
                    if (basicType.containsKey(returnType)) {
                        isBasic = true;
                    }
                    List<? extends CharSequence> paramTypes = methodReference.getParameterTypes();
                    List<CharSequence> dalvikParamTypes = new ArrayList<CharSequence>();
                    List<CharSequence> newParamTypes = new ArrayList<CharSequence>();
                    for (CharSequence charSequence : paramTypes) {
                        if (basicType.containsKey(charSequence.toString())) {
                            newParamTypes.add(charSequence);
                            dalvikParamTypes.add(basicType.get(charSequence.toString()));
                            continue;
                        }
                        boolean isArray1 = charSequence.toString().startsWith("[");
                        dalvikParamTypes.add(DefineUtils.getDalvikClassName(charSequence.toString()) + (isArray ? "[]" : ""));
                        newParamTypes.add(DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(charSequence.toString())).className, isArray1));
                    }
                    final ImmutableMethodReference immutableReference = new ImmutableMethodReference(DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(methodReference.getDefiningClass())).className, false), classProcessor.methodProcess(DefineUtils.getDalvikClassName(methodReference.getDefiningClass()), methodReference.getName(), isBasic ? basicType.get(methodReference.getReturnType()) : DefineUtils.getDalvikClassName(methodReference.getReturnType()) + (isArray ? "[]" : ""), StringUtils.join(dalvikParamTypes.toArray(), ",")).methodName, newParamTypes, isBasic ? returnType : DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(methodReference.getReturnType())).className, methodReference.getReturnType().startsWith("[")));
                    if (instruction instanceof Instruction3rc) {
                        reinstructions.add(new ImmutableInstruction3rc(instruction.getOpcode(), ((Instruction3rc) instruction).getStartRegister(), ((Instruction3rc) instruction).getRegisterCount(), immutableReference));
                    } else if (instruction instanceof Instruction20bc) {
                        reinstructions.add(new ImmutableInstruction20bc(instruction.getOpcode(), ((Instruction20bc) instruction).getVerificationError(), immutableReference));
                    } else if (instruction instanceof Instruction21c) {
                        reinstructions.add(new ImmutableInstruction21c(instruction.getOpcode(), ((Instruction21c) instruction).getRegisterA(), immutableReference));
                    } else if (instruction instanceof Instruction22c) {
                        reinstructions.add(new ImmutableInstruction22c(instruction.getOpcode(), ((Instruction22c) instruction).getRegisterA(), ((Instruction22c) instruction).getRegisterB(), immutableReference));
                    } else if (instruction instanceof Instruction31c) {
                        reinstructions.add(new ImmutableInstruction31c(instruction.getOpcode(), ((Instruction31c) instruction).getRegisterA(), immutableReference));
                    } else if (instruction instanceof Instruction35c) {
                        reinstructions.add(new ImmutableInstruction35c(instruction.getOpcode(), ((Instruction35c) instruction).getRegisterCount(), ((Instruction35c) instruction).getRegisterC(), ((Instruction35c) instruction).getRegisterD(), ((Instruction35c) instruction).getRegisterE(), ((Instruction35c) instruction).getRegisterF(), ((Instruction35c) instruction).getRegisterG(), immutableReference));
                    }
                } catch (Exception e) {
                }
            } else if (opcode.referenceType == ReferenceType.FIELD) {
                FieldReference fieldReference = null;
                boolean isBasic = false;
                boolean isBasicArray = false;
                fieldReference = (FieldReference) ((ReferenceInstruction) instruction).getReference();
                if (fieldReference.getDefiningClass().startsWith("Ljava/lang/") || fieldReference.getDefiningClass().startsWith("Ljava/util/") || fieldReference.getDefiningClass().startsWith("[Ljava/lang/")) {
                    reinstructions.add(ImmutableInstruction.of(instruction));
                    continue;
                }
                if (basicType.containsKey(fieldReference.getType())) {
                    isBasic = true;
                }
                final ImmutableFieldReference immutableFieldReference = new ImmutableFieldReference(DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(fieldReference.getDefiningClass())).className, false), classProcessor.filedProcess(DefineUtils.getDalvikClassName(fieldReference.getDefiningClass()), isBasic ? basicType.get(fieldReference.getType()) : DefineUtils.getDalvikClassName(fieldReference.getType()), fieldReference.getName()).fieldName, isBasic ? fieldReference.getType() : DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(fieldReference.getType())).className, fieldReference.getType().startsWith("[")));
                if (instruction instanceof Instruction3rc) {
                    reinstructions.add(new ImmutableInstruction3rc(instruction.getOpcode(), ((Instruction3rc) instruction).getStartRegister(), ((Instruction3rc) instruction).getRegisterCount(), immutableFieldReference));
                } else if (instruction instanceof Instruction20bc) {
                    reinstructions.add(new ImmutableInstruction20bc(instruction.getOpcode(), ((Instruction20bc) instruction).getVerificationError(), immutableFieldReference));
                } else if (instruction instanceof Instruction21c) {
                    reinstructions.add(new ImmutableInstruction21c(instruction.getOpcode(), ((Instruction21c) instruction).getRegisterA(), immutableFieldReference));
                } else if (instruction instanceof Instruction22c) {
                    reinstructions.add(new ImmutableInstruction22c(instruction.getOpcode(), ((Instruction22c) instruction).getRegisterA(), ((Instruction22c) instruction).getRegisterB(), immutableFieldReference));
                } else if (instruction instanceof Instruction31c) {
                    reinstructions.add(new ImmutableInstruction31c(instruction.getOpcode(), ((Instruction31c) instruction).getRegisterA(), immutableFieldReference));
                } else if (instruction instanceof Instruction35c) {
                    reinstructions.add(new ImmutableInstruction35c(instruction.getOpcode(), ((Instruction35c) instruction).getRegisterCount(), ((Instruction35c) instruction).getRegisterC(), ((Instruction35c) instruction).getRegisterD(), ((Instruction35c) instruction).getRegisterE(), ((Instruction35c) instruction).getRegisterF(), ((Instruction35c) instruction).getRegisterG(), immutableFieldReference));
                }
            } else if (opcode.referenceType == ReferenceType.TYPE) {
                TypeReference typeReference = (TypeReference) ((ReferenceInstruction) instruction).getReference();
                String type = typeReference.getType();
                if (!basicType.containsKey(type) && !type.startsWith("Ljava/lang") && !type.startsWith("Ljava/util/") && !type.startsWith("[Ljava/lang")) {
                    type = DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(type)).className, type.startsWith("["));
                }
                ImmutableTypeReference immutableTypeReference = new ImmutableTypeReference(type);
                if (instruction instanceof Instruction3rc) {
                    reinstructions.add(new ImmutableInstruction3rc(instruction.getOpcode(), ((Instruction3rc) instruction).getStartRegister(), ((Instruction3rc) instruction).getRegisterCount(), immutableTypeReference));
                } else if (instruction instanceof Instruction20bc) {
                    reinstructions.add(new ImmutableInstruction20bc(instruction.getOpcode(), ((Instruction20bc) instruction).getVerificationError(), immutableTypeReference));
                } else if (instruction instanceof Instruction21c) {
                    reinstructions.add(new ImmutableInstruction21c(instruction.getOpcode(), ((Instruction21c) instruction).getRegisterA(), immutableTypeReference));
                } else if (instruction instanceof Instruction22c) {
                    reinstructions.add(new ImmutableInstruction22c(instruction.getOpcode(), ((Instruction22c) instruction).getRegisterA(), ((Instruction22c) instruction).getRegisterB(), immutableTypeReference));
                } else if (instruction instanceof Instruction31c) {
                    reinstructions.add(new ImmutableInstruction31c(instruction.getOpcode(), ((Instruction31c) instruction).getRegisterA(), immutableTypeReference));
                } else if (instruction instanceof Instruction35c) {
                    reinstructions.add(new ImmutableInstruction35c(instruction.getOpcode(), ((Instruction35c) instruction).getRegisterCount(), ((Instruction35c) instruction).getRegisterC(), ((Instruction35c) instruction).getRegisterD(), ((Instruction35c) instruction).getRegisterE(), ((Instruction35c) instruction).getRegisterF(), ((Instruction35c) instruction).getRegisterG(), immutableTypeReference));
                }
            } else if (opcode.referenceType == ReferenceType.STRING) {
                StringReference stringReference = (StringReference) ((ReferenceInstruction) instruction).getReference();
                String type = stringReference.getString();
                //                    if (!basicType.contains(type) && !type.startsWith("[Ljava/lang")) {
                //                        type = DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(type)).className);
                //                    }
                ImmutableStringReference immutableStringReference = new ImmutableStringReference(type);
                if (instruction instanceof Instruction3rc) {
                    reinstructions.add(new ImmutableInstruction3rc(instruction.getOpcode(), ((Instruction3rc) instruction).getStartRegister(), ((Instruction3rc) instruction).getRegisterCount(), immutableStringReference));
                } else if (instruction instanceof Instruction20bc) {
                    reinstructions.add(new ImmutableInstruction20bc(instruction.getOpcode(), ((Instruction20bc) instruction).getVerificationError(), immutableStringReference));
                } else if (instruction instanceof Instruction21c) {
                    reinstructions.add(new ImmutableInstruction21c(instruction.getOpcode(), ((Instruction21c) instruction).getRegisterA(), immutableStringReference));
                } else if (instruction instanceof Instruction22c) {
                    reinstructions.add(new ImmutableInstruction22c(instruction.getOpcode(), ((Instruction22c) instruction).getRegisterA(), ((Instruction22c) instruction).getRegisterB(), immutableStringReference));
                } else if (instruction instanceof Instruction31c) {
                    reinstructions.add(new ImmutableInstruction31c(instruction.getOpcode(), ((Instruction31c) instruction).getRegisterA(), immutableStringReference));
                } else if (instruction instanceof Instruction35c) {
                    reinstructions.add(new ImmutableInstruction35c(instruction.getOpcode(), ((Instruction35c) instruction).getRegisterCount(), ((Instruction35c) instruction).getRegisterC(), ((Instruction35c) instruction).getRegisterD(), ((Instruction35c) instruction).getRegisterE(), ((Instruction35c) instruction).getRegisterF(), ((Instruction35c) instruction).getRegisterG(), immutableStringReference));
                }
            } else {
                reinstructions.add(ImmutableInstruction.of(instruction));
            }
        } else {
            reinstructions.add(ImmutableInstruction.of(instruction));
        }
    }
    return new Iterable<Instruction>() {

        @Override
        public Iterator<Instruction> iterator() {
            return reinstructions.iterator();
        }
    };
}
Also used : ImmutableInstruction31c(org.jf.dexlib2.immutable.instruction.ImmutableInstruction31c) Instruction31c(org.jf.dexlib2.iface.instruction.formats.Instruction31c) ImmutableInstruction21c(org.jf.dexlib2.immutable.instruction.ImmutableInstruction21c) Instruction21c(org.jf.dexlib2.iface.instruction.formats.Instruction21c) Instruction35c(org.jf.dexlib2.iface.instruction.formats.Instruction35c) ImmutableInstruction35c(org.jf.dexlib2.immutable.instruction.ImmutableInstruction35c) ArrayList(java.util.ArrayList) ImmutableFieldReference(org.jf.dexlib2.immutable.reference.ImmutableFieldReference) ReferenceInstruction(org.jf.dexlib2.iface.instruction.ReferenceInstruction) Opcode(org.jf.dexlib2.Opcode) ImmutableInstruction(org.jf.dexlib2.immutable.instruction.ImmutableInstruction) Instruction(org.jf.dexlib2.iface.instruction.Instruction) ReferenceInstruction(org.jf.dexlib2.iface.instruction.ReferenceInstruction) ImmutableInstruction35c(org.jf.dexlib2.immutable.instruction.ImmutableInstruction35c) ImmutableInstruction21c(org.jf.dexlib2.immutable.instruction.ImmutableInstruction21c) ImmutableInstruction31c(org.jf.dexlib2.immutable.instruction.ImmutableInstruction31c) TypeReference(org.jf.dexlib2.iface.reference.TypeReference) ImmutableTypeReference(org.jf.dexlib2.immutable.reference.ImmutableTypeReference) ImmutableTypeReference(org.jf.dexlib2.immutable.reference.ImmutableTypeReference) Instruction3rc(org.jf.dexlib2.iface.instruction.formats.Instruction3rc) ImmutableInstruction3rc(org.jf.dexlib2.immutable.instruction.ImmutableInstruction3rc) Instruction22c(org.jf.dexlib2.iface.instruction.formats.Instruction22c) ImmutableInstruction22c(org.jf.dexlib2.immutable.instruction.ImmutableInstruction22c) FieldReference(org.jf.dexlib2.iface.reference.FieldReference) ImmutableFieldReference(org.jf.dexlib2.immutable.reference.ImmutableFieldReference) ImmutableMethodReference(org.jf.dexlib2.immutable.reference.ImmutableMethodReference) ImmutableStringReference(org.jf.dexlib2.immutable.reference.ImmutableStringReference) ImmutableStringReference(org.jf.dexlib2.immutable.reference.ImmutableStringReference) StringReference(org.jf.dexlib2.iface.reference.StringReference) ImmutableInstruction20bc(org.jf.dexlib2.immutable.instruction.ImmutableInstruction20bc) ImmutableInstruction20bc(org.jf.dexlib2.immutable.instruction.ImmutableInstruction20bc) Instruction20bc(org.jf.dexlib2.iface.instruction.formats.Instruction20bc) ImmutableInstruction22c(org.jf.dexlib2.immutable.instruction.ImmutableInstruction22c) ImmutableInstruction3rc(org.jf.dexlib2.immutable.instruction.ImmutableInstruction3rc) ImmutableMethodReference(org.jf.dexlib2.immutable.reference.ImmutableMethodReference) MethodReference(org.jf.dexlib2.iface.reference.MethodReference)

Example 4 with Opcode

use of org.jf.dexlib2.Opcode in project smali by JesusFreke.

the class JumboStringConversionTest method testJumboStringConversion_NonMethodBuilder.

@Test
public void testJumboStringConversion_NonMethodBuilder() throws IOException {
    DexBuilder dexBuilder = new DexBuilder(Opcodes.getDefault());
    final List<Instruction> instructions = Lists.newArrayList();
    for (int i = 0; i < 66000; i++) {
        final StringReference ref = dexBuilder.internStringReference(String.format("%08d", i));
        instructions.add(new Instruction21c() {

            @Override
            public int getRegisterA() {
                return 0;
            }

            @Nonnull
            @Override
            public Reference getReference() {
                return ref;
            }

            @Override
            public int getReferenceType() {
                return ReferenceType.STRING;
            }

            @Override
            public Opcode getOpcode() {
                return Opcode.CONST_STRING;
            }

            @Override
            public int getCodeUnits() {
                return getOpcode().format.size / 2;
            }
        });
    }
    instructions.add(new ImmutableInstruction10x(Opcode.RETURN_VOID));
    MethodImplementation methodImpl = new MethodImplementation() {

        @Override
        public int getRegisterCount() {
            return 1;
        }

        @Nonnull
        @Override
        public Iterable<? extends Instruction> getInstructions() {
            return instructions;
        }

        @Nonnull
        @Override
        public List<? extends TryBlock<? extends ExceptionHandler>> getTryBlocks() {
            return ImmutableList.of();
        }

        @Nonnull
        @Override
        public Iterable<? extends DebugItem> getDebugItems() {
            return ImmutableList.of();
        }
    };
    dexBuilder.internClassDef("Ltest;", 0, "Ljava/lang/Object;", null, null, ImmutableSet.<Annotation>of(), null, ImmutableList.of(dexBuilder.internMethod("Ltest;", "test", null, "V", 0, ImmutableSet.<Annotation>of(), methodImpl)));
    MemoryDataStore dexStore = new MemoryDataStore();
    dexBuilder.writeTo(dexStore);
    DexBackedDexFile dexFile = new DexBackedDexFile(Opcodes.getDefault(), dexStore.getData());
    ClassDef classDef = Iterables.getFirst(dexFile.getClasses(), null);
    Assert.assertNotNull(classDef);
    Method method = Iterables.getFirst(classDef.getMethods(), null);
    Assert.assertNotNull(method);
    MethodImplementation impl = method.getImplementation();
    Assert.assertNotNull(impl);
    List<? extends Instruction> actualInstructions = Lists.newArrayList(impl.getInstructions());
    Assert.assertEquals(66001, actualInstructions.size());
    for (int i = 0; i < 65536; i++) {
        Assert.assertEquals(Opcode.CONST_STRING, actualInstructions.get(i).getOpcode());
        Assert.assertEquals(String.format("%08d", i), ((StringReference) ((ReferenceInstruction) actualInstructions.get(i)).getReference()).getString());
    }
    for (int i = 65536; i < 66000; i++) {
        Assert.assertEquals(Opcode.CONST_STRING_JUMBO, actualInstructions.get(i).getOpcode());
        Assert.assertEquals(String.format("%08d", i), ((StringReference) ((ReferenceInstruction) actualInstructions.get(i)).getReference()).getString());
    }
    Assert.assertEquals(Opcode.RETURN_VOID, actualInstructions.get(66000).getOpcode());
}
Also used : BuilderInstruction21c(org.jf.dexlib2.builder.instruction.BuilderInstruction21c) Instruction21c(org.jf.dexlib2.iface.instruction.formats.Instruction21c) DexBackedDexFile(org.jf.dexlib2.dexbacked.DexBackedDexFile) Nonnull(javax.annotation.Nonnull) Reference(org.jf.dexlib2.iface.reference.Reference) StringReference(org.jf.dexlib2.iface.reference.StringReference) MemoryDataStore(org.jf.dexlib2.writer.io.MemoryDataStore) Opcode(org.jf.dexlib2.Opcode) ReferenceInstruction(org.jf.dexlib2.iface.instruction.ReferenceInstruction) Instruction(org.jf.dexlib2.iface.instruction.Instruction) ReferenceInstruction(org.jf.dexlib2.iface.instruction.ReferenceInstruction) StringReference(org.jf.dexlib2.iface.reference.StringReference) ImmutableInstruction10x(org.jf.dexlib2.immutable.instruction.ImmutableInstruction10x) DexBuilder(org.jf.dexlib2.writer.builder.DexBuilder) Test(org.junit.Test)

Example 5 with Opcode

use of org.jf.dexlib2.Opcode in project smali by JesusFreke.

the class PayloadAlignmentTest method testPayloadAlignmentAddNopWithReferent.

@Test
public void testPayloadAlignmentAddNopWithReferent() {
    MethodImplementationBuilder implBuilder = new MethodImplementationBuilder(10);
    Label label = implBuilder.getLabel("array_payload");
    implBuilder.addInstruction(new BuilderInstruction31t(Opcode.FILL_ARRAY_DATA, 0, label));
    implBuilder.addInstruction(new BuilderInstruction12x(Opcode.MOVE, 0, 0));
    implBuilder.addInstruction(new BuilderInstruction12x(Opcode.MOVE, 0, 0));
    implBuilder.addInstruction(new BuilderInstruction12x(Opcode.MOVE, 0, 0));
    implBuilder.addInstruction(new BuilderInstruction12x(Opcode.MOVE, 0, 0));
    implBuilder.addLabel("array_payload");
    implBuilder.addInstruction(new BuilderArrayPayload(4, null));
    List<Instruction> instructions = Lists.newArrayList(implBuilder.getMethodImplementation().getInstructions());
    checkInstructions(instructions, new Opcode[] { Opcode.FILL_ARRAY_DATA, Opcode.MOVE, Opcode.MOVE, Opcode.MOVE, Opcode.MOVE, Opcode.NOP, Opcode.ARRAY_PAYLOAD });
    Instruction31t referent = (Instruction31t) instructions.get(0);
    Assert.assertEquals(8, referent.getCodeOffset());
}
Also used : OffsetInstruction(org.jf.dexlib2.iface.instruction.OffsetInstruction) Instruction(org.jf.dexlib2.iface.instruction.Instruction) Instruction31t(org.jf.dexlib2.iface.instruction.formats.Instruction31t) Test(org.junit.Test)

Aggregations

Opcode (org.jf.dexlib2.Opcode)17 Instruction (org.jf.dexlib2.iface.instruction.Instruction)15 ReferenceInstruction (org.jf.dexlib2.iface.instruction.ReferenceInstruction)11 OffsetInstruction (org.jf.dexlib2.iface.instruction.OffsetInstruction)10 MethodReference (org.jf.dexlib2.iface.reference.MethodReference)7 AnalyzedInstruction (org.jf.dexlib2.analysis.AnalyzedInstruction)6 Test (org.junit.Test)6 InvalidItemIndex (org.jf.dexlib2.dexbacked.DexBackedDexFile.InvalidItemIndex)4 Instruction31t (org.jf.dexlib2.iface.instruction.formats.Instruction31t)4 FieldReference (org.jf.dexlib2.iface.reference.FieldReference)4 TypeReference (org.jf.dexlib2.iface.reference.TypeReference)4 InvalidInstructionOffset (org.jf.dexlib2.util.InstructionOffsetMap.InvalidInstructionOffset)4 ExceptionWithContext (org.jf.util.ExceptionWithContext)4 Nonnull (javax.annotation.Nonnull)3 Instruction20bc (org.jf.dexlib2.iface.instruction.formats.Instruction20bc)3 Instruction22c (org.jf.dexlib2.iface.instruction.formats.Instruction22c)3 Reference (org.jf.dexlib2.iface.reference.Reference)3 ImmutableFieldReference (org.jf.dexlib2.immutable.reference.ImmutableFieldReference)3 IOException (java.io.IOException)2 ReferenceType (org.jf.dexlib2.ReferenceType)2