use of org.jf.dexlib2.builder.MethodImplementationBuilder in project smali by JesusFreke.
the class MethodAnalyzerTest method testInstanceOfNarrowingAfterMove_dalvik.
@Test
public void testInstanceOfNarrowingAfterMove_dalvik() throws IOException {
MethodImplementationBuilder builder = new MethodImplementationBuilder(3);
builder.addInstruction(new BuilderInstruction12x(Opcode.MOVE_OBJECT, 1, 2));
builder.addInstruction(new BuilderInstruction22c(Opcode.INSTANCE_OF, 0, 1, new ImmutableTypeReference("Lmain;")));
builder.addInstruction(new BuilderInstruction21t(Opcode.IF_EQZ, 0, builder.getLabel("not_instance_of")));
builder.addInstruction(new BuilderInstruction10x(Opcode.RETURN_VOID));
builder.addLabel("not_instance_of");
builder.addInstruction(new BuilderInstruction10x(Opcode.RETURN_VOID));
MethodImplementation methodImplementation = builder.getMethodImplementation();
Method method = new ImmutableMethod("Lmain;", "narrowing", Collections.singletonList(new ImmutableMethodParameter("Ljava/lang/Object;", null, null)), "V", AccessFlags.PUBLIC.getValue(), null, null, methodImplementation);
ClassDef classDef = new ImmutableClassDef("Lmain;", AccessFlags.PUBLIC.getValue(), "Ljava/lang/Object;", null, null, null, null, Collections.singletonList(method));
DexFile dexFile = new ImmutableDexFile(Opcodes.getDefault(), Collections.singletonList(classDef));
ClassPath classPath = new ClassPath(new DexClassProvider(dexFile));
MethodAnalyzer methodAnalyzer = new MethodAnalyzer(classPath, method, null, false);
List<AnalyzedInstruction> analyzedInstructions = methodAnalyzer.getAnalyzedInstructions();
Assert.assertEquals("Ljava/lang/Object;", analyzedInstructions.get(3).getPreInstructionRegisterType(1).type.getType());
Assert.assertEquals("Ljava/lang/Object;", analyzedInstructions.get(3).getPreInstructionRegisterType(2).type.getType());
Assert.assertEquals("Ljava/lang/Object;", analyzedInstructions.get(4).getPreInstructionRegisterType(1).type.getType());
Assert.assertEquals("Ljava/lang/Object;", analyzedInstructions.get(4).getPreInstructionRegisterType(2).type.getType());
}
use of org.jf.dexlib2.builder.MethodImplementationBuilder in project smali by JesusFreke.
the class PayloadAlignmentTest method testPayloadAlignmentRemoveNopWithReferent.
@Test
public void testPayloadAlignmentRemoveNopWithReferent() {
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 BuilderInstruction10x(Opcode.NOP));
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.ARRAY_PAYLOAD });
Instruction31t referent = (Instruction31t) instructions.get(0);
Assert.assertEquals(6, referent.getCodeOffset());
}
use of org.jf.dexlib2.builder.MethodImplementationBuilder in project smali by JesusFreke.
the class PayloadAlignmentTest method testPayloadAlignmentRemoveNop.
@Test
public void testPayloadAlignmentRemoveNop() {
MethodImplementationBuilder implBuilder = new MethodImplementationBuilder(10);
implBuilder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
implBuilder.addInstruction(new BuilderArrayPayload(4, null));
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);
}
use of org.jf.dexlib2.builder.MethodImplementationBuilder 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());
}
use of org.jf.dexlib2.builder.MethodImplementationBuilder 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());
}
Aggregations