⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inflate.c

📁 压缩解压,是unzip540的升级,这个外国网站摘来的源码,是evb编写.
💻 C
📖 第 1 页 / 共 4 页
字号:
          t = t->v.t + ((unsigned)b & mask_bits[e]);        }        NEEDBITS(e)        d = (unsigned)w - t->v.n - ((unsigned)b & mask_bits[e]);        DUMPBITS(e)        /* do the copy */        do {#if (defined(DLL) && !defined(NO_SLIDE_REDIR))          if (G.redirect_slide) {            /* &= w/ wsize unnecessary & wrong if redirect */            if ((UINT_D64)d >= wsize)              return 1;         /* invalid compressed data */            e = (unsigned)(wsize - (d > (unsigned)w ? (UINT_D64)d : w));          }          else#endif            e = (unsigned)(wsize -                           ((d &= (unsigned)(wsize-1)) > (unsigned)w ?                            (UINT_D64)d : w));          if ((UINT_D64)e > n) e = (unsigned)n;          n -= e;#ifndef NOMEMCPY          if ((unsigned)w - d >= e)          /* (this test assumes unsigned comparison) */          {            memcpy(redirSlide + (unsigned)w, redirSlide + d, e);            w += e;            d += e;          }          else                  /* do it slowly to avoid memcpy() overlap */#endif /* !NOMEMCPY */            do {              redirSlide[w++] = redirSlide[d++];            } while (--e);          if (w == wsize)          {            if ((retval = FLUSH(w)) != 0) goto cleanup_and_exit;            w = 0;          }        } while (n);        break;      }      if (e == 31)              /* it's the EOB signal */      {        /* sorry for this goto, but we have to exit two loops at once */        goto cleanup_decode;      }      if (IS_INVALID_CODE(e))        return 1;      e &= 31;      NEEDBITS(e)      t = t->v.t + ((unsigned)b & mask_bits[e]);    }  }cleanup_decode:  /* restore the globals from the locals */  G.wp = (unsigned)w;             /* restore global window pointer */  G.bb = b;                       /* restore global bit buffer */  G.bk = k;cleanup_and_exit:  /* done */  return retval;}#endif /* ASM_INFLATECODES */static int inflate_stored(__G)     __GDEF/* "decompress" an inflated type 0 (stored) block. */{  UINT_D64 w;           /* current window position (deflate64: up to 64k!) */  unsigned n;           /* number of bytes in block */  register ulg b;       /* bit buffer */  register unsigned k;  /* number of bits in bit buffer */  int retval = 0;       /* error code returned: initialized to "no error" */  /* make local copies of globals */  Trace((stderr, "\nstored block"));  b = G.bb;                       /* initialize bit buffer */  k = G.bk;  w = G.wp;                       /* initialize window position */  /* go to byte boundary */  n = k & 7;  DUMPBITS(n);  /* get the length and its complement */  NEEDBITS(16)  n = ((unsigned)b & 0xffff);  DUMPBITS(16)  NEEDBITS(16)  if (n != (unsigned)((~b) & 0xffff))    return 1;                   /* error in compressed data */  DUMPBITS(16)  /* read and output the compressed data */  while (n--)  {    NEEDBITS(8)    redirSlide[w++] = (uch)b;    if (w == wsize)    {      if ((retval = FLUSH(w)) != 0) goto cleanup_and_exit;      w = 0;    }    DUMPBITS(8)  }  /* restore the globals from the locals */  G.wp = (unsigned)w;             /* restore global window pointer */  G.bb = b;                       /* restore global bit buffer */  G.bk = k;cleanup_and_exit:  return retval;}/* Globals for literal tables (built once) *//* Moved to globals.h                      */#if 0struct huft *fixed_tl = (struct huft *)NULL;struct huft *fixed_td;int fixed_bl, fixed_bd;#endifstatic int inflate_fixed(__G)     __GDEF/* decompress an inflated type 1 (fixed Huffman codes) block.  We should   either replace this with a custom decoder, or at least precompute the   Huffman tables. */{  /* if first time, set up tables for fixed blocks */  Trace((stderr, "\nliteral block"));  if (G.fixed_tl == (struct huft *)NULL)  {    int i;                /* temporary variable */    unsigned l[288];      /* length list for huft_build */    /* literal table */    for (i = 0; i < 144; i++)      l[i] = 8;    for (; i < 256; i++)      l[i] = 9;    for (; i < 280; i++)      l[i] = 7;    for (; i < 288; i++)          /* make a complete, but wrong code set */      l[i] = 8;    G.fixed_bl = 7;#ifdef USE_DEFLATE64    if ((i = huft_build(__G__ l, 288, 257, G.cplens, G.cplext,                        &G.fixed_tl, &G.fixed_bl)) != 0)#else    if ((i = huft_build(__G__ l, 288, 257, cplens, cplext,                        &G.fixed_tl, &G.fixed_bl)) != 0)#endif    {      G.fixed_tl = (struct huft *)NULL;      return i;    }    /* distance table */    for (i = 0; i < MAXDISTS; i++)      /* make an incomplete code set */      l[i] = 5;    G.fixed_bd = 5;#ifdef USE_DEFLATE64    if ((i = huft_build(__G__ l, MAXDISTS, 0, cpdist, G.cpdext,                        &G.fixed_td, &G.fixed_bd)) > 1)#else    if ((i = huft_build(__G__ l, MAXDISTS, 0, cpdist, cpdext,                        &G.fixed_td, &G.fixed_bd)) > 1)#endif    {      huft_free(G.fixed_tl);      G.fixed_td = G.fixed_tl = (struct huft *)NULL;      return i;    }  }  /* decompress until an end-of-block code */  return inflate_codes(__G__ G.fixed_tl, G.fixed_td,                             G.fixed_bl, G.fixed_bd);}static int inflate_dynamic(__G)  __GDEF/* decompress an inflated type 2 (dynamic Huffman codes) block. */{  unsigned i;           /* temporary variables */  unsigned j;  unsigned l;           /* last length */  unsigned m;           /* mask for bit lengths table */  unsigned n;           /* number of lengths to get */  struct huft *tl;      /* literal/length code table */  struct huft *td;      /* distance code table */  unsigned bl;          /* lookup bits for tl */  unsigned bd;          /* lookup bits for td */  unsigned nb;          /* number of bit length codes */  unsigned nl;          /* number of literal/length codes */  unsigned nd;          /* number of distance codes */  unsigned ll[MAXLITLENS+MAXDISTS]; /* lit./length and distance code lengths */  register ulg b;       /* bit buffer */  register unsigned k;  /* number of bits in bit buffer */  int retval = 0;       /* error code returned: initialized to "no error" */  /* make local bit buffer */  Trace((stderr, "\ndynamic block"));  b = G.bb;  k = G.bk;  /* read in table lengths */  NEEDBITS(5)  nl = 257 + ((unsigned)b & 0x1f);      /* number of literal/length codes */  DUMPBITS(5)  NEEDBITS(5)  nd = 1 + ((unsigned)b & 0x1f);        /* number of distance codes */  DUMPBITS(5)  NEEDBITS(4)  nb = 4 + ((unsigned)b & 0xf);         /* number of bit length codes */  DUMPBITS(4)  if (nl > MAXLITLENS || nd > MAXDISTS)    return 1;                   /* bad lengths */  /* read in bit-length-code lengths */  for (j = 0; j < nb; j++)  {    NEEDBITS(3)    ll[border[j]] = (unsigned)b & 7;    DUMPBITS(3)  }  for (; j < 19; j++)    ll[border[j]] = 0;  /* build decoding table for trees--single level, 7 bit lookup */  bl = 7;  retval = huft_build(__G__ ll, 19, 19, NULL, NULL, &tl, &bl);  if (bl == 0)                  /* no bit lengths */    retval = 1;  if (retval)  {    if (retval == 1)      huft_free(tl);    return retval;              /* incomplete code set */  }  /* read in literal and distance code lengths */  n = nl + nd;  m = mask_bits[bl];  i = l = 0;  while (i < n)  {    NEEDBITS(bl)    j = (td = tl + ((unsigned)b & m))->b;    DUMPBITS(j)    j = td->v.n;    if (j < 16)                 /* length of code in bits (0..15) */      ll[i++] = l = j;          /* save last length in l */    else if (j == 16)           /* repeat last length 3 to 6 times */    {      NEEDBITS(2)      j = 3 + ((unsigned)b & 3);      DUMPBITS(2)      if ((unsigned)i + j > n)        return 1;      while (j--)        ll[i++] = l;    }    else if (j == 17)           /* 3 to 10 zero length codes */    {      NEEDBITS(3)      j = 3 + ((unsigned)b & 7);      DUMPBITS(3)      if ((unsigned)i + j > n)        return 1;      while (j--)        ll[i++] = 0;      l = 0;    }    else                        /* j == 18: 11 to 138 zero length codes */    {      NEEDBITS(7)      j = 11 + ((unsigned)b & 0x7f);      DUMPBITS(7)      if ((unsigned)i + j > n)        return 1;      while (j--)        ll[i++] = 0;      l = 0;    }  }  /* free decoding table for trees */  huft_free(tl);  /* restore the global bit buffer */  G.bb = b;  G.bk = k;  /* build the decoding tables for literal/length and distance codes */  bl = lbits;#ifdef USE_DEFLATE64  retval = huft_build(__G__ ll, nl, 257, G.cplens, G.cplext, &tl, &bl);#else  retval = huft_build(__G__ ll, nl, 257, cplens, cplext, &tl, &bl);#endif  if (bl == 0)                  /* no literals or lengths */    retval = 1;  if (retval)  {    if (retval == 1) {      if (!uO.qflag)        MESSAGE((uch *)"(incomplete l-tree)  ", 21L, 1);      huft_free(tl);    }    return retval;              /* incomplete code set */  }#ifdef FIX_PAST_EOB_BY_TABLEADJUST  /* Adjust the requested distance base table size so that a distance code     fetch never tries to get bits behind an immediatly following end-of-block     code. */  bd = (dbits <= bl+1 ? dbits : bl+1);#else  bd = dbits;#endif#ifdef USE_DEFLATE64  retval = huft_build(__G__ ll + nl, nd, 0, cpdist, G.cpdext, &td, &bd);#else  retval = huft_build(__G__ ll + nl, nd, 0, cpdist, cpdext, &td, &bd);#endif#ifdef PKZIP_BUG_WORKAROUND  if (retval == 1)    retval = 0;#endif  if (bd == 0 && nl > 257)    /* lengths but no distances */    retval = 1;  if (retval)  {    if (retval == 1) {      if (!uO.qflag)        MESSAGE((uch *)"(incomplete d-tree)  ", 21L, 1);      huft_free(td);    }    huft_free(tl);    return retval;  }  /* decompress until an end-of-block code */  retval = inflate_codes(__G__ tl, td, bl, bd);cleanup_and_exit:  /* free the decoding tables, return */  huft_free(tl);  huft_free(td);  return retval;}static int inflate_block(__G__ e)  __GDEF  int *e;               /* last block flag *//* decompress an inflated block */{  unsigned t;           /* block type */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -