📄 libewf_write.c
字号:
char *filename = NULL; size_t length = 0; if( internal_handle == NULL ) { LIBEWF_WARNING_PRINT( "libewf_write_create_segment_filename: invalid handle.\n" ); return( NULL ); } if( basename == NULL ) { LIBEWF_WARNING_PRINT( "libewf_write_create_segment_filename: invalid basename.\n" ); return( NULL ); } if( segment == 0 ) { LIBEWF_WARNING_PRINT( "libewf_write_create_segment_filename: invalid segment 0.\n" ); return( NULL ); } length = libewf_common_string_length( basename ); if( length == 0 ) { LIBEWF_WARNING_PRINT( "libewf_write_create_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( char ) ); if( filename == NULL ) { LIBEWF_WARNING_PRINT( "libewf_write_create_segment_filename: unable to allocate filename.\n" ); return( NULL ); } /* Add one additional character for the end of line */ if( libewf_common_string_copy( filename, basename, ( length + 1 ) ) == NULL ) { LIBEWF_WARNING_PRINT( "libewf_write_create_segment_filename: unable to copy basename.\n" ); libewf_common_free( filename ); return( NULL ); } filename[ length ] = '.'; if( libewf_write_determine_segment_file_extension( internal_handle, &filename[ length + 1 ], segment ) != 1 ) { LIBEWF_WARNING_PRINT( "libewf_write_create_segment_filename: unable to determine extension.\n" ); libewf_common_free( filename ); return( NULL ); } return( filename );}#endif/* Creates a new segment file entry within the segment table * Returns 1 on success, -1 on error */int8_t libewf_write_create_segment_file_entry( LIBEWF_INTERNAL_HANDLE *internal_handle, uint16_t segment ){ LIBEWF_SEGMENT_TABLE *segment_table = NULL;#if defined( HAVE_WIDE_CHARACTER_TYPE ) && defined( HAVE_WIDE_CHARACTER_SUPPORT_FUNCTIONS ) wchar_t *filename = NULL;#else char *filename = NULL;#endif size_t length_filename = 0; if( internal_handle == NULL ) { LIBEWF_WARNING_PRINT( "libewf_write_create_segment_file_entry: invalid handle.\n" ); return( -1 ); } if( internal_handle->segment_table == NULL ) { LIBEWF_WARNING_PRINT( "libewf_write_create_segment_file_entry: invalid handle - missing segment table.\n" ); return( -1 ); } if( segment == 0 ) { LIBEWF_WARNING_PRINT( "libewf_write_create_segment_file_entry: invalid segment 0.\n" ); return( -1 ); } /* Check if one additional entry in the segment table is needed */ if( internal_handle->segment_table->amount <= segment ) { /* Add one additional entry because the 0 entry is used for the basename */ segment_table = libewf_segment_table_realloc( internal_handle->segment_table, ( segment + 1 ) ); if( segment_table == NULL ) { LIBEWF_WARNING_PRINT( "libewf_write_create_segment_file_entry: unable to reallocate segment table.\n" ); return( -1 ); } internal_handle->segment_table = segment_table; } /* Check if the entry has already been filled */ else if( libewf_segment_table_values_is_set( internal_handle->segment_table, segment ) == 1 ) { LIBEWF_WARNING_PRINT( "libewf_write_create_segment_file_entry: segment file has already been created.\n" ); return( -1 ); }#if defined( HAVE_WIDE_CHARACTER_TYPE ) && defined( HAVE_WIDE_CHARACTER_SUPPORT_FUNCTIONS ) filename = libewf_write_create_wide_segment_filename( internal_handle, internal_handle->segment_table->filename[ 0 ], segment );#else filename = libewf_write_create_segment_filename( internal_handle, internal_handle->segment_table->filename[ 0 ], segment );#endif if( filename == NULL ) { LIBEWF_WARNING_PRINT( "libewf_write_create_segment_file_entry: unable to create filename.\n" ); return( -1 ); }#if defined( HAVE_WIDE_CHARACTER_TYPE ) && defined( HAVE_WIDE_CHARACTER_SUPPORT_FUNCTIONS ) length_filename = libewf_common_wide_string_length( filename );#else length_filename = libewf_common_string_length( filename );#endif if( length_filename == 0 ) { LIBEWF_WARNING_PRINT( "libewf_write_create_segment_file_entry: filename cannot be empty.\n" ); return( -1 ); }#if defined( HAVE_WIDE_CHARACTER_TYPE ) && defined( HAVE_WIDE_CHARACTER_SUPPORT_FUNCTIONS ) if( libewf_segment_table_set_wide_filename( internal_handle->segment_table, segment, filename, length_filename ) != 1 )#else if( libewf_segment_table_set_filename( internal_handle->segment_table, segment, filename, length_filename ) != 1 )#endif { LIBEWF_WARNING_PRINT( "libewf_write_create_segment_file_entry: unable to set filename in segment table.\n" ); libewf_common_free( filename ); return( -1 ); } if( libewf_segment_table_set_file_descriptor( internal_handle->segment_table, segment, -1 ) != 1 ) { LIBEWF_WARNING_PRINT( "libewf_write_create_segment_file_entry: unable to set file descriptor in segment table.\n" ); libewf_common_free( filename ); return( -1 ); }#if defined( HAVE_WIDE_CHARACTER_TYPE ) && defined( HAVE_WIDE_CHARACTER_SUPPORT_FUNCTIONS ) LIBEWF_VERBOSE_PRINT( "libewf_write_create_segment_file_entry: segment file created: %" PRIu32 " with name: %ls.\n", segment, filename );#else LIBEWF_VERBOSE_PRINT( "libewf_write_create_segment_file_entry: segment file created: %" PRIu32 " with name: %s.\n", segment, filename );#endif libewf_common_free( filename ); return( 1 );}/* Write the headers to file * Returns the amount of bytes written, or -1 on error */ssize_t libewf_write_headers( LIBEWF_INTERNAL_HANDLE *internal_handle, int file_descriptor, off_t start_offset, LIBEWF_SECTION_LIST *section_list ){ size_t header_size = 0; size_t header2_size = 0; size_t xheader_size = 0; ssize_t write_count = 0; ssize_t total_write_count = 0; if( internal_handle == NULL ) { LIBEWF_WARNING_PRINT( "libewf_write_headers: invalid handle.\n" ); return( -1 ); } if( section_list == NULL ) { LIBEWF_WARNING_PRINT( "libewf_write_headers: invalid section list.\n" ); return( -1 ); } if( file_descriptor == -1 ) { LIBEWF_WARNING_PRINT( "libewf_write_headers: invalid file descriptor.\n" ); return( -1 ); } if( ( internal_handle->header == NULL ) || ( internal_handle->header_size == 0 ) ) { LIBEWF_WARNING_PRINT( "libewf_write_headers: invalid header.\n" ); return( -1 ); } header_size = internal_handle->header_size - 1; if( ( internal_handle->format == LIBEWF_FORMAT_EWF ) || ( internal_handle->format == LIBEWF_FORMAT_SMART ) || ( internal_handle->format == LIBEWF_FORMAT_ENCASE1 ) ) { /* The header should be written only once * and using the compression used in the file */ write_count = libewf_section_header_write( internal_handle, file_descriptor, start_offset, internal_handle->header, header_size, internal_handle->compression_level ); if( write_count == -1 ) { LIBEWF_WARNING_PRINT( "libewf_write_headers: unable to write single header section.\n" ); return( -1 ); } if( libewf_section_list_append( section_list, (EWF_CHAR *) "header", start_offset, ( start_offset + write_count ) ) == NULL ) { LIBEWF_WARNING_PRINT( "libewf_write_headers: unable to append header section to section list.\n" ); return( -1 ); } start_offset += write_count; total_write_count += write_count; } else if( ( internal_handle->format == LIBEWF_FORMAT_ENCASE2 ) || ( internal_handle->format == LIBEWF_FORMAT_ENCASE3 ) || ( internal_handle->format == LIBEWF_FORMAT_LINEN5 ) || ( internal_handle->format == LIBEWF_FORMAT_LINEN6 ) || ( internal_handle->format == LIBEWF_FORMAT_FTK ) ) { /* The header should be written twice * the default compression is used */ write_count = libewf_section_header_write( internal_handle, file_descriptor, start_offset, internal_handle->header, header_size, EWF_COMPRESSION_DEFAULT ); if( write_count == -1 ) { LIBEWF_WARNING_PRINT( "libewf_write_headers: unable to write first header section.\n" ); return( -1 ); } if( libewf_section_list_append( section_list, (EWF_CHAR *) "header", start_offset, ( start_offset + write_count ) ) == NULL ) { LIBEWF_WARNING_PRINT( "libewf_write_headers: unable to append first header section to section list.\n" ); return( -1 ); } start_offset += write_count; total_write_count += write_count; write_count = libewf_section_header_write( internal_handle, file_descriptor, start_offset, internal_handle->header, header_size, EWF_COMPRESSION_DEFAULT ); if( write_count == -1 ) { LIBEWF_WARNING_PRINT( "libewf_write_headers: unable to write second header section.\n" ); return( -1 ); } if( libewf_section_list_append( section_list, (EWF_CHAR *) "header", start_offset, ( start_offset + write_count ) ) == NULL ) { LIBEWF_WARNING_PRINT( "libewf_write_headers: unable to append second header section to section list.\n" ); return( -1 ); } start_offset += write_count; total_write_count += write_count; } else if( ( internal_handle->format == LIBEWF_FORMAT_ENCASE4 ) || ( internal_handle->format == LIBEWF_FORMAT_ENCASE5 ) || ( internal_handle->format == LIBEWF_FORMAT_ENCASE6 ) ) { if( ( internal_handle->header2 == NULL ) && ( internal_handle->header2_size == 0 ) ) { LIBEWF_WARNING_PRINT( "libewf_write_headers: invalid header2.\n" ); return( -1 ); } header2_size = internal_handle->header2_size - 2; /* The header2 should be written twice * the default compression is used */ write_count = libewf_section_header2_write( internal_handle, file_descriptor, start_offset, internal_handle->header2, internal_handle->header2_size, EWF_COMPRESSION_DEFAULT ); if( write_count == -1 ) { LIBEWF_WARNING_PRINT( "libewf_write_headers: unable to write first header2 section.\n" ); return( -1 ); } if( libewf_section_list_append( section_list, (EWF_CHAR *) "header2", start_offset, ( start_offset + write_count ) ) == NULL ) { LIBEWF_WARNING_PRINT( "libewf_write_headers: unable to append first header2 section to section list.\n" ); return( -1 ); } start_offset += write_count; total_write_count += write_count; write_count = libewf_section_header2_write( internal_handle, file_descriptor, start_offset, internal_handle->header2, internal_handle->header2_size, EWF_COMPRESSION_DEFAULT ); if( write_count == -1 ) { LIBEWF_WARNING_PRINT( "libewf_write_headers: unable to write second header2 section.\n" ); return( -1 ); } if( libewf_section_list_append( section_list, (EWF_CHAR *) "header2", start_offset, ( start_offset + write_count ) ) == NULL ) { LIBEWF_WARNING_PRINT( "libewf_write_headers: unable to append second header2 section to section list.\n" ); return( -1 ); } start_offset += write_count; total_write_count += write_count; /* The header should be written once * the default compression is used */ write_count = libewf_section_header_write( internal_handle, file_descriptor, start_offset, internal_handle->header, header_size, EWF_COMPRESSION_DEFAULT ); if( write_count == -1 ) { LIBEWF_WARNING_PRINT( "libewf_write_headers: unable to write third header section.\n" ); return( -1 ); } if( libewf_section_list_append( section_list, (EWF_CHAR *) "header", start_offset, ( start_offset + write_count ) ) == NULL ) { LIBEWF_WARNING_PRINT( "libewf_write_headers: unable to append third header section to section list.\n" ); return( -1 ); } start_offset += write_count; total_write_count += write_count; } /* EWFX uses the header and header2 for backwards compatibility */ else if( internal_handle->format == LIBEWF_FORMAT_EWFX ) { if( ( internal_handle->xheader == NULL ) && ( internal_handle->xheader_size == 0 ) ) { LIBEWF_WARNING_PRINT( "libewf_write_headers: invalid xheader.\n" ); return( -1 ); } xheader_size = internal_handle->xheader_size; if( ( internal_handle->header2 == NULL ) && ( internal_handle->header2_size == 0 ) ) { LIBEWF_WARNING_PRINT( "libewf_write_headers: invalid header2.\n" ); return( -1 ); } header2_size = internal_handle->header2_size - 2; /* The xheader should be written once * the default compression is used */ write_count = libewf_section_xheader_write( internal_handle, file_descriptor, start_offset, internal_handle->xheader, xheader_size, EWF_COMPRESSION_DEFAULT ); if( write_count == -1 ) { LIBEWF_WARNING_PRINT( "libewf_write_headers: unable to write firts xheader section.\n" ); return( -1 ); } if( libewf_section_list_append( section_list, (EWF_CHAR *) "xheader", start_offset, ( start_offset + write_count ) ) == NULL ) { LIBEWF_WARNING_PRINT( "libewf_write_headers: unable to append first xheader section to section list.\n" ); return( -1 ); } start_offset += write_count; total_write_count += write_count;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -