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

📄 zipinfo.c

📁 完整的解压zip文件的源码。包含密码功能
💻 C
📖 第 1 页 / 共 5 页
字号:
/*---------------------------------------------------------------------------    Malloc space for check on unmatched filespecs (no big deal if one or both    are NULL).  ---------------------------------------------------------------------------*/    if (G.filespecs > 0  &&        (fn_matched=(int *)malloc(G.filespecs*sizeof(int))) != NULL)        for (j = 0;  j < G.filespecs;  ++j)            fn_matched[j] = FALSE;    if (G.xfilespecs > 0  &&        (xn_matched=(int *)malloc(G.xfilespecs*sizeof(int))) != NULL)        for (j = 0;  j < G.xfilespecs;  ++j)            xn_matched[j] = FALSE;/*---------------------------------------------------------------------------    Set file pointer to start of central directory, then loop through cen-    tral directory entries.  Check that directory-entry signature bytes are    actually there (just a precaution), then process the entry.  We know    the entire central directory is on this disk:  we wouldn't have any of    this information unless the end-of-central-directory record was on this    disk, and we wouldn't have gotten to this routine unless this is also    the disk on which the central directory starts.  In practice, this had    better be the *only* disk in the archive, but maybe someday we'll add    multi-disk support.  ---------------------------------------------------------------------------*/    uO.L_flag = FALSE;      /* zipinfo mode: never convert name to lowercase */    G.pInfo = G.info;       /* (re-)initialize, (just to make sure) */    G.pInfo->textmode = 0;  /* so one can read on screen (is this ever used?) */    /* reset endprev for new zipfile; account for multi-part archives (?) */    endprev = (G.crec.relative_offset_local_header == 4L)? 4L : 0L;    for (j = 0; j++ < (unsigned)G.ecrec.total_entries_central_dir;) {        if (readbuf(__G__ G.sig, 4) == 0)            return PK_EOF;        if (strncmp(G.sig, central_hdr_sig, 4)) {  /* just to make sure */            Info(slide, 0x401, ((char *)slide, LoadFarString(CentSigMsg), j));            return PK_BADERR;   /* sig not found */        }        /* process_cdir_file_hdr() sets pInfo->hostnum, pInfo->lcflag, ...: */        if ((error = process_cdir_file_hdr(__G)) != PK_COOL)            return error;       /* only PK_EOF defined */        if ((error = do_string(__G__ G.crec.filename_length, DS_FN)) !=             PK_COOL)        {          error_in_archive = error;   /* might be warning */          if (error > PK_WARN)        /* fatal */              return error;        }        if (!G.process_all_files) {   /* check if specified on command line */            unsigned i;            do_this_file = FALSE;            for (i = 0; i < G.filespecs; i++)                if (match(G.filename, G.pfnames[i], uO.C_flag)) {                    do_this_file = TRUE;                    if (fn_matched)                        fn_matched[i] = TRUE;                    break;       /* found match, so stop looping */                }            if (do_this_file) {  /* check if this is an excluded file */                for (i = 0; i < G.xfilespecs; i++)                    if (match(G.filename, G.pxnames[i], uO.C_flag)) {                        do_this_file = FALSE;  /* ^-- ignore case in match */                        if (xn_matched)                            xn_matched[i] = TRUE;                        break;                    }            }        }    /*-----------------------------------------------------------------------        If current file was specified on command line, or if no names were        specified, do the listing for this file.  Otherwise, get rid of the        file comment and go back for the next file.      -----------------------------------------------------------------------*/        if (G.process_all_files || do_this_file) {            switch (uO.lflag) {                case 1:                case 2:                    fnprint(__G);                    SKIP_(G.crec.extra_field_length)                    SKIP_(G.crec.file_comment_length)                    break;                case 3:                case 4:                case 5:                    if ((error = zi_short(__G)) != PK_COOL) {                        error_in_archive = error;   /* might be warning */                        if (error > PK_WARN)        /* fatal */                            return error;                    }                    break;                case 10:                    Info(slide, 0, ((char *)slide,                      LoadFarString(CentralDirEntry), j));                    if ((error = zi_long(__G__ &endprev)) != PK_COOL) {                        error_in_archive = error;   /* might be warning */                        if (error > PK_WARN)        /* fatal */                            return error;                    }                    break;                default:                    SKIP_(G.crec.extra_field_length)                    SKIP_(G.crec.file_comment_length)                    break;            } /* end switch (lflag) */            tot_csize += G.crec.csize;            tot_ucsize += G.crec.ucsize;            if (G.crec.general_purpose_bit_flag & 1)                tot_csize -= 12;   /* don't count encryption header */            ++members;#ifdef DLL            if ((G.statreportcb != NULL) &&                (*G.statreportcb)(__G__ UZ_ST_FINISH_MEMBER, G.zipfn,                                  G.filename, NULL)) {                if (fn_matched)                    free((zvoid *)fn_matched);                if (xn_matched)                    free((zvoid *)xn_matched);                return IZ_CTRLC;        /* cancel operation by user request */            }#endif#ifdef MACOS  /* MacOS is no preemptive OS, thus call event-handling by hand */            UserStop();#endif        } else {        /* not listing this file */            SKIP_(G.crec.extra_field_length)            SKIP_(G.crec.file_comment_length)        } /* end if (list member?) */    } /* end for-loop (j: member files) *//*---------------------------------------------------------------------------    Check that we actually found requested files; if so, print totals.  ---------------------------------------------------------------------------*/    if (uO.tflag) {        char *sgn = "";        int cfactor = ratio(tot_ucsize, tot_csize);        if (cfactor < 0) {            sgn = "-";            cfactor = -cfactor;        }        Info(slide, 0, ((char *)slide, LoadFarString(ZipfileStats),          members, (members==1)? nullStr:"s", tot_ucsize,          tot_csize, sgn, cfactor/10, cfactor%10));    }/*---------------------------------------------------------------------------    Check for unmatched filespecs on command line and print warning if any    found.  ---------------------------------------------------------------------------*/    if (fn_matched) {        for (j = 0;  j < G.filespecs;  ++j)            if (!fn_matched[j])                Info(slide, 0x401, ((char *)slide,                  LoadFarString(FilenameNotMatched), G.pfnames[j]));        free((zvoid *)fn_matched);    }    if (xn_matched) {        for (j = 0;  j < G.xfilespecs;  ++j)            if (!xn_matched[j])                Info(slide, 0x401, ((char *)slide,                  LoadFarString(ExclFilenameNotMatched), G.pxnames[j]));        free((zvoid *)xn_matched);    }/*---------------------------------------------------------------------------    Double check that we're back at the end-of-central-directory record.  ---------------------------------------------------------------------------*/    if (readbuf(__G__ G.sig, 4) == 0)  /* disk error? */        return PK_EOF;    if (strncmp(G.sig, end_central_sig, 4)) {   /* just to make sure again */        Info(slide, 0x401, ((char *)slide, LoadFarString(EndSigMsg)));        error_in_archive = PK_WARN;   /* didn't find sig */    }    if (members == 0 && error_in_archive <= PK_WARN)        error_in_archive = PK_FIND;    if (uO.lflag >= 10)        (*G.message)((zvoid *)&G, (uch *)"\n", 1L, 0);    return error_in_archive;} /* end function zipinfo() *//************************//*  Function zi_long()  *//************************/static int zi_long(__G__ pEndprev)   /* return PK-type error code */    __GDEF    ulg *pEndprev;                   /* for zi_long() check of extra bytes */{#ifdef USE_EF_UT_TIME    iztimes z_utime;#endif    int  error, error_in_archive=PK_COOL;    ush  hostnum, hostver, extnum, extver, methnum, xattr;    char workspace[12], attribs[22];    ZCONST char *varmsg_str;    char unkn[16];    static ZCONST char Far *os[NUM_HOSTS] = {        OS_FAT, OS_Amiga, OS_VMS, OS_Unix, OS_VMCMS, OS_AtariST, OS_HPFS,        OS_Macintosh, OS_ZSystem, OS_CPM, OS_TOPS20, OS_NTFS, OS_QDOS,        OS_Acorn, OS_VFAT, OS_MVS, OS_BeOS, OS_Tandem    };    static ZCONST char Far *method[NUM_METHODS] = {        MthdNone, MthdShrunk, MthdRedF1, MthdRedF2, MthdRedF3, MthdRedF4,        MthdImplode, MthdToken, MthdDeflate, MthdEnDeflate, MthdDCLImplode    };    static ZCONST char Far *dtypelng[4] = {        DeflNorm, DeflMax, DeflFast, DeflSFast    };/*---------------------------------------------------------------------------    Check whether there's any extra space inside the zipfile.  If *pEndprev is    zero, it's probably a signal that OS/2 extra fields are involved (with    unknown compressed size).  We won't worry about prepended junk here...  ---------------------------------------------------------------------------*/    if (G.crec.relative_offset_local_header != *pEndprev && *pEndprev > 0L) {        /*  GRR DEBUG        Info(slide, 0, ((char *)slide,          "  [crec.relative_offset_local_header = %lu, endprev = %lu]\n",          G.crec.relative_offset_local_header, *pEndprev));         */        Info(slide, 0, ((char *)slide, LoadFarString(ExtraBytesPreceding),          (long)G.crec.relative_offset_local_header - (long)(*pEndprev)));    }    /* calculate endprev for next time around (problem:  extra fields may     * differ in length between local and central-directory records) */    *pEndprev = G.crec.relative_offset_local_header + 4L + LREC_SIZE +      G.crec.filename_length + G.crec.extra_field_length +      G.crec.file_comment_length + G.crec.csize;/*---------------------------------------------------------------------------    Read the extra field, if any. It may be used to get UNIX style modtime.  ---------------------------------------------------------------------------*/    if ((error = do_string(__G__ G.crec.extra_field_length, EXTRA_FIELD)) != 0)    {        if (G.extra_field != NULL) {            free(G.extra_field);            G.extra_field = NULL;        }        error_in_archive = error;        /* The premature return in case of a "fatal" error (PK_EOF) is         * delayed until we analyze the extra field contents.         * This allows us to display all the other info that has been         * successfully read in.         */    }/*---------------------------------------------------------------------------    Print out various interesting things about the compressed file.  ---------------------------------------------------------------------------*/    hostnum = (ush)(G.pInfo->hostnum);    hostver = G.crec.version_made_by[0];    extnum = (ush)MIN(G.crec.version_needed_to_extract[1], NUM_HOSTS);    extver = G.crec.version_needed_to_extract[0];    methnum = (ush)MIN(G.crec.compression_method, NUM_METHODS);    (*G.message)((zvoid *)&G, (uch *)"  ", 2L, 0);  fnprint(__G);    Info(slide, 0, ((char *)slide, LoadFarString(LocalHeaderOffset),      G.crec.relative_offset_local_header,      G.crec.relative_offset_local_header));    if (hostnum >= NUM_HOSTS) {        sprintf(unkn, LoadFarString(UnknownNo),                (int)G.crec.version_made_by[1]);        varmsg_str = unkn;    } else {        varmsg_str = LoadFarStringSmall(os[hostnum]);    }    Info(slide, 0, ((char *)slide, LoadFarString(HostOS), varmsg_str));    Info(slide, 0, ((char *)slide, LoadFarString(EncodeSWVer), hostver/10,      hostver%10));    if (extnum >= NUM_HOSTS) {        sprintf(unkn, LoadFarString(UnknownNo),                (int)G.crec.version_needed_to_extract[1]);        varmsg_str = unkn;    } else {        varmsg_str = LoadFarStringSmall(os[extnum]);    }

⌨️ 快捷键说明

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