示例#1
0
文件: io_zip.c 项目: csarn/radare2
// Below this line are the r_io_zip plugin APIs
static RList *r_io_zip_open_many(RIO *io, const char *file, int rw, int mode) {
	RList *list_fds = NULL;
	RListIter *iter;
	RList *filenames = NULL;
	RIODesc *res = NULL;
	RIOZipFileObj *zfo = NULL;
	char *filename_in_zipfile, *zip_filename = NULL, *zip_uri;

	if (!r_io_zip_plugin_open (io, file, true)) {
		return NULL;
	}

	zip_uri = strdup (file);
	if (!zip_uri) {
		return NULL;
	}
	// 1) Tokenize to the '//' and find the base file directory ('/')
	zip_filename = strstr(zip_uri, "//");
	if (zip_filename && zip_filename[2]) {
		if (zip_filename[0] && zip_filename[0] == '/' &&
			zip_filename[1] && zip_filename[1] == '/' ) {
			*zip_filename++ = 0;
		}
		*zip_filename++ = 0;
	} else {
		free (zip_uri);
		return NULL;
	}

	filenames = r_io_zip_get_files(zip_filename, 0, mode, rw );

	if (!filenames) {
		free (zip_uri);
		return NULL;
	}

	list_fds = r_list_new ();
	r_list_foreach (filenames, iter, filename_in_zipfile) {
		size_t v = strlen (filename_in_zipfile);

		if (filename_in_zipfile[v - 1] == '/') {
			continue;
		}

		zfo = r_io_zip_alloc_zipfileobj (zip_filename,
			filename_in_zipfile, ZIP_CREATE, mode, rw);

		if (zfo && zfo->entry == -1) {
			eprintf ("Warning: File did not exist, creating a new one.\n");
		}

		if (zfo) {
			zfo->io_backref = io;
			res = r_io_desc_new (io, &r_io_plugin_zip,
				zfo->name, rw, mode, zfo);
		}
		r_list_append (list_fds, res);
	}
示例#2
0
文件: io_zip.c 项目: jdukes/radare2
// Below this line are the r_io_zip plugin APIs
static RIODesc *r_io_zip_open(RIO *io, const char *file, int rw, int mode) {
	RIODesc *result = NULL;
	RIOZipFileObj *zipFileObj = NULL;

	char *zip_uri = NULL, *zip_filename = NULL, *filename_in_zipfile = NULL;
	if (!r_io_zip_plugin_open (io, file)) {
		return result;
	}

	zip_uri = strdup(file);
	// 1) Tokenize to the '//' and find the base file directory ('/')
	zip_filename = strstr(zip_uri, "//");
	if (zip_filename && zip_filename[2]) {
		if (zip_filename[0] && zip_filename[0] == '/' &&
			zip_filename[1] && zip_filename[1] == '/' ) {
			*zip_filename++ = 0;	
		}
		*zip_filename++ = 0;

		filename_in_zipfile = strstr(zip_filename, "//");
		if (filename_in_zipfile && filename_in_zipfile[2]) {
			// null terminating uri to filename here.
			*filename_in_zipfile++ = 0;
			*filename_in_zipfile++ = 0;
		}
	}

	if (!zip_filename) {// && !filename_in_zipfile) {
		if (zip_uri)
			free(zip_uri);
		eprintf("usage: zip:///path/to/archive//filepath\n");
		eprintf("Archive was not found.\n");

		return result;
	}

	// Failed to find the file name the archive.
	if (!filename_in_zipfile) {
		RList *files = NULL;
		RListIter *iter, *iter_tmp;
		char *name;
		//eprintf("usage: zip:///path/to/archive//filepath\n");
		eprintf("\nFiles in archive\n\n");
		files = r_io_zip_get_files(zip_filename, 0, mode, rw );

		if (files) {
			int i = 0;
			r_list_foreach_safe(files, iter, iter_tmp, name) {
				// XXX - io->printf does not flush
				// io->printf("%s\n", name);
				r_cons_printf("%s\n", name);
				r_cons_flush ();
				free (name);
				r_list_delete (files, iter);
			}
			r_list_free (files);
		}