Beispiel #1
0
QString KTNEFMessage::rtfString()
{
	QVariant prop = property( 0x1009 );
	if ( prop.isNull() || prop.type() != QVariant::ByteArray)
		return QString::null;
	else
	{
		QByteArray rtf;
		QBuffer input( prop.asByteArray() ), output( rtf );
		if ( input.open( IO_ReadOnly ) && output.open( IO_WriteOnly ) )
			lzfu_decompress( &input, &output );
		return QString( rtf );
	}
}
Beispiel #2
0
int main( int argc, char * const argv[] )
#endif
{
	char destination[ 128 ];

	libcerror_error_t *error           = NULL;
	libcfile_file_t *destination_file  = NULL;
	libcfile_file_t *source_file       = NULL;
	uint8_t *buffer                    = NULL;
	uint8_t *uncompressed_data         = NULL;
	char *program                      = "lzfudecompress";
	char *source                       = NULL;
	libcstring_system_integer_t option = 0;
	size64_t source_size               = 0;
	off_t source_offset                = 0;
	size_t uncompressed_data_size      = 0;
	ssize_t read_count                 = 0;
	ssize_t write_count                = 0;
	int print_count                    = 0;
	int result                         = 0;
	int verbose                        = 0;

	assorted_output_version_fprint(
	 stdout,
	 program );

	while( ( option = libcsystem_getopt(
	                   argc,
	                   argv,
	                   _LIBCSTRING_SYSTEM_STRING( "ho:s:vV" ) ) ) != (libcstring_system_integer_t) -1 )
	{
		switch( option )
		{
			case '?':
			default:
				fprintf(
				 stderr,
				 "Invalid argument: %" PRIs_LIBCSTRING_SYSTEM "\n",
				 argv[ optind ] );

				usage_fprint(
				 stdout );

				return( EXIT_FAILURE );

			case 'h':
				usage_fprint(
				 stdout );

				return( EXIT_SUCCESS );

			case 'o':
				source_offset = atol( optarg );

				break;

			case 's':
				source_size = atol( optarg );

				break;

			case 'v':
				verbose = 1;

				break;

			case 'V':
				assorted_output_copyright_fprint(
				 stdout );

				return( EXIT_SUCCESS );
		}
	}
	if( optind == argc )
	{
		fprintf(
		 stderr,
		 "Missing source file.\n" );

		usage_fprint(
		 stdout );

		return( EXIT_FAILURE );
	}
	source = argv[ optind ];

	libcnotify_stream_set(
	 stderr,
	 NULL );
	libcnotify_verbose_set(
	 verbose );

	/* Open the source file
	 */
	if( libcfile_file_initialize(
	     &source_file,
	     &error ) != 1 )
	{
		fprintf(
		 stderr,
		 "Unable to create source file.\n" );

		goto on_error;
	}
	if( libcfile_file_open(
	     source_file,
	     source,
	     LIBCFILE_OPEN_READ,
	     &error ) != 1 )
	{
		fprintf(
		 stderr,
		 "Unable to open source file.\n" );

		goto on_error;
	}
	if( source_size == 0 )
	{
		if( libcfile_file_get_size(
		     source_file,
		     &source_size,
		     &error ) == -1 )
		{
			fprintf(
			 stderr,
			 "Unable to determine size of source file.\n" );

			goto on_error;
		}
	}
	if( source_size == 0 )
	{
		fprintf(
		 stderr,
		 "Invalid source size value is zero.\n" );

		goto on_error;
	}
	if( source_size > (size64_t) ( SSIZE_MAX / 16 ) )
	{
		fprintf(
		 stderr,
		 "Invalid source size value exceeds maximum.\n" );

		goto on_error;
	}
	buffer = (uint8_t *) memory_allocate(
	                      sizeof( uint8_t ) * source_size );

	if( buffer == NULL )
	{
		fprintf(
		 stderr,
		 "Unable to create buffer.\n" );

		goto on_error;
	}
	uncompressed_data_size = source_size * 16;

	uncompressed_data = (uint8_t *) memory_allocate(
	                                 sizeof( uint8_t ) * uncompressed_data_size );

	if( uncompressed_data == NULL )
	{
		fprintf(
		 stderr,
		 "Unable to create uncompressed data buffer.\n" );

		goto on_error;
	}
	/* Position the source file at the right offset
	 */
	if( libcfile_file_seek_offset(
	     source_file,
	     source_offset,
	     SEEK_SET,
	     &error ) == -1 )
	{
		fprintf(
		 stderr,
		 "Unable to seek offset in source file.\n" );

		goto on_error;
	}
	print_count = libcstring_narrow_string_snprintf(
	               destination,
	               128,
	               "%s.lzfudecompressed",
	               source );

	if( ( print_count < 0 )
	 || ( print_count > 128 ) )
	{
		fprintf(
		 stderr,
		 "Unable to set destination filename.\n" );

		goto on_error;
	}
	/* Read and decompress the data
	 */
	read_count = libcfile_file_read_buffer(
		      source_file,
		      buffer,
		      source_size,
	              &error );

	if( read_count != (ssize_t) source_size )
	{
		fprintf(
		 stderr,
		 "Unable to read from source file.\n" );

		goto on_error;
	}
	if( lzfu_decompress(
	     buffer,
	     source_size,
	     uncompressed_data,
	     &uncompressed_data_size,
	     &error ) != 1 )
	{
		fprintf(
		 stderr,
		 "Unable to decompress data.\n" );

		goto on_error;
	}
	/* Open the destination file
	 */
	if( libcfile_file_initialize(
	     &destination_file,
	     &error ) != 1 )
	{
		fprintf(
		 stderr,
		 "Unable to create destination file.\n" );

		goto on_error;
	}
	if( libcfile_file_open(
	     destination_file,
	     destination,
	     LIBCFILE_OPEN_WRITE,
	     &error ) != 1 )
	{
		fprintf(
		 stderr,
		 "Unable to open destination file.\n" );

		goto on_error;
	}
	write_count = libcfile_file_write_buffer(
		       destination_file,
		       uncompressed_data,
		       uncompressed_data_size,
		       &error );

	if( write_count != (ssize_t) uncompressed_data_size )
	{
		fprintf(
		 stderr,
		 "Unable to write to destination file.\n" );

		goto on_error;
	}
	/* Clean up
	 */
	if( libcfile_file_close(
	     destination_file,
	     &error ) != 0 )
	{
		fprintf(
		 stderr,
		 "Unable to close destination file.\n" );

		goto on_error;
	}
	if( libcfile_file_free(
	     &destination_file,
	     &error ) != 1 )
	{
		fprintf(
		 stderr,
		 "Unable to free destination file.\n" );

		goto on_error;
	}
	if( libcfile_file_close(
	     source_file,
	     &error ) != 0 )
	{
		fprintf(
		 stderr,
		 "Unable to close source file.\n" );

		goto on_error;
	}
	if( libcfile_file_free(
	     &source_file,
	     &error ) != 1 )
	{
		fprintf(
		 stderr,
		 "Unable to free source file.\n" );

		goto on_error;
	}
	memory_free(
	 uncompressed_data );

	memory_free(
	 buffer );

	if( result == -1 )
	{
		fprintf(
		 stdout,
		 "LZFu decompression:\tFAILURE\n" );

		return( EXIT_FAILURE );
	}
	fprintf(
	 stdout,
	 "LZFu decompression:\tSUCCESS\n" );

	return( EXIT_SUCCESS );

on_error:
	if( error != NULL )
	{
		libcnotify_print_error_backtrace(
		 error );
		libcerror_error_free(
		 &error );
	}
	if( destination_file != NULL )
	{
		libcfile_file_free(
		 &destination_file,
		 NULL );
	}
	if( uncompressed_data != NULL )
	{
		memory_free(
		 uncompressed_data );
	}
	if( buffer != NULL )
	{
		memory_free(
		 buffer );
	}
	if( source_file != NULL )
	{
		libcfile_file_free(
		 &source_file,
		 NULL );
	}
	return( EXIT_FAILURE );
}