use of org.jf.dexlib2.builder.instruction.BuilderInstruction12x 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());
}
use of org.jf.dexlib2.builder.instruction.BuilderInstruction12x in project smali by JesusFreke.
the class PayloadAlignmentTest method testPayloadAlignmentAddNop.
@Test
public void testPayloadAlignmentAddNop() {
MethodImplementationBuilder implBuilder = new MethodImplementationBuilder(10);
implBuilder.addInstruction(new BuilderInstruction12x(Opcode.MOVE, 0, 0));
implBuilder.addInstruction(new BuilderArrayPayload(4, null));
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);
}
use of org.jf.dexlib2.builder.instruction.BuilderInstruction12x in project smali by JesusFreke.
the class MethodAnalyzerTest method testInstanceOfNarrowingAfterMove_art.
@Test
public void testInstanceOfNarrowingAfterMove_art() 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(forArtVersion(56), Collections.singletonList(classDef));
ClassPath classPath = new ClassPath(Lists.newArrayList(new DexClassProvider(dexFile)), true, 56);
MethodAnalyzer methodAnalyzer = new MethodAnalyzer(classPath, method, null, false);
List<AnalyzedInstruction> analyzedInstructions = methodAnalyzer.getAnalyzedInstructions();
Assert.assertEquals("Lmain;", analyzedInstructions.get(3).getPreInstructionRegisterType(1).type.getType());
Assert.assertEquals("Lmain;", 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.instruction.BuilderInstruction12x 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.instruction.BuilderInstruction12x 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());
}
Aggregations