Beispiel #1
0
    def _parse_main_response(self, response_raw, subrequests):
        self.log.debug('Parsing main RPC response...')

        if response_raw.status_code == 403:
            raise ServerSideAccessForbiddenException("Seems your IP Address is banned or something else went badly wrong...")
        elif response_raw.status_code == 502:
            raise ServerBusyOrOfflineException("502: Bad Gateway")
        elif response_raw.status_code != 200:
            error = 'Unexpected HTTP server response - needs 200 got {}'.format(response_raw.status_code)
            self.log.warning(error)
            self.log.debug('HTTP output: \n%s', response_raw.content.decode('utf-8'))
            raise UnexpectedResponseException(error)

        if response_raw.content is None:
            self.log.warning('Empty server response!')
            return False

        response_proto = ResponseEnvelope()
        try:
            response_proto.ParseFromString(response_raw.content)
        except message.DecodeError as e:
            self.log.warning('Could not parse response: %s', e)
            return False

        self.log.debug('Protobuf structure of rpc response:\n\r%s', response_proto)
        try:
            self.log.debug('Decode raw over protoc (protoc has to be in your PATH):\n\r%s', self.decode_raw(response_raw.content).decode('utf-8'))
        except:
            self.log.debug('Error during protoc parsing - ignored.')

        response_proto_dict = protobuf_to_dict(response_proto)
        response_proto_dict = self._parse_sub_responses(response_proto, subrequests, response_proto_dict)

        return response_proto_dict
Beispiel #2
0
def response(context, flow):
    if not flow.request.url.startswith('https://pgorelease.nianticlabs.com/plfe'):
        return

    try:
        response_body = decode_gzip(flow.response.content)
        envelope = ResponseEnvelope()
        envelope.ParseFromString(response_body)
    except:
        return

    context.log('Got response for request {}.'.format(envelope.request_id))
    if envelope.request_id not in requested:
        context.log('Unknown request {}.'.format(envelope.request_id))
        return
    if response_envelope_handler:
        context.log('Handling response {}...'.format(envelope.response_id))
        response_envelope_handler(context, envelope)

    for i, response in enumerate(envelope.returns):
        request_type = requested[envelope.request_id][i]
        context.log('Got response for request type {}.'.format(request_type), level='debug')
        if request_type not in response_decoders or request_type not in response_handlers:
            continue

        context.log('Handling response for request type {}...'.format(request_type))
        response_proto_name = '{}Response'.format(response_decoders[request_type])
        message_proto_import = __import__('POGOProtos.Networking.Responses.{}_pb2'.format(response_proto_name), globals(),
                                          locals(), fromlist=[response_proto_name])
        message = getattr(message_proto_import, response_proto_name)

        response_obj = message()
        response_obj.ParseFromString(response)

        response_handlers[request_type](context, response_obj)

        envelope.returns[i] = response_obj.SerializeToString()

    processed_response_body = envelope.SerializeToString()
    processed_content = encode_gzip(processed_response_body)
    flow.response.content = processed_content