Esempio n. 1
0
/* Retrieves the identifier of the item
 * Returns 1 if successful or -1 on error
 */
int libpff_item_tree_get_identifier(
     libcdata_tree_node_t *item_tree_node,
     uint32_t *identifier,
     libcerror_error_t **error )
{
	libpff_item_descriptor_t *item_descriptor = NULL;
	static char *function                     = "libpff_item_tree_get_identifier";

	if( item_tree_node == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid item tree node.",
		 function );

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

		return( -1 );
	}
	if( libcdata_tree_node_get_value(
	     item_tree_node,
	     (intptr_t **) &item_descriptor,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
		 "%s: unable to retrieve item descriptor.",
		 function );

		return( -1 );
	}
	if( item_descriptor == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
		 "%s: missing item descriptor.",
		 function );

		return( -1 );
	}
	*identifier = item_descriptor->descriptor_identifier;

	return( 1 );
}
Esempio n. 2
0
/* Creates an item
 * Make sure the value item is referencing, is set to NULL
 * Returns 1 if successful or -1 on error
 */
int libolecf_item_initialize(
     libolecf_item_t **item,
     libolecf_io_handle_t *io_handle,
     libbfio_handle_t *file_io_handle,
     libolecf_internal_file_t *file,
     libcdata_tree_node_t *directory_tree_node,
     libcerror_error_t **error )
{
	libolecf_internal_item_t *internal_item = NULL;
	static char *function                   = "libolecf_item_initialize";

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

		return( -1 );
	}
	if( *item != NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
		 "%s: invalid item value 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 );
	}
	if( file_io_handle == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid file IO handle.",
		 function );

		return( -1 );
	}
	if( directory_tree_node == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid directory tree node.",
		 function );

		return( -1 );
	}
	internal_item = memory_allocate_structure(
	                 libolecf_internal_item_t );

	if( internal_item == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create internal item.",
		 function );

		goto on_error;
	}
	if( memory_set(
	     internal_item,
	     0,
	     sizeof( libolecf_internal_item_t ) ) == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_MEMORY,
		 LIBCERROR_MEMORY_ERROR_SET_FAILED,
		 "%s: unable to clear internal item.",
		 function );

		goto on_error;
	}
	internal_item->file_io_handle      = file_io_handle;
	internal_item->io_handle           = io_handle;
	internal_item->file                = file;
	internal_item->directory_tree_node = directory_tree_node;

	if( libcdata_tree_node_get_value(
	     directory_tree_node,
	     (intptr_t **) &( internal_item->directory_entry ),
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
		 "%s: unable to retrieve value from directory tree node.",
		 function );

		goto on_error;
	}
	*item = (libolecf_item_t *) internal_item;

	return( 1 );

on_error:
	if( internal_item != NULL )
	{
		memory_free(
		 internal_item );
	}
	return( -1 );
}
/* Retrieves the single file entry sub node for the specific UTF-8 formatted name
 * Returns 1 if successful, 0 if no such sub single file entry or -1 on error
 */
int libewf_single_file_tree_get_sub_node_by_utf8_name(
     libcdata_tree_node_t *node,
     const uint8_t *utf8_string,
     size_t utf8_string_length,
     libcdata_tree_node_t **sub_node,
     libewf_single_file_entry_t **sub_single_file_entry,
     libcerror_error_t **error )
{
	static char *function   = "libewf_single_file_tree_get_sub_node_by_utf8_name";
	int number_of_sub_nodes = 0;
	int result              = 0;
	int sub_node_index      = 0;

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

		return( -1 );
	}
	if( sub_node == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid sub node.",
		 function );

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

		return( -1 );
	}
	if( libcdata_tree_node_get_number_of_sub_nodes(
	     node,
	     &number_of_sub_nodes,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
		 "%s: unable to retrieve number of sub nodes.",
		 function );

		goto on_error;
	}
	if( libcdata_tree_node_get_sub_node_by_index(
	     node,
	     0,
	     sub_node,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
		 "%s: unable to retrieve first sub node.",
		 function );

		goto on_error;
	}
	for( sub_node_index = 0;
	     sub_node_index < number_of_sub_nodes;
	     sub_node_index++ )
	{
		if( libcdata_tree_node_get_value(
		     *sub_node,
		     (intptr_t **) sub_single_file_entry,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
			 "%s: unable to retrieve value from sub node: %d.",
			 function,
			 sub_node_index );

			goto on_error;
		}
		if( *sub_single_file_entry == NULL )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
			 "%s: missing sub single file entry: %d.",
			 function,
			 sub_node_index );

			goto on_error;
		}
		if( ( *sub_single_file_entry )->name != NULL )
		{
			result = libuna_utf8_string_compare_with_utf8_stream(
				  utf8_string,
				  utf8_string_length,
				  ( *sub_single_file_entry )->name,
				  (size_t) ( *sub_single_file_entry )->name_size,
				  error );
		}
		if( result == -1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_GENERIC,
			 "%s: unable to compare UTF-8 string.",
			 function );

			return( -1 );
		}
		else if( result != 0 )
		{
			break;
		}
		if( libcdata_tree_node_get_next_node(
		     *sub_node,
		     sub_node,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
			 "%s: unable to retrieve next node from sub node: %d.",
			 function,
			 sub_node_index );

			goto on_error;
		}
	}
	if( sub_node_index >= number_of_sub_nodes )
	{
		*sub_node              = NULL;
		*sub_single_file_entry = NULL;

		return( 0 );
	}
	return( 1 );

on_error:
	*sub_node              = NULL;
	*sub_single_file_entry = NULL;

	return( -1 );
}
Esempio n. 4
0
/* Retrieves the tree node of an item node
 * Returns 1 if successful, 0 if the item node was not found or -1 on error
 */
int libpff_item_tree_get_tree_node_by_identifier(
     libcdata_tree_node_t *item_tree_node,
     uint32_t item_identifier,
     libcdata_tree_node_t **result_item_tree_node,
     libcerror_error_t **error )
{
	libcdata_tree_node_t *sub_tree_node       = NULL;
	libpff_item_descriptor_t *item_descriptor = NULL;
	static char *function                     = "libpff_item_tree_get_tree_node_by_identifier";
	int number_of_sub_nodes                   = 0;
	int result                                = 0;
	int sub_node_index                        = 0;

	if( item_tree_node == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid item tree node.",
		 function );

		return( -1 );
	}
	if( libcdata_tree_node_get_value(
	     item_tree_node,
	     (intptr_t **) &item_descriptor,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
		 "%s: unable to retrieve item descriptor.",
		 function );

		return( -1 );
	}
	if( item_descriptor == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
		 "%s: missing item descriptor.",
		 function );

		return( -1 );
	}
	if( item_descriptor->descriptor_identifier == item_identifier )
	{
		if( result_item_tree_node == NULL )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
			 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
			 "%s: invalid result item tree node.",
			 function );

			return( -1 );
		}
		if( *result_item_tree_node != NULL )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
			 "%s: result item tree node already set.",
			 function );

			return( -1 );
		}
		*result_item_tree_node = item_tree_node;

		return( 1 );
	}
	if( libcdata_tree_node_get_number_of_sub_nodes(
	     item_tree_node,
	     &number_of_sub_nodes,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
		 "%s: unable to retrieve number of sub nodes.",
		 function );

		return( -1 );
	}
	if( number_of_sub_nodes > 0 )
	{
		if( libcdata_tree_node_get_sub_node_by_index(
		     item_tree_node,
		     0,
		     &sub_tree_node,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
			 "%s: unable to retrieve first sub node.",
			 function );

			return( -1 );
		}
		for( sub_node_index = 0;
		     sub_node_index < number_of_sub_nodes;
		     sub_node_index++ )
		{
			if( sub_tree_node == NULL )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
				 "%s: corruption detected for sub node: %d.",
				 function,
				 sub_node_index );

				return( -1 );
			}
			result = libpff_item_tree_get_tree_node_by_identifier(
			          sub_tree_node,
			          item_identifier,
			          result_item_tree_node,
			          error );

			if( result == -1 )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
				 "%s: unable to traverse sub node: %d.",
				 function,
				 sub_node_index );

				return( -1 );
			}
			else if( result != 0 )
			{
				break;
			}
			if( libcdata_tree_node_get_next_node(
			     sub_tree_node,
			     &sub_tree_node,
			     error ) != 1 )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
				 "%s: unable to retrieve next node of sub node: %d.",
				 function,
				 sub_node_index );

				return( -1 );
			}
		}
	}
	return( result );
}
Esempio n. 5
0
/* Retrieves the sub node for the specific UTF-16 formatted name
 * Returns 1 if successful, 0 if no such sub node or -1 on error
 */
int libolecf_directory_tree_get_sub_node_by_utf16_name(
     libcdata_tree_node_t *directory_tree_node,
     const uint16_t *utf16_string,
     size_t utf16_string_length,
     uint8_t byte_order,
     libcdata_tree_node_t **sub_directory_tree_node,
     libcerror_error_t **error )
{
	libcdata_tree_node_t *safe_sub_directory_tree_node = NULL;
	libolecf_directory_entry_t *sub_directory_entry    = NULL;
	static char *function                              = "libolecf_directory_tree_get_sub_node_by_utf16_name";
	int number_of_sub_nodex                            = 0;
	int result                                         = 0;
	int sub_node_index                                 = 0;

	if( directory_tree_node == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid directory tree node.",
		 function );

		return( -1 );
	}
	if( sub_directory_tree_node == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid sub directory tree node.",
		 function );

		return( -1 );
	}
	*sub_directory_tree_node = NULL;

	if( libcdata_tree_node_get_number_of_sub_nodes(
	     directory_tree_node,
	     &number_of_sub_nodex,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
		 "%s: unable to retrieve number of sub nodex.",
		 function );

		return( -1 );
	}
	for( sub_node_index = 0;
	     sub_node_index < number_of_sub_nodex;
	     sub_node_index++ )
        {
		if( libcdata_tree_node_get_sub_node_by_index(
		     directory_tree_node,
		     sub_node_index,
		     &safe_sub_directory_tree_node,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
			 "%s: unable to retrieve number of sub nodex: %d.",
			 function,
			 sub_node_index );

			return( -1 );
		}
		if( libcdata_tree_node_get_value(
		     safe_sub_directory_tree_node,
		     (intptr_t **) &sub_directory_entry,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
			 "%s: unable to retrieve value from sub directory tree node: %d.",
			 function,
			 sub_node_index );

			return( -1 );
		}
		if( sub_directory_entry == NULL )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
			 "%s: missing sub directory entry: %d.",
			 function,
			 sub_node_index );

			return( -1 );
		}
		result = libuna_utf16_string_compare_with_utf16_stream(
		          utf16_string,
		          utf16_string_length,
		          sub_directory_entry->name,
		          sub_directory_entry->name_size,
		          byte_order,
		          error );

		if( result == -1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_GENERIC,
			 "%s: unable to compare sub directory entry: %d name.",
			 function,
			 sub_node_index );

			return( -1 );
		}
		else if( result == LIBUNA_COMPARE_EQUAL )
		{
			*sub_directory_tree_node = safe_sub_directory_tree_node;

			return( 1 );
		}
	}
	return( 0 );
}
/* Creates a resource
 * Make sure the value resource is referencing, is set to NULL
 * Returns 1 if successful or -1 on error
 */
int libwrc_resource_initialize(
     libwrc_resource_t **resource,
     libwrc_io_handle_t *io_handle,
     libbfio_handle_t *file_io_handle,
     libcdata_tree_node_t *resource_node,
     uint8_t flags,
     libcerror_error_t **error )
{
	libwrc_internal_resource_t *internal_resource = NULL;
	libwrc_resource_values_t *resource_values     = NULL;
	static char *function                         = "libwrc_resource_initialize";

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

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

		return( -1 );
	}
	if( resource_node == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid resource node.",
		 function );

		return( -1 );
	}
	if( ( flags & ~( LIBWRC_RESOURCE_FLAG_MANAGED_FILE_IO_HANDLE ) ) != 0 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
		 "%s: unsupported flags: 0x%02" PRIx8 ".",
		 function,
		 flags );

		return( -1 );
	}
	if( libcdata_tree_node_get_value(
	     resource_node,
	     (intptr_t **) &resource_values,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
		 "%s: unable to retrieve value of resource node.",
		 function );

		goto on_error;
	}
	if( resource_values == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
		 "%s: invalid resource values.",
		 function );

		goto on_error;
	}
	internal_resource = memory_allocate_structure(
	                     libwrc_internal_resource_t );

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

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

		memory_free(
		 internal_resource );

		return( -1 );
	}
	if( ( flags & LIBWRC_RESOURCE_FLAG_MANAGED_FILE_IO_HANDLE ) == 0 )
	{
		internal_resource->file_io_handle = file_io_handle;
	}
	else
	{
		if( libbfio_handle_clone(
		     &( internal_resource->file_io_handle ),
		     file_io_handle,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
			 "%s: unable to copy file IO handle.",
			 function );

			goto on_error;
		}
		if( libbfio_handle_set_open_on_demand(
		     internal_resource->file_io_handle,
		     1,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
			 "%s: unable to set open on demand in file IO handle.",
			 function );

			goto on_error;
		}
	}
	internal_resource->io_handle       = io_handle;
	internal_resource->resource_node   = resource_node;
	internal_resource->resource_values = resource_values;
	internal_resource->flags           = flags;

	*resource = (libwrc_resource_t *) internal_resource;

	return( 1 );

on_error:
	if( internal_resource != NULL )
	{
		if( ( flags & LIBWRC_RESOURCE_FLAG_MANAGED_FILE_IO_HANDLE ) != 0 )
		{
			if( internal_resource->file_io_handle != NULL )
			{
				libbfio_handle_free(
				 &( internal_resource->file_io_handle ),
				 NULL );
			}
		}
		memory_free(
		 internal_resource );
	}
	return( -1 );
}
/* Read the values
 * Returns 1 if successful or -1 on error
 */
int libwrc_resource_read_value(
     libwrc_internal_resource_t *internal_resource,
     libcerror_error_t **error )
{
	libcdata_tree_node_t *leaf_node                  = NULL;
	libcdata_tree_node_t *sub_node                   = NULL;
	libwrc_data_descriptor_t *data_descriptor        = NULL;
	libwrc_language_entry_t *existing_language_entry = NULL;
	libwrc_language_entry_t *language_entry          = NULL;
	libwrc_resource_values_t *leaf_resource_values   = NULL;
	libwrc_resource_values_t *sub_resource_values    = NULL;
	const char *resource_type_string                 = NULL;
	static char *function                            = "libwrc_resource_read_value";
	int entry_index                                  = 0;
	int leaf_node_index                              = 0;
	int number_of_leaf_nodes                         = 0;
	int number_of_sub_nodes                          = 0;
	int result                                       = 0;
	int sub_node_index                               = 0;

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

		return( -1 );
	}
	if( internal_resource->resource_node == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
		 "%s: invalid resource - missing resource node.",
		 function );

		return( -1 );
	}
	if( internal_resource->resource_values == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
		 "%s: invalid resource - missing resource values.",
		 function );

		return( -1 );
	}
	switch( internal_resource->resource_values->type )
	{
		case LIBWRC_RESOURCE_TYPE_STRING:
			resource_type_string = "string";

			result = libwrc_language_table_initialize(
			          (libwrc_language_table_t **) &( internal_resource->value ),
			          error );

			internal_resource->free_value = (int (*)(intptr_t **, libcerror_error_t **)) &libwrc_language_table_free;

			break;

		case LIBWRC_RESOURCE_TYPE_MESSAGE_TABLE:
			resource_type_string = "message table";

			result = libwrc_language_table_initialize(
			          (libwrc_language_table_t **) &( internal_resource->value ),
			          error );

			internal_resource->free_value = (int (*)(intptr_t **, libcerror_error_t **)) &libwrc_language_table_free;

			break;

		case LIBWRC_RESOURCE_TYPE_MANIFEST:
			resource_type_string = "manifest";

			result = libwrc_language_table_initialize(
			          (libwrc_language_table_t **) &( internal_resource->value ),
			          error );

			internal_resource->free_value = (int (*)(intptr_t **, libcerror_error_t **)) &libwrc_language_table_free;

			break;

		case LIBWRC_RESOURCE_TYPE_MUI:
			resource_type_string = "mui";

			result = libwrc_language_table_initialize(
			          (libwrc_language_table_t **) &( internal_resource->value ),
			          error );

			internal_resource->free_value = (int (*)(intptr_t **, libcerror_error_t **)) &libwrc_language_table_free;

			break;

		case LIBWRC_RESOURCE_TYPE_VERSION:
			resource_type_string = "version";

			result = libwrc_language_table_initialize(
			          (libwrc_language_table_t **) &( internal_resource->value ),
			          error );

			internal_resource->free_value = (int (*)(intptr_t **, libcerror_error_t **)) &libwrc_language_table_free;

			break;

		case LIBWRC_RESOURCE_TYPE_WEVT_TEMPLATE:
			resource_type_string = "event template";

			result = libwrc_language_table_initialize(
			          (libwrc_language_table_t **) &( internal_resource->value ),
			          error );

			internal_resource->free_value = (int (*)(intptr_t **, libcerror_error_t **)) &libwrc_language_table_free;

			break;

		default:
#if defined( HAVE_DEBUG_OUTPUT )
			resource_type_string = "UNKNOWN";

			result = 1;

			break;
#else
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
			 LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
			 "%s: unsupported resource type: 0x%08" PRIx32 ".",
			 function,
			 internal_resource->resource_values->type );

			goto on_error;
#endif
	}
	if( result != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_MEMORY,
		 LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
		 "%s: unable to create %s resource.",
		 function,
		 resource_type_string );

		goto on_error;
	}
	if( libcdata_tree_node_get_number_of_sub_nodes(
	     internal_resource->resource_node,
	     &number_of_sub_nodes,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
		 "%s: unable to retrieve number of sub nodes.",
		 function );

		goto on_error;
	}
	if( ( internal_resource->resource_values->type == LIBWRC_RESOURCE_TYPE_MESSAGE_TABLE )
	 || ( internal_resource->resource_values->type == LIBWRC_RESOURCE_TYPE_VERSION )
	 || ( internal_resource->resource_values->type == LIBWRC_RESOURCE_TYPE_MANIFEST )
	 || ( internal_resource->resource_values->type == LIBWRC_RESOURCE_TYPE_MUI )
	 || ( internal_resource->resource_values->type == LIBWRC_RESOURCE_TYPE_WEVT_TEMPLATE ) )
	{
		if( number_of_sub_nodes != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
			 LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
			 "%s: unsupported number of sub nodes: %d.",
			 function,
			 number_of_sub_nodes );

			goto on_error;
		}
	}
	for( sub_node_index = 0;
	     sub_node_index < number_of_sub_nodes;
	     sub_node_index++ )
	{
		if( libcdata_tree_node_get_sub_node_by_index(
		     internal_resource->resource_node,
		     sub_node_index,
		     &sub_node,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
			 "%s: unable to retrieve sub node: %d.",
			 function,
			 sub_node_index );

			goto on_error;
		}
		if( libcdata_tree_node_get_value(
		     sub_node,
		     (intptr_t **) &sub_resource_values,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
			 "%s: unable to retrieve value of sub node: %d.",
			 function,
			 sub_node_index );

			goto on_error;
		}
		if( sub_resource_values == NULL )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
			 "%s: invalid sub resource values: %d.",
			 function,
			 sub_node_index );

			goto on_error;
		}
		if( libcdata_tree_node_get_number_of_sub_nodes(
		     sub_node,
		     &number_of_leaf_nodes,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
			 "%s: unable to retrieve number of leaf nodes.",
			 function );

			goto on_error;
		}
		for( leaf_node_index = 0;
		     leaf_node_index < number_of_leaf_nodes;
		     leaf_node_index++ )
		{
			if( libcdata_tree_node_get_sub_node_by_index(
			     sub_node,
			     leaf_node_index,
			     &leaf_node,
			     error ) != 1 )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
				 "%s: unable to retrieve leaf node: %d.",
				 function,
				 leaf_node_index );

				goto on_error;
			}
			if( libcdata_tree_node_get_value(
			     leaf_node,
			     (intptr_t **) &leaf_resource_values,
			     error ) != 1 )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
				 "%s: unable to retrieve value of leaf node: %d.",
				 function,
				 leaf_node_index );

				goto on_error;
			}
			if( leaf_resource_values == NULL )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
				 "%s: invalid leaf resource values: %d.",
				 function,
				 leaf_node_index );

				goto on_error;
			}
			if( leaf_resource_values->data_descriptor == NULL )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
				 "%s: invalid leaf resource values: 0x%08" PRIx32 " - missing data descriptor.",
				 function,
				 leaf_resource_values->identifier );

				goto on_error;
			}
			data_descriptor = leaf_resource_values->data_descriptor;

			switch( internal_resource->resource_values->type )
			{
				case LIBWRC_RESOURCE_TYPE_STRING:
					result = libwrc_language_table_get_entry_by_identifier(
						  (libwrc_language_table_t *) internal_resource->value,
						  leaf_resource_values->identifier,
						  &existing_language_entry,
						  error );

					if( result == -1 )
					{
						libcerror_error_set(
						 error,
						 LIBCERROR_ERROR_DOMAIN_RUNTIME,
						 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
						 "%s: unable to retrieve number of language entry: 0x%08" PRIx32 ".",
						 function );

						goto on_error;
					}
					if( existing_language_entry != NULL )
					{
						language_entry = existing_language_entry;
					}
					else
					{
						if( libwrc_language_entry_initialize(
						     &language_entry,
						     leaf_resource_values->identifier,
						     (int (*)(intptr_t **, libcerror_error_t **)) &libfvalue_value_free,
						     error ) != 1 )
						{
							libcerror_error_set(
							 error,
							 LIBCERROR_ERROR_DOMAIN_RUNTIME,
							 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
							 "%s: unable to create language entry.",
							 function );

							goto on_error;
						}
					}
					break;

				case LIBWRC_RESOURCE_TYPE_MANIFEST:
				case LIBWRC_RESOURCE_TYPE_MESSAGE_TABLE:
					if( libwrc_language_entry_initialize(
					     &language_entry,
					     leaf_resource_values->identifier,
					     (int (*)(intptr_t **, libcerror_error_t **)) &libfvalue_value_free,
					     error ) != 1 )
					{
						libcerror_error_set(
						 error,
						 LIBCERROR_ERROR_DOMAIN_RUNTIME,
						 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
						 "%s: unable to create language entry.",
						 function );

						goto on_error;
					}
					break;

				case LIBWRC_RESOURCE_TYPE_MUI:
					if( libwrc_language_entry_initialize(
					     &language_entry,
					     leaf_resource_values->identifier,
					     (int (*)(intptr_t **, libcerror_error_t **)) &libwrc_mui_values_free,
					     error ) != 1 )
					{
						libcerror_error_set(
						 error,
						 LIBCERROR_ERROR_DOMAIN_RUNTIME,
						 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
						 "%s: unable to create MUI values.",
						 function );

						goto on_error;
					}
					break;

				case LIBWRC_RESOURCE_TYPE_VERSION:
					if( libwrc_language_entry_initialize(
					     &language_entry,
					     leaf_resource_values->identifier,
					     (int (*)(intptr_t **, libcerror_error_t **)) &libwrc_version_values_free,
					     error ) != 1 )
					{
						libcerror_error_set(
						 error,
						 LIBCERROR_ERROR_DOMAIN_RUNTIME,
						 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
						 "%s: unable to create version values.",
						 function );

						goto on_error;
					}
					break;

				case LIBWRC_RESOURCE_TYPE_WEVT_TEMPLATE:
					if( libwrc_language_entry_initialize(
					     &language_entry,
					     leaf_resource_values->identifier,
					     (int (*)(intptr_t **, libcerror_error_t **)) &libfwevt_manifest_free,
					     error ) != 1 )
					{
						libcerror_error_set(
						 error,
						 LIBCERROR_ERROR_DOMAIN_RUNTIME,
						 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
						 "%s: unable to create event template values.",
						 function );

						goto on_error;
					}
					break;
			}
#if defined( HAVE_DEBUG_OUTPUT )
			switch( internal_resource->resource_values->type )
			{
				case LIBWRC_RESOURCE_TYPE_STRING:
					if( libcnotify_verbose != 0 )
					{
						libcnotify_printf(
						 "%s: reading string: 0x%08" PRIx32 " for language identifier: 0x%08" PRIx32 " (%s)\n",
						 function,
						 sub_resource_values->identifier - 1,
						 leaf_resource_values->identifier,
						 libfwnt_locale_identifier_language_tag_get_identifier(
						  leaf_resource_values->identifier & 0x0000ffffUL ) );
					}
					break;

				case LIBWRC_RESOURCE_TYPE_MANIFEST:
				case LIBWRC_RESOURCE_TYPE_MESSAGE_TABLE:
				case LIBWRC_RESOURCE_TYPE_MUI:
				case LIBWRC_RESOURCE_TYPE_VERSION:
				case LIBWRC_RESOURCE_TYPE_WEVT_TEMPLATE:
					if( libcnotify_verbose != 0 )
					{
						libcnotify_printf(
						 "%s: reading %s for language identifier: 0x%08" PRIx32 " (%s)\n",
						 function,
						 resource_type_string,
						 leaf_resource_values->identifier,
						 libfwnt_locale_identifier_language_tag_get_identifier(
						  leaf_resource_values->identifier & 0x0000ffffUL ) );
					}
					break;
			}
#endif
			switch( internal_resource->resource_values->type )
			{
				case LIBWRC_RESOURCE_TYPE_STRING:
					result = libwrc_string_values_read(
					          language_entry,
					          internal_resource->io_handle,
					          internal_resource->file_io_handle,
					          sub_resource_values->identifier - 1,
					          data_descriptor,
					          error );
					break;

				case LIBWRC_RESOURCE_TYPE_MESSAGE_TABLE:
					result = libwrc_message_table_values_read(
					          language_entry,
					          internal_resource->io_handle,
					          internal_resource->file_io_handle,
					          data_descriptor,
					          error );
					break;

				case LIBWRC_RESOURCE_TYPE_MANIFEST:
					result = libwrc_manifest_values_read(
					          language_entry,
					          internal_resource->io_handle,
					          internal_resource->file_io_handle,
					          data_descriptor,
					          error );
					break;

				case LIBWRC_RESOURCE_TYPE_MUI:
					result = libwrc_mui_values_read(
					          language_entry,
					          internal_resource->io_handle,
					          internal_resource->file_io_handle,
					          data_descriptor,
					          error );
					break;

				case LIBWRC_RESOURCE_TYPE_VERSION:
					result = libwrc_version_values_read(
					          language_entry,
					          internal_resource->io_handle,
					          internal_resource->file_io_handle,
					          data_descriptor,
					          error );
					break;

				case LIBWRC_RESOURCE_TYPE_WEVT_TEMPLATE:
					result = libwrc_wevt_template_values_read(
					          language_entry,
					          internal_resource->io_handle,
					          internal_resource->file_io_handle,
					          data_descriptor,
					          error );
					break;

#if defined( HAVE_DEBUG_OUTPUT )
				default:
					if( libwrc_resource_read_data_descriptor(
					     internal_resource,
					     internal_resource->io_handle,
					     internal_resource->file_io_handle,
					     data_descriptor,
					     error ) != 1 )
					{
						libcerror_error_set(
						 error,
						 LIBCERROR_ERROR_DOMAIN_IO,
						 LIBCERROR_IO_ERROR_READ_FAILED,
						 "%s: unable to read unknown resource.",
						 function );

						goto on_error;
					}
					break;
#endif
			}
			switch( internal_resource->resource_values->type )
			{
				case LIBWRC_RESOURCE_TYPE_STRING:
					if( result != 1 )
					{
						libcerror_error_set(
						 error,
						 LIBCERROR_ERROR_DOMAIN_IO,
						 LIBCERROR_IO_ERROR_READ_FAILED,
						 "%s: unable to read %s: 0x%08" PRIx32 " for language identifier: 0x%08" PRIx32 ".",
						 function,
						 resource_type_string,
						 sub_resource_values->identifier,
						 leaf_resource_values->identifier );

						goto on_error;
					}
					if( language_entry != existing_language_entry )
					{
						if( libwrc_language_table_append_entry(
						     (libwrc_language_table_t *) internal_resource->value,
						     &entry_index,
						     language_entry,
						     error ) != 1 )
						{
							libcerror_error_set(
							 error,
							 LIBCERROR_ERROR_DOMAIN_RUNTIME,
							 LIBCERROR_RUNTIME_ERROR_APPEND_FAILED,
							 "%s: unable to append messages for language identifier: 0x%08" PRIx32 " to languages array.",
							 function,
							 leaf_resource_values->identifier );

							goto on_error;
						}
					}
					language_entry = NULL;

					break;

				case LIBWRC_RESOURCE_TYPE_MANIFEST:
				case LIBWRC_RESOURCE_TYPE_MESSAGE_TABLE:
				case LIBWRC_RESOURCE_TYPE_MUI:
				case LIBWRC_RESOURCE_TYPE_VERSION:
				case LIBWRC_RESOURCE_TYPE_WEVT_TEMPLATE:
					if( result != 1 )
					{
						libcerror_error_set(
						 error,
						 LIBCERROR_ERROR_DOMAIN_IO,
						 LIBCERROR_IO_ERROR_READ_FAILED,
						 "%s: unable to read %s for language identifier: 0x%08" PRIx32 ".",
						 function,
						 resource_type_string,
						 leaf_resource_values->identifier );

						goto on_error;
					}
					if( libwrc_language_table_append_entry(
					     (libwrc_language_table_t *) internal_resource->value,
					     &entry_index,
					     language_entry,
					     error ) != 1 )
					{
						libcerror_error_set(
						 error,
						 LIBCERROR_ERROR_DOMAIN_RUNTIME,
						 LIBCERROR_RUNTIME_ERROR_APPEND_FAILED,
						 "%s: unable to append %s for language identifier: 0x%08" PRIx32 " to languages array.",
						 function,
						 resource_type_string,
						 leaf_resource_values->identifier );

						goto on_error;
					}
					language_entry = NULL;

					break;
			}
		}
	}
	return( 1 );

on_error:
	if( ( language_entry != NULL )
	 && ( language_entry != existing_language_entry ) )
	{
		libwrc_language_entry_free(
		 &language_entry,
		 NULL );
	}
	if( internal_resource->value != NULL )
	{
		if( internal_resource->free_value != NULL )
		{
			internal_resource->free_value(
			 &( internal_resource->value ),
			 NULL );
		}
		internal_resource->free_value = NULL;
	}
	return( -1 );
}
Esempio n. 8
0
/* Retrieves a specific resource by an UTF-16 formatted name
 * Returns 1 if successful, 0 if no such resource or -1 on error
 */
int libwrc_stream_get_resource_by_utf16_name(
     libwrc_stream_t *stream,
     const uint16_t *utf16_string,
     size_t utf16_string_length,
     libwrc_resource_t **resource,
     libcerror_error_t **error )
{
	libcdata_tree_node_t *resource_node       = NULL;
	libwrc_internal_stream_t *internal_stream = NULL;
	libwrc_resource_values_t *resource_values = NULL;
	static char *function                     = "libwrc_stream_get_resource_by_type";
	int number_of_resources                   = 0;
	int resource_index                        = 0;
	int result                                = 0;

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

		return( -1 );
	}
	internal_stream = (libwrc_internal_stream_t *) stream;

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

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

		return( -1 );
	}
	if( libcdata_tree_node_get_number_of_sub_nodes(
	     internal_stream->resources_root_node,
	     &number_of_resources,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
		 "%s: unable to retrieve number of resources.",
		 function );

		return( -1 );
	}
	if( libcdata_tree_node_get_sub_node_by_index(
	     internal_stream->resources_root_node,
	     0,
	     &resource_node,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
		 "%s: unable to retrieve first resource node.",
		 function );

		return( -1 );
	}
	for( resource_index = 0;
	     resource_index < number_of_resources;
	     resource_index++ )
	{
		if( libcdata_tree_node_get_value(
		     resource_node,
		     (intptr_t **) &resource_values,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
			 "%s: unable to retrieve value of resource node: %d.",
			 function,
			 resource_index );

			return( -1 );
		}
		if( resource_values == NULL )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
			 "%s: missing resource values: %d.",
			 function,
			 resource_index );

			return( -1 );
		}
		if( resource_values->name_string_size > 0 )
		{
			result = libuna_utf16_string_compare_with_utf16_stream(
			          utf16_string,
			          utf16_string_length + 1,
			          resource_values->name_string,
			          resource_values->name_string_size,
			          LIBUNA_ENDIAN_LITTLE,
			          error );

			if( result == -1 )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_GENERIC,
				 "%s: unable to compare name of resource node: %d.",
				 function,
				 resource_index );

				return( -1 );
			}
			else if( result == LIBUNA_COMPARE_EQUAL )
			{
				if( libwrc_resource_initialize(
				     resource,
				     internal_stream->io_handle,
				     internal_stream->file_io_handle,
				     resource_node,
				     LIBWRC_RESOURCE_FLAGS_DEFAULT,
				     error ) != 1 )
				{
					libcerror_error_set(
					 error,
					 LIBCERROR_ERROR_DOMAIN_RUNTIME,
					 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
					 "%s: unable to create resource.",
					 function );

					return( -1 );
				}
				return( 1 );
			}
		}
		if( libcdata_tree_node_get_next_node(
		     resource_node,
		     &resource_node,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
			 "%s: unable to retrieve next node of resource node: %d.",
			 function,
			 resource_index );

			return( -1 );
		}
	}
	return( 0 );
}
Esempio n. 9
0
/* Retrieves a specific resource by type
 * Returns 1 if successful, 0 if no such resource or -1 on error
 */
int libwrc_stream_get_resource_by_type(
     libwrc_stream_t *stream,
     int type,
     libwrc_resource_t **resource,
     libcerror_error_t **error )
{
	libcdata_tree_node_t *resource_node       = NULL;
	libwrc_internal_stream_t *internal_stream = NULL;
	libwrc_resource_values_t *resource_values = NULL;
	static char *function                     = "libwrc_stream_get_resource_by_type";
	int number_of_resources                   = 0;
	int resource_index                        = 0;

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

		return( -1 );
	}
	internal_stream = (libwrc_internal_stream_t *) stream;

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

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

		return( -1 );
	}
	if( libcdata_tree_node_get_number_of_sub_nodes(
	     internal_stream->resources_root_node,
	     &number_of_resources,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
		 "%s: unable to retrieve number of resources.",
		 function );

		return( -1 );
	}
	if( libcdata_tree_node_get_sub_node_by_index(
	     internal_stream->resources_root_node,
	     0,
	     &resource_node,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
		 "%s: unable to retrieve first resource node.",
		 function );

		return( -1 );
	}
	for( resource_index = 0;
	     resource_index < number_of_resources;
	     resource_index++ )
	{
		if( libcdata_tree_node_get_value(
		     resource_node,
		     (intptr_t **) &resource_values,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
			 "%s: unable to retrieve value of resource node: %d.",
			 function,
			 resource_index );

			return( -1 );
		}
		if( resource_values == NULL )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
			 "%s: missing resource values: %d.",
			 function,
			 resource_index );

			return( -1 );
		}
		if( type == resource_values->type )
		{
			if( libwrc_resource_initialize(
			     resource,
			     internal_stream->io_handle,
			     internal_stream->file_io_handle,
			     resource_node,
			     LIBWRC_RESOURCE_FLAGS_DEFAULT,
			     error ) != 1 )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
				 "%s: unable to create resource.",
				 function );

				return( -1 );
			}
			return( 1 );
		}
		if( libcdata_tree_node_get_next_node(
		     resource_node,
		     &resource_node,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
			 "%s: unable to retrieve next node of resource node: %d.",
			 function,
			 resource_index );

			return( -1 );
		}
	}
	return( 0 );
}