Ejemplo n.º 1
0
static RIODesc *ewf__open(RIO *io, const char *pathname, int rw, int mode) {
	RIOEwf *rewf;
	libewf_handle_t *ewf_h;
	// XXX filename list should be dynamic. 1024 limit is ugly
	const char *filenames[1024];
	char *ptr,*optr;
	ut8 hash[1024];
	size64_t media_size;
	uint32_t bytes_per_sector;
	//uint64_t amount_of_sectors;
	uint32_t error_granularity;
	//uint32_t amount_of_acquiry_errors;
	int8_t compression_level;
	uint8_t media_type;
	uint8_t media_flags;
	uint8_t compress_empty_block;
	uint8_t format;
	int i;

	if (!memcmp (pathname, "els://", 6)) {
		FILE *fd = r_sandbox_fopen (pathname+6, "r");
		ut64 len;
		char *buf;

		if (fd == NULL)
			return NULL;
		fseek (fd, 0, SEEK_END);
		len = ftell (fd);
		fseek(fd, 0, SEEK_SET);
		buf = (char *)malloc (len);
		fread (buf, len, 1, fd);
		
		ptr = strchr (buf, '\n');
		for (i=0, optr = buf; ptr&&(ptr=strchr(ptr, '\n')); optr=ptr) {
			*ptr = '\0';
			ptr++;
			filenames[i++] = optr;
		}
		filenames[i] = NULL;

		free (buf);
		fclose (fd);

		for (i=0; filenames[i]; i++)
			eprintf ("%02x: %s)\n", i, filenames[i]);
	} else {
		filenames[0] = pathname + 6;
		filenames[1] = NULL;
	}
	libewf_handle_initialize (&ewf_h, NULL);
	if (libewf_handle_open (ewf_h, (char * const *)filenames, (int)1, rw?
			LIBEWF_OPEN_READ_WRITE: LIBEWF_OPEN_READ, NULL) != 1)
		return NULL;
#if 0
		if( ((libewf_internal_plugin_t*)ewf_h)->header_values == NULL ) {
			fprintf( stream, "\tNo information found in file.\n" );
		} else {
			libewf_get_header_value_examiner_name(ewf_h, hash, 128);
			eprintf("ExaminerName:     %s\n", hash);
			libewf_get_header_value_case_number(ewf_h, hash, 128);
			eprintf("CaseNumber:       %s\n", hash);
		}
#endif
	libewf_handle_get_format (ewf_h, &format, NULL);
	eprintf ("FormatVersion:    %d\n", format);
	libewf_handle_get_compression_values (ewf_h,
		&compression_level, &compress_empty_block, NULL);
	eprintf ("CompressionLevel: %d\n", compression_level);
	libewf_handle_get_error_granularity (ewf_h, &error_granularity, NULL);
	eprintf ("ErrorGranurality: %d\n", error_granularity);
	//libewf_handle_get_number_of_sectors (ewf_h, &amount_of_sectors, NULL);
	//eprintf ("AmountOfSectors:  %"PFMT64d"\n", amount_of_sectors);
	libewf_handle_get_bytes_per_sector (ewf_h, &bytes_per_sector, NULL);
	eprintf ("BytesPerSector:   %d\n", bytes_per_sector);
	libewf_handle_get_media_size (ewf_h, &media_size, NULL);
	eprintf ("MediaSize:        %"PFMT64d"\n", media_size);
	libewf_handle_get_media_type (ewf_h, &media_type, NULL);
	eprintf ("MediaType:        %d\n", media_type);
	libewf_handle_get_media_flags (ewf_h, &media_flags, NULL);
	eprintf ("MediaFlags:       %d\n", media_flags);
	libewf_handle_get_md5_hash (ewf_h, hash, 128, NULL);
	eprintf ("CalculatedHash:   %s\n", hash);

	rewf = R_NEW (RIOEwf);
	rewf->handle = ewf_h;
	rewf->fd = RIOEWF_TO_FD (rewf);
	return r_io_desc_new (&r_io_plugin_shm, rewf->fd, pathname, rw, mode, rewf);
}
Ejemplo n.º 2
0
Archivo: ewf.c Proyecto: 111X/radare
int ewf_open(const char *pathname, int flags, mode_t mode)
{
	// XXX filename list should be dynamic. 1024 limit is ugly
	const char *filenames[1024];
	char *ptr,*optr;
	char hash[1024];
	size64_t media_size;
	uint32_t bytes_per_sector;
	uint32_t amount_of_sectors;
	uint32_t error_granularity;
	uint32_t amount_of_acquiry_errors;
	int8_t compression_level;
	int8_t media_type;
	int8_t media_flags;
	int8_t volume_type;
	uint8_t compress_empty_block;
	uint8_t format;
	int i;

	if (!memcmp(pathname, "els://", 6)) {
		FILE *fd = fopen(pathname+6, "r");
		ut64 len;
		char *buf;

		if (fd == NULL)
			return -1;
		fseek(fd, 0, SEEK_END);
		len = ftell(fd);
		fseek(fd, 0, SEEK_SET);
		buf = (char *)malloc(len);
		fread(buf, len, 1, fd);
		
		ptr = strchr(buf, '\n');
		for(i=0,optr = buf;ptr&&(ptr=strchr(ptr, '\n'));optr=ptr) {
			ptr[0] = '\0';
			ptr = ptr + 1;
			filenames[i++] = optr;
		}
		filenames[i] = NULL;

		free(buf);
		fclose(fd);

		for(i=0;filenames[i];i++)
			printf("%02x: %s)\n", i, filenames[i]);
	} else {
		filenames[0] = pathname + 6;
		filenames[1] = NULL;
	}
	
	ewf_h = libewf_open(&filenames, 1, 
		(((int)config_get("file.write"))==0)?
		LIBEWF_OPEN_READ_WRITE:LIBEWF_OPEN_READ);


	if (ewf_h == NULL)
		ewf_fd = -1;
	else {
		ewf_fd = EWF_FD;
#if 0
		if( ((libewf_internal_handle_t*)ewf_h)->header_values == NULL ) {
			fprintf( stream, "\tNo information found in file.\n" );
		} else {
			libewf_get_header_value_examiner_name(ewf_h, hash, 128);
			eprintf("ExaminerName:     %s\n", hash);
			libewf_get_header_value_case_number(ewf_h, hash, 128);
			eprintf("CaseNumber:       %s\n", hash);
#endif
			libewf_get_format(ewf_h, &format);
			eprintf("FormatVersion:    %d\n", format);
			libewf_get_compression_values(ewf_h, &compression_level, &compress_empty_block);
			eprintf("CompressionLevel: %d\n", compression_level);
			libewf_get_error_granularity(ewf_h, &error_granularity);
			eprintf("ErrorGranurality: %d\n", error_granularity);
			libewf_get_amount_of_sectors(ewf_h, &amount_of_sectors);
			eprintf("AmountOfSectors:  %d\n", amount_of_sectors);
			libewf_get_bytes_per_sector(ewf_h, &bytes_per_sector);
			eprintf("BytesPerSector:   %d\n", bytes_per_sector);
			libewf_get_volume_type(ewf_h, &volume_type);
			eprintf("VolumeType:       %d\n", volume_type);
			libewf_get_media_size(ewf_h, &media_size);
			eprintf("MediaSize:        %lld\n", media_size);
			libewf_get_media_type(ewf_h, &media_type);
			eprintf("MediaType:        %d\n", media_type);
			libewf_get_media_flags(ewf_h, &media_flags);
			eprintf("MediaFlags:       %d\n", media_flags);
			libewf_get_md5_hash(ewf_h, hash, 128);
			eprintf("CalculatedHash:   %s\n", hash);
#if 0
		}
#endif
	}

	return ewf_fd;
}