Search in sources :

Example 6 with PackedSwitchPayload

use of org.jf.dexlib2.iface.instruction.formats.PackedSwitchPayload in project smali by JesusFreke.

the class SmalideaMethodTest method testPackedSwitch.

public void testPackedSwitch() {
    String text = ".class public LFormat31t;\n" + ".super Ljava/lang/Object;\n" + ".source \"Format31t.smali\"" + "\n" + ".method public test_packed-switch()V\n" + "    .registers 1\n" + "    .annotation runtime Lorg/junit/Test;\n" + "    .end annotation\n" + "\n" + "    const v0, 12\n" + "\n" + ":switch\n" + "    packed-switch v0, :PackedSwitch\n" + "\n" + ":Label10\n" + "    invoke-static {}, Lorg/junit/Assert;->fail()V\n" + "    return-void\n" + "\n" + ":Label11\n" + "    invoke-static {}, Lorg/junit/Assert;->fail()V\n" + "    return-void\n" + "\n" + ":Label12\n" + "    return-void\n" + "\n" + ":Label13\n" + "    invoke-static {}, Lorg/junit/Assert;->fail()V\n" + "    return-void\n" + "\n" + ":PackedSwitch\n" + "    .packed-switch 10\n" + "        :Label10\n" + "        :Label11\n" + "        :Label12\n" + "        :Label13\n" + "    .end packed-switch\n" + ".end method";
    SmaliFile file = (SmaliFile) myFixture.addFileToProject("my/pkg/blah.smali", text);
    SmaliClass smaliClass = file.getPsiClass();
    SmaliMethod smaliMethod = smaliClass.getMethods()[0];
    SmalideaMethod method = new SmalideaMethod(smaliMethod);
    MethodImplementation impl = method.getImplementation();
    Assert.assertNotNull(impl);
    List<Instruction> instructions = Lists.newArrayList(impl.getInstructions());
    PackedSwitchPayload packedSwitchPayload = (PackedSwitchPayload) instructions.get(9);
    List<? extends SwitchElement> switchElements = packedSwitchPayload.getSwitchElements();
    Assert.assertEquals(4, switchElements.size());
    checkSwitchElement(switchElements.get(0), 10, 6);
    checkSwitchElement(switchElements.get(1), 11, 14);
    checkSwitchElement(switchElements.get(2), 12, 22);
    checkSwitchElement(switchElements.get(3), 13, 24);
}
Also used : SmaliFile(org.jf.smalidea.psi.impl.SmaliFile) MethodImplementation(org.jf.dexlib2.iface.MethodImplementation) SmaliClass(org.jf.smalidea.psi.impl.SmaliClass) SmaliMethod(org.jf.smalidea.psi.impl.SmaliMethod) Instruction(org.jf.dexlib2.iface.instruction.Instruction)

Aggregations

Instruction (org.jf.dexlib2.iface.instruction.Instruction)3 Nonnull (javax.annotation.Nonnull)2 SwitchElement (org.jf.dexlib2.iface.instruction.SwitchElement)2 ExceptionWithContext (org.jf.util.ExceptionWithContext)2 IOException (java.io.IOException)1 Nullable (javax.annotation.Nullable)1 DexReader (org.jf.dexlib2.dexbacked.DexReader)1 DexBackedInstruction (org.jf.dexlib2.dexbacked.instruction.DexBackedInstruction)1 ExceptionHandler (org.jf.dexlib2.iface.ExceptionHandler)1 MethodImplementation (org.jf.dexlib2.iface.MethodImplementation)1 OffsetInstruction (org.jf.dexlib2.iface.instruction.OffsetInstruction)1 OneRegisterInstruction (org.jf.dexlib2.iface.instruction.OneRegisterInstruction)1 ReferenceInstruction (org.jf.dexlib2.iface.instruction.ReferenceInstruction)1 PackedSwitchPayload (org.jf.dexlib2.iface.instruction.formats.PackedSwitchPayload)1 AnnotatedBytes (org.jf.dexlib2.util.AnnotatedBytes)1 SmaliClass (org.jf.smalidea.psi.impl.SmaliClass)1 SmaliFile (org.jf.smalidea.psi.impl.SmaliFile)1 SmaliMethod (org.jf.smalidea.psi.impl.SmaliMethod)1 Test (org.junit.Test)1