Beispiel #1
0
int ZEXPORT unzOpenCurrentFile2 (
    unzFile file,
    int* method,
    int* level,
    int raw)
{
    return unzOpenCurrentFile3(file, method, level, raw, NULL);
}
Beispiel #2
0
std::vector<unsigned char> Unzip::getFileContent(const std::string & fileName)
{
	std::vector<unsigned char> fileContent;

	if(fileInfos.count(fileName) == 0){
		return fileContent;
	}

	//locate file
	if(! goToFile(fileName)){
		return fileContent;
	}

	//open file
	if(UNZ_OK != unzOpenCurrentFile3(zipfile_handle, NULL, NULL, 0, formatPassword(this->password))){
		return fileContent;
	}

	//read content
	unsigned char buffer[CPPZIP_UNZIP_CHAR_ARRAY_BUFFER_SIZE];

	unsigned int len = 0;
	while((len = unzReadCurrentFile(
			zipfile_handle,
			buffer,
			CPPZIP_UNZIP_CHAR_ARRAY_BUFFER_SIZE))
	){
		for(unsigned int i = 0; i < len; ++i){
			fileContent.push_back(buffer[i]);
		}
	}

	//close file
	if(UNZ_OK != unzCloseCurrentFile(zipfile_handle)){
		return fileContent;
	}

	return fileContent;
}
Beispiel #3
0
int UnCompressZip::unzOpenCurrentFile (unzFile file)
{
  return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
}
Beispiel #4
0
bool Unzip::extractFileTo_Internal(
		const std::string & fileName,
		const std::string & path,
		int max,
		int current,
		const bool & overwriteExistingFile)
{
	if(! containsFile(fileName)){
		return false;
	}

	if(!overwriteExistingFile && doesFileExistOnFileSystem(path)){
		return false;
	}

	bool extraction_ok = true;

	try{
		std::string destinationPath = path;
		beforeFileExtraction(destinationPath);

		boost::filesystem::path p(destinationPath);
		if(createFolderIfNotExists(p.parent_path().string()) == false){
			extraction_ok = false;
		}

		//locate filefileContent
		if(! goToFile(fileName)){
			return false;
		}

		//open file
		if(UNZ_OK != unzOpenCurrentFile3(zipfile_handle, NULL, NULL, 0, formatPassword(this->password))){
			return false;
		}

		//destination
		boost::filesystem::ofstream ofs(p, std::ios::out | std::ios::binary);

		//copy the content
		unsigned char buffer[CPPZIP_UNZIP_CHAR_ARRAY_BUFFER_SIZE];

		unsigned int len = 0;
		while((len = unzReadCurrentFile(
				zipfile_handle,
				buffer,
				CPPZIP_UNZIP_CHAR_ARRAY_BUFFER_SIZE))
		){
			ofs.write((const char *)buffer, len);
		}

		//close file
		if(UNZ_OK != unzCloseCurrentFile(zipfile_handle)){
			return false;
		}

		ofs.flush();

		if(ofs.fail()){
			extraction_ok = false;
		}
		ofs.close();

		fileExtracted(destinationPath, max, current);
	} catch(...){
		return false;
	}

	return extraction_ok;
}
Beispiel #5
0
int ZEXPORT unzOpenCurrentFilePassword (
    unzFile file,
    const char* password)
{
    return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
}
Beispiel #6
0
int ZEXPORT unzOpenCurrentFile (
    unzFile file)
{
    return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
}
static int
gather_bundled_assemblies_from_apk (
		struct DylibMono      *mono,
		const char            *apk,
		MonoBundledAssembly ***bundle,
		int                   *bundle_count)
{
	int fd;
	struct stat buf;
	struct md_mmap_info mmap_info;
	unzFile file;

	zlib_filefunc_def funcs = {
		md_mmap_open_file,  // zopen_file,
		md_mmap_read_file,  // zread_file,
		NULL,               // zwrite_file,
		md_mmap_tell_file,  // ztell_file,
		md_mmap_seek_file,  // zseek_file,
		md_mmap_close_file, // zclose_file
		md_mmap_error_file, // zerror_file
		NULL                // opaque
	};

	if ((fd = open (apk, O_RDONLY)) < 0) {
		log_error (LOG_DEFAULT, "ERROR: Unable to load application package %s.", apk);
		// TODO: throw
		return -1;
	}
	if (fstat (fd, &buf) < 0) {
		close (fd);
		// TODO: throw
		return -1;
	}

	mmap_info.area = mmap (NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
	mmap_info.size = buf.st_size;

	log_info (LOG_ASSEMBLY, "                       start: %08p  end: %08p  len: % 12u        apk: %s", 
			mmap_info.area, mmap_info.area + mmap_info.size, (unsigned int) mmap_info.size, apk);

	close (fd);

	funcs.opaque = &mmap_info;

	if ((file = unzOpen2 (NULL, &funcs)) != NULL) {
		do {
			unz_file_info info;
			uLong offset;
			unsigned int *psize;
			char cur_entry_name [256];
			MonoBundledAssembly *cur;
			int entry_is_overridden = FALSE;

			cur_entry_name [0] = 0;
			if (unzGetCurrentFileInfo (file, &info, cur_entry_name, sizeof (cur_entry_name)-1, NULL, 0, NULL, 0) != UNZ_OK ||
					info.compression_method != 0 ||
					unzOpenCurrentFile3 (file, NULL, NULL, 1, NULL) != UNZ_OK ||
					unzGetRawFileOffset (file, &offset) != UNZ_OK) {
				continue;
			}

			if (strcmp ("typemap.jm", cur_entry_name) == 0) {
				add_type_mapping (&java_to_managed_maps, apk, cur_entry_name, ((const char*) mmap_info.area) + offset);
				continue;
			}
			if (strcmp ("typemap.mj", cur_entry_name) == 0) {
				add_type_mapping (&managed_to_java_maps, apk, cur_entry_name, ((const char*) mmap_info.area) + offset);
				continue;
			}
			if (strncmp ("assemblies/", cur_entry_name, sizeof ("assemblies/")-1) != 0)
				continue;

			// assemblies must be 4-byte aligned, or Bad Things happen
			if ((offset & 0x3) != 0) {
				log_fatal (LOG_ASSEMBLY, "Assembly '%s' is located at a bad address %p\n", cur_entry_name,
						((const unsigned char*) mmap_info.area) + offset);
				log_fatal (LOG_ASSEMBLY, "You MUST run `zipalign` on %s\n", strrchr (apk, '/') + 1);
				exit (FATAL_EXIT_MISSING_ZIPALIGN);
			}

			if (should_register)
				entry_is_overridden = !should_register (strrchr (cur_entry_name, '/') + 1, should_register_data);

			if (ends_with (cur_entry_name, ".mdb") &&
					register_debug_symbols &&
					!entry_is_overridden &&
					*bundle != NULL &&
					register_debug_symbols_for_assembly (mono, cur_entry_name, (*bundle) [*bundle_count-1],
						((const mono_byte*) mmap_info.area) + offset,
						info.uncompressed_size))
				continue;

			if (ends_with (cur_entry_name, ".config") &&
					*bundle != NULL) {
				char *assembly_name = monodroid_strdup_printf ("%s", basename (cur_entry_name));
				// Remove '.config' suffix
				*strrchr (assembly_name, '.') = '\0';

				mono->mono_register_config_for_assembly (assembly_name, ((const char*) mmap_info.area) + offset);

				continue;
			}

			if (!(ends_with (cur_entry_name, ".dll") || ends_with (cur_entry_name, ".exe")))
				continue;

			if (entry_is_overridden)
				continue;

			*bundle = xrealloc (*bundle, sizeof(void*)*(*bundle_count + 1));
			cur = (*bundle) [*bundle_count] = xcalloc (1, sizeof (MonoBundledAssembly));
			++*bundle_count;

			cur->name = monodroid_strdup_printf ("%s", strstr (cur_entry_name, "assemblies/") + sizeof ("assemblies"));
			cur->data = ((const unsigned char*) mmap_info.area) + offset;

			// MonoBundledAssembly::size is const?!
			psize = (unsigned int*) &cur->size;
			*psize = info.uncompressed_size;

			if ((log_categories & LOG_ASSEMBLY) != 0) {
				const char *p = (const char*) cur->data;

				char header[9];
				int i;
				for (i = 0; i < sizeof(header)-1; ++i)
					header[i] = isprint (p [i]) ? p [i] : '.';
				header [sizeof(header)-1] = '\0';

				log_info (LOG_ASSEMBLY, "file-offset: % 8x  start: %08p  end: %08p  len: % 12i  zip-entry:  %s name: %s [%s]",
						(int) offset, cur->data, cur->data + *psize, (int) info.uncompressed_size, cur_entry_name, cur->name, header);
			}

			unzCloseCurrentFile (file);

		} while (unzGoToNextFile (file) == UNZ_OK);
		unzClose (file);
	}

	return 0;
}