/* Retrieves a specific element from the list * Returns 1 if successful or -1 on error */ int libcdata_list_get_element_by_index( libcdata_list_t *list, int element_index, libcdata_list_element_t **element, libcerror_error_t **error ) { libcdata_internal_list_t *internal_list = NULL; libcdata_list_element_t *list_element = NULL; static char *function = "libcdata_list_get_element_by_index"; int element_iterator = 0; if( list == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid list.", function ); return( -1 ); } internal_list = (libcdata_internal_list_t *) list; if( ( element_index < 0 ) || ( element_index >= internal_list->number_of_elements ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid element index value out of bounds.", function ); return( -1 ); } if( element == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid list element.", function ); return( -1 ); } if( element_index < ( internal_list->number_of_elements / 2 ) ) { list_element = internal_list->first_element; for( element_iterator = 0; element_iterator < element_index; element_iterator++ ) { if( list_element == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: corruption detected in element: %d.", function, element_iterator ); 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 from list element: %d.", function, element_index ); return( -1 ); } } } else { list_element = internal_list->last_element; for( element_iterator = ( internal_list->number_of_elements - 1 ); element_iterator > element_index; element_iterator-- ) { if( list_element == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: corruption detected in element: %d.", function, element_iterator ); return( -1 ); } if( libcdata_list_element_get_previous_element( list_element, &list_element, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve previous element from list element: %d.", function, element_index ); return( -1 ); } } } if( list_element == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: corruption detected - missing list element.", function ); return( -1 ); } *element = list_element; return( 1 ); }
/* Empties a list and frees the elements * Uses the value_free_function to free the element value * Returns 1 if successful or -1 on error */ int libcdata_list_empty( libcdata_list_t *list, int (*value_free_function)( intptr_t **value, libcerror_error_t **error ), libcerror_error_t **error ) { libcdata_internal_list_t *internal_list = NULL; libcdata_list_element_t *list_element = NULL; libcdata_list_element_t *next_element = NULL; static char *function = "libcdata_list_empty"; int element_index = 0; int number_of_elements = 0; int result = 1; if( list == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid list.", function ); return( -1 ); } internal_list = (libcdata_internal_list_t *) list; if( internal_list->number_of_elements > 0 ) { number_of_elements = internal_list->number_of_elements; list_element = internal_list->first_element; for( element_index = 0; element_index < number_of_elements; element_index++ ) { if( libcdata_list_element_get_next_element( list_element, &next_element, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve next element from list element: %d.", function, element_index ); return( -1 ); } internal_list->first_element = next_element; if( internal_list->last_element == list_element ) { internal_list->last_element = next_element; } internal_list->number_of_elements -= 1; if( next_element != NULL ) { if( libcdata_list_element_set_previous_element( next_element, NULL, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set previous element of list element: %d.", function, element_index + 1 ); return( -1 ); } } if( libcdata_list_element_set_next_element( list_element, NULL, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set next element of list element: %d.", function, element_index ); return( -1 ); } if( libcdata_list_element_free( &list_element, value_free_function, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free element: %d.", function, element_index ); return( -1 ); } list_element = next_element; } } return( result ); }
/* Clones the list and its elements * * The values are cloned using the value_clone_function * On error the values are freed using the value_free_function * * Returns 1 if successful or -1 on error */ int libcdata_list_clone( libcdata_list_t **destination_list, libcdata_list_t *source_list, int (*value_free_function)( intptr_t **value, libcerror_error_t **error ), int (*value_clone_function)( intptr_t **destination, intptr_t *source, libcerror_error_t **error ), libcerror_error_t **error ) { libcdata_internal_list_t *internal_source_list = NULL; libcdata_list_element_t *source_list_element = NULL; intptr_t *destination_value = NULL; intptr_t *source_value = NULL; static char *function = "libcdata_list_clone"; int element_index = 0; if( destination_list == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid destination list.", function ); return( -1 ); } if( *destination_list != NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, "%s: invalid destination list already set.", function ); return( -1 ); } if( value_free_function == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid value free function.", function ); return( -1 ); } if( value_clone_function == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid value clone function.", function ); return( -1 ); } if( source_list == NULL ) { *destination_list = NULL; return( 1 ); } internal_source_list = (libcdata_internal_list_t *) source_list; if( libcdata_list_initialize( destination_list, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create destination list.", function ); goto on_error; } if( *destination_list == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: missing destination list.", function ); goto on_error; } source_list_element = internal_source_list->first_element; for( element_index = 0; element_index < internal_source_list->number_of_elements; element_index++ ) { if( libcdata_list_element_get_value( source_list_element, &source_value, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve value from source list element: %d.", function, element_index ); goto on_error; } if( value_clone_function( &destination_value, source_value, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to clone value of source list element: %d.", function, element_index ); goto on_error; } if( libcdata_list_append_value( *destination_list, destination_value, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, "%s: unable to append value of list element: %d.", function, element_index ); goto on_error; } destination_value = NULL; if( libcdata_list_element_get_next_element( source_list_element, &source_list_element, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve next element from source list element: %d.", function, element_index ); goto on_error; } } return( 1 ); on_error: if( destination_value != NULL ) { value_free_function( &destination_value, NULL ); } if( *destination_list != NULL ) { libcdata_list_free( destination_list, value_free_function, error ); } return( -1 ); }
/* Inserts a list element into the list * * Uses the value_compare_function to determine the order of the entries * The value_compare_function should return LIBCDATA_COMPARE_LESS, * LIBCDATA_COMPARE_EQUAL, LIBCDATA_COMPARE_GREATER if successful or -1 on error * * Duplicate entries are allowed by default and inserted after the last duplicate value. * Only allowing unique entries can be enforced by setting the flag LIBCDATA_INSERT_FLAG_UNIQUE_ENTRIES * * Returns 1 if successful, 0 if the list element already exists or -1 on error */ int libcdata_list_insert_element( libcdata_list_t *list, libcdata_list_element_t *element, int (*value_compare_function)( intptr_t *first_value, intptr_t *second_value, libcerror_error_t **error ), uint8_t insert_flags, libcerror_error_t **error ) { libcdata_internal_list_t *internal_list = NULL; libcdata_list_element_t *list_element = NULL; libcdata_list_element_t *next_element = NULL; libcdata_list_element_t *previous_element = NULL; intptr_t *element_value = NULL; intptr_t *list_element_value = NULL; static char *function = "libcdata_list_insert_element"; int element_index = 0; int result = -1; if( list == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid list.", function ); return( -1 ); } internal_list = (libcdata_internal_list_t *) list; if( element == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid list element.", function ); return( -1 ); } if( value_compare_function == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid value compare function.", function ); return( -1 ); } if( ( insert_flags & ~( LIBCDATA_INSERT_FLAG_UNIQUE_ENTRIES ) ) != 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, "%s: unsupported insert flags: 0x%02" PRIx8 ".", function, insert_flags ); return( -1 ); } if( libcdata_list_element_get_elements( element, &previous_element, &next_element, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve previous and next element from list element.", function ); return( -1 ); } if( ( previous_element != NULL ) || ( next_element != NULL ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, "%s: list element already part of a list.", function ); return( -1 ); } if( libcdata_list_element_get_value( element, &element_value, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve value from list element.", function ); return( -1 ); } if( internal_list->number_of_elements == 0 ) { if( internal_list->first_element != NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: corruption detected - first element already set.", function ); return( -1 ); } if( internal_list->last_element != NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: corruption detected - last element already set.", function ); return( -1 ); } internal_list->first_element = element; internal_list->last_element = element; } else { if( internal_list->first_element == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: corruption detected - missing first.", function ); return( -1 ); } if( internal_list->last_element == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: corruption detected - missing last.", function ); return( -1 ); } list_element = internal_list->first_element; for( element_index = 0; element_index < internal_list->number_of_elements; element_index++ ) { if( libcdata_list_element_get_value( list_element, &list_element_value, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve value from list element: %d.", function, element_index ); return( -1 ); } result = value_compare_function( element_value, list_element_value, error ); if( result == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to compare list element: %d.", function, element_index ); return( -1 ); } else if( result == LIBCDATA_COMPARE_EQUAL ) { if( ( insert_flags & LIBCDATA_INSERT_FLAG_UNIQUE_ENTRIES ) != 0 ) { return( 0 ); } } else if( result == LIBCDATA_COMPARE_LESS ) { break; } else if( result != LIBCDATA_COMPARE_GREATER ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, "%s: unsupported value compare function return value: %d.", function, result ); 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 from list element: %d.", function, element_index ); return( -1 ); } } if( result == LIBCDATA_COMPARE_LESS ) { if( libcdata_list_element_get_previous_element( list_element, &previous_element, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve previous element from list element: %d.", function, element_index ); return( -1 ); } if( libcdata_list_element_set_elements( element, previous_element, list_element, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set previous and next element of list element.", function ); return( -1 ); } if( list_element == internal_list->first_element ) { internal_list->first_element = element; } else { if( libcdata_list_element_set_next_element( previous_element, element, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set next element of list element: %d.", function, element_index - 1 ); return( -1 ); } } if( libcdata_list_element_set_previous_element( list_element, element, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set previous element of list element: %d.", function, element_index ); return( -1 ); } } else { if( libcdata_list_set_last_element( list, element, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set last element.", function ); return( -1 ); } } } internal_list->number_of_elements += 1; return( 1 ); }
/* 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 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 ); }
/* 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 ); }
/* 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 ); }