static PyObject* CPPMDecoder_decode(decoders_CPPMDecoder *self, PyObject *args) { char* input_buffer; #ifdef PY_SSIZE_T_CLEAN Py_ssize_t input_len; #else int input_len; #endif uint8_t* output_buffer; int output_len; PyObject* decoded; if (!PyArg_ParseTuple(args, "s#", &input_buffer, &input_len)) return NULL; if (input_len % DVDCPXM_BLOCK_SIZE) { PyErr_SetString(PyExc_ValueError, "encoded block must be a multiple of 2048"); return NULL; } output_len = input_len; output_buffer = malloc(sizeof(uint8_t) * output_len); memcpy(output_buffer, input_buffer, input_len); cppm_decrypt(&(self->decoder), output_buffer, output_len / DVDCPXM_BLOCK_SIZE, 1); decoded = PyString_FromStringAndSize((char *)output_buffer, (Py_ssize_t)output_len); free(output_buffer); return decoded; }
static int read_sector(DVDA_Sector_Reader* reader, struct bs_buffer* sector) { if (reader->current.sector <= reader->end_sector) { DVDA_AOB* aob = reader->current.aob; static uint8_t sector_data[SECTOR_SIZE]; const size_t bytes_read = fread(sector_data, sizeof(uint8_t), SECTOR_SIZE, aob->file); buf_write(sector, sector_data, (uint32_t)bytes_read); if (bytes_read == SECTOR_SIZE) { /*sector read successfully*/ #ifdef HAS_UNPROT /*unprotect if necessary*/ if (reader->cppm_decoder != NULL) { cppm_decrypt(reader->cppm_decoder, sector_data, 1, 1); } #endif /*then move on to next sector*/ reader->current.sector++; if (reader->current.sector > aob->end_sector) { /*move on to next AOB in set, if any*/ if (reader->current.sector <= reader->end_sector) { seek_sector(reader, reader->current.sector); } } return 0; } else { /*I/O error reading sector*/ return 1; } } else { /*no more sectors to read, so return EOF*/ return 0; } }