1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
/***************************************************************************
* _______ _______ _______ *
* | ___ |____ | ___ | *
* | | |_| / /| | |_| *
* | |_____ / / | |_____ *
* |_____ | / / |_____ | *
* _ | | / / _ | | *
* | |___| |/ /____| |___| | *
* |_______|_______|_______| *
* *
* Wiimms SZS Tools *
* https://szs.wiimm.de/ *
* *
***************************************************************************
* *
* This file is part of the SZS project. *
* Visit https://szs.wiimm.de/ for project details and sources. *
* *
* Copyright (c) 2011-2024 by Dirk Clemens <wiimm@wiimm.de> *
* *
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* See file gpl-2.0.txt or http://www.gnu.org/licenses/gpl-2.0.txt *
* *
***************************************************************************/
#ifndef SZS_LIB_LZMA_H
#define SZS_LIB_LZMA_H 1
#define _GNU_SOURCE 1
#include "lib-std.h"
//
///////////////////////////////////////////////////////////////////////////////
/////////////// definitions ///////////////
///////////////////////////////////////////////////////////////////////////////
#define LZMA_MAGIC_NUM3 0x5d0000 // 3 relevant bytes
#define XZ_MAGIC_NUM6 0xfd377a585a00ull // 6 relevant bytes
#define LZMA_DEFAULT_COMPR 6
//
///////////////////////////////////////////////////////////////////////////////
/////////////// helpers ///////////////
///////////////////////////////////////////////////////////////////////////////
int IsLZ
(
// returns
// -1: not LZ data
// 0: seems to be LZ; compression level is unknown
// 1..9: seems to be LZ; compression level is returned
cvp data, // NULL or data to investigate
uint size // size of 'data'
);
//-----------------------------------------------------------------------------
int IsLZMA
(
// returns
// -1: not LZMA data
// 0: seems to be LZMA data; compression level is unknown
// 1..9: seems to be LZMA data; compression level is returned
cvp data, // NULL or data to investigate
uint size // size of 'data'
);
//-----------------------------------------------------------------------------
int CalcCompressionLevelLZMA
(
int compr_level // valid are 1..9 / 0: use default value
);
//-----------------------------------------------------------------------------
int GetDicSizeByLevel ( int level );
int GetComprLevelLZMA ( u32 dict_size );
//-----------------------------------------------------------------------------
int IsXZ
(
// returns
// -1: not XZ data
// 0: seems to be LZMA data; compression level is unknown
// 1..9: seems to be LZMA data; compression level is returned
cvp data, // NULL or data to investigate
uint size // size of 'data'
);
//-----------------------------------------------------------------------------
ccp GetMessageLZMA
(
int err, // error code
ccp unkown_error // result for unkown error codes
);
//
///////////////////////////////////////////////////////////////////////////////
/////////////// Encode LZMA ///////////////
///////////////////////////////////////////////////////////////////////////////
enumError EncodeLZMAbuf
(
void *dest, // valid destination buffer
uint dest_size, // size of 'dest'
uint *dest_written, // store num bytes written to 'dest', never NULL
const void *src, // source buffer
uint src_size, // size of source buffer
int compr_level, // valid are 1..9 / 0: use default value
bool add_dec_size // true: add decompressed size
);
//-----------------------------------------------------------------------------
enumError EncodeLZMA
(
u8 **dest_ptr, // result: store destination buffer addr
uint *dest_written, // store num bytes written to 'dest', never NULL
bool use_iobuf, // true: allow the usage of 'iobuf'
uint header_size, // insert 'header_size' bytes before dest data
bool add_dec_size, // true: add decompressed size
const void *src, // source buffer
uint src_size, // size of source buffer
int compr_level // valid are 1..9 / 0: use default value
);
//
///////////////////////////////////////////////////////////////////////////////
/////////////// Decode LZMA ///////////////
///////////////////////////////////////////////////////////////////////////////
enumError DecodeLZMAbin
(
u8 **dest_ptr, // result: store destination buffer addr
uint *dest_written, // store num bytes written to 'dest', never NULL
uint header_size, // insert 'header_size' bytes before dest data
const void *src, // source buffer
uint src_size // size of source buffer
);
///////////////////////////////////////////////////////////////////////////////
enumError DecodeLZMApart
(
// decompress until dest buffer full or end of source reached
// return ERR_WARNING for an incomplete decompression
void *dest_buf, // result: store read data here
uint dest_size, // size of 'dest_buf'
uint *dest_written, // store num bytes written to 'dest_ptr', never NULL
const void *src, // source buffer
uint src_size // size of source buffer
);
///////////////////////////////////////////////////////////////////////////////
enumError DecodeLZMAsize
(
u8 **dest_ptr, // result: store destination buffer addr
uint *dest_written, // store num bytes written to 'dest', never NULL
uint header_size, // insert 'header_size' bytes before dest data
const void *src, // source buffer, first 4 bytes = dest size
uint src_size // size of source buffer
);
//
///////////////////////////////////////////////////////////////////////////////
/////////////// END ///////////////
///////////////////////////////////////////////////////////////////////////////
#endif // SZS_LIB_LZMA_H 1
|