예제 #1
0
파일: io_zip.c 프로젝트: csarn/radare2
int r_io_zip_flush_file(RIOZipFileObj *zfo) {
	int res = false;
	struct zip * zipArch;

	if (!zfo) {
		return res;
	}

	zipArch = r_io_zip_open_archive (
		zfo->archivename, zfo->perm, zfo->mode, zfo->rw);
	if (!zipArch) {
		return res;
	}

	struct zip_source *s = zip_source_buffer (zipArch, zfo->b->buf, zfo->b->length, 0);
	if (s && zfo->entry != -1) {
		if (zip_replace(zipArch, zfo->entry, s) == 0) {
			res = true;
		}
	} else if (s && zfo->name) {
		if (zip_add (zipArch, zfo->name, s) == 0) {
			zfo->entry = zip_name_locate (zipArch, zfo->name, 0);
			res = true;
		}
	}
	// s (zip_source) is freed when the archive is closed, i think - dso
	zip_close (zipArch);
	if (s) {
		zip_source_free (s);
	}
	return res;
}
예제 #2
0
파일: io_zip.c 프로젝트: csarn/radare2
/* The file can be a file in the archive or ::[num].  */
RIOZipFileObj* r_io_zip_alloc_zipfileobj(const char *archivename, const char *filename, ut32 perm, int mode, int rw) {
	RIOZipFileObj *zfo = NULL;
	ut64 i, num_entries;
	struct zip_stat sb;
	struct zip *zipArch = r_io_zip_open_archive (archivename, perm, mode, rw);
	if (!zipArch) {
		return NULL;
	}
	num_entries = zip_get_num_files (zipArch);

	for (i = 0; i < num_entries; i++) {
		zip_stat_init (&sb);
		zip_stat_index (zipArch, i, 0, &sb);
		if (sb.name != NULL) {
			if (strcmp (sb.name, filename) == 0) {
				zfo = r_io_zip_create_new_file (
					archivename, filename, &sb,
					perm, mode, rw);
				r_io_zip_slurp_file (zfo);
				break;
			}
		}
	}
	if (!zfo) {
		zfo = r_io_zip_create_new_file (archivename,
			filename, NULL, perm, mode, rw);
	}
	zip_close (zipArch);
	return zfo;
}
예제 #3
0
파일: io_zip.c 프로젝트: csarn/radare2
static int r_io_zip_slurp_file(RIOZipFileObj *zfo) {
	struct zip_file *zFile = NULL;
	struct zip *zipArch;
	struct zip_stat sb;
	bool res = false;
	if (!zfo) {
		return res;
	}
	zipArch = r_io_zip_open_archive (
		zfo->archivename, zfo->perm,
		zfo->mode, zfo->rw);

	if (zipArch && zfo && zfo->entry != -1) {
		zFile = zip_fopen_index (zipArch, zfo->entry, 0);
		if (!zfo->b) {
			zfo->b = r_buf_new ();
		}
		zip_stat_init (&sb);
		if (zFile && zfo->b && !zip_stat_index (zipArch, zfo->entry, 0, &sb)) {
			ut8 *buf = malloc (sb.size);
			memset (buf, 0, sb.size);
			if (buf) {
				zip_fread (zFile, buf, sb.size);
				r_buf_set_bytes (zfo->b, buf, sb.size);
				res = true;
				zfo->opened = true;
				free (buf);
			}
		}
		zip_fclose (zFile);
	}
	zip_close (zipArch);
	return res;
}
예제 #4
0
파일: io_zip.c 프로젝트: CodingFree/radare2
int r_io_zip_slurp_file(RIOZipFileObj *zfo) {
	int res = R_FALSE;
	struct zip_stat sb;
	struct zip_file *zFile = NULL;
	struct zip * zipArch ;

	if (!zfo) return res;
	zipArch = r_io_zip_open_archive (
		zfo->archivename, zfo->flags,
		zfo->mode, zfo->rw);
	//eprintf("Slurping file");

	if (zipArch && zfo && zfo->entry != -1) {
		zFile = zip_fopen_index (zipArch, zfo->entry, 0);
		if (!zfo->b)
			zfo->b = r_buf_new ();
		zip_stat_init (&sb);
		if (zFile && zfo->b && !zip_stat_index(zipArch,
				zfo->entry, 0, &sb) ) {
			ut8 *buf = malloc (sb.size);
			memset (buf, 0, sb.size);
			if (buf) {
				zip_fread (zFile, buf, sb.size);
				r_buf_set_bytes (zfo->b, buf, sb.size);
				res = zfo->opened = R_TRUE;
				free (buf);
			}
		}
		zip_fclose (zFile);
	}
	zip_close (zipArch);
	return res;
}
예제 #5
0
파일: io_zip.c 프로젝트: jdukes/radare2
int r_io_zip_flush_file(RIOZipFileObj *zip_file_obj) {
	int result = R_FALSE;
	struct zip * zipArch = r_io_zip_open_archive(zip_file_obj->archivename, zip_file_obj->flags, zip_file_obj->mode, zip_file_obj->rw);  

	if (!zipArch) {
		return result;
	}

	if (zip_file_obj) {
		struct zip_source *s = zip_source_buffer(zipArch, zip_file_obj->b, zip_file_obj->b->length, 0);
		if (s && zip_file_obj->entry != -1) {

			if (zip_replace(zipArch, zip_file_obj->entry, s) == 0)
				result = R_TRUE;

		}else if (s && zip_file_obj->name) {

			if (zip_add(zipArch, zip_file_obj->name, s) == 0) {

				zip_file_obj->entry = zip_name_locate(zipArch, zip_file_obj->name, 0);
				result = R_TRUE;
			}
		}
		if (s)
			zip_source_free(s);		

	}

	if (zipArch)
		zip_close(zipArch);

	return result;
}
예제 #6
0
파일: io_zip.c 프로젝트: jdukes/radare2
RList * r_io_zip_get_files(char *archivename, ut32 flags, int mode, int rw) {
	ut64 num_entries = 0, i = 0;
	struct zip * zipArch = r_io_zip_open_archive(archivename, flags, mode, rw);
	struct zip_stat sb; 
	RList *files = NULL; 
	//eprintf("Slurping file");
	if (zipArch) {
		files = r_list_new();
		num_entries = zip_get_num_files(zipArch);

		for (i=0; i < num_entries; i++) {
			char *name = NULL;	
			zip_stat_init(&sb );
			zip_stat_index(zipArch, i, 0, &sb );	
			//eprintf("Comparing %s == %s = %d\n", sb.name, filename, strcmp(sb.name, filename));
			name = strdup(sb.name);
			if (name) {
				r_list_append(files, name);
			}

		}
	}
	if (zipArch)
		zip_close(zipArch);

	return files;
}
예제 #7
0
파일: io_zip.c 프로젝트: csarn/radare2
RList * r_io_zip_get_files(char *archivename, ut32 perm, int mode, int rw) {
	struct zip *zipArch = r_io_zip_open_archive (archivename, perm, mode, rw);
	ut64 num_entries = 0, i = 0;
	RList *files = NULL;
	struct zip_stat sb;
	char *name;
	if (zipArch) {
		files = r_list_newf (free);
		if (!files) {
			zip_close (zipArch);
			return NULL;
		}
		num_entries = zip_get_num_files (zipArch);
		for (i = 0; i < num_entries; i++) {
			zip_stat_init (&sb);
			zip_stat_index (zipArch, i, 0, &sb);
			if ((name = strdup (sb.name))) {
				r_list_append (files, name);
			}
		}
	}
	zip_close (zipArch);
	return files;
}