View | Details | Raw Unified | Return to bug 86510 | Differences between
and this patch

Collapse All | Expand All

(-)clamav/Makefile (-1 / +18 lines)
Lines 23-29 Link Here
23
		unzip:${PORTSDIR}/archivers/unzip
23
		unzip:${PORTSDIR}/archivers/unzip
24
24
25
OPTIONS=	MILTER "Compile the milter interface" Off \
25
OPTIONS=	MILTER "Compile the milter interface" Off \
26
		CURL "Support URL downloading" Off
26
		CURL "Support URL downloading" Off \
27
		UNRAR "Support for external Unrar library" Off
27
USE_REINPLACE=	yes
28
USE_REINPLACE=	yes
28
USE_LIBTOOL_VER=15
29
USE_LIBTOOL_VER=15
29
CONFIGURE_TARGET=	--build=${MACHINE_ARCH}-portbld-freebsd${OSREL}
30
CONFIGURE_TARGET=	--build=${MACHINE_ARCH}-portbld-freebsd${OSREL}
Lines 124-132 Link Here
124
CONFIGURE_ARGS+=	--without-libcurl
125
CONFIGURE_ARGS+=	--without-libcurl
125
.endif
126
.endif
126
127
128
.if defined(WITH_LIBUNRAR)
129
WANT_AUTOMAKE_VER=      19
130
USE_AUTOCONF_VER=       259
131
LIB_DEPENDS+=		unrar.3:${PORTSDIR}/archivers/libunrar
132
133
pre-configure:
134
	cd ${WRKSRC} && \
135
	${ACLOCAL} && \
136
	${AUTOHEADER} && \
137
	${AUTOCONF} && \
138
	${AUTOMAKE}
139
.endif
140
127
post-patch:
141
post-patch:
128
	@${REINPLACE_CMD} -e 's|-pthread -lc_r|${PTHREAD_LIBS}|g' \
142
	@${REINPLACE_CMD} -e 's|-pthread -lc_r|${PTHREAD_LIBS}|g' \
129
		${CONFIGURE_WRKSRC}/${CONFIGURE_SCRIPT}
143
		${CONFIGURE_WRKSRC}/${CONFIGURE_SCRIPT}
144
.if defined(WITH_LIBUNRAR)
145
	${PATCH} -d  ${WRKSRC}/libclamav < ${PORTSDIR}/security/clamav/files/clamav-0.87-libunrar3.patch
146
.endif
130
147
131
pre-build:
148
pre-build:
132
	@if ${LDCONFIG} -r | ${GREP} -qw -e -lclamav; then \
149
	@if ${LDCONFIG} -r | ${GREP} -qw -e -lclamav; then \
(-)clamav/files/clamav-0.87-libunrar3.patch (+3236 lines)
Line 0 Link Here
1
diff -ruN clamav-0.84.orig/libclamav/Makefile.am clamav-0.84/libclamav/Makefile.am
2
--- clamav-0.84.orig/libclamav/Makefile.am	2005-04-20 03:33:17.000000000 +0400
3
+++ clamav-0.84/libclamav/Makefile.am	2005-05-04 02:12:02.540693464 +0400
4
@@ -17,6 +17,8 @@
5
 
6
 
7
 INCLUDES = -I$(top_srcdir) -I@srcdir@/zziplib -I@srcdir@/mspack
8
+CFLAGS = @CFLAGS@ -DUNRAR3
9
+LDFLAGS = @LDFLAGS@ -lunrar
10
 
11
 libclamav_la_LIBADD = @LIBCLAMAV_LIBS@
12
 
13
diff -ruN clamav-0.84.orig/libclamav/scanners.c clamav-0.84/libclamav/scanners.c
14
--- clamav-0.84.orig/libclamav/scanners.c	2005-04-29 05:31:10.000000000 +0400
15
+++ clamav-0.84/libclamav/scanners.c	2005-05-04 02:12:02.543693008 +0400
16
@@ -42,12 +42,13 @@
17
 
18
 #include <mspack.h>
19
 
20
+#ifndef UNRAR3
21
 #ifdef CL_THREAD_SAFE
22
 #  include <pthread.h>
23
 pthread_mutex_t cli_scanrar_mutex = PTHREAD_MUTEX_INITIALIZER;
24
 #endif
25
 int cli_scanrar_inuse = 0;
26
-
27
+#endif
28
 extern short cli_leavetemps_flag;
29
 
30
 extern int cli_mbox(const char *dir, int desc, unsigned int options); /* FIXME */
31
@@ -111,6 +112,7 @@
32
 static int cli_scanfile(const char *filename, const char **virname, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, unsigned int arec, unsigned int mrec);
33
 
34
 
35
+#ifndef UNRAR3
36
 #ifdef CL_THREAD_SAFE
37
 static void cli_unlock_mutex(void *mtx)
38
 {
39
@@ -330,6 +332,7 @@
40
 
41
     return ret;
42
 }
43
+#endif
44
 
45
 #ifdef HAVE_ZLIB_H
46
 static int cli_scanzip(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, unsigned int arec, unsigned int mrec)
47
@@ -1213,6 +1216,43 @@
48
     return ret;
49
 }
50
 
51
+#ifdef UNRAR3
52
+static int cli_scanrar3(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, unsigned int arec, unsigned int mrec)
53
+{
54
+	const char *tmpdir;
55
+	char *dir;
56
+	int ret = CL_CLEAN;
57
+
58
+
59
+	cli_dbgmsg("in cli_scanrar3()\n");
60
+
61
+	if((tmpdir = getenv("TMPDIR")) == NULL)
62
+#ifdef P_tmpdir
63
+    	    tmpdir = P_tmpdir;
64
+#else
65
+    	    tmpdir = "/tmp";
66
+#endif
67
+
68
+     /* generate temporary directory */
69
+        dir = cli_gentemp(tmpdir);
70
+        if(mkdir(dir, 0700)) {
71
+    	    cli_errmsg("Rar3: Can't create temporary directory %s\n", dir);
72
+    	    return CL_ETMPDIR;
73
+        }
74
+
75
+        if((ret = cli_unrar3(dir, desc)))
76
+    	    cli_dbgmsg("Rar3: %s\n", cl_strerror(ret));
77
+        else
78
+    	    ret = cli_scandir(dir, virname, scanned, root, limits, options, arec, mrec);
79
+
80
+        if(!cli_leavetemps_flag)
81
+    	    cli_rmdirs(dir);
82
+
83
+        free(dir);
84
+        return ret;
85
+}
86
+#endif
87
+
88
 static int cli_scanmschm(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, unsigned int arec, unsigned int mrec)
89
 {
90
 	char *tempname;
91
@@ -1400,8 +1440,13 @@
92
 
93
     switch(type) {
94
 	case CL_TYPE_RAR:
95
+#ifdef UNRAR3
96
+	    if(!DISABLE_RAR && SCAN_ARCHIVE)
97
+		ret = cli_scanrar3(desc, virname, scanned, root, limits, options, arec, mrec);
98
+#else
99
 	    if(!DISABLE_RAR && SCAN_ARCHIVE && !cli_scanrar_inuse)
100
 		ret = cli_scanrar(desc, virname, scanned, root, limits, options, arec, mrec);
101
+#endif
102
 	    break;
103
 
104
 	case CL_TYPE_ZIP:
105
@@ -1538,8 +1583,17 @@
106
 	 * in raw mode. Now we will try to unpack them
107
 	 */
108
 	case CL_TYPE_MSEXE:
109
+#ifdef UNRAR3
110
+	    if(!DISABLE_RAR && SCAN_ARCHIVE)
111
+		ret = cli_scanrar3(desc, virname, scanned, root, limits, options, arec, mrec);
112
+	    if(SCAN_PE && ret != CL_VIRUS)
113
+#else
114
 	    if(SCAN_PE)
115
+#endif
116
+	    {
117
+		lseek(desc, 0, SEEK_SET);
118
 		ret = cli_scanpe(desc, virname, scanned, root, limits, options, arec, mrec);
119
+	    }
120
 	    break;
121
 
122
 	default:
123
diff -ruN clamav-0.84.orig/libclamav/unrarlib.c clamav-0.84/libclamav/unrarlib.c
124
--- clamav-0.84.orig/libclamav/unrarlib.c	2005-04-20 03:33:17.000000000 +0400
125
+++ clamav-0.84/libclamav/unrarlib.c	2005-05-04 02:12:27.131955024 +0400
126
@@ -1,2774 +1,119 @@
127
-/* It contains some changes needed for libclamav and isn't compatible with
128
- * the original version, --tk
129
+/*
130
+ *  Copyright (C) 2004 McMCC <mcmcc@mail.ru>
131
+ *
132
+ *  Support check archives RAR v.3.x
133
+ *
134
+ *  This program is free software; you can redistribute it and/or modify
135
+ *  it under the terms of the GNU General Public License as published by
136
+ *  the Free Software Foundation; either version 2 of the License, or
137
+ *  (at your option) any later version.
138
+ *
139
+ *  This program is distributed in the hope that it will be useful,
140
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
141
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
142
+ *  GNU General Public License for more details.
143
+ *
144
+ *  You should have received a copy of the GNU General Public License
145
+ *  along with this program; if not, write to the Free Software
146
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
147
+ *
148
  */
149
-/* ***************************************************************************
150
- **
151
- **  This file is part of the UniquE RAR File Library.
152
- **
153
- **  Copyright (C) 2000-2002 by Christian Scheurer (www.ChristianScheurer.ch)
154
- **  UNIX port copyright (c) 2000-2002 by Johannes Winkelmann (jw@tks6.net)
155
- **
156
- **  The contents of this file are subject to the UniquE RAR File Library
157
- **  License (the "unrarlib-license.txt"). You may not use this file except
158
- **  in compliance with the License. You may obtain a copy of the License
159
- **  at http://www.unrarlib.org/license.html.
160
- **  Software distributed under the License is distributed on an "AS IS"
161
- **  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied warranty.
162
- **
163
- **  Alternatively, the contents of this file may be used under the terms
164
- **  of the GNU General Public License Version 2 or later (the "GPL"), in
165
- **  which case the provisions of the GPL are applicable instead of those
166
- **  above. If you wish to allow use of your version of this file only
167
- **  under the terms of the GPL and not to allow others to use your version
168
- **  of this file under the terms of the UniquE RAR File Library License,
169
- **  indicate your decision by deleting the provisions above and replace
170
- **  them with the notice and other provisions required by the GPL. If you
171
- **  do not delete the provisions above, a recipient may use your version
172
- **  of this file under the terms of the GPL or the UniquE RAR File Library
173
- **  License.
174
- **
175
- ************************************************************************** */
176
-
177
-/* ***************************************************************************
178
- **
179
- **                           UniquE RAR File Library
180
- **                     The free file lib for the demoscene
181
- **                   multi-OS version (Win32, Linux and SunOS)
182
- **
183
- *****************************************************************************
184
- **
185
- **   ==> Please configure the program in "unrarlib.h". <==
186
- **
187
- **   RAR decompression code:
188
- **    (C) Eugene Roshal
189
- **   Modifications to a FileLib:
190
- **    (C) 2000-2002 Christian Scheurer aka. UniquE/Vantage (cs@unrarlib.org)
191
- **   Linux port:
192
- **    (C) 2000-2002 Johannes Winkelmann (jw@tks6.net)
193
- **
194
- **  The UniquE RAR File Library gives you the ability to access RAR archives
195
- **  (any compression method supported in RAR v2.0 including Multimedia
196
- **  Compression and encryption) directly from your program with ease an by
197
- **  adding only 12kB (6kB UPX-compressed) additional code to your program.
198
- **  Both solid and normal (recommended for fast random access to the files!)
199
- **  archives are supported. This FileLib is made for the Demo scene, so it's
200
- **  designed for easy use within your demos and intros.
201
- **  Please read "licence.txt" to learn more about how you may use URARFileLib
202
- **  in your productions.
203
- **
204
- *****************************************************************************
205
- **
206
- **  ==> see the "CHANGES" file to see what's new
207
- **
208
- ************************************************************************** */
209
-
210
-/* -- include files ------------------------------------------------------- */
211
-#if HAVE_CONFIG_H
212
-#include "clamav-config.h"
213
-#endif
214
-
215
-#include "unrarlib.h"                       /* include global configuration */
216
-#include "others.h"
217
-/* ------------------------------------------------------------------------ */
218
-
219
+static char const rcsid[] = "$Id: unrarlib.c,v 1.0 2004/10/20 18:18:46 mcmcc Exp $";
220
 
221
-
222
-/* -- global stuff -------------------------------------------------------- */
223
-#ifdef _WIN_32
224
-
225
-#include <windows.h>                        /* WIN32 definitions            */
226
 #include <stdio.h>
227
-#include <string.h>
228
-
229
-
230
-#define ENABLE_ACCESS
231
-
232
-#define HOST_OS     WIN_32
233
-
234
-#define FM_NORMAL   0x00
235
-#define FM_RDONLY   0x01
236
-#define FM_HIDDEN   0x02
237
-#define FM_SYSTEM   0x04
238
-#define FM_LABEL    0x08
239
-#define FM_DIREC    0x10
240
-#define FM_ARCH     0x20
241
-
242
-#define PATHDIVIDER  "\\"
243
-#define CPATHDIVIDER '\\'
244
-#define MASKALL      "*.*"
245
-
246
-#define READBINARY   "rb"
247
-#define READTEXT     "rt"
248
-#define UPDATEBINARY "r+b"
249
-#define CREATEBINARY "w+b"
250
-#define CREATETEXT   "w"
251
-#define APPENDTEXT   "at"
252
-
253
-#endif
254
-
255
-#ifdef _UNIX
256
-
257
-#include <stdio.h>                          /* LINUX/UNIX definitions       */
258
 #include <stdlib.h>
259
-#include <unistd.h>
260
-#include <ctype.h>
261
-#include <string.h>
262
 #include <errno.h>
263
-
264
-#define ENABLE_ACCESS
265
-
266
-#define HOST_OS     UNIX
267
-
268
-#define FM_LABEL    0x0000
269
-#define FM_DIREC    0x4000
270
-
271
-#define PATHDIVIDER  "/"
272
-#define CPATHDIVIDER '/'
273
-#define MASKALL      "*.*"
274
-
275
-#define READBINARY   "r"
276
-#define READTEXT     "r"
277
-#define UPDATEBINARY "r+"
278
-#define CREATEBINARY "w+"
279
-#define CREATETEXT   "w"
280
-#define APPENDTEXT   "a"
281
-
282
-
283
-/* emulation of the windows API and data types                              */
284
-/* 20-08-2000 Johannes Winkelmann, jw@tks6.net                              */
285
-
286
-typedef long    DWORD;
287
-typedef short   BOOL;
288
-#define TRUE    1
289
-#define FALSE   0
290
-
291
-
292
-#ifdef _DEBUG_LOG                           /* define macros for debugging  */
293
+#include <string.h>
294
 #include <unistd.h>
295
-#include <sys/time.h>
296
-
297
-DWORD GetTickCount()
298
-{
299
-    struct timeval tv;
300
-    gettimeofday( &tv, 0 );
301
-    return (tv.tv_usec / 1000);
302
-}
303
-#endif
304
-
305
-#endif
306
-
307
-
308
-
309
-
310
-
311
-#ifdef _DEBUG_LOG                           /* define macros for debugging  */
312
-
313
-BOOL debug_log_first_start = TRUE;
314
-
315
-#define debug_log(a); debug_log_proc(a, __FILE__, __LINE__);
316
-#define debug_init(a); debug_init_proc(a);
317
-
318
-void debug_log_proc(char *text, char *sourcefile, int sourceline);
319
-void debug_init_proc(char *file_name);
320
-
321
-#else
322
-#define debug_log(a);	cli_dbgmsg("%s:%d %s\n", __FILE__, __LINE__, a);
323
-#define debug_init(a);  /* no debug this time */
324
-#endif
325
-
326
-
327
-
328
-
329
-
330
-#define MAXWINSIZE      0x100000
331
-#define MAXWINMASK      (MAXWINSIZE-1)
332
-#define UNP_MEMORY      MAXWINSIZE
333
-#define Min(x,y) (((x)<(y)) ? (x):(y))
334
-#define Max(x,y) (((x)>(y)) ? (x):(y))
335
-#define NM  260
336
-
337
-#define SIZEOF_MARKHEAD         7
338
-#define SIZEOF_OLDMHD           7
339
-#define SIZEOF_NEWMHD          13
340
-#define SIZEOF_OLDLHD          21
341
-#define SIZEOF_NEWLHD          32
342
-#define SIZEOF_SHORTBLOCKHEAD   7
343
-#define SIZEOF_LONGBLOCKHEAD   11
344
-#define SIZEOF_COMMHEAD        13
345
-#define SIZEOF_PROTECTHEAD     26
346
-
347
-
348
-#define PACK_VER       20                   /* version of decompression code*/
349
-#define UNP_VER        20
350
-#define PROTECT_VER    20
351
-
352
-
353
-enum { M_DENYREAD,M_DENYWRITE,M_DENYNONE,M_DENYALL };
354
-enum { FILE_EMPTY,FILE_ADD,FILE_UPDATE,FILE_COPYOLD,FILE_COPYBLOCK };
355
-enum { SUCCESS,WARNING,FATAL_ERROR,CRC_ERROR,LOCK_ERROR,WRITE_ERROR,
356
-       OPEN_ERROR,USER_ERROR,MEMORY_ERROR,USER_BREAK=255,IMM_ABORT=0x8000 };
357
-enum { EN_LOCK=1,EN_VOL=2 };
358
-enum { SD_MEMORY=1,SD_FILES=2 };
359
-enum { NAMES_DONTCHANGE };
360
-enum { LOG_ARC=1,LOG_FILE=2 };
361
-enum { OLD_DECODE=0,OLD_ENCODE=1,NEW_CRYPT=2 };
362
-enum { OLD_UNPACK,NEW_UNPACK };
363
-
364
-
365
-#define MHD_COMMENT        2
366
-#define MHD_LOCK           4
367
-#define MHD_PACK_COMMENT   16
368
-#define MHD_AV             32
369
-#define MHD_PROTECT        64
370
-
371
-#define LHD_SPLIT_BEFORE   1
372
-#define LHD_SPLIT_AFTER    2
373
-#define LHD_PASSWORD       4
374
-#define LHD_COMMENT        8
375
-#define LHD_SOLID          16
376
-
377
-#define LHD_WINDOWMASK     0x00e0
378
-#define LHD_WINDOW64       0
379
-#define LHD_WINDOW128      32
380
-#define LHD_WINDOW256      64
381
-#define LHD_WINDOW512      96
382
-#define LHD_WINDOW1024     128
383
-#define LHD_DIRECTORY      0x00e0
384
-
385
-#define LONG_BLOCK         0x8000
386
-#define READSUBBLOCK       0x8000
387
-
388
-enum { ALL_HEAD=0,MARK_HEAD=0x72,MAIN_HEAD=0x73,FILE_HEAD=0x74,
389
-       COMM_HEAD=0x75,AV_HEAD=0x76,SUB_HEAD=0x77,PROTECT_HEAD=0x78};
390
-enum { EA_HEAD=0x100 };
391
-enum { MS_DOS=0,OS2=1,WIN_32=2,UNIX=3 };
392
-
393
-
394
-struct MarkHeader
395
-{
396
-  UBYTE Mark[7];
397
-};
398
-
399
-
400
-struct NewMainArchiveHeader
401
-{
402
-  UWORD HeadCRC;
403
-  UBYTE HeadType;
404
-  UWORD Flags;
405
-  UWORD HeadSize;
406
-  UWORD Reserved;
407
-  UDWORD Reserved1;
408
-};
409
-
410
-
411
-struct NewFileHeader
412
-{
413
-  UWORD HeadCRC;
414
-  UBYTE HeadType;
415
-  UWORD Flags;
416
-  UWORD HeadSize;
417
-  UDWORD PackSize;
418
-  UDWORD UnpSize;
419
-  UBYTE HostOS;
420
-  UDWORD FileCRC;
421
-  UDWORD FileTime;
422
-  UBYTE UnpVer;
423
-  UBYTE Method;
424
-  UWORD NameSize;
425
-  UDWORD FileAttr;
426
-};
427
-
428
-
429
-struct BlockHeader
430
-{
431
-  UWORD HeadCRC;
432
-  UBYTE HeadType;
433
-  UWORD Flags;
434
-  UWORD HeadSize;
435
-  UDWORD DataSize;
436
-};
437
-
438
-
439
-struct Decode
440
-{
441
-  unsigned int MaxNum;
442
-  unsigned int DecodeLen[16];
443
-  unsigned int DecodePos[16];
444
-  unsigned int DecodeNum[2];
445
-};
446
-
447
-
448
-static struct MarkHeader MarkHead;
449
-static struct NewMainArchiveHeader NewMhd;
450
-static struct NewFileHeader NewLhd;
451
-static struct BlockHeader BlockHead;
452
-
453
-static UBYTE *TempMemory = NULL;                          /* temporary unpack-buffer      */
454
-static char *CommMemory = NULL;
455
-
456
-
457
-static UBYTE *UnpMemory = NULL;
458
-static char ArgName[NM];                           /* current file in rar archive  */
459
-static char ArcFileName[NM];                       /* file to decompress           */
460
-
461
-#ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION  /* mem-to-mem decompression     */
462
-static  MemoryFile *MemRARFile;                   /* pointer to RAR file in memory*/
463
-#else
464
-static  FILE *ArcPtr;                             /* input RAR file handler       */
465
-#endif
466
-static char Password[255];                         /* password to decrypt files    */
467
-
468
-static unsigned char *temp_output_buffer;          /* extract files to this pointer*/
469
-static unsigned long *temp_output_buffer_offset;   /* size of temp. extract buffer */
470
-
471
-static int MainHeadSize;
472
-
473
-static long CurBlockPos,NextBlockPos;
474
-
475
-static unsigned long CurUnpRead;
476
-static long UnpPackedSize;
477
-static long DestUnpSize;
478
-
479
-static UDWORD HeaderCRC;
480
-static int Encryption;
481
-
482
-static unsigned int UnpPtr,WrPtr;
483
-
484
-static unsigned char PN1,PN2,PN3;
485
-static unsigned short OldKey[4];
486
-
487
-
488
-
489
-/* function header definitions                                              */
490
-static int ReadHeader(int BlockType);
491
-static BOOL ExtrFile(int desc);
492
-static int tread(void *stream,void *buf,unsigned len);
493
-static int tseek(void *stream,long offset,int fromwhere);
494
-/* static BOOL UnstoreFile(void); */
495
-static int IsArchive(void);
496
-static int ReadBlock(int BlockType);
497
-static unsigned int UnpRead(unsigned char *Addr,unsigned int Count);
498
-static void UnpInitData(void);
499
-static void Unpack(unsigned char *UnpAddr, BOOL FileFound);
500
-static UBYTE DecodeAudio(int Delta);
501
-static void DecodeNumber(struct Decode *Dec);
502
-static void UpdKeys(UBYTE *Buf);
503
-static void SetCryptKeys(char* NewPassword);
504
-static void SetOldKeys(char *NewPassword);
505
-static void DecryptBlock(unsigned char *Buf);
506
-static void InitCRC(void);
507
-static UDWORD CalcCRC32(UDWORD StartCRC,UBYTE *Addr,UDWORD Size);
508
-static void UnpReadBuf(int FirstBuf);
509
-static void ReadTables(void);
510
-static void ReadLastTables(void);
511
-static void MakeDecodeTables(unsigned char *LenTab,
512
-                             struct Decode *Dec,
513
-                             int Size);
514
-static int stricomp(char *Str1,char *Str2);
515
-/* ------------------------------------------------------------------------ */
516
-
517
-
518
-/* -- global functions ---------------------------------------------------- */
519
-
520
-int urarlib_get(void *output,
521
-                unsigned long *size,
522
-                char *filename,
523
-                int desc,
524
-                char *libpassword)
525
-/* Get a file from a RAR file to the "output" buffer. The UniquE RAR FileLib
526
- * does everything from allocating memory, decrypting and unpacking the file
527
- * from the archive. TRUE is returned if the file could be successfully
528
- * extracted, else a FALSE indicates a failure.
529
- */
530
-{
531
-  BOOL  retcode = FALSE;
532
-
533
-#ifdef _DEBUG_LOG
534
-  int  str_offs;                            /* used for debug-strings       */
535
-  char DebugMsg[500];                       /* used to compose debug msg    */
536
-
537
-  if(debug_log_first_start)
538
-  {
539
-    debug_log_first_start=FALSE;            /* only create a new log file   */
540
-    debug_init(_DEBUG_LOG_FILE);            /* on startup                   */
541
-  }
542
-
543
-#endif
544
-
545
-  InitCRC();                                /* init some vars               */
546
-
547
-  strcpy(ArgName, filename);                /* set file(s) to extract       */
548
-#ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
549
-  MemRARFile = rarfile;                     /* set pointer to mem-RAR file  */
550
-#endif
551
-  if(libpassword != NULL)
552
-    strcpy(Password, libpassword);          /* init password                */
553
-
554
-  temp_output_buffer = NULL;
555
-  temp_output_buffer_offset=size;           /* set size of the temp buffer  */
556
-
557
-  retcode = ExtrFile(desc);                     /* unpack file now! */
558
-
559
-
560
-  memset(Password,0,sizeof(Password));      /* clear password               */
561
-
562
-#ifndef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
563
-  if (ArcPtr!=NULL){
564
-      /* FIXME: possible FILE* leak */
565
-      cli_dbgmsg("%s:%d NOT Close ArcPtr from fd %d\n", __FILE__, __LINE__, desc);
566
-      /*
567
-      fclose(ArcPtr);
568
-      lseek(desc, 0, SEEK_SET);
569
-      ArcPtr = NULL;
570
-      */
571
-  }
572
-#endif
573
-
574
-  if(UnpMemory)
575
-    free(UnpMemory);
576
-
577
-  if(TempMemory)
578
-    free(TempMemory);
579
-
580
-  if(CommMemory)
581
-    free(CommMemory);
582
-
583
-  UnpMemory=NULL;
584
-  TempMemory=NULL;
585
-  CommMemory=NULL;
586
-
587
-
588
-  if(retcode == FALSE)
589
-  {
590
-    if(temp_output_buffer)
591
-	free(temp_output_buffer);               /* free memory and return NULL  */
592
-    temp_output_buffer=NULL;
593
-    *(DWORD*)output=0;                      /* pointer on errors            */
594
-    *size=0;
595
-#ifdef _DEBUG_LOG
596
-
597
-
598
-   /* sorry for this ugly code, but older SunOS gcc compilers don't support */
599
-   /* white spaces within strings                                           */
600
-   str_offs  = sprintf(DebugMsg, "Error - couldn't extract ");
601
-   str_offs += sprintf(DebugMsg + str_offs, ">%s<", filename);
602
-   str_offs += sprintf(DebugMsg + str_offs, " and allocated ");
603
-   str_offs += sprintf(DebugMsg + str_offs, "%u Bytes", (unsigned int)*size);
604
-   str_offs += sprintf(DebugMsg + str_offs, " of unused memory!");
605
-
606
-  } else
607
-  {
608
-    sprintf(DebugMsg, "Extracted %u Bytes.", (unsigned int)*size);
609
-  }
610
-  debug_log(DebugMsg);
611
-#else
612
-  }
613
-#endif
614
-  *(DWORD*)output=(DWORD)temp_output_buffer;/* return pointer for unpacked*/
615
-                                            /* data                       */
616
-
617
-  return retcode;
618
-}
619
-
620
-
621
-int urarlib_list(int desc, ArchiveList_struct *list)
622
-{
623
-  ArchiveList_struct *tmp_List = NULL;
624
-  int NoOfFilesInArchive       = 0;         /* number of files in archive   */
625
-  int newdesc;
626
-
627
-#ifdef _DEBUG_LOG
628
-  if(debug_log_first_start)
629
-  {
630
-    debug_log_first_start=FALSE;            /* only create a new log file   */
631
-    debug_init(_DEBUG_LOG_FILE);            /* on startup                   */
632
-  }
633
-#endif
634
-
635
-  InitCRC();                                /* init some vars               */
636
-
637
-#ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
638
-  MemRARFile         = rarfile;             /* assign pointer to RAR file   */
639
-  MemRARFile->offset = 0;
640
-  if (!IsArchive())
641
-  {
642
-    debug_log("Not a RAR file");
643
-    return NoOfFilesInArchive;              /* error => exit!               */
644
-  }
645
-#else
646
-  /* open and identify archive                                              */
647
-  newdesc = dup(desc);
648
-  cli_dbgmsg("ExtrFile(): dup(%d) = %d\n", desc, newdesc);
649
-  if ((ArcPtr=fdopen(newdesc,READBINARY))!=NULL)
650
-  {
651
-    if (!IsArchive())
652
-    {
653
-      cli_dbgmsg("urarlib_list(): Not a valid archive.");
654
-      debug_log("Not a RAR file");
655
-      fclose(ArcPtr);
656
-      lseek(desc, 0, SEEK_SET);
657
-      ArcPtr = NULL;
658
-      return NoOfFilesInArchive;            /* error => exit!               */
659
-    }
660
-  }
661
-  else {
662
-    cli_dbgmsg("urarlib_list(): Error opening file: %s", strerror(errno));
663
-    debug_log("Error opening file.");
664
-    cli_dbgmsg("%s:%d Close fd %d\n", __FILE__, __LINE__, newdesc);
665
-    close(newdesc);
666
-    return NoOfFilesInArchive;
667
-  }
668
-#endif
669
-
670
-  if ((UnpMemory=malloc(UNP_MEMORY))==NULL)
671
-  {
672
-    cli_dbgmsg("urarlib_list(): out of memory.");
673
-    debug_log("Can't allocate memory for decompression!");
674
-    fclose(ArcPtr);
675
-    return NoOfFilesInArchive;
676
-  }
677
-
678
-#ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
679
-  MemRARFile->offset+=NewMhd.HeadSize-MainHeadSize;
680
-#else
681
-  tseek(ArcPtr,NewMhd.HeadSize-MainHeadSize,SEEK_CUR);
682
-#endif
683
-  (*(DWORD*)list) = (DWORD)NULL;            /* init file list               */
684
-  /* do while file is not extracted and there's no error                    */
685
-  for(;;)
686
-  {
687
-    int ReadBlockResult;
688
-    if ((ReadBlockResult = ReadBlock(FILE_HEAD | READSUBBLOCK)) <= 0) /* read name of the next  */
689
-    {                                       /* file within the RAR archive  */
690
-      cli_dbgmsg("Couldn't read next filename from archive (I/O error): %d\n", ReadBlockResult);
691
-      break;                                /* error, file not found in     */
692
-    }                                       /* archive or I/O error         */
693
-    if (BlockHead.HeadType==SUB_HEAD)
694
-    {
695
-      debug_log("Sorry, sub-headers not supported.");
696
-      NoOfFilesInArchive = 0;
697
-      break;                                /* error => exit                */
698
-    }
699
-
700
-    if((void*)(*(DWORD*)list) == NULL)      /* first entry                  */
701
-    {
702
-      tmp_List = malloc(sizeof(ArchiveList_struct));
703
-      tmp_List->next = NULL;
704
-
705
-      (*(DWORD*)list) = (DWORD)tmp_List;
706
-
707
-    } else                                  /* add entry                    */
708
-    {
709
-      tmp_List->next = malloc(sizeof(ArchiveList_struct));
710
-      tmp_List = (ArchiveList_struct*) tmp_List->next;
711
-      tmp_List->next = NULL;
712
-    }
713
-
714
-    tmp_List->item.Name = malloc(NewLhd.NameSize + 1);
715
-    strcpy(tmp_List->item.Name, ArcFileName);
716
-    tmp_List->item.NameSize = NewLhd.NameSize;
717
-    tmp_List->item.PackSize = NewLhd.PackSize;
718
-    tmp_List->item.UnpSize = NewLhd.UnpSize;
719
-    tmp_List->item.HostOS = NewLhd.HostOS;
720
-    tmp_List->item.FileCRC = NewLhd.FileCRC;
721
-    tmp_List->item.FileTime = NewLhd.FileTime;
722
-    tmp_List->item.UnpVer = NewLhd.UnpVer;
723
-    tmp_List->item.Method = NewLhd.Method;
724
-    tmp_List->item.FileAttr = NewLhd.FileAttr;
725
-    tmp_List->item.Flags = NewLhd.Flags;
726
-
727
-    NoOfFilesInArchive++;                   /* count files                  */
728
-
729
-#ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
730
-    MemRARFile->offset = NextBlockPos;
731
-#else
732
-    if (ArcPtr!=NULL) tseek(ArcPtr,NextBlockPos,SEEK_SET);
733
-#endif
734
-
735
-  };
736
-
737
-  /* free memory, clear password and close archive                          */
738
-  memset(Password,0,sizeof(Password));      /* clear password               */
739
-#ifndef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
740
-  if (ArcPtr!=NULL){
741
-      fclose(ArcPtr);
742
-      ArcPtr = NULL;
743
-      lseek(desc, 0, SEEK_SET);
744
-  }
745
-#endif
746
-
747
-  if(UnpMemory)
748
-    free(UnpMemory);
749
-
750
-  if(TempMemory)
751
-    free(TempMemory);
752
-
753
-  if(CommMemory)
754
-    free(CommMemory);
755
-
756
-  UnpMemory=NULL;
757
-  TempMemory=NULL;
758
-  CommMemory=NULL;
759
-
760
-  return NoOfFilesInArchive;
761
-}
762
-
763
-
764
-
765
-/* urarlib_freelist:
766
- * (after the suggestion and code of Duy Nguyen, Sean O'Blarney
767
- * and Johannes Winkelmann who independently wrote a patch)
768
- * free the memory of a ArchiveList_struct created by urarlib_list.
769
- *
770
- *    input: *list          pointer to an ArchiveList_struct
771
- *    output: -
772
- */
773
-
774
-void urarlib_freelist(ArchiveList_struct *list)
775
-{
776
-    ArchiveList_struct* tmp = list;
777
-
778
-    while ( list ) {
779
-        tmp = list->next;
780
-        free( list->item.Name );
781
-        free( list );
782
-        list = tmp;
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
- *******                    B L O C K   I / O                         *******
813
- *******                                                              *******
814
- *******                                                              *******
815
- *******                                                              *******
816
- ****************************************************************************
817
- ****************************************************************************
818
- ****************************************************************************
819
- ****************************************************************************/
820
-
821
-
822
-
823
-#define GetHeaderByte(N) Header[N]
824
-
825
-#define GetHeaderWord(N) (Header[N]+((UWORD)Header[N+1]<<8))
826
-
827
-#define GetHeaderDword(N) (Header[N]+((UWORD)Header[N+1]<<8)+\
828
-                          ((UDWORD)Header[N+2]<<16)+\
829
-                          ((UDWORD)Header[N+3]<<24))
830
-
831
-
832
-int ReadBlock(int BlockType)
833
-{
834
-  struct NewFileHeader SaveFileHead;
835
-  int Size=0,ReadSubBlock=0;
836
-  static int LastBlock;
837
-  memcpy(&SaveFileHead,&NewLhd,sizeof(SaveFileHead));
838
-  if (BlockType & READSUBBLOCK) {
839
-    ReadSubBlock=1;
840
-    BlockType &= 0xff;
841
-  }
842
-  {
843
-    while (1)
844
-    {
845
-#ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
846
-      CurBlockPos=MemRARFile->offset;       /* get offset of mem-file       */
847
-#else
848
-      CurBlockPos=ftell(ArcPtr);
849
-#endif
850
-      Size=ReadHeader(FILE_HEAD);
851
-      if (Size!=0)
852
-      {
853
-        if (NewLhd.HeadSize<SIZEOF_SHORTBLOCKHEAD)
854
-          return(0);
855
-        NextBlockPos=CurBlockPos+NewLhd.HeadSize;
856
-        if (NewLhd.Flags & LONG_BLOCK)
857
-          NextBlockPos+=NewLhd.PackSize;
858
-        if (NextBlockPos<=CurBlockPos)
859
-          return(0);
860
-      }
861
-
862
-      if (Size > 0 && BlockType!=SUB_HEAD)
863
-        LastBlock=BlockType;
864
-      if (Size==0 || BlockType==ALL_HEAD || NewLhd.HeadType==BlockType ||
865
-          (NewLhd.HeadType==SUB_HEAD && ReadSubBlock && LastBlock==BlockType))
866
-        break;
867
-#ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
868
-      MemRARFile->offset = NextBlockPos;
869
-#else
870
-      tseek(ArcPtr, NextBlockPos, SEEK_SET);
871
-#endif
872
+#include <sys/stat.h>
873
+#include <fcntl.h>
874
+#include <sys/param.h>
875
+#include <libunrar3/dll.hpp>
876
+#include "clamav.h"
877
+#include "others.h"
878
+#include "unrarlib.h"
879
+#include "mbox.h"
880
+#include "blob.h"
881
+
882
+int cli_unrar3(const char *dir, int desc)
883
+{
884
+
885
+    struct RAROpenArchiveDataEx OpenArchiveData;
886
+    struct RARHeaderData HeaderData;
887
+    int iReadHeaderCode, iProcessFileCode, fd, s_buff;
888
+    char buff[4096], uname[48];
889
+    const char *tmpdir;
890
+    HANDLE hArcData;
891
+    FILE *out;
892
+
893
+    if((tmpdir = getenv("TMPDIR")) == NULL)
894
+#ifdef P_tmpdir
895
+        tmpdir = P_tmpdir;
896
+#else
897
+        tmpdir = "/tmp";
898
+#endif
899
+
900
+    sprintf(uname, "%s/rarXXXXXX", tmpdir);
901
+
902
+    if((fd = mkstemp(uname)) < 0 || (out = fdopen(fd, "w+")) == NULL)
903
+    {
904
+	
905
+	cli_dbgmsg("cli_unrar3: can't generate temporary file %s or open descriptor %d.\n", 
906
+		    uname, fd);
907
+	if(fd >= 0)
908
+	    close(fd);
909
+	unlink(uname);
910
+	return CL_ETMPFILE;
911
+    }	
912
+
913
+    while((s_buff=read(desc, buff, sizeof(buff))) > 0) 
914
+    {    
915
+    	if(fwrite(buff, 1, s_buff, out) != s_buff)
916
+	{
917
+	    cli_dbgmsg("cli_unrar3: can't write to file %s.\n", uname); 
918
+	    fclose(out);
919
+	    close(fd);
920
+	    unlink(uname);
921
+	    return CL_EOPEN;
922
+	}
923
     }
924
-  }
925
-
926
-  BlockHead.HeadCRC=NewLhd.HeadCRC;
927
-  BlockHead.HeadType=NewLhd.HeadType;
928
-  BlockHead.Flags=NewLhd.Flags;
929
-  BlockHead.HeadSize=NewLhd.HeadSize;
930
-  BlockHead.DataSize=NewLhd.PackSize;
931
-
932
-  if (BlockType!=NewLhd.HeadType) BlockType=ALL_HEAD;
933
-
934
-  if((FILE_HEAD == BlockType) && (Size>0))
935
-  {
936
-    NewLhd.NameSize=Min(NewLhd.NameSize,sizeof(ArcFileName)-1);
937
-#ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
938
-    tread(MemRARFile, ArcFileName, NewLhd.NameSize);
939
-#else
940
-    tread(ArcPtr,ArcFileName,NewLhd.NameSize);
941
-#endif
942
-    ArcFileName[NewLhd.NameSize]=0;
943
-#ifdef _DEBUG_LOG
944
-    if (NewLhd.HeadCRC!=(UWORD)~CalcCRC32(HeaderCRC,(UBYTE*)&ArcFileName[0],
945
-                                          NewLhd.NameSize))
946
-    {
947
-      debug_log("file header broken");
948
+    fclose(out);
949
+    close(fd);
950
+    
951
+    memset(&OpenArchiveData, 0, sizeof(OpenArchiveData));
952
+	
953
+    OpenArchiveData.ArcName         = uname; /* name arch */
954
+    OpenArchiveData.CmtBuf          = NULL;
955
+    OpenArchiveData.OpenMode        = RAR_OM_EXTRACT;
956
+		    
957
+    hArcData = RAROpenArchiveEx(&OpenArchiveData);
958
+			
959
+    if (OpenArchiveData.OpenResult != 0)
960
+    {
961
+        cli_dbgmsg("cli_unrar3: error archive open (%d)\n", OpenArchiveData.OpenResult);
962
+	unlink(uname);
963
+        return CL_EOPEN;
964
+    }
965
+						    
966
+    HeaderData.CmtBuf = NULL;
967
+									
968
+    while ((iReadHeaderCode = RARReadHeader(hArcData, &HeaderData)) == 0)
969
+    {
970
+        iProcessFileCode = RARProcessFile(hArcData, RAR_EXTRACT, (char *)dir, NULL);
971
+        if (iProcessFileCode != 0)
972
+	{
973
+            cli_dbgmsg("cli_unrar3: error archive extract (%d)\n", iProcessFileCode);
974
+            break;
975
+	}
976
+		    
977
     }
978
-#endif
979
-    Size+=NewLhd.NameSize;
980
-  } else
981
-  {
982
-    memcpy(&NewLhd,&SaveFileHead,sizeof(NewLhd));
983
-#ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
984
-    MemRARFile->offset = CurBlockPos;
985
-#else
986
-    tseek(ArcPtr,CurBlockPos,SEEK_SET);
987
-#endif
988
-  }
989
-
990
-
991
-  return(Size);
992
-}
993
-
994
-
995
-int ReadHeader(int BlockType)
996
-{
997
-  int Size = 0;
998
-  unsigned char Header[64];
999
-  memset(Header, 0, sizeof(Header));
1000
-  switch(BlockType)
1001
-  {
1002
-    case MAIN_HEAD:
1003
-#ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
1004
-        Size=tread(MemRARFile, Header, SIZEOF_NEWMHD);
1005
-#else
1006
-        Size=tread(ArcPtr,Header,SIZEOF_NEWMHD);
1007
-#endif
1008
-        NewMhd.HeadCRC=(unsigned short)GetHeaderWord(0);
1009
-        NewMhd.HeadType=GetHeaderByte(2);
1010
-        NewMhd.Flags=(unsigned short)GetHeaderWord(3);
1011
-        NewMhd.HeadSize=(unsigned short)GetHeaderWord(5);
1012
-        NewMhd.Reserved=(unsigned short)GetHeaderWord(7);
1013
-        NewMhd.Reserved1=GetHeaderDword(9);
1014
-        HeaderCRC=CalcCRC32(0xFFFFFFFFL,&Header[2],SIZEOF_NEWMHD-2);
1015
-      break;
1016
-    case FILE_HEAD:
1017
-#ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
1018
-        Size=tread(MemRARFile, Header, SIZEOF_NEWLHD);
1019
-#else
1020
-        Size=tread(ArcPtr,Header,SIZEOF_NEWLHD);
1021
-#endif
1022
-        NewLhd.HeadCRC=(unsigned short)GetHeaderWord(0);
1023
-        NewLhd.HeadType=GetHeaderByte(2);
1024
-        NewLhd.Flags=(unsigned short)GetHeaderWord(3);
1025
-        NewLhd.HeadSize=(unsigned short)GetHeaderWord(5);
1026
-        NewLhd.PackSize=GetHeaderDword(7);
1027
-        NewLhd.UnpSize=GetHeaderDword(11);
1028
-        NewLhd.HostOS=GetHeaderByte(15);
1029
-        NewLhd.FileCRC=GetHeaderDword(16);
1030
-        NewLhd.FileTime=GetHeaderDword(20);
1031
-        NewLhd.UnpVer=GetHeaderByte(24);
1032
-        NewLhd.Method=GetHeaderByte(25);
1033
-        NewLhd.NameSize=(unsigned short)GetHeaderWord(26);
1034
-        NewLhd.FileAttr=GetHeaderDword(28);
1035
-        HeaderCRC=CalcCRC32(0xFFFFFFFFL,Header+2,SIZEOF_NEWLHD-2);
1036
-      break;
1037
-
1038
-#ifdef _DEBUG_LOG
1039
-  case COMM_HEAD:                           /* log errors in case of debug  */
1040
-        debug_log("Comment headers not supported! "\
1041
-                  "Please create archives without comments.");
1042
-      break;
1043
-  case PROTECT_HEAD:
1044
-        debug_log("Protected headers not supported!");
1045
-      break;
1046
-  case ALL_HEAD:
1047
-        debug_log("ShortBlockHeader not supported!");
1048
-      break;
1049
-  default:
1050
-        debug_log("Unknown//unsupported !");
1051
-#else
1052
-  default:                                  /* else do nothing              */
1053
-        break;
1054
-#endif
1055
-  }
1056
-  return(Size);
1057
+					    
1058
+    RARCloseArchive(hArcData);
1059
+    unlink(uname);
1060
+    
1061
+    /*
1062
+    if (iProcessFileCode == ERAR_BAD_DATA)
1063
+	return CL_ERAR;
1064
+    */
1065
+    return CL_CLEAN;
1066
 }
1067
-
1068
-/* **************************************************************************
1069
- ****************************************************************************
1070
- ****************************************************************************
1071
- ************************************************************************** */
1072
-
1073
-
1074
-
1075
-
1076
-
1077
-
1078
-
1079
-
1080
-
1081
-
1082
-
1083
-
1084
-
1085
-
1086
-
1087
-
1088
-
1089
-/* **************************************************************************
1090
- ****************************************************************************
1091
- ****************************************************************************
1092
- ****************************************************************************
1093
- *******                                                              *******
1094
- *******                                                              *******
1095
- *******                                                              *******
1096
- *******                  E X T R A C T   L O O P                     *******
1097
- *******                                                              *******
1098
- *******                                                              *******
1099
- *******                                                              *******
1100
- ****************************************************************************
1101
- ****************************************************************************
1102
- ****************************************************************************
1103
- ************************************************************************** */
1104
-
1105
-
1106
-int IsArchive(void)
1107
-{
1108
-#ifdef _DEBUG_LOG
1109
-  int  str_offs;                            /* used for debug-strings       */
1110
-  char DebugMsg[500];                       /* used to compose debug msg    */
1111
-#endif
1112
-
1113
-#ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
1114
-  if (tread(MemRARFile, MarkHead.Mark, SIZEOF_MARKHEAD) != SIZEOF_MARKHEAD) {
1115
-    debug_log("IsArchive(): short read: FALSE");
1116
-    return(FALSE);
1117
-  }
1118
-#else
1119
-  if (tread(ArcPtr,MarkHead.Mark,SIZEOF_MARKHEAD)!=SIZEOF_MARKHEAD) {
1120
-    debug_log("IsArchive(): short read: FALSE");
1121
-    return(FALSE);
1122
-  }
1123
-#endif
1124
-  /* Old archive => error                                                   */
1125
-  if (MarkHead.Mark[0]==0x52 && MarkHead.Mark[1]==0x45 &&
1126
-      MarkHead.Mark[2]==0x7e && MarkHead.Mark[3]==0x5e)
1127
-  {
1128
-    debug_log("Attention: format as OLD detected! Can't handle archive!");
1129
-  }
1130
-  else
1131
-      /* original RAR v2.0                                                  */
1132
-      if ((MarkHead.Mark[0]==0x52 && MarkHead.Mark[1]==0x61 && /* original  */
1133
-           MarkHead.Mark[2]==0x72 && MarkHead.Mark[3]==0x21 && /* RAR header*/
1134
-           MarkHead.Mark[4]==0x1a && MarkHead.Mark[5]==0x07 &&
1135
-           MarkHead.Mark[6]==0x00) ||
1136
-     /* "UniquE!" - header                                                  */
1137
-          (MarkHead.Mark[0]=='U' && MarkHead.Mark[1]=='n' &&   /* "UniquE!" */
1138
-           MarkHead.Mark[2]=='i' && MarkHead.Mark[3]=='q' &&   /* header    */
1139
-           MarkHead.Mark[4]=='u' && MarkHead.Mark[5]=='E' &&
1140
-           MarkHead.Mark[6]=='!'))
1141
-
1142
-    {
1143
-      if (ReadHeader(MAIN_HEAD)!=SIZEOF_NEWMHD) {
1144
-        debug_log("IsArchive(): ReadHeader() failed");
1145
-        return(FALSE);
1146
-      }
1147
-    } else
1148
-    {
1149
-
1150
-#ifdef _DEBUG_LOG
1151
-     /* sorry for this ugly code, but older SunOS gcc compilers don't       */
1152
-     /* support white spaces within strings                                 */
1153
-     str_offs  = sprintf(DebugMsg, "unknown archive type (only plain RAR ");
1154
-     str_offs += sprintf(DebugMsg + str_offs, "supported (normal and solid ");
1155
-     str_offs += sprintf(DebugMsg + str_offs, "archives), SFX and Volumes ");
1156
-     str_offs += sprintf(DebugMsg + str_offs, "are NOT supported!)");
1157
-
1158
-     debug_log(DebugMsg);
1159
-#endif
1160
-
1161
-    }
1162
-
1163
-
1164
-  MainHeadSize=SIZEOF_NEWMHD;
1165
-
1166
-  return(TRUE);
1167
-}
1168
-
1169
-
1170
-BOOL ExtrFile(int desc)
1171
-{
1172
-  BOOL ReturnCode=TRUE;
1173
-  BOOL FileFound=FALSE;                     /* TRUE=use current extracted   */
1174
-                                            /* data FALSE=throw data away,  */
1175
-                                            /* wrong file                   */
1176
-  int newdesc;
1177
-
1178
-#ifdef  _USE_MEMORY_TO_MEMORY_DECOMPRESSION
1179
-  MemRARFile->offset = 0;                   /* start reading from offset 0  */
1180
-  if (!IsArchive())
1181
-  {
1182
-    debug_log("Not a RAR file");
1183
-    return FALSE;                           /* error => exit!               */
1184
-  }
1185
-
1186
-#else
1187
-  /* open and identify archive                                              */
1188
-  newdesc = dup(desc);
1189
-  cli_dbgmsg("ExtrFile(): dup(%d) = %d\n", desc, newdesc);
1190
-  if ((ArcPtr=fdopen(newdesc,READBINARY))!=NULL)
1191
-  {
1192
-    if (!IsArchive())
1193
-    {
1194
-      debug_log("Not a RAR file");
1195
-      fclose(ArcPtr);
1196
-      ArcPtr = NULL;
1197
-      return FALSE;                         /* error => exit!               */
1198
-    }
1199
-  } else
1200
-  {
1201
-    debug_log("Error opening file.");
1202
-    return FALSE;
1203
-  }
1204
-#endif
1205
-
1206
-
1207
-  if ((UnpMemory=malloc(UNP_MEMORY))==NULL)
1208
-  {
1209
-    cli_dbgmsg("unrarlib: Can't allocate memory for decompression!");
1210
-    return FALSE;
1211
-  } else cli_dbgmsg("unrarlib: Allocated %d bytes.\n", UNP_MEMORY);
1212
-
1213
-#ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
1214
-  MemRARFile->offset+=NewMhd.HeadSize-MainHeadSize;
1215
-#else
1216
-  tseek(ArcPtr,NewMhd.HeadSize-MainHeadSize,SEEK_CUR);
1217
-#endif
1218
-
1219
-  /* do while file is not extracted and there's no error                    */
1220
-  do
1221
-  {
1222
-
1223
-    if (ReadBlock(FILE_HEAD | READSUBBLOCK) <= 0) /* read name of the next  */
1224
-    {                                       /* file within the RAR archive  */
1225
-/*
1226
- *
1227
- * 21.11.2000  UnQ  There's a problem with some linux distros when a file
1228
- *                  can not be found in an archive.
1229
- * 07.09.2004  ThL  Seems more like a logical bug in this lib, since it
1230
- *		    appears to occur once for every archive.
1231
- */
1232
-
1233
-      /*
1234
-      debug_log("Couldn't read next filename from archive (I/O error).");
1235
-      */
1236
-      ReturnCode=FALSE;
1237
-      break;                                /* error, file not found in     */
1238
-    }                                       /* archive or I/O error         */
1239
-    if (BlockHead.HeadType==SUB_HEAD)
1240
-    {
1241
-      debug_log("Sorry, sub-headers not supported.");
1242
-      ReturnCode=FALSE;
1243
-      break;                                /* error => exit                */
1244
-    }
1245
-
1246
-
1247
-    if(TRUE == (FileFound=(stricomp(ArgName, ArcFileName) == 0)))
1248
-    /* *** file found! ***                                                  */
1249
-    {
1250
-      {
1251
-	cli_dbgmsg("unrarlib: Allocating %d bytes\n", NewLhd.UnpSize);
1252
-        if((temp_output_buffer=malloc(NewLhd.UnpSize)) == NULL) { ;/* allocate memory for the*/
1253
-	    cli_errmsg("unrarlib: Can't malloc %d bytes\n", NewLhd.UnpSize);
1254
-	    ReturnCode = FALSE;
1255
-	    break;
1256
-	}
1257
-      }
1258
-      *temp_output_buffer_offset=0;         /* file. The default offset     */
1259
-                                            /* within the buffer is 0       */
1260
-    }
1261
-
1262
-    /* in case of a solid archive, we need to decompress any single file till
1263
-     * we have found the one we are looking for. In case of normal archives
1264
-     * (recommended!!), we skip the files until we are sure that it is the
1265
-     * one we want.
1266
-     */
1267
-    if((NewMhd.Flags & 0x08) || FileFound)
1268
-    {
1269
-      if (NewLhd.UnpVer<13 || NewLhd.UnpVer>UNP_VER)
1270
-      {
1271
-        cli_dbgmsg("unknown compression method: %d  (min=13 max=%d)\n", NewLhd.UnpVer, UNP_VER);
1272
-        ReturnCode=FALSE;
1273
-        break;                              /* error, can't extract file!   */
1274
-      }
1275
-
1276
-      CurUnpRead=0;
1277
-      if ((*Password!=0) && (NewLhd.Flags & LHD_PASSWORD))
1278
-        Encryption=NewLhd.UnpVer;
1279
-      else
1280
-        Encryption=0;
1281
-      if (Encryption) SetCryptKeys(Password);
1282
-
1283
-      UnpPackedSize=NewLhd.PackSize;
1284
-      DestUnpSize=NewLhd.UnpSize;
1285
-
1286
-      if (NewLhd.Method==0x30)
1287
-      {
1288
-	cli_dbgmsg("unrarlib: Unstore method temporarily not supported\n");
1289
-        /* UnstoreFile(); */
1290
-        ReturnCode=FALSE;
1291
-        break;                              /* error, can't extract file! */
1292
-      } else
1293
-      {
1294
-	cli_dbgmsg("unrarlib: Unpack()\n");
1295
-        Unpack(UnpMemory, FileFound);
1296
-      }
1297
-
1298
-
1299
-#ifdef _DO_CRC32_CHECK                      /* calculate CRC32              */
1300
-      if((UBYTE*)temp_output_buffer != NULL)
1301
-      {
1302
-        if(NewLhd.FileCRC!=~CalcCRC32(0xFFFFFFFFL,
1303
-                                      (UBYTE*)temp_output_buffer,
1304
-                                      NewLhd.UnpSize))
1305
-        {
1306
-          debug_log("CRC32 error - file couldn't be decompressed correctly!");
1307
-          ReturnCode=FALSE;
1308
-          break;                              /* error, can't extract file! */
1309
-        }
1310
-      }
1311
-#endif
1312
-
1313
-    }
1314
-
1315
-#ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
1316
-    MemRARFile->offset = NextBlockPos;
1317
-#else
1318
-    if (ArcPtr!=NULL) tseek(ArcPtr,NextBlockPos,SEEK_SET);
1319
-#endif
1320
-  } while(stricomp(ArgName, ArcFileName) != 0);/* exit if file is extracted */
1321
-
1322
-  /* free memory, clear password and close archive                          */
1323
-  if(UnpMemory)
1324
-    free(UnpMemory);
1325
-
1326
-  UnpMemory=NULL;
1327
-#ifndef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
1328
-  if (ArcPtr!=NULL){
1329
-      fclose(ArcPtr);
1330
-      lseek(desc, 0, SEEK_SET);
1331
-      ArcPtr = NULL;
1332
-  }
1333
-#endif
1334
-
1335
-  return ReturnCode;
1336
-}
1337
-
1338
-/* **************************************************************************
1339
- ****************************************************************************
1340
- ****************************************************************************
1341
- ************************************************************************** */
1342
-
1343
-
1344
-
1345
-
1346
-
1347
-
1348
-
1349
-
1350
-
1351
-
1352
-
1353
-
1354
-
1355
-
1356
-
1357
-
1358
-
1359
-
1360
-/* **************************************************************************
1361
- ****************************************************************************
1362
- ****************************************************************************
1363
- ****************************************************************************
1364
- *******                                                              *******
1365
- *******                                                              *******
1366
- *******                                                              *******
1367
- *******             G L O B A L   F U N C T I O N S                  *******
1368
- *******                                                              *******
1369
- *******                                                              *******
1370
- *******                                                              *******
1371
- ****************************************************************************
1372
- ****************************************************************************
1373
- ****************************************************************************
1374
- ************************************************************************** */
1375
-
1376
-
1377
-int tread(void *stream,void *buf,unsigned len)
1378
-{
1379
-#ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
1380
-
1381
-  if(((MemRARFile->offset + len) > MemRARFile->size) || (len == 0))
1382
-     return 0;
1383
-
1384
-  memcpy(buf,
1385
-         (BYTE*)(((MemoryFile*)stream)->data)+((MemoryFile*)stream)->offset,
1386
-         len % ((((MemoryFile*)stream)->size) - 1));
1387
-
1388
-  MemRARFile->offset+=len;                  /* update read pointer          */
1389
-  return len % ((((MemoryFile*)stream)->size) - 1);
1390
-#else
1391
-  return(fread(buf,1,len,(FILE*)stream));
1392
-#endif
1393
-}
1394
-
1395
-
1396
-#ifndef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
1397
-int tseek(void *stream,long offset,int fromwhere)
1398
-{
1399
-  return(fseek((FILE*)stream,offset,fromwhere));
1400
-}
1401
-#endif
1402
-
1403
-
1404
-static char* strupper(char *Str)
1405
-{
1406
-  char *ChPtr;
1407
-  for (ChPtr=Str;*ChPtr;ChPtr++)
1408
-    *ChPtr=(char)toupper(*ChPtr);
1409
-  return(Str);
1410
-}
1411
-
1412
-
1413
-int stricomp(char *Str1,char *Str2)
1414
-/* compare strings without regard of '\' and '/'                            */
1415
-{
1416
-  char S1[512],S2[512];
1417
-  char *chptr;
1418
-
1419
-  strncpy(S1,Str1,sizeof(S1));
1420
-  strncpy(S2,Str2,sizeof(S2));
1421
-
1422
-  while((chptr = strchr(S1, '\\')) != NULL) /* ignore backslash             */
1423
-  {
1424
-    *chptr = '_';
1425
-  }
1426
-
1427
-  while((chptr = strchr(S2, '\\')) != NULL) /* ignore backslash             */
1428
-  {
1429
-    *chptr = '_';
1430
-  }
1431
-
1432
-  while((chptr = strchr(S1, '/')) != NULL)  /* ignore slash                 */
1433
-  {
1434
-    *chptr = '_';
1435
-  }
1436
-
1437
-  while((chptr = strchr(S2, '/')) != NULL)  /* ignore slash                 */
1438
-  {
1439
-    *chptr = '_';
1440
-  }
1441
-
1442
-  return(strcmp(strupper(S1),strupper(S2)));
1443
-}
1444
-
1445
-
1446
-/* **************************************************************************
1447
- ****************************************************************************
1448
- ****************************************************************************
1449
- ************************************************************************** */
1450
-
1451
-
1452
-
1453
-
1454
-
1455
-
1456
-
1457
-
1458
-
1459
-
1460
-
1461
-
1462
-
1463
-
1464
-
1465
-
1466
-
1467
-
1468
-/* **************************************************************************
1469
- ****************************************************************************
1470
- ****************************************************************************
1471
- ****************************************************************************
1472
- *******                                                              *******
1473
- *******                                                              *******
1474
- *******                                                              *******
1475
- *******                   U N P A C K   C O D E                      *******
1476
- *******                                                              *******
1477
- *******                                                              *******
1478
- *******                                                              *******
1479
- ****************************************************************************
1480
- ****************************************************************************
1481
- ****************************************************************************
1482
- ************************************************************************** */
1483
-
1484
-
1485
-/* *****************************
1486
- * ** unpack stored RAR files **
1487
- * *****************************/
1488
-
1489
-/*
1490
-BOOL UnstoreFile(void)
1491
-{
1492
-  if ((long)(*temp_output_buffer_offset=UnpRead(temp_output_buffer,
1493
-                                                NewLhd.UnpSize))==-1)
1494
-  {
1495
-    cli_dbgmsg("unrarlib: Read error of stored file!");
1496
-    return FALSE;
1497
-  }
1498
-  return TRUE;
1499
-}
1500
-*/
1501
-
1502
-
1503
-/* ****************************************
1504
- * ** RAR decompression code starts here **
1505
- * ****************************************/
1506
-
1507
-#define NC 298                              /* alphabet = {0,1,2, .,NC - 1} */
1508
-#define DC 48
1509
-#define RC 28
1510
-#define BC 19
1511
-#define MC 257
1512
-
1513
-enum {CODE_HUFFMAN=0,CODE_LZ=1,CODE_LZ2=2,CODE_REPEATLZ=3,CODE_CACHELZ=4,
1514
-      CODE_STARTFILE=5,CODE_ENDFILE=6,CODE_STARTMM=8,CODE_ENDMM=7,
1515
-      CODE_MMDELTA=9};
1516
-
1517
-struct AudioVariables
1518
-{
1519
-  int K1,K2,K3,K4,K5;
1520
-  int D1,D2,D3,D4;
1521
-  int LastDelta;
1522
-  unsigned int Dif[11];
1523
-  unsigned int ByteCount;
1524
-  int LastChar;
1525
-};
1526
-
1527
-
1528
-#define NC 298  /* alphabet = {0, 1, 2, ..., NC - 1} */
1529
-#define DC 48
1530
-#define RC 28
1531
-#define BC 19
1532
-#define MC 257
1533
-
1534
-
1535
-static struct AudioVariables AudV[4];
1536
-
1537
-#define GetBits()                                                 \
1538
-        BitField = ( ( ( (UDWORD)InBuf[InAddr]   << 16 ) |        \
1539
-                       ( (UWORD) InBuf[InAddr+1] <<  8 ) |        \
1540
-                       (         InBuf[InAddr+2]       ) )        \
1541
-                       >> (8-InBit) ) & 0xffff;
1542
-
1543
-
1544
-#define AddBits(Bits)                          \
1545
-        InAddr += ( InBit + (Bits) ) >> 3;     \
1546
-        InBit  =  ( InBit + (Bits) ) &  7;
1547
-
1548
-static unsigned char *UnpBuf;
1549
-static unsigned int BitField;
1550
-static unsigned int Number;
1551
-
1552
-static unsigned char InBuf[8192];                  /* input read buffer            */
1553
-
1554
-static unsigned char UnpOldTable[MC*4];
1555
-
1556
-static unsigned int InAddr,InBit,ReadTop;
1557
-
1558
-static unsigned int LastDist,LastLength;
1559
-static unsigned int Length,Distance;
1560
-
1561
-static unsigned int OldDist[4],OldDistPtr;
1562
-
1563
-
1564
-static struct LitDecode
1565
-{
1566
-  unsigned int MaxNum;
1567
-  unsigned int DecodeLen[16];
1568
-  unsigned int DecodePos[16];
1569
-  unsigned int DecodeNum[NC];
1570
-} LD;
1571
-
1572
-static struct DistDecode
1573
-{
1574
-  unsigned int MaxNum;
1575
-  unsigned int DecodeLen[16];
1576
-  unsigned int DecodePos[16];
1577
-  unsigned int DecodeNum[DC];
1578
-} DD;
1579
-
1580
-static struct RepDecode
1581
-{
1582
-  unsigned int MaxNum;
1583
-  unsigned int DecodeLen[16];
1584
-  unsigned int DecodePos[16];
1585
-  unsigned int DecodeNum[RC];
1586
-} RD;
1587
-
1588
-static struct MultDecode
1589
-{
1590
-  unsigned int MaxNum;
1591
-  unsigned int DecodeLen[16];
1592
-  unsigned int DecodePos[16];
1593
-  unsigned int DecodeNum[MC];
1594
-} MD[4];
1595
-
1596
-static struct BitDecode
1597
-{
1598
-  unsigned int MaxNum;
1599
-  unsigned int DecodeLen[16];
1600
-  unsigned int DecodePos[16];
1601
-  unsigned int DecodeNum[BC];
1602
-} BD;
1603
-
1604
-static struct MultDecode *MDPtr[4]={&MD[0],&MD[1],&MD[2],&MD[3]};
1605
-
1606
-static int UnpAudioBlock,UnpChannels,CurChannel,ChannelDelta;
1607
-
1608
-
1609
-void Unpack(unsigned char *UnpAddr, BOOL FileFound)
1610
-/* *** 38.3% of all CPU time is spent within this function!!!               */
1611
-{
1612
-  static unsigned char LDecode[]={0,1,2,3,4,5,6,7,8,10,12,14,16,20,24,28,32,
1613
-                                  40,48,56,64,80,96,112,128,160,192,224};
1614
-  static unsigned char LBits[]=  {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,
1615
-                                  3,3,3,4,4,4,4,5,5,5,5};
1616
-  static int DDecode[]={0,1,2,3,4,6,8,12,16,24,32,48,64,96,128,192,256,384,
1617
-                        512,768,1024,1536,2048,3072,4096,6144,8192,12288,
1618
-                        16384,24576,32768U,49152U,65536,98304,131072,196608,
1619
-                        262144,327680,393216,458752,524288,589824,655360,
1620
-                        720896,786432,851968,917504,983040};
1621
-  static unsigned char DBits[]=  {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,
1622
-                                  9,10,10,11,11,12,12,13,13,14,14,15,15,16,
1623
-                                  16,16,16,16,16,16,16,16,16,16,16,16,16};
1624
-  static unsigned char SDDecode[]={0,4,8,16,32,64,128,192};
1625
-  static unsigned char SDBits[]={2,2,3, 4, 5, 6,  6,  6};
1626
-  unsigned int Bits;
1627
-
1628
-
1629
-  UnpBuf=UnpAddr;                           /* UnpAddr is a pointer to the  */
1630
-  UnpInitData();                            /* unpack buffer                */
1631
-  UnpReadBuf(1);
1632
-  if (!(NewLhd.Flags & LHD_SOLID))
1633
-     ReadTables();
1634
-   DestUnpSize--;
1635
-
1636
-  while (DestUnpSize>=0)
1637
-  {
1638
-    UnpPtr&=MAXWINMASK;
1639
-
1640
-    if (InAddr>sizeof(InBuf)-30)
1641
-      UnpReadBuf(0);
1642
-    if (((WrPtr-UnpPtr) & MAXWINMASK)<270 && WrPtr!=UnpPtr)
1643
-    {
1644
-
1645
-
1646
-      if (FileFound)
1647
-      {
1648
-
1649
-        if (UnpPtr<WrPtr)
1650
-        {
1651
-                        if((*temp_output_buffer_offset + ((0-WrPtr) & MAXWINMASK) + UnpPtr) > NewLhd.UnpSize)
1652
-                        {
1653
-                           debug_log("Fatal! Buffer overrun during decompression!");
1654
-                          DestUnpSize=-1;
1655
-
1656
-                    } else
1657
-                        {
1658
-              /* copy extracted data to output buffer                         */
1659
-              memcpy(temp_output_buffer + *temp_output_buffer_offset,
1660
-                     &UnpBuf[WrPtr], (0-WrPtr) & MAXWINMASK);
1661
-              /* update offset within buffer                                  */
1662
-              *temp_output_buffer_offset+= (0-WrPtr) & MAXWINMASK;
1663
-              /* copy extracted data to output buffer                         */
1664
-              memcpy(temp_output_buffer + *temp_output_buffer_offset, UnpBuf,
1665
-                     UnpPtr);
1666
-              /* update offset within buffer                                  */
1667
-              *temp_output_buffer_offset+=UnpPtr;
1668
-                        }
1669
-        } else
1670
-        {
1671
-                        if((*temp_output_buffer_offset + (UnpPtr-WrPtr)) > NewLhd.UnpSize)
1672
-                        {
1673
-                           debug_log("Fatal! Buffer overrun during decompression!");
1674
-                          DestUnpSize=-1;
1675
-                    } else
1676
-                        {
1677
-                  /* copy extracted data to output buffer                       */
1678
-              memcpy(temp_output_buffer + *temp_output_buffer_offset,
1679
-                     &UnpBuf[WrPtr], UnpPtr-WrPtr);
1680
-              *temp_output_buffer_offset+=UnpPtr-WrPtr;                                                /* update offset within buffer */
1681
-                    }
1682
-
1683
-            }
1684
-      }
1685
-
1686
-      WrPtr=UnpPtr;
1687
-    }
1688
-
1689
-    if (UnpAudioBlock)
1690
-    {
1691
-      DecodeNumber((struct Decode *)MDPtr[CurChannel]);
1692
-      if (Number==256)
1693
-      {
1694
-        ReadTables();
1695
-        continue;
1696
-      }
1697
-      UnpBuf[UnpPtr++]=DecodeAudio(Number);
1698
-      if (++CurChannel==UnpChannels)
1699
-        CurChannel=0;
1700
-      DestUnpSize--;
1701
-      continue;
1702
-    }
1703
-
1704
-    DecodeNumber((struct Decode *)&LD);
1705
-    if (Number<256)
1706
-    {
1707
-      UnpBuf[UnpPtr++]=(UBYTE)Number;
1708
-      DestUnpSize--;
1709
-      continue;
1710
-    }
1711
-    if (Number>269)
1712
-    {
1713
-      Length=LDecode[Number-=270]+3;
1714
-      if ((Bits=LBits[Number])>0)
1715
-      {
1716
-        GetBits();
1717
-        Length+=BitField>>(16-Bits);
1718
-        AddBits(Bits);
1719
-      }
1720
-
1721
-      DecodeNumber((struct Decode *)&DD);
1722
-      Distance=DDecode[Number]+1;
1723
-      if ((Bits=DBits[Number])>0)
1724
-      {
1725
-        GetBits();
1726
-        Distance+=BitField>>(16-Bits);
1727
-        AddBits(Bits);
1728
-      }
1729
-
1730
-      if (Distance>=0x40000L)
1731
-        Length++;
1732
-
1733
-      if (Distance>=0x2000)
1734
-        Length++;
1735
-
1736
-       LastDist=OldDist[OldDistPtr++ & 3]=Distance;
1737
-       DestUnpSize-=(LastLength=Length);
1738
-       while (Length--)
1739
-       {
1740
-         UnpBuf[UnpPtr]=UnpBuf[(UnpPtr-Distance) & MAXWINMASK];
1741
-         UnpPtr=(UnpPtr+1) & MAXWINMASK;
1742
-       }
1743
-
1744
-      continue;
1745
-    }
1746
-    if (Number==269)
1747
-    {
1748
-      ReadTables();
1749
-      continue;
1750
-    }
1751
-    if (Number==256)
1752
-    {
1753
-      Length=LastLength;
1754
-      Distance=LastDist;
1755
-       LastDist=OldDist[OldDistPtr++ & 3]=Distance;
1756
-       DestUnpSize-=(LastLength=Length);
1757
-       while (Length--)
1758
-       {
1759
-         UnpBuf[UnpPtr]=UnpBuf[(UnpPtr-Distance) & MAXWINMASK];
1760
-         UnpPtr=(UnpPtr+1) & MAXWINMASK;
1761
-       }
1762
-      continue;
1763
-    }
1764
-    if (Number<261)
1765
-    {
1766
-      Distance=OldDist[(OldDistPtr-(Number-256)) & 3];
1767
-      DecodeNumber((struct Decode *)&RD);
1768
-      Length=LDecode[Number]+2;
1769
-      if ((Bits=LBits[Number])>0)
1770
-      {
1771
-        GetBits();
1772
-        Length+=BitField>>(16-Bits);
1773
-        AddBits(Bits);
1774
-      }
1775
-      if (Distance>=0x40000)
1776
-        Length++;
1777
-      if (Distance>=0x2000)
1778
-        Length++;
1779
-      if (Distance>=0x101)
1780
-        Length++;
1781
-       LastDist=OldDist[OldDistPtr++ & 3]=Distance;
1782
-       DestUnpSize-=(LastLength=Length);
1783
-       while (Length--)
1784
-       {
1785
-         UnpBuf[UnpPtr]=UnpBuf[(UnpPtr-Distance) & MAXWINMASK];
1786
-         UnpPtr=(UnpPtr+1) & MAXWINMASK;
1787
-       }
1788
-      continue;
1789
-    }
1790
-    if (Number<270)
1791
-    {
1792
-      Distance=SDDecode[Number-=261]+1;
1793
-      if ((Bits=SDBits[Number])>0)
1794
-      {
1795
-        GetBits();
1796
-        Distance+=BitField>>(16-Bits);
1797
-        AddBits(Bits);
1798
-      }
1799
-      Length=2;
1800
-       LastDist=OldDist[OldDistPtr++ & 3]=Distance;
1801
-       DestUnpSize-=(LastLength=Length);
1802
-       while (Length--)
1803
-       {
1804
-         UnpBuf[UnpPtr]=UnpBuf[(UnpPtr-Distance) & MAXWINMASK];
1805
-         UnpPtr=(UnpPtr+1) & MAXWINMASK;
1806
-       }
1807
-      continue;
1808
-   }
1809
-  }
1810
-  ReadLastTables();
1811
-
1812
-  if (FileFound)                            /* flush buffer                 */
1813
-  {
1814
-
1815
-    if (UnpPtr<WrPtr)
1816
-    {
1817
-          if((*temp_output_buffer_offset + ((0-WrPtr) & MAXWINMASK) + UnpPtr) > NewLhd.UnpSize)
1818
-          {
1819
-            debug_log("Fatal! Buffer overrun during decompression!");
1820
-                DestUnpSize=-1;
1821
-          } else
1822
-          {
1823
-        /* copy extracted data to output buffer                             */
1824
-        memcpy(temp_output_buffer + *temp_output_buffer_offset, &UnpBuf[WrPtr],
1825
-               (0-WrPtr) & MAXWINMASK);
1826
-        /* update offset within buffer                                      */
1827
-        *temp_output_buffer_offset+= (0-WrPtr) & MAXWINMASK;
1828
-        /* copy extracted data to output buffer                             */
1829
-        memcpy(temp_output_buffer + *temp_output_buffer_offset, UnpBuf, UnpPtr);
1830
-        /* update offset within buffer                                      */
1831
-        *temp_output_buffer_offset+=UnpPtr;
1832
-          }
1833
-    } else
1834
-    {
1835
-          if((*temp_output_buffer_offset + (UnpPtr-WrPtr)) > NewLhd.UnpSize)
1836
-          {
1837
-                 debug_log("Fatal! Buffer overrun during decompression!");
1838
-                DestUnpSize=-1;
1839
-          } else
1840
-          {
1841
-        /* copy extracted data to output buffer                             */
1842
-        memcpy(temp_output_buffer + *temp_output_buffer_offset, &UnpBuf[WrPtr],
1843
-               UnpPtr-WrPtr);
1844
-        /* update offset within buffer                                      */
1845
-        *temp_output_buffer_offset+=UnpPtr-WrPtr;
1846
-          }
1847
-    }
1848
-  }
1849
-
1850
-  WrPtr=UnpPtr;
1851
-}
1852
-
1853
-
1854
-unsigned int UnpRead(unsigned char *Addr,unsigned int Count)
1855
-{
1856
-  int RetCode=0;
1857
-  unsigned int I,ReadSize,TotalRead=0;
1858
-  unsigned char *ReadAddr;
1859
-  ReadAddr=Addr;
1860
-  while (Count > 0)
1861
-  {
1862
-    ReadSize=(unsigned int)((Count>(unsigned long)UnpPackedSize) ?
1863
-                                                  UnpPackedSize : Count);
1864
-#ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
1865
-    cli_dbgmsg("unrarlib: UnpREAD: Using memory->memory decompression\n");
1866
-    if(MemRARFile->data == NULL)
1867
-      return(0);
1868
-    RetCode=tread(MemRARFile, ReadAddr, ReadSize);
1869
-#else
1870
-    if (ArcPtr==NULL)
1871
-      return(0);
1872
-    RetCode=tread(ArcPtr,ReadAddr,ReadSize);
1873
-#endif
1874
-    CurUnpRead+=RetCode;
1875
-    ReadAddr+=RetCode;
1876
-    TotalRead+=RetCode;
1877
-    Count-=RetCode;
1878
-    UnpPackedSize-=RetCode;
1879
-      break;
1880
-  }
1881
-
1882
-  cli_dbgmsg("CurUnpRead == %d, TotalRead == %d, Count == %d, UnpPackedSize == %d\n", CurUnpRead, TotalRead, Count, UnpPackedSize);
1883
-
1884
-  if (RetCode!= -1)
1885
-  {
1886
-    RetCode=TotalRead;
1887
-    if (Encryption)
1888
-    {
1889
-      if (Encryption<20)
1890
-          {
1891
-            cli_dbgmsg("unrarlib: Old Crypt() not supported!");
1892
-          }
1893
-      else
1894
-      {
1895
-        for (I=0;I<(unsigned int)RetCode;I+=16)
1896
-          DecryptBlock(&Addr[I]);
1897
-      }
1898
-    }
1899
-  }
1900
-  return(RetCode);
1901
-}
1902
-
1903
-
1904
-void UnpReadBuf(int FirstBuf)
1905
-{
1906
-  int RetCode;
1907
-  if (FirstBuf)
1908
-  {
1909
-    ReadTop=UnpRead(InBuf,sizeof(InBuf));
1910
-    InAddr=0;
1911
-  }
1912
-  else
1913
-  {
1914
-    memcpy(InBuf,&InBuf[sizeof(InBuf)-32],32);
1915
-    InAddr&=0x1f;
1916
-    RetCode=UnpRead(&InBuf[32],sizeof(InBuf)-32);
1917
-    if (RetCode>0)
1918
-      ReadTop=RetCode+32;
1919
-    else
1920
-      ReadTop=InAddr;
1921
-  }
1922
-}
1923
-
1924
-
1925
-void ReadTables(void)
1926
-{
1927
-  UBYTE BitLength[BC];
1928
-  unsigned char Table[MC*4];
1929
-  int TableSize,N,I;
1930
-  if (InAddr>sizeof(InBuf)-25)
1931
-    UnpReadBuf(0);
1932
-  GetBits();
1933
-  UnpAudioBlock=(BitField & 0x8000);
1934
-
1935
-  if (!(BitField & 0x4000))
1936
-    memset(UnpOldTable,0,sizeof(UnpOldTable));
1937
-  AddBits(2);
1938
-
1939
-
1940
-  if (UnpAudioBlock)
1941
-  {
1942
-    UnpChannels=((BitField>>12) & 3)+1;
1943
-    if (CurChannel>=UnpChannels)
1944
-      CurChannel=0;
1945
-    AddBits(2);
1946
-    TableSize=MC*UnpChannels;
1947
-  }
1948
-  else
1949
-    TableSize=NC+DC+RC;
1950
-
1951
-
1952
-  for (I=0;I<BC;I++)
1953
-  {
1954
-    GetBits();
1955
-    BitLength[I]=(UBYTE)(BitField >> 12);
1956
-    AddBits(4);
1957
-  }
1958
-  MakeDecodeTables(BitLength,(struct Decode *)&BD,BC);
1959
-  I=0;
1960
-  while (I<TableSize)
1961
-  {
1962
-    if (InAddr>sizeof(InBuf)-5)
1963
-      UnpReadBuf(0);
1964
-    DecodeNumber((struct Decode *)&BD);
1965
-    if (Number<16) {
1966
-      Table[I]=(Number+UnpOldTable[I]) & 0xf;
1967
-      I++;
1968
-    }
1969
-    else
1970
-      if (Number==16)
1971
-      {
1972
-        GetBits();
1973
-        N=(BitField >> 14)+3;
1974
-        AddBits(2);
1975
-        while (N-- > 0 && I<TableSize)
1976
-        {
1977
-          Table[I]=Table[I-1];
1978
-          I++;
1979
-        }
1980
-      }
1981
-      else
1982
-      {
1983
-        if (Number==17)
1984
-        {
1985
-          GetBits();
1986
-          N=(BitField >> 13)+3;
1987
-          AddBits(3);
1988
-        }
1989
-        else
1990
-        {
1991
-          GetBits();
1992
-          N=(BitField >> 9)+11;
1993
-          AddBits(7);
1994
-        }
1995
-        while (N-- > 0 && I<TableSize)
1996
-          Table[I++]=0;
1997
-      }
1998
-  }
1999
-  if (UnpAudioBlock)
2000
-    for (I=0;I<UnpChannels;I++)
2001
-      MakeDecodeTables(&Table[I*MC],(struct Decode *)MDPtr[I],MC);
2002
-  else
2003
-  {
2004
-    MakeDecodeTables(&Table[0],(struct Decode *)&LD,NC);
2005
-    MakeDecodeTables(&Table[NC],(struct Decode *)&DD,DC);
2006
-    MakeDecodeTables(&Table[NC+DC],(struct Decode *)&RD,RC);
2007
-  }
2008
-  memcpy(UnpOldTable,Table,sizeof(UnpOldTable));
2009
-}
2010
-
2011
-
2012
-static void ReadLastTables(void)
2013
-{
2014
-  if (ReadTop>=InAddr+5)
2015
-  {
2016
-    if (UnpAudioBlock)
2017
-    {
2018
-      DecodeNumber((struct Decode *)MDPtr[CurChannel]);
2019
-      if (Number==256)
2020
-        ReadTables();
2021
-    }
2022
-    else
2023
-    {
2024
-      DecodeNumber((struct Decode *)&LD);
2025
-      if (Number==269)
2026
-        ReadTables();
2027
-    }
2028
-  }
2029
-}
2030
-
2031
-
2032
-static void MakeDecodeTables(unsigned char *LenTab,
2033
-                             struct Decode *Dec,
2034
-                             int Size)
2035
-{
2036
-  int LenCount[16],TmpPos[16],I;
2037
-  long M,N;
2038
-  memset(LenCount,0,sizeof(LenCount));
2039
-  for (I=0;I<Size;I++)
2040
-    LenCount[LenTab[I] & 0xF]++;
2041
-
2042
-  LenCount[0]=0;
2043
-  for (TmpPos[0]=Dec->DecodePos[0]=Dec->DecodeLen[0]=0,N=0,I=1;I<16;I++)
2044
-  {
2045
-    N=2*(N+LenCount[I]);
2046
-    M=N<<(15-I);
2047
-    if (M>0xFFFF)
2048
-      M=0xFFFF;
2049
-    Dec->DecodeLen[I]=(unsigned int)M;
2050
-    TmpPos[I]=Dec->DecodePos[I]=Dec->DecodePos[I-1]+LenCount[I-1];
2051
-  }
2052
-
2053
-  for (I=0;I<Size;I++)
2054
-    if (LenTab[I]!=0)
2055
-      Dec->DecodeNum[TmpPos[LenTab[I] & 0xF]++]=I;
2056
-  Dec->MaxNum=Size;
2057
-}
2058
-
2059
-
2060
-static void DecodeNumber(struct Decode *Deco)
2061
-/* *** 52.6% of all CPU time is spent within this function!!!               */
2062
-{
2063
-  unsigned int I;
2064
-  register unsigned int N;
2065
-  GetBits();
2066
-
2067
-#ifdef _USE_ASM
2068
-
2069
-#ifdef _WIN_32
2070
- __asm {
2071
-
2072
-    xor eax, eax
2073
-    mov eax, BitField                       /* N=BitField & 0xFFFE; */
2074
-    and eax, 0xFFFFFFFE
2075
-    mov [N], eax
2076
-    mov edx, [Deco]                         /* EAX=N, EDX=Deco */
2077
-
2078
-          cmp  eax, dword ptr[edx + 8*4 + 4] /* if (N<Dec->DecodeLen[8]) */
2079
-          jae  else_G
2080
-
2081
-             cmp  eax, dword ptr[edx + 4*4 + 4] /* if (N<Dec->DecodeLen[4]) */
2082
-             jae  else_F
2083
-
2084
-
2085
-                cmp  eax, dword ptr[edx + 2*4 + 4] /* if (N<Dec->DecodeLen[2]) */
2086
-                jae  else_C
2087
-
2088
-                   cmp  eax, dword ptr[edx + 1*4 + 4] /* if (N<Dec->DecodeLen[1]) */
2089
-                   jae  else_1
2090
-                   mov  I, 1                         /*  I=1; */
2091
-                   jmp  next_1
2092
-                 else_1:                             /* else */
2093
-                   mov  I, 2                         /*  I=2; */
2094
-                 next_1:
2095
-
2096
-                jmp  next_C
2097
-              else_C:                             /* else */
2098
-
2099
-                   cmp  eax, dword ptr[edx + 3*4 + 4] /* if (N<Dec->DecodeLen[3]) */
2100
-                   jae  else_2
2101
-                   mov  I, 3                         /*  I=3; */
2102
-                   jmp  next_2
2103
-                 else_2:                             /* else */
2104
-                   mov  I, 4                         /*  I=4; */
2105
-                 next_2:
2106
-
2107
-              next_C:                             /* else */
2108
-
2109
-             jmp  next_F
2110
-           else_F:
2111
-
2112
-
2113
-             cmp  eax, dword ptr[edx + 6*4 + 4] /* if (N<Dec->DecodeLen[6]) */
2114
-             jae  else_E
2115
-
2116
-                cmp  eax, dword ptr[edx + 5*4 + 4] /* if (N<Dec->DecodeLen[5]) */
2117
-                jae  else_3
2118
-                mov  I, 5                         /*  I=5; */
2119
-                jmp  next_3
2120
-              else_3:                             /* else */
2121
-                mov  I, 6                         /*  I=6; */
2122
-              next_3:
2123
-
2124
-             jmp  next_E
2125
-           else_E:                             /* else */
2126
-
2127
-                cmp  eax, dword ptr[edx + 7*4 + 4] /* if (N<Dec->DecodeLen[7]) */
2128
-                jae  else_4
2129
-                mov  I, 7                         /*  I=7; */
2130
-                jmp  next_4
2131
-              else_4:                             /* else */
2132
-                mov  I, 8                         /*  I=8; */
2133
-              next_4:
2134
-
2135
-           next_E:
2136
-
2137
-           next_F:
2138
-
2139
-          jmp  next_G
2140
-        else_G:
2141
-
2142
-          cmp  eax, dword ptr[edx + 12*4 + 4] /* if (N<Dec->DecodeLen[12]) */
2143
-          jae  else_D
2144
-
2145
-             cmp  eax, dword ptr[edx + 10*4 + 4] /* if (N<Dec->DecodeLen[10]) */
2146
-             jae  else_B
2147
-
2148
-                cmp  eax, dword ptr[edx + 9*4 + 4] /* if (N<Dec->DecodeLen[9]) */
2149
-                jae  else_5
2150
-                mov  I, 9                         /*  I=9; */
2151
-                jmp  next_5
2152
-              else_5:                             /* else */
2153
-                mov  I, 10                         /*  I=10; */
2154
-              next_5:
2155
-
2156
-             jmp  next_B
2157
-           else_B:                             /* else */
2158
-
2159
-                cmp  eax, dword ptr[edx + 11*4 + 4] /* if (N<Dec->DecodeLen[11]) */
2160
-                jae  else_6
2161
-                mov  I, 11                         /*  I=11; */
2162
-                jmp  next_6
2163
-              else_6:                              /* else */
2164
-                mov  I, 12                         /*  I=12; */
2165
-              next_6:
2166
-
2167
-           next_B:
2168
-
2169
-
2170
-          jmp  next_D
2171
-        else_D:                             /* else */
2172
-
2173
-               cmp  eax, dword ptr[edx + 14*4 + 4] /* if (N<Dec->DecodeLen[14]) */
2174
-               jae  else_A
2175
-
2176
-                  cmp  eax, dword ptr[edx + 13*4 + 4] /* if (N<Dec->DecodeLen[13]) */
2177
-                  jae  else_7
2178
-                  mov  I, 13                         /*  I=13; */
2179
-                  jmp  next_7
2180
-                 else_7:                             /* else */
2181
-                  mov  I, 14                         /*  I=14; */
2182
-                 next_7:
2183
-
2184
-               jmp  next_A
2185
-              else_A:                             /* else */
2186
-               mov  I, 15                         /*  I=15; */
2187
-              next_A:
2188
-
2189
-        next_D:
2190
-    next_G:
2191
-}
2192
-#else
2193
- __asm__ __volatile__ (
2194
-     "andl $0xFFFFFFFE, %%eax"
2195
-"      movl %%eax, %1"
2196
-"          cmpl 8*4(%%edx), %%eax /* 5379 */"
2197
-"          jae  else_G"
2198
-""
2199
-"             cmpl 4*4(%%edx), %%eax"
2200
-"             jae  else_F"
2201
-""
2202
-"                cmpl 2*4(%%edx), %%eax"
2203
-"                jae  else_C"
2204
-""
2205
-"                   cmpl 1*4(%%edx), %%eax"
2206
-""
2207
-"                   jae  else_1"
2208
-"                   movl $1, %0"
2209
-"                   jmp  next_1"
2210
-"                 else_1:       "
2211
-"                   movl  $2, %0"
2212
-"                 next_1:"
2213
-"                "
2214
-"                jmp  next_C"
2215
-"              else_C:          "
2216
-""
2217
-"                   cmpl 3*4(%%edx), %%eax "
2218
-"                   jae  else_2"
2219
-"                   movl  $3, %0"
2220
-"                   jmp  next_2"
2221
-"                 else_2:       "
2222
-"                   movl  $4, %0"
2223
-"                 next_2:"
2224
-""
2225
-"              next_C:          "
2226
-""
2227
-"             jmp  next_F"
2228
-"           else_F:"
2229
-""
2230
-"             cmpl 6*4(%%edx), %%eax"
2231
-"             jae  else_E"
2232
-""
2233
-"                cmpl 5*4(%%edx), %%eax"
2234
-"                jae  else_3"
2235
-"                movl  $5, %0   "
2236
-"                jmp  next_3"
2237
-"              else_3:          "
2238
-"                movl  $6, %0   "
2239
-"              next_3:"
2240
-""
2241
-"             jmp  next_E"
2242
-"           else_E:             "
2243
-""
2244
-"                cmpl 7*4(%%edx), %%eax"
2245
-"                jae  else_4"
2246
-"                movl  $7, %0   "
2247
-"                jmp  next_4"
2248
-"              else_4:          "
2249
-"                movl  $8, %0   "
2250
-"              next_4:"
2251
-""
2252
-"           next_E:"
2253
-""
2254
-"           next_F:"
2255
-""
2256
-"          jmp  next_G"
2257
-"        else_G:"
2258
-""
2259
-"          cmpl 12*4(%%edx), %%eax"
2260
-"          jae  else_D"
2261
-""
2262
-"             cmpl 10*4(%%edx), %%eax"
2263
-"             jae  else_B"
2264
-""
2265
-"                cmpl 9*4(%%edx), %%eax"
2266
-"                jae  else_5"
2267
-"                movl  $9, %0   "
2268
-"                jmp  next_5"
2269
-"              else_5:          "
2270
-"                movl  $10, %0  "
2271
-"              next_5:"
2272
-""
2273
-"             jmp  next_B"
2274
-"           else_B:             "
2275
-""
2276
-"                cmpl 11*4(%%edx), %%eax"
2277
-" "
2278
-"                jae  else_6"
2279
-"                movl  $11, %0  "
2280
-"                jmp  next_6"
2281
-"              else_6:          "
2282
-"                movl  $12, %0  "
2283
-"              next_6:"
2284
-""
2285
-"           next_B:"
2286
-"      "
2287
-"        "
2288
-"          jmp  next_D"
2289
-"        else_D:                "
2290
-""
2291
-"               cmpl 14*4(%%edx), %%eax"
2292
-"               jae  else_A"
2293
-""
2294
-"                  cmpl 13*4(%%edx), %%eax"
2295
-"                  jae  else_7"
2296
-"                  movl  $13, %0"
2297
-"                  jmp  next_7"
2298
-"                 else_7:       "
2299
-"                  movl  $14, %0"
2300
-"                 next_7:"
2301
-""
2302
-"               jmp  next_A"
2303
-"              else_A:          "
2304
-"               movl  $15, %0   "
2305
-"              next_A:"
2306
-"          "
2307
-"        next_D:                             "
2308
-"    next_G:"
2309
-     : "=g" (I), "=r"(N)
2310
-     : "eax" ((long)BitField), "edx"((long)Deco->DecodeLen)
2311
-      : "memory"
2312
-     );
2313
-#endif /* #ifdef _WIN_32 ... #elif defined _X86_ASM_ */
2314
-
2315
-#else
2316
-  N=BitField & 0xFFFE;
2317
-  if (N<Deco->DecodeLen[8])  {
2318
-    if (N<Deco->DecodeLen[4]) {
2319
-      if (N<Deco->DecodeLen[2]) {
2320
-        if (N<Deco->DecodeLen[1])
2321
-          I=1;
2322
-        else
2323
-          I=2;
2324
-      } else {
2325
-        if (N<Deco->DecodeLen[3])
2326
-          I=3;
2327
-        else
2328
-          I=4;
2329
-      }
2330
-    } else {
2331
-      if (N<Deco->DecodeLen[6])  {
2332
-        if (N<Deco->DecodeLen[5])
2333
-          I=5;
2334
-        else
2335
-          I=6;
2336
-      } else {
2337
-        if (N<Deco->DecodeLen[7])
2338
-          I=7;
2339
-        else
2340
-          I=8;
2341
-      }
2342
-   }
2343
-  } else {
2344
-    if (N<Deco->DecodeLen[12]) {
2345
-      if (N<Deco->DecodeLen[10]) {
2346
-        if (N<Deco->DecodeLen[9])
2347
-          I=9;
2348
-        else
2349
-          I=10;
2350
-      } else {
2351
-        if (N<Deco->DecodeLen[11])
2352
-          I=11;
2353
-        else
2354
-          I=12;
2355
-      }
2356
-    } else {
2357
-      if (N<Deco->DecodeLen[14]) {
2358
-        if (N<Deco->DecodeLen[13])
2359
-          I=13;
2360
-        else
2361
-          I=14;
2362
-
2363
-      } else {
2364
-          I=15;
2365
-      }
2366
-    }
2367
-
2368
-  }
2369
-#endif
2370
-
2371
-  AddBits(I);
2372
-  if ((N=Deco->DecodePos[I]+((N-Deco->DecodeLen[I-1])>>(16-I)))>=Deco->MaxNum)
2373
-      N=0;
2374
-  Number=Deco->DecodeNum[N];
2375
-}
2376
-
2377
-
2378
-void UnpInitData()
2379
-{
2380
-  InAddr=InBit=0;
2381
-  if (!(NewLhd.Flags & LHD_SOLID))
2382
-  {
2383
-    ChannelDelta=CurChannel=0;
2384
-
2385
-#ifdef _USE_ASM
2386
-
2387
-#ifdef _WIN_32                              /* Win32 with VisualC           */
2388
-
2389
-    __asm {
2390
-        push edi
2391
-        push eax
2392
-        push ecx
2393
-
2394
-        cld                                 /* increment EDI and ESI        */
2395
-        mov  al, 0x00
2396
-        mov  ecx, SIZE AudV
2397
-        mov  edi, Offset AudV
2398
-        rep  stosb                          /* clear memory                 */
2399
-
2400
-        mov  ecx, SIZE OldDist
2401
-        mov  edi, Offset OldDist
2402
-        rep  stosb                          /* clear memory                 */
2403
-
2404
-        mov  ecx, SIZE UnpOldTable
2405
-        mov  edi, Offset UnpOldTable
2406
-        rep  stosb                          /* clear memory                 */
2407
-
2408
-        pop  ecx
2409
-        pop  eax
2410
-        pop  edi
2411
-
2412
-
2413
-        mov  [OldDistPtr], 0
2414
-        mov  [LastDist], 0
2415
-        mov  [LastLength], 0
2416
-        mov  [UnpPtr], 0
2417
-        mov  [WrPtr], 0
2418
-        mov  [OldDistPtr], 0
2419
-        mov  [LastLength], 0
2420
-        mov  [LastDist], 0
2421
-        mov  [UnpPtr], 0
2422
-        mov  [WrPtr], 0
2423
-
2424
-    }
2425
-    memset(UnpBuf,0,MAXWINSIZE);
2426
-
2427
-
2428
-#else                    /* unix/linux on i386 cpus */
2429
-    __asm__ __volatile (
2430
-"        cld                                 /* increment EDI and ESI        */"
2431
-"        movb $0x00, %%al"
2432
-"        movl %0, %%ecx"
2433
-"        movl %1, %%edi"
2434
-"        rep  "
2435
-"        stosb                              /* clear memory                 */"
2436
-""
2437
-"        movl %2, %%ecx"
2438
-"        mov  %3, %%edi"
2439
-"        rep  "
2440
-"        stosb                              /* clear memory                 */"
2441
-""
2442
-"        movl %4, %%ecx"
2443
-"        movl %5, %%edi"
2444
-"        rep  "
2445
-"        stosb                              /* clear memory                 */"
2446
-""
2447
-"        movl $0, (OldDistPtr)"
2448
-"        movl $0, (LastDist)"
2449
-"        movl $0, (LastLength)"
2450
-"        movl $0, (UnpPtr)"
2451
-"        movl $0, (WrPtr)"
2452
-"        movl $0, (OldDistPtr)"
2453
-"        movl $0, (LastLength)"
2454
-"        movl $0, (LastDist)"
2455
-"        movl $0, (UnpPtr)"
2456
-"        movl $0, (WrPtr)"
2457
-        :
2458
-        : "m" ((long)sizeof(AudV)),
2459
-          "m" ((long)AudV),
2460
-          "m" ((long)sizeof(OldDist)),
2461
-          "m" ((long)OldDist),
2462
-          "m" ((long)sizeof(UnpOldTable)),
2463
-          "m" ((long)UnpOldTable)
2464
-        : "memory", "edi", "eax", "ecx"
2465
-    );
2466
-    memset(UnpBuf,0,MAXWINSIZE);
2467
-#endif
2468
-
2469
-#else                                       /* unix/linux on non-i386 cpu  */
2470
-    memset(AudV,0,sizeof(AudV));
2471
-    memset(OldDist,0,sizeof(OldDist));
2472
-    OldDistPtr=0;
2473
-    LastDist=LastLength=0;
2474
-    memset(UnpBuf,0,MAXWINSIZE);
2475
-    memset(UnpOldTable,0,sizeof(UnpOldTable));
2476
-    UnpPtr=WrPtr=0;
2477
-#endif
2478
-
2479
-  }
2480
-}
2481
-
2482
-
2483
-UBYTE DecodeAudio(int Delta)
2484
-{
2485
-  struct AudioVariables *V;
2486
-  unsigned int Ch;
2487
-  unsigned int NumMinDif,MinDif;
2488
-  int PCh,I;
2489
-
2490
-  V=&AudV[CurChannel];
2491
-  V->ByteCount++;
2492
-  V->D4=V->D3;
2493
-  V->D3=V->D2;
2494
-  V->D2=V->LastDelta-V->D1;
2495
-  V->D1=V->LastDelta;
2496
-  PCh=8*V->LastChar+V->K1*V->D1+V->K2*V->D2+
2497
-           V->K3*V->D3+V->K4*V->D4+V->K5*ChannelDelta;
2498
-  PCh=(PCh>>3) & 0xFF;
2499
-
2500
-  Ch=PCh-Delta;
2501
-
2502
-  I=((signed char)Delta)<<3;
2503
-
2504
-  V->Dif[0]+=abs(I);
2505
-  V->Dif[1]+=abs(I-V->D1);
2506
-  V->Dif[2]+=abs(I+V->D1);
2507
-  V->Dif[3]+=abs(I-V->D2);
2508
-  V->Dif[4]+=abs(I+V->D2);
2509
-  V->Dif[5]+=abs(I-V->D3);
2510
-  V->Dif[6]+=abs(I+V->D3);
2511
-  V->Dif[7]+=abs(I-V->D4);
2512
-  V->Dif[8]+=abs(I+V->D4);
2513
-  V->Dif[9]+=abs(I-ChannelDelta);
2514
-  V->Dif[10]+=abs(I+ChannelDelta);
2515
-
2516
-  ChannelDelta=V->LastDelta=(signed char)(Ch-V->LastChar);
2517
-  V->LastChar=Ch;
2518
-
2519
-  if ((V->ByteCount & 0x1F)==0)
2520
-  {
2521
-    MinDif=V->Dif[0];
2522
-    NumMinDif=0;
2523
-    V->Dif[0]=0;
2524
-    for (I=1;(unsigned int)I<sizeof(V->Dif)/sizeof(V->Dif[0]);I++)
2525
-    {
2526
-      if (V->Dif[I]<MinDif)
2527
-      {
2528
-        MinDif=V->Dif[I];
2529
-        NumMinDif=I;
2530
-      }
2531
-      V->Dif[I]=0;
2532
-    }
2533
-    switch(NumMinDif)
2534
-    {
2535
-      case 1:
2536
-        if (V->K1>=-16)
2537
-          V->K1--;
2538
-        break;
2539
-      case 2:
2540
-        if (V->K1<16)
2541
-          V->K1++;
2542
-        break;
2543
-      case 3:
2544
-        if (V->K2>=-16)
2545
-          V->K2--;
2546
-        break;
2547
-      case 4:
2548
-        if (V->K2<16)
2549
-          V->K2++;
2550
-        break;
2551
-      case 5:
2552
-        if (V->K3>=-16)
2553
-          V->K3--;
2554
-        break;
2555
-      case 6:
2556
-        if (V->K3<16)
2557
-          V->K3++;
2558
-        break;
2559
-      case 7:
2560
-        if (V->K4>=-16)
2561
-          V->K4--;
2562
-        break;
2563
-      case 8:
2564
-        if (V->K4<16)
2565
-          V->K4++;
2566
-        break;
2567
-      case 9:
2568
-        if (V->K5>=-16)
2569
-          V->K5--;
2570
-        break;
2571
-      case 10:
2572
-        if (V->K5<16)
2573
-          V->K5++;
2574
-        break;
2575
-    }
2576
-  }
2577
-  return((UBYTE)Ch);
2578
-}
2579
-
2580
-
2581
-
2582
-
2583
-
2584
-
2585
-
2586
-/* ***************************************************
2587
- * ** CRCCrypt Code - decryption engine starts here **
2588
- * ***************************************************/
2589
-
2590
-
2591
-#define NROUNDS 32
2592
-
2593
-#define rol(x,n)  (((x)<<(n)) | ((x)>>(8*sizeof(x)-(n))))
2594
-#define ror(x,n)  (((x)>>(n)) | ((x)<<(8*sizeof(x)-(n))))
2595
-
2596
-#define substLong(t) ( (UDWORD)SubstTable[(int)t&255] | \
2597
-           ((UDWORD)SubstTable[(int)(t>> 8)&255]<< 8) | \
2598
-           ((UDWORD)SubstTable[(int)(t>>16)&255]<<16) | \
2599
-           ((UDWORD)SubstTable[(int)(t>>24)&255]<<24) )
2600
-
2601
-
2602
-static UDWORD CRCTab[256];
2603
-
2604
-static UBYTE SubstTable[256];
2605
-static const UBYTE InitSubstTable[256]={
2606
-  215, 19,149, 35, 73,197,192,205,249, 28, 16,119, 48,221,  2, 42,
2607
-  232,  1,177,233, 14, 88,219, 25,223,195,244, 90, 87,239,153,137,
2608
-  255,199,147, 70, 92, 66,246, 13,216, 40, 62, 29,217,230, 86,  6,
2609
-   71, 24,171,196,101,113,218,123, 93, 91,163,178,202, 67, 44,235,
2610
-  107,250, 75,234, 49,167,125,211, 83,114,157,144, 32,193,143, 36,
2611
-  158,124,247,187, 89,214,141, 47,121,228, 61,130,213,194,174,251,
2612
-   97,110, 54,229,115, 57,152, 94,105,243,212, 55,209,245, 63, 11,
2613
-  164,200, 31,156, 81,176,227, 21, 76, 99,139,188,127, 17,248, 51,
2614
-  207,120,189,210,  8,226, 41, 72,183,203,135,165,166, 60, 98,  7,
2615
-  122, 38,155,170, 69,172,252,238, 39,134, 59,128,236, 27,240, 80,
2616
-  131,  3, 85,206,145, 79,154,142,159,220,201,133, 74, 64, 20,129,
2617
-  224,185,138,103,173,182, 43, 34,254, 82,198,151,231,180, 58, 10,
2618
-  118, 26,102, 12, 50,132, 22,191,136,111,162,179, 45,  4,148,108,
2619
-  161, 56, 78,126,242,222, 15,175,146, 23, 33,241,181,190, 77,225,
2620
-    0, 46,169,186, 68, 95,237, 65, 53,208,253,168,  9, 18,100, 52,
2621
-  116,184,160, 96,109, 37, 30,106,140,104,150,  5,204,117,112, 84
2622
-};
2623
-
2624
-static UDWORD Key[4];
2625
-
2626
-
2627
-static void EncryptBlock(UBYTE *Buf)
2628
-{
2629
-  int I;
2630
-
2631
-  UDWORD A,B,C,D,T,TA,TB;
2632
-#ifdef NON_INTEL_BYTE_ORDER
2633
-  A=((UDWORD)Buf[0]|((UDWORD)Buf[1]<<8)|((UDWORD)Buf[2]<<16)|
2634
-      ((UDWORD)Buf[3]<<24))^Key[0];
2635
-  B=((UDWORD)Buf[4]|((UDWORD)Buf[5]<<8)|((UDWORD)Buf[6]<<16)|
2636
-      ((UDWORD)Buf[7]<<24))^Key[1];
2637
-  C=((UDWORD)Buf[8]|((UDWORD)Buf[9]<<8)|((UDWORD)Buf[10]<<16)|
2638
-      ((UDWORD)Buf[11]<<24))^Key[2];
2639
-  D=((UDWORD)Buf[12]|((UDWORD)Buf[13]<<8)|((UDWORD)Buf[14]<<16)|
2640
-      ((UDWORD)Buf[15]<<24))^Key[3];
2641
-#else
2642
-  UDWORD *BufPtr;
2643
-  BufPtr=(UDWORD *)Buf;
2644
-  A=BufPtr[0]^Key[0];
2645
-  B=BufPtr[1]^Key[1];
2646
-  C=BufPtr[2]^Key[2];
2647
-  D=BufPtr[3]^Key[3];
2648
-#endif
2649
-  for(I=0;I<NROUNDS;I++)
2650
-  {
2651
-    T=((C+rol(D,11))^Key[I&3]);
2652
-    TA=A^substLong(T);
2653
-    T=((D^rol(C,17))+Key[I&3]);
2654
-    TB=B^substLong(T);
2655
-    A=C;
2656
-    B=D;
2657
-    C=TA;
2658
-    D=TB;
2659
-  }
2660
-#ifdef NON_INTEL_BYTE_ORDER
2661
-  C^=Key[0];
2662
-  Buf[0]=(UBYTE)C;
2663
-  Buf[1]=(UBYTE)(C>>8);
2664
-  Buf[2]=(UBYTE)(C>>16);
2665
-  Buf[3]=(UBYTE)(C>>24);
2666
-  D^=Key[1];
2667
-  Buf[4]=(UBYTE)D;
2668
-  Buf[5]=(UBYTE)(D>>8);
2669
-  Buf[6]=(UBYTE)(D>>16);
2670
-  Buf[7]=(UBYTE)(D>>24);
2671
-  A^=Key[2];
2672
-  Buf[8]=(UBYTE)A;
2673
-  Buf[9]=(UBYTE)(A>>8);
2674
-  Buf[10]=(UBYTE)(A>>16);
2675
-  Buf[11]=(UBYTE)(A>>24);
2676
-  B^=Key[3];
2677
-  Buf[12]=(UBYTE)B;
2678
-  Buf[13]=(UBYTE)(B>>8);
2679
-  Buf[14]=(UBYTE)(B>>16);
2680
-  Buf[15]=(UBYTE)(B>>24);
2681
-#else
2682
-  BufPtr[0]=C^Key[0];
2683
-  BufPtr[1]=D^Key[1];
2684
-  BufPtr[2]=A^Key[2];
2685
-  BufPtr[3]=B^Key[3];
2686
-#endif
2687
-  UpdKeys(Buf);
2688
-}
2689
-
2690
-
2691
-void DecryptBlock(UBYTE *Buf)
2692
-{
2693
-  int I;
2694
-  UBYTE InBuf[16];
2695
-  UDWORD A,B,C,D,T,TA,TB;
2696
-#ifdef NON_INTEL_BYTE_ORDER
2697
-  A=((UDWORD)Buf[0]|((UDWORD)Buf[1]<<8)|((UDWORD)Buf[2]<<16)|
2698
-      ((UDWORD)Buf[3]<<24))^Key[0];
2699
-  B=((UDWORD)Buf[4]|((UDWORD)Buf[5]<<8)|((UDWORD)Buf[6]<<16)|
2700
-      ((UDWORD)Buf[7]<<24))^Key[1];
2701
-  C=((UDWORD)Buf[8]|((UDWORD)Buf[9]<<8)|((UDWORD)Buf[10]<<16)|
2702
-      ((UDWORD)Buf[11]<<24))^Key[2];
2703
-  D=((UDWORD)Buf[12]|((UDWORD)Buf[13]<<8)|((UDWORD)Buf[14]<<16)|
2704
-      ((UDWORD)Buf[15]<<24))^Key[3];
2705
-#else
2706
-  UDWORD *BufPtr;
2707
-  BufPtr=(UDWORD *)Buf;
2708
-  A=BufPtr[0]^Key[0];                       /* xxx may be this can be       */
2709
-  B=BufPtr[1]^Key[1];                       /* optimized in assembler       */
2710
-  C=BufPtr[2]^Key[2];
2711
-  D=BufPtr[3]^Key[3];
2712
-#endif
2713
-  memcpy(InBuf,Buf,sizeof(InBuf));
2714
-  for(I=NROUNDS-1;I>=0;I--)
2715
-  {
2716
-    T=((C+rol(D,11))^Key[I&3]);
2717
-    TA=A^substLong(T);
2718
-    T=((D^rol(C,17))+Key[I&3]);
2719
-    TB=B^substLong(T);
2720
-    A=C;
2721
-    B=D;
2722
-    C=TA;
2723
-    D=TB;
2724
-  }
2725
-#ifdef NON_INTEL_BYTE_ORDER
2726
-  C^=Key[0];
2727
-  Buf[0]=(UBYTE)C;
2728
-  Buf[1]=(UBYTE)(C>>8);
2729
-  Buf[2]=(UBYTE)(C>>16);
2730
-  Buf[3]=(UBYTE)(C>>24);
2731
-  D^=Key[1];
2732
-  Buf[4]=(UBYTE)D;
2733
-  Buf[5]=(UBYTE)(D>>8);
2734
-  Buf[6]=(UBYTE)(D>>16);
2735
-  Buf[7]=(UBYTE)(D>>24);
2736
-  A^=Key[2];
2737
-  Buf[8]=(UBYTE)A;
2738
-  Buf[9]=(UBYTE)(A>>8);
2739
-  Buf[10]=(UBYTE)(A>>16);
2740
-  Buf[11]=(UBYTE)(A>>24);
2741
-  B^=Key[3];
2742
-  Buf[12]=(UBYTE)B;
2743
-  Buf[13]=(UBYTE)(B>>8);
2744
-  Buf[14]=(UBYTE)(B>>16);
2745
-  Buf[15]=(UBYTE)(B>>24);
2746
-#else
2747
-  BufPtr[0]=C^Key[0];
2748
-  BufPtr[1]=D^Key[1];
2749
-  BufPtr[2]=A^Key[2];
2750
-  BufPtr[3]=B^Key[3];
2751
-#endif
2752
-  UpdKeys(InBuf);
2753
-}
2754
-
2755
-
2756
-void UpdKeys(UBYTE *Buf)
2757
-{
2758
-  int I;
2759
-  for (I=0;I<16;I+=4)
2760
-  {
2761
-    Key[0]^=CRCTab[Buf[I]];                 /* xxx may be I'll rewrite this */
2762
-    Key[1]^=CRCTab[Buf[I+1]];               /* in asm for speedup           */
2763
-    Key[2]^=CRCTab[Buf[I+2]];
2764
-    Key[3]^=CRCTab[Buf[I+3]];
2765
-  }
2766
-}
2767
-
2768
-static void SetCryptKeys(char *NewPassword)
2769
-{
2770
-  unsigned int I,J,K,PswLength;
2771
-  unsigned char N1,N2;
2772
-  unsigned char Psw[256];
2773
-
2774
-#if !defined _USE_ASM
2775
-  UBYTE Ch;
2776
-#endif
2777
-
2778
-  SetOldKeys(NewPassword);
2779
-
2780
-  Key[0]=0xD3A3B879L;
2781
-  Key[1]=0x3F6D12F7L;
2782
-  Key[2]=0x7515A235L;
2783
-  Key[3]=0xA4E7F123L;
2784
-  memset(Psw,0,sizeof(Psw));
2785
-  strcpy((char *)Psw,NewPassword);
2786
-  PswLength=strlen(NewPassword);
2787
-  memcpy(SubstTable,InitSubstTable,sizeof(SubstTable));
2788
-
2789
-  for (J=0;J<256;J++)
2790
-    for (I=0;I<PswLength;I+=2)
2791
-    {
2792
-      N2=(unsigned char)CRCTab[(Psw[I+1]+J)&0xFF];
2793
-      for (K=1, N1=(unsigned char)CRCTab[(Psw[I]-J)&0xFF];
2794
-           (N1!=N2);
2795
-           N1++, K++)
2796
-          {
2797
-#ifdef _USE_ASM
2798
-
2799
-#ifdef _WIN_32
2800
-          __asm {
2801
-
2802
-                    mov ebx, Offset SubstTable
2803
-                    mov edx, ebx
2804
-
2805
-                    xor ecx, ecx            /* read SubstTable[N1]... */
2806
-                    mov cl, N1
2807
-                    add ebx, ecx
2808
-                    mov al, byte ptr[ebx]
2809
-
2810
-                    mov cl, N1              /* read SubstTable[(N1+I+K)&0xFF]... */
2811
-                    add ecx, I
2812
-                    add ecx, K
2813
-                    and ecx, 0xFF
2814
-                    add edx, ecx
2815
-                    mov ah, byte ptr[edx]
2816
-
2817
-                    mov  byte ptr[ebx], ah  /* and write back */
2818
-                    mov  byte ptr[edx], al
2819
-
2820
-               }
2821
-#else
2822
-                     __asm__ __volatile__ (
2823
-"                    xorl %%ecx, %%ecx"
2824
-"                    movl %2, %%ecx                     /* ecx = N1 */"
2825
-"                    mov %%ebx, %%edx"
2826
-"                    addl %%ecx, %%ebx"
2827
-""
2828
-"                    addl %0, %%ecx"
2829
-"                    addl %1, %%ecx"
2830
-"                    andl $0x000000FF, %%ecx"
2831
-"                    addl %%ecx, %%edx"
2832
-"                    "
2833
-"                    movb (%%ebx), %%al"
2834
-"                    movb (%%edx), %%ah"
2835
-""
2836
-"                    movb  %%ah, (%%ebx)     /* and write back */"
2837
-"                    movb  %%al, (%%edx)"
2838
-                    : : "g" ((long)I),
2839
-                        "g" ((long)K),
2840
-                        "g" ((long)N1),
2841
-                        "ebx"((long)SubstTable)
2842
-                    : "ecx", "edx"
2843
-
2844
-              );
2845
-#endif
2846
-
2847
-#else
2848
-            /* Swap(&SubstTable[N1],&SubstTable[(N1+I+K)&0xFF]);            */
2849
-             Ch=SubstTable[N1];
2850
-             SubstTable[N1]=SubstTable[(N1+I+K)&0xFF];
2851
-             SubstTable[(N1+I+K)&0xFF]=Ch;
2852
-#endif
2853
-          }
2854
-    }
2855
-  for (I=0;I<PswLength;I+=16)
2856
-    EncryptBlock(&Psw[I]);
2857
-}
2858
-
2859
-
2860
-void SetOldKeys(char *NewPassword)
2861
-{
2862
-  UDWORD PswCRC;
2863
-  UBYTE Ch;
2864
-  PswCRC=CalcCRC32(0xFFFFFFFFL,(UBYTE*)NewPassword,strlen(NewPassword));
2865
-  OldKey[0]=(UWORD)PswCRC;
2866
-  OldKey[1]=(UWORD)(PswCRC>>16);
2867
-  OldKey[2]=OldKey[3]=0;
2868
-  PN1=PN2=PN3=0;
2869
-  while ((Ch=*NewPassword)!=0)
2870
-  {
2871
-    PN1+=Ch;
2872
-    PN2^=Ch;
2873
-    PN3+=Ch;
2874
-    PN3=(UBYTE)rol(PN3,1);
2875
-    OldKey[2]^=((UWORD)(Ch^CRCTab[Ch]));
2876
-    OldKey[3]+=((UWORD)(Ch+(CRCTab[Ch]>>16)));
2877
-    NewPassword++;
2878
-  }
2879
-}
2880
-
2881
-static short crcInitialized = 0;
2882
-void InitCRC(void)
2883
-{
2884
-  int I, J;
2885
-  UDWORD C;
2886
-  if (crcInitialized) return;
2887
-
2888
-  cli_dbgmsg("%s:%d:%s Initialize CRC table\n", __FILE__, __LINE__, "InitCRC");
2889
-  for (I=0;I<256;I++)
2890
-  {
2891
-    for (C=I,J=0;J<8;J++)
2892
-      C=(C & 1) ? (C>>1)^0xEDB88320L : (C>>1);
2893
-    CRCTab[I]=C;
2894
-  }
2895
-  crcInitialized = 1;
2896
-}
2897
-
2898
-
2899
-static UDWORD CalcCRC32(UDWORD StartCRC,UBYTE *Addr,UDWORD Size)
2900
-{
2901
-  unsigned int I;
2902
-  for (I=0; I<Size; I++)
2903
-    StartCRC = CRCTab[(UBYTE)StartCRC ^ Addr[I]] ^ (StartCRC >> 8);
2904
-  return(StartCRC);
2905
-}
2906
-
2907
-
2908
-/* **************************************************************************
2909
- ****************************************************************************
2910
- ****************************************************************************
2911
- ************************************************************************** */
2912
-
2913
-
2914
-
2915
-
2916
-
2917
-
2918
-
2919
-
2920
-
2921
-
2922
-
2923
-
2924
-
2925
-
2926
-
2927
-
2928
-
2929
-
2930
-
2931
-
2932
-
2933
-
2934
-
2935
-
2936
-
2937
-/* **************************************************************************
2938
- ****************************************************************************
2939
- ****************************************************************************
2940
- ****************************************************************************
2941
- *******                                                              *******
2942
- *******                                                              *******
2943
- *******                                                              *******
2944
- *******              D E B U G    F U N C T I O N S                  *******
2945
- *******                                                              *******
2946
- *******                                                              *******
2947
- *******                                                              *******
2948
- ****************************************************************************
2949
- ****************************************************************************
2950
- ****************************************************************************
2951
- ************************************************************************** */
2952
-#ifdef _DEBUG_LOG
2953
-
2954
-
2955
-/* -- global stuff -------------------------------------------------------- */
2956
-char  log_file_name[256];                   /* file name for the log file   */
2957
-DWORD debug_start_time;                     /* starttime of debug           */
2958
-BOOL  debug_started = FALSE;                /* debug_log writes only if     */
2959
-                                            /* this is TRUE                 */
2960
-/* ------------------------------------------------------------------------ */
2961
-
2962
-
2963
-/* -- global functions ---------------------------------------------------- */
2964
-void debug_init_proc(char *file_name)
2965
-/* Create/Rewrite a log file                                                */
2966
-{
2967
-  FILE *fp;
2968
-  char date[] = __DATE__;
2969
-  char time[] = __TIME__;
2970
-
2971
-  debug_start_time = GetTickCount();        /* get start time               */
2972
-  strcpy(log_file_name, file_name);         /* save file name               */
2973
-
2974
-  if((fp = fopen(log_file_name, CREATETEXT)) != NULL)
2975
-  {
2976
-    debug_started = TRUE;                   /* enable debug                 */
2977
-    fprintf(fp, "Debug log of UniquE's RARFileLib\n"\
2978
-                "~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~\n");
2979
-    fprintf(fp, "(executable compiled on %s at %s)\n\n", date, time);
2980
-    fclose(fp);
2981
-  }
2982
-}
2983
-
2984
-
2985
-void debug_log_proc(char *text, char *sourcefile, int sourceline)
2986
-/* add a line to the log file                                               */
2987
-{
2988
-  FILE *fp;
2989
-
2990
-  if(debug_started == FALSE) return;        /* exit if not initialized      */
2991
-
2992
-  if((fp = fopen(log_file_name, APPENDTEXT)) != NULL) /* append to logfile  */
2993
-
2994
-  {
2995
-    fprintf(fp, " %8u ms (line %u in %s):\n              - %s\n",
2996
-            (unsigned int)(GetTickCount() - debug_start_time),
2997
-            sourceline, sourcefile, text);
2998
-    fclose(fp);
2999
-  }
3000
-}
3001
-
3002
-/* ------------------------------------------------------------------------ */
3003
-#endif
3004
-/* **************************************************************************
3005
- ****************************************************************************
3006
- ****************************************************************************
3007
- ************************************************************************** */
3008
-
3009
-
3010
-/* end of file urarlib.c */
3011
diff -ruN clamav-0.84.orig/libclamav/unrarlib.h clamav-0.84/libclamav/unrarlib.h
3012
--- clamav-0.84.orig/libclamav/unrarlib.h	2005-04-20 03:33:17.000000000 +0400
3013
+++ clamav-0.84/libclamav/unrarlib.h	2005-05-04 02:12:02.551691792 +0400
3014
@@ -1,205 +1,22 @@
3015
-/* ***************************************************************************
3016
- **
3017
- **  This file is part of the UniquE RAR File Library.
3018
- **
3019
- **  Copyright (C) 2000-2002 by Christian Scheurer (www.ChristianScheurer.ch)
3020
- **  UNIX port copyright (c) 2000-2002 by Johannes Winkelmann (jw@tks6.net)
3021
- **
3022
- **  The contents of this file are subject to the UniquE RAR File Library
3023
- **  License (the "unrarlib-license.txt"). You may not use this file except
3024
- **  in compliance with the License. You may obtain a copy of the License
3025
- **  at http://www.unrarlib.org/license.html.
3026
- **  Software distributed under the License is distributed on an "AS IS"
3027
- **  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied warranty.
3028
- **
3029
- **  Alternatively, the contents of this file may be used under the terms
3030
- **  of the GNU General Public License Version 2 or later (the "GPL"), in
3031
- **  which case the provisions of the GPL are applicable instead of those
3032
- **  above. If you wish to allow use of your version of this file only
3033
- **  under the terms of the GPL and not to allow others to use your version
3034
- **  of this file under the terms of the UniquE RAR File Library License,
3035
- **  indicate your decision by deleting the provisions above and replace
3036
- **  them with the notice and other provisions required by the GPL. If you
3037
- **  do not delete the provisions above, a recipient may use your version
3038
- **  of this file under the terms of the GPL or the UniquE RAR File Library
3039
- **  License.
3040
- **
3041
- ************************************************************************** */
3042
-
3043
-/* include file for the "UniquE RAR File Library"  */
3044
-/* (C) 2000-2002 by Christian Scheurer aka. UniquE */
3045
-/* multi-OS version (Win32, Linux and SUN)         */
3046
-
3047
-#ifndef __URARLIB_H
3048
-#define __URARLIB_H
3049
-
3050
-#ifdef __cplusplus
3051
-extern "C"
3052
-{
3053
-#endif
3054
-
3055
-
3056
-/* ************************************************************************ */
3057
-/* ************************************************************************ */
3058
-/* **                                                                    ** */
3059
-/* **   CONFIGURATION of the UniquE RAR FileLib                          ** */
3060
-/* **   ==> you may change the setting for the lib HERE!                 ** */
3061
-/* **                                                                    ** */
3062
-/* ************************************************************************ */
3063
-/* ************************************************************************ */
3064
-
3065
-
3066
-/* #define _DEBUG_LOG */                          /* generate debug messages      */
3067
-
3068
-#define _DO_CRC32_CHECK                     /* perform cyclical redundancy  */
3069
-                                            /* check (CRC32) - disable this */
3070
-                                            /* for a little speed-up        */
3071
-/*#define _USE_ASM*/                            /*
3072
-                                             * enable assembly extensions
3073
-                                             * x86 cpus.
3074
-                                             */
3075
-
3076
-/*#define _USE_MEMORY_TO_MEMORY_DECOMPRESSION*/ /* read file from memory or a   */
3077
-                                            /* resource instead of reading  */
3078
-                                            /* from a file. NOTE: you wont't*/
3079
-                                            /*  be able to decompress from  */
3080
-                                            /*  file if you enable this     */
3081
-                                            /*  option!                     */
3082
-
3083
-
3084
-#ifdef WIN32                                /* autodetect Win32 and Linux   */
3085
-#define _WIN_32                             /* Win32 with VisualC           */
3086
-#define _DEBUG_LOG_FILE "C:\\temp\\debug_unrar.txt" /* log file path        */
3087
-#else
3088
-#define _UNIX                               /* Linux or Unix with GCC       */
3089
-#define _DEBUG_LOG_FILE "/tmp/debug_unrar.txt" /* log file path             */
3090
-/*#define NON_INTEL_BYTE_ORDER*/               /* GCC on motorola systems    */
3091
-
3092
-#endif
3093
-
3094
-/* ------------------------------------------------------------------------ */
3095
-
3096
-/* detected by clamav/configure */
3097
-#if 1 - WORDS_BIGENDIAN
3098
-#define NON_INTEL_BYTE_ORDER
3099
-#endif
3100
-
3101
-/* -- global type definitions --------------------------------------------- */
3102
-
3103
-#ifdef NON_INTEL_BYTE_ORDER
3104
-#ifdef _USE_ASM
3105
-#warning Disabling assembly because NON_INTEL_BYTE_ORDER is set
3106
-#undef _USE_ASM
3107
-#endif
3108
-#endif
3109
-
3110
-#ifdef _WIN_32
3111
-typedef unsigned char    UBYTE;             /* WIN32 definitions            */
3112
-typedef unsigned short   UWORD;
3113
-typedef unsigned long    UDWORD;
3114
-#endif
3115
-
3116
-#ifdef _UNIX                                /* LINUX/UNIX definitions       */
3117
-typedef unsigned char    UBYTE;
3118
-typedef unsigned short   UWORD;
3119
-typedef unsigned long    UDWORD;
3120
-#endif
3121
-
3122
-#define RAR_FENTRY_ATTR_DIRECTORY ( 0x10 | 0x4000 )
3123
-
3124
-/* This structure is used for listing archive content                       */
3125
-struct RAR20_archive_entry                  /* These infos about files are  */
3126
-{                                           /* stored in RAR v2.0 archives  */
3127
-  char   *Name;
3128
-  UWORD  NameSize;
3129
-  UDWORD PackSize;
3130
-  UDWORD UnpSize;
3131
-  UBYTE  HostOS;                            /* MSDOS=0,OS2=1,WIN32=2,UNIX=3 */
3132
-  UDWORD FileCRC;
3133
-  UDWORD FileTime;
3134
-  UBYTE  UnpVer;
3135
-  UBYTE  Method;
3136
-  UDWORD FileAttr;
3137
-  UWORD  Flags;
3138
-};
3139
-
3140
-typedef struct  archivelist                 /* used to list archives        */
3141
-{
3142
-  struct RAR20_archive_entry item;
3143
-  struct archivelist         *next;
3144
-} ArchiveList_struct;
3145
-
3146
-
3147
-#ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
3148
-typedef struct  memory_file                 /* used to decompress files in  */
3149
-{                                           /* memory                       */
3150
-  void                       *data;         /* pointer to the file data     */
3151
-  unsigned long              size;          /* total size of the file data  */
3152
-  unsigned long              offset;        /* offset within "memory-file"  */
3153
-} MemoryFile;
3154
-#endif
3155
-
3156
-/* -- global functions ---------------------------------------------------- */
3157
-
3158
-/* urarlib_get:
3159
- * decompresses and decrypt data from a RAR file to a buffer in system memory.
3160
+/*
3161
+ *  Copyright (C) 2004 McMCC <mcmcc@mail.ru>
3162
  *
3163
- *   input: *output         pointer to an empty char*. This pointer will show
3164
- *                          to the extracted data
3165
- *          *size           shows where to write the size of the decompressed
3166
- *                          file
3167
- *                          (**NOTE: URARLib _does_ memory allocation etc.!**)
3168
- *          *filename       pointer to string containing the file to decompress
3169
- *          *rarfile        pointer to a string with the full name and path of
3170
- *                          the RAR file or pointer to a RAR file in memory if
3171
- *                          memory-to-memory decompression is active.
3172
- *          *libpassword    pointer to a string with the password used to
3173
- *                          en-/decrypt the RAR
3174
- *   output: int            returns TRUE on success or FALSE on error
3175
- *                          (FALSE=0, TRUE=1)
3176
- */
3177
-
3178
-extern int urarlib_get(void  *output,
3179
-                       unsigned long *size,
3180
-                       char *filename,
3181
-                       int desc,
3182
-                       char *libpassword);
3183
-
3184
-
3185
-
3186
-/* urarlib_list:
3187
- * list the content of a RAR archive.
3188
+ *  Support check archives RAR v.3.x
3189
  *
3190
- *   input: *rarfile        pointer to a string with the full name and path of
3191
- *                          the RAR file or pointer to a RAR file in memory if
3192
- *                          memory-to-memory decompression is active.
3193
- *          *list           pointer to an ArchiveList_struct that can be
3194
- *                          filled with details about the archive
3195
- *                          to the extracted data
3196
- *   output: int            number of files/directories within archive
3197
- */
3198
-
3199
-extern int urarlib_list(int desc, ArchiveList_struct *list);
3200
-
3201
-
3202
-/* urarlib_freelist:
3203
- * (after the suggestion and code of Duy Nguyen, Sean O'Blarney
3204
- * and Johannes Winkelmann who independently wrote a patch)
3205
- * free the memory of a ArchiveList_struct created by urarlib_list.
3206
+ *  This program is free software; you can redistribute it and/or modify
3207
+ *  it under the terms of the GNU General Public License as published by
3208
+ *  the Free Software Foundation; either version 2 of the License, or
3209
+ *  (at your option) any later version.
3210
+ *
3211
+ *  This program is distributed in the hope that it will be useful,
3212
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
3213
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
3214
+ *  GNU General Public License for more details.
3215
+ *
3216
+ *  You should have received a copy of the GNU General Public License
3217
+ *  along with this program; if not, write to the Free Software
3218
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
3219
  *
3220
- *    input: *list          pointer to an ArchiveList_struct
3221
- *    output: -
3222
  */
3223
 
3224
-extern void urarlib_freelist(ArchiveList_struct *list);
3225
-
3226
-/* ------------------------------------------------------------------------ */
3227
-
3228
-
3229
-
3230
-#ifdef __cplusplus
3231
-}
3232
-#endif
3233
-
3234
-#endif
3235
-
3236
+int cli_unrar3(const char *dir, int desc);

Return to bug 86510