use of org.jf.dexlib2.builder.instruction.BuilderSparseSwitchPayload in project smali by JesusFreke.
the class MutableMethodImplementation method newBuilderSparseSwitchPayload.
@Nonnull
private BuilderSparseSwitchPayload newBuilderSparseSwitchPayload(@Nonnull MethodLocation location, @Nonnull int[] codeAddressToIndex, @Nonnull SparseSwitchPayload instruction) {
List<? extends SwitchElement> switchElements = instruction.getSwitchElements();
if (switchElements.size() == 0) {
return new BuilderSparseSwitchPayload(null);
}
MethodLocation switchLocation = findSwitchForPayload(location);
int baseAddress;
if (switchLocation == null) {
baseAddress = 0;
} else {
baseAddress = switchLocation.codeAddress;
}
List<SwitchLabelElement> labelElements = Lists.newArrayList();
for (SwitchElement element : switchElements) {
labelElements.add(new SwitchLabelElement(element.getKey(), newLabel(codeAddressToIndex, element.getOffset() + baseAddress)));
}
return new BuilderSparseSwitchPayload(labelElements);
}
use of org.jf.dexlib2.builder.instruction.BuilderSparseSwitchPayload in project smali by JesusFreke.
the class PayloadAlignmentTest method testSparseSwitchAlignment.
@Test
public void testSparseSwitchAlignment() {
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 BuilderSparseSwitchPayload(Lists.newArrayList(new SwitchLabelElement(0, implBuilder.getLabel("switch_target_1")), new SwitchLabelElement(5, implBuilder.getLabel("switch_target_2")), new SwitchLabelElement(10, 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.SPARSE_SWITCH, 0, implBuilder.getLabel("switch_payload")));
List<Instruction> instructions = Lists.newArrayList(implBuilder.getMethodImplementation().getInstructions());
checkInstructions(instructions, new Opcode[] { Opcode.GOTO, Opcode.NOP, Opcode.SPARSE_SWITCH_PAYLOAD, Opcode.NOP, Opcode.NOP, Opcode.NOP, Opcode.NOP, Opcode.SPARSE_SWITCH });
OffsetInstruction gotoInstruction = (OffsetInstruction) instructions.get(0);
Assert.assertEquals(16, gotoInstruction.getCodeOffset());
SparseSwitchPayload payload = (SparseSwitchPayload) instructions.get(2);
Assert.assertEquals(3, payload.getSwitchElements().size());
Assert.assertEquals(-20, 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(-18, referent.getCodeOffset());
}
use of org.jf.dexlib2.builder.instruction.BuilderSparseSwitchPayload in project tinker by Tencent.
the class BuilderMutableMethodImplementation method newBuilderSparseSwitchPayload.
@Nonnull
private BuilderSparseSwitchPayload newBuilderSparseSwitchPayload(@Nonnull MethodLocation location, @Nonnull int[] codeAddressToIndex, @Nonnull SparseSwitchPayload instruction) {
List<? extends SwitchElement> switchElements = instruction.getSwitchElements();
if (switchElements.size() == 0) {
return new BuilderSparseSwitchPayload(null);
}
MethodLocation switchLocation = findSwitchForPayload(location);
int baseAddress;
if (switchLocation == null) {
baseAddress = 0;
} else {
baseAddress = switchLocation.codeAddress;
}
List<SwitchLabelElement> labelElements = Lists.newArrayList();
for (SwitchElement element : switchElements) {
labelElements.add(new SwitchLabelElement(element.getKey(), newLabel(codeAddressToIndex, element.getOffset() + baseAddress)));
}
return new BuilderSparseSwitchPayload(labelElements);
}
Aggregations