-
Notifications
You must be signed in to change notification settings - Fork 7
/
unz.c
executable file
·7958 lines (7036 loc) · 251 KB
/
unz.c
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright 2009-2017 Luigi Auriemma
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
http://www.gnu.org/licenses/gpl-2.0.txt
*/
// all the compression algorithms
// what to do if the output buffer is overflowed:
// - break ok: return what has been written till now which is very good for the compression scanner and buggy implementations
// - return -1 error: return an error and interrupt the extraction
#define quickbms_unz_output_overflow break // return -1
void *calldll_alloc(u8 *dump, u32 dumpsz, u32 argc, ...);
#define MYALLOC_ZEROES 16 // long story, anyway keep 16 for both XmemDecompress and general padding/blocks (indeed AES uses 16 bytes)
#define ASURACMP // comment it if the input doesn't have the first 8 bytes assigned to zsize and size
#include "included/asura_huffboh.c"
#include "included/lzss.c"
#include "included/lzssx.c"
#include "compression/quicklz.h"
//#include "compression/unq3huff.c"
int unq3huff( unsigned char *in, int insz, unsigned char *out, int outsz );
#include "included/unrlew.c"
#include "included/unmeng.c"
#include "included/unlz2k.c"
#include "included/undarksector.c"
#include "included/un49g.c"
#include "included/unthandor.c"
#include "included/tzar_lzss.c"
#include "compression/lzh.h"
#include "compression/sr3c.h"
#include "included/undk2.c"
#include "included/stalker_lza.c"
#include "included/puyo.c"
#include "included/rdc.c"
#include "included/ilzr.c"
#include "compression/libLZR.h"
#include "included/mppc.c"
#include "included/un434a.c"
#include "included/fal_codec.c"
#include "compression/doomhuff.h"
#include "included/msf.c"
#include "included/ntcompress.c"
#include "included/undact.c"
#include "included/lz77_0.c"
#include "included/lzbss.c"
//#include "included/bgbpaq0.c"
int BPAQ0_DecodeData(u8 *in, u8 *out);
//#include "included/dict.c"
int DictDecode (u8 *buf, unsigned bufsize, u8 *outbuf, unsigned *outsize);
#include "included/rep.c"
#include "included/elias.c"
#include "included/kzip_old.c"
#include "libs/uberflate/uberflate.c"
#include "included/enet_compress.c"
#include "included/lzfu.c"
#include "included/he3.c"
#include "included/ntfs_compress.c"
#include "included/comprlib.c"
#include "included/hd2.c"
#include "included/prs.cpp"
#include "included/sega_lz77.c"
#include "included/unyakuza.c"
#define LZ4F_DISABLE_OBSOLETE_ENUMS
#include "libs/lz4/lz4.h"
#include "libs/lz4/lz4frame.h"
#include "libs/lz4/lz4hc.h"
LZ4_streamDecode_t *g_LZ4_streamDecode = NULL;
#define LZ5F_DISABLE_OBSOLETE_ENUMS
#include "libs/lz5/lz5.h"
#include "libs/lz5/lz5frame.h"
#include "libs/lz5/lz5hc.h"
#include "libs/lizard/lizard_compress.h"
#include "libs/lizard/lizard_decompress.h"
#include "included/lunar.c"
#include "included/goldensun.c"
#include "included/luminousarc.c"
#include "compression/fastlz.h"
//#include "included/zax.c"
int zax_uncompress(unsigned char *infd, int insz, unsigned char *outfd, int outsz);
#include "compression/Shrinker.h"
#include "libs/mmini/mmini.h"
#include "libs/clzw/lzw.h"
#include "included/lzham.c"
#include "included/sega_lzs2.c"
#include "libs/lzlib/lzlib.h"
#include "included/undflt.c"
#include "included/ffce.c"
#include "libs/snappy/snappy-c.h"
#include "compression/scummvm.h"
#include "included/compression_unknown.c"
#include "included/blackdesert_unpack.c"
#include "included/zyxel_lzsd.c"
#include "libs/blosc/blosclz.h"
#include "included/crush.c"
#include "libs/liblzg/src/include/lzg.h"
#include "included/yappy.c"
#include "libs/aplib/depacks.h"
#include "included/xpksqsh.c"
#include "included/unpxp.c"
#include "included/boh.c"
#include "included/qfs.c"
#include "libs/zstd/common/fse.h"
#include "libs/zstd/zstd.h"
#define HEATSHRINK_DYNAMIC_ALLOC
#include "libs/heatshrink/heatshrink_decoder.h"
#include "libs/heatshrink/heatshrink_encoder.h"
#include "libs/TurboRLE/trle.h"
#include "libs/TurboRLE/ext/mrle.h"
#include "compression/smaz.h"
#include "compression/lzfx.h"
#include "compression/pithy.h"
#include "libs/density/src/density_api.h"
#include "libs/brotli/dec/decode.h"
#include "libs/libbsc/libbsc.h"
#include "libs/shoco/shoco.h"
#include "compression/wfLZ.h"
#include "compression/FastAri.h"
#include "compression/dicky.h"
#include "compression/squish.h"
#include "libs/ms-compress/include/lznt1.h"
#include "libs/ms-compress/include/xpress.h"
#include "libs/ms-compress/include/xpress_huff.h"
#include "included/neptunia.c"
#include "included/compresslayla.c"
#include "libs/lhasa/lib/public/lha_decoder.h"
#include "included/old_bizarre.c"
#include "libs/liblzf/lzf.h"
// never use lzf_compress, use EVER lzf_compress_best!
unsigned int
lzf_compress_best (const void *const in_data, unsigned int in_len,
void *out_data, unsigned int out_len
#if LZF_STATE_ARG
, LZF_STATE_BEST state
#endif
);
#include "libs/zopfli/zopfli.h"
#include "included/yay0dec.c"
#include "compression/tinf.h"
#include "included/lego_ixs.c"
#include "libs/mylibmcomp/libmcomp.c"
#include "included/ea_comp.c"
#include "included/ea_huff.c"
#include "included/ea_jdlz.c"
#include "compression/filter-lzw.h"
#include "included/kofdecompress.c"
#include "included/unrfpk.c"
#include "included/wp16.c"
#include "included/oodle.c"
#include "included/rodecompress.c"
#include "libs/lzfse/src/lzfse.h"
#include "libs/mydzip/dzip.c"
int stac_decompress(unsigned char*buf_in, int len_in, unsigned char*buf_out, int len_out);
int sd3_decomp(void* pin,int lin, void* pout, int lout, int flg);
int sd4_decomp(void* pin,int lin, void* pout, int lout, int flg);
int ds_dec(void* pin,int lin, void* pout, int lout, int flg);
int jm_dec(void* pin,int lin, void* pout, int lout, int flg);
int refpack_decompress_safe(const uint8_t *indata, size_t insize,
size_t *bytes_read_out, uint8_t *outdata, size_t outsize,
size_t *bytes_written_out, uint32_t *compressed_size_out,
uint32_t *decompressed_size_out
, int skip_header);
u8* DecryptAsh( const u8* ba_data , int *ret_size, int optional_outsz);
int bpe_compress (unsigned char *in, int insz, unsigned char *out, int outsz, int yuke);
int sqx1_decoder(unsigned char *in, int insz, unsigned char *out, int outsz, int has_compflags);
int dipperstein_decompress(unsigned char *in, int insz, unsigned char *out, int outsz, int compression);
unsigned int lzrw1kh_Compression(u8 *Source, u8 *Dest, unsigned int SourceSize);
unsigned int lzrw1kh_Decompression(u8 *Source, u8 *Dest, unsigned int SourceSize);
void *lzhlight_initComp(void);
void lzhlight_delComp(void *comp);
size_t lzhlight_compress(void *comp, unsigned char *buf, size_t size, unsigned char *ret);
void *lzhlight_initDecomp(void);
size_t lzhlight_decompress(void *decomp, unsigned char *buf, size_t size, unsigned char *ret, size_t retsize);
void lzhlight_delDecomp(void *decomp);
extern int lzjody_compress(const unsigned char * const, unsigned char * const,
const unsigned int, const unsigned int);
extern int lzjody_decompress(const unsigned char * const, unsigned char * const,
const unsigned int, const unsigned int);
int csc_decompress(unsigned char *in, int insz, unsigned char *out, int outsz);
int zling_compress(unsigned char *in, int insz, unsigned char *out, int outsz);
int zling_decompress(unsigned char *in, int insz, unsigned char *out, int outsz);
int de_compress(unsigned long ibytes, int mb, unsigned char *infp, unsigned char *out);
int de_huffman(unsigned long obytes, unsigned char *infp, unsigned char *out_ptr);
int lzd(unsigned char * input_f, unsigned char * output_f);
void BLZ_Decode(char *filename);
void BLZ_Encode(char *filename, int mode);
void HUF_Decode(char *filename);
void HUF_Encode(char *filename, int cmd);
void LZE_Decode(char *filename);
void LZE_Encode(char *filename);
void LZS_Decode(char *filename);
void LZS_Encode(char *filename, int mode);
void LZX_Decode(char *filename);
void LZX_Encode(char *filename, int cmd, int vram);
void RLE_Decode(char *filename);
void RLE_Encode(char *filename);
int nintendo_ds_set_inout(unsigned char *in, int insz, unsigned char *out, int outsz);
#include "included/nintendo.c"
int unpp20(unsigned char *in, int insz, unsigned char *out, int outsz);
int unazo(unsigned char *in, int insz, unsigned char *out, int outsz);
int __cdecl zen_decompress (char* pScrBuffer, char* pDstBuffer, int dwSize);
int pucrunch_UnPack(int loadAddr, const unsigned char *data, unsigned char *file, int flags);
static int clzw_outsz = 0;
void lzw_writebuf(void *stream, char *buf, unsigned size) {
memcpy(stream + clzw_outsz, buf, size);
clzw_outsz += size;
}
int unlpaq8(unsigned char *in, int insz, unsigned char *out, int size, int mem, int meth);
int rLZV1 (unsigned char *in, unsigned char *out, int ilen, int len);
int lzmat_decode(u8 *pbOut, u32 *pcbOut, u8 *pbIn, u32 cbIn);
// 7z_advancecomp is used only for zlib/deflate compression on Windows and it doesn't affect the performance (memory/cpu when launched)
//#ifdef WIN32
int advancecomp_rfc1950(unsigned char *in, int insz, unsigned char *out, int outsz);
int advancecomp_deflate(unsigned char *in, int insz, unsigned char *out, int outsz);
int advancecomp_lzma(unsigned char *in, int insz, unsigned char *out, int outsz, int lzma_flags);
//#else
// #define zlib_compress advancecomp_rfc1950
// #define deflate_compress advancecomp_deflate
// //#define lzma_compress advancecomp_lzma
//#endif
int KENS_Nemesis(unsigned char *in, int insz, unsigned char *out, int outsz);
int KENS_Kosinski(unsigned char *in, int insz, unsigned char *out, int outsz, int Moduled);
int KENS_Enigma(unsigned char *in, int insz, unsigned char *out, int outsz);
int KENS_Saxman(unsigned char *in, int insz, unsigned char *out, int outsz);
int _rnc_unpack(const unsigned char* input, unsigned long input_size, unsigned char* output, unsigned long have_ret_len);
void *rnc_pack (void *data, long datalen, long *packlen);
long rnc_unpack (void *packed, void *unpacked, long *leeway, long packed_len, long unpacked_len);
int PAK_explode(unsigned char * srcBuffer, unsigned char * dstBuffer, unsigned compressedSize, unsigned uncompressedSize, unsigned short flags);
int gz_unpack(unsigned char *in, int insz, unsigned char *out, int outsz);
int dmc2_uncompress(unsigned char *in, int insz, unsigned char *out, int outsz);
int ahuff_ExpandMemory(unsigned char *in, int insz, unsigned char *out, int outsz);
int arith_ExpandMemory(unsigned char *in, int insz, unsigned char *out, int outsz);
int arith1_ExpandMemory(unsigned char *in, int insz, unsigned char *out, int outsz);
int arith1e_ExpandMemory(unsigned char *in, int insz, unsigned char *out, int outsz);
int arithn_ExpandMemory(unsigned char *in, int insz, unsigned char *out, int outsz);
int compand_ExpandMemory(unsigned char *in, int insz, unsigned char *out, int outsz);
int huff_ExpandMemory(unsigned char *in, int insz, unsigned char *out, int outsz);
int tdcb_lzss_init(int x1, int x2, int x3, int x4);
int lzss_ExpandMemory(unsigned char *in, int insz, unsigned char *out, int outsz);
int lzw12_ExpandMemory(unsigned char *in, int insz, unsigned char *out, int outsz);
int lzw15v_ExpandMemory(unsigned char *in, int insz, unsigned char *out, int outsz);
int silence_ExpandMemory(unsigned char *in, int insz, unsigned char *out, int outsz);
int lzrw1_compress_decompress(unsigned char *p_wrk_mem, unsigned char *p_src_first, unsigned int src_len, unsigned char *p_dst_first, unsigned int *p_dst_len);
int lzrw1a_compress_decompress(unsigned char *p_wrk_mem, unsigned char *p_src_first, unsigned int src_len, unsigned char *p_dst_first, unsigned int *p_dst_len);
int lzrw2_compress_decompress(unsigned char *p_wrk_mem, unsigned char *p_src_first, unsigned int src_len, unsigned char *p_dst_first, unsigned int *p_dst_len);
int lzrw3_compress_decompress(unsigned char *p_wrk_mem, unsigned char *p_src_first, unsigned int src_len, unsigned char *p_dst_first, unsigned int *p_dst_len);
int lzrw3a_compress_decompress(unsigned char *p_wrk_mem, unsigned char *p_src_first, unsigned int src_len, unsigned char *p_dst_first, unsigned int *p_dst_len);
int lzrw5_compress_decompress(unsigned char *p_wrk_mem, unsigned char *p_src_first, unsigned int src_len, unsigned char *p_dst_first, unsigned int *p_dst_len);
#define perform_lzrw_decompress(X,Y) \
t32 = size; \
p = calloc(Y, 1); \
lzrw##X##_compress_decompress(p, in, zsize, out, &t32); \
FREE(p) \
size = t32;
int unsqueeze(unsigned char *in, int insz, unsigned char *out, int outsz);
int d3101(unsigned char *in, int insz, unsigned char *out, int outsz);
int yuke_bpe(unsigned char *in, int insz, unsigned char *out, int outsz, int fill_outsz);
int huffman_decode_memory(const unsigned char *bufin, int bufinlen, unsigned char **bufout, int *pbufoutlen);
int huffman_encode_memory(const unsigned char *bufin, int bufinlen, unsigned char **pbufout, int *pbufoutlen);
void Huffman_Uncompress( unsigned char *in, unsigned char *out, unsigned insize, unsigned outsize );
int Huffman_Compress( unsigned char *in, unsigned char *out, unsigned insize );
void LZ_Uncompress( unsigned char *in, unsigned char *out, unsigned insize );
int LZ_Compress( unsigned char *in, unsigned char *out, unsigned insize );
void Rice_Uncompress( void *in, void *out, unsigned insize, unsigned outsize, int format );
int Rice_Compress( void *in, void *out, unsigned insize, int format );
unsigned RLE_Uncompress( unsigned char *in, unsigned insize, unsigned char *out, unsigned outsize );
unsigned RLE_Compress( unsigned char *in, unsigned insize, unsigned char *out, unsigned outsize );
void SF_Uncompress( unsigned char *in, unsigned char *out, unsigned insize, unsigned outsize );
int SF_Compress( unsigned char *in, unsigned char *out, unsigned insize );
int Scz_Decompress_Buffer2Buffer( char *inbuffer, int N, char **outbuffer, int *M );
//int szip_allow_encoding = 0;
int SZ_encoder_enabled();
int SZ_BufftoBuffDecompress(void *dest, size_t *destLen, const void *source, size_t sourceLen, void *param);
int SZ_BufftoBuffCompress(void *dest, size_t *destLen, const void *source, size_t sourceLen, void *param);
int unbpe2(unsigned char *in, int insz, unsigned char *out, int outsz);
int strexpand(unsigned char *dest, unsigned char *source, int sourcelen, int maxlen, unsigned char *input_pairtable, int input_pairtable_default);
int hstest_hs_unpack(unsigned char *out, unsigned char *in, int insz);
int hstest_unpackc(unsigned char *out, unsigned char *in, int insz);
int unsixpack(unsigned char *in, int insz, unsigned char *out, int outsz);
int unashford(unsigned char *in, int insz, unsigned char *out, int outsz);
__stdcall int JCALG1_Decompress_Small(void *Source, void *Destination);
__stdcall void * JCALG1_AllocFunc(unsigned nMemSize) { return(malloc(nMemSize)); }
__stdcall int JCALG1_DeallocFunc(void *pBuffer) { free(pBuffer); return 1; }
__stdcall int JCALG1_CallbackFunc(unsigned pSourcePos, unsigned pDestinationPos) { return 1; }
__stdcall unsigned JCALG1_Compress(void *Source, unsigned Length, void *Destination, unsigned WindowSize, void *pAlloc, void *pDealloc, void *pCallback, int bDisableChecksum);
int unjam(unsigned char *in, int insz, unsigned char *out, int outsz);
int unsrank(unsigned char *in, int insz, unsigned char *out, int outsz);
int ZzUncompressBlock(unsigned char *buffer);
int sh_DecodeBlock(unsigned char *iBlock, unsigned char *oBlock, int bSize);
unsigned blz_depack_safe(const void *source, unsigned srclen, void *destination, unsigned depacked_length);
unsigned blz_depack(const void *source, void *destination, unsigned depacked_length);
unsigned blz_workmem_size(unsigned length);
unsigned blz_max_packed_size(unsigned length);
unsigned blz_pack(const void *source, void *destination, unsigned length, void *workmem);
int unpaq6(unsigned char *in, int insz, unsigned char *out, int outsz, int levelx);
int unppmdi(unsigned char *in, int insz, unsigned char *out, int outsz);
int unppmdi_raw(unsigned char *in, int insz, unsigned char *out, int outsz, int SaSize, int MaxOrder, int MRMethod);
int unppmdg(unsigned char *in, int insz, unsigned char *out, int outsz);
int unppmdg_raw(unsigned char *in, int insz, unsigned char *out, int outsz, int SaSize, int MaxOrder);
int unppmdj(unsigned char *in, int insz, unsigned char *out, int outsz);
int unppmdj_raw(unsigned char *in, int insz, unsigned char *out, int outsz, int SaSize, int MaxOrder, int CutOff);
int unppmdh(unsigned char *in, int insz, unsigned char *out, int outsz);
int unppmdh_raw(unsigned char *in, int insz, unsigned char *out, int outsz, int SaSize, int MaxOrder);
int unshrink(unsigned char *in, int insz, unsigned char *out, int outsz);
int irolz_uncompress(unsigned char *in, int insz, unsigned char *out, int outsz);
int irolz2_uncompress(unsigned char *in, int insz, unsigned char *out, int outsz);
int unquad(unsigned char *in, int insz, unsigned char *out, int outsz);
int unbalz(unsigned char *in, int insz, unsigned char *out, int outsz);
unsigned GRZip_DecompressBlock(unsigned char * Input, unsigned Size, unsigned char * Output);
int de_lzah(unsigned char *in, int insz, unsigned char *out, int obytes);
int de_lzh(unsigned char *in, int ibytes, unsigned char *out, int obytes, int bits);
int bpe_expand(unsigned char *in, int insz, unsigned char *out, int outsz);
int unlzh(unsigned char *in, int insz, unsigned char *out, int outsz);
int unlzari(unsigned char *in, int insz, unsigned char *out, int outsz);
int uncompress_lzw(unsigned char *in, int insz, unsigned char *out, int outsz, int init_byte);
int undmc(unsigned char *in, int insz, unsigned char *out, int outsz);
int unlzx(unsigned char *in, int insz, unsigned char *out, int outsz);
int unmspack(unsigned char *in, int insz, unsigned char *out, int outsz, int window_bits, int interval, int algo);
uint32_t unlzw(uint8_t *outbuff, uint32_t maxsize, uint8_t *in, uint32_t insize);
uint32_t unlzwx(uint8_t *outbuff, uint32_t maxsize, uint8_t *in, uint32_t insize);
u32 __stdcall nitroDecompress(u8 *srcp, u32 size, u8 *dstp, signed char depth);
u32 __stdcall nitroCompress(u8 *srcp, u32 size, u8 *dstp, char *compList, u8 rawHeader);
u32 DiffFiltRead(u8 *srcp, u32 size, u8 *dstp, u8 diffBitSize);
u32 RLCompRead(u8 *srcp, u32 size, u8 *dstp);
u32 LZCompRead(u8 *srcp, u32 size, u8 *dstp);
u32 HuffCompRead(u8 *srcp, u32 size, u8 *dstp, u8 huffBitSize);
int unctw(unsigned char *in, int insz, unsigned char *out, int outsz);
int lzpx_unpack(unsigned char *in, unsigned char *out);
long ultima4_lzwDecompress(unsigned char* compressedMem, unsigned char* decompressedMem, long compressedSize);
int iris_decompress(unsigned char *in, int insz, unsigned char *out, int outsz);
int iris_huffman(char *in, int insz, char *out, int outsz);
int iris_uo_huffman(char *in, int insz, char *out, int outsz);
int LZXdecompress(unsigned char *inbuf, unsigned char *outbuf, unsigned inlen, unsigned outlen);
int MRCIDecompressWrapper(const void *pb, int cb, const void *pOut, int cbOut); // return is S_OK
int zpaq_decompress(unsigned char *in, int insz, unsigned char *out, int outsz);
int zpaq_compress(unsigned char *in, int insz, unsigned char *out, int outsz);
int gipfeli_uncompress(void *in, int insz, void *out, int outsz);
int gipfeli_compress(void *in, int insz, void *out, int outsz);
int doboz_decompress(void *in, int insz, void *out, int outsz);
int doboz_compress(void *in, int insz, void *out, int outsz);
int tornado_decompress(unsigned char *in, int insz, unsigned char *out, int outsz, int algo);
int flzp_decompress(unsigned char *in, int insz, unsigned char *out);
int sr3_decompress(unsigned char *in, int insz, unsigned char *out, int outsz, int version, int profile);
int StormLib_Compress_huff(void * out, int outsz, void * in, int insz);
int StormLib_Decompress_huff(void * out, int outsz, void * in, int insz);
enum CompressorTypes
{
CT_RawCompressor = 0,
CT_HughesTransform = 1,
CT_LZ77 = 2,
CT_ELSCoder = 3,
CT_RefPack = 4,
};
int shadowforce_decompress(int algo, unsigned char *in, int insz, unsigned char *out, int outsz);
int shadowforce_compress(int algo, unsigned char *in, int insz, unsigned char *out, int outsz);
void _compressLZ(u8** dest, unsigned* dest_sz, void* src, unsigned src_sz);
void _decompressLZ(u8** dest, unsigned* dest_sz, void* src, unsigned src_sz);
int unace1(unsigned char *in, int insz, unsigned char *out, int outsz);
int opentitus_lzw_decode(unsigned char *input, int in_len, unsigned char *output, int out_len);
int opentitus_huffman_decode(unsigned char *input, int in_len, unsigned char *output, int out_len);
int KB_funLZW(char *result, unsigned int max, unsigned char *in, int insz);
int DOS_LZW(char *dst, int dst_max, char *src, int src_len);
int filter_bash_unrle(uint8_t *out, int lenOut, const uint8_t *in, int lenIn);
int filter_ddave_unrle(uint8_t *out, int lenOut, const uint8_t *in, int lenIn);
int filter_got_unlzss(uint8_t *out, int lenOut, const uint8_t *in, int lenIn);
int filter_skyroads_unlzs(uint8_t *out, int lenOut, /*const*/ uint8_t *in, int lenIn);
int filter_z66_decompress(uint8_t *out, int lenOut,/*const*/ uint8_t *in, int lenIn);
int filter_stargunner_decompress(const uint8_t* in, unsigned int expanded_size, uint8_t* out);
int deLZW(void* _src, void *_dst, int dstSize);
int jazz_jackrabbit_rle(unsigned char *compressed, int compressed_length, unsigned char *out);
int keen13_rle(unsigned char *in, int insz, unsigned char *out, int outsz);
int sango_fighter_rlc(unsigned char *in, int insz, unsigned char *out, int outsz);
int westwood1(unsigned char *c_data, int c_data_Length, unsigned char *data, int data_Length);
int westwood3(unsigned char *src, unsigned char *dest, int len, int swapWord);
int westwood40(unsigned char *Source, unsigned char *Dest);
int westwood80(unsigned char *Source, unsigned char *Dest);
int splay_trees(unsigned char *in, int insz, unsigned char *out, int outsz, int do_compress);
int arithshift_compress(unsigned char *in, int insz, unsigned char *out, int outsz);
int arithshift_decompress(unsigned char *in, int insz, unsigned char *out, int outsz);
int pkware_dcl_explode(unsigned char *in, int insz, unsigned char *out, int outsz);
int pkware_dcl_implode(unsigned char *in, int insz, unsigned char *out, int outsz);
int terse_decompress(unsigned char *in, int insz, unsigned char *out, int outsz, int is_raw_pack_spack /*-1:PACK 1:PACK*/, int force_binary);
int reduce_decompress(unsigned char *in, int insz, unsigned char *out, int outsz, int factor);
int ultima6_lzw_decompress(unsigned char *source, long source_length, unsigned char *destination, long destination_length);
int yalz77_compress(unsigned char *in, int insz, unsigned char *out, int outsz);
int yalz77_decompress(unsigned char *in, int insz, unsigned char *out, int outsz);
int lzkn1_decompress(unsigned char *input, unsigned char *output);
int lzkn2_decompress(byte *input, byte *output);
int lzkn3_decompress(byte *input, byte *output);
int ppmz2_encode(unsigned char *rawBuf, int rawLen, unsigned char *out, int outsz, unsigned char *conditionBuf, int conditionLen);
int ppmz2_decode(unsigned char *compBuf, int compLen, unsigned char *out, int outsz, unsigned char *conditionBuf, int conditionLen);
int opendark_DecodeFile(unsigned char *in, int insz, unsigned char *out, int outsz);
int alz_decompress(unsigned char *in, int insz, unsigned char *out, int outsz, int type);
int fact5lz_decompress(byte *input, byte *output);
ushort LZCapTsu_decompress(byte *input, byte *output);
int tf3_rle_decompress(byte *data, byte *output, int out_size);
int winimplode_explode(unsigned char *input);
#include "included/falcom_din.c"
int glza_decompress(unsigned char *in, int insz, unsigned char *out, int outsz);
int m99coder(unsigned char *infile, int insz, unsigned char *outfile, int dec_enc);
int lz4x(unsigned char *fin, int flen, unsigned char *fout, int dec_enc);
int get_cpu_number(void) {
#ifdef WIN32
SYSTEM_INFO info;
GetSystemInfo(&info);
return info.dwNumberOfProcessors;
#else
#ifdef _SC_NPROCESSORS_ONLN
return sysconf(_SC_NPROCESSORS_ONLN);
#endif
#endif
return -1;
}
// in recompression mode I consider MAXZIPLEN as universal for any algorithm, indeed I don't use /1000
void alloc_err(const char *fname, i32 line, const char *func);
int MAXZIPLEN(int n) {
int ret;
if(n < 0) ALLOC_ERR;
ret = ((n)+(((n)/10)+1)+12+4096);
if(ret < n) ALLOC_ERR;
return ret;
}
//#define MAXZIPLEN(n) ((n)+(((n)/10)+1)+12+512) // 10 instead of 1000 and + 512
//#define MAXZIPLEN(n) ((n)+(((n)/1000)+1)+12) // this is the correct one for zlib/deflate
#define QUICK_IN_OUT \
unsigned char *inl = in + insz, \
*o = out, \
*outl = out + outsz;
#define lame_feof(X) ((infile >= infilel) ? EOF : 0)
#define lame_getc(X) ((infile >= infilel) ? EOF : (*infile++))
#define lame_putc(Y,X) ((outfile >= outfilel) ? EOF : (*outfile++ = Y))
#define lame_fgetc lame_getc
#define lame_fputc lame_putc
// if I'm not in error, this is good if *ret_outsz was 0 and ret_out wasn't allocated
#define not_ret_out_boh \
if(!*ret_out) { \
*ret_outsz = 0; \
*ret_out = calloc(*ret_outsz, 1); \
if(!*ret_out) STD_ERR(QUICKBMS_ERROR_MEMORY); \
}
int uncopy(unsigned char *in, int insz, unsigned char *out, int outsz) {
int sz;
if(insz <= outsz) sz = insz;
else sz = outsz;
memcpy(out, in, sz);
if(outsz > sz) memset(out + sz, 0, outsz - sz); // padding
return(outsz);
}
int unlzo(u8 *in, int insz, u8 *out, int outsz, int type) {
lzo_uint len = outsz;
int err = LZO_E_OK;
#ifdef DISABLE_LZO
if(type == COMP_LZO1X) {
if(g_comtype_dictionary) {
fprintf(stderr, "\nError: LZO1X dictionary not supported with DISABLE_LZO\n");
myexit(QUICKBMS_ERROR_COMPRESSION);
} else {
err = lzo1x_decompress_safe(in, insz, out, &len, NULL);
}
} else {
fprintf(stderr, "\nError: unsupported LZO decompression %d\n", type);
return -1;
}
#else
switch(type) {
case COMP_LZO1: { err = lzo1_decompress(in, insz, out, &len, NULL); break; }
case COMP_LZO1A: { err = lzo1a_decompress(in, insz, out, &len, NULL); break; }
case COMP_LZO1B: { err = lzo1b_decompress_safe(in, insz, out, &len, NULL); break; }
case COMP_LZO1C: { err = lzo1c_decompress_safe(in, insz, out, &len, NULL); break; }
case COMP_LZO1F: { err = lzo1f_decompress_safe(in, insz, out, &len, NULL); break; }
case COMP_LZO1X: {
if(g_comtype_dictionary) {
err = lzo1x_decompress_dict_safe(in, insz, out, &len, NULL, g_comtype_dictionary, g_comtype_dictionary_len);
} else {
err = lzo1x_decompress_safe(in, insz, out, &len, NULL);
}
break;
}
case COMP_LZO1Y: {
if(g_comtype_dictionary) {
err = lzo1y_decompress_dict_safe(in, insz, out, &len, NULL, g_comtype_dictionary, g_comtype_dictionary_len);
} else {
err = lzo1y_decompress_safe(in, insz, out, &len, NULL);
}
break;
}
case COMP_LZO1Z: {
if(g_comtype_dictionary) {
err = lzo1z_decompress_dict_safe(in, insz, out, &len, NULL, g_comtype_dictionary, g_comtype_dictionary_len);
} else {
err = lzo1z_decompress_safe(in, insz, out, &len, NULL);
}
break;
}
case COMP_LZO2A: { err = lzo2a_decompress_safe(in, insz, out, &len, NULL); break; }
default: {
fprintf(stderr, "\nError: unsupported LZO decompression %d\n", type);
return -1;
break;
}
}
#endif
if((err != LZO_E_OK) && (err != LZO_E_INPUT_NOT_CONSUMED)) {
fprintf(stderr, "\nError: the compressed LZO input is wrong or incomplete (%d)\n", err);
return -1;
}
return len;
}
int lzo_compress(u8 *in, int insz, u8 *out, int outsz, int type) {
lzo_uint len = outsz;
int err = LZO_E_OK;
static u8 *wrkmem = NULL;
#ifdef DISABLE_LZO
if(type == COMP_LZO1X_COMPRESS) {
if(g_comtype_dictionary) {
fprintf(stderr, "\nError: LZO1X dictionary not supported with DISABLE_LZO\n");
myexit(QUICKBMS_ERROR_COMPRESSION);
} else {
wrkmem = realloc(wrkmem, LZO1X_MEM_COMPRESS);
if(!wrkmem) STD_ERR(QUICKBMS_ERROR_MEMORY);
err = lzo1x_1_compress(in, insz, out, &len, wrkmem);
}
} else {
fprintf(stderr, "\nError: unsupported LZO compression %d\n", type);
return -1;
}
#else
switch(type) {
case COMP_LZO1_COMPRESS: {
wrkmem = realloc(wrkmem, LZO1_99_MEM_COMPRESS);
if(!wrkmem) STD_ERR(QUICKBMS_ERROR_MEMORY);
err = lzo1_99_compress(in, insz, out, &len, wrkmem);
break;
}
case COMP_LZO1X_COMPRESS: {
wrkmem = realloc(wrkmem, LZO1X_999_MEM_COMPRESS);
if(!wrkmem) STD_ERR(QUICKBMS_ERROR_MEMORY);
if(g_comtype_dictionary) {
err = lzo1x_999_compress_dict(in, insz, out, &len, wrkmem, g_comtype_dictionary, g_comtype_dictionary_len);
} else {
err = lzo1x_999_compress(in, insz, out, &len, wrkmem);
}
break;
}
case COMP_LZO2A_COMPRESS: {
wrkmem = realloc(wrkmem, LZO2A_999_MEM_COMPRESS);
if(!wrkmem) STD_ERR(QUICKBMS_ERROR_MEMORY);
err = lzo2a_999_compress(in, insz, out, &len, wrkmem);
break;
}
// useless compressors
case COMP_LZO1A_COMPRESS: {
wrkmem = realloc(wrkmem, LZO1A_99_MEM_COMPRESS);
if(!wrkmem) STD_ERR(QUICKBMS_ERROR_MEMORY);
err = lzo1a_99_compress(in, insz, out, &len, wrkmem);
break;
}
case COMP_LZO1B_COMPRESS: {
wrkmem = realloc(wrkmem, LZO1B_999_MEM_COMPRESS);
if(!wrkmem) STD_ERR(QUICKBMS_ERROR_MEMORY);
err = lzo1b_999_compress(in, insz, out, &len, wrkmem);
break;
}
case COMP_LZO1C_COMPRESS: {
wrkmem = realloc(wrkmem, LZO1C_999_MEM_COMPRESS);
if(!wrkmem) STD_ERR(QUICKBMS_ERROR_MEMORY);
err = lzo1c_999_compress(in, insz, out, &len, wrkmem);
break;
}
case COMP_LZO1F_COMPRESS: {
wrkmem = realloc(wrkmem, LZO1F_999_MEM_COMPRESS);
if(!wrkmem) STD_ERR(QUICKBMS_ERROR_MEMORY);
err = lzo1f_999_compress(in, insz, out, &len, wrkmem);
break;
}
case COMP_LZO1Y_COMPRESS: {
wrkmem = realloc(wrkmem, LZO1Y_999_MEM_COMPRESS);
if(!wrkmem) STD_ERR(QUICKBMS_ERROR_MEMORY);
if(g_comtype_dictionary) {
err = lzo1y_999_compress_dict(in, insz, out, &len, wrkmem, g_comtype_dictionary, g_comtype_dictionary_len);
} else {
err = lzo1y_999_compress(in, insz, out, &len, wrkmem);
}
break;
}
case COMP_LZO1Z_COMPRESS: {
wrkmem = realloc(wrkmem, LZO1Z_999_MEM_COMPRESS);
if(!wrkmem) STD_ERR(QUICKBMS_ERROR_MEMORY);
if(g_comtype_dictionary) {
err = lzo1z_999_compress_dict(in, insz, out, &len, wrkmem, g_comtype_dictionary, g_comtype_dictionary_len);
} else {
err = lzo1z_999_compress(in, insz, out, &len, wrkmem);
}
break;
}
default: {
fprintf(stderr, "\nError: unsupported LZO compression %d\n", type);
return -1;
break;
}
}
#endif
if(err != LZO_E_OK) {
fprintf(stderr, "\nError: LZO compression (%d)\n", err);
return -1;
}
return len;
}
int ucl_compress(u8 *in, int insz, u8 *out, int outsz, int type) {
#ifdef DISABLE_UCL
fprintf(stderr, "\nError: UCL support has been disabled in this build\n");
return -1;
#else
ucl_uint len;
int err = UCL_E_OK;
len = outsz;
switch(type) {
case COMP_NRV2b_COMPRESS: err = ucl_nrv2b_99_compress(in, insz, out, &len, NULL, 10, NULL, NULL); break;
case COMP_NRV2d_COMPRESS: err = ucl_nrv2d_99_compress(in, insz, out, &len, NULL, 10, NULL, NULL); break;
case COMP_NRV2e_COMPRESS: err = ucl_nrv2e_99_compress(in, insz, out, &len, NULL, 10, NULL, NULL); break;
default: {
fprintf(stderr, "\nError: unsupported UCL compression %d\n", type);
return -1;
break;
}
}
if((err != UCL_E_OK) && (err != UCL_E_INPUT_NOT_CONSUMED)) {
fprintf(stderr, "\nError: the compressed UCL input is wrong or incomplete (%d)\n", err);
return -1;
}
return len;
#endif
}
int ucl_decompress(u8 *in, int insz, u8 *out, int outsz, int type) {
#ifdef DISABLE_UCL
fprintf(stderr, "\nError: UCL support has been disabled in this build\n");
return -1;
#else
ucl_uint len;
int i,
err = UCL_E_OK;
#define ucl_decompress_scan(X,Y) \
err = ucl_nrv##X##_decompress_safe_##Y(in, insz, out, &len, NULL)
#define ucl_decompress_scan2(X) { \
if(i == 0) ucl_decompress_scan(X, 8); \
else if(i == 1) ucl_decompress_scan(X, le32); \
else if(i == 2) ucl_decompress_scan(X, le16); \
else return -1; \
}
for(i = 0;; i++) {
len = outsz;
switch(type) {
case COMP_NRV2b: ucl_decompress_scan2(2b) break;
case COMP_NRV2d: ucl_decompress_scan2(2d) break;
case COMP_NRV2e: ucl_decompress_scan2(2e) break;
default: return -1; break;
}
if((err == UCL_E_OK) || (err == UCL_E_INPUT_NOT_CONSUMED)) {
return len;
}
}
return -1;
#endif
}
static const u8 define_Z_FULL_FLUSH[12] = "Z_FULL_FLUSH";
#define ZIP_BASE(NAME,WBITS) \
int NAME(u8 *in, int insz, u8 *out, int outsz) { \
static z_stream *z = NULL; \
int no_error = 0; \
int ret, \
sync = Z_FINISH; \
\
if(!in && !out) { \
if(z) { \
deflateEnd(z); \
FREE(z); \
} \
z = NULL; \
return -1; \
} \
\
if(!z) { \
z = calloc(sizeof(z_stream), 1); \
if(!z) return -1; \
memset(z, 0, sizeof(z_stream)); \
if(deflateInit2(z, 9, Z_DEFLATED, WBITS, 9, Z_DEFAULT_STRATEGY)) { \
fprintf(stderr, "\nError: zlib initialization error\n"); \
return -1; \
} \
} \
deflateReset(z); \
\
if(g_comtype_dictionary) { \
if((g_comtype_dictionary_len >= sizeof(define_Z_FULL_FLUSH)) && !memcmp(g_comtype_dictionary, define_Z_FULL_FLUSH, sizeof(define_Z_FULL_FLUSH))) { \
sync = Z_FULL_FLUSH; \
if(g_comtype_dictionary_len > sizeof(define_Z_FULL_FLUSH)) deflateSetDictionary(z, g_comtype_dictionary + sizeof(define_Z_FULL_FLUSH), g_comtype_dictionary_len - sizeof(define_Z_FULL_FLUSH)); \
} else { \
deflateSetDictionary(z, g_comtype_dictionary, g_comtype_dictionary_len); \
} \
} \
\
z->next_in = in; \
z->avail_in = insz; \
z->next_out = out; \
z->avail_out = outsz; \
ret = deflate(z, sync); \
if((ret != Z_STREAM_END) && !no_error) { \
fprintf(stderr, "\nError: the compressed zlib/deflate input is wrong or incomplete (%d)\n", ret); \
return -1; \
} \
return z->total_out; \
}
ZIP_BASE(zlib_compress, 15)
ZIP_BASE(deflate_compress, -15)
#define UNZIP_BASE(NAME,WBITS) \
int NAME(u8 *in, int insz, u8 *out, int outsz, int no_error) { \
static z_stream *z = NULL; \
int ret, \
sync = Z_FINISH; \
\
if(!in && !out) { \
if(z) { \
inflateEnd(z); \
FREE(z); \
} \
z = NULL; \
return -1; \
} \
\
if(!z) { \
z = calloc(sizeof(z_stream), 1); \
if(!z) return -1; \
memset(z, 0, sizeof(z_stream)); \
if(inflateInit2(z, WBITS)) { \
fprintf(stderr, "\nError: zlib initialization error\n"); \
return -1; \
} \
} \
inflateReset(z); \
\
if(g_comtype_dictionary) { \
if((g_comtype_dictionary_len >= sizeof(define_Z_FULL_FLUSH)) && !memcmp(g_comtype_dictionary, define_Z_FULL_FLUSH, sizeof(define_Z_FULL_FLUSH))) { \
sync = Z_FULL_FLUSH; \
if(g_comtype_dictionary_len > sizeof(define_Z_FULL_FLUSH)) inflateSetDictionary(z, g_comtype_dictionary + sizeof(define_Z_FULL_FLUSH), g_comtype_dictionary_len - sizeof(define_Z_FULL_FLUSH)); \
} else { \
inflateSetDictionary(z, g_comtype_dictionary, g_comtype_dictionary_len); \
} \
} \
\
z->next_in = in; \
z->avail_in = insz; \
z->next_out = out; \
z->avail_out = outsz; \
ret = inflate(z, sync); \
if((ret != Z_STREAM_END) && !no_error) { \
fprintf(stderr, "\nError: the compressed zlib/deflate input is wrong or incomplete (%d)\n", ret); \
return -1; \
} \
return z->total_out; \
}
UNZIP_BASE(unzip_zlib, 15)
UNZIP_BASE(unzip_deflate, -15)
int unzip_dynamic(u8 *in, int insz, u8 **ret_out, int *ret_outsz, int fixed_wbits) {
z_stream z;
int err,
retsz,
addsz,
wbits,
retry;
if(fixed_wbits) {
wbits = fixed_wbits;
} else {
if((in[0] == 0x78) || (in[0] == 0x68)) { // just a simple guess to save time
wbits = 15; // zlib
} else {
wbits = -15; // deflate
}
}
retry = 0;
redo:
memset(&z, 0, sizeof(z_stream));
if(inflateInit2(&z, wbits)) {
fprintf(stderr, "\nError: zlib initialization error\n");
return -1;
}
addsz = insz / 4;
if(!addsz) addsz = insz;
not_ret_out_boh
retsz = 0;
z.next_in = in;
z.avail_in = insz;
while(z.avail_in) {
z.next_out = *ret_out + retsz;
z.avail_out = *ret_outsz - retsz;
err = inflate(&z, Z_FINISH);
retsz = (u8 *)z.next_out - *ret_out;
if(err == Z_STREAM_END) break;
if(((err == Z_OK) && z.avail_in) || (err == Z_BUF_ERROR)) {
if(!z.avail_out) myalloc(ret_out, *ret_outsz + addsz, ret_outsz);
} else {
//if(retsz <= 0) {
//printf("\nError: invalid zlib compressed data (%d)\n", err);
retsz = -1;
//}
break;
}
}
inflateEnd(&z);
if(retsz < 0) {
if(!fixed_wbits) {
if(wbits > 0) { // zlib->deflate
wbits = -15;
} else { // deflate->zlib
wbits = 15;
}
retry++;
if(retry < 2) goto redo;
}
myalloc(ret_out, insz, ret_outsz);
memcpy(*ret_out, in, insz);
retsz = insz;
}
return retsz;
}
#ifdef WIN32 // it's a zlib with the adding of inflateBack9 which is not default
#include "compression/infback9.h"
typedef struct {
u8 *p;
u8 *l;
} zlib_func_t;
static unsigned zlib_inf(zlib_func_t *data, u8 **ret) {
unsigned len;
*ret = data->p;
len = data->l - data->p;
data->p += len;
return len;
}
static int zlib_outf(zlib_func_t *data, u8 *buff, int len) {
//int size = data->l - data->p;
if((data->p + len) > data->l) return -1;
memcpy(data->p, buff, len);
data->p += len;
return 0;
}
int inflate64(u8 *in, int insz, u8 *out, int outsz) {
static unsigned char *window = NULL; // from gun.c
zlib_func_t myin,
myout;
z_stream z; // I don't know if inflate64 supports Reset
int ret;
if(!window) {
window = malloc(65536);
if(!window) return -1;
}
memset(&z, 0, sizeof(z_stream));
if(inflateBack9Init(&z, window)) {
fprintf(stderr, "\nError: inflate64 initialization error\n");
return -1;
}
if(g_comtype_dictionary) { // supported?
inflateSetDictionary(&z, g_comtype_dictionary, g_comtype_dictionary_len);
}
myin.p = in;
myin.l = in + insz;
myout.p = out;
myout.l = out + outsz;
z.next_in = in;
z.avail_in = insz;
z.next_out = out;
z.avail_out = outsz;
ret = inflateBack9(&z,
(void *)zlib_inf, &myin,
(void *)zlib_outf, &myout);
if(ret != Z_STREAM_END) {
inflateBack9End(&z); // reset not supported by inflate9
fprintf(stderr, "\nError: the compressed deflate64 input is wrong or incomplete (%d)\n", ret);
return -1;
}
outsz = myout.p - out;
inflateBack9End(&z);
return(outsz);
}
#else
int inflate64(u8 *in, int insz, u8 *out, int outsz) {
fprintf(stderr, "\nError: inflate64 is not supported on this platform\n");
myexit(QUICKBMS_ERROR_COMPRESSION);
return -1;
}
#endif
int unbzip2(u8 *in, int insz, u8 *out, int outsz) { // no reset in bzlib
int err;
err = BZ2_bzBuffToBuffDecompress(out, &outsz, in, insz, 0, 0);
if(err != BZ_OK) {
fprintf(stderr, "\nError: invalid bz2 compressed data (%d)\n", err);
return -1;
}
return(outsz);
}
int bzip2_compress(u8 *in, int insz, u8 *out, int outsz) {
int err;
err = BZ2_bzBuffToBuffCompress(out, &outsz, in, insz, 9, 0, 0);
if(err != BZ_OK) {
fprintf(stderr, "\nError: invalid bz2 compressed data (%d)\n", err);
return -1;
}
return(outsz);
}
int unbzip2_file(u8 *in, int insz, u8 **ret_out, int *ret_outsz) { // no reset in bzlib
bz_stream bz;
int err,
retsz,
addsz;
bz.bzalloc = NULL;
bz.bzfree = NULL;
bz.opaque = NULL;