コード例 #1
0
ファイル: mount_handle.c プロジェクト: Bletchley13/MBA
/* Frees a mount handle
 * Returns 1 if successful or -1 on error
 */
int mount_handle_free(
     mount_handle_t **mount_handle,
     libcerror_error_t **error )
{
	static char *function = "mount_handle_free";
	int result            = 1;

	if( mount_handle == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid mount handle.",
		 function );

		return( -1 );
	}
	if( *mount_handle != NULL )
	{
		if( ( *mount_handle )->basename != NULL )
		{
			memory_free(
			 ( *mount_handle )->basename );
		}
		if( libcdata_array_free(
		     &( ( *mount_handle )->input_files_array ),
		     (int (*)(intptr_t **, libcerror_error_t **)) &libqcow_file_free,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
			 "%s: unable to free input files array.",
			 function );

			result = -1;
		}
		if( memory_set(
		     ( *mount_handle )->key_data,
		     0,
		     16 ) == NULL )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_MEMORY,
			 LIBCERROR_MEMORY_ERROR_SET_FAILED,
			 "%s: unable to clear key data.",
			 function );

			result = -1;
		}
		memory_free(
		 *mount_handle );

		*mount_handle = NULL;
	}
	return( result );
}
コード例 #2
0
ファイル: libbde_external_key.c プロジェクト: UIKit0/libbde
/* Frees an external key
 * Returns 1 if successful or -1 on error
 */
int libbde_external_key_free(
     libbde_external_key_t **external_key,
     libcerror_error_t **error )
{
	static char *function = "libbde_external_key_free";
	int result            = 1;

	if( external_key == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid external key.",
		 function );

		return( -1 );
	}
	if( *external_key != NULL )
	{
		if( ( *external_key )->key != NULL )
		{
			if( libbde_key_free(
			     &( ( *external_key )->key ),
			     error ) != 1 )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
				 "%s: unable to free key.",
				 function );

				result = -1;
			}
		}
		if( libcdata_array_free(
		     &( ( *external_key )->entries_array ),
		     (int(*)(intptr_t **, libcerror_error_t **)) &libbde_metadata_entry_free,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
			 "%s: unable to free entries array.",
			 function );

			result = -1;
		}
		memory_free(
		 *external_key );

		*external_key = NULL;
	}
	return( result );
}
コード例 #3
0
/* Frees a data handle
 * Returns 1 if successful or -1 on error
 */
int libfvalue_data_handle_free(
     libfvalue_data_handle_t **data_handle,
     libcerror_error_t **error )
{
	libfvalue_internal_data_handle_t *internal_data_handle = NULL;
	static char *function                                  = "libfvalue_data_handle_free";
	int result                                             = 1;

	if( data_handle == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid data handle.",
		 function );

		return( -1 );
	}
	if( *data_handle != NULL )
	{
		internal_data_handle = (libfvalue_internal_data_handle_t *) *data_handle;
		*data_handle         = NULL;

		if( ( internal_data_handle->flags & LIBFVALUE_VALUE_DATA_FLAG_MANAGED ) != 0 )
		{
			if( internal_data_handle->data != NULL )
			{
				memory_free(
				 internal_data_handle->data );
			}
		}
		if( internal_data_handle->value_entries != NULL )
		{
			if( libcdata_array_free(
			     &( internal_data_handle->value_entries ),
			     (int (*)(intptr_t **, libcerror_error_t **)) &libfvalue_value_entry_free,
			     error ) != 1 )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
				 "%s: unable to free value entries array.",
				 function );

				result = -1;
			}
		}
		memory_free(
		 internal_data_handle );
	}
	return( result );
}
コード例 #4
0
/* Frees a hive bin
 * Returns 1 if successful or -1 on error
 */
int libregf_hive_bin_free(
     libregf_hive_bin_t **hive_bin,
     libcerror_error_t **error )
{
	static char *function = "libregf_hive_bin_free";
	int result            = 1;

	if( hive_bin == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid hive bin.",
		 function );

		return( -1 );
	}
	if( *hive_bin != NULL )
	{
		if( ( *hive_bin )->cells_array != NULL )
		{
			if( libcdata_array_free(
			     &( ( *hive_bin )->cells_array ),
			     (int (*)(intptr_t **, libcerror_error_t **)) &libregf_hive_bin_cell_free,
			     error ) != 1 )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
				 "%s: unable to free the hive bin cells array.",
				 function );

				result = -1;
			}
		}
		if( ( *hive_bin )->data != NULL )
		{
			memory_free(
			 ( *hive_bin )->data );
		}
		memory_free(
		 *hive_bin );

		*hive_bin = NULL;
	}
	return( result );
}
コード例 #5
0
ファイル: mount_file_system.c プロジェクト: libyal/libvmdk
/* Frees a file system
 * Returns 1 if successful or -1 on error
 */
int mount_file_system_free(
     mount_file_system_t **file_system,
     libcerror_error_t **error )
{
	static char *function = "mount_file_system_free";
	int result            = 1;

	if( file_system == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid file system.",
		 function );

		return( -1 );
	}
	if( *file_system != NULL )
	{
		if( ( *file_system )->path_prefix != NULL )
		{
			memory_free(
			 ( *file_system )->path_prefix );
		}
		if( libcdata_array_free(
		     &( ( *file_system )->handles_array ),
		     NULL,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
			 "%s: unable to free handles array.",
			 function );

			result = -1;
		}
		memory_free(
		 *file_system );

		*file_system = NULL;
	}
	return( result );
}
コード例 #6
0
/* Frees the segment table including elements
 * Returns 1 if successful or -1 on error
 */
int libewf_segment_table_free(
     libewf_segment_table_t **segment_table,
     libcerror_error_t **error )
{
	static char *function = "libewf_segment_table_free";
	int result            = 1;

	if( segment_table == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid segment table.",
		 function );

		return( -1 );
	}
	if( *segment_table != NULL )
	{
		if( ( *segment_table )->basename != NULL )
		{
			memory_free(
			 ( *segment_table )->basename );
		}
		if( libcdata_array_free(
		     &( ( *segment_table )->segment_files_array ),
		     (int (*)(intptr_t **, libcerror_error_t **)) &libewf_segment_file_handle_free,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
			 "%s: unable to free the segment files array.",
			 function );

			result = -1;
		}
		memory_free(
		 *segment_table );

		*segment_table = NULL;
	}
	return( result );
}
コード例 #7
0
/* Frees logical volume values
 * Returns 1 if successful or -1 on error
 */
int libvslvm_logical_volume_values_free(
     libvslvm_logical_volume_values_t **logical_volume_values,
     libcerror_error_t **error )
{
	static char *function = "libvslvm_logical_volume_values_free";
	int result            = 1;

	if( logical_volume_values == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid logical volume values.",
		 function );

		return( -1 );
	}
	if( *logical_volume_values != NULL )
	{
		if( ( *logical_volume_values )->name != NULL )
		{
			memory_free(
			 ( *logical_volume_values )->name );
		}
		if( libcdata_array_free(
		     &( ( *logical_volume_values )->segments_array ),
		     (int (*)(intptr_t **, libcerror_error_t **)) &libvslvm_internal_segment_free,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
			 "%s: unable to free segments array.",
			 function );

			result = -1;
		}
		memory_free(
		 *logical_volume_values );

		*logical_volume_values = NULL;
	}
	return( result );
}
コード例 #8
0
ファイル: libcreg_data_block.c プロジェクト: libyal/libcreg
/* Frees a data block
 * Returns 1 if successful or -1 on error
 */
int libcreg_data_block_free(
     libcreg_data_block_t **data_block,
     libcerror_error_t **error )
{
	static char *function = "libcreg_data_block_free";
	int result            = 1;

	if( data_block == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid data block.",
		 function );

		return( -1 );
	}
	if( *data_block != NULL )
	{
		if( libcdata_array_free(
		     &( ( *data_block )->entries_array ),
		     (int (*)(intptr_t **, libcerror_error_t **)) &libcreg_data_block_entry_free,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
			 "%s: unable to free the entries array.",
			 function );

			result = -1;
		}
		if( ( *data_block )->data != NULL )
		{
			memory_free(
			 ( *data_block )->data );
		}
		memory_free(
		 *data_block );

		*data_block = NULL;
	}
	return( result );
}
コード例 #9
0
ファイル: libfwevt_manifest.c プロジェクト: libyal/libfwevt
/* Frees a manifest
 * Returns 1 if successful or -1 on error
 */
int libfwevt_manifest_free(
     libfwevt_manifest_t **manifest,
     libcerror_error_t **error )
{
	libfwevt_internal_manifest_t *internal_manifest = NULL;
	static char *function                           = "libfwevt_manifest_free";
	int result                                      = 1;

	if( manifest == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid manifest.",
		 function );

		return( -1 );
	}
	if( *manifest != NULL )
	{
		internal_manifest = (libfwevt_internal_manifest_t *) *manifest;
		*manifest         = NULL;

		if(internal_manifest ->providers_array != NULL )
		{
			if( libcdata_array_free(
			     &( internal_manifest->providers_array ),
			     (int (*)(intptr_t **, libcerror_error_t **)) &libfwevt_provider_free,
			     error ) != 1 )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
				 "%s: unable to free providers array.",
				 function );

				result = -1;
			}
		}
		memory_free(
		 internal_manifest );
	}
	return( result );
}
コード例 #10
0
ファイル: libvslvm_segment.c プロジェクト: libyal/libvslvm
/* Frees a segment
 * Returns 1 if successful or -1 on error
 */
int libvslvm_internal_segment_free(
     libvslvm_internal_segment_t **internal_segment,
     libcerror_error_t **error )
{
	static char *function = "libvslvm_internal_segment_free";
	int result            = 1;

	if( internal_segment == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid segment.",
		 function );

		return( -1 );
	}
	if( *internal_segment != NULL )
	{
		if( ( *internal_segment )->name != NULL )
		{
			memory_free(
			 ( *internal_segment )->name );
		}
		if( libcdata_array_free(
		     &( ( *internal_segment )->stripes_array ),
		     (int (*)(intptr_t **, libcerror_error_t **)) &libvslvm_internal_stripe_free,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
			 "%s: unable to free stripes array.",
			 function );

			result = -1;
		}
		memory_free(
		 *internal_segment );

		*internal_segment = NULL;
	}
	return( result );
}
コード例 #11
0
ファイル: libesedb_page.c プロジェクト: ClevererBoy/libesedb
/* Frees a page
 * Returns 1 if successful or -1 on error
 */
int libesedb_page_free(
     libesedb_page_t **page,
     libcerror_error_t **error )
{
	static char *function = "libesedb_page_free";
	int result            = 1;

	if( page == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid page.",
		 function );

		return( -1 );
	}
	if( *page != NULL )
	{
		if( libcdata_array_free(
		     &( ( *page )->values_array ),
		     (int (*)(intptr_t **, libcerror_error_t **)) &libesedb_page_value_free,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
			 "%s: unable to free the page values array.",
			 function );

			result = -1;
		}
		if( ( *page )->data != NULL )
		{
			memory_free(
			 ( *page )->data );
		}
		memory_free(
		 *page );

		*page = NULL;
	}
	return( result );
}
コード例 #12
0
/* Frees a property set
 * Returns 1 if successful or -1 on error
 */
int libolecf_property_set_free(
     libolecf_property_set_t **property_set,
     libcerror_error_t **error )
{
	libolecf_internal_property_set_t *internal_property_set = NULL;
	static char *function                                   = "libolecf_property_set_free";
	int result                                              = 1;

        if( property_set == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid property set.",
		 function );

		return( -1 );
	}
	if( *property_set != NULL )
	{
		internal_property_set = (libolecf_internal_property_set_t *) *property_set;
		*property_set         = NULL;

		if( libcdata_array_free(
		     &( internal_property_set->sections ),
		     (int (*)(intptr_t **, libcerror_error_t **)) &libolecf_internal_property_section_free,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
			 "%s: unable to free sections array.",
			 function );

			result = -1;
		}
		memory_free(
		 internal_property_set );
	}
        return( result );
}
コード例 #13
0
ファイル: libfcache_cache.c プロジェクト: Bletchley13/MBA
/* Frees a cache
 * Returns 1 if successful or -1 on error
 */
int libfcache_cache_free(
     libfcache_cache_t **cache,
     libcerror_error_t **error )
{
	libfcache_internal_cache_t *internal_cache = NULL;
	static char *function                     = "libfcache_cache_free";
	int result                                = 1;

	if( cache == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid cache.",
		 function );

		return( -1 );
	}
	if( *cache != NULL )
	{
		internal_cache = (libfcache_internal_cache_t *) *cache;
		*cache         = NULL;

		if( libcdata_array_free(
		     &( internal_cache->entries ),
		     (int (*)(intptr_t **, libcerror_error_t **)) &libfcache_cache_value_free,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
			 "%s: unable to free the entries array.",
			 function );

			result = -1;
		}
		memory_free(
		 internal_cache );
	}
	return( result );
}
コード例 #14
0
/* Frees a metadata area
 * Returns 1 if successful or -1 on error
 */
int libvslvm_metadata_area_free(
     libvslvm_metadata_area_t **metadata_area,
     libcerror_error_t **error )
{
	static char *function = "libvslvm_metadata_area_free";
	int result            = 1;

	if( metadata_area == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid metadata area.",
		 function );

		return( -1 );
	}
	if( *metadata_area != NULL )
	{
		if( libcdata_array_free(
		     &( ( *metadata_area )->raw_location_descriptors_array ),
		     (int (*)(intptr_t **, libcerror_error_t **)) &libvslvm_raw_location_descriptor_free,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
			 "%s: unable to free raw location descriptors array.",
			 function );

			result = -1;
		}
		memory_free(
		 *metadata_area );

		*metadata_area = NULL;
	}
	return( result );
}
コード例 #15
0
/* Frees level 1 metadata
 * Returns 1 if successful or -1 on error
 */
int libfsrefs_level1_metadata_free(
     libfsrefs_level1_metadata_t **level1_metadata,
     libcerror_error_t **error )
{
	static char *function = "libfsrefs_level1_metadata_free";
	int result            = 1;

	if( level1_metadata == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid level 1 metadata.",
		 function );

		return( -1 );
	}
	if( *level1_metadata != NULL )
	{
		if( libcdata_array_free(
		     &( ( *level1_metadata )->level2_metadata_block_descriptors_array ),
		     (int (*)(intptr_t **, libcerror_error_t **)) &libfsrefs_block_descriptor_free,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
			 "%s: unable to free level 2 metadata block descriptors array.",
			 function );

			result = -1;
		}
		memory_free(
		 *level1_metadata );

		*level1_metadata = NULL;
	}
	return( result );
}
コード例 #16
0
ファイル: libfdata_area.c プロジェクト: libyal/libfdata
/* Creates an area
 * Make sure the value area is referencing, is set to NULL
 *
 * If the flag LIBFDATA_DATA_HANDLE_FLAG_MANAGED is set the area
 * takes over management of the data handle and the data handle is freed when
 * no longer needed
 *
 * Returns 1 if successful or -1 on error
 */
int libfdata_area_initialize(
     libfdata_area_t **area,
     size64_t element_data_size,
     intptr_t *data_handle,
     int (*free_data_handle)(
            intptr_t **data_handle,
            libcerror_error_t **error ),
     int (*clone_data_handle)(
            intptr_t **destination_data_handle,
            intptr_t *source_data_handle,
            libcerror_error_t **error ),
     int (*read_element_data)(
            intptr_t *data_handle,
            intptr_t *file_io_handle,
            libfdata_area_t *area,
            libfdata_cache_t *cache,
            off64_t element_value_offset,
            int element_data_file_index,
            off64_t element_data_offset,
            size64_t element_data_size,
            uint32_t element_data_flags,
            uint8_t read_flags,
            libcerror_error_t **error ),
     int (*write_element_data)(
            intptr_t *data_handle,
            intptr_t *file_io_handle,
            libfdata_area_t *area,
            libfdata_cache_t *cache,
            off64_t element_value_offset,
            int element_data_file_index,
            off64_t element_data_offset,
            size64_t element_data_size,
            uint32_t element_data_flags,
            uint8_t write_flags,
            libcerror_error_t **error ),
     uint8_t flags,
     libcerror_error_t **error )
{
	libfdata_internal_area_t *internal_area = NULL;
	static char *function                   = "libfdata_area_initialize";

	if( area == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid area.",
		 function );

		return( -1 );
	}
	if( *area != NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
		 "%s: invalid area value already set.",
		 function );

		return( -1 );
	}
	if( element_data_size == 0 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_VALUE_ZERO_OR_LESS,
		 "%s: invalid element data size value zero or less.",
		 function );

		return( -1 );
	}
	internal_area = memory_allocate_structure(
	                 libfdata_internal_area_t );

	if( internal_area == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_MEMORY,
		 LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
		 "%s: unable to create area.",
		 function );

		goto on_error;
	}
	if( memory_set(
	     internal_area,
	     0,
	     sizeof( libfdata_internal_area_t ) ) == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_MEMORY,
		 LIBCERROR_MEMORY_ERROR_SET_FAILED,
		 "%s: unable to clear area.",
		 function );

		memory_free(
		 internal_area );

		return( -1 );
	}
	if( libcdata_array_initialize(
	     &( internal_area->segments_array ),
	     0,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create segments array.",
		 function );

		goto on_error;
	}
	if( libcdata_array_initialize(
	     &( internal_area->mapped_ranges_array ),
	     0,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create mapped ranges array.",
		 function );

		goto on_error;
	}
	if( libfcache_date_time_get_timestamp(
	     &( internal_area->timestamp ),
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
		 "%s: unable to retrieve cache timestamp.",
		 function );

		goto on_error;
	}
	internal_area->element_data_size  = element_data_size;
	internal_area->flags             |= flags;
	internal_area->data_handle        = data_handle;
	internal_area->free_data_handle   = free_data_handle;
	internal_area->clone_data_handle  = clone_data_handle;
	internal_area->read_element_data  = read_element_data;
	internal_area->write_element_data = write_element_data;

	*area = (libfdata_area_t *) internal_area;

	return( 1 );

on_error:
	if( internal_area != NULL )
	{
		if( internal_area->segments_array != NULL )
		{
			libcdata_array_free(
			 &( internal_area->segments_array ),
			 NULL,
			 NULL );
		}
		memory_free(
		 internal_area );
	}
	return( -1 );
}
コード例 #17
0
/* Clones the array and its entries
 *
 * The entries are cloned using the entry_clone_function
 * On error the entries are freed using the entry_free_function
 *
 * Returns 1 if successful or -1 on error
 */
int libcdata_array_clone(
     libcdata_array_t **destination_array,
     libcdata_array_t *source_array,
     int (*entry_free_function)(
            intptr_t **entry,
            libcerror_error_t **error ),
     int (*entry_clone_function)(
            intptr_t **destination_entry,
            intptr_t *source_entry,
            libcerror_error_t **error ),
     libcerror_error_t **error )
{
	libcdata_internal_array_t *internal_destination_array = NULL;
	libcdata_internal_array_t *internal_source_array      = NULL;
	static char *function                                 = "libcdata_array_clone";
	int entry_iterator                                    = 0;
	int result                                            = 1;

	if( destination_array == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid destination array.",
		 function );

		return( -1 );
	}
	if( *destination_array != NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
		 "%s: invalid destination array already set.",
		 function );

		return( -1 );
	}
	if( entry_free_function == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid entry free function.",
		 function );

		return( -1 );
	}
	if( entry_clone_function == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid entry clone function.",
		 function );

		return( -1 );
	}
	if( source_array == NULL )
	{
		*destination_array = NULL;

		return( 1 );
	}
	internal_source_array = (libcdata_internal_array_t *) source_array;

	if( libcdata_array_initialize(
	     destination_array,
	     internal_source_array->number_of_entries,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create destination array.",
		 function );

		goto on_error;
	}
	if( *destination_array == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
		 "%s: missing destination array.",
		 function );

		goto on_error;
	}
	internal_destination_array = (libcdata_internal_array_t *) *destination_array;

#if defined( HAVE_MULTI_THREAD_SUPPORT ) && !defined( HAVE_LOCAL_LIBCDATA )
	if( libcthreads_read_write_lock_grab_for_read(
	     internal_source_array->read_write_lock,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
		 "%s: unable to grab read/write lock for reading.",
		 function );

		goto on_error;
	}
#endif
	if( internal_source_array->entries != NULL )
	{
		for( entry_iterator = 0;
		     entry_iterator < internal_source_array->number_of_entries;
		     entry_iterator++ )
		{
			if( internal_source_array->entries[ entry_iterator ] != NULL )
			{
				result = entry_clone_function(
				          &( internal_destination_array->entries[ entry_iterator ] ),
				          internal_source_array->entries[ entry_iterator ],
				          error );

				if( result != 1 )
				{
					libcerror_error_set(
					 error,
					 LIBCERROR_ERROR_DOMAIN_RUNTIME,
					 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
					 "%s: unable to create destination array entry: %d.",
					 function,
					 entry_iterator );

					break;
				}
			}
		}
	}
#if defined( HAVE_MULTI_THREAD_SUPPORT ) && !defined( HAVE_LOCAL_LIBCDATA )
	if( libcthreads_read_write_lock_release_for_read(
	     internal_source_array->read_write_lock,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
		 "%s: unable to release read/write lock for reading.",
		 function );

		goto on_error;
	}
#endif
	if( result != 1 )
	{
		goto on_error;
	}
	return( 1 );

on_error:
	if( *destination_array != NULL )
	{
		libcdata_array_free(
		 destination_array,
		 entry_free_function,
		 NULL );
	}
	return( -1 );
}
コード例 #18
0
ファイル: libfdata_area.c プロジェクト: libyal/libfdata
/* Frees an area
 * Returns 1 if successful or -1 on error
 */
int libfdata_area_free(
     libfdata_area_t **area,
     libcerror_error_t **error )
{
	libfdata_internal_area_t *internal_area = NULL;
	static char *function                   = "libfdata_area_free";
	int result                              = 1;

	if( area == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid area.",
		 function );

		return( -1 );
	}
	if( *area != NULL )
	{
		internal_area = (libfdata_internal_area_t *) *area;
		*area         = NULL;

		if( libcdata_array_free(
		     &( internal_area->segments_array ),
		     (int (*)(intptr_t **, libcerror_error_t **)) &libfdata_range_free,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
			 "%s: unable to free segments array.",
			 function );

			result = -1;
		}
		if( libcdata_array_free(
		     &( internal_area->mapped_ranges_array ),
		     (int (*)(intptr_t **, libcerror_error_t **)) &libfdata_mapped_range_free,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
			 "%s: unable to free mapped ranges array.",
			 function );

			result = -1;
		}
		if( ( internal_area->flags & LIBFDATA_DATA_HANDLE_FLAG_MANAGED ) != 0 )
		{
			if( internal_area->data_handle != NULL )
			{
				if( internal_area->free_data_handle == NULL )
				{
					libcerror_error_set(
					 error,
					 LIBCERROR_ERROR_DOMAIN_RUNTIME,
					 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
					 "%s: invalid area - missing free data handle function.",
					 function );

					result = -1;
				}
				else if( internal_area->free_data_handle(
				          &( internal_area->data_handle ),
				          error ) != 1 )
				{
					libcerror_error_set(
					 error,
					 LIBCERROR_ERROR_DOMAIN_RUNTIME,
					 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
					 "%s: unable to free data handle.",
					 function );

					result = -1;
				}
			}
		}
		memory_free(
		 internal_area );
	}
	return( result );
}
コード例 #19
0
ファイル: libfdata_area.c プロジェクト: libyal/libfdata
/* Clones (duplicates) the area
 * Returns 1 if successful or -1 on error
 */
int libfdata_area_clone(
     libfdata_area_t **destination_area,
     libfdata_area_t *source_area,
     libcerror_error_t **error )
{
	libfdata_internal_area_t *internal_destination_area = NULL;
	libfdata_internal_area_t *internal_source_area      = NULL;
	static char *function                               = "libfdata_area_clone";

	if( destination_area == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid destination area.",
		 function );

		return( -1 );
	}
	if( *destination_area != NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
		 "%s: invalid destination area value already set.",
		 function );

		return( -1 );
	}
	if( source_area == NULL )
	{
		*destination_area = source_area;

		return( 1 );
	}
	internal_source_area = (libfdata_internal_area_t *) source_area;

/* TODO refactor to use libfdata_area_initialize this requires libcdata_array_copy_elements function */
	internal_destination_area = memory_allocate_structure(
	                             libfdata_internal_area_t );

	if( internal_destination_area == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_MEMORY,
		 LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
		 "%s: unable to create destination area.",
		 function );

		goto on_error;
	}
	if( memory_set(
	     internal_destination_area,
	     0,
	     sizeof( libfdata_internal_area_t ) ) == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_MEMORY,
		 LIBCERROR_MEMORY_ERROR_SET_FAILED,
		 "%s: unable to clear destination area.",
		 function );

		memory_free(
		 internal_destination_area );

		return( -1 );
	}
	if( internal_source_area->data_handle != NULL )
	{
		if( internal_source_area->free_data_handle == NULL )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
			 "%s: invalid source area - missing free data handle function.",
			 function );

			goto on_error;
		}
		if( internal_source_area->clone_data_handle == NULL )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
			 "%s: invalid source area - missing clone data handle function.",
			 function );

			goto on_error;
		}
		if( internal_source_area->clone_data_handle(
		     &( internal_destination_area->data_handle ),
		     internal_source_area->data_handle,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
			 "%s: unable to create destination data handle.",
			 function );

			goto on_error;
		}
	}
	if( libcdata_array_clone(
	     &( internal_destination_area->segments_array ),
	     internal_source_area->segments_array,
	     (int (*)(intptr_t **, libcerror_error_t **)) &libfdata_range_free,
	     (int (*)(intptr_t **, intptr_t *, libcerror_error_t **)) &libfdata_range_clone,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create destination segments array.",
		 function );

		goto on_error;
	}
	if( libcdata_array_clone(
	     &( internal_destination_area->mapped_ranges_array ),
	     internal_source_area->mapped_ranges_array,
	     (int (*)(intptr_t **, libcerror_error_t **)) &libfdata_mapped_range_free,
	     (int (*)(intptr_t **, intptr_t *, libcerror_error_t **)) &libfdata_mapped_range_clone,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create destination mapped ranges array.",
		 function );

		goto on_error;
	}
	internal_destination_area->element_data_size  = internal_source_area->element_data_size;
	internal_destination_area->timestamp          = internal_source_area->timestamp;
	internal_destination_area->flags              = internal_source_area->flags | LIBFDATA_DATA_HANDLE_FLAG_MANAGED;
	internal_destination_area->data_handle        = internal_source_area->data_handle;
	internal_destination_area->free_data_handle   = internal_source_area->free_data_handle;
	internal_destination_area->clone_data_handle  = internal_source_area->clone_data_handle;
	internal_destination_area->read_element_data  = internal_source_area->read_element_data;
	internal_destination_area->write_element_data = internal_source_area->write_element_data;

	*destination_area = (libfdata_area_t *) internal_destination_area;

	return( 1 );

on_error:
	if( internal_destination_area != NULL )
	{
		if( internal_destination_area->segments_array != NULL )
		{
			libcdata_array_free(
			 &( internal_destination_area->segments_array ),
			 (int (*)(intptr_t **, libcerror_error_t **)) &libfdata_range_free,
			 NULL );
		}
		if( ( internal_destination_area->data_handle != NULL )
		 && ( internal_source_area->free_data_handle != NULL ) )
		{
			internal_source_area->free_data_handle(
			 &( internal_destination_area->data_handle ),
			 NULL );
		}
		memory_free(
		 internal_destination_area );
	}
	return( -1 );
}
コード例 #20
0
ファイル: libmsiecf_file.c プロジェクト: no-madsoul/libmsiecf
/* Closes a file
 * Returns 0 if successful or -1 on error
 */
int libmsiecf_file_close(
    libmsiecf_file_t *file,
    libcerror_error_t **error )
{
    libmsiecf_internal_file_t *internal_file = NULL;
    static char *function                    = "libmsiecf_file_close";
    int result                               = 0;

    if( file == NULL )
    {
        libcerror_error_set(
            error,
            LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
            LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
            "%s: invalid file.",
            function );

        return( -1 );
    }
    internal_file = (libmsiecf_internal_file_t *) file;

    if( internal_file->file_io_handle == NULL )
    {
        libcerror_error_set(
            error,
            LIBCERROR_ERROR_DOMAIN_RUNTIME,
            LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
            "%s: invalid file - missing file IO handle.",
            function );

        return( -1 );
    }
#if defined( HAVE_DEBUG_OUTPUT )
    if( libcnotify_verbose != 0 )
    {
        if( internal_file->file_io_handle_created_in_library != 0 )
        {
            if( libmsiecf_debug_print_read_offsets(
                        internal_file->file_io_handle,
                        error ) != 1 )
            {
                libcerror_error_set(
                    error,
                    LIBCERROR_ERROR_DOMAIN_RUNTIME,
                    LIBCERROR_RUNTIME_ERROR_PRINT_FAILED,
                    "%s: unable to print the read offsets.",
                    function );
            }
        }
    }
#endif
    if( internal_file->file_io_handle_opened_in_library != 0 )
    {
        if( libbfio_handle_close(
                    internal_file->file_io_handle,
                    error ) != 0 )
        {
            libcerror_error_set(
                error,
                LIBCERROR_ERROR_DOMAIN_IO,
                LIBCERROR_IO_ERROR_CLOSE_FAILED,
                "%s: unable to close file IO handle.",
                function );

            result = -1;
        }
        internal_file->file_io_handle_opened_in_library = 0;
    }
    if( internal_file->file_io_handle_created_in_library != 0 )
    {
        if( libbfio_handle_free(
                    &( internal_file->file_io_handle ),
                    error ) != 1 )
        {
            libcerror_error_set(
                error,
                LIBCERROR_ERROR_DOMAIN_RUNTIME,
                LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
                "%s: unable to free file IO handle.",
                function );

            result = -1;
        }
        internal_file->file_io_handle_created_in_library = 0;
    }
    internal_file->file_io_handle = NULL;

    if( libmsiecf_io_handle_clear(
                internal_file->io_handle,
                error ) != 1 )
    {
        libcerror_error_set(
            error,
            LIBCERROR_ERROR_DOMAIN_RUNTIME,
            LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
            "%s: unable to clear IO handle.",
            function );

        result = -1;
    }
    if( internal_file->directory_array != NULL )
    {
        if( libcdata_array_free(
                    &( internal_file->directory_array ),
                    (int (*)(intptr_t **, libcerror_error_t **)) &libmsiecf_directory_descriptor_free,
                    error ) != 1 )
        {
            libcerror_error_set(
                error,
                LIBCERROR_ERROR_DOMAIN_RUNTIME,
                LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
                "%s: unable to free directory array.",
                function );

            result = -1;
        }
    }
    if( internal_file->item_array != NULL )
    {
        if( libcdata_array_free(
                    &( internal_file->item_array ),
                    (int (*)(intptr_t **, libcerror_error_t **)) &libmsiecf_item_descriptor_free,
                    error ) != 1 )
        {
            libcerror_error_set(
                error,
                LIBCERROR_ERROR_DOMAIN_RUNTIME,
                LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
                "%s: unable to free item array.",
                function );

            result = -1;
        }
    }
    if( internal_file->recovered_item_array != NULL )
    {
        if( libcdata_array_free(
                    &( internal_file->recovered_item_array ),
                    (int (*)(intptr_t **, libcerror_error_t **)) &libmsiecf_item_descriptor_free,
                    error ) != 1 )
        {
            libcerror_error_set(
                error,
                LIBCERROR_ERROR_DOMAIN_RUNTIME,
                LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
                "%s: unable to free recovered item array.",
                function );

            result = -1;
        }
    }
    if( internal_file->unallocated_block_list != NULL )
    {
        if( libcdata_range_list_free(
                    &( internal_file->unallocated_block_list ),
                    NULL,
                    error ) != 1 )
        {
            libcerror_error_set(
                error,
                LIBCERROR_ERROR_DOMAIN_RUNTIME,
                LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
                "%s: unable to free unallocated block list.",
                function );

            result = -1;
        }
    }
    return( result );
}
コード例 #21
0
ファイル: libmsiecf_file.c プロジェクト: no-madsoul/libmsiecf
/* Opens a file for reading
 * Returns 1 if successful or -1 on error
 */
int libmsiecf_file_open_read(
    libmsiecf_internal_file_t *internal_file,
    libbfio_handle_t *file_io_handle,
    libcerror_error_t **error )
{
    static char *function      = "libmsiecf_file_open_read";
    uint32_t hash_table_offset = 0;

    if( internal_file == NULL )
    {
        libcerror_error_set(
            error,
            LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
            LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
            "%s: invalid file.",
            function );

        return( -1 );
    }
    if( internal_file->io_handle == NULL )
    {
        libcerror_error_set(
            error,
            LIBCERROR_ERROR_DOMAIN_RUNTIME,
            LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
            "%s: invalid file - missing IO handle.",
            function );

        return( -1 );
    }
    if( internal_file->directory_array != NULL )
    {
        libcerror_error_set(
            error,
            LIBCERROR_ERROR_DOMAIN_RUNTIME,
            LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
            "%s: invalid file - directory array already set.",
            function );

        return( -1 );
    }
    if( internal_file->item_array != NULL )
    {
        libcerror_error_set(
            error,
            LIBCERROR_ERROR_DOMAIN_RUNTIME,
            LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
            "%s: invalid file - item array already set.",
            function );

        return( -1 );
    }
    if( internal_file->recovered_item_array != NULL )
    {
        libcerror_error_set(
            error,
            LIBCERROR_ERROR_DOMAIN_RUNTIME,
            LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
            "%s: invalid file - recovered item array already set.",
            function );

        return( -1 );
    }
    if( internal_file->unallocated_block_list != NULL )
    {
        libcerror_error_set(
            error,
            LIBCERROR_ERROR_DOMAIN_RUNTIME,
            LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
            "%s: invalid file - unallocated block list already set.",
            function );

        return( -1 );
    }
    if( libcdata_array_initialize(
                &( internal_file->directory_array ),
                0,
                error ) != 1 )
    {
        libcerror_error_set(
            error,
            LIBCERROR_ERROR_DOMAIN_MEMORY,
            LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
            "%s: unable to create directory array.",
            function );

        goto on_error;
    }
    if( libcdata_array_initialize(
                &( internal_file->item_array ),
                0,
                error ) != 1 )
    {
        libcerror_error_set(
            error,
            LIBCERROR_ERROR_DOMAIN_MEMORY,
            LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
            "%s: unable to create item array.",
            function );

        goto on_error;
    }
    if( libcdata_array_initialize(
                &( internal_file->recovered_item_array ),
                0,
                error ) != 1 )
    {
        libcerror_error_set(
            error,
            LIBCERROR_ERROR_DOMAIN_MEMORY,
            LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
            "%s: unable to create recovered item array.",
            function );

        goto on_error;
    }
    if( libcdata_range_list_initialize(
                &( internal_file->unallocated_block_list ),
                error ) != 1 )
    {
        libcerror_error_set(
            error,
            LIBCERROR_ERROR_DOMAIN_MEMORY,
            LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
            "%s: unable to create unallocated data block list.",
            function );

        goto on_error;
    }
#if defined( HAVE_DEBUG_OUTPUT )
    if( libcnotify_verbose != 0 )
    {
        libcnotify_printf(
            "Reading file header:\n" );
    }
#endif
    if( libmsiecf_io_handle_read_file_header(
                internal_file->io_handle,
                file_io_handle,
                &hash_table_offset,
                internal_file->directory_array,
                internal_file->unallocated_block_list,
                error ) != 1 )
    {
        libcerror_error_set(
            error,
            LIBCERROR_ERROR_DOMAIN_IO,
            LIBCERROR_IO_ERROR_READ_FAILED,
            "%s: unable to read file header.",
            function );

        goto on_error;
    }
#if defined( HAVE_DEBUG_OUTPUT )
    if( libcnotify_verbose != 0 )
    {
        libcnotify_printf(
            "Reading hash table:\n" );
    }
#endif
    if( libmsiecf_io_handle_read_hash_table(
                internal_file->item_array,
                internal_file->io_handle,
                file_io_handle,
                hash_table_offset,
                error ) != 1 )
    {
        libcerror_error_set(
            error,
            LIBCERROR_ERROR_DOMAIN_IO,
            LIBCERROR_IO_ERROR_READ_FAILED,
            "%s: unable to read hash table.",
            function );

        goto on_error;
    }
#if defined( HAVE_DEBUG_OUTPUT )
    if( libcnotify_verbose != 0 )
    {
        libcnotify_printf(
            "Scanning for records:\n" );
    }
#endif
    if( libmsiecf_io_handle_read_record_scan(
                internal_file->item_array,
                internal_file->recovered_item_array,
                internal_file->io_handle,
                file_io_handle,
                hash_table_offset,
                internal_file->unallocated_block_list,
                error ) != 1 )
    {
        libcerror_error_set(
            error,
            LIBCERROR_ERROR_DOMAIN_IO,
            LIBCERROR_IO_ERROR_READ_FAILED,
            "%s: unable to perform record scan.",
            function );

        goto on_error;
    }
    return( 1 );

on_error:
    if( internal_file->unallocated_block_list != NULL )
    {
        libcdata_range_list_free(
            &( internal_file->unallocated_block_list ),
            NULL,
            NULL );
    }
    if( internal_file->recovered_item_array != NULL )
    {
        libcdata_array_free(
            &( internal_file->recovered_item_array ),
            (int (*)(intptr_t **, libcerror_error_t **)) &libmsiecf_item_descriptor_free,
            NULL );
    }
    if( internal_file->item_array != NULL )
    {
        libcdata_array_free(
            &( internal_file->item_array ),
            (int (*)(intptr_t **, libcerror_error_t **)) &libmsiecf_item_descriptor_free,
            NULL );
    }
    if( internal_file->directory_array != NULL )
    {
        libcdata_array_free(
            &( internal_file->directory_array ),
            (int (*)(intptr_t **, libcerror_error_t **)) &libmsiecf_directory_descriptor_free,
            NULL );
    }
    return( -1 );
}
コード例 #22
0
ファイル: libesedb_page.c プロジェクト: ClevererBoy/libesedb
/* Reads a page and its values
 * Returns 1 if successful or -1 on error
 */
int libesedb_page_read(
     libesedb_page_t *page,
     libesedb_io_handle_t *io_handle,
     libbfio_handle_t *file_io_handle,
     off64_t file_offset,
     libcerror_error_t **error )
{
	libcdata_array_t *page_tags_array  = NULL;
	uint8_t *page_values_data          = NULL;
	static char *function              = "libesedb_page_read";
	size_t page_values_data_offset     = 0;
	size_t page_values_data_size       = 0;
	ssize_t read_count                 = 0;
	uint32_t calculated_ecc32_checksum = 0;
	uint32_t calculated_page_number    = 0;
	uint32_t calculated_xor32_checksum = 0;
	uint32_t stored_ecc32_checksum     = 0;
	uint32_t stored_page_number        = 0;
	uint32_t stored_xor32_checksum     = 0;
	uint16_t available_data_size       = 0;
	uint16_t available_page_tag        = 0;

#if defined( HAVE_DEBUG_OUTPUT )
	uint64_t value_64bit               = 0;
	uint16_t value_16bit               = 0;
#endif

	if( page == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid page.",
		 function );

		return( -1 );
	}
	if( page->data != NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
		 "%s: invalid page data already set.",
		 function );

		return( -1 );
	}
	if( io_handle == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid IO handle.",
		 function );

		return( -1 );
	}
	calculated_page_number = (uint32_t) ( ( file_offset - io_handle->page_size ) / io_handle->page_size );

	page->offset = file_offset;

#if defined( HAVE_DEBUG_OUTPUT )
	if( libcnotify_verbose != 0 )
	{
		libcnotify_printf(
		 "%s: reading page: %" PRIu32 " at offset: %" PRIi64 " (0x%08" PRIx64 ")\n",
		 function,
		 calculated_page_number,
		 page->offset,
		 page->offset );
	}
#endif
	if( libbfio_handle_seek_offset(
	     file_io_handle,
	     page->offset,
	     SEEK_SET,
	     error ) == -1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_IO,
		 LIBCERROR_IO_ERROR_SEEK_FAILED,
		 "%s: unable to seek page offset: %" PRIi64 ".",
		 function,
		 page->offset );

		goto on_error;
	}
	page->data = (uint8_t *) memory_allocate(
	                          (size_t) io_handle->page_size );

	if( page->data == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_MEMORY,
		 LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
		 "%s: unable to create page data.",
		 function );

		goto on_error;
	}
	page->data_size = (size_t) io_handle->page_size;

	read_count = libbfio_handle_read_buffer(
	              file_io_handle,
	              page->data,
	              page->data_size,
	              error );

	if( read_count != (ssize_t) page->data_size )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_IO,
		 LIBCERROR_IO_ERROR_READ_FAILED,
		 "%s: unable to read page data.",
		 function );

		goto on_error;
	}
	page_values_data      = page->data;
	page_values_data_size = page->data_size;

#if defined( HAVE_DEBUG_OUTPUT )
	if( libcnotify_verbose != 0 )
	{
		libcnotify_printf(
		 "%s: page header:\n",
		 function );
		libcnotify_print_data(
		 page_values_data,
		 sizeof( esedb_page_header_t ),
		 0 );
	}
#endif
	page->page_number = calculated_page_number;

	byte_stream_copy_to_uint16_little_endian(
	 ( (esedb_page_header_t *) page_values_data )->available_data_size,
	 available_data_size );

	byte_stream_copy_to_uint32_little_endian(
	 ( (esedb_page_header_t *) page_values_data )->previous_page,
	 page->previous_page_number );
	byte_stream_copy_to_uint32_little_endian(
	 ( (esedb_page_header_t *) page_values_data )->next_page,
	 page->next_page_number );
	byte_stream_copy_to_uint32_little_endian(
	 ( (esedb_page_header_t *) page_values_data )->father_data_page_object_identifier,
	 page->father_data_page_object_identifier );

	byte_stream_copy_to_uint16_little_endian(
	 ( (esedb_page_header_t *) page_values_data )->available_page_tag,
	 available_page_tag );

	byte_stream_copy_to_uint32_little_endian(
	 ( (esedb_page_header_t *) page_values_data )->page_flags,
	 page->flags );

	/* Make sure to read after the page flags
	 */
	if( ( io_handle->format_revision >= LIBESEDB_FORMAT_REVISION_EXTENDED_PAGE_HEADER )
	 && ( io_handle->page_size >= 16384 ) )
	{
		/* TODO handle checksum */
	}
	else
	{
		byte_stream_copy_to_uint32_little_endian(
		 ( (esedb_page_header_t *) page_values_data )->xor_checksum,
		 stored_xor32_checksum );

		if( ( io_handle->format_revision >= LIBESEDB_FORMAT_REVISION_NEW_RECORD_FORMAT )
		 && ( ( page->flags & LIBESEDB_PAGE_FLAG_IS_NEW_RECORD_FORMAT ) != 0 ) )
		{
			byte_stream_copy_to_uint32_little_endian(
			 ( (esedb_page_header_t *) page_values_data )->ecc_checksum,
			 stored_ecc32_checksum );
		}
		else
		{
			byte_stream_copy_to_uint32_little_endian(
			 ( (esedb_page_header_t *) page_values_data )->page_number,
			 stored_page_number );
		}
	}
#if defined( HAVE_DEBUG_OUTPUT )
	if( libcnotify_verbose != 0 )
	{
		libcnotify_printf(
		 "%s: current page number\t\t\t\t\t: %" PRIu32 "\n",
		 function,
		 calculated_page_number );

		if( ( io_handle->format_revision >= LIBESEDB_FORMAT_REVISION_EXTENDED_PAGE_HEADER )
		 && ( io_handle->page_size >= 16384 ) )
		{
			/* TODO handle checksum */

			byte_stream_copy_to_uint64_little_endian(
			 page_values_data,
			 value_64bit );
			libcnotify_printf(
			 "%s: checksum\t\t\t\t\t\t: 0x%08" PRIx64 "\n",
			 function,
			 value_64bit );
		}
		else
		{
			libcnotify_printf(
			 "%s: XOR checksum\t\t\t\t\t: 0x%08" PRIx32 "\n",
			 function,
			 stored_xor32_checksum );

			if( ( io_handle->format_revision >= LIBESEDB_FORMAT_REVISION_NEW_RECORD_FORMAT )
			 && ( ( page->flags & LIBESEDB_PAGE_FLAG_IS_NEW_RECORD_FORMAT ) != 0 ) )
			{
				libcnotify_printf(
				 "%s: ECC checksum\t\t\t\t\t: 0x%08" PRIx32 "\n",
				 function,
				 stored_ecc32_checksum );
			}
			else
			{
				libcnotify_printf(
				 "%s: page number\t\t\t\t\t\t: %" PRIu32 "\n",
				 function,
				 stored_page_number );
			}
		}
		libcnotify_printf(
		 "%s: database modification time:\n",
		 function );
		libcnotify_print_data(
		 ( (esedb_page_header_t *) page_values_data )->database_modification_time,
		 8,
		 0 );

		libcnotify_printf(
		 "%s: previous page number\t\t\t\t: %" PRIu32 "\n",
		 function,
		 page->previous_page_number );
		libcnotify_printf(
		 "%s: next page number\t\t\t\t\t: %" PRIu32 "\n",
		 function,
		 page->next_page_number );
		libcnotify_printf(
		 "%s: father data page (FDP) object identifier\t\t: %" PRIu32 "\n",
		 function,
		 page->father_data_page_object_identifier );

		libcnotify_printf(
		 "%s: available data size\t\t\t\t\t: %" PRIu32 "\n",
		 function,
		 available_data_size );

		byte_stream_copy_to_uint16_little_endian(
		 ( (esedb_page_header_t *) page_values_data )->available_uncommitted_data_size,
		 value_16bit );
		libcnotify_printf(
		 "%s: available uncommitted data size\t\t\t: %" PRIu16 "\n",
		 function,
		 value_16bit );

		byte_stream_copy_to_uint16_little_endian(
		 ( (esedb_page_header_t *) page_values_data )->available_data_offset,
		 value_16bit );
		libcnotify_printf(
		 "%s: available data offset\t\t\t\t: %" PRIu16 "\n",
		 function,
		 value_16bit );

		libcnotify_printf(
		 "%s: available page tag\t\t\t\t\t: %" PRIu32 "\n",
		 function,
		 available_page_tag );

		libcnotify_printf(
		 "%s: page flags\t\t\t\t\t\t: 0x%08" PRIx32 "\n",
		 function,
		 page->flags );
		libesedb_debug_print_page_flags(
		 page->flags );
		libcnotify_printf(
		 "\n" );
	}
#endif
	/* TODO for now don't bother calculating a checksum for uninitialized pages */

	if( ( page_values_data[ 0 ] != 0 )
	 || ( page_values_data[ 1 ] != 0 )
	 || ( page_values_data[ 2 ] != 0 )
	 || ( page_values_data[ 3 ] != 0 ) )
	{
		if( ( io_handle->format_revision >= LIBESEDB_FORMAT_REVISION_EXTENDED_PAGE_HEADER )
		 && ( io_handle->page_size >= 16384 ) )
		{
			/* TODO handle checksum */
		}
		else if( ( io_handle->format_revision >= LIBESEDB_FORMAT_REVISION_NEW_RECORD_FORMAT )
		      && ( ( page->flags & LIBESEDB_PAGE_FLAG_IS_NEW_RECORD_FORMAT ) != 0 ) )
		{
			if( libesedb_checksum_calculate_little_endian_ecc32(
			     &calculated_ecc32_checksum,
			     &calculated_xor32_checksum,
			     page_values_data,
			     page_values_data_size,
			     8,
			     calculated_page_number,
			     error ) != 1 )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
				 "%s: unable to calculate ECC-32 and XOR-32 checksum.",
				 function );

				goto on_error;
			}
		}
		else
		{
			if( libesedb_checksum_calculate_little_endian_xor32(
			     &calculated_xor32_checksum,
			     &( page_values_data[ 4 ] ),
			     page_values_data_size - 4,
			     0x89abcdef,
			     error ) != 1 )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
				 "%s: unable to calculate XOR-32 checksum.",
				 function );

				goto on_error;
			}
		}
		if( stored_xor32_checksum != calculated_xor32_checksum )
		{
#ifdef TODO
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_INPUT,
			 LIBCERROR_INPUT_ERROR_CRC_MISMATCH,
			 "%s: mismatch in page XOR-32 checksum ( 0x%08" PRIx32 " != 0x%08" PRIx32 " ).",
			 function,
			 stored_xor32_checksum,
			 calculated_xor32_checksum );

			goto on_error;
#else
			if( libcnotify_verbose != 0 )
			{
				libcnotify_printf(
				 "%s: mismatch in page XOR-32 checksum ( 0x%08" PRIx32 " != 0x%08" PRIx32 " ).\n",
				 function,
				 stored_xor32_checksum,
				 calculated_xor32_checksum );
			}
#endif
		}
		if( stored_ecc32_checksum != calculated_ecc32_checksum )
		{
#ifdef TODO
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_INPUT,
			 LIBCERROR_INPUT_ERROR_CRC_MISMATCH,
			 "%s: mismatch in page ECC-32 checksum ( 0x%08" PRIx32 " != 0x%08" PRIx32 " ).",
			 function,
			 stored_ecc32_checksum,
			 calculated_ecc32_checksum );

			goto on_error;
#else
			if( libcnotify_verbose != 0 )
			{
				libcnotify_printf(
				 "%s: mismatch in page ECC-32 checksum ( 0x%08" PRIx32 " != 0x%08" PRIx32 " ).\n",
				 function,
				 stored_ecc32_checksum,
				 calculated_ecc32_checksum );
			}
#endif
		}
	}
	page_values_data        += sizeof( esedb_page_header_t );
	page_values_data_size   -= sizeof( esedb_page_header_t );
	page_values_data_offset += sizeof( esedb_page_header_t );

	if( ( io_handle->format_revision >= LIBESEDB_FORMAT_REVISION_EXTENDED_PAGE_HEADER )
	 && ( io_handle->page_size >= 16384 ) )
	{
#if defined( HAVE_DEBUG_OUTPUT )
		if( libcnotify_verbose != 0 )
		{
			libcnotify_printf(
			 "%s: extended page header:\n",
			 function );
			libcnotify_print_data(
			 page_values_data,
			 40,
			 0 );
		}
#endif
#if defined( HAVE_DEBUG_OUTPUT )
		if( libcnotify_verbose != 0 )
		{
			byte_stream_copy_to_uint64_little_endian(
			 ( (esedb_extended_page_header_t *) page_values_data )->checksum1,
			 value_64bit );
			libcnotify_printf(
			 "%s: checksum1\t\t\t\t\t\t: 0x%08" PRIx64 "\n",
			 function,
			 value_64bit );

			byte_stream_copy_to_uint64_little_endian(
			 ( (esedb_extended_page_header_t *) page_values_data )->checksum2,
			 value_64bit );
			libcnotify_printf(
			 "%s: checksum2\t\t\t\t\t\t: 0x%08" PRIx64 "\n",
			 function,
			 value_64bit );

			byte_stream_copy_to_uint64_little_endian(
			 ( (esedb_extended_page_header_t *) page_values_data )->checksum3,
			 value_64bit );
			libcnotify_printf(
			 "%s: checksum3\t\t\t\t\t\t: 0x%08" PRIx64 "\n",
			 function,
			 value_64bit );

			byte_stream_copy_to_uint64_little_endian(
			 ( (esedb_extended_page_header_t *) page_values_data )->page_number,
			 value_64bit );
			libcnotify_printf(
			 "%s: page number\t\t\t\t\t\t: %" PRIu64 "\n",
			 function,
			 value_64bit );

			libcnotify_printf(
			 "%s: unknown1:\n",
			 function );
			libcnotify_print_data(
			 ( (esedb_extended_page_header_t *) page_values_data )->unknown1,
			 8,
			 0 );
		}
#endif
		page_values_data        += sizeof( esedb_extended_page_header_t );
		page_values_data_size   -= sizeof( esedb_extended_page_header_t );
		page_values_data_offset += sizeof( esedb_extended_page_header_t );
	}
	if( available_page_tag > 0 )
	{
		/* Create the page tags array
		 */
		if( libcdata_array_initialize(
		     &page_tags_array,
		     0,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
			 "%s: unable to create page tags array.",
			 function );

			goto on_error;
		}
		if( libesedb_page_read_tags(
		     page_tags_array,
		     io_handle,
		     available_page_tag,
		     page->data,
		     page->data_size,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_IO,
			 LIBCERROR_IO_ERROR_READ_FAILED,
			 "%s: unable to read page tags.",
			 function );

			goto on_error;
		}
		/* The offsets in the page tags are relative after the page header
		 */
		if( libesedb_page_read_values(
		     page,
		     io_handle,
		     page_tags_array,
		     page_values_data,
		     page_values_data_size,
		     page_values_data_offset,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_IO,
			 LIBCERROR_IO_ERROR_READ_FAILED,
			 "%s: unable to read page values.",
			 function );

			goto on_error;
		}
		if( libcdata_array_free(
		     &page_tags_array,
		     (int (*)(intptr_t **, libcerror_error_t **)) &libesedb_page_tags_value_free,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
			 "%s: unable to free the page tags array.",
			 function );

			goto on_error;
		}
	}
	return( 1 );

on_error:
	if( page_tags_array != NULL )
	{
		libcdata_array_free(
		 &page_tags_array,
		 (int (*)(intptr_t **, libcerror_error_t **)) &libesedb_page_tags_value_free,
		 NULL );
	}
	if( page->data != NULL )
	{
		memory_free(
		 page->data );

		page->data = NULL;
	}
	return( -1 );
}
コード例 #23
0
/* Frees a volume
 * Returns 1 if successful or -1 on error
 */
int libvshadow_volume_free(
     libvshadow_volume_t **volume,
     libcerror_error_t **error )
{
	libvshadow_internal_volume_t *internal_volume = NULL;
	static char *function                         = "libvshadow_volume_free";
	int result                                    = 1;

	if( volume == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid volume.",
		 function );

		return( -1 );
	}
	if( *volume != NULL )
	{
		internal_volume = (libvshadow_internal_volume_t *) *volume;

		if( internal_volume->file_io_handle != NULL )
		{
			if( libvshadow_volume_close(
			     *volume,
			     error ) != 0 )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_IO,
				 LIBCERROR_IO_ERROR_CLOSE_FAILED,
				 "%s: unable to close volume.",
				 function );

				result = -1;
			}
		}
		*volume = NULL;

#if defined( HAVE_LIBVSHADOW_MULTI_THREAD_SUPPORT )
		if( libcthreads_read_write_lock_free(
		     &( internal_volume->read_write_lock ),
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
			 "%s: unable to free read/write lock.",
			 function );

			result = -1;
		}
#endif
		if( libcdata_array_free(
		     &( internal_volume->store_descriptors_array ),
		     (int (*)(intptr_t **, libcerror_error_t **)) &libvshadow_store_descriptor_free,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
			 "%s: unable to free store descriptors array.",
			 function );

			result = -1;
		}
		if( libvshadow_io_handle_free(
		     &( internal_volume->io_handle ),
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
			 "%s: unable to free IO handle.",
			 function );

			result = -1;
		}
		memory_free(
		 internal_volume );
	}
	return( result );
}
コード例 #24
0
/* Frees a volume master key
 * Returns 1 if successful or -1 on error
 */
int libbde_volume_master_key_free(
     libbde_volume_master_key_t **volume_master_key,
     libcerror_error_t **error )
{
	static char *function = "libbde_volume_master_key_free";
	int result            = 1;

	if( volume_master_key == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid volume master key.",
		 function );

		return( -1 );
	}
	if( *volume_master_key != NULL )
	{
		if( ( *volume_master_key )->key != NULL )
		{
			if( libbde_key_free(
			     &( ( *volume_master_key )->key ),
			     error ) != 1 )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
				 "%s: unable to free key.",
				 function );

				result = -1;
			}
		}
		if( ( *volume_master_key )->stretch_key != NULL )
		{
			if( libbde_stretch_key_free(
			     &( ( *volume_master_key )->stretch_key ),
			     error ) != 1 )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
				 "%s: unable to free stretch key.",
				 function );

				result = -1;
			}
		}
		if( ( *volume_master_key )->aes_ccm_encrypted_key != NULL )
		{
			if( libbde_aes_ccm_encrypted_key_free(
			     &( ( *volume_master_key )->aes_ccm_encrypted_key ),
			     error ) != 1 )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
				 "%s: unable to free AES-CCM encrypted key.",
				 function );

				result = -1;
			}
		}
		if( libcdata_array_free(
		     &( ( *volume_master_key )->entries_array ),
		     (int(*)(intptr_t **, libcerror_error_t **)) &libbde_metadata_entry_free,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
			 "%s: unable to free entries array.",
			 function );

			result = -1;
		}
		memory_free(
		 *volume_master_key );

		*volume_master_key = NULL;
	}
	return( result );
}
コード例 #25
0
/* Creates a volume
 * ake sure the value volume is referencing, is set to NULL
 * Returns 1 if successful or -1 on error
 */
int libvshadow_volume_initialize(
     libvshadow_volume_t **volume,
     libcerror_error_t **error )
{
	libvshadow_internal_volume_t *internal_volume = NULL;
	static char *function                         = "libvshadow_volume_initialize";

	if( volume == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid volume.",
		 function );

		return( -1 );
	}
	if( *volume != NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
		 "%s: invalid volume value already set.",
		 function );

		return( -1 );
	}
	internal_volume = memory_allocate_structure(
	                   libvshadow_internal_volume_t );

	if( internal_volume == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_MEMORY,
		 LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
		 "%s: unable to create volume.",
		 function );

		goto on_error;
	}
	if( memory_set(
	     internal_volume,
	     0,
	     sizeof( libvshadow_internal_volume_t ) ) == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_MEMORY,
		 LIBCERROR_MEMORY_ERROR_SET_FAILED,
		 "%s: unable to clear volume.",
		 function );

		memory_free(
		 internal_volume );

		return( -1 );
	}
	if( libcdata_array_initialize(
	     &( internal_volume->store_descriptors_array ),
	     0,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create store descriptors array.",
		 function );

		goto on_error;
	}
	if( libvshadow_io_handle_initialize(
	     &( internal_volume->io_handle ),
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create IO handle.",
		 function );

		goto on_error;
	}
#if defined( HAVE_LIBVSHADOW_MULTI_THREAD_SUPPORT )
	if( libcthreads_read_write_lock_initialize(
	     &( internal_volume->read_write_lock ),
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to intialize read/write lock.",
		 function );

		goto on_error;
	}
#endif
	*volume = (libvshadow_volume_t *) internal_volume;

	return( 1 );

on_error:
	if( internal_volume != NULL )
	{
		if( internal_volume->store_descriptors_array != NULL )
		{
			libcdata_array_free(
			 &( internal_volume->store_descriptors_array ),
			 (int (*)(intptr_t **, libcerror_error_t **)) &libvshadow_store_descriptor_free,
			 NULL );
		}
		memory_free(
		 internal_volume );
	}
	return( -1 );
}
コード例 #26
0
ファイル: libfwevt_manifest.c プロジェクト: libyal/libfwevt
/* Reads the manifest
 * Returns 1 if successful or -1 on error
 */
int libfwevt_manifest_read(
     libfwevt_manifest_t *manifest,
     const uint8_t *data,
     size_t data_size,
     libcerror_error_t **error )
{
	libfwevt_internal_manifest_t *internal_manifest = NULL;
	libfwevt_provider_t *provider                   = NULL;
	fwevt_template_manifest_t *wevt_manifest        = NULL;
	fwevt_template_provider_entry_t *provider_entry = NULL;
	static char *function                           = "libfwevt_manifest_read";
	size_t data_offset                              = 0;
	uint32_t number_of_providers                    = 0;
	uint32_t provider_data_offset                   = 0;
	uint32_t provider_index                         = 0;

#if defined( HAVE_DEBUG_OUTPUT )
	system_character_t guid_string[ 48 ];

	libfguid_identifier_t *guid                     = NULL;
	uint32_t value_32bit                            = 0;
	int result                                      = 0;
#endif

	if( manifest == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid manifest.",
		 function );

		return( -1 );
	}
	internal_manifest = (libfwevt_internal_manifest_t *) manifest;

	if( data == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid data.",
		 function );

		return( -1 );
	}
	if( data_size > (size_t) SSIZE_MAX )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
		 "%s: invalid data size value exceeds maximum.",
		 function );

		return( -1 );
	}
	if( data_size < sizeof( fwevt_template_manifest_t ) )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
		 "%s: invalid data value too small.",
		 function );

		return( -1 );
	}
	wevt_manifest = (fwevt_template_manifest_t *) data;

#if defined( HAVE_DEBUG_OUTPUT )
	if( libcnotify_verbose != 0 )
	{
		libcnotify_printf(
		 "%s: manifest data:\n",
		 function );
		libcnotify_print_data(
		 (uint8_t *) wevt_manifest,
		 sizeof( fwevt_template_manifest_t ),
		 0 );
	}
#endif
	byte_stream_copy_to_uint16_little_endian(
	 wevt_manifest->major_version,
	 internal_manifest->major_version );

	byte_stream_copy_to_uint16_little_endian(
	 wevt_manifest->minor_version,
	 internal_manifest->minor_version );

	byte_stream_copy_to_uint32_little_endian(
	 wevt_manifest->number_of_providers,
	 number_of_providers );

#if defined( HAVE_DEBUG_OUTPUT )
	if( libcnotify_verbose != 0 )
	{
		libcnotify_printf(
		 "%s: signature\t\t\t\t\t: %c%c%c%c\n",
		 function,
		 wevt_manifest->signature[ 0 ],
		 wevt_manifest->signature[ 1 ],
		 wevt_manifest->signature[ 2 ],
		 wevt_manifest->signature[ 3 ] );

		byte_stream_copy_to_uint32_little_endian(
		 wevt_manifest->size,
		 value_32bit );
		libcnotify_printf(
		 "%s: size\t\t\t\t\t\t: %" PRIu32 "\n",
		 function,
		 value_32bit );

		libcnotify_printf(
		 "%s: major version\t\t\t\t\t: %" PRIu16 "\n",
		 function,
		 internal_manifest->major_version );

		libcnotify_printf(
		 "%s: minor version\t\t\t\t\t: %" PRIu16 "\n",
		 function,
		 internal_manifest->minor_version );

		libcnotify_printf(
		 "%s: number of providers\t\t\t\t: %" PRIu32 "\n",
		 function,
		 number_of_providers );

		libcnotify_printf(
		 "\n" );
	}
#endif
	if( memory_compare(
	     wevt_manifest->signature,
	     "CRIM",
	     4 ) != 0 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
		 "%s: unsupported manifest signature.",
		 function );

		goto on_error;
	}
	data_offset = sizeof( fwevt_template_manifest_t );

	if( libcdata_array_initialize(
	     &( internal_manifest->providers_array ),
	     number_of_providers,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create providers array.",
		 function );

		goto on_error;
	}
	for( provider_index = 0;
	     provider_index < number_of_providers;
	     provider_index++ )
	{
		if( data_offset >= data_size )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
			 "%s: invalid data offset value out of bounds.",
			 function );

			goto on_error;
		}
		provider_entry = (fwevt_template_provider_entry_t *) &( data[ data_offset ] );

		if( ( data_offset + sizeof( fwevt_template_provider_entry_t ) ) >= data_size )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
			 "%s: invalid data value too small.",
			 function );

			goto on_error;
		}
		byte_stream_copy_to_uint32_little_endian(
		 provider_entry->data_offset,
		 provider_data_offset );

#if defined( HAVE_DEBUG_OUTPUT )
		if( libcnotify_verbose != 0 )
		{
			if( libfguid_identifier_initialize(
			     &guid,
			     error ) != 1 )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
				 "%s: unable to create GUID.",
				 function );

				goto on_error;
			}
			if( libfguid_identifier_copy_from_byte_stream(
			     guid,
			     provider_entry->identifier,
			     16,
			     LIBFGUID_ENDIAN_LITTLE,
			     error ) != 1 )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
				 "%s: unable to copy byte stream to GUID.",
				 function );

				goto on_error;
			}
#if defined( HAVE_WIDE_SYSTEM_CHARACTER )
			result = libfguid_identifier_copy_to_utf16_string(
				  guid,
				  (uint16_t *) guid_string,
				  48,
				  LIBFGUID_STRING_FORMAT_FLAG_USE_LOWER_CASE,
				  error );
#else
			result = libfguid_identifier_copy_to_utf8_string(
				  guid,
				  (uint8_t *) guid_string,
				  48,
				  LIBFGUID_STRING_FORMAT_FLAG_USE_LOWER_CASE,
				  error );
#endif
			if( result != 1 )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
				 "%s: unable to copy GUID to string.",
				 function );

				goto on_error;
			}
			libcnotify_printf(
			 "%s: provider entry: %02" PRIu32 " identifier\t\t\t: %" PRIs_SYSTEM "\n",
			 function,
			 provider_index,
			 guid_string );

			if( libfguid_identifier_free(
			     &guid,
			     error ) != 1 )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
				 "%s: unable to free GUID.",
				 function );

				goto on_error;
			}
			libcnotify_printf(
			 "%s: provider entry: %02" PRIu32 " data offset\t\t\t: 0x%08" PRIx32 "\n",
			 function,
			 provider_index,
			 provider_data_offset );
		}
#endif
		data_offset += sizeof( fwevt_template_provider_entry_t );

		if( libfwevt_provider_initialize(
		     &provider,
		     provider_entry->identifier,
		     16,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
			 "%s: unable to create provider: %" PRIu32 ".",
			 function,
			 provider_index );

			goto on_error;
		}
		if( libfwevt_provider_read(
		     provider,
		     data,
		     data_size,
		     (size_t) provider_data_offset,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_IO,
			 LIBCERROR_IO_ERROR_READ_FAILED,
			 "%s: unable to read provider: %d.",
			 function,
			 provider_index );

			goto on_error;
		}
		if( libcdata_array_set_entry_by_index(
		     internal_manifest->providers_array,
		     (int) provider_index,
		     (intptr_t *) provider,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
			 "%s: unable to set provider: %" PRIu32 ".",
			 function,
			 provider_index );

			goto on_error;
		}
		provider = NULL;
	}
/* TODO refactor to read on demand ? */
	for( provider_index = 0;
	     provider_index < number_of_providers;
	     provider_index++ )
	{
		if( libcdata_array_get_entry_by_index(
		     internal_manifest->providers_array,
		     provider_index,
		     (intptr_t **) &provider,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
			 "%s: unable to retrieve provider: %d.",
			 function,
			 provider_index );

			provider = NULL;

			goto on_error;
		}
		if( libfwevt_provider_read_channels(
		     provider,
		     data,
		     data_size,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_IO,
			 LIBCERROR_IO_ERROR_READ_FAILED,
			 "%s: unable to read channels.",
			 function );

			provider = NULL;

			goto on_error;
		}
		if( libfwevt_provider_read_events(
		     provider,
		     data,
		     data_size,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_IO,
			 LIBCERROR_IO_ERROR_READ_FAILED,
			 "%s: unable to read events.",
			 function );

			provider = NULL;

			goto on_error;
		}
		if( libfwevt_provider_read_keywords(
		     provider,
		     data,
		     data_size,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_IO,
			 LIBCERROR_IO_ERROR_READ_FAILED,
			 "%s: unable to read keywords.",
			 function );

			provider = NULL;

			goto on_error;
		}
		if( libfwevt_provider_read_levels(
		     provider,
		     data,
		     data_size,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_IO,
			 LIBCERROR_IO_ERROR_READ_FAILED,
			 "%s: unable to read levels.",
			 function );

			provider = NULL;

			goto on_error;
		}
		if( libfwevt_provider_read_maps(
		     provider,
		     data,
		     data_size,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_IO,
			 LIBCERROR_IO_ERROR_READ_FAILED,
			 "%s: unable to read maps.",
			 function );

			provider = NULL;

			goto on_error;
		}
		if( libfwevt_provider_read_opcodes(
		     provider,
		     data,
		     data_size,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_IO,
			 LIBCERROR_IO_ERROR_READ_FAILED,
			 "%s: unable to read opcodes.",
			 function );

			provider = NULL;

			goto on_error;
		}
		if( libfwevt_provider_read_tasks(
		     provider,
		     data,
		     data_size,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_IO,
			 LIBCERROR_IO_ERROR_READ_FAILED,
			 "%s: unable to read tasks.",
			 function );

			provider = NULL;

			goto on_error;
		}
		if( libfwevt_provider_read_templates(
		     provider,
		     data,
		     data_size,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_IO,
			 LIBCERROR_IO_ERROR_READ_FAILED,
			 "%s: unable to read templates.",
			 function );

			provider = NULL;

			goto on_error;
		}
	}
/* TODO end refactor */
#if defined( HAVE_DEBUG_OUTPUT )
	if( libcnotify_verbose != 0 )
	{
		if( number_of_providers > 0 )
		{
			libcnotify_printf(
			 "\n" );
		}
	}
#endif
	return( 1 );

on_error:
#if defined( HAVE_DEBUG_OUTPUT )
	if( guid != NULL )
	{
		libfguid_identifier_free(
		 &guid,
		 NULL );
	}
#endif
	if( provider != NULL )
	{
		libfwevt_provider_free(
		 &provider,
		 NULL );
	}
	if( internal_manifest->providers_array != NULL )
	{
		libcdata_array_free(
		 &( internal_manifest->providers_array ),
		 (int (*)(intptr_t **, libcerror_error_t **)) &libfwevt_provider_free,
		 NULL );
	}
	return( -1 );
}
コード例 #27
0
/* Tests the libewf_session_section_read_data function
 * Returns 1 if successful or 0 if not
 */
int ewf_test_session_section_read_data(
     void )
{
	libcdata_array_t *sessions          = NULL;
	libcdata_array_t *tracks            = NULL;
	libcerror_error_t *error            = NULL;
	libewf_media_values_t *media_values = NULL;
	int result                          = 0;

	/* Initialize test
	 */
	result = libewf_media_values_initialize(
	          &media_values,
	          &error );

	EWF_TEST_ASSERT_EQUAL_INT(
	 "result",
	 result,
	 1 );

	EWF_TEST_ASSERT_IS_NOT_NULL(
	 "media_values",
	 media_values );

	EWF_TEST_ASSERT_IS_NULL(
	 "error",
	 error );

	result = libcdata_array_initialize(
	          &sessions,
	          0,
	          &error );

	EWF_TEST_ASSERT_EQUAL_INT(
	 "result",
	 result,
	 1 );

	EWF_TEST_ASSERT_IS_NOT_NULL(
	 "sessions",
	 sessions );

	EWF_TEST_ASSERT_IS_NULL(
	 "error",
	 error );

	result = libcdata_array_initialize(
	          &tracks,
	          0,
	          &error );

	EWF_TEST_ASSERT_EQUAL_INT(
	 "result",
	 result,
	 1 );

	EWF_TEST_ASSERT_IS_NOT_NULL(
	 "tracks",
	 tracks );

	EWF_TEST_ASSERT_IS_NULL(
	 "error",
	 error );

	/* Test regular cases
	 */
	result = libewf_session_section_read_data(
	          ewf_test_session_section_data1,
	          168,
	          1,
	          media_values,
	          sessions,
	          tracks,
	          &error );

	EWF_TEST_ASSERT_EQUAL_INT(
	 "result",
	 result,
	 1 );

	EWF_TEST_ASSERT_IS_NULL(
	 "error",
	 error );

	/* Test error cases
	 */
	result = libewf_session_section_read_data(
	          NULL,
	          168,
	          1,
	          media_values,
	          sessions,
	          tracks,
	          &error );

	EWF_TEST_ASSERT_EQUAL_INT(
	 "result",
	 result,
	 -1 );

	EWF_TEST_ASSERT_IS_NOT_NULL(
	 "error",
	 error );

	libcerror_error_free(
	 &error );

	result = libewf_session_section_read_data(
	          ewf_test_session_section_data1,
	          (size_t) SSIZE_MAX + 1,
	          1,
	          media_values,
	          sessions,
	          tracks,
	          &error );

	EWF_TEST_ASSERT_EQUAL_INT(
	 "result",
	 result,
	 -1 );

	EWF_TEST_ASSERT_IS_NOT_NULL(
	 "error",
	 error );

	libcerror_error_free(
	 &error );

	result = libewf_session_section_read_data(
	          ewf_test_session_section_data1,
	          0,
	          1,
	          media_values,
	          sessions,
	          tracks,
	          &error );

	EWF_TEST_ASSERT_EQUAL_INT(
	 "result",
	 result,
	 -1 );

	EWF_TEST_ASSERT_IS_NOT_NULL(
	 "error",
	 error );

	libcerror_error_free(
	 &error );

	result = libewf_session_section_read_data(
	          ewf_test_session_section_data1,
	          168,
	          0,
	          media_values,
	          sessions,
	          tracks,
	          &error );

	EWF_TEST_ASSERT_EQUAL_INT(
	 "result",
	 result,
	 -1 );

	EWF_TEST_ASSERT_IS_NOT_NULL(
	 "error",
	 error );

	libcerror_error_free(
	 &error );

	result = libewf_session_section_read_data(
	          ewf_test_session_section_data1,
	          168,
	          1,
	          NULL,
	          sessions,
	          tracks,
	          &error );

	EWF_TEST_ASSERT_EQUAL_INT(
	 "result",
	 result,
	 -1 );

	EWF_TEST_ASSERT_IS_NOT_NULL(
	 "error",
	 error );

	libcerror_error_free(
	 &error );

	/* Clean up
	 */
	result = libewf_media_values_free(
	          &media_values,
	          &error );

	EWF_TEST_ASSERT_EQUAL_INT(
	 "result",
	 result,
	 1 );

	EWF_TEST_ASSERT_IS_NULL(
	 "media_values",
	 media_values );

	EWF_TEST_ASSERT_IS_NULL(
	 "error",
	 error );

	result = libcdata_array_free(
	          &sessions,
	          (int (*)(intptr_t **, libcerror_error_t **)) &libewf_sector_range_free,
	          &error );

	EWF_TEST_ASSERT_EQUAL_INT(
	 "result",
	 result,
	 1 );

	EWF_TEST_ASSERT_IS_NULL(
	 "sessions",
	 sessions );

	EWF_TEST_ASSERT_IS_NULL(
	 "error",
	 error );

	result = libcdata_array_free(
	          &tracks,
	          (int (*)(intptr_t **, libcerror_error_t **)) &libewf_sector_range_free,
	          &error );

	EWF_TEST_ASSERT_EQUAL_INT(
	 "result",
	 result,
	 1 );

	EWF_TEST_ASSERT_IS_NULL(
	 "tracks",
	 tracks );

	EWF_TEST_ASSERT_IS_NULL(
	 "error",
	 error );

	return( 1 );

on_error:
	if( error != NULL )
	{
		libcerror_error_free(
		 &error );
	}
	if( tracks != NULL )
	{
		libcdata_array_free(
		 &tracks,
		 (int (*)(intptr_t **, libcerror_error_t **)) &libewf_sector_range_free,
		 NULL );
	}
	if( sessions != NULL )
	{
		libcdata_array_free(
		 &sessions,
		 (int (*)(intptr_t **, libcerror_error_t **)) &libewf_sector_range_free,
		 NULL );
	}
	if( media_values != NULL )
	{
		libewf_media_values_free(
		 &media_values,
		 NULL );
	}
	return( 0 );
}
コード例 #28
0
ファイル: libvsmbr_handle.c プロジェクト: roox/libvsmbr
/* Frees a handle
 * Returns 1 if successful or -1 on error
 */
int libvsmbr_handle_free(
     libvsmbr_handle_t **handle,
     libcerror_error_t **error )
{
	libvsmbr_internal_handle_t *internal_handle = NULL;
	static char *function                       = "libvsmbr_handle_free";
	int result                                  = 1;

	if( handle == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid handle.",
		 function );

		return( -1 );
	}
	if( *handle != NULL )
	{
		internal_handle = (libvsmbr_internal_handle_t *) *handle;

		if( internal_handle->file_io_handle != NULL )
		{
			if( libvsmbr_handle_close(
			     *handle,
			     error ) != 0 )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_IO,
				 LIBCERROR_IO_ERROR_CLOSE_FAILED,
				 "%s: unable to close handle.",
				 function );

				result = -1;
			}
		}
		*handle = NULL;

		if( libcdata_array_free(
		     &( internal_handle->partitions_array ),
		     (int (*)(intptr_t **, libcerror_error_t **)) &libvsmbr_partition_values_free,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
			 "%s: unable to free the partitions array.",
			 function );

			result = -1;
		}
		if( libcdata_array_free(
		     &( internal_handle->sections_array ),
		     (int (*)(intptr_t **, libcerror_error_t **)) &libvsmbr_section_values_free,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
			 "%s: unable to free the sections array.",
			 function );

			result = -1;
		}
		if( libvsmbr_io_handle_free(
		     &( internal_handle->io_handle ),
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
			 "%s: unable to free IO handle.",
			 function );

			result = -1;
		}
		memory_free(
		 internal_handle );
	}
	return( result );
}
コード例 #29
0
ファイル: libvsmbr_handle.c プロジェクト: roox/libvsmbr
/* Creates a handle
 * Make sure the value handle is referencing, is set to NULL
 * Returns 1 if successful or -1 on error
 */
int libvsmbr_handle_initialize(
     libvsmbr_handle_t **handle,
     libcerror_error_t **error )
{
	libvsmbr_internal_handle_t *internal_handle = NULL;
	static char *function                       = "libvsmbr_handle_initialize";

	if( handle == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid handle.",
		 function );

		return( -1 );
	}
	if( *handle != NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
		 "%s: invalid handle value already set.",
		 function );

		return( -1 );
	}
	internal_handle = memory_allocate_structure(
	                   libvsmbr_internal_handle_t );

	if( internal_handle == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_MEMORY,
		 LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
		 "%s: unable to create handle.",
		 function );

		goto on_error;
	}
	if( memory_set(
	     internal_handle,
	     0,
	     sizeof( libvsmbr_internal_handle_t ) ) == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_MEMORY,
		 LIBCERROR_MEMORY_ERROR_SET_FAILED,
		 "%s: unable to clear handle.",
		 function );

		memory_free(
		 internal_handle );

		return( -1 );
	}
	if( libvsmbr_io_handle_initialize(
	     &( internal_handle->io_handle ),
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create IO handle.",
		 function );

		goto on_error;
	}
	if( libcdata_array_initialize(
	     &( internal_handle->partitions_array ),
	     0,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create partitions array.",
		 function );

		goto on_error;
	}
	if( libcdata_array_initialize(
	     &( internal_handle->sections_array ),
	     0,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create sections array.",
		 function );

		goto on_error;
	}
	*handle = (libvsmbr_handle_t *) internal_handle;

	return( 1 );

on_error:
	if( internal_handle != NULL )
	{
		if( internal_handle->partitions_array != NULL )
		{
			libcdata_array_free(
			 &( internal_handle->partitions_array ),
			 (int (*)(intptr_t **, libcerror_error_t **)) &libvsmbr_partition_values_free,
			 NULL );
		}
		memory_free(
		 internal_handle );
	}
	return( -1 );
}
コード例 #30
0
ファイル: mount_handle.c プロジェクト: gema-arta/libvslvm
/* Frees a mount handle
 * Returns 1 if successful or -1 on error
 */
int mount_handle_free(
     mount_handle_t **mount_handle,
     libcerror_error_t **error )
{
	static char *function = "mount_handle_free";
	int result            = 1;

	if( mount_handle == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid mount handle.",
		 function );

		return( -1 );
	}
	if( *mount_handle != NULL )
	{
		if( libcdata_array_free(
		     &( ( *mount_handle )->logical_volumes_array ),
		     (int (*)(intptr_t **, libcerror_error_t **)) &libvslvm_logical_volume_free,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
			 "%s: unable to free logical volumes array.",
			 function );

			result = -1;
		}
		if( ( *mount_handle )->volume_group != NULL )
		{
			if( libvslvm_volume_group_free(
			     &( ( *mount_handle )->volume_group ),
			     error ) != 1 )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
				 "%s: unable to free volume group.",
				 function );

				result = -1;
			}
		}
		if( libvslvm_handle_free(
		     &( ( *mount_handle )->input_handle ),
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
			 "%s: unable to free input handle.",
			 function );

			result = -1;
		}
		if( libbfio_pool_free(
		     &( ( *mount_handle )->physical_volume_file_io_pool ),
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
			 "%s: unable to free physical volume file IO pool.",
			 function );

			result = -1;
		}
		if( libbfio_handle_free(
		     &( ( *mount_handle )->input_file_io_handle ),
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
			 "%s: unable to free input file IO handle.",
			 function );

			result = -1;
		}
		memory_free(
		 *mount_handle );

		*mount_handle = NULL;
	}
	return( result );
}