Exemplo n.º 1
0
class SAPHDBPartError(PacketNoPadded):
    """SAP HANA SQL Command Network Protocol Error Part
    """
    part_kind = 6
    name = "SAP HANA SQL Command Network Protocol Error Part"
    fields_desc = [
        LESignedIntField("error_code", 0),
        LESignedIntField("error_position", 0),
        FieldLenField("error_text_length", None, length_of="error_text", fmt="<i"),
        EnumField("error_level", 0, hdb_error_level_vals, fmt="<b"),
        StrFixedLenField("sql_state", "HY000", 5),
        PadField(StrFixedLenField("error_text", "", length_from=lambda pkt: pkt.error_text_length), 8),
    ]
class IEC104_IE_BCR:
    """
    BCR - binary counter reading

    EN 60870-5-101:2003, sec. 7.2.6.9 (p. 47)
    """
    CA_FLAG_COUNTER_NOT_ADJUSTED = 0
    CA_FLAG_COUNTER_ADJUSTED = 1
    CA_FLAGS = {
        CA_FLAG_COUNTER_NOT_ADJUSTED: 'counter not adjusted',
        CA_FLAG_COUNTER_ADJUSTED: 'counter adjusted'
    }

    CY_FLAG_NO_OVERFLOW = 0
    CY_FLAG_OVERFLOW = 1
    CY_FLAGS = {
        CY_FLAG_NO_OVERFLOW: 'no overflow',
        CY_FLAG_OVERFLOW: 'overflow'
    }

    informantion_element_fields = [
        LESignedIntField('counter_value', 0),
        BitEnumField('iv', 0, 1, IEC104_IE_CommonQualityFlags.IV_FLAGS),
        # invalid
        BitEnumField('ca', 0, 1, CA_FLAGS),  # counter adjusted
        BitEnumField('cy', 0, 1, CY_FLAGS),  # carry flag / overflow
        BitField('sq', 0, 5)  # sequence
    ]
Exemplo n.º 3
0
class SAPCARArchiveFilev200Format(PacketNoPadded):
    """SAP CAR file information format

    This is ued to parse files inside a SAP CAR archive.
    """
    name = "SAP CAR Archive File 2.00"

    fields_desc = [
        StrFixedLenField("type", SAPCAR_TYPE_FILE, 2),
        LEIntField("perm_mode", 0),
        LEIntField("file_length", 0),
        LEIntField("unknown1", 0),
        LEIntField("unknown2", 0),
        LEIntField("timestamp", 0),
        StrFixedLenField("unknown3", None, 10),
        FieldLenField("filename_length", None, length_of="filename", fmt="<H"),
        StrFixedLenField("filename",
                         None,
                         length_from=lambda x: x.filename_length),
        ConditionalField(
            StrFixedLenField("mark", "ED", 2),
            lambda x: x.type == SAPCAR_TYPE_FILE and x.file_length > 0),
        ConditionalField(
            PacketField("compressed", None, SAPCARCompressedFileFormat),
            lambda x: x.type == SAPCAR_TYPE_FILE and x.file_length > 0),
        ConditionalField(
            LESignedIntField("checksum", 0),
            lambda x: x.type == SAPCAR_TYPE_FILE and x.file_length > 0),
    ]
Exemplo n.º 4
0
class SAPHDBSegment(PacketNoPadded):
    """SAP HANA SQL Command Network Protocol Segment

    This packet represents a segment within a HDB packet.

    The segment header is comprised of 24 byte, being the first 13 bytes always the same fields and the remaining 11
    bytes depend on the segment kind field.
    """
    name = "SAP HANA SQL Command Network Protocol Segment"
    fields_desc = [
        # Segment length needs to be calculated counting the segment header
        FieldLenField("segmentlength", None, length_of="parts", fmt="<i", adjust=lambda x, l:l+24),
        LESignedIntField("segmentofs", 0),
        FieldLenField("noofparts", None, count_of="parts", fmt="<h"),
        LESignedShortField("segmentno", 1),
        EnumField("segmentkind", 1, hdb_segmentkind_values, fmt="<b"),
        ConditionalField(EnumField("messagetype", 0, hdb_message_type_values, fmt="<b"), hdb_segment_is_request),
        ConditionalField(LESignedByteField("commit", 0), hdb_segment_is_request),
        ConditionalField(LESignedByteField("commandoptions", 0), hdb_segment_is_request),
        ConditionalField(LongField("reserved1", 0), hdb_segment_is_request),
        ConditionalField(ByteField("reserved2", 0), hdb_segment_is_reply),
        ConditionalField(EnumField("functioncode", 0, hdb_function_code_values, fmt="<h"), hdb_segment_is_reply),
        ConditionalField(LongField("reserved3", 0), hdb_segment_is_reply),
        ConditionalField(StrFixedLenField("reserved4", None, 11), lambda pkt: not (hdb_segment_is_reply(pkt) or hdb_segment_is_request(pkt))),
        PacketListField("parts", None, SAPHDBPart, count_from=lambda x: x.noofparts),
    ]
Exemplo n.º 5
0
class SAPHDBOptionPartRow(PacketNoPadded):
    """SAP HANA SQL Command Network Protocol Option Part Row

    This packet represents a row in an Option Part.

    Each row is comprised of a key, type and value.
    """
    part_kind = None
    option_keys = None
    name = "SAP HANA SQL Command Network Protocol Option Part Row"
    fields_desc = [
        MultiEnumField("key", 0, hdb_option_part_key_vals, depends_on=lambda x: x.part_kind, fmt="<b"),
        EnumField("type", 0, hdb_data_type_vals, fmt="<b"),
        ConditionalField(FieldLenField("length", None, length_of="value", fmt="<h"), lambda x: x.type in [29, 30, 33]),
        MultipleTypeField(
            [
                (LESignedByteField("value", 0), lambda x: x.type == 1),
                (LESignedShortField("value", 0), lambda x: x.type == 2),
                (LESignedIntField("value", 0), lambda x: x.type == 3),
                (LESignedLongField("value", 0), lambda x: x.type == 4),
                (Field("value", 0, fmt="<d"), lambda x: x.type == 7),
                (YesNoByteField("value", 0), lambda x: x.type == 28),
                (StrFixedLenField("value", None, length_from=lambda x: x.length), lambda x: x.type in [29, 30, 33]),
            ],
            StrField("value", ""),
        ),
    ]
Exemplo n.º 6
0
class RoomMessage(SizeAwarePacket, Packet):
    name = "RoomMessage"
    fields_desc = [
        LEShortField("contentSize", None),
        ByteEnumField("type", None, RoomMessageType.as_dict()),
        LESignedIntField("roomCode", None),
        PacketListField("messages", [], cls=GameData),
    ]
Exemplo n.º 7
0
class USBAck(USBMitm):
    fields_desc = [
        PacketField('ep', USBEp(), USBEp),
        LESignedIntField('status', 0),
        StrField('data', ''),
    ]

    def desc(self):
        return 'ACK %r' % (self.status,)
Exemplo n.º 8
0
class PAS5211MsgHeader(Packet):
    name = "PAS5211MsgHeader"
    fields_desc = [
        LEIntField("sequence_number", 0),
        XLEShortField("opcode", 0),
        LEShortField("event_type", 0),
        LESignedShortField("channel_id", -1),
        LESignedShortField("onu_id", -1),
        LESignedIntField("onu_session_id", -1)
    ]
Exemplo n.º 9
0
class SAPHDBPart(PacketNoPadded):
    """SAP HANA SQL Command Network Protocol Part

    This packet represents a part within a HDB packet.

    The part header is comprised of 16 bytes.
    """
    name = "SAP HANA SQL Command Network Protocol Part"
    fields_desc = [
        EnumField("partkind", 0, hdb_partkind_values, fmt="<b"),
        LESignedByteField("partattributes", 0),
        FieldLenField("argumentcount", None, count_of="buffer", fmt="<h"),
        LESignedIntField("bigargumentcount", 0),
        FieldLenField("bufferlength", None, length_of="buffer", fmt="<i"),
        LESignedIntField("buffersize", 2**17 - 32 - 24),
        PadField(PacketListField("buffer", [], next_cls_cb=saphdb_determine_part_class,
                                 count_from=lambda x: x.argumentcount,
                                 length_from=lambda x: x.bufferlength), 8),
    ]
class PrismHeader(Packet):
    """ iwpriv wlan0 monitor 3 """
    name = "Prism header"
    fields_desc = [
        LEIntField("msgcode", 68),
        LEIntField("len", 144),
        StrFixedLenField("dev", "", 16),
        LEIntField("hosttime_did", 0),
        LEShortField("hosttime_status", 0),
        LEShortField("hosttime_len", 0),
        LEIntField("hosttime", 0),
        LEIntField("mactime_did", 0),
        LEShortField("mactime_status", 0),
        LEShortField("mactime_len", 0),
        LEIntField("mactime", 0),
        LEIntField("channel_did", 0),
        LEShortField("channel_status", 0),
        LEShortField("channel_len", 0),
        LEIntField("channel", 0),
        LEIntField("rssi_did", 0),
        LEShortField("rssi_status", 0),
        LEShortField("rssi_len", 0),
        LEIntField("rssi", 0),
        LEIntField("sq_did", 0),
        LEShortField("sq_status", 0),
        LEShortField("sq_len", 0),
        LEIntField("sq", 0),
        LEIntField("signal_did", 0),
        LEShortField("signal_status", 0),
        LEShortField("signal_len", 0),
        LESignedIntField("signal", 0),
        LEIntField("noise_did", 0),
        LEShortField("noise_status", 0),
        LEShortField("noise_len", 0),
        LEIntField("noise", 0),
        LEIntField("rate_did", 0),
        LEShortField("rate_status", 0),
        LEShortField("rate_len", 0),
        LEIntField("rate", 0),
        LEIntField("istx_did", 0),
        LEShortField("istx_status", 0),
        LEShortField("istx_len", 0),
        LEIntField("istx", 0),
        LEIntField("frmlen_did", 0),
        LEShortField("frmlen_status", 0),
        LEShortField("frmlen_len", 0),
        LEIntField("frmlen", 0),
    ]

    def answers(self, other):
        if isinstance(other, PrismHeader):
            return self.payload.answers(other.payload)
        else:
            return self.payload.answers(other)
Exemplo n.º 11
0
class SAPCARCompressedBlockFormat(PacketNoPadded):
    """SAP CAR compressed block

    This is used for decompressing blocks inside the file info format.
    """
    name = "SAP CAR Archive Compressed block"

    fields_desc = [
        StrFixedLenField("type", SAPCAR_BLOCK_TYPE_COMPRESSED_LAST, 2),
        ConditionalField(PacketField("compressed", None, SAPCARCompressedBlobFormat),
                         lambda x: x.type in [SAPCAR_BLOCK_TYPE_COMPRESSED_LAST, SAPCAR_BLOCK_TYPE_COMPRESSED]),
        ConditionalField(LESignedIntField("checksum", 0),
                         lambda x: x.type == SAPCAR_BLOCK_TYPE_COMPRESSED_LAST),
    ]
Exemplo n.º 12
0
class SAPHDB(Packet):
    """SAP HANA SQL Command Network Protocol packet

    This packet is used for the HANA SQL Command Network Protocol.

    The message header is comprised of 32 bytes.
    """
    name = "SAP HANA SQL Command Network Protocol"
    fields_desc = [
        LESignedLongField("sessionid", -1),
        LESignedIntField("packetcount", 0),
        FieldLenField("varpartlength", None, length_of="segments", fmt="<I"),
        LEIntField("varpartsize", 2**17 - 32),
        FieldLenField("noofsegm", None, count_of="segments", fmt="<h"),
        EnumField("packetoptions", 0, hdb_packetoptions_values, fmt="b"),
        ByteField("reserved1", None),
        LEIntField("compressionvarpartlength", 0),
        IntField("reserved2", None),
        PacketListField("segments", None, SAPHDBSegment, count_from=lambda x: x.noofsegm),
    ]