Rizin
unix-like reverse engineering framework and cli tools
io_zip.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2012-2016 pancake <pancake@nopcode.org>
2 // SPDX-FileCopyrightText: 2012-2016 Adam Pridgen <dso@rice.edu>
3 // SPDX-License-Identifier: LGPL-3.0-only
4 
5 #include <rz_io.h>
6 #include <rz_lib.h>
7 #include <rz_util.h>
8 #include <rz_cons.h>
9 #include <zip.h>
10 
11 typedef enum {
12  RZ_IO_PARENT_ZIP = 0x0001,
13  RZ_IO_CHILD_FILE = 0x0002,
14  RZ_IO_NEW_FILE = 0x0004,
19 
20 typedef struct rz_io_zip_uri_const_t {
21  const char *name;
24 
26  { "zip://", 6 },
27  { "apk://", 6 },
28  { "ipa://", 6 },
29  { "jar://", 6 },
30  { NULL, 0 }
31 };
32 
34  { "zipall://", 9 },
35  { "apkall://", 9 },
36  { "ipaall://", 9 },
37  { "jarall://", 9 },
38  { NULL, 0 }
39 };
40 
41 typedef struct rz_io_zfo_t {
42  char *name;
43  char *archivename;
44  int mode;
45  int rw;
46  int fd;
47  int opened;
49  int perm;
52  char *password;
56 
57 static int rz_io_zip_has_uri_substr(const char *file) {
58  return (file && strstr(file, "://"));
59 }
60 
61 static int rz_io_zip_check_uri_many(const char *file) {
62  int i;
64  for (i = 0; ZIP_ALL_URIS[i].name != NULL; i++) {
65  if (!strncmp(file, ZIP_ALL_URIS[i].name, ZIP_ALL_URIS[i].len) && file[ZIP_ALL_URIS[i].len]) {
66  return true;
67  }
68  }
69  }
70  return false;
71 }
72 
73 static int rz_io_zip_check_uri(const char *file) {
74  int i;
76  for (i = 0; ZIP_URIS[i].name != NULL; i++) {
77  if (!strncmp(file, ZIP_URIS[i].name, ZIP_URIS[i].len) && file[ZIP_URIS[i].len]) {
78  return true;
79  }
80  }
81  }
82  return false;
83 }
84 
85 static bool rz_io_zip_plugin_open(RzIO *io, const char *file, bool many) {
86  if (io && file) {
87  if (many) {
89  }
90  return rz_io_zip_check_uri(file);
91  }
92  return false;
93 }
94 
95 struct zip *rz_io_zip_open_archive(const char *archivename, ut32 perm, int mode, int rw) {
96  struct zip *zipArch = NULL;
97  int zip_errorp;
98  if (!archivename) {
99  return NULL;
100  }
101  if ((zipArch = zip_open(archivename, perm, &zip_errorp))) {
102  return zipArch;
103  }
104  if (zip_errorp == ZIP_ER_INVAL) {
105  eprintf("ZIP File Error: Invalid file name (NULL).\n");
106  } else if (zip_errorp == ZIP_ER_OPEN) {
107  eprintf("ZIP File Error: File could not be opened file name.\n");
108  } else if (zip_errorp == ZIP_ER_NOENT) {
109  eprintf("ZIP File Error: File does not exist.\n");
110  } else if (zip_errorp == ZIP_ER_READ) {
111  eprintf("ZIP File Error: Read error occurred.\n");
112  } else if (zip_errorp == ZIP_ER_NOZIP) {
113  eprintf("ZIP File Error: File is not a valid ZIP archive.\n");
114  } else if (zip_errorp == ZIP_ER_INCONS) {
115  eprintf("ZIP File Error: ZIP file had some inconsistencies archive.\n");
116  } else {
117  eprintf("ZIP File Error: Something bad happened, get your debug on.\n");
118  }
119  return NULL;
120 }
121 
123  struct zip_file *zFile = NULL;
124  struct zip *zipArch;
125  struct zip_stat sb;
126  bool res = false;
127  if (!zfo) {
128  return res;
129  }
130  zipArch = rz_io_zip_open_archive(
131  zfo->archivename, zfo->perm,
132  zfo->mode, zfo->rw);
133 
134  if (zipArch && zfo && zfo->entry != -1) {
135  zFile = zip_fopen_index(zipArch, zfo->entry, 0);
136  if (!zFile) {
137  zip_close(zipArch);
138  return false;
139  }
140  if (!zfo->b) {
141  zfo->b = rz_buf_new_with_bytes(NULL, 0);
142  }
143  zip_stat_init(&sb);
144  if (zfo->b && !zip_stat_index(zipArch, zfo->entry, 0, &sb)) {
145  ut8 *buf = calloc(1, sb.size);
146  if (buf) {
147  zip_fread(zFile, buf, sb.size);
148  rz_buf_set_bytes(zfo->b, buf, sb.size);
149  res = true;
150  zfo->opened = true;
151  free(buf);
152  }
153  }
154  zip_fclose(zFile);
155  }
156  zip_close(zipArch);
157  return res;
158 }
159 
160 RzList *rz_io_zip_get_files(const char *archivename, ut32 perm, int mode, int rw) {
161  struct zip *zipArch = rz_io_zip_open_archive(archivename, perm, mode, rw);
162  ut64 num_entries = 0, i = 0;
163  struct zip_stat sb;
164  char *name = NULL;
165  RzList *files = NULL;
166  if (!zipArch) {
167  return NULL;
168  }
169 
171  if (!files) {
172  zip_close(zipArch);
173  return NULL;
174  }
175 
176  num_entries = zip_get_num_files(zipArch);
177  for (i = 0; i < num_entries; i++) {
178  zip_stat_init(&sb);
179  zip_stat_index(zipArch, i, 0, &sb);
180  if ((name = strdup(sb.name))) {
182  }
183  }
184  zip_close(zipArch);
185  return files;
186 }
187 
189  int res = false;
190  struct zip *zipArch;
191 
192  if (!zfo) {
193  return res;
194  }
195 
196  zipArch = rz_io_zip_open_archive(
197  zfo->archivename, zfo->perm, zfo->mode, zfo->rw);
198  if (!zipArch) {
199  return res;
200  }
201 
202  ut64 tmpsz;
203  const ut8 *tmp = rz_buf_data(zfo->b, &tmpsz);
204  struct zip_source *s = zip_source_buffer(zipArch, tmp, tmpsz, 0);
205  if (s && zfo->entry != -1) {
206  if (zip_replace(zipArch, zfo->entry, s) == 0) {
207  res = true;
208  }
209  } else if (s && zfo->name) {
210  if (zip_add(zipArch, zfo->name, s) == 0) {
211  zfo->entry = zip_name_locate(zipArch, zfo->name, 0);
212  res = true;
213  }
214  }
215  // s (zip_source) is freed when the archive is closed, i think - dso
216  zip_close(zipArch);
217  if (s) {
219  }
220  return res;
221 }
222 
224  if (!zfo) {
225  return;
226  }
227  if (zfo->modified) {
229  }
230  free(zfo->name);
231  free(zfo->password);
232  rz_buf_free(zfo->b);
233  free(zfo);
234 }
235 
236 RzIOZipFileObj *rz_io_zip_create_new_file(const char *archivename, const char *filename, struct zip_stat *sb, ut32 perm, int mode, int rw) {
238  if (zfo) {
239  zfo->b = rz_buf_new_with_bytes(NULL, 0);
240  zfo->archivename = strdup(archivename);
241  zfo->name = strdup(sb ? sb->name : filename);
242  zfo->entry = !sb ? -1 : sb->index;
243  zfo->fd = rz_num_rand(0xFFFF); // XXX: Use rz_io_fd api
244  zfo->perm = perm;
245  zfo->mode = mode;
246  zfo->rw = rw;
247  }
248  return zfo;
249 }
250 
251 /* The file can be a file in the archive or ::[num]. */
252 RzIOZipFileObj *rz_io_zip_alloc_zipfileobj(const char *archivename, const char *filename, ut32 perm, int mode, int rw) {
253  RzIOZipFileObj *zfo = NULL;
254  ut64 i, num_entries;
255  struct zip_stat sb;
256  struct zip *zipArch = rz_io_zip_open_archive(archivename, perm, mode, rw);
257  if (!zipArch) {
258  return NULL;
259  }
260  num_entries = zip_get_num_files(zipArch);
261 
262  for (i = 0; i < num_entries; i++) {
263  zip_stat_init(&sb);
264  zip_stat_index(zipArch, i, 0, &sb);
265  if (sb.name != NULL) {
266  if (strcmp(sb.name, filename) == 0) {
268  archivename, filename, &sb,
269  perm, mode, rw);
271  break;
272  }
273  }
274  }
275  if (!zfo) {
276  zfo = rz_io_zip_create_new_file(archivename,
277  filename, NULL, perm, mode, rw);
278  }
279  zip_close(zipArch);
280  return zfo;
281 }
282 
283 // Below this line are the rz_io_zip plugin APIs
284 static RzList *rz_io_zip_open_many(RzIO *io, const char *file, int rw, int mode) {
285  RzList *list_fds = NULL;
286  RzListIter *iter;
287  RzList *filenames = NULL;
288  RzIODesc *res = NULL;
289  RzIOZipFileObj *zfo = NULL;
290  char *filename_in_zipfile, *zip_filename = NULL, *zip_uri;
291 
292  if (!rz_io_zip_plugin_open(io, file, true)) {
293  return NULL;
294  }
295 
296  zip_uri = strdup(file);
297  if (!zip_uri) {
298  return NULL;
299  }
300  // 1) Tokenize to the '//' and find the base file directory ('/')
301  zip_filename = strstr(zip_uri, "//");
302  if (zip_filename && zip_filename[2]) {
303  if (zip_filename[0] && zip_filename[0] == '/' &&
304  zip_filename[1] && zip_filename[1] == '/') {
305  *zip_filename++ = 0;
306  }
307  *zip_filename++ = 0;
308  } else {
309  free(zip_uri);
310  return NULL;
311  }
312 
313  filenames = rz_io_zip_get_files(zip_filename, 0, mode, rw);
314 
315  if (!filenames) {
316  free(zip_uri);
317  return NULL;
318  }
319 
320  list_fds = rz_list_new();
321  rz_list_foreach (filenames, iter, filename_in_zipfile) {
322  size_t v = strlen(filename_in_zipfile);
323 
324  if (filename_in_zipfile[v - 1] == '/') {
325  continue;
326  }
327 
328  zfo = rz_io_zip_alloc_zipfileobj(zip_filename,
329  filename_in_zipfile, ZIP_CREATE, mode, rw);
330 
331  if (zfo && zfo->entry == -1) {
332  eprintf("Warning: File did not exist, creating a new one.\n");
333  }
334 
335  if (zfo) {
336  zfo->io_backref = io;
337  res = rz_io_desc_new(io, &rz_io_plugin_zip,
338  zfo->name, rw, mode, zfo);
339  }
340  rz_list_append(list_fds, res);
341  }
342 
343  free(zip_uri);
344  rz_list_free(filenames);
345  return list_fds;
346 }
347 
348 char *rz_io_zip_get_by_file_idx(const char *archivename, const char *idx, ut32 perm, int mode, int rw) {
349  char *filename = NULL;
350  ut64 i, num_entries;
351  ut32 file_idx = -1;
352  struct zip_stat sb;
353  struct zip *zipArch = rz_io_zip_open_archive(archivename, perm, mode, rw);
354  if (!idx || !zipArch) {
355  zip_close(zipArch);
356  return filename;
357  }
358  num_entries = zip_get_num_files(zipArch);
359  file_idx = atoi(idx);
360  if ((file_idx == 0 && idx[0] != '0') || (file_idx >= num_entries)) {
361  zip_close(zipArch);
362  return filename;
363  }
364  for (i = 0; i < num_entries; i++) {
365  zip_stat_init(&sb);
366  zip_stat_index(zipArch, i, 0, &sb);
367  if (file_idx == i) {
368  filename = strdup(sb.name);
369  break;
370  }
371  }
372  zip_close(zipArch);
373  return filename;
374 }
375 
376 static char *find_ipa_binary(const char *filename, int rw, int mode) {
377  RzList *files = NULL;
378  RzListIter *iter;
379  char *name;
380  int app_size = 0;
381  const char *app_name;
382  const char *last_slash;
383 
384  char *zip_filename = NULL;
386 
387  rz_list_foreach (files, iter, name) {
388  /* Find matching file */
389  app_name = strstr(name, ".app/");
390  if (!app_name) {
391  continue;
392  }
393  last_slash = rz_str_rchr(name, app_name, '/');
394  if (!last_slash) {
395  continue;
396  }
397  app_size = (app_name - last_slash) - 1;
398  zip_filename = rz_str_newf("//Payload/%.*s.app/%.*s", app_size, last_slash + 1, app_size, last_slash + 1);
399  if (zip_filename && !strcmp(name, zip_filename + 2)) {
400  break;
401  }
402  RZ_FREE(zip_filename);
403  }
405 
406  return zip_filename;
407 }
408 
409 static char *find_apk_binary(const char *filename, int rw, int mode, RzIO *io) {
410  RzList *files = NULL;
411  RzListIter *iter = NULL;
412  char *name = NULL;
413  RzIOZipFileObj *zfo = NULL;
414  char *zip_filename = rz_str_newf("//%s//classes.dex", filename);
416 
417  if (files) {
418  rz_list_foreach (files, iter, name) {
419  /* Find matching file */
420  if (!strcmp(name, "classes.dex")) {
421  continue;
422  } else if (rz_str_endswith(name, ".dex")) {
423  RZ_LOG_INFO("Adding extra IO descriptor to file %s\n", name);
425  if (!zfo) {
426  eprintf("Error: cannot allocate zip file object.\n");
427  continue;
428  }
429  if (zfo->entry == -1) {
430  if (!rw) {
431  eprintf("Warning: File %s does not exist.\n", name);
433  continue;
434  }
435  eprintf("Warning: File %s does not exist, creating a new one.\n", name);
436  }
437  zfo->io_backref = io;
438  RzIODesc *desc = rz_io_desc_new(io, &rz_io_plugin_zip, zfo->name, rw, mode, zfo);
439  desc->name = strdup(name);
440  rz_io_desc_add(io, desc);
441  }
442  }
444  }
445 
446  return zip_filename;
447 }
448 
449 static RzIODesc *rz_io_zip_open(RzIO *io, const char *file, int rw, int mode) {
450  RzIODesc *res = NULL;
451  char *uri_path, *tmp;
452  RzIOZipFileObj *zfo = NULL;
453  char *zip_uri = NULL, *zip_filename = NULL, *filename_in_zipfile = NULL;
454 
455  if (!rz_io_zip_plugin_open(io, file, false)) {
456  return NULL;
457  }
458  zip_uri = strdup(file);
459  if (!zip_uri) {
460  return NULL;
461  }
462  uri_path = strstr(zip_uri, "://");
463  if (uri_path) {
464  tmp = strstr(uri_path + 3, "//");
465  zip_filename = tmp ? strdup(tmp) : NULL;
466  // 1) Tokenize to the '//' and find the base file directory ('/')
467  if (!zip_filename) {
468  if (!strncmp(zip_uri, "apk://", 6)) {
469  zip_filename = find_apk_binary(uri_path + 3, rw, mode, io);
470  } else if (!strncmp(zip_uri, "ipa://", 6)) {
471  zip_filename = find_ipa_binary(uri_path + 3, rw, mode);
472  } else {
473  zip_filename = strdup(uri_path + 1);
474  }
475  } else {
476  free(zip_filename);
477  zip_filename = strdup(uri_path + 1);
478  }
479  }
480  tmp = zip_filename;
481  if (zip_filename && zip_filename[1] && zip_filename[2]) {
482  if (zip_filename[0] && zip_filename[0] == '/' &&
483  zip_filename[1] && zip_filename[1] == '/') {
484  *zip_filename++ = 0;
485  }
486  *zip_filename++ = 0;
487 
488  // check for // for file in the archive
489  if ((filename_in_zipfile = strstr(zip_filename, "//")) && filename_in_zipfile[2]) {
490  // null terminating uri to filename here.
491  *filename_in_zipfile++ = 0;
492  *filename_in_zipfile++ = 0;
493  filename_in_zipfile = strdup(filename_in_zipfile);
494  // check for :: index
495  } else if ((filename_in_zipfile = strstr(zip_filename, "::")) &&
496  filename_in_zipfile[2]) {
497  // null terminating uri to filename here.
498  *filename_in_zipfile++ = 0;
499  *filename_in_zipfile++ = 0;
500  filename_in_zipfile = rz_io_zip_get_by_file_idx(
501  zip_filename, filename_in_zipfile,
502  ZIP_CREATE, mode, rw);
503  } else {
504  filename_in_zipfile = rz_str_newf("%s", zip_filename);
505  RZ_FREE(tmp);
506  zip_filename = strdup(uri_path + 3);
507  if (!strcmp(zip_filename, filename_in_zipfile)) {
508  // RZ_FREE (zip_filename);
509  RZ_FREE(filename_in_zipfile);
510  }
511  }
512  }
513 
514  if (!zip_filename) { // && !filename_in_zipfile) {
515  // free (zip_uri);
516  eprintf("usage: zip:///path/to/archive//filepath\n"
517  "usage: zip:///path/to/archive::[number]\n"
518  "Archive was not found.\n");
519  // return res;
520  }
521 
522  // Failed to find the file name the archive.
523  if (!filename_in_zipfile) {
524  RzList *files = NULL;
525  RzListIter *iter;
526  char *name;
527  // eprintf("usage: zip:///path/to/archive//filepath\n");
528  files = rz_io_zip_get_files(zip_filename, 0, mode, rw);
529  if (files) {
530  ut32 i = 0;
531  rz_list_foreach (files, iter, name) {
532  io->cb_printf("%d %s\n", i, name);
533  i++;
534  }
536  }
537  goto done;
538  }
539  // eprintf("After parsing the given uri: %s\n", file);
540  // eprintf("Zip filename the given uri: %s\n", zip_filename);
541  // eprintf("File in the zip: %s\n", filename_in_zipfile);
542  zfo = rz_io_zip_alloc_zipfileobj(zip_filename,
543  filename_in_zipfile, ZIP_CREATE, mode, rw);
544 
545  if (zfo) {
546  if (zfo->entry == -1) {
547  eprintf("Warning: File %s does not exist, creating a new one.\n", filename_in_zipfile);
548  }
549  zfo->io_backref = io;
550  res = rz_io_desc_new(io, &rz_io_plugin_zip,
551  zfo->name, rw, mode, zfo);
552  }
553 
554  if (!res) {
555  eprintf("Failed to open the archive %s and file %s\n",
556  zip_filename, filename_in_zipfile);
557  // free (zfo); zfo is already freed by rz_io_desc_new
558  rz_io_desc_free(res);
559  res = NULL;
560  }
561 done:
562  free(filename_in_zipfile);
563  free(zip_uri);
564  free(tmp);
565  return res;
566 }
567 
568 static ut64 rz_io_zip_lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) {
569  RzIOZipFileObj *zfo;
570  ut64 seek_val = 0;
571 
572  if (!fd || !fd->data) {
573  return -1;
574  }
575 
576  zfo = fd->data;
577  seek_val = rz_buf_tell(zfo->b);
578 
579  switch (whence) {
580  case SEEK_SET:
581  seek_val = (rz_buf_size(zfo->b) < offset) ? rz_buf_size(zfo->b) : offset;
582  io->off = seek_val;
583  rz_buf_seek(zfo->b, seek_val, RZ_BUF_SET);
584  return seek_val;
585  case SEEK_CUR:
586  seek_val = (rz_buf_size(zfo->b) < (offset + rz_buf_tell(zfo->b))) ? rz_buf_size(zfo->b) : offset + rz_buf_tell(zfo->b);
587  io->off = seek_val;
588  rz_buf_seek(zfo->b, seek_val, RZ_BUF_SET);
589  return seek_val;
590  case SEEK_END:
591  seek_val = rz_buf_size(zfo->b);
592  io->off = seek_val;
593  rz_buf_seek(zfo->b, seek_val, RZ_BUF_SET);
594  return seek_val;
595  }
596  return seek_val;
597 }
598 
599 static int rz_io_zip_read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) {
600  RzIOZipFileObj *zfo = NULL;
601  if (!fd || !fd->data || !buf) {
602  return -1;
603  }
604  zfo = fd->data;
605  if (rz_buf_size(zfo->b) < io->off) {
606  io->off = rz_buf_size(zfo->b);
607  }
608  int r = rz_buf_read_at(zfo->b, io->off, buf, count);
609  if (r >= 0) {
610  rz_buf_seek(zfo->b, r, RZ_BUF_CUR);
611  }
612  return r;
613 }
614 
616  return rz_buf_resize(zfo->b, rz_buf_tell(zfo->b) + count);
617 }
618 
620  return rz_buf_resize(zfo->b, size > 0 ? size : 0);
621 }
622 
623 static bool rz_io_zip_resize(RzIO *io, RzIODesc *fd, ut64 size) {
624  RzIOZipFileObj *zfo;
625  if (!fd || !fd->data) {
626  return false;
627  }
628  zfo = fd->data;
629  if (rz_io_zip_truncate_buf(zfo, size)) {
630  zfo->modified = 1;
632  return true;
633  }
634  return false;
635 }
636 
637 static int rz_io_zip_write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count) {
638  RzIOZipFileObj *zfo;
639  int ret = 0;
640  if (!fd || !fd->data || !buf) {
641  return -1;
642  }
643  zfo = fd->data;
644  if (!(zfo->perm & RZ_PERM_W)) {
645  return -1;
646  }
647  if (rz_buf_tell(zfo->b) + count >= rz_buf_size(zfo->b)) {
649  }
650  if (rz_buf_size(zfo->b) < io->off) {
651  io->off = rz_buf_size(zfo->b);
652  }
653  zfo->modified = 1;
654  ret = rz_buf_write_at(zfo->b, io->off, buf, count);
655  if (ret >= 0) {
656  rz_buf_seek(zfo->b, ret, RZ_BUF_CUR);
657  }
658  // XXX - Implement a flush of some sort, but until then, lets
659  // just write through
661  return ret;
662 }
663 
665  RzIOZipFileObj *zfo;
666  if (!fd || !fd->data) {
667  return -1;
668  }
669  zfo = fd->data;
671  zfo = fd->data = NULL;
672  return 0;
673 }
674 
676  .name = "zip",
677  .desc = "Open zip files",
678  .uris = "zip://,apk://,ipa://,jar://,zipall://,apkall://,ipaall://,jarall://",
679  .license = "BSD",
680  .open = rz_io_zip_open,
681  .open_many = rz_io_zip_open_many,
682  .write = rz_io_zip_write,
683  .read = rz_io_zip_read,
684  .close = rz_io_zip_close,
685  .lseek = rz_io_zip_lseek,
686  .check = rz_io_zip_plugin_open,
687  .resize = rz_io_zip_resize,
688 };
689 
690 #ifndef RZ_PLUGIN_INCORE
692  .type = RZ_LIB_TYPE_IO,
693  .data = &rz_io_plugin_zip,
695 };
696 #endif
size_t len
Definition: 6502dis.c:15
lzma_index ** i
Definition: index.h:629
static SblHeader sb
Definition: bin_mbn.c:26
const char * desc
Definition: bin_vsf.c:19
#define RZ_API
#define NULL
Definition: cris-opc.c:27
#define r
Definition: crypto_rc6.c:12
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
uint32_t ut32
const char * v
Definition: dsignal.c:12
struct tab * done
Definition: enough.c:233
checking print the parsed form of the magic use in n conjunction with m to debug a new magic file n before installing it n output MIME type special files
Definition: file_opts.h:46
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RzList * rz_io_zip_get_files(const char *archivename, ut32 perm, int mode, int rw)
Definition: io_zip.c:160
static RzIOZipConstURI ZIP_ALL_URIS[]
Definition: io_zip.c:33
static ut64 rz_io_zip_lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence)
Definition: io_zip.c:568
static RzIODesc * rz_io_zip_open(RzIO *io, const char *file, int rw, int mode)
Definition: io_zip.c:449
struct zip * rz_io_zip_open_archive(const char *archivename, ut32 perm, int mode, int rw)
Definition: io_zip.c:95
static int rz_io_zip_read(RzIO *io, RzIODesc *fd, ut8 *buf, int count)
Definition: io_zip.c:599
static bool rz_io_zip_resize(RzIO *io, RzIODesc *fd, ut64 size)
Definition: io_zip.c:623
static RzIOZipConstURI ZIP_URIS[]
Definition: io_zip.c:25
static int rz_io_zip_close(RzIODesc *fd)
Definition: io_zip.c:664
static bool rz_io_zip_truncate_buf(RzIOZipFileObj *zfo, int size)
Definition: io_zip.c:619
RzIOPlugin rz_io_plugin_zip
Definition: io_zip.c:675
RZ_API RzLibStruct rizin_plugin
Definition: io_zip.c:691
static bool rz_io_zip_plugin_open(RzIO *io, const char *file, bool many)
Definition: io_zip.c:85
struct rz_io_zip_uri_const_t RzIOZipConstURI
RzIOZipFileObj * rz_io_zip_alloc_zipfileobj(const char *archivename, const char *filename, ut32 perm, int mode, int rw)
Definition: io_zip.c:252
int rz_io_zip_flush_file(RzIOZipFileObj *zfo)
Definition: io_zip.c:188
static char * find_apk_binary(const char *filename, int rw, int mode, RzIO *io)
Definition: io_zip.c:409
static int rz_io_zip_realloc_buf(RzIOZipFileObj *zfo, int count)
Definition: io_zip.c:615
static RzList * rz_io_zip_open_many(RzIO *io, const char *file, int rw, int mode)
Definition: io_zip.c:284
static char * find_ipa_binary(const char *filename, int rw, int mode)
Definition: io_zip.c:376
RzIOZipFileObj * rz_io_zip_create_new_file(const char *archivename, const char *filename, struct zip_stat *sb, ut32 perm, int mode, int rw)
Definition: io_zip.c:236
static int rz_io_zip_has_uri_substr(const char *file)
Definition: io_zip.c:57
static void rz_io_zip_free_zipfileobj(RzIOZipFileObj *zfo)
Definition: io_zip.c:223
static int rz_io_zip_check_uri(const char *file)
Definition: io_zip.c:73
char * rz_io_zip_get_by_file_idx(const char *archivename, const char *idx, ut32 perm, int mode, int rw)
Definition: io_zip.c:348
static int rz_io_zip_check_uri_many(const char *file)
Definition: io_zip.c:61
RZ_IO_ZIP_ARCHIVE_TYPE
Definition: io_zip.c:11
@ RZ_IO_DELETED_FILE
Definition: io_zip.c:17
@ RZ_IO_PARENT_ZIP
Definition: io_zip.c:12
@ RZ_IO_EXISTING_FILE
Definition: io_zip.c:15
@ RZ_IO_CHILD_FILE
Definition: io_zip.c:13
@ RZ_IO_NEW_FILE
Definition: io_zip.c:14
@ RZ_IO_MODIFIED_FILE
Definition: io_zip.c:16
static int rz_io_zip_write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count)
Definition: io_zip.c:637
static int rz_io_zip_slurp_file(RzIOZipFileObj *zfo)
Definition: io_zip.c:122
struct rz_io_zfo_t RzIOZipFileObj
voidpf void uLong size
Definition: ioapi.h:138
const char * filename
Definition: ioapi.h:137
voidpf uLong offset
Definition: ioapi.h:144
const char int mode
Definition: ioapi.h:137
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
Definition: list.c:235
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
Definition: list.c:288
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
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)
Definition: zip_fclose.c:41
#define ZIP_ER_OPEN
Definition: zip.h:116
ZIP_EXTERN zip_int64_t zip_add(zip_t *_Nonnull, const char *_Nonnull, zip_source_t *_Nonnull)
Definition: zip_add.c:47
#define ZIP_ER_NOENT
Definition: zip.h:114
ZIP_EXTERN int zip_get_num_files(zip_t *_Nonnull)
ZIP_EXTERN void zip_stat_init(zip_stat_t *_Nonnull)
Definition: zip_stat_init.c:40
#define ZIP_CREATE
Definition: zip.h:67
ZIP_EXTERN zip_int64_t zip_fread(zip_file_t *_Nonnull, void *_Nonnull, zip_uint64_t)
Definition: zip_fread.c:39
ZIP_EXTERN int zip_close(zip_t *_Nonnull)
Definition: zip_close.c:52
#define ZIP_ER_INVAL
Definition: zip.h:123
ZIP_EXTERN void zip_source_free(zip_source_t *_Nullable)
ZIP_EXTERN zip_t *_Nullable zip_open(const char *_Nonnull, int, int *_Nullable)
Definition: zip_open.c:54
ZIP_EXTERN int zip_replace(zip_t *_Nonnull, zip_uint64_t, zip_source_t *_Nonnull)
Definition: zip_replace.c:40
ZIP_EXTERN int zip_stat_index(zip_t *_Nonnull, zip_uint64_t, zip_flags_t, zip_stat_t *_Nonnull)
#define ZIP_ER_NOZIP
Definition: zip.h:124
#define ZIP_ER_INCONS
Definition: zip.h:126
ZIP_EXTERN zip_file_t *_Nullable zip_fopen_index(zip_t *_Nonnull, zip_uint64_t, zip_flags_t)
#define ZIP_ER_READ
Definition: zip.h:110
ZIP_EXTERN zip_source_t *_Nullable zip_source_buffer(zip_t *_Nonnull, const void *_Nullable, zip_uint64_t, int)
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
int idx
Definition: setup.py:197
const char * name
Definition: op.c:541
#define eprintf(x, y...)
Definition: rlcc.c:7
static RzSocket * s
Definition: rtr.c:28
RZ_API ut64 rz_buf_tell(RZ_NONNULL RzBuffer *b)
Return the current cursor position.
Definition: buf.c:1238
RZ_API bool rz_buf_resize(RZ_NONNULL RzBuffer *b, ut64 newsize)
Resize the buffer size.
Definition: buf.c:890
RZ_API st64 rz_buf_seek(RZ_NONNULL RzBuffer *b, st64 addr, int whence)
Modify the current cursor position in the buffer.
Definition: buf.c:1166
#define RZ_BUF_CUR
Definition: rz_buf.h:15
RZ_API st64 rz_buf_write_at(RZ_NONNULL RzBuffer *b, ut64 addr, RZ_NONNULL const ut8 *buf, ut64 len)
Write len bytes of the buffer at the specified address.
Definition: buf.c:1197
RZ_API st64 rz_buf_read_at(RZ_NONNULL RzBuffer *b, ut64 addr, RZ_NONNULL RZ_OUT ut8 *buf, ut64 len)
Read len bytes of the buffer at the specified address.
Definition: buf.c:1136
#define RZ_BUF_SET
Definition: rz_buf.h:14
RZ_API void rz_buf_free(RzBuffer *b)
Free all internal data hold by the buffer and the buffer.
Definition: buf.c:1253
RZ_API bool rz_buf_set_bytes(RZ_NONNULL RzBuffer *b, RZ_NONNULL const ut8 *buf, ut64 len)
Replace the content of the buffer with the bytes array.
Definition: buf.c:905
RZ_API RZ_OWN RzBuffer * rz_buf_new_with_bytes(RZ_NULLABLE RZ_BORROW const ut8 *bytes, ut64 len)
Creates a new buffer with a bytes array.
Definition: buf.c:465
RZ_DEPRECATE RZ_API RZ_BORROW ut8 * rz_buf_data(RZ_NONNULL RzBuffer *b, RZ_NONNULL RZ_OUT ut64 *size)
Return a borrowed array of bytes representing the buffer data.
Definition: buf.c:1287
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
Definition: buf.c:1225
RZ_API void rz_io_desc_free(RzIODesc *desc)
Definition: io_desc.c:35
RZ_API bool rz_io_desc_add(RzIO *io, RzIODesc *desc)
Definition: io_desc.c:49
RZ_API RzIODesc * rz_io_desc_new(RzIO *io, RzIOPlugin *plugin, const char *uri, int flags, int mode, void *data)
Definition: io_desc.c:11
@ RZ_LIB_TYPE_IO
Definition: rz_lib.h:69
#define RZ_LOG_INFO(fmtstr,...)
Definition: rz_log.h:54
RZ_API int rz_num_rand(int max)
Definition: unum.c:47
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API const char * rz_str_rchr(const char *base, const char *p, int ch)
Definition: str.c:829
RZ_API bool rz_str_endswith(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string ends with a specifc sequence of characters (case sensitive)
Definition: str.c:3329
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define RZ_PERM_W
Definition: rz_types.h:94
#define RZ_FREE(x)
Definition: rz_types.h:369
#define RZ_VERSION
Definition: rz_version.h:8
Definition: gzappend.c:170
Definition: z80asm.h:102
const char * name
Definition: rz_io.h:115
const char * version
Definition: rz_io.h:117
Definition: rz_io.h:59
ut64 off
Definition: rz_io.h:61
PrintfCallback cb_printf
Definition: rz_io.h:91
char * name
Definition: io_zip.c:42
ut64 entry
Definition: io_zip.c:48
RzBuffer * b
Definition: io_zip.c:51
ut8 encryption_value
Definition: io_zip.c:53
RzIO * io_backref
Definition: io_zip.c:54
char * password
Definition: io_zip.c:52
int mode
Definition: io_zip.c:44
int opened
Definition: io_zip.c:47
int perm
Definition: io_zip.c:49
char * archivename
Definition: io_zip.c:43
int rw
Definition: io_zip.c:45
ut8 modified
Definition: io_zip.c:50
int fd
Definition: io_zip.c:46
const char * name
Definition: io_zip.c:21
Definition: zip.h:300
Definition: zipint.h:278
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static const z80_opcode fd[]
Definition: z80_tab.h:997
#define SEEK_SET
Definition: zip.c:88
#define SEEK_CUR
Definition: zip.c:80
#define SEEK_END
Definition: zip.c:84