Browse code

make the code independent of external bzlib

git-svn: trunk@3060

Tomasz Kojm authored on 2007/05/23 22:53:29
Showing 5 changed files
... ...
@@ -1,3 +1,7 @@
1
+Wed May 23 15:14:44 CEST 2007 (tk)
2
+----------------------------------
3
+  * libclamav/nsis: make the code independent of external bzlib
4
+
1 5
 Mon May 21 20:48:00 EEST 2007 (edwin)
2 6
 ----------------------------------
3 7
   * libclamav/nsis/nsis_zlib.h: use _NSIS_ZLIB_H instead of _ZLIB_H
... ...
@@ -30,8 +30,6 @@
30 30
 #include "clamav-config.h"
31 31
 #endif
32 32
 
33
-#ifdef HAVE_BZLIB_H
34
-
35 33
 #include "bzlib_private.h"
36 34
 #include "others.h"
37 35
 
... ...
@@ -169,6 +167,20 @@ void makeMaps_d ( DState* s )
169 169
    lval = gPerm[zvec - gBase[zn]];                \
170 170
 }
171 171
 
172
+/*---------------------------------------------------*/
173
+
174
+inline static Int32 indexIntoF ( Int32 indx, Int32 *cftab )
175
+{
176
+   Int32 nb, na, mid;
177
+   nb = 0;
178
+   na = 256;
179
+   do {
180
+      mid = (nb + na) >> 1;
181
+      if (indx >= cftab[mid]) nb = mid; else na = mid;
182
+   }
183
+   while (na - nb != 1);
184
+   return nb;
185
+}
172 186
 
173 187
 /*---------------------------------------------------*/
174 188
 /* Return  True iff data corruption is discovered.
... ...
@@ -430,7 +442,39 @@ Bool unRLE_obuf_to_output_SMALL ( DState* s )
430 430
 
431 431
    }
432 432
 }
433
+/*---------------------------------------------------*/
434
+
435
+static void CreateDecodeTables ( Int32 *limit,
436
+                                Int32 *base,
437
+                                Int32 *perm,
438
+                                UChar *length,
439
+                                Int32 minLen,
440
+                                Int32 maxLen,
441
+                                Int32 alphaSize )
442
+{
443
+   Int32 pp, i, j, vec;
444
+
445
+   pp = 0;
446
+   for (i = minLen; i <= maxLen; i++)
447
+      for (j = 0; j < alphaSize; j++)
448
+         if (length[j] == i) { perm[pp] = j; pp++; };
449
+
450
+   for (i = 0; i < BZ_MAX_CODE_LEN; i++) base[i] = 0;
451
+   for (i = 0; i < alphaSize; i++) base[length[i]+1]++;
452
+
453
+   for (i = 1; i < BZ_MAX_CODE_LEN; i++) base[i] += base[i-1];
433 454
 
455
+   for (i = 0; i < BZ_MAX_CODE_LEN; i++) limit[i] = 0;
456
+   vec = 0;
457
+
458
+   for (i = minLen; i <= maxLen; i++) {
459
+      vec += (base[i+1] - base[i]);
460
+      limit[i] = vec-1;
461
+      vec <<= 1;
462
+   }
463
+   for (i = minLen + 1; i <= maxLen; i++)
464
+      base[i] = ((limit[i-1] + 1) << 1) - base[i];
465
+}
434 466
 
435 467
 /*---------------------------------------------------*/
436 468
 static Int32 BZ2_decompress ( DState* s )
... ...
@@ -676,7 +720,7 @@ static Int32 BZ2_decompress ( DState* s )
676 676
             if (s->len[t][i] > maxLen) maxLen = s->len[t][i];
677 677
             if (s->len[t][i] < minLen) minLen = s->len[t][i];
678 678
          }
679
-         BZ2_hbCreateDecodeTables ( 
679
+         CreateDecodeTables ( 
680 680
             &(s->limit[t][0]), 
681 681
             &(s->base[t][0]), 
682 682
             &(s->perm[t][0]), 
... ...
@@ -1106,5 +1150,3 @@ int BZ_API(nsis_BZ2_bzDecompressEnd)  ( nsis_bzstream *strm )
1106 1106
 /*-------------------------------------------------------------*/
1107 1107
 /*--- end                                           bzlib.c ---*/
1108 1108
 /*-------------------------------------------------------------*/
1109
-
1110
-#endif /* HAVE_BZLIB_H */
... ...
@@ -20,6 +20,10 @@
20 20
 #ifndef _BZLIB_PRIVATE_H
21 21
 #define _BZLIB_PRIVATE_H
22 22
 
23
+#if HAVE_CONFIG_H
24
+#include "clamav-config.h"
25
+#endif
26
+
23 27
 #include <stdlib.h>
24 28
 
25 29
 #ifndef BZ_NO_STDIO
... ...
@@ -262,26 +266,6 @@ typedef
262 262
    EState;
263 263
 
264 264
 
265
-
266
-/*-- externs for compression. --*/
267
-/* aCaB
268
-extern void 
269
-BZ2_blockSort ( EState* );
270
-
271
-extern void 
272
-BZ2_compressBlock ( EState*, Bool );
273
-
274
-extern void 
275
-BZ2_bsInitWrite ( EState* );
276
-
277
-extern void 
278
-BZ2_hbAssignCodes ( Int32*, UChar*, Int32, Int32, Int32 );
279
-
280
-extern void 
281
-BZ2_hbMakeCodeLengths ( UChar*, Int32*, Int32, Int32 );
282
-*/
283
-
284
-
285 265
 /*-- states for decompression. --*/
286 266
 
287 267
 #define BZ_X_IDLE        1
... ...
@@ -465,19 +449,9 @@ typedef
465 465
    (((UInt32)s->ll16[i]) | (GET_LL4(i) << 16))
466 466
 
467 467
 #define BZ_GET_SMALL(cccc)                            \
468
-      cccc = BZ2_indexIntoF ( s->tPos, s->cftab );    \
468
+      cccc = indexIntoF ( s->tPos, s->cftab );    \
469 469
       s->tPos = GET_LL(s->tPos);
470 470
 
471
-
472
-/*-- externs for decompression. --*/
473
-
474
-extern Int32 BZ2_indexIntoF ( Int32, Int32* );
475
-
476
-/* extern Int32  */
477
-/* BZ2_decompress ( DState* ); */
478
-
479
-extern void BZ2_hbCreateDecodeTables ( Int32*, Int32*, Int32*, UChar*, Int32,  Int32, Int32 );
480
-
481 471
 #endif
482 472
 
483 473
 
... ...
@@ -32,9 +32,7 @@
32 32
 #include "nulsft.h"
33 33
 #include "others.h"
34 34
 #include "cltypes.h"
35
-#ifdef HAVE_BZLIB_H
36 35
 #include "nsis_bzlib.h"
37
-#endif
38 36
 #include "LZMADecode.h"
39 37
 #include "nsis_zlib.h"
40 38
 
... ...
@@ -59,15 +57,10 @@ enum {
59 59
 static int nsis_init(struct nsis_st *n) {
60 60
   switch(n->comp) {
61 61
   case COMP_BZIP2:
62
-#ifdef HAVE_BZLIB_H
63 62
     if (nsis_BZ2_bzDecompressInit(&n->bz, 0, 0)!=BZ_OK)
64 63
       return CL_EBZIP;
65 64
     n->freecomp=1;
66 65
     break;
67
-#else
68
-    cli_warnmsg("NSIS: Bzip2 support not compiled in\n");
69
-    return CL_ESUPPORT;
70
-#endif
71 66
   case COMP_LZMA:
72 67
     lzmaInit(&n->lz);
73 68
     n->freecomp=1;
... ...
@@ -85,9 +78,7 @@ static void nsis_shutdown(struct nsis_st *n) {
85 85
 
86 86
   switch(n->comp) {
87 87
   case COMP_BZIP2:
88
-#ifdef HAVE_BZLIB_H
89 88
     nsis_BZ2_bzDecompressEnd(&n->bz);
90
-#endif
91 89
     break;
92 90
   case COMP_LZMA:
93 91
     lzmaShutdown(&n->lz);
... ...
@@ -102,7 +93,6 @@ static int nsis_decomp(struct nsis_st *n) {
102 102
   int ret = CL_EFORMAT;
103 103
   switch(n->comp) {
104 104
   case COMP_BZIP2:
105
-#ifdef HAVE_BZLIB_H
106 105
     n->bz.avail_in = n->nsis.avail_in;
107 106
     n->bz.next_in = n->nsis.next_in;
108 107
     n->bz.avail_out = n->nsis.avail_out;
... ...
@@ -118,7 +108,6 @@ static int nsis_decomp(struct nsis_st *n) {
118 118
     n->nsis.next_in = n->bz.next_in;
119 119
     n->nsis.avail_out = n->bz.avail_out;
120 120
     n->nsis.next_out = n->bz.next_out;
121
-#endif /* HAVE_BZLIB_H */
122 121
     break;
123 122
   case COMP_LZMA:
124 123
     n->lz.avail_in = n->nsis.avail_in;
... ...
@@ -842,10 +842,6 @@ static int cli_scannulsft(int desc, cli_ctx *ctx, off_t offset) {
842 842
 		    ret = nsist.solid ? CL_BREAK : CL_SUCCESS;
843 843
 		}
844 844
 	    }
845
-
846
-	    if(ret == CL_ESUPPORT) /* bzip2 code not compiled in, continue */
847
-		ret = CL_SUCCESS;
848
-
849 845
 	} else {
850 846
 	    cli_dbgmsg("NSIS: Successully extracted file #%u\n", nsist.fno);
851 847
 	    lseek(nsist.ofd, 0, SEEK_SET);