/* 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 ); }
/* 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 ); }
/* 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 ); }
/* 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 ); }