⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 libewf_write.c

📁 sleuthit-2.09 一个磁盘的工具集
💻 C
📖 第 1 页 / 共 5 页
字号:
	if( internal_handle->write == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_write_test_chunks_section_full: invalid handle - missing subhandle write.\n" );		return( -1 );	}	if( segment_file_offset > (off_t) INT32_MAX )	{		LIBEWF_WARNING_PRINT( "libewf_write_test_chunks_section_full: invalid segment file offset only values below 2^32 are supported.\n" );		return( -1 );	}	if( internal_handle->write->segment_file_size > (uint32_t) INT32_MAX )	{		LIBEWF_WARNING_PRINT( "libewf_write_test_chunks_section_full: invalid segment file size only values below 2^32 are supported.\n" );		return( 0 );	}	/* Check if a chunks section has been opened	 */	if( internal_handle->write->chunks_section_offset == 0 )	{		LIBEWF_VERBOSE_PRINT( "libewf_write_test_chunks_section_full: no chunks section has been created.\n" );		return( 0 );	}	/* Check if the maximum amount of chunks has been reached	 */	if( ( internal_handle->media->amount_of_chunks != 0 ) && ( internal_handle->media->amount_of_chunks == internal_handle->write->amount_of_chunks ) )	{		LIBEWF_VERBOSE_PRINT( "libewf_write_test_chunks_section_full: all required chunks have been written.\n" );		return( 1 );	}	/* Check if the end of the input has been reached	*/	if( ( internal_handle->write->input_write_size != 0 ) && ( internal_handle->write->input_write_count >= (int64_t) internal_handle->write->input_write_size ) )	{		LIBEWF_VERBOSE_PRINT( "libewf_write_test_chunks_section_full: all required data has been written.\n" );		return( 1 );	}	/* The EWF-S01 and EnCase1 format do not allow for a growth of the offset table	 */	if( ( internal_handle->ewf_format == EWF_FORMAT_S01 ) || ( internal_handle->format == LIBEWF_FORMAT_ENCASE1 ) )	{		if( internal_handle->write->section_amount_of_chunks >= internal_handle->write->chunks_per_chunks_section )		{			LIBEWF_VERBOSE_PRINT( "libewf_write_test_chunks_section_full: no space left for additional chunk.\n" );			return( 1 );		}	}	else	{		remaining_segment_file_size = (int32_t) internal_handle->write->segment_file_size;		/* Calculate the remaining segment file size		 */		remaining_segment_file_size -= (int32_t) segment_file_offset;		/* Leave space for the done or next section		 */		remaining_segment_file_size -= EWF_SECTION_SIZE;		/* Leave space for the table and table2 sections		 */		remaining_segment_file_size -= 2 * ( EWF_SECTION_SIZE + ( (int32_t) internal_handle->write->section_amount_of_chunks * EWF_TABLE_OFFSET_SIZE ) + EWF_CRC_SIZE );		/* Determine if a chunk would fit in the segment file		 */		remaining_segment_file_size -= internal_handle->media->chunk_size + EWF_CRC_SIZE;		if( remaining_segment_file_size <= 0 )		{			LIBEWF_VERBOSE_PRINT( "libewf_write_test_chunks_section_full: no space left for additional chunk.\n" );			return( 1 );		}	}	/* If the maximum offsets in table restriction should apply	 */	if( ( internal_handle->write->unrestrict_offset_amount == 0 ) && ( internal_handle->write->section_amount_of_chunks >= EWF_MAXIMUM_OFFSETS_IN_TABLE ) )	{		LIBEWF_VERBOSE_PRINT( "libewf_write_test_chunks_section_full: no space left for additional chunk.\n" );		return( 1 );	}	LIBEWF_VERBOSE_PRINT( "libewf_write_test_chunks_section_full: space left for additional chunk.\n" );	return( 0 );}#if defined( HAVE_WIDE_CHARACTER_TYPE ) && defined( HAVE_WIDE_CHARACTER_SUPPORT_FUNCTIONS )/* Determines a wide character extension for a certain segment file * For EWF-E01, EWF-S01 segment file extension naming scheme * Returns 1 on success, -1 on error */int8_t libewf_write_determine_wide_segment_file_extension( LIBEWF_INTERNAL_HANDLE *internal_handle, wchar_t* extension, uint16_t segment ){	wchar_t extension_first_character       = (wchar_t) '\0';	wchar_t extension_additional_characters = (wchar_t) '\0';	if( internal_handle == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_write_determine_wide_segment_file_extension: invalid handle.\n" );		return( -1 );	}	if( internal_handle->write == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_write_determine_wide_segment_file_extension: invalid handle - missing subhandle write.\n" );		return( -1 );	}	if( extension == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_write_determine_wide_segment_file_extension: invalid extension.\n" );		return( -1 );	}	if( segment == 0 )	{		LIBEWF_WARNING_PRINT( "libewf_write_determine_wide_segment_file_extension: invalid segment 0.\n" );		return( -1 );	}	if( internal_handle->write->maximum_amount_of_segments <= -1 )	{		LIBEWF_WARNING_PRINT( "libewf_write_determine_wide_segment_file_extension: unable to determine the maximum amount of segment files.\n" );		return( -1 );	}	if( segment > (uint16_t) internal_handle->write->maximum_amount_of_segments )	{		LIBEWF_WARNING_PRINT( "libewf_write_determine_wide_segment_file_extension: segment exceeds the maximum amount of segment files.\n" );		return( -1 );	}	if( ( internal_handle->format == LIBEWF_FORMAT_EWF ) || ( internal_handle->format == LIBEWF_FORMAT_EWFX ) )	{		extension_first_character       = (wchar_t) 'e';		extension_additional_characters = (wchar_t) 'a';	}	else if( internal_handle->ewf_format == EWF_FORMAT_S01 )	{		extension_first_character       = (wchar_t) 's';		extension_additional_characters = (wchar_t) 'a';	}	else if( internal_handle->ewf_format == EWF_FORMAT_E01 )	{		extension_first_character       = (wchar_t) 'E';		extension_additional_characters = (wchar_t) 'A';	}	else if( internal_handle->ewf_format == EWF_FORMAT_L01 )	{		extension_first_character       = (wchar_t) 'L';		extension_additional_characters = (wchar_t) 'A';	}	else	{		LIBEWF_WARNING_PRINT( "libewf_write_determine_wide_segment_file_extension: unsupported EWF format.\n" );		return( -1 );	}	extension[ 0 ] = extension_first_character;	if( segment <= 99 )	{		extension[ 2 ] = (wchar_t) '0' + (wchar_t) ( segment % 10 );		extension[ 1 ] = (wchar_t) '0' + (wchar_t) ( segment / 10 );	}	else if( segment >= 100 )	{		segment        -= 100;		extension[ 2 ]  = extension_additional_characters + (wchar_t) ( segment % 26 );		segment        /= 26;		extension[ 1 ]  = extension_additional_characters + (wchar_t) ( segment % 26 );		segment        /= 26;		if( segment >= 26 )		{			LIBEWF_WARNING_PRINT( "libewf_write_determine_wide_segment_file_extension: unable to support for more segment files.\n" );			return( -1 );		}		extension[ 0 ] = extension_first_character + (wchar_t) segment;	}	/* Safety check	 */	if( ( extension[ 0 ] > (wchar_t) 'z' ) || ( ( extension[ 0 ] > (wchar_t) 'Z' ) && ( extension[ 0 ] < (wchar_t) 'a' ) ) )	{		LIBEWF_WARNING_PRINT( "libewf_write_determine_wide_segment_file_extension: unable to support for more segment files.\n" );		return( -1 );	}	extension[ 3 ] = (wchar_t) '\0';	return( 1 );}#else/* Determines an extension for a certain segment file * For EWF-E01, EWF-S01 segment file extension naming scheme * Returns 1 on success, -1 on error */int8_t libewf_write_determine_segment_file_extension( LIBEWF_INTERNAL_HANDLE *internal_handle, char* extension, uint16_t segment ){	char extension_first_character       = (char) '\0';	char extension_additional_characters = (char) '\0';	if( internal_handle == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_write_determine_segment_file_extension: invalid handle.\n" );		return( -1 );	}	if( internal_handle->write == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_write_determine_segment_file_extension: invalid handle - missing subhandle write.\n" );		return( -1 );	}	if( extension == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_write_determine_segment_file_extension: invalid extension.\n" );		return( -1 );	}	if( segment == 0 )	{		LIBEWF_WARNING_PRINT( "libewf_write_determine_segment_file_extension: invalid segment 0.\n" );		return( -1 );	}	if( internal_handle->write->maximum_amount_of_segments <= -1 )	{		LIBEWF_WARNING_PRINT( "libewf_write_determine_segment_file_extension: unable to determine the maximum amount of segment files.\n" );		return( -1 );	}	if( segment > (uint16_t) internal_handle->write->maximum_amount_of_segments )	{		LIBEWF_WARNING_PRINT( "libewf_write_determine_segment_file_extension: segment exceeds the maximum amount of segment files.\n" );		return( -1 );	}	if( ( internal_handle->format == LIBEWF_FORMAT_EWF ) || ( internal_handle->format == LIBEWF_FORMAT_EWFX ) )	{		extension_first_character       = (char) 'e';		extension_additional_characters = (char) 'a';	}	else if( internal_handle->ewf_format == EWF_FORMAT_S01 )	{		extension_first_character       = (char) 's';		extension_additional_characters = (char) 'a';	}	else if( internal_handle->ewf_format == EWF_FORMAT_E01 )	{		extension_first_character       = (char) 'E';		extension_additional_characters = (char) 'A';	}	else if( internal_handle->ewf_format == EWF_FORMAT_L01 )	{		extension_first_character       = (char) 'L';		extension_additional_characters = (char) 'A';	}	else	{		LIBEWF_WARNING_PRINT( "libewf_write_determine_segment_file_extension: unsupported EWF format.\n" );		return( -1 );	}	extension[ 0 ] = extension_first_character;	if( segment <= 99 )	{		extension[ 2 ] = (char) '0' + (char) ( segment % 10 );		extension[ 1 ] = (char) '0' + (char) ( segment / 10 );	}	else if( segment >= 100 )	{		segment        -= 100;		extension[ 2 ]  = extension_additional_characters + (char) ( segment % 26 );		segment        /= 26;		extension[ 1 ]  = extension_additional_characters + (char) ( segment % 26 );		segment        /= 26;		if( segment >= 26 )		{			LIBEWF_WARNING_PRINT( "libewf_write_determine_segment_file_extension: unable to support for more segment files.\n" );			return( -1 );		}		extension[ 0 ] = extension_first_character + (char) segment;	}	/* Safety check	 */	if( ( extension[ 0 ] > (char) 'z' ) || ( ( extension[ 0 ] > (char) 'Z' ) && ( extension[ 0 ] < (char) 'a' ) ) )	{		LIBEWF_WARNING_PRINT( "libewf_write_determine_segment_file_extension: unable to support for more segment files.\n" );		return( -1 );	}	extension[ 3 ] = (char) '\0';	return( 1 );}#endif#if defined( HAVE_WIDE_CHARACTER_TYPE ) && defined( HAVE_WIDE_CHARACTER_SUPPORT_FUNCTIONS )/* Creates a wide character filename for a certain segment file * Returns the pointer to the filename, NULL on error */wchar_t *libewf_write_create_wide_segment_filename( LIBEWF_INTERNAL_HANDLE *internal_handle, wchar_t* basename, uint16_t segment ){	wchar_t *filename = NULL;	size_t length     = 0;	if( internal_handle == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_write_create_wide_segment_filename: invalid handle.\n" );		return( NULL );	}	if( basename == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_write_create_wide_segment_filename: invalid basename.\n" );		return( NULL );	}	if( segment == 0 )	{		LIBEWF_WARNING_PRINT( "libewf_write_create_wide_segment_filename: invalid segment 0.\n" );		return( NULL );	}	length = libewf_common_wide_string_length( basename );	if( length == 0 )	{		LIBEWF_WARNING_PRINT( "libewf_write_create_wide_segment_filename: an emtpy basename is not supported.\n" );		return( NULL );	}	/* The actual filename also contain a . 3 character extension and a end of string byte	 */	filename = libewf_common_alloc( ( length + 5 ) * sizeof( wchar_t ) );	if( filename == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_write_create_wide_segment_filename: unable to allocate filename.\n" );		return( NULL );	}	/* Add one additional character for the end of line	 */	if( libewf_common_wide_string_copy( filename, basename, ( length + 1 ) ) == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_write_create_wide_segment_filename: unable to copy basename.\n" );		libewf_common_free( filename );		return( NULL );	}	filename[ length ] = '.';	if( libewf_write_determine_wide_segment_file_extension( internal_handle, &filename[ length + 1 ], segment ) != 1 )	{		LIBEWF_WARNING_PRINT( "libewf_write_create_wide_segment_filename: unable to determine extension.\n" );		libewf_common_free( filename );		return( NULL );	}	return( filename );}#else/* Creates a filename for a certain segment file * Returns the pointer to the filename, NULL on error */char *libewf_write_create_segment_filename( LIBEWF_INTERNAL_HANDLE *internal_handle, char* basename, uint16_t segment ){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -