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
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
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