Ejemplo n.º 1
0
void do_file(const u8 * base, u32 offset, u32 size, const char *path, const char *name, int mode) {
	int fd;
	u8 *file_data;
	const u8 *srcdata;

	// Allow for uncompressed XIP executable
	if (mode & S_ISVTX) {
		// It seems that the offset may not necessarily be page
		// aligned. This is silly because mkcramfs wastes
		// the alignment space, whereas it might be used if it wasn't
		// bogusly in our file extent.
		//
		// blksize must be a power of 2 for the following to work, but it seems
		// quite likely.

		srcdata = (const u8 *)(((long)(base + offset) + blksize - 1) & ~(blksize - 1));

		//printsize(size, srcdata + size - (base + offset));
		//printf("%s", name);
	} else {
		//printsize(size, compressed_size(base, base + offset, size));
		//printf("%s", name);
	}

	// Check if we are actually unpacking
	if (path[0] == '-') {
		return;
	}
	// Make local copy
	fd = open(path, O_CREAT | O_TRUNC | O_RDWR, mode);
	if (fd == -1) {
		perror("create");
		return;
	};

	if (ftruncate(fd, size) == -1) {
		perror("ftruncate");
		close(fd);
		return;
	}

	file_data = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
	if (file_data == MAP_FAILED) {
		perror("mmap");
		close(fd);
		return;
	}
	// Allow for uncompressed XIP executable
	if (mode & S_ISVTX) {
		memcpy(file_data, srcdata, size);
	} else {
		uncompress_data(base, base + offset, size, file_data);
	}

	munmap(file_data, size);
	close(fd);

}
Ejemplo n.º 2
0
/**
 * unzip_file:
 * @zip_file:   pointer to start of compressed data
 * @unzip_size: the size of the compressed data block
 *
 * Returns a pointer to uncompressed data (maybe NULL)
 */
void *unzip_file(gchar *zip_file, gulong *unzip_size)
{
	void *unzip_data = NULL;
#ifndef HAVE_LIBZ
	goto end;
#else
	gchar *zip_data;
	struct _lfh {
		guint32 sig;
		guint16 extract_version;
		guint16 flags;
		guint16 comp_method;
		guint16 time;
		guint16 date;
		guint32 crc_32;
		guint32 compressed_size;
		guint32 uncompressed_size;
		guint16 filename_len;
		guint16 extra_field_len;
	}  __attribute__ ((__packed__)) *local_file_header = NULL;


	local_file_header = (struct _lfh *) zip_file;
	if (GUINT32_FROM_LE(local_file_header->sig) != 0x04034b50) {
		g_warning("%s(): wrong format", __PRETTY_FUNCTION__);
		g_free(unzip_data);
		goto end;
	}

	zip_data = zip_file + sizeof(struct _lfh)
		+ GUINT16_FROM_LE(local_file_header->filename_len)
		+ GUINT16_FROM_LE(local_file_header->extra_field_len);
	gulong uncompressed_size = GUINT32_FROM_LE(local_file_header->uncompressed_size);
	unzip_data = g_malloc(uncompressed_size);

	if (!(*unzip_size = uncompress_data(unzip_data, uncompressed_size, zip_data, GUINT32_FROM_LE(local_file_header->compressed_size)))) {
		g_free(unzip_data);
		unzip_data = NULL;
		goto end;
	}

#endif
end:
	return(unzip_data);
}
Ejemplo n.º 3
0
void do_symlink(const u8 * base, u32 offset, u32 size, const char *path, const char *name, int mode) {
	// Allocate the uncompressed string
	u8 link_contents[size + 1];

	// do uncompression
	uncompress_data(base, base + offset, size, link_contents);
	link_contents[size] = 0;

	printsize(size, compressed_size(base, base + offset, size));
	printf("%s -> %s", name, link_contents);

	// Check if we are actually unpacking
	if (path[0] == '-') {
		return;
	}
	// Make local copy
	if (symlink((const char *)link_contents, path) == -1) {
		perror(path);
		exit(1);
	}
}
Ejemplo n.º 4
0
static void *unzip_hgt_file(gchar *zip_file, gulong *unzip_size)
{
	void *unzip_data = NULL;
	gchar *zip_data;
	struct _lfh {
		guint32 sig;
		guint16 extract_version;
		guint16 flags;
		guint16 comp_method;
		guint16 time;
		guint16 date;
		guint32 crc_32;
		guint32 compressed_size;
		guint32 uncompressed_size;
		guint16 filename_len;
		guint16 extra_field_len;
	}  __attribute__ ((__packed__)) *local_file_header = NULL;


	local_file_header = (struct _lfh *) zip_file;
	if (local_file_header->sig != 0x04034b50) {
		g_warning("%s(): wrong format", __PRETTY_FUNCTION__);
		g_free(unzip_data);
		goto end;
	}

	zip_data = zip_file + sizeof(struct _lfh) + local_file_header->filename_len + local_file_header->extra_field_len;
	unzip_data = g_malloc(local_file_header->uncompressed_size);
	gulong uncompressed_size = local_file_header->uncompressed_size;

	if (!(*unzip_size = uncompress_data(unzip_data, uncompressed_size, zip_data, local_file_header->compressed_size))) {
		g_free(unzip_data);
		unzip_data = NULL;
		goto end;
	}

end:
	return(unzip_data);
}
Ejemplo n.º 5
0
int fm_unbuild(fm_index *s, uchar ** text, ulong *length) {
	
	int error;
	ulong  i;
	if ((error = read_prologue(s)) < 0 ) {
			free_unbuild_mem(s);
			return error;
	}
	if ((error = uncompress_data(s)) < 0 ) {
			free_unbuild_mem(s);
			return error;
	}
	if ((error = fm_compute_lf(s)) < 0 ) {
			free_unbuild_mem(s);
			return error;
	}

	if ((error = fm_invert_bwt(s)) < 0 ) {
			free_unbuild_mem(s);
			return error;
	}

	ulong real_text_size;
    if(s->skip>1) real_text_size = s->text_size-s->num_marked_rows;
  	else real_text_size = s->text_size;
		
	/* remap text */	
	for(i=0; i<real_text_size; i++) {
		if(s->text[i] == s->specialchar) s->text[i] = s->subchar;
    	s->text[i] = s->inv_char_map[s->text[i]];
	}
	*text = s->text;
	s->text = NULL;
	free_unbuild_mem(s); /* libera memoria allocata */

	*length = real_text_size;
	return FM_OK;
}