Rizin
unix-like reverse engineering framework and cli tools
kwaj.h
Go to the documentation of this file.
1 /* This file is part of libmspack.
2  * (C) 2003-2010 Stuart Caie.
3  *
4  * libmspack is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License (LGPL) version 2.1
6  *
7  * For further details, see the file COPYING.LIB distributed with libmspack
8  */
9 
10 #ifndef MSPACK_KWAJ_H
11 #define MSPACK_KWAJ_H 1
12 
13 #include <lzss.h>
14 
15 /* generic KWAJ definitions */
16 #define kwajh_Signature1 (0x00)
17 #define kwajh_Signature2 (0x04)
18 #define kwajh_CompMethod (0x08)
19 #define kwajh_DataOffset (0x0a)
20 #define kwajh_Flags (0x0c)
21 #define kwajh_SIZEOF (0x0e)
22 
23 /* KWAJ compression definitions */
24 
26  struct mskwaj_compressor base;
28  /* todo */
29  int param[2]; /* !!! MATCH THIS TO NUM OF PARAMS IN MSPACK.H !!! */
30  int error;
31 };
32 
33 /* KWAJ decompression definitions */
34 
38  int error;
39 };
40 
42  struct mskwajd_header base;
43  struct mspack_file *fh;
44 };
45 
46 /* input buffer size during decompression - not worth parameterising IMHO */
47 #define KWAJ_INPUT_SIZE (2048)
48 
49 /* huffman codes that are 9 bits or less are decoded immediately */
50 #define KWAJ_TABLEBITS (9)
51 
52 /* number of codes in each huffman table */
53 #define KWAJ_MATCHLEN1_SYMS (16)
54 #define KWAJ_MATCHLEN2_SYMS (16)
55 #define KWAJ_LITLEN_SYMS (32)
56 #define KWAJ_OFFSET_SYMS (64)
57 #define KWAJ_LITERAL_SYMS (256)
58 
59 /* define decoding table sizes */
60 #define KWAJ_TABLESIZE (1 << KWAJ_TABLEBITS)
61 #if KWAJ_TABLESIZE < (KWAJ_MATCHLEN1_SYMS * 2)
62 # define KWAJ_MATCHLEN1_TBLSIZE (KWAJ_MATCHLEN1_SYMS * 4)
63 #else
64 # define KWAJ_MATCHLEN1_TBLSIZE (KWAJ_TABLESIZE + (KWAJ_MATCHLEN1_SYMS * 2))
65 #endif
66 #if KWAJ_TABLESIZE < (KWAJ_MATCHLEN2_SYMS * 2)
67 # define KWAJ_MATCHLEN2_TBLSIZE (KWAJ_MATCHLEN2_SYMS * 4)
68 #else
69 # define KWAJ_MATCHLEN2_TBLSIZE (KWAJ_TABLESIZE + (KWAJ_MATCHLEN2_SYMS * 2))
70 #endif
71 #if KWAJ_TABLESIZE < (KWAJ_LITLEN_SYMS * 2)
72 # define KWAJ_LITLEN_TBLSIZE (KWAJ_LITLEN_SYMS * 4)
73 #else
74 # define KWAJ_LITLEN_TBLSIZE (KWAJ_TABLESIZE + (KWAJ_LITLEN_SYMS * 2))
75 #endif
76 #if KWAJ_TABLESIZE < (KWAJ_OFFSET_SYMS * 2)
77 # define KWAJ_OFFSET_TBLSIZE (KWAJ_OFFSET_SYMS * 4)
78 #else
79 # define KWAJ_OFFSET_TBLSIZE (KWAJ_TABLESIZE + (KWAJ_OFFSET_SYMS * 2))
80 #endif
81 #if KWAJ_TABLESIZE < (KWAJ_LITERAL_SYMS * 2)
82 # define KWAJ_LITERAL_TBLSIZE (KWAJ_LITERAL_SYMS * 4)
83 #else
84 # define KWAJ_LITERAL_TBLSIZE (KWAJ_TABLESIZE + (KWAJ_LITERAL_SYMS * 2))
85 #endif
86 
87 struct kwajd_stream {
88  /* I/O buffering */
89  struct mspack_system *sys;
90  struct mspack_file *input;
92  unsigned char *i_ptr, *i_end;
93  unsigned int bit_buffer, bits_left;
94  int input_end;
95 
96  /* huffman code lengths */
99  unsigned char LITLEN_len [KWAJ_LITLEN_SYMS];
100  unsigned char OFFSET_len [KWAJ_OFFSET_SYMS];
102 
103  /* huffman decoding tables */
109 
110  /* input buffer */
111  unsigned char inbuf[KWAJ_INPUT_SIZE];
112 
113  /* history window */
114  unsigned char window[LZSS_WINDOW_SIZE];
115 };
116 
117 
118 #endif
#define KWAJ_OFFSET_SYMS
Definition: kwaj.h:56
#define KWAJ_LITLEN_SYMS
Definition: kwaj.h:55
#define KWAJ_OFFSET_TBLSIZE
Definition: kwaj.h:79
#define KWAJ_LITERAL_SYMS
Definition: kwaj.h:57
#define KWAJ_MATCHLEN2_SYMS
Definition: kwaj.h:54
#define KWAJ_MATCHLEN2_TBLSIZE
Definition: kwaj.h:69
#define KWAJ_LITLEN_TBLSIZE
Definition: kwaj.h:74
#define KWAJ_INPUT_SIZE
Definition: kwaj.h:47
#define KWAJ_MATCHLEN1_SYMS
Definition: kwaj.h:53
#define KWAJ_MATCHLEN1_TBLSIZE
Definition: kwaj.h:64
#define KWAJ_LITERAL_TBLSIZE
Definition: kwaj.h:84
#define LZSS_WINDOW_SIZE
Definition: lzss.h:19
unsigned short MATCHLEN1_table[KWAJ_MATCHLEN1_TBLSIZE]
Definition: kwaj.h:104
unsigned short LITLEN_table[KWAJ_LITLEN_TBLSIZE]
Definition: kwaj.h:106
struct mspack_file * output
Definition: kwaj.h:91
struct mspack_file * input
Definition: kwaj.h:90
unsigned char LITERAL_len[KWAJ_LITERAL_SYMS]
Definition: kwaj.h:101
unsigned int bit_buffer
Definition: kwaj.h:93
unsigned char * i_end
Definition: kwaj.h:92
unsigned short OFFSET_table[KWAJ_OFFSET_TBLSIZE]
Definition: kwaj.h:107
unsigned short MATCHLEN2_table[KWAJ_MATCHLEN2_TBLSIZE]
Definition: kwaj.h:105
unsigned char MATCHLEN1_len[KWAJ_MATCHLEN1_SYMS]
Definition: kwaj.h:97
unsigned char LITLEN_len[KWAJ_LITLEN_SYMS]
Definition: kwaj.h:99
struct mspack_system * sys
Definition: kwaj.h:89
unsigned char MATCHLEN2_len[KWAJ_MATCHLEN2_SYMS]
Definition: kwaj.h:98
int input_end
Definition: kwaj.h:94
unsigned char inbuf[KWAJ_INPUT_SIZE]
Definition: kwaj.h:111
unsigned short LITERAL_table[KWAJ_LITERAL_TBLSIZE]
Definition: kwaj.h:108
unsigned char OFFSET_len[KWAJ_OFFSET_SYMS]
Definition: kwaj.h:100
unsigned char * i_ptr
Definition: kwaj.h:92
unsigned int bits_left
Definition: kwaj.h:93
struct mskwaj_compressor base
Definition: kwaj.h:26
int param[2]
Definition: kwaj.h:29
struct mspack_system * system
Definition: kwaj.h:27
struct mskwaj_decompressor base
Definition: kwaj.h:36
struct mspack_system * system
Definition: kwaj.h:37
struct mskwajd_header base
Definition: kwaj.h:42
struct mspack_file * fh
Definition: kwaj.h:43