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

📄 libewf_segment_table.c

📁 sleuthit-2.09 一个磁盘的工具集
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * libewf segment table * * Copyright (c) 2006-2007, Joachim Metz <forensics@hoffmannbv.nl>, * Hoffmann Investigations. All rights reserved. * * Refer to AUTHORS for acknowledgements. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, *   this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright notice, *   this list of conditions and the following disclaimer in the documentation *   and/or other materials provided with the distribution. * - Neither the name of the creator, related organisations, nor the names of *   its contributors may be used to endorse or promote products derived from *   this software without specific prior written permission. * - All advertising materials mentioning features or use of this software *   must acknowledge the contribution by people stated in the acknowledgements. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER, COMPANY AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */#include "libewf_includes.h"#include <libewf/libewf_definitions.h>#include "libewf_common.h"#include "libewf_notify.h"#include "libewf_segment_table.h"#include "libewf_string.h"/* Allocates memory for a segment table struct * Returns a pointer to the new instance, NULL on error */LIBEWF_SEGMENT_TABLE *libewf_segment_table_alloc( uint16_t amount ){	LIBEWF_SEGMENT_TABLE *segment_table = NULL;	uint16_t iterator                   = 0;	segment_table = (LIBEWF_SEGMENT_TABLE *) libewf_common_alloc( LIBEWF_SEGMENT_TABLE_SIZE );	if( segment_table == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_segment_table_alloc: unable to allocate segment table.\n" );		return( NULL );	}#if defined( HAVE_WIDE_CHARACTER_TYPE ) && defined( HAVE_WIDE_CHARACTER_SUPPORT_FUNCTIONS )	segment_table->filename = (wchar_t **) libewf_common_alloc_cleared( ( amount * LIBEWF_SEGMENT_TABLE_FILENAME_SIZE ), 0 );#else	segment_table->filename = (char **) libewf_common_alloc_cleared( ( amount * LIBEWF_SEGMENT_TABLE_FILENAME_SIZE ), 0 );#endif	if( segment_table->filename == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_segment_table_alloc: unable to allocate filename array.\n" );		libewf_common_free( segment_table );		return( NULL );	}	segment_table->file_descriptor = (int *) libewf_common_alloc_cleared( ( amount * LIBEWF_SEGMENT_TABLE_FILE_DESCRIPTOR_SIZE ), -1 );	if( segment_table->file_descriptor == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_segment_table_alloc: unable to allocate file descriptor array.\n" );		libewf_common_free( segment_table->filename );		libewf_common_free( segment_table );		return( NULL );	}	segment_table->file_offset = (off_t *) libewf_common_alloc_cleared( ( amount * LIBEWF_SEGMENT_TABLE_FILE_OFFSET_SIZE ), 0 );	if( segment_table->file_offset == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_segment_table_alloc: unable to allocate file offset array.\n" );		libewf_common_free( segment_table->filename );		libewf_common_free( segment_table->file_descriptor );		libewf_common_free( segment_table );		return( NULL );	}	segment_table->amount_of_chunks = (uint32_t *) libewf_common_alloc_cleared( ( amount * LIBEWF_SEGMENT_TABLE_AMOUNT_OF_CHUNKS_SIZE ), 0 );	if( segment_table->amount_of_chunks == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_segment_table_alloc: unable to allocate amount of chunks array.\n" );		libewf_common_free( segment_table->filename );		libewf_common_free( segment_table->file_descriptor );		libewf_common_free( segment_table->file_offset );		libewf_common_free( segment_table );		return( NULL );	}	segment_table->section_list = (LIBEWF_SECTION_LIST **) libewf_common_alloc_cleared( ( amount * LIBEWF_SEGMENT_TABLE_SECTION_LIST_SIZE ), 0 );	if( segment_table->section_list == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_segment_table_alloc: unable to allocate section list array.\n" );		libewf_common_free( segment_table->filename );		libewf_common_free( segment_table->file_descriptor );		libewf_common_free( segment_table->file_offset );		libewf_common_free( segment_table->amount_of_chunks );		libewf_common_free( segment_table );		return( NULL );	}	for( iterator = 0; iterator < amount; iterator++ )	{		if( segment_table->section_list[ iterator ] == NULL )		{			segment_table->section_list[ iterator ] = (LIBEWF_SECTION_LIST *) libewf_common_alloc( LIBEWF_SECTION_LIST_SIZE );			if( segment_table->section_list[ iterator ] == NULL )			{				LIBEWF_WARNING_PRINT( "libewf_segment_table_alloc: unable to allocate section list.\n" );				/* The current entry does not need to be freed, because it was never allocated				 * but the first entry 0 does, because the iterator is a unsigned integer				 * the iterator - 1 construction is used				 * There are no entries in the list				 */				for( ; iterator > 0; iterator-- )				{					libewf_common_free( segment_table->section_list[ iterator - 1 ] );				}				libewf_common_free( segment_table->filename );				libewf_common_free( segment_table->file_descriptor );				libewf_common_free( segment_table->file_offset );				libewf_common_free( segment_table->amount_of_chunks );				libewf_common_free( segment_table->section_list );				libewf_common_free( segment_table );				return( NULL );			}			segment_table->section_list[ iterator ]->first = NULL;			segment_table->section_list[ iterator ]->last  = NULL;		}		else		{			LIBEWF_WARNING_PRINT( "libewf_segment_table_alloc: section list already created.\n" );		}	}	segment_table->amount = amount;	return( segment_table );}/* Reallocates memory for the segment table  * Returns a pointer to the instance, NULL on error */LIBEWF_SEGMENT_TABLE *libewf_segment_table_realloc( LIBEWF_SEGMENT_TABLE *segment_table, uint16_t amount ){	void *reallocation = NULL;	uint16_t iterator  = 0;	if( segment_table == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_segment_table_realloc: invalid segment table.\n" );		return( NULL );	}	reallocation = libewf_common_realloc_new_cleared( segment_table->filename, ( segment_table->amount * LIBEWF_SEGMENT_TABLE_FILENAME_SIZE ), ( amount * LIBEWF_SEGMENT_TABLE_FILENAME_SIZE ), 0 );	if( reallocation == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_segment_table_realloc: unable to reallocate dynamic filename array.\n" );		return( NULL );	}#if defined( HAVE_WIDE_CHARACTER_TYPE ) && defined( HAVE_WIDE_CHARACTER_SUPPORT_FUNCTIONS )	segment_table->filename = (wchar_t **) reallocation;#else	segment_table->filename = (char **) reallocation;#endif	reallocation            = libewf_common_realloc_new_cleared( segment_table->file_descriptor, ( segment_table->amount * LIBEWF_SEGMENT_TABLE_FILE_DESCRIPTOR_SIZE ), ( amount * LIBEWF_SEGMENT_TABLE_FILE_DESCRIPTOR_SIZE ), -1 );	if( reallocation == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_segment_table_realloc: unable to reallocate dynamic file descriptor array.\n" );		return( NULL );	}	segment_table->file_descriptor = (int *) reallocation;	reallocation                   = libewf_common_realloc_new_cleared( segment_table->file_offset, ( segment_table->amount * LIBEWF_SEGMENT_TABLE_FILE_OFFSET_SIZE ), ( amount * LIBEWF_SEGMENT_TABLE_FILE_OFFSET_SIZE ), 0 );	if( reallocation == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_segment_table_realloc: unable to reallocate dynamic file offset array.\n" );		return( NULL );	}	segment_table->file_offset = (off_t *) reallocation;	reallocation               = libewf_common_realloc_new_cleared( segment_table->amount_of_chunks, ( segment_table->amount * LIBEWF_SEGMENT_TABLE_AMOUNT_OF_CHUNKS_SIZE ), ( amount * LIBEWF_SEGMENT_TABLE_AMOUNT_OF_CHUNKS_SIZE ), 0 );	if( reallocation == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_segment_table_realloc: unable to reallocate dynamic amount of chunks array.\n" );		return( NULL );	}	segment_table->amount_of_chunks = (uint32_t *) reallocation;	reallocation                    = libewf_common_realloc_new_cleared( segment_table->section_list, ( segment_table->amount * LIBEWF_SEGMENT_TABLE_SECTION_LIST_SIZE ), ( amount * LIBEWF_SEGMENT_TABLE_SECTION_LIST_SIZE ), 0 );	if( reallocation == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_segment_table_realloc: unable to reallocate dynamic section list array.\n" );		return( NULL );	}	segment_table->section_list = (LIBEWF_SECTION_LIST **) reallocation;	for( iterator = segment_table->amount; iterator < amount; iterator++ )	{		if( segment_table->section_list[ iterator ] == NULL )		{			segment_table->section_list[ iterator ] = (LIBEWF_SECTION_LIST *) libewf_common_alloc( LIBEWF_SECTION_LIST_SIZE );			if( segment_table->section_list[ iterator ] == NULL )			{				LIBEWF_WARNING_PRINT( "libewf_segment_table_realloc: unable to allocate section list.\n" );				return( NULL );			}			segment_table->section_list[ iterator ]->first = NULL;			segment_table->section_list[ iterator ]->last  = NULL;		}		else		{			LIBEWF_WARNING_PRINT( "libewf_segment_table_realloc: section list already created.\n" );		}	}	segment_table->amount = amount;	return( segment_table );}/* Frees memory of a file list struct including elements */void libewf_segment_table_free( LIBEWF_SEGMENT_TABLE *segment_table ){	LIBEWF_SECTION_LIST_ENTRY *section_list_entry         = NULL;	LIBEWF_SECTION_LIST_ENTRY *current_section_list_entry = NULL;	uint16_t iterator                                     = 0;	if( segment_table == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_segment_table_free: invalid segment table.\n" );		return;	}	for( iterator = 0; iterator < segment_table->amount; iterator++ )	{		if( segment_table->filename[ iterator ] != NULL )		{			libewf_common_free( segment_table->filename[ iterator ] );

⌨️ 快捷键说明

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