/* Retrieves a specific name to map entry * Returns 1 if successful, 0 if not or -1 on error */ int libpff_name_to_id_map_entry_get_entry_by_identifier( libcdata_list_t *name_to_id_map_list, uint32_t identifier, libpff_internal_name_to_id_map_entry_t **name_to_id_map_entry, libcerror_error_t **error ) { libcdata_list_element_t *list_element = NULL; libpff_internal_name_to_id_map_entry_t *search_name_to_id_map_entry = NULL; static char *function = "libpff_name_to_id_map_entry_get_entry_by_identifier"; int element_index = 0; int number_of_elements = 0; if( name_to_id_map_entry == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid name to id map entry.", function ); return( -1 ); } *name_to_id_map_entry = NULL; if( name_to_id_map_list == NULL ) { return( 0 ); } if( libcdata_list_get_number_of_elements( name_to_id_map_list, &number_of_elements, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve number of name to id map entries.", function ); return( -1 ); } if( libcdata_list_get_first_element( name_to_id_map_list, &list_element, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve first name to id map entry list element.", function ); return( -1 ); } for( element_index = 0; element_index < number_of_elements; element_index++ ) { /* TODO is this necessary? */ if( list_element == NULL ) { break; } if( libcdata_list_element_get_value( list_element, (intptr_t **) &search_name_to_id_map_entry, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve name to id map entry: %d.", function, element_index ); return( -1 ); } if( ( search_name_to_id_map_entry != NULL ) && ( search_name_to_id_map_entry->identifier == identifier ) ) { *name_to_id_map_entry = search_name_to_id_map_entry; return( 1 ); } if( libcdata_list_element_get_next_element( list_element, &list_element, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve name to id map entry: %d next list element.", function, element_index ); return( -1 ); } } return( 0 ); }
/* Retrieves the table definition for the specific name * Returns 1 if successful, 0 if no corresponding table definition was found or -1 on error */ int libesedb_catalog_get_table_definition_by_name( libesedb_catalog_t *catalog, const uint8_t *table_name, size_t table_name_size, libesedb_table_definition_t **table_definition, libcerror_error_t **error ) { libcdata_list_element_t *list_element = NULL; static char *function = "libesedb_catalog_get_table_definition_by_name"; int element_index = 0; int number_of_elements = 0; if( catalog == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid catalog.", function ); return( -1 ); } if( catalog->table_definition_list == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid catalog - missing table definition list.", function ); return( -1 ); } if( table_name == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid table name.", function ); return( -1 ); } if( table_name_size > (size_t) SSIZE_MAX ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid table name size value exceeds maximum.", function ); return( -1 ); } if( table_definition == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid table definition.", function ); return( -1 ); } if( libcdata_list_get_first_element( catalog->table_definition_list, &list_element, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve first element of table definition list.", function ); return( -1 ); } if( libcdata_list_get_number_of_elements( catalog->table_definition_list, &number_of_elements, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve number of elements in table definition list.", function ); return( -1 ); } for( element_index = 0; element_index < number_of_elements; element_index++ ) { if( libcdata_list_element_get_value( list_element, (intptr_t **) table_definition, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve value from element: %d.", function, element_index ); return( -1 ); } if( *table_definition == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: missing table definition: %d.", function, element_index ); return( -1 ); } if( ( *table_definition )->table_catalog_definition == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid table definition: %d - missing table catalog definition.", function, element_index ); return( -1 ); } if( ( *table_definition )->table_catalog_definition->name == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid table catalog definition: %d - missing name.", function, element_index ); return( -1 ); } if( table_name_size == ( *table_definition )->table_catalog_definition->name_size ) { if( memory_compare( ( *table_definition )->table_catalog_definition->name, table_name, table_name_size ) == 0 ) { return( 1 ); } } if( libcdata_list_element_get_next_element( list_element, &list_element, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve next element of element: %d.", function, element_index ); return( -1 ); } } *table_definition = NULL; return( 0 ); }
/* Retrieves the table definition for the specific UTF-16 encoded name * Returns 1 if successful, 0 if no corresponding table definition was found or -1 on error */ int libesedb_catalog_get_table_definition_by_utf16_name( libesedb_catalog_t *catalog, const uint16_t *utf16_string, size_t utf16_string_length, libesedb_table_definition_t **table_definition, libcerror_error_t **error ) { libcdata_list_element_t *list_element = NULL; static char *function = "libesedb_catalog_get_table_definition_by_utf16_name"; int element_index = 0; int number_of_elements = 0; int result = 0; if( catalog == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid catalog.", function ); return( -1 ); } if( catalog->table_definition_list == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid catalog - missing table definition list.", function ); return( -1 ); } if( utf16_string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid UTF-16 string.", function ); return( -1 ); } if( utf16_string_length > (size_t) SSIZE_MAX ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid UTF-16 string length value exceeds maximum.", function ); return( -1 ); } if( table_definition == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid table definition.", function ); return( -1 ); } if( libcdata_list_get_first_element( catalog->table_definition_list, &list_element, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve first element of table definition list.", function ); return( -1 ); } if( libcdata_list_get_number_of_elements( catalog->table_definition_list, &number_of_elements, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve number of elements in table definition list.", function ); return( -1 ); } for( element_index = 0; element_index < number_of_elements; element_index++ ) { if( libcdata_list_element_get_value( list_element, (intptr_t **) table_definition, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve value from element: %d.", function, element_index ); return( -1 ); } if( *table_definition == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: missing table definition: %d.", function, element_index ); return( -1 ); } if( ( *table_definition )->table_catalog_definition == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid table definition: %d - missing table catalog definition.", function, element_index ); return( -1 ); } if( ( *table_definition )->table_catalog_definition->name == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid table catalog definition: %d - missing name.", function, element_index ); return( -1 ); } result = libuna_utf16_string_compare_with_byte_stream( utf16_string, utf16_string_length, ( *table_definition )->table_catalog_definition->name, ( *table_definition )->table_catalog_definition->name_size, LIBUNA_CODEPAGE_WINDOWS_1252, error ); if( result == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: unable to compare UTF-16 string with table catalog definition: %d name.", function, element_index ); return( -1 ); } else if( result != 0 ) { return( 1 ); } if( libcdata_list_element_get_next_element( list_element, &list_element, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve next element of element: %d.", function, element_index ); return( -1 ); } } *table_definition = NULL; return( 0 ); }
/* Create the directory tree from the directory entry list * Returns 1 if succesful, 0 if no directory entries or -1 on error */ int libolecf_directory_tree_create( libcdata_tree_node_t **directory_tree_root_node, uint32_t *short_sector_stream_start_sector_identifier, libolecf_directory_entry_t **document_summary_information_directory_entry, libolecf_directory_entry_t **summary_information_directory_entry, libcdata_list_t *directory_entry_list, uint8_t byte_order, libcerror_error_t **error ) { libcdata_list_element_t *list_element = NULL; libolecf_directory_entry_t *directory_entry = NULL; static char *function = "libolecf_directory_tree_create"; int element_index = 0; int number_of_elements = 0; if( directory_tree_root_node == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid directory tree root node.", function ); return( -1 ); } if( *directory_tree_root_node != NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, "%s: directory tree root node already set.", function ); return( -1 ); } if( short_sector_stream_start_sector_identifier == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid short sector stream start sector identifier.", function ); return( -1 ); } if( libcdata_list_get_first_element( directory_entry_list, &list_element, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve first element of directory entry list.", function ); goto on_error; } if( libcdata_list_get_number_of_elements( directory_entry_list, &number_of_elements, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve number of elements in directory entry list.", function ); goto on_error; } if( number_of_elements == 0 ) { return( 0 ); } for( element_index = 0; element_index < number_of_elements; element_index++ ) { if( libcdata_list_element_get_value( list_element, (intptr_t **) &directory_entry, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve value from element: %d.", function, element_index ); goto on_error; } if( directory_entry == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: missing directory entry: %d.", function, element_index ); goto on_error; } if( directory_entry->type == LIBOLECF_ITEM_TYPE_ROOT_STORAGE ) { break; } if( libcdata_list_element_get_next_element( list_element, &list_element, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve next element of element: %d.", function, element_index ); goto on_error; } } if( list_element == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: unable to find root storage directory entry.", function ); goto on_error; } #if defined( HAVE_VERBOSE_OUTPUT ) || defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( element_index != 0 ) { libcnotify_printf( "%s: root storage is not first directory entry.\n", function ); } if( directory_entry->previous_directory_identifier != LIBOLECF_SECTOR_IDENTIFIER_UNUSED ) { libcnotify_printf( "%s: previous directory identifier in root storage is not unused.\n", function ); } if( directory_entry->next_directory_identifier != LIBOLECF_SECTOR_IDENTIFIER_UNUSED ) { libcnotify_printf( "%s: next directory identifier in root storage is not unused.\n", function ); } } #endif if( directory_entry->sub_directory_identifier == LIBOLECF_SECTOR_IDENTIFIER_UNUSED ) { return( 0 ); } if( libcdata_tree_node_initialize( directory_tree_root_node, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create directory root node.", function ); goto on_error; } if( libcdata_tree_node_set_value( *directory_tree_root_node, (intptr_t *) directory_entry, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set directory root node value.", function ); goto on_error; } *short_sector_stream_start_sector_identifier = directory_entry->sector_identifier; if( libolecf_directory_tree_create_process_entry( *directory_tree_root_node, directory_entry, document_summary_information_directory_entry, summary_information_directory_entry, directory_entry_list, directory_entry, byte_order, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to process sub directory entry.", function ); goto on_error; } return( 1 ); on_error: if( *directory_tree_root_node != NULL ) { /* The directory entry is managed by the list */ libcdata_tree_node_free( directory_tree_root_node, NULL, NULL ); } return( -1 ); }