Search in sources :

Example 1 with BuilderInstruction32x

use of org.jf.dexlib2.builder.instruction.BuilderInstruction32x in project smali by JesusFreke.

the class MutableMethodImplementationTest method testNewLabelByIndex.

@Test
public void testNewLabelByIndex() {
    MethodImplementationBuilder builder = new MethodImplementationBuilder(10);
    builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
    builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
    builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
    builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
    builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
    builder.addInstruction(new BuilderInstruction32x(Opcode.MOVE_16, 0, 0));
    MutableMethodImplementation mutableMethodImplementation = new MutableMethodImplementation(builder.getMethodImplementation());
    mutableMethodImplementation.addCatch(mutableMethodImplementation.newLabelForIndex(0), mutableMethodImplementation.newLabelForIndex(6), mutableMethodImplementation.newLabelForIndex(1));
    Assert.assertEquals(0, mutableMethodImplementation.getTryBlocks().get(0).getStartCodeAddress());
    Assert.assertEquals(8, mutableMethodImplementation.getTryBlocks().get(0).getCodeUnitCount());
    Assert.assertEquals(1, mutableMethodImplementation.getTryBlocks().get(0).getExceptionHandlers().get(0).getHandlerCodeAddress());
}
Also used : BuilderInstruction10x(org.jf.dexlib2.builder.instruction.BuilderInstruction10x) BuilderInstruction32x(org.jf.dexlib2.builder.instruction.BuilderInstruction32x) Test(org.junit.Test)

Example 2 with BuilderInstruction32x

use of org.jf.dexlib2.builder.instruction.BuilderInstruction32x in project smali by JesusFreke.

the class MutableMethodImplementationTest method testNewLabelByAddress.

@Test
public void testNewLabelByAddress() {
    MethodImplementationBuilder builder = new MethodImplementationBuilder(10);
    builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
    builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
    builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
    builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
    builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
    builder.addInstruction(new BuilderInstruction32x(Opcode.MOVE_16, 0, 0));
    MutableMethodImplementation mutableMethodImplementation = new MutableMethodImplementation(builder.getMethodImplementation());
    mutableMethodImplementation.addCatch(mutableMethodImplementation.newLabelForAddress(0), mutableMethodImplementation.newLabelForAddress(8), mutableMethodImplementation.newLabelForAddress(1));
    Assert.assertEquals(0, mutableMethodImplementation.getTryBlocks().get(0).getStartCodeAddress());
    Assert.assertEquals(8, mutableMethodImplementation.getTryBlocks().get(0).getCodeUnitCount());
    Assert.assertEquals(1, mutableMethodImplementation.getTryBlocks().get(0).getExceptionHandlers().get(0).getHandlerCodeAddress());
}
Also used : BuilderInstruction10x(org.jf.dexlib2.builder.instruction.BuilderInstruction10x) BuilderInstruction32x(org.jf.dexlib2.builder.instruction.BuilderInstruction32x) Test(org.junit.Test)

Example 3 with BuilderInstruction32x

use of org.jf.dexlib2.builder.instruction.BuilderInstruction32x in project smali by JesusFreke.

the class MutableMethodImplementationTest method testTryEndAtEndOfMethod.

@Test
public void testTryEndAtEndOfMethod() {
    MethodImplementationBuilder builder = new MethodImplementationBuilder(10);
    Label startLabel = builder.addLabel("start");
    builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
    builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
    builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
    builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
    builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
    builder.addInstruction(new BuilderInstruction32x(Opcode.MOVE_16, 0, 0));
    Label endLabel = builder.addLabel("end");
    builder.addCatch(startLabel, endLabel, startLabel);
    MethodImplementation methodImplementation = builder.getMethodImplementation();
    Assert.assertEquals(0, methodImplementation.getTryBlocks().get(0).getStartCodeAddress());
    Assert.assertEquals(8, methodImplementation.getTryBlocks().get(0).getCodeUnitCount());
    methodImplementation = new MutableMethodImplementation(methodImplementation);
    Assert.assertEquals(0, methodImplementation.getTryBlocks().get(0).getStartCodeAddress());
    Assert.assertEquals(8, methodImplementation.getTryBlocks().get(0).getCodeUnitCount());
}
Also used : MethodImplementation(org.jf.dexlib2.iface.MethodImplementation) BuilderInstruction10x(org.jf.dexlib2.builder.instruction.BuilderInstruction10x) BuilderInstruction32x(org.jf.dexlib2.builder.instruction.BuilderInstruction32x) Test(org.junit.Test)

Aggregations

BuilderInstruction10x (org.jf.dexlib2.builder.instruction.BuilderInstruction10x)3 BuilderInstruction32x (org.jf.dexlib2.builder.instruction.BuilderInstruction32x)3 Test (org.junit.Test)3 MethodImplementation (org.jf.dexlib2.iface.MethodImplementation)1