Rizin
unix-like reverse engineering framework and cli tools
ziptool.c File Reference
#include "config.h"
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "getopt.h"
#include "zip.h"
#include "compat.h"

Go to the source code of this file.

Classes

struct  dispatch_table_s
 
struct  progress_userdata_s
 

Macros

#define OPTIONS_REGRESS   ""
 
#define USAGE_REGRESS   ""
 
#define ziptool_open   read_from_file
 

Typedefs

typedef struct dispatch_table_s dispatch_table_t
 

Functions

static zip_flags_t get_flags (const char *arg)
 
static zip_int32_t get_compression_method (const char *arg)
 
static zip_uint16_t get_encryption_method (const char *arg)
 
static void hexdump (const zip_uint8_t *data, zip_uint16_t len)
 
int ziptool_post_close (const char *archive)
 
static int add (char *argv[])
 
static int add_dir (char *argv[])
 
static int add_file (char *argv[])
 
static int add_from_zip (char *argv[])
 
static int cat (char *argv[])
 
static int count_extra (char *argv[])
 
static int count_extra_by_id (char *argv[])
 
static int delete (char *argv[])
 
static int delete_extra (char *argv[])
 
static int delete_extra_by_id (char *argv[])
 
static int get_archive_comment (char *argv[])
 
static int get_extra (char *argv[])
 
static int get_extra_by_id (char *argv[])
 
static int get_file_comment (char *argv[])
 
static int get_num_entries (char *argv[])
 
static int name_locate (char *argv[])
 
static void progress_callback (zip_t *archive, double percentage, void *ud)
 
static int print_progress (char *argv[])
 
static int zrename (char *argv[])
 
static int replace_file_contents (char *argv[])
 
static int set_extra (char *argv[])
 
static int set_archive_comment (char *argv[])
 
static int set_file_comment (char *argv[])
 
static int set_file_compression (char *argv[])
 
static int set_file_encryption (char *argv[])
 
static int set_file_dostime (char *argv[])
 
static int set_file_mtime (char *argv[])
 
static int set_file_mtime_all (char *argv[])
 
static int set_password (char *argv[])
 
static int zstat (char *argv[])
 
static zip_tread_from_file (const char *archive, int flags, zip_error_t *error, zip_uint64_t offset, zip_uint64_t length)
 
static int dispatch (int argc, char *argv[])
 
static void usage (const char *progname, const char *reason)
 
int main (int argc, char *argv[])
 

Variables

int optopt
 
zip_tza
 
zip_tz_in [16]
 
unsigned int z_in_count
 
zip_flags_t stat_flags
 
struct progress_userdata_s progress_userdata
 
dispatch_table_t dispatch_table []
 

Macro Definition Documentation

◆ OPTIONS_REGRESS

#define OPTIONS_REGRESS   ""

Definition at line 75 of file ziptool.c.

◆ USAGE_REGRESS

#define USAGE_REGRESS   ""

Definition at line 76 of file ziptool.c.

◆ ziptool_open

#define ziptool_open   read_from_file

Definition at line 874 of file ziptool.c.

Typedef Documentation

◆ dispatch_table_t

Function Documentation

◆ add()

static int add ( char *  argv[])
static

Definition at line 84 of file ziptool.c.

84  {
85  zip_source_t *zs;
86 
87  if ((zs = zip_source_buffer(za, argv[1], strlen(argv[1]), 0)) == NULL) {
88  fprintf(stderr, "can't create zip_source from buffer: %s\n", zip_strerror(za));
89  return -1;
90  }
91 
92  if (zip_add(za, argv[0], zs) == -1) {
93  zip_source_free(zs);
94  fprintf(stderr, "can't add file '%s': %s\n", argv[0], zip_strerror(za));
95  return -1;
96  }
97  return 0;
98 }
#define NULL
Definition: cris-opc.c:27
ZIP_EXTERN zip_int64_t zip_add(zip_t *_Nonnull, const char *_Nonnull, zip_source_t *_Nonnull)
Definition: zip_add.c:47
ZIP_EXTERN void zip_source_free(zip_source_t *_Nullable)
ZIP_EXTERN zip_source_t *_Nullable zip_source_buffer(zip_t *_Nonnull, const void *_Nullable, zip_uint64_t, int)
ZIP_EXTERN const char *_Nonnull zip_strerror(zip_t *_Nonnull)
Definition: zip_strerror.c:39
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
zip_t * za
Definition: ziptool.c:79

References argv, NULL, za, zip_add(), zip_source_buffer(), zip_source_free(), and zip_strerror().

Referenced by avr_il_update_indirect_address_reg(), bf_inc(), bf_right_arrow(), libps_snprint(), LZMA_API(), md5_process_bytes(), mnemonic(), print_loop(), rz_core_get_boundaries_prot(), rz_il_op_new_add(), rz_il_op_pure_dup(), rz_il_op_pure_free(), rz_range_add(), sdb_diff_report(), sdb_diff_report_kv(), sdb_diff_report_ns(), sh_il_mac(), str_to_uint64(), update_size(), and vle_snprint().

◆ add_dir()

static int add_dir ( char *  argv[])
static

Definition at line 101 of file ziptool.c.

101  {
102  /* add directory */
103  if (zip_add_dir(za, argv[0]) < 0) {
104  fprintf(stderr, "can't add directory '%s': %s\n", argv[0], zip_strerror(za));
105  return -1;
106  }
107  return 0;
108 }
ZIP_EXTERN zip_int64_t zip_add_dir(zip_t *_Nonnull, const char *_Nonnull)
Definition: zip_add_dir.c:42

References argv, za, zip_add_dir(), and zip_strerror().

◆ add_file()

static int add_file ( char *  argv[])
static

Definition at line 111 of file ziptool.c.

111  {
112  zip_source_t *zs;
113  zip_uint64_t start = strtoull(argv[2], NULL, 10);
114  zip_int64_t len = strtoll(argv[3], NULL, 10);
115 
116  if (strcmp(argv[1], "/dev/stdin") == 0) {
117  if ((zs = zip_source_filep(za, stdin, start, len)) == NULL) {
118  fprintf(stderr, "can't create zip_source from stdin: %s\n", zip_strerror(za));
119  return -1;
120  }
121  }
122  else {
123  if ((zs = zip_source_file(za, argv[1], start, len)) == NULL) {
124  fprintf(stderr, "can't create zip_source from file: %s\n", zip_strerror(za));
125  return -1;
126  }
127  }
128 
129  if (zip_add(za, argv[0], zs) == -1) {
130  zip_source_free(zs);
131  fprintf(stderr, "can't add file '%s': %s\n", argv[0], zip_strerror(za));
132  return -1;
133  }
134  return 0;
135 }
size_t len
Definition: 6502dis.c:15
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
Definition: sflib.h:133
ZIP_EXTERN zip_source_t *_Nullable zip_source_filep(zip_t *_Nonnull, FILE *_Nonnull, zip_uint64_t, zip_int64_t)
ZIP_EXTERN zip_source_t *_Nullable zip_source_file(zip_t *_Nonnull, const char *_Nonnull, zip_uint64_t, zip_int64_t)
uint64_t zip_uint64_t
Definition: zipconf.h:39
int64_t zip_int64_t
Definition: zipconf.h:38

References argv, len, NULL, start, za, zip_add(), zip_source_file(), zip_source_filep(), zip_source_free(), and zip_strerror().

◆ add_from_zip()

static int add_from_zip ( char *  argv[])
static

Definition at line 138 of file ziptool.c.

138  {
141  int err;
142  zip_source_t *zs;
143  /* add from another zip file */
144  idx = strtoull(argv[2], NULL, 10);
145  start = strtoull(argv[3], NULL, 10);
146  len = strtoll(argv[4], NULL, 10);
147  if ((z_in[z_in_count] = zip_open(argv[1], ZIP_CHECKCONS, &err)) == NULL) {
150  fprintf(stderr, "can't open zip archive '%s': %s\n", argv[1], zip_error_strerror(&error));
152  return -1;
153  }
154  if ((zs = zip_source_zip(za, z_in[z_in_count], idx, 0, start, len)) == NULL) {
155  fprintf(stderr, "error creating file source from '%s' index '%" PRIu64 "': %s\n", argv[1], idx, zip_strerror(za));
157  return -1;
158  }
159  if (zip_add(za, argv[0], zs) == -1) {
160  fprintf(stderr, "can't add file '%s': %s\n", argv[0], zip_strerror(za));
161  zip_source_free(zs);
163  return -1;
164  }
165  z_in_count++;
166  return 0;
167 }
static bool err
Definition: armass.c:435
#define PRIu64
Definition: macros.h:18
ZIP_EXTERN void zip_error_init_with_code(zip_error_t *_Nonnull, int)
Definition: zip_error.c:66
#define ZIP_CHECKCONS
Definition: zip.h:69
ZIP_EXTERN int zip_close(zip_t *_Nonnull)
Definition: zip_close.c:52
ZIP_EXTERN void zip_error_fini(zip_error_t *_Nonnull)
Definition: zip_error.c:52
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 zip_t *_Nullable zip_open(const char *_Nonnull, int, int *_Nullable)
Definition: zip_open.c:54
ZIP_EXTERN const char *_Nonnull zip_error_strerror(zip_error_t *_Nonnull)
int idx
Definition: setup.py:197
Definition: zip.h:284
void error(const char *msg)
Definition: untgz.c:593
zip_t * z_in[16]
Definition: ziptool.c:79
unsigned int z_in_count
Definition: ziptool.c:80

References argv, err, error(), setup::idx, len, NULL, PRIu64, start, z_in, z_in_count, za, zip_add(), ZIP_CHECKCONS, zip_close(), zip_error_fini(), zip_error_init_with_code(), zip_error_strerror(), zip_open(), zip_source_free(), zip_source_zip(), and zip_strerror().

◆ cat()

static int cat ( char *  argv[])
static

Definition at line 170 of file ziptool.c.

170  {
171  /* output file contents to stdout */
173  zip_int64_t n;
174  zip_file_t *zf;
175  char buf[8192];
176  int err;
177  idx = strtoull(argv[0], NULL, 10);
178 
179 #ifdef _WIN32
180  /* Need to set stdout to binary mode for Windows */
181  setmode(fileno(stdout), _O_BINARY);
182 #endif
183  if ((zf = zip_fopen_index(za, idx, 0)) == NULL) {
184  fprintf(stderr, "can't open file at index '%" PRIu64 "': %s\n", idx, zip_strerror(za));
185  return -1;
186  }
187  while ((n = zip_fread(zf, buf, sizeof(buf))) > 0) {
188  if (fwrite(buf, (size_t)n, 1, stdout) != 1) {
189  zip_fclose(zf);
190  fprintf(stderr, "can't write file contents to stdout: %s\n", strerror(errno));
191  return -1;
192  }
193  }
194  if (n == -1) {
195  fprintf(stderr, "can't read file at index '%" PRIu64 "': %s\n", idx, zip_file_strerror(zf));
196  zip_fclose(zf);
197  return -1;
198  }
199  if ((err = zip_fclose(zf)) != 0) {
201 
203  fprintf(stderr, "can't close file at index '%" PRIu64 "': %s\n", idx, zip_error_strerror(&error));
204  return -1;
205  }
206 
207  return 0;
208 }
voidpf void * buf
Definition: ioapi.h:138
ZIP_EXTERN int zip_fclose(zip_file_t *_Nonnull)
Definition: zip_fclose.c:41
ZIP_EXTERN const char *_Nonnull zip_file_strerror(zip_file_t *_Nonnull)
ZIP_EXTERN zip_int64_t zip_fread(zip_file_t *_Nonnull, void *_Nonnull, zip_uint64_t)
Definition: zip_fread.c:39
ZIP_EXTERN zip_file_t *_Nullable zip_fopen_index(zip_t *_Nonnull, zip_uint64_t, zip_flags_t)
int n
Definition: mipsasm.c:19

References argv, err, error(), setup::idx, n, NULL, PRIu64, za, zip_error_init_with_code(), zip_error_strerror(), zip_fclose(), zip_file_strerror(), zip_fopen_index(), zip_fread(), and zip_strerror().

Referenced by categorize(), and hexagon_disasm_instruction().

◆ count_extra()

static int count_extra ( char *  argv[])
static

Definition at line 211 of file ziptool.c.

211  {
214  zip_flags_t ceflags = 0;
215  idx = strtoull(argv[0], NULL, 10);
216  ceflags = get_flags(argv[1]);
217  if ((count = zip_file_extra_fields_count(za, idx, ceflags)) < 0) {
218  fprintf(stderr, "can't get extra field count for file at index '%" PRIu64 "': %s\n", idx, zip_strerror(za));
219  return -1;
220  }
221  else {
222  printf("Extra field count: %d\n", count);
223  }
224  return 0;
225 }
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
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
Definition: sflib.h:98
ZIP_EXTERN zip_int16_t zip_file_extra_fields_count(zip_t *_Nonnull, zip_uint64_t, zip_flags_t)
zip_uint32_t zip_flags_t
Definition: zip.h:347
int16_t zip_int16_t
Definition: zipconf.h:34
static zip_flags_t get_flags(const char *arg)
Definition: ziptool.c:617

References argv, count, get_flags(), setup::idx, NULL, printf(), PRIu64, za, zip_file_extra_fields_count(), and zip_strerror().

◆ count_extra_by_id()

static int count_extra_by_id ( char *  argv[])
static

Definition at line 228 of file ziptool.c.

228  {
230  zip_uint16_t eid;
231  zip_flags_t ceflags = 0;
233  idx = strtoull(argv[0], NULL, 10);
234  eid = (zip_uint16_t)strtoull(argv[1], NULL, 10);
235  ceflags = get_flags(argv[2]);
236  if ((count = zip_file_extra_fields_count_by_id(za, idx, eid, ceflags)) < 0) {
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));
238  return -1;
239  }
240  else {
241  printf("Extra field count: %d\n", count);
242  }
243  return 0;
244 }
ZIP_EXTERN zip_int16_t zip_file_extra_fields_count_by_id(zip_t *_Nonnull, zip_uint64_t, zip_uint16_t, zip_flags_t)
uint16_t zip_uint16_t
Definition: zipconf.h:35

References argv, count, get_flags(), setup::idx, NULL, printf(), PRIu64, za, zip_file_extra_fields_count_by_id(), and zip_strerror().

◆ delete()

static int delete ( char *  argv[])
static

Definition at line 246 of file ziptool.c.

246  {
248  idx = strtoull(argv[0], NULL, 10);
249  if (zip_delete(za, idx) < 0) {
250  fprintf(stderr, "can't delete file at index '%" PRIu64 "': %s\n", idx, zip_strerror(za));
251  return -1;
252  }
253  return 0;
254 }
ZIP_EXTERN int zip_delete(zip_t *_Nonnull, zip_uint64_t)
Definition: zip_delete.c:39

References argv, setup::idx, NULL, PRIu64, za, zip_delete(), and zip_strerror().

◆ delete_extra()

static int delete_extra ( char *  argv[])
static

Definition at line 257 of file ziptool.c.

257  {
258  zip_flags_t geflags;
259  zip_uint16_t eid;
261  idx = strtoull(argv[0], NULL, 10);
262  eid = (zip_uint16_t)strtoull(argv[1], NULL, 10);
263  geflags = get_flags(argv[2]);
264  if ((zip_file_extra_field_delete(za, idx, eid, geflags)) < 0) {
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));
266  return -1;
267  }
268  return 0;
269 }
ZIP_EXTERN int zip_file_extra_field_delete(zip_t *_Nonnull, zip_uint64_t, zip_uint16_t, zip_flags_t)

References argv, get_flags(), setup::idx, NULL, PRIu64, za, zip_file_extra_field_delete(), and zip_strerror().

◆ delete_extra_by_id()

static int delete_extra_by_id ( char *  argv[])
static

Definition at line 272 of file ziptool.c.

272  {
273  zip_flags_t geflags;
274  zip_uint16_t eid, eidx;
276  idx = strtoull(argv[0], NULL, 10);
277  eid = (zip_uint16_t)strtoull(argv[1], NULL, 10);
278  eidx = (zip_uint16_t)strtoull(argv[2], NULL, 10);
279  geflags = get_flags(argv[3]);
280  if ((zip_file_extra_field_delete_by_id(za, idx, eid, eidx, geflags)) < 0) {
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));
282  return -1;
283  }
284  return 0;
285 }
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)

References argv, get_flags(), setup::idx, NULL, PRIu64, za, zip_file_extra_field_delete_by_id(), and zip_strerror().

◆ dispatch()

static int dispatch ( int  argc,
char *  argv[] 
)
static

Definition at line 773 of file ziptool.c.

773  {
774  unsigned int i;
775  for (i = 0; i < sizeof(dispatch_table) / sizeof(dispatch_table_t); i++) {
776  if (strcmp(dispatch_table[i].cmdline_name, argv[0]) == 0) {
777  argc--;
778  argv++;
779  /* 1 for the command, argument_count for the arguments */
780  if (argc < dispatch_table[i].argument_count) {
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);
782  return -1;
783  }
784  if (dispatch_table[i].function(argv) == 0)
785  return 1 + dispatch_table[i].argument_count;
786  return -1;
787  }
788  }
789 
790  fprintf(stderr, "unknown command '%s'\n", argv[0]);
791  return -1;
792 }
lzma_index ** i
Definition: index.h:629
int argument_count
Definition: ziptool.c:62
dispatch_table_t dispatch_table[]
Definition: ziptool.c:737

References dispatch_table_s::argument_count, argv, dispatch_table, and i.

Referenced by main().

◆ get_archive_comment()

static int get_archive_comment ( char *  argv[])
static

Definition at line 288 of file ziptool.c.

288  {
289  const char *comment;
290  int len;
291  /* get archive comment */
292  if ((comment = zip_get_archive_comment(za, &len, 0)) == NULL)
293  printf("No archive comment\n");
294  else
295  printf("Archive comment: %.*s\n", len, comment);
296  return 0;
297 }
ZIP_EXTERN const char *_Nullable zip_get_archive_comment(zip_t *_Nonnull, int *_Nullable, zip_flags_t)

References len, NULL, printf(), za, and zip_get_archive_comment().

◆ get_compression_method()

static zip_int32_t get_compression_method ( const char *  arg)
static

Definition at line 641 of file ziptool.c.

641  {
642  if (strcasecmp(arg, "default") == 0)
643  return ZIP_CM_DEFAULT;
644  else if (strcasecmp(arg, "store") == 0)
645  return ZIP_CM_STORE;
646  else if (strcasecmp(arg, "deflate") == 0)
647  return ZIP_CM_DEFLATE;
648 #if defined(HAVE_LIBBZ2)
649  else if (strcasecmp(arg, "bzip2") == 0)
650  return ZIP_CM_BZIP2;
651 #endif
652 #if defined(HAVE_LIBLZMA)
653  /* Disabled - because 7z isn't able to unpack ZIP+LZMA ZIP+LZMA2
654  archives made this way - and vice versa.
655 
656  else if (strcasecmp(arg, "lzma2") == 0)
657  return ZIP_CM_LZMA2;
658  */
659  else if (strcasecmp(arg, "lzma") == 0)
660  return ZIP_CM_LZMA;
661  else if (strcasecmp(arg, "xz") == 0)
662  return ZIP_CM_XZ;
663 #endif
664 #if defined(HAVE_LIBZSTD)
665  else if (strcasecmp(arg, "zstd") == 0)
666  return ZIP_CM_ZSTD;
667 
668 #endif
669  else if (strcasecmp(arg, "unknown") == 0)
670  return 100;
671  return 0; /* TODO: error handling */
672 }
#define ZIP_CM_STORE
Definition: zip.h:149
#define ZIP_CM_BZIP2
Definition: zip.h:161
#define ZIP_CM_ZSTD
Definition: zip.h:169
#define ZIP_CM_XZ
Definition: zip.h:170
#define ZIP_CM_LZMA
Definition: zip.h:163
#define ZIP_CM_DEFAULT
Definition: zip.h:148
#define ZIP_CM_DEFLATE
Definition: zip.h:157

References ZIP_CM_BZIP2, ZIP_CM_DEFAULT, ZIP_CM_DEFLATE, ZIP_CM_LZMA, ZIP_CM_STORE, ZIP_CM_XZ, and ZIP_CM_ZSTD.

Referenced by set_file_compression().

◆ get_encryption_method()

static zip_uint16_t get_encryption_method ( const char *  arg)
static

Definition at line 675 of file ziptool.c.

675  {
676  if (strcasecmp(arg, "none") == 0)
677  return ZIP_EM_NONE;
678  else if (strcasecmp(arg, "PKWARE") == 0)
679  return ZIP_EM_TRAD_PKWARE;
680  else if (strcasecmp(arg, "AES-128") == 0)
681  return ZIP_EM_AES_128;
682  else if (strcasecmp(arg, "AES-192") == 0)
683  return ZIP_EM_AES_192;
684  else if (strcasecmp(arg, "AES-256") == 0)
685  return ZIP_EM_AES_256;
686  else if (strcasecmp(arg, "unknown") == 0)
687  return 100;
688  return (zip_uint16_t)-1; /* TODO: error handling */
689 }
#define ZIP_EM_TRAD_PKWARE
Definition: zip.h:178
#define ZIP_EM_AES_256
Definition: zip.h:192
#define ZIP_EM_AES_192
Definition: zip.h:191
#define ZIP_EM_NONE
Definition: zip.h:177
#define ZIP_EM_AES_128
Definition: zip.h:190

References ZIP_EM_AES_128, ZIP_EM_AES_192, ZIP_EM_AES_256, ZIP_EM_NONE, and ZIP_EM_TRAD_PKWARE.

Referenced by set_file_encryption().

◆ get_extra()

static int get_extra ( char *  argv[])
static

Definition at line 300 of file ziptool.c.

300  {
301  zip_flags_t geflags;
302  zip_uint16_t id, eidx, eflen;
303  const zip_uint8_t *efdata;
305  /* get extra field data */
306  idx = strtoull(argv[0], NULL, 10);
307  eidx = (zip_uint16_t)strtoull(argv[1], NULL, 10);
308  geflags = get_flags(argv[2]);
309  if ((efdata = zip_file_extra_field_get(za, idx, eidx, &id, &eflen, geflags)) == NULL) {
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));
311  return -1;
312  }
313  printf("Extra field 0x%04x: len %d", id, eflen);
314  if (eflen > 0) {
315  printf(", data ");
316  hexdump(efdata, eflen);
317  }
318  printf("\n");
319  return 0;
320 }
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)
int id
Definition: op.c:540
uint8_t zip_uint8_t
Definition: zipconf.h:33
static void hexdump(const zip_uint8_t *data, zip_uint16_t len)
Definition: ziptool.c:692

References argv, get_flags(), hexdump(), id, setup::idx, NULL, printf(), PRIu64, za, zip_file_extra_field_get(), and zip_strerror().

◆ get_extra_by_id()

static int get_extra_by_id ( char *  argv[])
static

Definition at line 323 of file ziptool.c.

323  {
324  zip_flags_t geflags;
325  zip_uint16_t eid, eidx, eflen;
326  const zip_uint8_t *efdata;
328  idx = strtoull(argv[0], NULL, 10);
329  eid = (zip_uint16_t)strtoull(argv[1], NULL, 10);
330  eidx = (zip_uint16_t)strtoull(argv[2], NULL, 10);
331  geflags = get_flags(argv[3]);
332  if ((efdata = zip_file_extra_field_get_by_id(za, idx, eid, eidx, &eflen, geflags)) == NULL) {
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));
334  return -1;
335  }
336  printf("Extra field 0x%04x: len %d", eid, eflen);
337  if (eflen > 0) {
338  printf(", data ");
339  hexdump(efdata, eflen);
340  }
341  printf("\n");
342  return 0;
343 }
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)

References argv, get_flags(), hexdump(), setup::idx, NULL, printf(), PRIu64, za, zip_file_extra_field_get_by_id(), and zip_strerror().

◆ get_file_comment()

static int get_file_comment ( char *  argv[])
static

Definition at line 346 of file ziptool.c.

346  {
347  const char *comment;
348  int len;
350  /* get file comment */
351  idx = strtoull(argv[0], NULL, 10);
352  if ((comment = zip_get_file_comment(za, idx, &len, 0)) == NULL) {
353  fprintf(stderr, "can't get comment for '%s': %s\n", zip_get_name(za, idx, 0), zip_strerror(za));
354  return -1;
355  }
356  else if (len == 0)
357  printf("No comment for '%s'\n", zip_get_name(za, idx, 0));
358  else
359  printf("File comment for '%s': %.*s\n", zip_get_name(za, idx, 0), len, comment);
360  return 0;
361 }
ZIP_EXTERN const char *_Nullable zip_get_name(zip_t *_Nonnull, zip_uint64_t, zip_flags_t)
Definition: zip_get_name.c:41
ZIP_EXTERN const char *_Nullable zip_get_file_comment(zip_t *_Nonnull, zip_uint64_t, int *_Nullable, int)

References argv, setup::idx, len, NULL, printf(), za, zip_get_file_comment(), zip_get_name(), and zip_strerror().

◆ get_flags()

static zip_flags_t get_flags ( const char *  arg)
static

Definition at line 617 of file ziptool.c.

617  {
618  zip_flags_t flags = 0;
619  if (strchr(arg, 'C') != NULL)
620  flags |= ZIP_FL_NOCASE;
621  if (strchr(arg, 'c') != NULL)
623  if (strchr(arg, 'd') != NULL)
624  flags |= ZIP_FL_NODIR;
625  if (strchr(arg, 'l') != NULL)
626  flags |= ZIP_FL_LOCAL;
627  if (strchr(arg, 'u') != NULL)
629  if (strchr(arg, '8') != NULL)
631  if (strchr(arg, '4') != NULL)
633  if (strchr(arg, 'r') != NULL)
635  if (strchr(arg, 's') != NULL)
637  return flags;
638 }
#define ZIP_FL_NODIR
Definition: zip.h:77
#define ZIP_FL_LOCAL
Definition: zip.h:85
#define ZIP_FL_CENTRAL
Definition: zip.h:86
#define ZIP_FL_ENC_STRICT
Definition: zip.h:84
#define ZIP_FL_ENC_CP437
Definition: zip.h:89
#define ZIP_FL_ENC_RAW
Definition: zip.h:83
#define ZIP_FL_ENC_UTF_8
Definition: zip.h:88
#define ZIP_FL_UNCHANGED
Definition: zip.h:79
#define ZIP_FL_NOCASE
Definition: zip.h:76
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123

References flags, NULL, ZIP_FL_CENTRAL, ZIP_FL_ENC_CP437, ZIP_FL_ENC_RAW, ZIP_FL_ENC_STRICT, ZIP_FL_ENC_UTF_8, ZIP_FL_LOCAL, ZIP_FL_NOCASE, ZIP_FL_NODIR, and ZIP_FL_UNCHANGED.

Referenced by count_extra(), count_extra_by_id(), delete_extra(), delete_extra_by_id(), get_extra(), get_extra_by_id(), get_num_entries(), name_locate(), and set_extra().

◆ get_num_entries()

static int get_num_entries ( char *  argv[])
static

Definition at line 364 of file ziptool.c.

364  {
367  /* get number of entries in archive */
368  flags = get_flags(argv[0]);
370  printf("%" PRId64 " entr%s in archive\n", count, count == 1 ? "y" : "ies");
371  return 0;
372 }
#define PRId64
Definition: macros.h:17
ZIP_EXTERN zip_int64_t zip_get_num_entries(zip_t *_Nonnull, zip_flags_t)

References argv, count, flags, get_flags(), PRId64, printf(), za, and zip_get_num_entries().

◆ hexdump()

static void hexdump ( const zip_uint8_t data,
zip_uint16_t  len 
)
static

Definition at line 692 of file ziptool.c.

692  {
693  zip_uint16_t i;
694 
695  if (len <= 0)
696  return;
697 
698  printf("0x");
699 
700  for (i = 0; i < len; i++)
701  printf("%02x", data[i]);
702 }

References i, len, and printf().

Referenced by get_extra(), get_extra_by_id(), and test_command().

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 882 of file ziptool.c.

882  {
883  const char *archive;
884  unsigned int i;
885  int c, arg, err, flags;
886  const char *prg;
887  zip_uint64_t len = 0, offset = 0;
889 
890  flags = 0;
891  prg = argv[0];
892 
893  while ((c = getopt(argc, argv, "ceghl:no:rst" OPTIONS_REGRESS)) != -1) {
894  switch (c) {
895  case 'c':
896  flags |= ZIP_CHECKCONS;
897  break;
898  case 'e':
899  flags |= ZIP_EXCL;
900  break;
901  case 'g':
903  break;
904  case 'h':
905  usage(prg, NULL);
906  break;
907  case 'l':
908  len = strtoull(optarg, NULL, 10);
909  break;
910  case 'n':
911  flags |= ZIP_CREATE;
912  break;
913  case 'o':
914  offset = strtoull(optarg, NULL, 10);
915  break;
916  case 'r':
918  break;
919  case 's':
921  break;
922  case 't':
923  flags |= ZIP_TRUNCATE;
924  break;
925 #ifdef GETOPT_REGRESS
927 #endif
928 
929  default: {
930  char reason[128];
931  snprintf(reason, sizeof(reason), "invalid option -%c", optopt);
932  usage(prg, reason);
933  }
934  }
935  }
936 
937  if (optind >= argc - 1)
938  usage(prg, "too few arguments");
939 
940  arg = optind;
941 
942  archive = argv[arg++];
943 
944  if (flags == 0)
945  flags = ZIP_CREATE;
946 
949  if (za == NULL) {
950  fprintf(stderr, "can't open zip archive '%s': %s\n", archive, zip_error_strerror(&error));
952  return 1;
953  }
955 
956  err = 0;
957  while (arg < argc) {
958  int ret;
959  ret = dispatch(argc - arg, argv + arg);
960  if (ret > 0) {
961  arg += ret;
962  }
963  else {
964  err = 1;
965  break;
966  }
967  }
968 
969  if (zip_close(za) == -1) {
970  fprintf(stderr, "can't close zip archive '%s': %s\n", archive, zip_strerror(za));
971  return 1;
972  }
973  if (ziptool_post_close(archive) < 0) {
974  err = 1;
975  }
976 
977  for (i = 0; i < z_in_count; i++) {
978  if (zip_close(z_in[i]) < 0) {
979  err = 1;
980  }
981  }
982 
983  return err;
984 }
static const char * prg
static const char * arg(RzAnalysis *a, csh *handle, cs_insn *insn, char *buf, int n)
Definition: arm_esil32.c:136
int getopt(int nargc, char *const nargv[], const char *ostr)
Definition: getopt.h:20
const char * optarg
Definition: getopt.h:9
int optind
Definition: getopt.h:6
voidpf uLong offset
Definition: ioapi.h:144
snprintf
Definition: kernel.h:364
#define ZIP_EXCL
Definition: zip.h:68
ZIP_EXTERN void zip_error_init(zip_error_t *_Nonnull)
Definition: zip_error.c:59
#define ZIP_CREATE
Definition: zip.h:67
#define ZIP_FL_ENC_GUESS
Definition: zip.h:82
#define ZIP_TRUNCATE
Definition: zip.h:70
#define c(i)
Definition: sha256.c:43
Definition: zipcmp.c:60
static int dispatch(int argc, char *argv[])
Definition: ziptool.c:773
int optopt
Definition: getopt.h:7
#define OPTIONS_REGRESS
Definition: ziptool.c:75
int ziptool_post_close(const char *archive)
Definition: ziptool.c:876
static void usage(const char *progname, const char *reason)
Definition: ziptool.c:796
zip_flags_t stat_flags
Definition: ziptool.c:81
#define ziptool_open
Definition: ziptool.c:874
#define GETOPT_REGRESS

References arg(), argv, c, dispatch(), err, error(), flags, getopt(), GETOPT_REGRESS, i, len, NULL, optarg, optind, OPTIONS_REGRESS, optopt, prg, snprintf, stat_flags, usage(), z_in, z_in_count, za, ZIP_CHECKCONS, zip_close(), ZIP_CREATE, zip_error_fini(), zip_error_init(), zip_error_strerror(), ZIP_EXCL, ZIP_FL_ENC_GUESS, ZIP_FL_ENC_RAW, ZIP_FL_ENC_STRICT, zip_strerror(), ZIP_TRUNCATE, ziptool_open, and ziptool_post_close().

◆ name_locate()

static int name_locate ( char *  argv[])
static

Definition at line 375 of file ziptool.c.

375  {
378  flags = get_flags(argv[1]);
379 
380  if ((idx = zip_name_locate(za, argv[0], flags)) < 0) {
381  fprintf(stderr, "can't find entry with name '%s' using flags '%s'\n", argv[0], argv[1]);
382  }
383  else {
384  printf("name '%s' using flags '%s' found at index %" PRId64 "\n", argv[0], argv[1], idx);
385  }
386 
387  return 0;
388 }
ZIP_EXTERN zip_int64_t zip_name_locate(zip_t *_Nonnull, const char *_Nonnull, zip_flags_t)

References argv, flags, get_flags(), setup::idx, PRId64, printf(), za, and zip_name_locate().

◆ print_progress()

static int print_progress ( char *  argv[])
static

Definition at line 404 of file ziptool.c.

404  {
406  return 0;
407 }
ZIP_EXTERN int zip_register_progress_callback_with_state(zip_t *_Nonnull, double, zip_progress_callback _Nullable, void(*_Nullable)(void *_Nullable), void *_Nullable)
static void progress_callback(zip_t *archive, double percentage, void *ud)
Definition: ziptool.c:398

References NULL, progress_callback(), za, and zip_register_progress_callback_with_state().

◆ progress_callback()

static void progress_callback ( zip_t archive,
double  percentage,
void *  ud 
)
static

Definition at line 398 of file ziptool.c.

398  {
399  printf("%.1f%% done\n", percentage * 100);
401 }
double percentage
Definition: main.c:10
struct progress_userdata_s progress_userdata
Definition: ziptool.c:395

References percentage, progress_userdata_s::percentage, printf(), and progress_userdata.

Referenced by print_progress(), and zip_register_progress_callback().

◆ read_from_file()

static zip_t* read_from_file ( const char *  archive,
int  flags,
zip_error_t error,
zip_uint64_t  offset,
zip_uint64_t  length 
)
static

Definition at line 706 of file ziptool.c.

706  {
707  zip_t *zaa;
709  int err;
710 
711  if (offset == 0 && length == 0) {
712  if (strcmp(archive, "/dev/stdin") == 0) {
714  }
715  else {
716  zaa = zip_open(archive, flags, &err);
717  }
718  if (zaa == NULL) {
719  zip_error_set(error, err, errno);
720  return NULL;
721  }
722  }
723  else {
724  if (length > ZIP_INT64_MAX) {
726  return NULL;
727  }
730  return NULL;
731  }
732  }
733 
734  return zaa;
735 }
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
Definition: sflib.h:133
ZIP_EXTERN void zip_error_set(zip_error_t *_Nullable, int, int)
Definition: zip_error.c:126
ZIP_EXTERN zip_t *_Nullable zip_open_from_source(zip_source_t *_Nonnull, int, zip_error_t *_Nullable)
Definition: zip_open.c:79
ZIP_EXTERN zip_t *_Nullable zip_fdopen(int, int, int *_Nullable)
Definition: zip_fdopen.c:42
#define ZIP_ER_INVAL
Definition: zip.h:123
ZIP_EXTERN zip_source_t *_Nullable zip_source_file_create(const char *_Nonnull, zip_uint64_t, zip_int64_t, zip_error_t *_Nullable)
const char * source
Definition: lz4.h:699
Definition: zipint.h:278
#define STDIN_FILENO
Definition: private.h:37
#define ZIP_INT64_MAX
Definition: zipconf.h:54

References err, error(), flags, length, NULL, source, STDIN_FILENO, ZIP_CREATE, ZIP_ER_INVAL, zip_error_set(), zip_fdopen(), ZIP_INT64_MAX, zip_open(), zip_open_from_source(), zip_source_file_create(), and zip_source_free().

Referenced by ziptool_open().

◆ replace_file_contents()

static int replace_file_contents ( char *  argv[])
static

Definition at line 421 of file ziptool.c.

421  {
422  /* replace file contents with data from command line */
423  const char *content;
424  zip_source_t *s;
426  idx = strtoull(argv[0], NULL, 10);
427  content = argv[1];
428  if ((s = zip_source_buffer(za, content, strlen(content), 0)) == NULL || zip_file_replace(za, idx, s, 0) < 0) {
430  fprintf(stderr, "error replacing file data: %s\n", zip_strerror(za));
431  return -1;
432  }
433  return 0;
434 }
ZIP_EXTERN int zip_file_replace(zip_t *_Nonnull, zip_uint64_t, zip_source_t *_Nonnull, zip_flags_t)
static RzSocket * s
Definition: rtr.c:28

References argv, setup::idx, NULL, s, za, zip_file_replace(), zip_source_buffer(), zip_source_free(), and zip_strerror().

◆ set_archive_comment()

static int set_archive_comment ( char *  argv[])
static

Definition at line 455 of file ziptool.c.

455  {
456  if (zip_set_archive_comment(za, argv[0], (zip_uint16_t)strlen(argv[0])) < 0) {
457  fprintf(stderr, "can't set archive comment to '%s': %s\n", argv[0], zip_strerror(za));
458  return -1;
459  }
460  return 0;
461 }
ZIP_EXTERN int zip_set_archive_comment(zip_t *_Nonnull, const char *_Nullable, zip_uint16_t)

References argv, za, zip_set_archive_comment(), and zip_strerror().

◆ set_extra()

static int set_extra ( char *  argv[])
static

Definition at line 437 of file ziptool.c.

437  {
438  zip_flags_t geflags;
439  zip_uint16_t eid, eidx;
440  const zip_uint8_t *efdata;
442  idx = strtoull(argv[0], NULL, 10);
443  eid = (zip_uint16_t)strtoull(argv[1], NULL, 10);
444  eidx = (zip_uint16_t)strtoull(argv[2], NULL, 10);
445  geflags = get_flags(argv[3]);
446  efdata = (zip_uint8_t *)argv[4];
447  if ((zip_file_extra_field_set(za, idx, eid, eidx, efdata, (zip_uint16_t)strlen((const char *)efdata), geflags)) < 0) {
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));
449  return -1;
450  }
451  return 0;
452 }
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)

References argv, get_flags(), setup::idx, NULL, PRIu64, za, zip_file_extra_field_set(), and zip_strerror().

◆ set_file_comment()

static int set_file_comment ( char *  argv[])
static

Definition at line 464 of file ziptool.c.

464  {
466  idx = strtoull(argv[0], NULL, 10);
467  if (zip_file_set_comment(za, idx, argv[1], (zip_uint16_t)strlen(argv[1]), 0) < 0) {
468  fprintf(stderr, "can't set file comment at index '%" PRIu64 "' to '%s': %s\n", idx, argv[1], zip_strerror(za));
469  return -1;
470  }
471  return 0;
472 }
ZIP_EXTERN int zip_file_set_comment(zip_t *_Nonnull, zip_uint64_t, const char *_Nullable, zip_uint16_t, zip_flags_t)

References argv, setup::idx, NULL, PRIu64, za, zip_file_set_comment(), and zip_strerror().

◆ set_file_compression()

static int set_file_compression ( char *  argv[])
static

Definition at line 475 of file ziptool.c.

475  {
476  zip_int32_t method;
479  idx = strtoull(argv[0], NULL, 10);
480  method = get_compression_method(argv[1]);
481  flags = (zip_uint32_t)strtoull(argv[2], NULL, 10);
482  if (zip_set_file_compression(za, idx, method, flags) < 0) {
483  fprintf(stderr, "can't set file compression method at index '%" PRIu64 "' to '%s', flags '%" PRIu32 "': %s\n", idx, argv[1], flags, zip_strerror(za));
484  return -1;
485  }
486  return 0;
487 }
#define PRIu32
Definition: macros.h:20
ZIP_EXTERN int zip_set_file_compression(zip_t *_Nonnull, zip_uint64_t, zip_int32_t, zip_uint32_t)
uint32_t zip_uint32_t
Definition: zipconf.h:37
int32_t zip_int32_t
Definition: zipconf.h:36
static zip_int32_t get_compression_method(const char *arg)
Definition: ziptool.c:641

References argv, flags, get_compression_method(), setup::idx, NULL, PRIu32, PRIu64, za, zip_set_file_compression(), and zip_strerror().

◆ set_file_dostime()

static int set_file_dostime ( char *  argv[])
static

Definition at line 508 of file ziptool.c.

508  {
509  /* set file last modification time (mtime) directly */
510  zip_uint16_t dostime, dosdate;
512  idx = strtoull(argv[0], NULL, 10);
513  dostime = (zip_uint16_t)strtoull(argv[1], NULL, 10);
514  dosdate = (zip_uint16_t)strtoull(argv[2], NULL, 10);
515  if (zip_file_set_dostime(za, idx, dostime, dosdate, 0) < 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));
517  return -1;
518  }
519  return 0;
520 }
ZIP_EXTERN int zip_file_set_dostime(zip_t *_Nonnull, zip_uint64_t, zip_uint16_t, zip_uint16_t, zip_flags_t)

References argv, setup::idx, NULL, PRIu64, za, zip_file_set_dostime(), and zip_strerror().

◆ set_file_encryption()

static int set_file_encryption ( char *  argv[])
static

Definition at line 490 of file ziptool.c.

490  {
491  zip_uint16_t method;
493  char *password;
494  idx = strtoull(argv[0], NULL, 10);
495  method = get_encryption_method(argv[1]);
496  password = argv[2];
497  if (strlen(password) == 0) {
498  password = NULL;
499  }
500  if (zip_file_set_encryption(za, idx, method, password) < 0) {
501  fprintf(stderr, "can't set file encryption method at index '%" PRIu64 "' to '%s': %s\n", idx, argv[1], zip_strerror(za));
502  return -1;
503  }
504  return 0;
505 }
ZIP_EXTERN int zip_file_set_encryption(zip_t *_Nonnull, zip_uint64_t, zip_uint16_t, const char *_Nullable)
static zip_uint16_t get_encryption_method(const char *arg)
Definition: ziptool.c:675

References argv, get_encryption_method(), setup::idx, NULL, PRIu64, za, zip_file_set_encryption(), and zip_strerror().

◆ set_file_mtime()

static int set_file_mtime ( char *  argv[])
static

Definition at line 523 of file ziptool.c.

523  {
524  /* set file last modification time (mtime) */
525  time_t mtime;
527  idx = strtoull(argv[0], NULL, 10);
528  mtime = (time_t)strtoull(argv[1], NULL, 10);
529  if (zip_file_set_mtime(za, idx, mtime, 0) < 0) {
530  fprintf(stderr, "can't set file mtime at index '%" PRIu64 "' to '%lld': %s\n", idx, (long long)mtime, zip_strerror(za));
531  return -1;
532  }
533  return 0;
534 }
ZIP_EXTERN int zip_file_set_mtime(zip_t *_Nonnull, zip_uint64_t, time_t, zip_flags_t)
int time_t
Definition: sftypes.h:66

References argv, setup::idx, NULL, PRIu64, za, zip_file_set_mtime(), and zip_strerror().

◆ set_file_mtime_all()

static int set_file_mtime_all ( char *  argv[])
static

Definition at line 537 of file ziptool.c.

537  {
538  /* set last modification time (mtime) for all files */
539  time_t mtime;
540  zip_int64_t num_entries;
542  mtime = (time_t)strtoull(argv[0], NULL, 10);
543 
544  if ((num_entries = zip_get_num_entries(za, 0)) < 0) {
545  fprintf(stderr, "can't get number of entries: %s\n", zip_strerror(za));
546  return -1;
547  }
548  for (idx = 0; idx < (zip_uint64_t)num_entries; idx++) {
549  if (zip_file_set_mtime(za, idx, mtime, 0) < 0) {
550  fprintf(stderr, "can't set file mtime at index '%" PRIu64 "' to '%lld': %s\n", idx, (long long)mtime, zip_strerror(za));
551  return -1;
552  }
553  }
554  return 0;
555 }

References argv, setup::idx, NULL, PRIu64, za, zip_file_set_mtime(), zip_get_num_entries(), and zip_strerror().

◆ set_password()

static int set_password ( char *  argv[])
static

Definition at line 558 of file ziptool.c.

558  {
559  /* set default password */
560  if (zip_set_default_password(za, argv[0]) < 0) {
561  fprintf(stderr, "can't set default password to '%s'\n", argv[0]);
562  return -1;
563  }
564  return 0;
565 }
ZIP_EXTERN int zip_set_default_password(zip_t *_Nonnull, const char *_Nullable)

References argv, za, and zip_set_default_password().

◆ usage()

static void usage ( const char *  progname,
const char *  reason 
)
static

Definition at line 796 of file ziptool.c.

796  {
797  unsigned int i;
798  FILE *out;
799  if (reason == NULL)
800  out = stdout;
801  else
802  out = stderr;
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);
806  exit(1);
807  }
808 
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"
812 #ifdef FOR_REGRESS
813  "\t-F size\t\tfragment size for in memory archive\n"
814 #endif
815  "\t-g\t\tguess file name encoding (for stat)\n"
816 #ifdef FOR_REGRESS
817  "\t-H\t\twrite files with holes compactly\n"
818 #endif
819  "\t-h\t\tdisplay this usage\n"
820  "\t-l len\t\tonly use len bytes of file\n"
821 #ifdef FOR_REGRESS
822  "\t-m\t\tread archive into memory, and modify there; write out at end\n"
823 #endif
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");
830  for (i = 0; i < sizeof(dispatch_table) / sizeof(dispatch_table_t); i++) {
831  fprintf(out, "\t%s %s\n\t %s\n\n", dispatch_table[i].cmdline_name, dispatch_table[i].arg_names, dispatch_table[i].description);
832  }
833  fprintf(out, "\nSupported flags are:\n"
834  "\t0\t(no flags)\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"
845  "\tdefault\n");
847  fprintf(out, "\tbzip2\n");
848  }
849  fprintf(out, "\tdeflate\n"
850  "\tstore\n");
852  fprintf(out, "\txz\n");
853  }
855  fprintf(out, "\tzstd\n");
856  }
857  fprintf(out, "\nSupported encryption methods are:\n"
858  "\tnone\n");
860  fprintf(out, "\tAES-128\n");
861  }
863  fprintf(out, "\tAES-192\n");
864  }
866  fprintf(out, "\tAES-256\n");
867  }
868  fprintf(out, "\tPKWARE\n");
869  fprintf(out, "\nThe index is zero-based.\n");
870  exit(0);
871 }
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
ZIP_EXTERN int zip_compression_method_supported(zip_int32_t method, int compress)
ZIP_EXTERN int zip_encryption_method_supported(zip_uint16_t method, int encode)
string FILE
Definition: benchmark.py:21
description
Definition: setup.py:259
#define progname
#define USAGE_REGRESS
Definition: ziptool.c:76
#define FOR_REGRESS

References setup::description, dispatch_table, test-lz4-list::exit, benchmark::FILE, FOR_REGRESS, i, NULL, out, progname, USAGE_REGRESS, ZIP_CM_BZIP2, ZIP_CM_XZ, ZIP_CM_ZSTD, zip_compression_method_supported(), ZIP_EM_AES_128, ZIP_EM_AES_192, ZIP_EM_AES_256, and zip_encryption_method_supported().

Referenced by main().

◆ ziptool_post_close()

int ziptool_post_close ( const char *  archive)

Definition at line 876 of file ziptool.c.

876  {
877  return 0;
878 }

Referenced by main().

◆ zrename()

static int zrename ( char *  argv[])
static

Definition at line 410 of file ziptool.c.

410  {
412  idx = strtoull(argv[0], NULL, 10);
413  if (zip_rename(za, idx, argv[1]) < 0) {
414  fprintf(stderr, "can't rename file at index '%" PRIu64 "' to '%s': %s\n", idx, argv[1], zip_strerror(za));
415  return -1;
416  }
417  return 0;
418 }
ZIP_EXTERN int zip_rename(zip_t *_Nonnull, zip_uint64_t, const char *_Nonnull)
Definition: zip_rename.c:40

References argv, setup::idx, NULL, PRIu64, za, zip_rename(), and zip_strerror().

◆ zstat()

static int zstat ( char *  argv[])
static

Definition at line 568 of file ziptool.c.

568  {
570  char buf[100];
571  struct zip_stat sb;
572  idx = strtoull(argv[0], NULL, 10);
573 
574  if (zip_stat_index(za, idx, stat_flags, &sb) < 0) {
575  fprintf(stderr, "zip_stat_index failed on '%" PRIu64 "' failed: %s\n", idx, zip_strerror(za));
576  return -1;
577  }
578 
579  if (sb.valid & ZIP_STAT_NAME)
580  printf("name: '%s'\n", sb.name);
581  if (sb.valid & ZIP_STAT_INDEX)
582  printf("index: '%" PRIu64 "'\n", sb.index);
583  if (sb.valid & ZIP_STAT_SIZE)
584  printf("size: '%" PRIu64 "'\n", sb.size);
585  if (sb.valid & ZIP_STAT_COMP_SIZE)
586  printf("compressed size: '%" PRIu64 "'\n", sb.comp_size);
587  if (sb.valid & ZIP_STAT_MTIME) {
588  struct tm *tpm;
589 #ifdef HAVE_LOCALTIME_R
590  struct tm tm;
591  tpm = localtime_r(&sb.mtime, &tm);
592 #else
593  tpm = localtime(&sb.mtime);
594 #endif
595  if (tpm == NULL) {
596  printf("mtime: <not valid>\n");
597  }
598  else {
599  strftime(buf, sizeof(buf), "%a %b %d %Y %H:%M:%S", tpm);
600  printf("mtime: '%s'\n", buf);
601  }
602  }
603  if (sb.valid & ZIP_STAT_CRC)
604  printf("crc: '%0x'\n", sb.crc);
605  if (sb.valid & ZIP_STAT_COMP_METHOD)
606  printf("compression method: '%d'\n", sb.comp_method);
607  if (sb.valid & ZIP_STAT_ENCRYPTION_METHOD)
608  printf("encryption method: '%d'\n", sb.encryption_method);
609  if (sb.valid & ZIP_STAT_FLAGS)
610  printf("flags: '%ld'\n", (long)sb.flags);
611  printf("\n");
612 
613  return 0;
614 }
static SblHeader sb
Definition: bin_mbn.c:26
#define ZIP_STAT_NAME
Definition: zip.h:290
#define ZIP_STAT_SIZE
Definition: zip.h:292
#define ZIP_STAT_COMP_METHOD
Definition: zip.h:296
#define ZIP_STAT_ENCRYPTION_METHOD
Definition: zip.h:297
#define ZIP_STAT_COMP_SIZE
Definition: zip.h:293
#define ZIP_STAT_MTIME
Definition: zip.h:294
#define ZIP_STAT_INDEX
Definition: zip.h:291
ZIP_EXTERN int zip_stat_index(zip_t *_Nonnull, zip_uint64_t, zip_flags_t, zip_stat_t *_Nonnull)
#define ZIP_STAT_CRC
Definition: zip.h:295
#define ZIP_STAT_FLAGS
Definition: zip.h:298
Definition: zip.h:300

References argv, setup::idx, NULL, printf(), PRIu64, sb, stat_flags, za, ZIP_STAT_COMP_METHOD, ZIP_STAT_COMP_SIZE, ZIP_STAT_CRC, ZIP_STAT_ENCRYPTION_METHOD, ZIP_STAT_FLAGS, ZIP_STAT_INDEX, zip_stat_index(), ZIP_STAT_MTIME, ZIP_STAT_NAME, ZIP_STAT_SIZE, and zip_strerror().

Variable Documentation

◆ dispatch_table

dispatch_table_t dispatch_table[]

Definition at line 737 of file ziptool.c.

Referenced by dispatch(), and usage().

◆ optopt

int optopt
extern

Definition at line 7 of file getopt.h.

Referenced by main().

◆ progress_userdata

struct progress_userdata_s progress_userdata

Definition at line 375 of file ziptool.c.

Referenced by cancel(), cancel_callback(), and progress_callback().

◆ stat_flags

zip_flags_t stat_flags

Definition at line 81 of file ziptool.c.

Referenced by main(), and zstat().

◆ z_in

zip_t * z_in[16]

Definition at line 79 of file ziptool.c.

Referenced by add_from_zip(), main(), and zin_close().

◆ z_in_count

unsigned int z_in_count

Definition at line 80 of file ziptool.c.

Referenced by add_from_zip(), main(), and zin_close().

◆ za

zip_t* za

Definition at line 79 of file ziptool.c.

Referenced by _zip_add_entry(), _zip_allocate_new(), _zip_cdir_write(), _zip_changed(), _zip_checkcons(), _zip_deregister_source(), _zip_dirent_write(), _zip_ef_write(), _zip_file_extra_field_prepare_for_change(), _zip_file_get_end(), _zip_file_get_offset(), _zip_file_new(), _zip_file_replace(), _zip_find_central_dir(), _zip_get_dirent(), _zip_get_name(), _zip_name_locate(), _zip_new(), _zip_open(), _zip_progress_new(), _zip_read_cdir(), _zip_read_local_ef(), _zip_register_source(), _zip_set_name(), _zip_source_set_source_archive(), _zip_string_write(), _zip_unchange(), _zip_write(), add(), add_data(), add_dir(), add_file(), add_from_zip(), add_nul(), cancel(), cat(), compare_zip(), compression_source_new(), confirm_replace(), copy_data(), copy_source(), count_extra(), count_extra_by_id(), delete(), delete_extra(), delete_extra_by_id(), ef_read(), get_archive_comment(), get_extra(), get_extra_by_id(), get_file_comment(), get_num_entries(), is_seekable(), list_zip(), LLVMFuzzerTestOneInput(), main(), merge_zip(), name_locate(), print_progress(), replace_file_contents(), seek(), set_archive_comment(), set_extra(), set_file_comment(), set_file_compression(), set_file_dostime(), set_file_encryption(), set_file_mtime(), set_file_mtime_all(), set_password(), test_file(), unchange_all(), unchange_one(), windows_open(), write_cdir(), write_data_descriptor(), zip_add(), zip_add_dir(), zip_close(), zip_delete(), zip_dir_add(), zip_discard(), zip_error_clear(), zip_error_get(), zip_fdopen(), zip_file_add(), zip_file_extra_field_delete(), zip_file_extra_field_delete_by_id(), zip_file_extra_field_get(), zip_file_extra_field_get_by_id(), zip_file_extra_field_set(), zip_file_extra_fields_count(), zip_file_extra_fields_count_by_id(), zip_file_get_comment(), zip_file_get_external_attributes(), zip_file_rename(), zip_file_replace(), zip_file_set_comment(), zip_file_set_dostime(), zip_file_set_encryption(), zip_file_set_external_attributes(), zip_file_set_mtime(), zip_fopen(), zip_fopen_encrypted(), zip_fopen_index(), zip_fopen_index_encrypted(), zip_get_archive_comment(), zip_get_archive_flag(), zip_get_error(), zip_get_file_comment(), zip_get_name(), zip_get_num_entries(), zip_get_num_files(), zip_name_locate(), zip_open(), zip_open_from_source(), zip_register_cancel_callback_with_state(), zip_register_progress_callback(), zip_register_progress_callback_with_state(), zip_rename(), zip_replace(), zip_set_archive_comment(), zip_set_archive_flag(), zip_set_default_password(), zip_set_file_comment(), zip_set_file_compression(), zip_source_buffer(), zip_source_buffer_fragment(), zip_source_buffer_with_attributes(), zip_source_compress(), zip_source_decompress(), zip_source_file(), zip_source_filep(), zip_source_function(), zip_source_layered(), zip_source_pkware_decode(), zip_source_pkware_encode(), zip_source_win32a(), zip_source_win32handle(), zip_source_win32w(), zip_source_winzip_aes_decode(), zip_source_winzip_aes_encode(), zip_source_zip(), zip_stat(), zip_stat_index(), zip_strerror(), zip_unchange(), zip_unchange_all(), zip_unchange_archive(), ziptool_open(), zrename(), and zstat().