1 /* conf.h --
2
3 This file is part of the UPX executable compressor.
4
5 Copyright (C) 1996-2020 Markus Franz Xaver Johannes Oberhumer
6 Copyright (C) 1996-2020 Laszlo Molnar
7 All Rights Reserved.
8
9 UPX and the UCL library are free software; you can redistribute them
10 and/or modify them under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of
12 the License, or (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; see the file COPYING.
21 If not, write to the Free Software Foundation, Inc.,
22 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24 Markus F.X.J. Oberhumer Laszlo Molnar
25 <markus@oberhumer.com> <ezerotven+github@gmail.com>
26 */
27
28
29 #ifndef __UPX_CONF_H
30 #define __UPX_CONF_H 1
31
32 #include "version.h"
33
34 #if !defined(_FILE_OFFSET_BITS)
35 # define _FILE_OFFSET_BITS 64
36 #endif
37 #undef NDEBUG
38
39
40 /*************************************************************************
41 // ACC
42 **************************************************************************/
43
44 #ifndef ACC_CFG_USE_NEW_STYLE_CASTS
45 #define ACC_CFG_USE_NEW_STYLE_CASTS 1
46 #endif
47 #define ACC_CFG_PREFER_TYPEOF_ACC_INT32E_T ACC_TYPEOF_INT
48 #define ACC_CFG_PREFER_TYPEOF_ACC_INT64E_T ACC_TYPEOF_LONG_LONG
49 #include "miniacc.h"
50 #if !(ACC_CC_CLANG || ACC_CC_GNUC || ACC_CC_MSC)
51 // other compilers may work, but we're NOT interested into supporting them
52 # error "only clang and gcc are officially supported"
53 #endif
54 // UPX sanity checks for a sane compiler
55 #if !defined(UINT_MAX) || (UINT_MAX != 0xffffffffL)
56 # error "UINT_MAX"
57 #endif
58 ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(int) == 4)
59 ACC_COMPILE_TIME_ASSERT_HEADER((1u << 31) << 1 == 0)
60 ACC_COMPILE_TIME_ASSERT_HEADER(((int)(1u << 31)) >> 31 == -1) // arithmetic right shift
61 ACC_COMPILE_TIME_ASSERT_HEADER(CHAR_MAX == 255) // -funsigned-char
62 ACC_COMPILE_TIME_ASSERT_HEADER((char)(-1) > 0) // -funsigned-char
63
64 #if (ACC_CC_MSC)
65 # pragma warning(error: 4127)
66 # pragma warning(error: 4146)
67 # pragma warning(error: 4319)
68 # pragma warning(error: 4805)
69 # pragma warning(disable: 4244) // -Wconversion
70 # pragma warning(disable: 4267) // -Wconversion
71 # pragma warning(disable: 4820) // padding added after data member
72 #endif
73
74 // FIXME - quick hack for arm-wince-gcc-3.4 (Debian pocketpc-*.deb packages)
75 #if 1 && (ACC_ARCH_ARM) && defined(__pe__) && !defined(__CEGCC__) && !defined(_WIN32)
76 # undef HAVE_CHMOD
77 # undef HAVE_CHOWN
78 # undef HAVE_LSTAT
79 # undef HAVE_UTIME
80 #endif
81
82 #define ACC_WANT_ACC_INCD_H 1
83 #define ACC_WANT_ACC_INCE_H 1
84 #define ACC_WANT_ACC_LIB_H 1
85 #define ACC_WANT_ACC_CXX_H 1
86 #include "miniacc.h"
87
88 /* intergral types */
89 typedef acc_int8_t upx_int8_t;
90 typedef acc_uint8_t upx_uint8_t;
91 typedef acc_int16_t upx_int16_t;
92 typedef acc_uint16_t upx_uint16_t;
93 typedef acc_int32_t upx_int32_t;
94 typedef acc_uint32_t upx_uint32_t;
95 typedef acc_int64_t upx_int64_t;
96 typedef acc_uint64_t upx_uint64_t;
97 typedef acc_uintptr_t upx_uintptr_t;
98 #define UPX_INT16_C ACC_INT16_C
99 #define UPX_UINT16_C ACC_UINT16_C
100 #define UPX_INT32_C ACC_INT32_C
101 #define UPX_UINT32_C ACC_UINT32_C
102 #define UPX_INT64_C ACC_INT64_C
103 #define UPX_UINT64_C ACC_UINT64_C
104
105 typedef unsigned char upx_byte;
106 #define upx_bytep upx_byte *
107
108
109 /*************************************************************************
110 //
111 **************************************************************************/
112
113 #if defined(__linux__) && !defined(__unix__)
114 # define __unix__ 1
115 #endif
116
117 // just in case
118 #undef _
119 #undef __
120 #undef ___
121 #undef dos
122 #undef linux
123 #undef small
124 #undef tos
125 #undef unix
126 #if (ACC_OS_DOS32) && defined(__DJGPP__)
127 # undef sopen
128 # undef __unix__
129 # undef __unix
130 #endif
131
132 #define WITH_LZMA 0x443
133 #define WITH_UCL 1
134 #define WITH_ZLIB 1
135 #if (WITH_UCL)
136 # define ucl_compress_config_t REAL_ucl_compress_config_t
137 # include <ucl/uclconf.h>
138 # include <ucl/ucl.h>
139 # if !defined(UCL_VERSION) || (UCL_VERSION < 0x010300L)
140 # error "please upgrade your UCL installation"
141 # endif
142 # undef ucl_compress_config_t
143 # undef ucl_compress_config_p
144 #endif
145
146 // malloc debuggers
147 #if (WITH_VALGRIND)
148 # include <valgrind/memcheck.h>
149 #endif
150 #if !defined(VALGRIND_MAKE_MEM_DEFINED)
151 # define VALGRIND_MAKE_MEM_DEFINED(addr,len) 0
152 #endif
153 #if !defined(VALGRIND_MAKE_MEM_NOACCESS)
154 # define VALGRIND_MAKE_MEM_NOACCESS(addr,len) 0
155 #endif
156 #if !defined(VALGRIND_MAKE_MEM_UNDEFINED)
157 # define VALGRIND_MAKE_MEM_UNDEFINED(addr,len) 0
158 #endif
159
160 // IMPORTANT: unconditionally enable assertions
161 #undef NDEBUG
162 #include <assert.h>
163
164 // protect against integer overflows and malicious header fields
165 // see C 11 standard, Annex K
166 typedef size_t upx_rsize_t;
167 #define UPX_RSIZE_MAX UPX_RSIZE_MAX_MEM
168 #define UPX_RSIZE_MAX_MEM (768 * 1024 * 1024) // DO NOT CHANGE
169 #define UPX_RSIZE_MAX_STR (1024 * 1024)
170
171
172 /*************************************************************************
173 // portab
174 **************************************************************************/
175
176 #ifndef STDIN_FILENO
177 # define STDIN_FILENO (fileno(stdin))
178 #endif
179 #ifndef STDOUT_FILENO
180 # define STDOUT_FILENO (fileno(stdout))
181 #endif
182 #ifndef STDERR_FILENO
183 # define STDERR_FILENO (fileno(stderr))
184 #endif
185
186 #if !(HAVE_STRCASECMP) && (HAVE_STRICMP)
187 # define strcasecmp stricmp
188 #endif
189 #if !(HAVE_STRNCASECMP) && (HAVE_STRNICMP)
190 # define strncasecmp strnicmp
191 #endif
192
193 #if !defined(S_IWUSR) && defined(_S_IWUSR)
194 # define S_IWUSR _S_IWUSR
195 #elif !defined(S_IWUSR) && defined(_S_IWRITE)
196 # define S_IWUSR _S_IWRITE
197 #endif
198
199 #if !defined(S_IFMT) && defined(_S_IFMT)
200 # define S_IFMT _S_IFMT
201 #endif
202 #if !defined(S_IFREG) && defined(_S_IFREG)
203 # define S_IFREG _S_IFREG
204 #endif
205 #if !defined(S_IFDIR) && defined(_S_IFDIR)
206 # define S_IFDIR _S_IFDIR
207 #endif
208 #if !defined(S_IFCHR) && defined(_S_IFCHR)
209 # define S_IFCHR _S_IFCHR
210 #endif
211
212 #if !defined(S_ISREG)
213 # if defined(S_IFMT) && defined(S_IFREG)
214 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
215 # else
216 # error "S_ISREG"
217 # endif
218 #endif
219 #if !defined(S_ISDIR)
220 # if defined(S_IFMT) && defined(S_IFDIR)
221 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
222 # else
223 # error "S_ISDIR"
224 # endif
225 #endif
226 #if !defined(S_ISCHR)
227 # if defined(S_IFMT) && defined(S_IFCHR)
228 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
229 # endif
230 #endif
231
232 // avoid warnings about shadowing global functions
233 #undef basename
234 #undef index
235 #undef outp
236 #define basename upx_basename
237 #define index upx_index
238 #define outp upx_outp
239
240 #undef PAGE_MASK
241 #undef PAGE_SIZE
242
243 #if !defined(O_BINARY) || (O_BINARY+0 == 0)
244 # if (ACC_OS_CYGWIN || ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_EMX || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
245 # error "missing O_BINARY"
246 # endif
247 #endif
248 #if !defined(O_BINARY)
249 # define O_BINARY 0
250 #endif
251
252 #ifndef OPTIONS_VAR
253 # define OPTIONS_VAR "UPX"
254 #endif
255
256
257 /*************************************************************************
258 //
259 **************************************************************************/
260
261 #if (ACC_CC_MSC)
262 #define __packed_struct(s) struct s {
263 #define __packed_struct_end() };
264 #else
265 #define __packed_struct(s) __acc_struct_packed(s)
266 #define __packed_struct_end() __acc_struct_packed_end()
267 #endif
268
269 #define UNUSED(var) ACC_UNUSED(var)
270 #define COMPILE_TIME_ASSERT(e) ACC_COMPILE_TIME_ASSERT(e)
271
272 #define __COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b) { \
273 typedef a acc_tmp_a_t; typedef b acc_tmp_b_t; \
274 __packed_struct(acc_tmp_t) acc_tmp_b_t x; acc_tmp_a_t y; acc_tmp_b_t z; __packed_struct_end() \
275 COMPILE_TIME_ASSERT(sizeof(struct acc_tmp_t) == 2*sizeof(b)+sizeof(a)) \
276 COMPILE_TIME_ASSERT(sizeof(((acc_tmp_t*)0)->x)+sizeof(((acc_tmp_t*)0)->y)+sizeof(((acc_tmp_t*)0)->z) == 2*sizeof(b)+sizeof(a)) \
277 }
278 #if defined(__acc_alignof)
279 # define __COMPILE_TIME_ASSERT_ALIGNOF(a,b) \
280 __COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b) \
281 COMPILE_TIME_ASSERT(__acc_alignof(a) == sizeof(b))
282 #else
283 # define __COMPILE_TIME_ASSERT_ALIGNOF(a,b) \
284 __COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b)
285 #endif
286 #define COMPILE_TIME_ASSERT_ALIGNED1(a) __COMPILE_TIME_ASSERT_ALIGNOF(a,char)
287
288 #define TABLESIZE(table) ((sizeof(table)/sizeof((table)[0])))
289
290
291 template <class T>
ALIGN_DOWN(const T & a,const T & b)292 inline T ALIGN_DOWN(const T& a, const T& b) { T r; r = (a / b) * b; return r; }
293 template <class T>
ALIGN_UP(const T & a,const T & b)294 inline T ALIGN_UP (const T& a, const T& b) { T r; r = ((a + b - 1) / b) * b; return r; }
295 template <class T>
ALIGN_GAP(const T & a,const T & b)296 inline T ALIGN_GAP (const T& a, const T& b) { T r; r = ALIGN_UP(a, b) - a; return r; }
297
298 template <class T>
UPX_MAX(const T & a,const T & b)299 inline const T& UPX_MAX(const T& a, const T& b) { if (a < b) return b; return a; }
300 template <class T>
UPX_MIN(const T & a,const T & b)301 inline const T& UPX_MIN(const T& a, const T& b) { if (a < b) return a; return b; }
302
303
304 // An Array allocates memory on the heap, but automatically
305 // gets destructed when leaving scope or on exceptions.
306 #define Array(type, var, size) \
307 MemBuffer var ## _membuf(mem_size(sizeof(type), size)); \
308 type * const var = ACC_STATIC_CAST(type *, var ## _membuf.getVoidPtr())
309
310 #define ByteArray(var, size) Array(unsigned char, var, size)
311
312 class noncopyable
313 {
314 protected:
noncopyable()315 inline noncopyable() {}
~noncopyable()316 inline ~noncopyable() {}
317 private:
318 noncopyable(const noncopyable &); // undefined
319 const noncopyable& operator=(const noncopyable &); // undefined
320 };
321
322
323 /*************************************************************************
324 // constants
325 **************************************************************************/
326
327 /* exit codes of this program: 0 ok, 1 error, 2 warning */
328 #define EXIT_OK 0
329 #define EXIT_ERROR 1
330 #define EXIT_WARN 2
331
332 #define EXIT_USAGE 1
333 #define EXIT_FILE_READ 1
334 #define EXIT_FILE_WRITE 1
335 #define EXIT_MEMORY 1
336 #define EXIT_CHECKSUM 1
337 #define EXIT_INIT 1
338 #define EXIT_INTERNAL 1
339
340
341 // magic constants for patching
342 #define UPX_MAGIC_LE32 0x21585055 /* "UPX!" */
343 #define UPX_MAGIC2_LE32 0xD5D0D8A1
344
345
346 // upx_compress() error codes
347 #define UPX_E_OK (0)
348 #define UPX_E_ERROR (-1)
349 #define UPX_E_OUT_OF_MEMORY (-2)
350 #define UPX_E_NOT_COMPRESSIBLE (-3)
351 #define UPX_E_INPUT_OVERRUN (-4)
352 #define UPX_E_OUTPUT_OVERRUN (-5)
353 #define UPX_E_LOOKBEHIND_OVERRUN (-6)
354 #define UPX_E_EOF_NOT_FOUND (-7)
355 #define UPX_E_INPUT_NOT_CONSUMED (-8)
356 #define UPX_E_NOT_YET_IMPLEMENTED (-9)
357 #define UPX_E_INVALID_ARGUMENT (-10)
358
359
360 // Executable formats. Note: big endian types are >= 128.
361 #define UPX_F_DOS_COM 1
362 #define UPX_F_DOS_SYS 2
363 #define UPX_F_DOS_EXE 3
364 #define UPX_F_DJGPP2_COFF 4
365 #define UPX_F_WATCOM_LE 5
366 #define UPX_F_VXD_LE 6 // NOT IMPLEMENTED
367 #define UPX_F_DOS_EXEH 7 // OBSOLETE
368 #define UPX_F_TMT_ADAM 8
369 #define UPX_F_WIN32_PE 9
370 #define UPX_F_LINUX_i386 10
371 #define UPX_F_WIN16_NE 11 // NOT IMPLEMENTED
372 #define UPX_F_LINUX_ELF_i386 12
373 #define UPX_F_LINUX_SEP_i386 13 // NOT IMPLEMENTED
374 #define UPX_F_LINUX_SH_i386 14
375 #define UPX_F_VMLINUZ_i386 15
376 #define UPX_F_BVMLINUZ_i386 16
377 #define UPX_F_ELKS_8086 17 // NOT IMPLEMENTED
378 #define UPX_F_PS1_EXE 18
379 #define UPX_F_VMLINUX_i386 19
380 #define UPX_F_LINUX_ELFI_i386 20
381 #define UPX_F_WINCE_ARM_PE 21
382 #define UPX_F_LINUX_ELF64_AMD 22
383 #define UPX_F_LINUX_ELF32_ARMEL 23
384 #define UPX_F_BSD_i386 24
385 #define UPX_F_BSD_ELF_i386 25
386 #define UPX_F_BSD_SH_i386 26
387
388 #define UPX_F_VMLINUX_AMD64 27
389 #define UPX_F_VMLINUX_ARMEL 28
390 #define UPX_F_MACH_i386 29
391 #define UPX_F_LINUX_ELF32_MIPSEL 30
392 #define UPX_F_VMLINUZ_ARMEL 31
393 #define UPX_F_MACH_ARMEL 32
394
395 #define UPX_F_DYLIB_i386 33
396 #define UPX_F_MACH_AMD64 34
397 #define UPX_F_DYLIB_AMD64 35
398
399 #define UPX_F_WIN64_PEP 36
400
401 #define UPX_F_MACH_ARM64EL 37
402
403 #define UPX_F_MACH_PPC64LE 38
404 #define UPX_F_LINUX_ELFPPC64LE 39
405 #define UPX_F_VMLINUX_PPC64LE 40
406 #define UPX_F_DYLIB_PPC64LE 41
407
408 #define UPX_F_LINUX_ELF64_ARM 42
409
410 #define UPX_F_ATARI_TOS 129
411 #define UPX_F_SOLARIS_SPARC 130 // NOT IMPLEMENTED
412 #define UPX_F_MACH_PPC32 131
413 #define UPX_F_LINUX_ELFPPC32 132
414 #define UPX_F_LINUX_ELF32_ARMEB 133
415 #define UPX_F_MACH_FAT 134
416 #define UPX_F_VMLINUX_ARMEB 135
417 #define UPX_F_VMLINUX_PPC32 136
418 #define UPX_F_LINUX_ELF32_MIPSEB 137
419 #define UPX_F_DYLIB_PPC32 138
420
421 #define UPX_F_MACH_PPC64 139
422 #define UPX_F_LINUX_ELFPPC64 140
423 #define UPX_F_VMLINUX_PPC64 141
424 #define UPX_F_DYLIB_PPC64 142
425
426 // compression methods
427 #define M_ALL (-1)
428 #define M_END (-2)
429 #define M_NONE (-3)
430 #define M_SKIP (-4)
431 #define M_ULTRA_BRUTE (-5)
432 // compression methods - DO NOT CHANGE
433 #define M_NRV2B_LE32 2
434 #define M_NRV2B_8 3
435 #define M_NRV2B_LE16 4
436 #define M_NRV2D_LE32 5
437 #define M_NRV2D_8 6
438 #define M_NRV2D_LE16 7
439 #define M_NRV2E_LE32 8
440 #define M_NRV2E_8 9
441 #define M_NRV2E_LE16 10
442 //#define M_CL1B_LE32 11
443 //#define M_CL1B_8 12
444 //#define M_CL1B_LE16 13
445 #define M_LZMA 14
446 #define M_DEFLATE 15 /* zlib */
447
448 #define M_IS_NRV2B(x) ((x) >= M_NRV2B_LE32 && (x) <= M_NRV2B_LE16)
449 #define M_IS_NRV2D(x) ((x) >= M_NRV2D_LE32 && (x) <= M_NRV2D_LE16)
450 #define M_IS_NRV2E(x) ((x) >= M_NRV2E_LE32 && (x) <= M_NRV2E_LE16)
451 //#define M_IS_CL1B(x) ((x) >= M_CL1B_LE32 && (x) <= M_CL1B_LE16)
452 #define M_IS_LZMA(x) (((x) & 255) == M_LZMA)
453 #define M_IS_DEFLATE(x) ((x) == M_DEFLATE)
454
455
456 // filters
457 #define FT_END (-1)
458 #define FT_NONE (-2)
459 #define FT_SKIP (-3)
460 #define FT_ULTRA_BRUTE (-4)
461
462
463 /*************************************************************************
464 // compression - callback_t
465 **************************************************************************/
466
467 struct upx_callback_t;
468 typedef upx_callback_t *upx_callback_p;
469 typedef void (__acc_cdecl *upx_progress_func_t)
470 (upx_callback_p, unsigned, unsigned);
471
472 struct upx_callback_t
473 {
474 upx_progress_func_t nprogress;
475 void *user;
476
resetupx_callback_t477 void reset() { memset(this, 0, sizeof(*this)); }
478 };
479
480
481 /*************************************************************************
482 // compression - config_t
483 **************************************************************************/
484
485 template <class T, T default_value_, T min_value_, T max_value_>
486 struct OptVar
487 {
488 typedef T value_type;
489 static const T default_value = default_value_;
490 static const T min_value = min_value_;
491 static const T max_value = max_value_;
492
assertValueOptVar493 static void assertValue(const T &v) {
494 // info: this generates annoying warnings "unsigned >= 0 is always true"
495 //assert(v >= min_value);
496 assert(v == min_value || v >= min_value + 1);
497 assert(v <= max_value);
498 }
assertValueOptVar499 void assertValue() const {
500 assertValue(v);
501 }
502
OptVarOptVar503 OptVar() : v(default_value), is_set(0) { }
504 OptVar& operator= (const T &other) {
505 v = other; is_set = 1;
506 assertValue();
507 return *this;
508 }
509
resetOptVar510 void reset() { v = default_value; is_set = 0; }
TOptVar511 operator T () const { return v; }
512
513 T v;
514 unsigned is_set;
515 };
516
517
518 // optional assignments
519 template <class T, T a, T b, T c>
oassign(OptVar<T,a,b,c> & self,const OptVar<T,a,b,c> & other)520 inline void oassign(OptVar<T,a,b,c> &self, const OptVar<T,a,b,c> &other) {
521 if (other.is_set) { self.v = other.v; self.is_set = 1; }
522 }
523 template <class T, T a, T b, T c>
oassign(T & v,const OptVar<T,a,b,c> & other)524 inline void oassign(T &v, const OptVar<T,a,b,c> &other) {
525 if (other.is_set) { v = other.v; }
526 }
527
528
529 struct lzma_compress_config_t
530 {
531 typedef OptVar<unsigned, 2u, 0u, 4u> pos_bits_t; // pb
532 typedef OptVar<unsigned, 0u, 0u, 4u> lit_pos_bits_t; // lp
533 typedef OptVar<unsigned, 3u, 0u, 8u> lit_context_bits_t; // lc
534 typedef OptVar<unsigned, (1u<<22), 1u, (1u<<30) > dict_size_t;
535 typedef OptVar<unsigned, 64u, 5u, 273u> num_fast_bytes_t;
536
537 pos_bits_t pos_bits; // pb
538 lit_pos_bits_t lit_pos_bits; // lp
539 lit_context_bits_t lit_context_bits; // lc
540 dict_size_t dict_size;
541 unsigned fast_mode;
542 num_fast_bytes_t num_fast_bytes;
543 unsigned match_finder_cycles;
544
545 unsigned max_num_probs;
546
547 void reset();
548 };
549
550
551 struct ucl_compress_config_t : public REAL_ucl_compress_config_t
552 {
resetucl_compress_config_t553 void reset() { memset(this, 0xff, sizeof(*this)); }
554 };
555
556
557 struct zlib_compress_config_t
558 {
559 typedef OptVar<unsigned, 8u, 1u, 9u> mem_level_t; // ml
560 typedef OptVar<unsigned, 15u, 9u, 15u> window_bits_t; // wb
561 typedef OptVar<unsigned, 0u, 0u, 4u> strategy_t; // st
562
563 mem_level_t mem_level; // ml
564 window_bits_t window_bits; // wb
565 strategy_t strategy; // st
566
567 void reset();
568 };
569
570
571 struct upx_compress_config_t
572 {
573 lzma_compress_config_t conf_lzma;
574 ucl_compress_config_t conf_ucl;
575 zlib_compress_config_t conf_zlib;
resetupx_compress_config_t576 void reset() { conf_lzma.reset(); conf_ucl.reset(); conf_zlib.reset(); }
577 };
578
579 #define NULL_cconf ((upx_compress_config_t *) NULL)
580
581
582 /*************************************************************************
583 // compression - result_t
584 **************************************************************************/
585
586 struct lzma_compress_result_t
587 {
588 unsigned pos_bits; // pb
589 unsigned lit_pos_bits; // lp
590 unsigned lit_context_bits; // lc
591 unsigned dict_size;
592 unsigned fast_mode;
593 unsigned num_fast_bytes;
594 unsigned match_finder_cycles;
595 unsigned num_probs; // (computed result)
596
resetlzma_compress_result_t597 void reset() { memset(this, 0, sizeof(*this)); }
598 };
599
600
601 struct ucl_compress_result_t
602 {
603 ucl_uint result[16];
604
resetucl_compress_result_t605 void reset() { memset(this, 0, sizeof(*this)); }
606 };
607
608
609 struct zlib_compress_result_t
610 {
611 unsigned dummy;
612
resetzlib_compress_result_t613 void reset() { memset(this, 0, sizeof(*this)); }
614 };
615
616
617 struct upx_compress_result_t
618 {
619 // debug
620 int method, level;
621 unsigned u_len, c_len;
622
623 lzma_compress_result_t result_lzma;
624 ucl_compress_result_t result_ucl;
625 zlib_compress_result_t result_zlib;
626
resetupx_compress_result_t627 void reset() {
628 memset(this, 0, sizeof(*this));
629 result_lzma.reset(); result_ucl.reset(); result_zlib.reset();
630 }
631 };
632
633
634 /*************************************************************************
635 // globals
636 **************************************************************************/
637
638 #include "snprintf.h" // must get included first!
639 #include "stdcxx.h"
640 #include "options.h"
641 #include "except.h"
642 #include "bele.h"
643 #include "util.h"
644 #include "console.h"
645
646
647 // classes
648 class ElfLinker;
649 typedef ElfLinker Linker;
650
651
652 // main.cpp
653 extern const char *progname;
654 bool set_exit_code(int ec);
655 #if (ACC_CC_CLANG || ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
656 void e_exit(int ec) __attribute__((__noreturn__));
657 #else
658 void e_exit(int ec);
659 #endif
660
661
662 // msg.cpp
663 void printSetNl(int need_nl);
664 void printClearLine(FILE *f = NULL);
665 void printErr(const char *iname, const Throwable *e);
666 void printUnhandledException(const char *iname, const std::exception *e);
667 #if (ACC_CC_CLANG || ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
668 void __acc_cdecl_va printErr(const char *iname, const char *format, ...)
669 __attribute__((__format__(__printf__,2,3)));
670 void __acc_cdecl_va printWarn(const char *iname, const char *format, ...)
671 __attribute__((__format__(__printf__,2,3)));
672 #else
673 void __acc_cdecl_va printErr(const char *iname, const char *format, ...);
674 void __acc_cdecl_va printWarn(const char *iname, const char *format, ...);
675 #endif
676
677 #if (ACC_CC_CLANG || ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
678 void __acc_cdecl_va infoWarning(const char *format, ...)
679 __attribute__((__format__(__printf__,1,2)));
680 void __acc_cdecl_va infoHeader(const char *format, ...)
681 __attribute__((__format__(__printf__,1,2)));
682 void __acc_cdecl_va info(const char *format, ...)
683 __attribute__((__format__(__printf__,1,2)));
684 #else
685 void __acc_cdecl_va infoWarning(const char *format, ...);
686 void __acc_cdecl_va infoHeader(const char *format, ...);
687 void __acc_cdecl_va info(const char *format, ...);
688 #endif
689 void infoHeader();
690 void infoWriting(const char *what, long size);
691
692
693 // work.cpp
694 void do_one_file(const char *iname, char *oname);
695 void do_files(int i, int argc, char *argv[]);
696
697
698 // help.cpp
699 extern const char gitrev[];
700 void show_head(void);
701 void show_help(int verbose=0);
702 void show_license(void);
703 void show_usage(void);
704 void show_version(int);
705
706
707 // compress.cpp
708 unsigned upx_adler32(const void *buf, unsigned len, unsigned adler=1);
709 unsigned upx_crc32(const void *buf, unsigned len, unsigned crc=0);
710
711 int upx_compress ( const upx_bytep src, unsigned src_len,
712 upx_bytep dst, unsigned* dst_len,
713 upx_callback_p cb,
714 int method, int level,
715 const upx_compress_config_t *cconf,
716 upx_compress_result_t *cresult );
717 int upx_decompress ( const upx_bytep src, unsigned src_len,
718 upx_bytep dst, unsigned* dst_len,
719 int method,
720 const upx_compress_result_t *cresult );
721 int upx_test_overlap ( const upx_bytep buf,
722 const upx_bytep tbuf,
723 unsigned src_off, unsigned src_len,
724 unsigned* dst_len,
725 int method,
726 const upx_compress_result_t *cresult );
727
728
729 #if (ACC_OS_CYGWIN || ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_EMX || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
730 # if defined(INVALID_HANDLE_VALUE) || defined(MAKEWORD) || defined(RT_CURSOR)
731 # error "something pulled in <windows.h>"
732 # endif
733 #endif
734
735
736 #endif /* already included */
737
738 /* vim:set ts=4 sw=4 et: */
739