1 /* 2 * Extract RAR archives 3 * 4 * Modified for JtR, (c) magnum 2012. This code use a memory buffer instead 5 * of a file handle, and decrypts while reading. It does not store inflated 6 * data, it just CRC's it. Support for older RAR versions was stripped. 7 * Autoconf stuff was removed. 8 * 9 * Copyright (C) 2005-2006 trog@uncon.org 10 * 11 * This code is based on the work of Alexander L. Roshal (C) 12 * 13 * The unRAR sources may be used in any software to handle RAR 14 * archives without limitations free of charge, but cannot be used 15 * to re-create the RAR compression algorithm, which is proprietary. 16 * Distribution of modified unRAR sources in separate form or as a 17 * part of other software is permitted, provided that it is clearly 18 * stated in the documentation and source comments that the code may 19 * not be used to develop a RAR (WinRAR) compatible archiver. 20 * 21 */ 22 23 24 #ifndef UNRAR_PPM_H 25 #define UNRAR_PPM_H 1 26 27 #define N1 4 28 #define N2 4 29 #define N3 4 30 #define N4 26 31 #define N_INDEXES 38 32 33 typedef struct rar_mem_blk_tag 34 { 35 struct rar_mem_blk_tag *next, *prev; 36 unsigned short stamp, nu; 37 } rar_mem_blk_t; 38 39 struct rar_node 40 { 41 struct rar_node *next; 42 }; 43 44 typedef struct sub_allocator_tag 45 { 46 unsigned char *ptext, *units_start, *heap_end, *fake_units_start; 47 unsigned char *heap_start, *lo_unit, *hi_unit; 48 long sub_allocator_size; 49 struct rar_node free_list[N_INDEXES]; 50 short indx2units[N_INDEXES], units2indx[128], glue_count; 51 } sub_allocator_t; 52 53 typedef struct range_coder_tag 54 { 55 unsigned int low, code, range; 56 unsigned int low_count, high_count, scale; 57 }range_coder_t; 58 59 struct ppm_context; 60 61 struct see2_context_tag 62 { 63 unsigned short summ; 64 unsigned char shift, count; 65 }; 66 67 #ifdef _MSC_VER 68 #define __attribute__(a) 69 #pragma pack(1) 70 #endif 71 struct state_tag 72 { 73 struct ppm_context *successor; 74 unsigned char symbol; 75 unsigned char freq; 76 } __attribute__((packed)); 77 78 struct freq_data_tag 79 { 80 struct state_tag *stats; 81 unsigned short summ_freq; 82 } __attribute__((packed)); 83 84 struct ppm_context { 85 struct ppm_context *suffix; 86 union { 87 struct freq_data_tag u; 88 struct state_tag one_state; 89 } con_ut; 90 unsigned short num_stats; 91 } __attribute__((packed)); 92 93 #ifdef _MSC_VER 94 #undef __attribute__ 95 #pragma pack() 96 #endif 97 98 typedef struct ppm_data_tag 99 { 100 struct state_tag *found_state; 101 struct ppm_context *min_context, *max_context; 102 struct see2_context_tag see2cont[25][16], dummy_sse2cont; 103 int num_masked; 104 sub_allocator_t sub_alloc; 105 range_coder_t coder; 106 int init_esc, order_fall, max_order, run_length, init_rl; 107 unsigned char char_mask[256], ns2indx[256], ns2bsindx[256], hb2flag[256]; 108 unsigned short bin_summ[128][64]; 109 unsigned char esc_count, prev_success, hi_bits_flag; 110 111 } ppm_data_t; 112 113 void ppm_cleanup(ppm_data_t *ppm_data); 114 int ppm_decode_init(ppm_data_t *ppm_data, const unsigned char **fd, struct unpack_data_tag *unpack_data, int *EscChar); 115 int ppm_decode_char(ppm_data_t *ppm_data, const unsigned char **fd, struct unpack_data_tag *unpack_data); 116 void ppm_constructor(ppm_data_t *ppm_data); 117 void ppm_destructor(ppm_data_t *ppm_data); 118 119 #endif 120