Exemplo n.º 1
0
    def getPayload(self):
        payload = bytearray()

        payload.extend(Proto.build_byte(Flags.COM_QUERY))
        payload.extend(Proto.build_eop_str(self.query))

        return payload
    def getEventBody(self):
        payload = bytearray()

        payload.extend(Proto.build_fixed_int(2, self.binlog_version))
        payload.extend(Proto.build_fixed_str(50, self.mysql_server_version))
        payload.extend(Proto.build_fixed_int(4, self.timestamp))
        payload.extend(Proto.build_fixed_int(1, self.header_length))
        payload.extend(self.event_type_header_length)

        return payload
Exemplo n.º 3
0
    def getPayload(self):
        payload = bytearray()

        payload.extend(Proto.build_byte(Flags.ERR))
        payload.extend(Proto.build_fixed_int(2, self.errorCode))
        payload.extend(Proto.build_byte(ord('#')))
        payload.extend(Proto.build_fixed_str(5, self.sqlState))
        payload.extend(Proto.build_eop_str(self.errorMessage))

        return payload
Exemplo n.º 4
0
    def loadFromPacket(packet):
        obj = ERR()
        proto = Proto(packet, 3)

        obj.sequenceId = proto.get_fixed_int(1)
        proto.get_filler(1)
        obj.errorCode = proto.get_fixed_int(2)
        proto.get_filler(1)
        obj.sqlState = proto.get_fixed_str(5)
        obj.errorMessage = proto.get_eop_str()

        return obj
Exemplo n.º 5
0
    def getPayload(self):

        # 1 0xef kPacketMagicNum
        # 8 log_pos
        # n binlog_filename

        payload = bytearray()
        payload.extend(Proto.build_byte(0xef))
        payload.extend(Proto.build_fixed_int(8, self.binlog_pos))
        payload.extend(Proto.build_eop_str(self.binlog_filename))

        return payload
Exemplo n.º 6
0
    def loadFromPacket(packet):

        obj = GitdEvent()
        proto = Proto(packet)

        obj.commit_flag = byte2int(proto.get_fixed_int(1)) == 1
        obj.sid = proto.read(16)
        obj.gno = struct.unpack('<Q', proto.read(8))[0]

        nibbles = binascii.hexlify(obj.sid).decode('ascii')
        obj.gtid = '%s-%s-%s-%s-%s:%d' % (
            nibbles[:8], nibbles[8:12], nibbles[12:16], nibbles[16:20], nibbles[20:], obj.gno
        )

        return obj
Exemplo n.º 7
0
    def toPacket(self):
        """
        Convert a Packet object to a byte array stream
        """
        payload = self.getPayload()

        # Size is payload + packet size + sequence id
        size = len(payload)

        packet = bytearray(size + 4)

        packet[0:2] = Proto.build_fixed_int(3, size)
        packet[3] = Proto.build_fixed_int(1, self.sequenceId)[0]
        packet[4:] = payload

        return packet
Exemplo n.º 8
0
    def loadFromPacket(packet):
        obj = Query()
        proto = Proto(packet, 3)

        obj.sequenceId = proto.get_fixed_int(1)
        proto.get_filler(1)
        obj.query = proto.get_eop_str()

        return obj
Exemplo n.º 9
0
    def getPayload(self):
        payload = bytearray()

        payload.extend(b'\x00')  # OK
        payload.extend(Proto.build_fixed_int(4, self.timestamp))
        payload.extend(Proto.build_fixed_int(1, self.event_type))
        payload.extend(Proto.build_fixed_int(4, self.server_id))
        payload.extend(Proto.build_fixed_int(4, len(self.getEventBody())))
        payload.extend(Proto.build_fixed_int(4, self.log_pos))
        payload.extend(Proto.build_fixed_int(2, self.flags))
        payload.extend(self.getEventBody())

        return payload
Exemplo n.º 10
0
    def loadFromPacket(packet):
        obj = Response()
        proto = Proto(packet, 3)

        obj.sequenceId = proto.get_fixed_int(1)
        obj.capabilityFlags = proto.get_fixed_int(2)
        proto.offset -= 2

        if obj.hasCapabilityFlag(Flags.CLIENT_PROTOCOL_41):
            obj.capabilityFlags = proto.get_fixed_int(4)
            obj.maxPacketSize = proto.get_fixed_int(4)
            obj.characterSet = proto.get_fixed_int(1)
            proto.get_filler(23)
            obj.username = proto.get_null_str()

            if obj.hasCapabilityFlag(
                    Flags.CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA):
                authResponseLen = proto.get_lenenc_int()
                obj.authResponse = proto.get_fixed_str(authResponseLen)
            elif obj.hasCapabilityFlag(Flags.CLIENT_SECURE_CONNECTION):
                authResponseLen = proto.get_lenenc_int()
                obj.authResponse = proto.get_fixed_str(authResponseLen)
            else:
                obj.authResponse = proto.get_null_str()

            if obj.hasCapabilityFlag(Flags.CLIENT_CONNECT_WITH_DB):
                obj.schema = proto.get_null_str()

            if obj.hasCapabilityFlag(Flags.CLIENT_PLUGIN_AUTH):
                obj.pluginName = proto.get_null_str()

            if obj.hasCapabilityFlag(Flags.CLIENT_CONNECT_ATTRS):
                attribute_length = proto.get_lenenc_int()
                while proto.has_remaining_data():
                    k = proto.get_lenenc_str()
                    v = proto.get_lenenc_str()
                    obj.clientAttributes[k] = v

        else:
            obj.capabilityFlags = proto.get_fixed_int(2)
            obj.maxPacketSize = proto.get_fixed_int(3)
            obj.username = proto.get_null_str()
            if obj.hasCapabilityFlag(Flags.CLIENT_CONNECT_WITH_DB):
                obj.authResponse = proto.get_null_str()
                obj.schema = proto.get_null_str()
            else:
                obj.authResponse = proto.get_eop_str()

        return obj
Exemplo n.º 11
0
    def getPayload(self):
        payload = bytearray()

        if self.hasCapabilityFlag(Flags.CLIENT_PROTOCOL_41):
            payload.extend(Proto.build_fixed_int(4, self.capabilityFlags))
            payload.extend(Proto.build_fixed_int(4, self.maxPacketSize))
            payload.extend(Proto.build_fixed_int(1, self.characterSet))
            payload.extend(Proto.build_filler(23))
            payload.extend(Proto.build_null_str(self.username))

            if self.hasCapabilityFlag(
                    Flags.CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA):
                payload.extend(Proto.build_lenenc_int(len(self.authResponse)))
                payload.extend(
                    Proto.build_fixed_str(len(self.authResponse),
                                          self.authResponse))
            elif self.hasCapabilityFlag(Flags.CLIENT_SECURE_CONNECTION):
                payload.extend(Proto.build_lenenc_int(len(self.authResponse)))
                payload.extend(
                    Proto.build_fixed_str(len(self.authResponse),
                                          self.authResponse))
            else:
                payload.extend(Proto.build_null_str(self.authResponse))

            if self.hasCapabilityFlag(Flags.CLIENT_CONNECT_WITH_DB):
                payload.extend(Proto.build_null_str(self.schema))

            if self.hasCapabilityFlag(Flags.CLIENT_PLUGIN_AUTH):
                payload.extend(Proto.build_null_str(self.pluginName))

            if self.hasCapabilityFlag(Flags.CLIENT_CONNECT_ATTRS):
                attributes = bytearray()
                for k, v in self.clientAttributes.items():
                    attributes.extend(Proto.build_lenenc_str(k))
                    attributes.extend(Proto.build_lenenc_str(v))
                payload.extend(Proto.build_lenenc_int(len(attributes)))
                payload.extend(attributes)

        else:
            payload.extend(Proto.build_fixed_int(2, self.capabilityFlags))
            payload.extend(Proto.build_fixed_int(3, self.maxPacketSize))
            payload.extend(Proto.build_null_str(self.username))
            if self.hasCapabilityFlag(Flags.CLIENT_CONNECT_WITH_DB):
                payload.extend(Proto.build_null_str(self.authResponse))
                payload.extend(Proto.build_null_str(self.schema))
            else:
                payload.extend(Proto.build_eop_str(self.authResponse))

        return payload
Exemplo n.º 12
0
    def loadFromPacket(packet):
        obj = Challenge()
        proto = Proto(packet, 3)

        obj.sequenceId = proto.get_fixed_int(1)
        obj.protocolVersion = proto.get_fixed_int(1)
        obj.serverVersion = proto.get_null_str()
        obj.connectionId = proto.get_fixed_int(4)
        obj.challenge1 = proto.get_fixed_str(8)
        proto.get_filler(1)
        obj.capabilityFlags = proto.get_fixed_int(2) << 16
        if proto.has_remaining_data():
            obj.characterSet = proto.get_fixed_int(1)
            obj.statusFlags = proto.get_fixed_int(2)
            obj.setCapabilityFlag(proto.get_fixed_int(2))

            if obj.hasCapabilityFlag(Flags.CLIENT_PLUGIN_AUTH):
                obj.authPluginDataLength = proto.get_fixed_int(1)
            else:
                proto.get_filler(1)

            proto.get_filler(10)

            if (obj.hasCapabilityFlag(Flags.CLIENT_SECURE_CONNECTION)):
                obj.challenge2 = proto.get_fixed_str(max(13, obj.authPluginDataLength - 8))

            if (obj.hasCapabilityFlag(Flags.CLIENT_PLUGIN_AUTH)):
                obj.authPluginName = proto.get_null_str()

        return obj
Exemplo n.º 13
0
    def getPayload(self):
        payload = bytearray()

        payload.extend(Proto.build_fixed_int(1, self.protocolVersion))
        payload.extend(Proto.build_null_str(self.serverVersion))
        payload.extend(Proto.build_fixed_int(4, self.connectionId))
        payload.extend(Proto.build_fixed_str(8, self.challenge1))
        payload.extend(Proto.build_filler(1))
        payload.extend(Proto.build_fixed_int(2, self.capabilityFlags >> 16))
        payload.extend(Proto.build_fixed_int(1, self.characterSet))
        payload.extend(Proto.build_fixed_int(2, self.statusFlags))
        payload.extend(Proto.build_fixed_int(2, self.capabilityFlags & 0xffff))

        if self.hasCapabilityFlag(Flags.CLIENT_PLUGIN_AUTH):
            payload.extend(Proto.build_fixed_int(1, self.authPluginDataLength))
        else:
            payload.extend(Proto.build_filler(1))

        payload.extend(Proto.build_filler(10))

        if self.hasCapabilityFlag(Flags.CLIENT_SECURE_CONNECTION):
            payload.extend(Proto.build_fixed_str(
                max(13, self.authPluginDataLength - 8),
                           self.challenge2))
        if self.hasCapabilityFlag(Flags.CLIENT_PLUGIN_AUTH):
            payload.extend(Proto.build_null_str(self.authPluginName))

        return payload
Exemplo n.º 14
0
def getSequenceId(packet):
    """
    Returns the Sequence ID for the given packet
    """
    return Proto(packet, 3).get_fixed_int(1)
Exemplo n.º 15
0
def getSize(packet):
    """
    Returns a specified packet size
    """
    return Proto(packet).get_fixed_int(3)