47 #define STDIN_FILENO _fileno(stdin)
75 #define OPTIONS_REGRESS ""
76 #define USAGE_REGRESS ""
88 fprintf(stderr,
"can't create zip_source from buffer: %s\n",
zip_strerror(
za));
116 if (strcmp(
argv[1],
"/dev/stdin") == 0) {
118 fprintf(stderr,
"can't create zip_source from stdin: %s\n",
zip_strerror(
za));
124 fprintf(stderr,
"can't create zip_source from file: %s\n",
zip_strerror(
za));
181 setmode(fileno(stdout), _O_BINARY);
188 if (fwrite(
buf, (
size_t)
n, 1, stdout) != 1) {
190 fprintf(stderr,
"can't write file contents to stdout: %s\n", strerror(errno));
237 fprintf(stderr,
"can't get extra field count for file at index '%" PRIu64 "' and for id '%d': %s\n",
idx, eid,
zip_strerror(
za));
246 static int delete (
char *
argv[]) {
265 fprintf(stderr,
"can't delete extra field data for file at index '%" PRIu64 "', extra field id '%d': %s\n",
idx, eid,
zip_strerror(
za));
281 fprintf(stderr,
"can't delete extra field data for file at index '%" PRIu64 "', extra field id '%d', extra field idx '%d': %s\n",
idx, eid, eidx,
zip_strerror(
za));
293 printf(
"No archive comment\n");
295 printf(
"Archive comment: %.*s\n",
len, comment);
310 fprintf(stderr,
"can't get extra field data for file at index %" PRIu64 ", extra field %d, flags %u: %s\n",
idx, eidx, geflags,
zip_strerror(
za));
313 printf(
"Extra field 0x%04x: len %d",
id, eflen);
333 fprintf(stderr,
"can't get extra field data for file at index %" PRIu64 ", extra field id %d, ef index %d, flags %u: %s\n",
idx, eid, eidx, geflags,
zip_strerror(
za));
336 printf(
"Extra field 0x%04x: len %d", eid, eflen);
381 fprintf(stderr,
"can't find entry with name '%s' using flags '%s'\n",
argv[0],
argv[1]);
430 fprintf(stderr,
"error replacing file data: %s\n",
zip_strerror(
za));
448 fprintf(stderr,
"can't set extra field data for file at index '%" PRIu64 "', extra field id '%d', index '%d': %s\n",
idx, eid, eidx,
zip_strerror(
za));
457 fprintf(stderr,
"can't set archive comment to '%s': %s\n",
argv[0],
zip_strerror(
za));
497 if (strlen(password) == 0) {
516 fprintf(stderr,
"can't set file dostime at index '%" PRIu64 "' to '%d'/'%d': %s\n",
idx, (
int)dostime, (
int)dosdate,
zip_strerror(
za));
530 fprintf(stderr,
"can't set file mtime at index '%" PRIu64 "' to '%lld': %s\n",
idx, (
long long)mtime,
zip_strerror(
za));
545 fprintf(stderr,
"can't get number of entries: %s\n",
zip_strerror(
za));
550 fprintf(stderr,
"can't set file mtime at index '%" PRIu64 "' to '%lld': %s\n",
idx, (
long long)mtime,
zip_strerror(
za));
561 fprintf(stderr,
"can't set default password to '%s'\n",
argv[0]);
589 #ifdef HAVE_LOCALTIME_R
591 tpm = localtime_r(&
sb.mtime, &tm);
593 tpm = localtime(&
sb.mtime);
596 printf(
"mtime: <not valid>\n");
599 strftime(
buf,
sizeof(
buf),
"%a %b %d %Y %H:%M:%S", tpm);
606 printf(
"compression method: '%d'\n",
sb.comp_method);
608 printf(
"encryption method: '%d'\n",
sb.encryption_method);
610 printf(
"flags: '%ld'\n", (
long)
sb.flags);
642 if (strcasecmp(
arg,
"default") == 0)
644 else if (strcasecmp(
arg,
"store") == 0)
646 else if (strcasecmp(
arg,
"deflate") == 0)
648 #if defined(HAVE_LIBBZ2)
649 else if (strcasecmp(
arg,
"bzip2") == 0)
652 #if defined(HAVE_LIBLZMA)
659 else if (strcasecmp(
arg,
"lzma") == 0)
661 else if (strcasecmp(
arg,
"xz") == 0)
664 #if defined(HAVE_LIBZSTD)
665 else if (strcasecmp(
arg,
"zstd") == 0)
669 else if (strcasecmp(
arg,
"unknown") == 0)
676 if (strcasecmp(
arg,
"none") == 0)
678 else if (strcasecmp(
arg,
"PKWARE") == 0)
680 else if (strcasecmp(
arg,
"AES-128") == 0)
682 else if (strcasecmp(
arg,
"AES-192") == 0)
684 else if (strcasecmp(
arg,
"AES-256") == 0)
686 else if (strcasecmp(
arg,
"unknown") == 0)
712 if (strcmp(
archive,
"/dev/stdin") == 0) {
738 {
"add_dir", 1,
"name",
"add directory",
add_dir},
739 {
"add_file", 4,
"name file_to_add offset len",
"add file to archive, len bytes starting from offset",
add_file},
740 {
"add_from_zip", 5,
"name archivename index offset len",
"add file from another archive, len bytes starting from offset",
add_from_zip},
741 {
"cat", 1,
"index",
"output file contents to stdout",
cat},
742 {
"count_extra", 2,
"index flags",
"show number of extra fields for archive entry",
count_extra},
743 {
"count_extra_by_id", 3,
"index extra_id flags",
"show number of extra fields of type extra_id for archive entry",
count_extra_by_id},
744 {
"delete", 1,
"index",
"remove entry",
delete},
745 {
"delete_extra", 3,
"index extra_idx flags",
"remove extra field",
delete_extra},
746 {
"delete_extra_by_id", 4,
"index extra_id extra_index flags",
"remove extra field of type extra_id",
delete_extra_by_id},
748 {
"get_extra", 3,
"index extra_index flags",
"show extra field",
get_extra},
749 {
"get_extra_by_id", 4,
"index extra_id extra_index flags",
"show extra field of type extra_id",
get_extra_by_id},
751 {
"get_num_entries", 1,
"flags",
"get number of entries in archive",
get_num_entries},
752 {
"name_locate", 2,
"name flags",
"find entry in archive",
name_locate},
753 {
"print_progress", 0,
"",
"print progress during zip_close()",
print_progress},
754 {
"rename", 2,
"index name",
"rename entry",
zrename},
757 {
"set_extra", 5,
"index extra_id extra_index flags value",
"set extra field",
set_extra},
758 {
"set_file_comment", 2,
"index comment",
"set file comment",
set_file_comment},
759 {
"set_file_compression", 3,
"index method compression_flags",
"set file compression method",
set_file_compression},
760 {
"set_file_dostime", 3,
"index time date",
"set file modification time and date (DOS format)",
set_file_dostime},
761 {
"set_file_encryption", 3,
"index method password",
"set file encryption method",
set_file_encryption},
762 {
"set_file_mtime", 2,
"index timestamp",
"set file modification time",
set_file_mtime},
763 {
"set_file_mtime_all", 1,
"timestamp",
"set file modification time for all files",
set_file_mtime_all},
764 {
"set_password", 1,
"password",
"set default password for encryption",
set_password},
765 {
"stat", 1,
"index",
"print information about entry",
zstat}
766 #ifdef DISPATCH_REGRESS
781 fprintf(stderr,
"not enough arguments for command '%s': %d available, %d needed\n",
dispatch_table[
i].cmdline_name, argc,
dispatch_table[
i].argument_count);
790 fprintf(stderr,
"unknown command '%s'\n",
argv[0]);
803 fprintf(
out,
"usage: %s [-ceghnrst]" USAGE_REGRESS " [-l len] [-o offset] archive command1 [args] [command2 [args] ...]\n",
progname);
804 if (reason !=
NULL) {
805 fprintf(
out,
"%s\n", reason);
809 fprintf(
out,
"\nSupported options are:\n"
810 "\t-c\t\tcheck consistency\n"
811 "\t-e\t\terror if archive already exists (only useful with -n)\n"
813 "\t-F size\t\tfragment size for in memory archive\n"
815 "\t-g\t\tguess file name encoding (for stat)\n"
817 "\t-H\t\twrite files with holes compactly\n"
819 "\t-h\t\tdisplay this usage\n"
820 "\t-l len\t\tonly use len bytes of file\n"
822 "\t-m\t\tread archive into memory, and modify there; write out at end\n"
824 "\t-n\t\tcreate archive if it doesn't exist\n"
825 "\t-o offset\tstart reading file at offset\n"
826 "\t-r\t\tprint raw file name encoding without translation (for stat)\n"
827 "\t-s\t\tfollow file name convention strictly (for stat)\n"
828 "\t-t\t\tdisregard current archive contents, if any\n");
829 fprintf(
out,
"\nSupported commands and arguments are:\n");
833 fprintf(
out,
"\nSupported flags are:\n"
835 "\t4\tZIP_FL_ENC_CP437\n"
836 "\t8\tZIP_FL_ENC_UTF_8\n"
837 "\tC\tZIP_FL_NOCASE\n"
838 "\tc\tZIP_FL_CENTRAL\n"
839 "\td\tZIP_FL_NODIR\n"
840 "\tl\tZIP_FL_LOCAL\n"
841 "\tr\tZIP_FL_ENC_RAW\n"
842 "\ts\tZIP_FL_ENC_STRICT\n"
843 "\tu\tZIP_FL_UNCHANGED\n");
844 fprintf(
out,
"\nSupported compression methods are:\n"
847 fprintf(
out,
"\tbzip2\n");
849 fprintf(
out,
"\tdeflate\n"
852 fprintf(
out,
"\txz\n");
855 fprintf(
out,
"\tzstd\n");
857 fprintf(
out,
"\nSupported encryption methods are:\n"
860 fprintf(
out,
"\tAES-128\n");
863 fprintf(
out,
"\tAES-192\n");
866 fprintf(
out,
"\tAES-256\n");
868 fprintf(
out,
"\tPKWARE\n");
869 fprintf(
out,
"\nThe index is zero-based.\n");
874 #define ziptool_open read_from_file
925 #ifdef GETOPT_REGRESS
static const char * arg(RzAnalysis *a, csh *handle, cs_insn *insn, char *buf, int n)
const lzma_allocator const uint8_t size_t uint8_t * out
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void start
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
ZIP_EXTERN void zip_error_set(zip_error_t *_Nullable, int, int)
ZIP_EXTERN const zip_uint8_t *_Nullable zip_file_extra_field_get(zip_t *_Nonnull, zip_uint64_t, zip_uint16_t, zip_uint16_t *_Nullable, zip_uint16_t *_Nullable, zip_flags_t)
ZIP_EXTERN void zip_error_init_with_code(zip_error_t *_Nonnull, int)
ZIP_EXTERN int zip_compression_method_supported(zip_int32_t method, int compress)
ZIP_EXTERN zip_int64_t zip_name_locate(zip_t *_Nonnull, const char *_Nonnull, zip_flags_t)
ZIP_EXTERN int zip_fclose(zip_file_t *_Nonnull)
ZIP_EXTERN const char *_Nonnull zip_file_strerror(zip_file_t *_Nonnull)
ZIP_EXTERN zip_t *_Nullable zip_open_from_source(zip_source_t *_Nonnull, int, zip_error_t *_Nullable)
#define ZIP_EM_TRAD_PKWARE
ZIP_EXTERN zip_int16_t zip_file_extra_fields_count(zip_t *_Nonnull, zip_uint64_t, zip_flags_t)
ZIP_EXTERN const char *_Nullable zip_get_archive_comment(zip_t *_Nonnull, int *_Nullable, zip_flags_t)
ZIP_EXTERN zip_source_t *_Nullable zip_source_filep(zip_t *_Nonnull, FILE *_Nonnull, zip_uint64_t, zip_int64_t)
ZIP_EXTERN zip_t *_Nullable zip_fdopen(int, int, int *_Nullable)
#define ZIP_STAT_COMP_METHOD
ZIP_EXTERN int zip_encryption_method_supported(zip_uint16_t method, int encode)
ZIP_EXTERN zip_int64_t zip_add(zip_t *_Nonnull, const char *_Nonnull, zip_source_t *_Nonnull)
ZIP_EXTERN int zip_file_extra_field_delete_by_id(zip_t *_Nonnull, zip_uint64_t, zip_uint16_t, zip_uint16_t, zip_flags_t)
ZIP_EXTERN int zip_set_default_password(zip_t *_Nonnull, const char *_Nullable)
ZIP_EXTERN int zip_file_set_mtime(zip_t *_Nonnull, zip_uint64_t, time_t, zip_flags_t)
ZIP_EXTERN const char *_Nullable zip_get_name(zip_t *_Nonnull, zip_uint64_t, zip_flags_t)
ZIP_EXTERN void zip_error_init(zip_error_t *_Nonnull)
ZIP_EXTERN int zip_set_file_compression(zip_t *_Nonnull, zip_uint64_t, zip_int32_t, zip_uint32_t)
ZIP_EXTERN int zip_file_extra_field_set(zip_t *_Nonnull, zip_uint64_t, zip_uint16_t, zip_uint16_t, const zip_uint8_t *_Nullable, zip_uint16_t, zip_flags_t)
ZIP_EXTERN int zip_file_replace(zip_t *_Nonnull, zip_uint64_t, zip_source_t *_Nonnull, zip_flags_t)
ZIP_EXTERN int zip_register_progress_callback_with_state(zip_t *_Nonnull, double, zip_progress_callback _Nullable, void(*_Nullable)(void *_Nullable), void *_Nullable)
ZIP_EXTERN int zip_set_archive_comment(zip_t *_Nonnull, const char *_Nullable, zip_uint16_t)
#define ZIP_STAT_ENCRYPTION_METHOD
ZIP_EXTERN zip_source_t *_Nullable zip_source_file(zip_t *_Nonnull, const char *_Nonnull, zip_uint64_t, zip_int64_t)
#define ZIP_STAT_COMP_SIZE
ZIP_EXTERN zip_int64_t zip_fread(zip_file_t *_Nonnull, void *_Nonnull, zip_uint64_t)
ZIP_EXTERN int zip_close(zip_t *_Nonnull)
ZIP_EXTERN int zip_file_set_encryption(zip_t *_Nonnull, zip_uint64_t, zip_uint16_t, const char *_Nullable)
ZIP_EXTERN int zip_file_set_comment(zip_t *_Nonnull, zip_uint64_t, const char *_Nullable, zip_uint16_t, zip_flags_t)
ZIP_EXTERN zip_int64_t zip_add_dir(zip_t *_Nonnull, const char *_Nonnull)
ZIP_EXTERN int zip_delete(zip_t *_Nonnull, zip_uint64_t)
ZIP_EXTERN void zip_error_fini(zip_error_t *_Nonnull)
#define ZIP_FL_ENC_STRICT
ZIP_EXTERN int zip_rename(zip_t *_Nonnull, zip_uint64_t, const char *_Nonnull)
ZIP_EXTERN int zip_file_extra_field_delete(zip_t *_Nonnull, zip_uint64_t, zip_uint16_t, zip_flags_t)
ZIP_EXTERN zip_source_t *_Nullable zip_source_zip(zip_t *_Nonnull, zip_t *_Nonnull, zip_uint64_t, zip_flags_t, zip_uint64_t, zip_int64_t)
ZIP_EXTERN void zip_source_free(zip_source_t *_Nullable)
ZIP_EXTERN zip_t *_Nullable zip_open(const char *_Nonnull, int, int *_Nullable)
ZIP_EXTERN int zip_stat_index(zip_t *_Nonnull, zip_uint64_t, zip_flags_t, zip_stat_t *_Nonnull)
ZIP_EXTERN const char *_Nonnull zip_error_strerror(zip_error_t *_Nonnull)
ZIP_EXTERN zip_int64_t zip_get_num_entries(zip_t *_Nonnull, zip_flags_t)
ZIP_EXTERN zip_int16_t zip_file_extra_fields_count_by_id(zip_t *_Nonnull, zip_uint64_t, zip_uint16_t, zip_flags_t)
ZIP_EXTERN const zip_uint8_t *_Nullable zip_file_extra_field_get_by_id(zip_t *_Nonnull, zip_uint64_t, zip_uint16_t, zip_uint16_t, zip_uint16_t *_Nullable, zip_flags_t)
ZIP_EXTERN zip_file_t *_Nullable zip_fopen_index(zip_t *_Nonnull, zip_uint64_t, zip_flags_t)
ZIP_EXTERN const char *_Nullable zip_get_file_comment(zip_t *_Nonnull, zip_uint64_t, int *_Nullable, int)
ZIP_EXTERN zip_source_t *_Nullable zip_source_buffer(zip_t *_Nonnull, const void *_Nullable, zip_uint64_t, int)
ZIP_EXTERN int zip_file_set_dostime(zip_t *_Nonnull, zip_uint64_t, zip_uint16_t, zip_uint16_t, zip_flags_t)
ZIP_EXTERN const char *_Nonnull zip_strerror(zip_t *_Nonnull)
ZIP_EXTERN zip_source_t *_Nullable zip_source_file_create(const char *_Nonnull, zip_uint64_t, zip_int64_t, zip_error_t *_Nullable)
static static fork const void static count static fd const char const char static newpath char char argv
static struct sockaddr static addrlen static backlog const void static flags void flags
const char * cmdline_name
void error(const char *msg)