Skip to content

Trying to understand Suitcase #57

@CyrilleFranchet

Description

@CyrilleFranchet

Hi, I'm trying to use Suitcase to define the Apple iAP protocol received through a stream.

I'm not sure my approach to handle the payload length is smart enough. The size could be on 1 byte or 3bytes depending if the packet is a small one or a large one. I used ConditionalField but would have preferred to record the length in only one field.

I also don't understand why I can't use Structure this way without fixing the length. I'm not able to decode LingoGeneralIdentifyDeviceLingoes as soon as I use DispatchTarget() in LingoGeneral.

class LingoGeneralIdentifyDeviceLingoes(Structure):
    id = UBInt8Sequence(12)


class LingoGeneral(Structure):
    command_id = DispatchField(UBInt8())
    command_data = DispatchTarget(dispatch_field=command_id, dispatch_mapping={
      0x13: LingoGeneralIdentifyDeviceLingoes,
    })


class LingoSimpleRemote(Structure):
    command_id = DispatchField(UBInt8())
    command_data = Payload()


class LingoDisplayRemote(Structure):
    command_id = DispatchField(UBInt8())
    command_data = Payload()


class LingoExtendedInterface(Structure):
    command_id = DispatchField(UBInt16())
    command_data = Payload()


class LingoPacket(Structure):
    header = Magic(b'\xFF\x55')
    payload_length = LengthField(UBInt8(), get_length=lambda l: l.getval() - 1, set_length=lambda f, v: f.setval(v + 1))
    large_payload_length = ConditionalField(LengthField(UBInt16(), get_length=lambda l: l.getval() - 1,
                                                  set_length=lambda f, v: f.setval(v + 1)), lambda m: m.payload_length == 0)
    lingo_id = DispatchField(UBInt8())
    payload = ConditionalField(DispatchTarget(length_provider=payload_length, dispatch_field=lingo_id, dispatch_mapping={
        0x00: LingoGeneral,
        0x02: LingoSimpleRemote,
        0x03: LingoDisplayRemote,
        0x04: LingoExtendedInterface
    }), lambda m: m.payload_length != 0)
    large_payload = ConditionalField(
        DispatchTarget(length_provider=large_payload_length, dispatch_field=lingo_id, dispatch_mapping={
            0x00: LingoGeneral,
            0x02: LingoSimpleRemote,
            0x03: LingoDisplayRemote,
            0x04: LingoExtendedInterface
    }), lambda m: m.payload_length == 0)
    checksum = CRCField(UBInt8(), algo=ipod_checksum, start=2, end=-1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions