use of org.jf.dexlib2.builder.instruction.BuilderPackedSwitchPayload in project tinker by Tencent.
the class BuilderMutableMethodImplementation method newBuilderPackedSwitchPayload.
@Nonnull
private BuilderPackedSwitchPayload newBuilderPackedSwitchPayload(@Nonnull MethodLocation location, @Nonnull int[] codeAddressToIndex, @Nonnull PackedSwitchPayload instruction) {
List<? extends SwitchElement> switchElements = instruction.getSwitchElements();
if (switchElements.size() == 0) {
return new BuilderPackedSwitchPayload(0, null);
}
MethodLocation switchLocation = findSwitchForPayload(location);
int baseAddress;
if (switchLocation == null) {
baseAddress = 0;
} else {
baseAddress = switchLocation.codeAddress;
}
List<Label> labels = Lists.newArrayList();
for (SwitchElement element : switchElements) {
labels.add(newLabel(codeAddressToIndex, element.getOffset() + baseAddress));
}
return new BuilderPackedSwitchPayload(switchElements.get(0).getKey(), labels);
}
use of org.jf.dexlib2.builder.instruction.BuilderPackedSwitchPayload in project smali by JesusFreke.
the class MutableMethodImplementation method newBuilderPackedSwitchPayload.
@Nonnull
private BuilderPackedSwitchPayload newBuilderPackedSwitchPayload(@Nonnull MethodLocation location, @Nonnull int[] codeAddressToIndex, @Nonnull PackedSwitchPayload instruction) {
List<? extends SwitchElement> switchElements = instruction.getSwitchElements();
if (switchElements.size() == 0) {
return new BuilderPackedSwitchPayload(0, null);
}
MethodLocation switchLocation = findSwitchForPayload(location);
int baseAddress;
if (switchLocation == null) {
baseAddress = 0;
} else {
baseAddress = switchLocation.codeAddress;
}
List<Label> labels = Lists.newArrayList();
for (SwitchElement element : switchElements) {
labels.add(newLabel(codeAddressToIndex, element.getOffset() + baseAddress));
}
return new BuilderPackedSwitchPayload(switchElements.get(0).getKey(), labels);
}
use of org.jf.dexlib2.builder.instruction.BuilderPackedSwitchPayload in project smali by JesusFreke.
the class PayloadAlignmentTest method testPackedSwitchAlignment.
@Test
public void testPackedSwitchAlignment() {
MethodImplementationBuilder implBuilder = new MethodImplementationBuilder(10);
implBuilder.addLabel("switch_target_1");
implBuilder.addInstruction(new BuilderInstruction10t(Opcode.GOTO, implBuilder.getLabel("goto_target")));
implBuilder.addLabel("switch_payload");
implBuilder.addInstruction(new BuilderPackedSwitchPayload(0, Lists.newArrayList(implBuilder.getLabel("switch_target_1"), implBuilder.getLabel("switch_target_2"), implBuilder.getLabel("switch_target_3"))));
implBuilder.addLabel("goto_target");
implBuilder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
implBuilder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
implBuilder.addLabel("switch_target_2");
implBuilder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
implBuilder.addLabel("switch_target_3");
implBuilder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
implBuilder.addInstruction(new BuilderInstruction31t(Opcode.PACKED_SWITCH, 0, implBuilder.getLabel("switch_payload")));
List<Instruction> instructions = Lists.newArrayList(implBuilder.getMethodImplementation().getInstructions());
checkInstructions(instructions, new Opcode[] { Opcode.GOTO, Opcode.NOP, Opcode.PACKED_SWITCH_PAYLOAD, Opcode.NOP, Opcode.NOP, Opcode.NOP, Opcode.NOP, Opcode.PACKED_SWITCH });
OffsetInstruction gotoInstruction = (OffsetInstruction) instructions.get(0);
Assert.assertEquals(12, gotoInstruction.getCodeOffset());
PackedSwitchPayload payload = (PackedSwitchPayload) instructions.get(2);
Assert.assertEquals(3, payload.getSwitchElements().size());
Assert.assertEquals(-16, payload.getSwitchElements().get(0).getOffset());
Assert.assertEquals(-2, payload.getSwitchElements().get(1).getOffset());
Assert.assertEquals(-1, payload.getSwitchElements().get(2).getOffset());
OffsetInstruction referent = (OffsetInstruction) instructions.get(7);
Assert.assertEquals(-14, referent.getCodeOffset());
}
Aggregations