📄 zipinfo.c
字号:
specified, do the listing for this file. Otherwise, get rid of the file comment and go back for the next file. -----------------------------------------------------------------------*/ if (process_all_files || do_this_file) { switch (lflag) { case 0: printf("%s\n", filename); SKIP_(crec.extra_field_length) SKIP_(crec.file_comment_length) break; case 2: if ((error = short_info()) != 0) { error_in_archive = error; /* might be warning */ if (error > 1) /* fatal */ return (error); } break; case 10:#ifdef VMS /* GRR: FIX THIS (no pipes: add cbreak-style "more" function) */ printf("\nCentral directory entry #%d:\n", j);#else /* !VMS */ /* formfeed/CR for piping to "more": */ printf("%s\nCentral directory entry #%d:\n", "\014", j);#endif /* ?VMS */ printf("---------------------------\n\n"); if ((error = long_info()) != 0) { error_in_archive = error; /* might be warning */ if (error > 1) /* fatal */ return (error); } break; default: SKIP_(crec.extra_field_length) SKIP_(crec.file_comment_length) break; } /* end switch (lflag) */ tot_ucsize += crec.uncompressed_size; tot_csize += crec.compressed_size; ++members; } else { /* not listing */ SKIP_(crec.extra_field_length) SKIP_(crec.file_comment_length) } /* end if (list member?) */ } /* end for-loop (j: member files) *//*--------------------------------------------------------------------------- Double check that we're back at the end-of-central-directory record. ---------------------------------------------------------------------------*/ readbuf(sig, 4); if (strncmp(sig, end_central_sig, 4)) { /* just to make sure again */ fprintf(stderr, EndSigMsg); /* didn't find end-of-central-dir sig */ error_in_archive = 1; /* 1: warning error */ }/*--------------------------------------------------------------------------- Check that we actually found requested files. ---------------------------------------------------------------------------*/ if (none_found && !process_all_files) { fnamev = fnv; /* don't destroy permanent filename ptr */ for (--fnamev; *++fnamev; ) printf("zipinfo: %s not found in %s\n", *fnamev, zipfn); } return (error_in_archive);}/**************************************//* Function process_cdir_file_hdr() *//**************************************/int process_cdir_file_hdr() /* return PK-type error code */{ cdir_byte_hdr byterec;/*--------------------------------------------------------------------------- Read the next central directory entry and do any necessary machine-type conversions (byte ordering, structure padding compensation--do so by copying the data from the array into which it was read (byterec) to the usable struct (crec)). ---------------------------------------------------------------------------*/ if (readbuf((char *) byterec, CREC_SIZE) <= 0) return (51); /* 51: unexpected EOF */ crec.version_made_by[0] = byterec[C_VERSION_MADE_BY_0]; crec.version_made_by[1] = byterec[C_VERSION_MADE_BY_1]; crec.version_needed_to_extract[0] = byterec[C_VERSION_NEEDED_TO_EXTRACT_0]; crec.version_needed_to_extract[1] = byterec[C_VERSION_NEEDED_TO_EXTRACT_1]; crec.general_purpose_bit_flag = makeword(&byterec[C_GENERAL_PURPOSE_BIT_FLAG]); crec.compression_method = makeword(&byterec[C_COMPRESSION_METHOD]); crec.last_mod_file_time = makeword(&byterec[C_LAST_MOD_FILE_TIME]); crec.last_mod_file_date = makeword(&byterec[C_LAST_MOD_FILE_DATE]); crec.crc32 = makelong(&byterec[C_CRC32]); crec.compressed_size = makelong(&byterec[C_COMPRESSED_SIZE]); crec.uncompressed_size = makelong(&byterec[C_UNCOMPRESSED_SIZE]); crec.filename_length = makeword(&byterec[C_FILENAME_LENGTH]); crec.extra_field_length = makeword(&byterec[C_EXTRA_FIELD_LENGTH]); crec.file_comment_length = makeword(&byterec[C_FILE_COMMENT_LENGTH]); crec.disk_number_start = makeword(&byterec[C_DISK_NUMBER_START]); crec.internal_file_attributes = makeword(&byterec[C_INTERNAL_FILE_ATTRIBUTES]); crec.external_file_attributes = makelong(&byterec[C_EXTERNAL_FILE_ATTRIBUTES]); /* LONG, not word! */ crec.relative_offset_local_header = makelong(&byterec[C_RELATIVE_OFFSET_LOCAL_HEADER]); return (0);} /* end function process_cdir_file_hdr() *//**************************//* Function long_info() *//**************************/int long_info() /* return PK-type error code */{ int error, error_in_archive=0; UWORD hostver, extver, xattr; char workspace[12], attribs[22]; static char unkn[16]; static char *os[NUM_HOSTS+1] = {"MS-DOS or OS/2 FAT", "Amiga", "VAX VMS", "Unix", "VM/CMS", "Atari ST", "OS/2 HPFS", "Macintosh", "Z-System", "CP/M", "unknown" }; static char *method[NUM_METHODS+1] = {"none (stored)", "shrunk", "reduced (factor 1)", "reduced (factor 2)", "reduced (factor 3)", "reduced (factor 4)", "imploded", "tokenized", "deflated", unkn}; static char *dtype[4] = {"normal", "maximum", "fastest", "undefined"};/*--------------------------------------------------------------------------- Print out various interesting things about the compressed file. ---------------------------------------------------------------------------*/ hostnum = min(crec.version_made_by[1], NUM_HOSTS); hostver = crec.version_made_by[0]; extnum = min(crec.version_needed_to_extract[1], NUM_HOSTS); extver = crec.version_needed_to_extract[0]; methnum = min(crec.compression_method, NUM_METHODS); if (methnum == NUM_METHODS) sprintf(unkn, "unknown (%d)", crec.compression_method); printf(" %s\n", filename); printf("\n host operating system (created on): %s\n", os[hostnum]); printf(" version of encoding software: %d.%d\n", hostver/10, hostver%10); printf(" minimum operating system compatibility required: %s\n", os[extnum]); printf(" minimum software version required to extract: %d.%d\n", extver/10, extver%10); printf(" compression method: %s\n", method[methnum]); if (methnum == IMPLODED) { printf(" size of sliding dictionary (implosion): %cK\n", (crec.general_purpose_bit_flag & 2)? '8' : '4'); printf(" number of Shannon-Fano trees (implosion): %c\n", (crec.general_purpose_bit_flag & 4)? '3' : '2'); } else if (methnum == DEFLATED) { UWORD dnum=(crec.general_purpose_bit_flag>>1) & 3; printf(" compression sub-type (deflation): %s\n", dtype[dnum]); } printf(" file security status: %sencrypted\n", (crec.general_purpose_bit_flag & 1)? "" : "not "); printf(" extended local header: %s\n", (crec.general_purpose_bit_flag & 8)? "yes" : "no"); /* print upper 3 bits for amusement? */ printf(" file last modified on: %s\n", zipinfo_time(&crec.last_mod_file_date, &crec.last_mod_file_time)); printf(" 32-bit CRC value (hex): %.8lx\n", crec.crc32); printf(" compressed size: %lu bytes\n", crec.compressed_size); printf(" uncompressed size: %lu bytes\n", crec.uncompressed_size); printf(" length of filename: %u characters\n", crec.filename_length); printf(" length of extra field: %u bytes\n", crec.extra_field_length); printf(" length of file comment: %u characters\n", crec.file_comment_length); printf(" disk number on which file begins: disk %u\n", crec.disk_number_start); printf(" apparent file type: %s\n", (crec.internal_file_attributes & 1)? "text" : "binary");/* printf(" external file attributes (hex): %.8lx\n", crec.external_file_attributes); */ xattr = (crec.external_file_attributes >> 16) & 0xFFFF; if (hostnum == VMS_) { char *p=attribs, *q=attribs+1; int i, j, k; for (k = 0; k < 12; ++k) workspace[k] = 0; if (xattr & S_IRUSR) workspace[0] = 'R'; if (xattr & S_IWUSR) { workspace[1] = 'W'; workspace[3] = 'D'; } if (xattr & S_IXUSR) workspace[2] = 'E'; if (xattr & S_IRGRP) workspace[4] = 'R'; if (xattr & S_IWGRP) { workspace[5] = 'W'; workspace[7] = 'D'; } if (xattr & S_IXGRP) workspace[6] = 'E'; if (xattr & S_IROTH) workspace[8] = 'R'; if (xattr & S_IWOTH) { workspace[9] = 'W'; workspace[11] = 'D'; } if (xattr & S_IXOTH) workspace[10] = 'E'; *p++ = '('; for (k = j = 0; j < 3; ++j) { /* loop over groups of permissions */ for (i = 0; i < 4; ++i, ++k) /* loop over perms within a group */ if (workspace[k]) *p++ = workspace[k]; *p++ = ','; /* group separator */ if (j == 0) while ((*p++ = *q++) != ','); /* system, owner perms are same */ } *p-- = 0; *p = ')'; /* overwrite last comma */ printf(" VMS file attributes (%06o octal): %s\n", xattr, attribs); } else if ((hostnum != DOS_OS2_FAT_) && (hostnum != OS2_HPFS_)) { /* assume Unix-like */ switch (xattr & S_IFMT) { case S_IFREG: attribs[0] = '-'; break; case S_IFLNK: attribs[0] = 'l'; break; case S_IFBLK: attribs[0] = 'b'; break; case S_IFCHR: attribs[0] = 'c'; break; case S_IFIFO: attribs[0] = 'p'; break; case S_IFSOCK: attribs[0] = 's'; break; case S_IFDIR: attribs[0] = 'd'; break; default: attribs[0] = '?'; break; } if (xattr & S_IRUSR) /* no read-permission: user */ attribs[1] = 'r'; else attribs[1] = '-'; if (xattr & S_IWUSR) /* no write-permission: user */ attribs[2] = 'w'; else attribs[2] = '-'; if (xattr & S_IXUSR) /* no execute-permission: user */ if (xattr & S_ISUID) attribs[3] = 's'; else attribs[3] = 'x'; else if (xattr & S_ISUID) attribs[3] = 'S'; /* undefined state */ else attribs[3] = '-'; if (xattr & S_IRGRP) /* no read-permission: group */ attribs[4] = 'r'; else attribs[4] = '-'; if (xattr & S_IWGRP) /* no write-permission: group */ attribs[5] = 'w'; else attribs[5] = '-'; if (xattr & S_IXGRP) /* no execute-permission: group */ if (xattr & S_ISGID) attribs[6] = 's'; else attribs[6] = 'x'; else if (xattr & S_ISGID) /* or could use S_ENFMT (same) */ attribs[6] = 'l'; else attribs[6] = '-'; if (xattr & S_IROTH) /* no read-permission: other */ attribs[7] = 'r'; else attribs[7] = '-'; if (xattr & S_IWOTH) /* no write-permission: other */ attribs[8] = 'w'; else attribs[8] = '-'; if (xattr & S_IXOTH) /* no execute-permission: other */ if (xattr & S_ISVTX) /* "sticky bit" */ attribs[9] = 't'; else attribs[9] = 'x'; else if (xattr & S_ISVTX) attribs[9] = 'T'; /* undefined state */ else attribs[9] = '-'; attribs[10] = 0; printf(" Unix file attributes (%06o octal): %s\n", xattr, attribs); } /* endif (hostnum: external attributes format) */ if ((xattr=crec.external_file_attributes & 0xFF) == 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -