Example #1
0
    def decode(self, article, data, raw_data):
        # Do we have SABYenc? Let it do all the work
        if sabnzbd.decoder.SABYENC_ENABLED:
            decoded_data, output_filename, crc, crc_expected, crc_correct = sabyenc.decode_usenet_chunks(
                raw_data, article.bytes)

            # Assume it is yenc
            article.nzf.type = 'yenc'

            # Only set the name if it was found and not obfuscated
            self.verify_filename(article, decoded_data, output_filename)

            # CRC check
            if not crc_correct:
                raise CrcError(crc_expected, crc, decoded_data)

            return decoded_data

        # Continue for _yenc or Python-yEnc
        # Filter out empty ones
        data = filter(None, data)
        # No point in continuing if we don't have any data left
        if data:
            nzf = article.nzf
            yenc, data = yCheck(data)
            ybegin, ypart, yend = yenc

            # Deal with non-yencoded posts
            if not ybegin:
                found = False
                try:
                    for i in xrange(min(40, len(data))):
                        if data[i].startswith('begin '):
                            nzf.type = 'uu'
                            found = True
                            # Pause the job and show warning
                            if nzf.nzo.status != Status.PAUSED:
                                nzf.nzo.pause()
                                msg = T(
                                    'UUencode detected, only yEnc encoding is supported [%s]'
                                ) % nzf.nzo.final_name
                                logging.warning(msg)
                            break
                except IndexError:
                    raise BadYenc()

                if found:
                    decoded_data = ''
                else:
                    raise BadYenc()

            # Deal with yenc encoded posts
            elif ybegin and yend:
                if 'name' in ybegin:
                    output_filename = yenc_name_fixer(ybegin['name'])
                else:
                    output_filename = None
                    logging.debug(
                        "Possible corrupt header detected => ybegin: %s",
                        ybegin)
                nzf.type = 'yenc'
                # Decode data
                if HAVE_YENC:
                    decoded_data, crc = _yenc.decode_string(''.join(data))[:2]
                    partcrc = '%08X' % ((crc ^ -1) & 2**32L - 1)
                else:
                    data = ''.join(data)
                    for i in (0, 9, 10, 13, 27, 32, 46, 61):
                        j = '=%c' % (i + 64)
                        data = data.replace(j, chr(i))
                    decoded_data = data.translate(YDEC_TRANS)
                    crc = binascii.crc32(decoded_data)
                    partcrc = '%08X' % (crc & 2**32L - 1)

                if ypart:
                    crcname = 'pcrc32'
                else:
                    crcname = 'crc32'

                if crcname in yend:
                    _partcrc = yenc_name_fixer('0' * (8 - len(yend[crcname])) +
                                               yend[crcname].upper())
                else:
                    _partcrc = None
                    logging.debug("Corrupt header detected => yend: %s", yend)

                if not _partcrc == partcrc:
                    raise CrcError(_partcrc, partcrc, decoded_data)
            else:
                raise BadYenc()

            # Parse filename if there was data
            if decoded_data:
                # Only set the name if it was found and not obfuscated
                self.verify_filename(article, decoded_data, output_filename)

            return decoded_data
Example #2
0
def decode(article, data):
    # Filter out empty ones
    data = filter(None, data)
    # No point in continuing if we don't have any data left
    if data:
        nzf = article.nzf
        yenc, data = yCheck(data)
        ybegin, ypart, yend = yenc
        decoded_data = None

        # Deal with non-yencoded posts
        if not ybegin:
            found = False
            try:
                for i in xrange(min(40, len(data))):
                    if data[i].startswith('begin '):
                        nzf.type = 'uu'
                        found = True
                        # Pause the job and show warning
                        if nzf.nzo.status != Status.PAUSED:
                            nzf.nzo.pause()
                            msg = T(
                                'UUencode detected, only yEnc encoding is supported [%s]'
                            ) % nzf.nzo.final_name
                            logging.warning(msg)
                        break
            except IndexError:
                raise BadYenc()

            if found:
                decoded_data = ''
            else:
                raise BadYenc()

        # Deal with yenc encoded posts
        elif ybegin and yend:
            if 'name' in ybegin:
                nzf.filename = yenc_name_fixer(ybegin['name'])
            else:
                logging.debug("Possible corrupt header detected => ybegin: %s",
                              ybegin)
            nzf.type = 'yenc'
            # Decode data
            if HAVE_YENC:
                decoded_data, crc = _yenc.decode_string(''.join(data))[:2]
                partcrc = '%08X' % ((crc ^ -1) & 2**32L - 1)
            else:
                data = ''.join(data)
                for i in (0, 9, 10, 13, 27, 32, 46, 61):
                    j = '=%c' % (i + 64)
                    data = data.replace(j, chr(i))
                decoded_data = data.translate(YDEC_TRANS)
                crc = binascii.crc32(decoded_data)
                partcrc = '%08X' % (crc & 2**32L - 1)

            if ypart:
                crcname = 'pcrc32'
            else:
                crcname = 'crc32'

            if crcname in yend:
                _partcrc = '0' * (8 -
                                  len(yend[crcname])) + yend[crcname].upper()
            else:
                _partcrc = None
                logging.debug("Corrupt header detected => yend: %s", yend)

            if not _partcrc == partcrc:
                raise CrcError(_partcrc, partcrc, decoded_data)
        else:
            raise BadYenc()

        return decoded_data
Example #3
0
    def decode(self, article, data, raw_data):
        # Do we have SABYenc? Let it do all the work
        if sabnzbd.decoder.SABYENC_ENABLED:
            decoded_data, output_filename, crc, crc_expected, crc_correct = sabyenc.decode_usenet_chunks(raw_data, article.bytes)

            # Assume it is yenc
            article.nzf.type = 'yenc'

            # Only set the name if it was found and not obfuscated
            self.verify_filename(article, decoded_data, output_filename)

            # CRC check
            if not crc_correct:
                raise CrcError(crc_expected, crc, decoded_data)

            return decoded_data

        # Continue for _yenc or Python-yEnc
        # Filter out empty ones
        data = filter(None, data)
        # No point in continuing if we don't have any data left
        if data:
            nzf = article.nzf
            yenc, data = yCheck(data)
            ybegin, ypart, yend = yenc

            # Deal with non-yencoded posts
            if not ybegin:
                found = False
                try:
                    for i in xrange(min(40, len(data))):
                        if data[i].startswith('begin '):
                            nzf.type = 'uu'
                            found = True
                            # Pause the job and show warning
                            if nzf.nzo.status != Status.PAUSED:
                                nzf.nzo.pause()
                                msg = T('UUencode detected, only yEnc encoding is supported [%s]') % nzf.nzo.final_name
                                logging.warning(msg)
                            break
                except IndexError:
                    raise BadYenc()

                if found:
                    decoded_data = ''
                else:
                    raise BadYenc()

            # Deal with yenc encoded posts
            elif ybegin and yend:
                if 'name' in ybegin:
                    output_filename = yenc_name_fixer(ybegin['name'])
                else:
                    output_filename = None
                    logging.debug("Possible corrupt header detected => ybegin: %s", ybegin)
                nzf.type = 'yenc'
                # Decode data
                if HAVE_YENC:
                    decoded_data, crc = _yenc.decode_string(''.join(data))[:2]
                    partcrc = '%08X' % ((crc ^ -1) & 2 ** 32L - 1)
                else:
                    data = ''.join(data)
                    for i in (0, 9, 10, 13, 27, 32, 46, 61):
                        j = '=%c' % (i + 64)
                        data = data.replace(j, chr(i))
                    decoded_data = data.translate(YDEC_TRANS)
                    crc = binascii.crc32(decoded_data)
                    partcrc = '%08X' % (crc & 2 ** 32L - 1)

                if ypart:
                    crcname = 'pcrc32'
                else:
                    crcname = 'crc32'

                if crcname in yend:
                    _partcrc = yenc_name_fixer('0' * (8 - len(yend[crcname])) + yend[crcname].upper())
                else:
                    _partcrc = None
                    logging.debug("Corrupt header detected => yend: %s", yend)

                if not _partcrc == partcrc:
                    raise CrcError(_partcrc, partcrc, decoded_data)
            else:
                raise BadYenc()

            # Parse filename if there was data
            if decoded_data:
                # Only set the name if it was found and not obfuscated
                self.verify_filename(article, decoded_data, output_filename)

            return decoded_data
Example #4
0
def decode(article, data):
    # Filter out empty ones
    data = filter(None, data)
    # No point in continuing if we don't have any data left
    if data:
        nzf = article.nzf
        yenc, data = yCheck(data)
        ybegin, ypart, yend = yenc
        decoded_data = None

        # Deal with non-yencoded posts
        if not ybegin:
            found = False
            try:
                for i in xrange(min(40, len(data))):
                    if data[i].startswith('begin '):
                        nzf.type = 'uu'
                        found = True
                        # Pause the job and show warning
                        if nzf.nzo.status != Status.PAUSED:
                            nzf.nzo.pause()
                            msg = T('UUencode detected, only yEnc encoding is supported [%s]') % nzf.nzo.final_name
                            logging.warning(msg)
                        break
            except IndexError:
                raise BadYenc()

            if found:
                decoded_data = ''
            else:
                raise BadYenc()

        # Deal with yenc encoded posts
        elif ybegin and yend:
            if 'name' in ybegin:
                nzf.filename = yenc_name_fixer(ybegin['name'])
            else:
                logging.debug("Possible corrupt header detected => ybegin: %s", ybegin)
            nzf.type = 'yenc'
            # Decode data
            if HAVE_YENC:
                decoded_data, crc = _yenc.decode_string(''.join(data))[:2]
                partcrc = '%08X' % ((crc ^ -1) & 2 ** 32L - 1)
            else:
                data = ''.join(data)
                for i in (0, 9, 10, 13, 27, 32, 46, 61):
                    j = '=%c' % (i + 64)
                    data = data.replace(j, chr(i))
                decoded_data = data.translate(YDEC_TRANS)
                crc = binascii.crc32(decoded_data)
                partcrc = '%08X' % (crc & 2 ** 32L - 1)

            if ypart:
                crcname = 'pcrc32'
            else:
                crcname = 'crc32'

            if crcname in yend:
                _partcrc = '0' * (8 - len(yend[crcname])) + yend[crcname].upper()
            else:
                _partcrc = None
                logging.debug("Corrupt header detected => yend: %s", yend)

            if not _partcrc == partcrc:
                raise CrcError(_partcrc, partcrc, decoded_data)
        else:
            raise BadYenc()

        return decoded_data
Example #5
0
def decode(article, data):
    data = strip(data)
    # No point in continuing if we don't have any data left
    if data:
        nzf = article.nzf
        yenc, data = yCheck(data)
        ybegin, ypart, yend = yenc
        decoded_data = None

        # Deal with non-yencoded posts
        if not ybegin:
            found = False
            try:
                for i in xrange(min(40, len(data))):
                    if data[i].startswith('begin '):
                        nzf.filename = yenc_name_fixer(data[i].split(None, 2)[2])
                        nzf.type = 'uu'
                        found = True
                        break
                if found:
                    for n in xrange(i + 1):
                        data.pop(0)
                if data[-1] == 'end':
                    data.pop()
                    if data[-1] == '`':
                        data.pop()
            except IndexError:
                raise BadYenc()

            if found:
                decoded_data = '\r\n'.join(data)
            else:
                raise BadYenc()

        # Deal with yenc encoded posts
        elif (ybegin and yend):
            if 'name' in ybegin:
                nzf.filename = yenc_name_fixer(ybegin['name'])
            else:
                logging.debug("Possible corrupt header detected => ybegin: %s", ybegin)
            nzf.type = 'yenc'
            # Decode data
            if HAVE_YENC:
                decoded_data, crc = _yenc.decode_string(''.join(data))[:2]
                partcrc = '%08X' % ((crc ^ -1) & 2 ** 32L - 1)
            else:
                data = ''.join(data)
                for i in (0, 9, 10, 13, 27, 32, 46, 61):
                    j = '=%c' % (i + 64)
                    data = data.replace(j, chr(i))
                decoded_data = data.translate(YDEC_TRANS)
                crc = binascii.crc32(decoded_data)
                partcrc = '%08X' % (crc & 2 ** 32L - 1)

            if ypart:
                crcname = 'pcrc32'
            else:
                crcname = 'crc32'

            if crcname in yend:
                _partcrc = '0' * (8 - len(yend[crcname])) + yend[crcname].upper()
            else:
                _partcrc = None
                logging.debug("Corrupt header detected => yend: %s", yend)

            if not (_partcrc == partcrc):
                raise CrcError(_partcrc, partcrc, decoded_data)
        else:
            raise BadYenc()

        return decoded_data