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

📄 extract.c

📁 完整的解压zip文件的源码。包含密码功能
💻 C
📖 第 1 页 / 共 5 页
字号:
            if (open_outfile(__G))   /* VMS:  required even for stdout! */                return PK_DISK;#endif        } else if (open_outfile(__G))            return PK_DISK;    }/*---------------------------------------------------------------------------    Unpack the file.  ---------------------------------------------------------------------------*/    defer_leftover_input(__G);    /* so NEXTBYTE bounds check will work */    switch (G.lrec.compression_method) {        case STORED:            if (!uO.tflag && QCOND2) {#ifdef SYMLINKS                if (G.symlnk)   /* can also be deflated, but rarer... */                    Info(slide, 0, ((char *)slide, LoadFarString(ExtractMsg),                      "link", FnFilter1(G.filename), "", ""));                else#endif /* SYMLINKS */                Info(slide, 0, ((char *)slide, LoadFarString(ExtractMsg),                  "extract", FnFilter1(G.filename),                  (uO.aflag != 1 /* && G.pInfo->textfile==G.pInfo->textmode */)?                  "" : (G.lrec.ucsize == 0L? nul : (G.pInfo->textfile? txt :                  bin)), uO.cflag? NEWLINE : ""));            }#if (defined(DLL) && !defined(NO_SLIDE_REDIR))            if (G.redirect_slide) {                wsize = G.redirect_size; redirSlide = G.redirect_buffer;            } else {                wsize = WSIZE; redirSlide = slide;            }#endif            G.outptr = redirSlide;            G.outcnt = 0L;            while ((b = NEXTBYTE) != EOF && !G.disk_full) {                *G.outptr++ = (uch)b;                if (++G.outcnt == wsize) {                    flush(__G__ redirSlide, G.outcnt, 0);                    G.outptr = redirSlide;                    G.outcnt = 0L;                }            }            if (G.outcnt)          /* flush final (partial) buffer */                flush(__G__ redirSlide, G.outcnt, 0);            break;#ifndef SFX#ifndef LZW_CLEAN        case SHRUNK:            if (!uO.tflag && QCOND2) {                Info(slide, 0, ((char *)slide, LoadFarString(ExtractMsg),                  LoadFarStringSmall(Unshrink), FnFilter1(G.filename),                  (uO.aflag != 1 /* && G.pInfo->textfile==G.pInfo->textmode */)?                  "" : (G.pInfo->textfile? txt : bin), uO.cflag? NEWLINE : ""));            }            if ((r = unshrink(__G)) != PK_COOL) {                if ((uO.tflag && uO.qflag) || (!uO.tflag && !QCOND2))                    Info(slide, 0x401, ((char *)slide,                      LoadFarStringSmall(ErrUnzipFile),                      LoadFarString(NotEnoughMem),                      LoadFarStringSmall2(Unshrink),                      FnFilter1(G.filename)));                else                    Info(slide, 0x401, ((char *)slide,                      LoadFarStringSmall(ErrUnzipNoFile),                      LoadFarString(NotEnoughMem),                      LoadFarStringSmall2(Unshrink)));                error = r;            }            break;#endif /* !LZW_CLEAN */#ifndef COPYRIGHT_CLEAN        case REDUCED1:        case REDUCED2:        case REDUCED3:        case REDUCED4:            if (!uO.tflag && QCOND2) {                Info(slide, 0, ((char *)slide, LoadFarString(ExtractMsg),                  "unreduc", FnFilter1(G.filename),                  (uO.aflag != 1 /* && G.pInfo->textfile==G.pInfo->textmode */)?                  "" : (G.pInfo->textfile? txt : bin), uO.cflag? NEWLINE : ""));            }            unreduce(__G);            break;#endif /* !COPYRIGHT_CLEAN */        case IMPLODED:            if (!uO.tflag && QCOND2) {                Info(slide, 0, ((char *)slide, LoadFarString(ExtractMsg),                  "explod", FnFilter1(G.filename),                  (uO.aflag != 1 /* && G.pInfo->textfile==G.pInfo->textmode */)?                  "" : (G.pInfo->textfile? txt : bin), uO.cflag? NEWLINE : ""));            }            if (((r = explode(__G)) != 0) && (r != 5)) { /* treat 5 specially */                if ((uO.tflag && uO.qflag) || (!uO.tflag && !QCOND2))                    Info(slide, 0x401, ((char *)slide,                      LoadFarStringSmall(ErrUnzipFile), r == 3?                      LoadFarString(NotEnoughMem) :                      LoadFarString(InvalidComprData),                      LoadFarStringSmall2(Explode),                      FnFilter1(G.filename)));                else                    Info(slide, 0x401, ((char *)slide,                      LoadFarStringSmall(ErrUnzipNoFile), r == 3?                      LoadFarString(NotEnoughMem) :                      LoadFarString(InvalidComprData),                      LoadFarStringSmall2(Explode)));                error = (r == 3)? PK_MEM3 : PK_ERR;            }            if (r == 5) {                int warning = ((ulg)G.used_csize <= G.lrec.csize);                if ((uO.tflag && uO.qflag) || (!uO.tflag && !QCOND2))                    Info(slide, 0x401, ((char *)slide, LoadFarString(LengthMsg),                      "", warning?  "warning" : "error", G.used_csize,                      G.lrec.ucsize, warning?  "  " : "", G.lrec.csize,                      " [", FnFilter1(G.filename), "]"));                else                    Info(slide, 0x401, ((char *)slide, LoadFarString(LengthMsg),                      "\n", warning? "warning" : "error", G.used_csize,                      G.lrec.ucsize, warning? "  ":"", G.lrec.csize,                      "", "", "."));                error = warning? PK_WARN : PK_ERR;            }            break;#endif /* !SFX */        case DEFLATED:            if (!uO.tflag && QCOND2) {                Info(slide, 0, ((char *)slide, LoadFarString(ExtractMsg),                  "inflat", FnFilter1(G.filename),                  (uO.aflag != 1 /* && G.pInfo->textfile==G.pInfo->textmode */)?                  "" : (G.pInfo->textfile? txt : bin), uO.cflag? NEWLINE : ""));            }#ifndef USE_ZLIB  /* zlib's function is called inflate(), too */#  define UZinflate inflate#endif            if ((r = UZinflate(__G)) != 0) {                if ((uO.tflag && uO.qflag) || (!uO.tflag && !QCOND2))                    Info(slide, 0x401, ((char *)slide,                      LoadFarStringSmall(ErrUnzipFile), r == 3?                      LoadFarString(NotEnoughMem) :                      LoadFarString(InvalidComprData),                      LoadFarStringSmall2(Inflate),                      FnFilter1(G.filename)));                else                    Info(slide, 0x401, ((char *)slide,                      LoadFarStringSmall(ErrUnzipNoFile), r == 3?                      LoadFarString(NotEnoughMem) :                      LoadFarString(InvalidComprData),                      LoadFarStringSmall2(Inflate)));                error = (r == 3)? PK_MEM3 : PK_ERR;            }            break;        default:   /* should never get to this point */            Info(slide, 0x401, ((char *)slide,              LoadFarString(FileUnknownCompMethod), FnFilter1(G.filename)));            /* close and delete file before return? */            undefer_input(__G);            return PK_WARN;    } /* end switch (compression method) *//*---------------------------------------------------------------------------    Close the file and set its date and time (not necessarily in that order),    and make sure the CRC checked out OK.  Logical-AND the CRC for 64-bit    machines (redundant on 32-bit machines).  ---------------------------------------------------------------------------*/#ifdef VMS                  /* VMS:  required even for stdout! (final flush) */    if (!uO.tflag)           /* don't close NULL file */        close_outfile(__G);#else#ifdef DLL    if (!uO.tflag && (!uO.cflag || G.redirect_data)) {        if (G.redirect_data)            FINISH_REDIRECT();        else            close_outfile(__G);    }#else    if (!uO.tflag && !uO.cflag)   /* don't close NULL file or stdout */        close_outfile(__G);#endif#endif /* VMS */            /* GRR: CONVERT close_outfile() TO NON-VOID:  CHECK FOR ERRORS! */    if (G.disk_full) {            /* set by flush() */        if (G.disk_full > 1) {#if (defined(DELETE_IF_FULL) && defined(HAVE_UNLINK))            /* delete the incomplete file if we can */            if (unlink(G.filename) != 0)                Trace((stderr, "extract.c:  could not delete %s\n",                  FnFilter1(G.filename)));#else            /* warn user about the incomplete file */            Info(slide, 0x421, ((char *)slide, LoadFarString(FileTruncated),              FnFilter1(G.filename)));#endif            error = PK_DISK;        } else {            error = PK_WARN;        }    }    if (error > PK_WARN) {/* don't print redundant CRC error if error already */        undefer_input(__G);        return error;    }    if (G.crc32val != G.lrec.crc32) {        /* if quiet enough, we haven't output the filename yet:  do it */        if ((uO.tflag && uO.qflag) || (!uO.tflag && !QCOND2))            Info(slide, 0x401, ((char *)slide, "%-22s ",              FnFilter1(G.filename)));        Info(slide, 0x401, ((char *)slide, LoadFarString(BadCRC), G.crc32val,          G.lrec.crc32));#if CRYPT        if (G.pInfo->encrypted)            Info(slide, 0x401, ((char *)slide, LoadFarString(MaybeBadPasswd)));#endif        error = PK_ERR;    } else if (uO.tflag) {#ifndef SFX        if (G.extra_field) {            if ((r = TestExtraField(__G__ G.extra_field,                                    G.lrec.extra_field_length)) > error)                error = r;        } else#endif /* !SFX */        if (!uO.qflag)            Info(slide, 0, ((char *)slide, " OK\n"));    } else {        if (QCOND2 && !error)   /* GRR:  is stdout reset to text mode yet? */            Info(slide, 0, ((char *)slide, "\n"));    }    undefer_input(__G);    return error;} /* end function extract_or_test_member() */#ifndef SFX/*******************************//*  Function TestExtraField()  *//*******************************/static int TestExtraField(__G__ ef, ef_len)    __GDEF    uch *ef;    unsigned ef_len;{    ush ebID;    unsigned ebLen;    unsigned eb_cmpr_offs = 0;    int r;    /* we know the regular compressed file data tested out OK, or else we     * wouldn't be here ==> print filename if any extra-field errors found     */    while (ef_len >= EB_HEADSIZE) {        ebID = makeword(ef);        ebLen = (unsigned)makeword(ef+EB_LEN);        if (ebLen > (ef_len - EB_HEADSIZE)) {           /* Discovered some extra field inconsistency! */            if (uO.qflag)                Info(slide, 1, ((char *)slide, "%-22s ",                  FnFilter1(G.filename)));            Info(slide, 1, ((char *)slide, LoadFarString(InconsistEFlength),              ebLen, (ef_len - EB_HEADSIZE)));            return PK_ERR;        }        switch (ebID) {            case EF_OS2:            case EF_ACL:            case EF_MAC3:            case EF_BEOS:                switch (ebID) {                  case EF_OS2:                  case EF_ACL:                    eb_cmpr_offs = EB_OS2_HLEN;                    break;                  case EF_MAC3:                    if (ebLen >= EB_MAC3_HLEN &&                        (makeword(ef+(EB_HEADSIZE+EB_FLGS_OFFS))                         & EB_M3_FL_UNCMPR) &&                        (makelong(ef+EB_HEADSIZE) == ebLen - EB_MAC3_HLEN))                        eb_cmpr_offs = 0;                    else                        eb_cmpr_offs = EB_MAC3_HLEN;                    break;                  case EF_BEOS:                    if (ebLen >= EB_BEOS_HLEN &&                        (*(ef+(EB_HEADSIZE+EB_FLGS_OFFS)) & EB_BE_FL_UNCMPR) &&                        (makelong(ef+EB_HEADSIZE) == ebLen - EB_BEOS_HLEN))                        eb_cmpr_offs = 0;                    else                        eb_cmpr_offs = EB_BEOS_HLEN;                    break;                }                if ((r = test_compr_eb(__G__ ef, ebLen, eb_cmpr_offs, NULL))                    != PK_OK) {                    if (uO.qflag)                        Info(slide, 1, ((char *)slide, "%-22s ",                          FnFilter1(G.filename)));                    switch (r) {                        case IZ_EF_TRUNC:                            Info(slide, 1, ((char *)slide,                              LoadFarString(TruncEAs),                              ebLen-(eb_cmpr_offs+EB_CMPRHEADLEN), "\n"));                            break;                        case PK_ERR

⌨️ 快捷键说明

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