📄 zipinfo.c
字号:
printf(" MS-DOS file attributes (%02X hex): none\n", xattr); else if (xattr == 1) printf( " MS-DOS file attributes (%02X hex): read-only\n", xattr); else printf( " MS-DOS file attributes (%02X hex): %s%s%s%s%s%s\n", xattr, (xattr&1)?"rdo ":"", (xattr&2)?"hid ":"", (xattr&4)?"sys ":"", (xattr&8)?"lab ":"", (xattr&16)?"dir ":"", (xattr&32)?"arc":""); printf( " offset of local header from start of archive: %lu (%.8lXh) bytes\n", crec.relative_offset_local_header, crec.relative_offset_local_header);/*--------------------------------------------------------------------------- Skip the extra field, if any, and print the file comment, if any (the filename has already been printed, above). That finishes up this file entry... ---------------------------------------------------------------------------*/ if (crec.extra_field_length > 0) { printf("\n There is an extra field (skipping).\n"); SKIP_(crec.extra_field_length) } else printf("\n"); if (!crec.file_comment_length) printf(" There is no file comment.\n"); else { printf("\------------------------- file comment begins ----------------------------\n"); if ((error = do_string(crec.file_comment_length, DISPLAY)) != 0) { error_in_archive = error; /* might be warning */ if (error > 1) /* fatal */ return (error); } printf("\n\-------------------------- file comment ends -----------------------------\n"); } return (error_in_archive);} /* end function long_info() *//***************************//* Function short_info() *//***************************/int short_info() /* return PK-type error code */{ int k, error, error_in_archive=0; UWORD hostver, xattr; char workspace[12], attribs[16]; static char impl[5]="i#:#", defl[5]="def#", unkn[8]; static char dtype[5]="NXF?"; /* normal, maximum, fastest, undefined */ static char *os[NUM_HOSTS+1] = {"dos", "ami", "vms", "unx", "cms", "atr", "os2", "mac", "zzz", "cpm", "???" }; static char *method[NUM_METHODS+1] = {"stor", "shrk", "re:1", "re:2", "re:3", "re:4", impl, "tokn", defl, unkn};/*--------------------------------------------------------------------------- Print out various interesting things about the compressed file. ---------------------------------------------------------------------------*/ methnum = min(crec.compression_method, NUM_METHODS); 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]; */ if (methnum == IMPLODED) { impl[1] = (crec.general_purpose_bit_flag & 2)? '8' : '4'; impl[3] = (crec.general_purpose_bit_flag & 4)? '3' : '2'; } else if (methnum == DEFLATED) { UWORD dnum=(crec.general_purpose_bit_flag>>1) & 3; defl[3] = dtype[dnum]; } else if (methnum == NUM_METHODS) { /* unknown */ sprintf(unkn, "u%03d", crec.compression_method); } for (k = 0; k < 15; ++k) attribs[k] = ' '; attribs[15] = 0; xattr = (crec.external_file_attributes >> 16) & 0xFFFF; switch (hostnum) { case VMS_: { char *p=attribs; int i, j; 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'; for (k = j = 0; j < 3; ++j) { /* groups of permissions */ for (i = 0; i < 4; ++i, ++k) /* perms within a group */ if (workspace[k]) *p++ = workspace[k]; *p++ = ','; /* group separator */ } *--p = ' '; /* overwrite last comma */ if ((p - attribs) < 12) sprintf(&attribs[12], "%d.%d", hostver/10, hostver%10); } break; case DOS_OS2_FAT_: case OS2_HPFS_: xattr = crec.external_file_attributes & 0xFF; sprintf(attribs, "%s,%s,%s,%s", (xattr&32)?"arc":"", (xattr&2)?"hid":"", (xattr&1)?"rdo":"rw", (xattr&4)?"sys":""); if ((k = strlen(attribs)) < 15) attribs[k] = ' '; /* overwrite '\0' */ if (k < 12) sprintf(&attribs[12], "%d.%d", hostver/10, hostver%10); break; default: /* 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] = '-'; sprintf(&attribs[12], "%d.%d", hostver/10, hostver%10); break; } /* end switch (hostnum: external attributes format) */ printf("%s %s %7lu %c%c %7lu %s %s %s\n", attribs, os[hostnum], crec.uncompressed_size, (crec.general_purpose_bit_flag & 1)? ((crec.internal_file_attributes & 1)? 'T' : 'B') : /* encrypted */ ((crec.internal_file_attributes & 1)? 't' : 'b'), /* plaintext */ (crec.general_purpose_bit_flag & 8)? (crec.extra_field_length? 'X' : 'l') : (crec.extra_field_length? 'x' : '-'), crec.compressed_size, method[methnum], zipinfo_time(&crec.last_mod_file_date, &crec.last_mod_file_time), filename);/*--------------------------------------------------------------------------- Skip the extra field and/or the file comment, if any (the filename has already been printed, above). That finishes up this file entry... ---------------------------------------------------------------------------*/ SKIP_(crec.extra_field_length) SKIP_(crec.file_comment_length) return (error_in_archive);} /* end function short_info() *//*****************************//* Function zipinfo_time() *//*****************************/char *zipinfo_time(datez, timez) UWORD *datez, *timez;{ UWORD yr, mo, dy, hh, mm, ss; static char d_t_str[21]; static char *month[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};/*--------------------------------------------------------------------------- Convert the file-modification date and time info to a string of the form "23 Feb 1990 17:15:00" or "23-Feb-91 17:15," depending on value of lflag. ---------------------------------------------------------------------------*/ yr = ((*datez >> 9) & 0x7f) + 80; /* dissect date */ mo = ((*datez >> 5) & 0x0f) - 1; dy = *datez & 0x1f; hh = (*timez >> 11) & 0x1f; /* dissect time */ mm = (*timez >> 5) & 0x3f; ss = (*timez & 0x1f) * 2; if (lflag == 2) sprintf(d_t_str, "%2u-%s-%u %02u:%02u", dy, month[mo], yr, hh, mm); else if (lflag > 9) /* verbose listing format */ sprintf(d_t_str, "%u %s %u %02u:%02u:%02u", dy, month[mo], yr+1900, hh, mm, ss); return(d_t_str);} /* end function zipinfo_time() *//********************************//* Function open_input_file() *//********************************/int open_input_file(){ /* return non-0 if open failed */ /* * open the zipfile for reading and in BINARY mode to prevent cr/lf * translation, which would corrupt the bitstreams */#ifndef UNIX zipfd = open(zipfn, O_RDONLY | O_BINARY);#else zipfd = open(zipfn, O_RDONLY);#endif if (zipfd < 1) { fprintf(stderr, "error: can't open zipfile [ %s ]\n", zipfn); return (1); } return 0;}/************************//* Function readbuf() *//************************/int readbuf(buf, size) char *buf; register unsigned size;{ /* return number of bytes read into buf */ register int count; int n; n = size; while (size) { if (incnt == 0) { if ((incnt = read(zipfd, inbuf, INBUFSIZ)) <= 0) return (n-size); /* buffer ALWAYS starts on a block boundary: */ cur_zipfile_bufstart += INBUFSIZ; inptr = inbuf; } count = min(size, incnt); memcpy(buf, inptr, count); buf += count; inptr += count; incnt -= count; size -= count; } return (n);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -