unsigned int rar_get_char(const unsigned char **fd, unpack_data_t *unpack_data) { if (unpack_data->in_addr > MAX_BUF_SIZE-30) { if (!rar_unp_read_buf(fd, unpack_data)) { rar_dbgmsg("rar_get_char: rar_unp_read_buf FAILED\n"); return -1; } } rar_dbgmsg("rar_get_char = %u\n", unpack_data->in_buf[unpack_data->in_addr]); return(unpack_data->in_buf[unpack_data->in_addr++]); }
static void execute_code(unpack_data_t *unpack_data, struct rarvm_prepared_program *prg) { rar_dbgmsg("in execute_code\n"); rar_dbgmsg("global_size: %ld\n", prg->global_size); if (prg->global_size > 0) { prg->init_r[6] = int64to32(unpack_data->written_size); rarvm_set_value(0, (unsigned int *)&prg->global_data[0x24], int64to32(unpack_data->written_size)); rarvm_set_value(0, (unsigned int *)&prg->global_data[0x28], int64to32(unpack_data->written_size>>32)); rarvm_execute(&unpack_data->rarvm_data, prg); }
static int read_tables20(int fd, unpack_data_t *unpack_data) { unsigned char bit_length[BC20]; unsigned char table[MC20 * 4]; int table_size, n, i, number; unsigned int bit_field; rar_dbgmsg("in read_tables20\n"); if (unpack_data->in_addr > unpack_data->read_top-25) { if (!rar_unp_read_buf(fd, unpack_data)) { return FALSE; } } bit_field = rar_getbits(unpack_data); unpack_data->unp_audio_block = (bit_field & 0x8000); if (!(bit_field & 0x4000)) { memset(unpack_data->unp_old_table20, 0, sizeof(unpack_data->unp_old_table20)); } rar_addbits(unpack_data, 2); if (unpack_data->unp_audio_block) { unpack_data->unp_channels = ((bit_field>>12) & 3) + 1; if (unpack_data->unp_cur_channel >= unpack_data->unp_channels) { unpack_data->unp_cur_channel = 0; } rar_addbits(unpack_data, 2); table_size = MC20 * unpack_data->unp_channels; } else {
void rar_unp_write_buf_old(unpack_data_t *unpack_data) { rar_dbgmsg("in rar_unp_write_buf_old\n"); if (unpack_data->unp_ptr < unpack_data->wr_ptr) { unp_write_data(unpack_data, &unpack_data->window[unpack_data->wr_ptr], -unpack_data->wr_ptr & MAXWINMASK); unp_write_data(unpack_data, unpack_data->window, unpack_data->unp_ptr); } else { unp_write_data(unpack_data, &unpack_data->window[unpack_data->wr_ptr], unpack_data->unp_ptr - unpack_data->wr_ptr); } unpack_data->wr_ptr = unpack_data->unp_ptr; }
static void unp_write_data(unpack_data_t *unpack_data, unsigned char *data, int size) { rar_dbgmsg("in unp_write_data length=%d\n", size); unpack_data->true_size += size; unpack_data->unp_crc = rar_crc(unpack_data->unp_crc, data, size); if(unpack_data->max_size) { if(unpack_data->written_size >= unpack_data->max_size) return; if(unpack_data->written_size + size > unpack_data->max_size) size = unpack_data->max_size - unpack_data->written_size; } unpack_data->written_size += size; }
void *rar_malloc(size_t size) { void *alloc; if(!size || size > RAR_MAX_ALLOCATION) { rar_dbgmsg("UNRAR: rar_malloc(): Attempt to allocate %lu bytes. Please report to http://bugs.clamav.net\n", size); return NULL; } alloc = malloc(size); if(!alloc) { fprintf(stderr, "UNRAR: rar_malloc(): Can't allocate memory (%lu bytes).\n", size); return NULL; } else return alloc; }