/* Closes the info handle * Returns the 0 if succesful or -1 on error */ int info_handle_close( info_handle_t *info_handle, libcerror_error_t **error ) { static char *function = "info_handle_close"; int result = 0; if( info_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid info handle.", function ); return( -1 ); } if( info_handle->root_item != NULL ) { if( libolecf_item_free( &( info_handle->root_item ), error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free root item.", function ); result = -1; } } if( libolecf_file_close( info_handle->input_file, error ) != 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_CLOSE_FAILED, "%s: unable to close input file.", function ); result = -1; } return( result ); }
/* Retrieves a file entry for a specific path * Returns 1 if successful, 0 if no such file entry or -1 on error */ int mount_handle_get_file_entry_by_path( mount_handle_t *mount_handle, const system_character_t *path, mount_file_entry_t **file_entry, libcerror_error_t **error ) { libolecf_item_t *olecf_item = NULL; const system_character_t *filename = NULL; static char *function = "mount_handle_get_file_entry_by_path"; size_t filename_length = 0; size_t path_index = 0; size_t path_length = 0; int result = 0; if( mount_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid mount handle.", function ); return( -1 ); } if( path == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid path.", function ); return( -1 ); } path_length = system_string_length( path ); if( path_length == 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid path length value out of bounds.", function ); goto on_error; } if( ( path_length >= 2 ) && ( path[ path_length - 1 ] == LIBCPATH_SEPARATOR ) ) { path_length--; } path_index = path_length; while( path_index > 0 ) { if( path[ path_index ] == LIBCPATH_SEPARATOR ) { break; } path_index--; } /* Ignore the name of the root item */ if( path_length == 0 ) { filename = _SYSTEM_STRING( "" ); filename_length = 0; } else { filename = &( path[ path_index + 1 ] ); filename_length = path_length - ( path_index + 1 ); } result = mount_file_system_get_item_by_path( mount_handle->file_system, path, path_length, &olecf_item, error ); if( result == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve item.", function ); goto on_error; } else if( result != 0 ) { if( mount_file_entry_initialize( file_entry, mount_handle->file_system, filename, filename_length, olecf_item, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to initialize file entry.", function ); goto on_error; } } return( result ); on_error: if( olecf_item != NULL ) { libolecf_item_free( &olecf_item, NULL ); } return( -1 ); }
/* Exports the file * Returns 1 if successful or -1 on error */ int export_handle_export_file( export_handle_t *export_handle, log_handle_t *log_handle, libcerror_error_t **error ) { libolecf_item_t *root_item = NULL; static char *function = "export_handle_export_file"; int result = 0; if( export_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid export handle.", function ); return( -1 ); } fprintf( export_handle->notify_stream, "Exporting items.\n" ); #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) result = libcpath_path_make_directory_wide( export_handle->items_export_path, error ); #else result = libcpath_path_make_directory( export_handle->items_export_path, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_WRITE_FAILED, "%s: unable to create directory: %" PRIs_SYSTEM "", function, export_handle->items_export_path ); goto on_error; } log_handle_printf( log_handle, "Created directory: %" PRIs_SYSTEM ".\n", export_handle->items_export_path ); result = libolecf_file_get_root_item( export_handle->input_file, &root_item, error ); if( result == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve root item.", function ); goto on_error; } else if( result == 0 ) { return( 1 ); } if( export_handle_export_sub_items( export_handle, root_item, export_handle->items_export_path, export_handle->items_export_path_size - 1, log_handle, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_OUTPUT, LIBCERROR_OUTPUT_ERROR_GENERIC, "%s: unable to export root item.", function ); goto on_error; } if( libolecf_item_free( &root_item, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free root item.", function ); goto on_error; } return( 1 ); on_error: if( root_item != NULL ) { libolecf_item_free( &root_item, NULL ); } return( -1 ); }
/* Exports the sub items * Returns 1 if successful or -1 on error */ int export_handle_export_sub_items( export_handle_t *export_handle, libolecf_item_t *item, const system_character_t *export_path, size_t export_path_length, log_handle_t *log_handle, libcerror_error_t **error ) { libolecf_item_t *sub_item = NULL; static char *function = "export_handle_export_sub_items"; int number_of_sub_items = 0; int sub_item_iterator = 0; if( export_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid export handle.", function ); return( -1 ); } if( item == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid item.", function ); return( -1 ); } if( export_path == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid export path.", function ); return( -1 ); } if( libolecf_item_get_number_of_sub_items( item, &number_of_sub_items, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve number of sub items.", function ); return( -1 ); } for( sub_item_iterator = 0; sub_item_iterator < number_of_sub_items; sub_item_iterator++ ) { if( libolecf_item_get_sub_item( item, sub_item_iterator, &sub_item, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve sub item: %d.", function, sub_item_iterator + 1 ); return( -1 ); } if( export_handle_export_item( export_handle, sub_item, sub_item_iterator, number_of_sub_items, export_path, export_path_length, log_handle, error ) != 1 ) { fprintf( stdout, "Unable to export item %d out of %d.\n", sub_item_iterator + 1, number_of_sub_items ); if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: unable to export sub item: %d.\n", function, sub_item_iterator + 1 ); } if( ( error != NULL ) && ( *error != NULL ) ) { libcnotify_print_error_backtrace( *error ); } libcerror_error_free( error ); log_handle_printf( log_handle, "Unable to export sub item: %d.\n", sub_item_iterator + 1 ); } if( libolecf_item_free( &sub_item, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free sub item: %d.", function, sub_item_iterator + 1 ); return( -1 ); } } return( 1 ); }
/* Frees an item object */ void pyolecf_item_free( pyolecf_item_t *pyolecf_item ) { libcerror_error_t *error = NULL; static char *function = "pyolecf_item_free"; if( pyolecf_item == NULL ) { PyErr_Format( PyExc_TypeError, "%s: invalid item.", function ); return; } if( pyolecf_item->ob_type == NULL ) { PyErr_Format( PyExc_TypeError, "%s: invalid item - missing ob_type.", function ); return; } if( pyolecf_item->ob_type->tp_free == NULL ) { PyErr_Format( PyExc_TypeError, "%s: invalid item - invalid ob_type - missing tp_free.", function ); return; } if( pyolecf_item->item == NULL ) { PyErr_Format( PyExc_TypeError, "%s: invalid item - missing libolecf item.", function ); return; } if( libolecf_item_free( &( pyolecf_item->item ), &error ) != 1 ) { pyolecf_error_raise( error, PyExc_IOError, "%s: unable to free libolecf item.", function ); libcerror_error_free( &error ); } if( pyolecf_item->file_object != NULL ) { Py_DecRef( (PyObject *) pyolecf_item->file_object ); } pyolecf_item->ob_type->tp_free( (PyObject*) pyolecf_item ); }
/* Prints the document summary information to a stream * Returns 1 if successful or -1 on error */ int info_handle_document_summary_information_fprint( info_handle_t *info_handle, libcerror_error_t **error ) { uint8_t guid_data[ 16 ]; libcstring_system_character_t guid_string[ 48 ]; libfguid_identifier_t *guid = NULL; libolecf_item_t *property_set_stream = NULL; libolecf_property_set_t *property_set = NULL; libolecf_property_section_t *property_section = NULL; libolecf_property_value_t *property_value = NULL; const char *property_value_identifier_string = NULL; static char *function = "info_handle_document_summary_information_fprint"; uint32_t property_value_identifier = 0; uint32_t property_value_type = 0; int number_of_properties = 0; int number_of_sections = 0; int property_index = 0; int result = 0; int section_index = 0; if( info_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid info handle.", function ); return( -1 ); } if( info_handle->root_item == NULL ) { if( libolecf_file_get_root_item( info_handle->input_file, &( info_handle->root_item ), error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve root item.", function ); return( -1 ); } } /* Using \005 because \x05 also absorbes the D */ result = libolecf_item_get_sub_item_by_utf8_name( info_handle->root_item, (uint8_t *) "\005DocumentSummaryInformation", 27, &property_set_stream, error ); if( result == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve sub item.", function ); goto on_error; } else if( result != 0 ) { fprintf( info_handle->notify_stream, "Document summary information:\n" ); if( libolecf_property_set_stream_get_set( property_set_stream, &property_set, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve property set stream.", function ); goto on_error; } if( libfguid_identifier_initialize( &guid, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create GUID.", function ); goto on_error; } if( libolecf_property_set_get_class_identifier( property_set, guid_data, 16, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve property set class identifier.", function ); goto on_error; } if( libfguid_identifier_copy_from_byte_stream( guid, guid_data, 16, LIBFGUID_ENDIAN_LITTLE, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy byte stream to GUID.", function ); goto on_error; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libfguid_identifier_copy_to_utf16_string( guid, (uint16_t *) guid_string, 48, LIBFGUID_STRING_FORMAT_FLAG_USE_LOWER_CASE, error ); #else result = libfguid_identifier_copy_to_utf8_string( guid, (uint8_t *) guid_string, 48, LIBFGUID_STRING_FORMAT_FLAG_USE_LOWER_CASE, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy GUID to string.", function ); goto on_error; } fprintf( info_handle->notify_stream, "\tClass identifier\t: %" PRIs_LIBCSTRING_SYSTEM "\n", guid_string ); if( libolecf_property_set_get_number_of_sections( property_set, &number_of_sections, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve number of sections.", function ); goto on_error; } fprintf( info_handle->notify_stream, "\tNumber of sections\t: %d\n", number_of_sections ); fprintf( info_handle->notify_stream, "\n" ); for( section_index = 0; section_index < number_of_sections; section_index++ ) { fprintf( info_handle->notify_stream, "\tSection: %d\n", section_index + 1 ); if( libolecf_property_set_get_section_by_index( property_set, section_index, &property_section, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve property set section: %d.", function, section_index ); goto on_error; } if( libolecf_property_section_get_class_identifier( property_section, guid_data, 16, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve property section class identifier.", function ); goto on_error; } if( libfguid_identifier_copy_from_byte_stream( guid, guid_data, 16, LIBFGUID_ENDIAN_LITTLE, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy byte stream to GUID.", function ); goto on_error; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libfguid_identifier_copy_to_utf16_string( guid, (uint16_t *) guid_string, 48, LIBFGUID_STRING_FORMAT_FLAG_USE_LOWER_CASE, error ); #else result = libfguid_identifier_copy_to_utf8_string( guid, (uint8_t *) guid_string, 48, LIBFGUID_STRING_FORMAT_FLAG_USE_LOWER_CASE, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy GUID to string.", function ); goto on_error; } fprintf( info_handle->notify_stream, "\tClass identifier\t: %" PRIs_LIBCSTRING_SYSTEM "\n", guid_string ); if( libolecf_property_section_get_number_of_properties( property_section, &number_of_properties, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve number of properties.", function ); goto on_error; } fprintf( info_handle->notify_stream, "\tNumber of properties\t: %d\n", number_of_properties ); fprintf( info_handle->notify_stream, "\n" ); for( property_index = 0; property_index < number_of_properties; property_index++ ) { fprintf( info_handle->notify_stream, "\tProperty: %d\n", property_index + 1 ); if( libolecf_property_section_get_property_by_index( property_section, property_index, &property_value, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve property: %d value.", function, property_index ); goto on_error; } if( libolecf_property_value_get_identifier( property_value, &property_value_identifier, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve property: %d value identifier.", function, property_index ); goto on_error; } if( libolecf_property_value_get_value_type( property_value, &property_value_type, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve property: %d value type.", function, property_index ); goto on_error; } property_value_identifier_string = NULL; if( memory_compare( guid_data, info_handle_class_identifier_document_summary_information, 16 ) == 0 ) { switch( property_value_type ) { /* TODO */ case LIBOLECF_VALUE_TYPE_INTEGER_16BIT_SIGNED: switch( property_value_identifier ) { case LIBOLECF_DOCUMENT_SUMMARY_INFORMATION_PID_CODEPAGE: property_value_identifier_string = "PIDDSI_CODEPAGE"; break; default: break; } break; case LIBOLECF_VALUE_TYPE_INTEGER_32BIT_SIGNED: switch( property_value_identifier ) { case LIBOLECF_DOCUMENT_SUMMARY_INFORMATION_PID_BYTE_COUNT: property_value_identifier_string = "PIDDSI_BYTECOUNT"; break; case LIBOLECF_DOCUMENT_SUMMARY_INFORMATION_PID_LINE_COUNT: property_value_identifier_string = "PIDDSI_LINECOUNT"; break; case LIBOLECF_DOCUMENT_SUMMARY_INFORMATION_PID_PARAGRAPH_COUNT: property_value_identifier_string = "PIDDSI_PARCOUNT"; break; case LIBOLECF_DOCUMENT_SUMMARY_INFORMATION_PID_SLIDE_COUNT: property_value_identifier_string = "PIDDSI_SLIDECOUNT"; break; case LIBOLECF_DOCUMENT_SUMMARY_INFORMATION_PID_NOTE_COUNT: property_value_identifier_string = "PIDDSI_NOTECOUNT"; break; case LIBOLECF_DOCUMENT_SUMMARY_INFORMATION_PID_HIDDEN_SLIDE_COUNT: property_value_identifier_string = "PIDDSI_HIDDENCOUNT"; break; case LIBOLECF_DOCUMENT_SUMMARY_INFORMATION_PID_MMCLIP_COUNT: property_value_identifier_string = "PIDDSI_MMCLIPCOUNT"; break; default: break; } break; case LIBOLECF_VALUE_TYPE_BOOLEAN: switch( property_value_identifier ) { case LIBOLECF_DOCUMENT_SUMMARY_INFORMATION_PID_SCALE: property_value_identifier_string = "PIDDSI_SCALE"; break; case LIBOLECF_DOCUMENT_SUMMARY_INFORMATION_PID_LINKS_DIRTY: property_value_identifier_string = "PIDDSI_LINKSDIRTY"; break; default: break; } break; case LIBOLECF_VALUE_TYPE_STRING_ASCII: case LIBOLECF_VALUE_TYPE_STRING_UNICODE: switch( property_value_identifier ) { case LIBOLECF_DOCUMENT_SUMMARY_INFORMATION_PID_CATEGORY : property_value_identifier_string = "PIDDSI_CATEGORY"; break; case LIBOLECF_DOCUMENT_SUMMARY_INFORMATION_PID_PRESENTATION_TARGET: property_value_identifier_string = "PIDDSI_PRESFORMAT"; break; case LIBOLECF_DOCUMENT_SUMMARY_INFORMATION_PID_MANAGER: property_value_identifier_string = "PIDDSI_MANAGER"; break; case LIBOLECF_DOCUMENT_SUMMARY_INFORMATION_PID_COMPANY: property_value_identifier_string = "PIDDSI_COMPANY"; break; default: break; } break; case LIBOLECF_VALUE_TYPE_MULTI_VALUE_VARIANT: switch( property_value_identifier ) { case LIBOLECF_DOCUMENT_SUMMARY_INFORMATION_PID_HEADING_PAIRS: property_value_identifier_string = "PIDDSI_HEADINGPAIR"; break; default: break; } break; case LIBOLECF_VALUE_TYPE_MULTI_VALUE_STRING_ASCII: case LIBOLECF_VALUE_TYPE_MULTI_VALUE_STRING_UNICODE: switch( property_value_identifier ) { case LIBOLECF_DOCUMENT_SUMMARY_INFORMATION_PID_DOCUMENT_PARTS: property_value_identifier_string = "PIDDSI_DOCPARTS"; break; default: break; } break; default: break; } } fprintf( info_handle->notify_stream, "\tValue identifier\t: " ); if( property_value_identifier_string != NULL ) { fprintf( info_handle->notify_stream, "%s (", property_value_identifier_string ); } fprintf( info_handle->notify_stream, "0x%08" PRIx32 "", property_value_identifier ); if( property_value_identifier_string != NULL ) { fprintf( info_handle->notify_stream, ")" ); } fprintf( info_handle->notify_stream, "\n" ); fprintf( info_handle->notify_stream, "\tValue type\t\t: %s (0x%08" PRIx32 ")\n", libfole_value_type_get_identifier( property_value_type ), property_value_type ); /* TODO print the properties */ if( libolecf_property_value_free( &property_value, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free property value.", function ); goto on_error; } fprintf( info_handle->notify_stream, "\n" ); } if( libolecf_property_section_free( &property_section, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free property section.", function ); goto on_error; } } if( libfguid_identifier_free( &guid, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free GUID.", function ); goto on_error; } if( libolecf_property_set_free( &property_set, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free property set.", function ); goto on_error; } if( libolecf_item_free( &property_set_stream, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free property set stream.", function ); goto on_error; } fprintf( info_handle->notify_stream, "\n" ); } return( 1 ); on_error: if( property_value != NULL ) { libolecf_property_value_free( &property_value, NULL ); } if( property_section != NULL ) { libolecf_property_section_free( &property_section, NULL ); } if( guid != NULL ) { libfguid_identifier_free( &guid, NULL ); } if( property_set != NULL ) { libolecf_property_set_free( &property_set, NULL ); } if( property_set_stream != NULL ) { libolecf_item_free( &property_set_stream, NULL ); } return( -1 ); }
/* Prints an item to a stream * Returns 1 if successful or -1 on error */ int info_handle_item_fprint( info_handle_t *info_handle, libolecf_item_t *item, int indentation_level, libcerror_error_t **error ) { libcstring_system_character_t *name = NULL; libolecf_item_t *sub_item = NULL; static char *function = "info_handle_item_fprint"; size_t name_index = 0; size_t name_size = 0; uint32_t size = 0; int number_of_sub_items = 0; int indentation_iterator = 0; int result = 0; int sub_item_index = 0; if( info_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid info handle.", function ); return( -1 ); } if( item == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid item.", function ); return( -1 ); } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libolecf_item_get_utf16_name_size( item, &name_size, error ); #else result = libolecf_item_get_utf8_name_size( item, &name_size, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve item name size.", function ); goto on_error; } name = libcstring_system_string_allocate( name_size ); if( name == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create name.", function ); goto on_error; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libolecf_item_get_utf16_name( item, (uint16_t *) name, name_size, error ); #else result = libolecf_item_get_utf8_name( item, (uint8_t *) name, name_size, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve item name.", function ); goto on_error; } if( libolecf_item_get_size( item, &size, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve item size.", function ); goto on_error; } for( indentation_iterator = 0; indentation_iterator < indentation_level; indentation_iterator++ ) { fprintf( info_handle->notify_stream, " " ); } for( name_index = 0; name_index < ( name_size - 1 ); name_index++ ) { /* Print control characters as hexadecimal values */ if( ( name[ name_index ] < 0x20 ) || ( name[ name_index ] == 0x7f ) ) { fprintf( info_handle->notify_stream, "\\x%02" PRIx8 "", (uint8_t) name[ name_index ] ); } else { fprintf( info_handle->notify_stream, "%" PRIc_LIBCSTRING_SYSTEM "", name[ name_index ] ); } } fprintf( info_handle->notify_stream, " (%" PRIu32 " bytes)\n", size ); memory_free( name ); name = NULL; if( libolecf_item_get_number_of_sub_items( item, &number_of_sub_items, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve number of sub items.", function ); goto on_error; } for( sub_item_index = 0; sub_item_index < number_of_sub_items; sub_item_index++ ) { if( libolecf_item_get_sub_item( item, sub_item_index, &sub_item, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve sub item: %d.", function, sub_item_index ); goto on_error; } if( info_handle_item_fprint( info_handle, sub_item, indentation_level + 1, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, "%s: unable to print sub item: %d.", function, sub_item_index ); libolecf_item_free( &sub_item, NULL ); goto on_error; } if( libolecf_item_free( &sub_item, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free sub item: %d.", function, sub_item_index ); goto on_error; } } return( 1 ); on_error: if( name != NULL ) { memory_free( name ); } return( -1 ); }
/* Prints the summary information to a stream * Returns 1 if successful or -1 on error */ int info_handle_summary_information_fprint( info_handle_t *info_handle, libcerror_error_t **error ) { uint8_t guid_data[ 16 ]; libcstring_system_character_t guid_string[ 48 ]; libfguid_identifier_t *guid = NULL; libolecf_item_t *property_set_stream = NULL; libolecf_property_set_t *property_set = NULL; libolecf_property_section_t *property_section = NULL; libolecf_property_value_t *property_value = NULL; const char *property_value_identifier_string = NULL; static char *function = "info_handle_summary_information_fprint"; uint32_t property_value_identifier = 0; uint32_t property_value_type = 0; int number_of_properties = 0; int number_of_sections = 0; int property_index = 0; int result = 0; int section_index = 0; if( info_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid info handle.", function ); return( -1 ); } if( info_handle->root_item == NULL ) { if( libolecf_file_get_root_item( info_handle->input_file, &( info_handle->root_item ), error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve root item.", function ); return( -1 ); } } result = libolecf_item_get_sub_item_by_utf8_name( info_handle->root_item, (uint8_t *) "\005SummaryInformation", 19, &property_set_stream, error ); if( result == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve sub item.", function ); goto on_error; } else if( result != 0 ) { fprintf( info_handle->notify_stream, "Summary information:\n" ); if( libolecf_property_set_stream_get_set( property_set_stream, &property_set, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve property set stream.", function ); goto on_error; } if( libfguid_identifier_initialize( &guid, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create GUID.", function ); goto on_error; } if( libolecf_property_set_get_class_identifier( property_set, guid_data, 16, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve property set class identifier.", function ); goto on_error; } if( libfguid_identifier_copy_from_byte_stream( guid, guid_data, 16, LIBFGUID_ENDIAN_LITTLE, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy byte stream to GUID.", function ); goto on_error; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libfguid_identifier_copy_to_utf16_string( guid, (uint16_t *) guid_string, 48, LIBFGUID_STRING_FORMAT_FLAG_USE_LOWER_CASE, error ); #else result = libfguid_identifier_copy_to_utf8_string( guid, (uint8_t *) guid_string, 48, LIBFGUID_STRING_FORMAT_FLAG_USE_LOWER_CASE, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy GUID to string.", function ); goto on_error; } fprintf( info_handle->notify_stream, "\tClass identifier\t: %" PRIs_LIBCSTRING_SYSTEM "\n", guid_string ); if( libolecf_property_set_get_number_of_sections( property_set, &number_of_sections, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve number of sections.", function ); goto on_error; } fprintf( info_handle->notify_stream, "\tNumber of sections\t: %d\n", number_of_sections ); fprintf( info_handle->notify_stream, "\n" ); for( section_index = 0; section_index < number_of_sections; section_index++ ) { fprintf( info_handle->notify_stream, "\tSection: %d\n", section_index + 1 ); if( libolecf_property_set_get_section_by_index( property_set, section_index, &property_section, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve property set section: %d.", function, section_index ); goto on_error; } if( libolecf_property_section_get_class_identifier( property_section, guid_data, 16, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve property section class identifier.", function ); goto on_error; } if( libfguid_identifier_copy_from_byte_stream( guid, guid_data, 16, LIBFGUID_ENDIAN_LITTLE, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy byte stream to GUID.", function ); goto on_error; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libfguid_identifier_copy_to_utf16_string( guid, (uint16_t *) guid_string, 48, LIBFGUID_STRING_FORMAT_FLAG_USE_LOWER_CASE, error ); #else result = libfguid_identifier_copy_to_utf8_string( guid, (uint8_t *) guid_string, 48, LIBFGUID_STRING_FORMAT_FLAG_USE_LOWER_CASE, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy GUID to string.", function ); goto on_error; } fprintf( info_handle->notify_stream, "\tClass identifier\t: %" PRIs_LIBCSTRING_SYSTEM "\n", guid_string ); if( libolecf_property_section_get_number_of_properties( property_section, &number_of_properties, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve number of properties.", function ); goto on_error; } fprintf( info_handle->notify_stream, "\tNumber of properties\t: %d\n", number_of_properties ); fprintf( info_handle->notify_stream, "\n" ); for( property_index = 0; property_index < number_of_properties; property_index++ ) { fprintf( info_handle->notify_stream, "\tProperty: %d\n", property_index + 1 ); if( libolecf_property_section_get_property_by_index( property_section, property_index, &property_value, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve property: %d value.", function, property_index ); goto on_error; } if( libolecf_property_value_get_identifier( property_value, &property_value_identifier, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve property: %d value identifier.", function, property_index ); goto on_error; } if( libolecf_property_value_get_value_type( property_value, &property_value_type, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve property: %d value type.", function, property_index ); goto on_error; } property_value_identifier_string = NULL; if( memory_compare( guid_data, info_handle_class_identifier_summary_information, 16 ) == 0 ) { switch( property_value_type ) { case LIBOLECF_VALUE_TYPE_INTEGER_16BIT_SIGNED: switch( property_value_identifier ) { case LIBOLECF_SUMMARY_INFORMATION_PID_CODEPAGE: property_value_identifier_string = "PIDSI_CODEPAGE"; break; default: break; } break; case LIBOLECF_VALUE_TYPE_INTEGER_32BIT_SIGNED: switch( property_value_identifier ) { case LIBOLECF_SUMMARY_INFORMATION_PID_NUMBER_OF_PAGES: property_value_identifier_string = "PIDSI_PAGECOUNT"; break; case LIBOLECF_SUMMARY_INFORMATION_PID_NUMBER_OF_WORDS: property_value_identifier_string = "PIDSI_WORDCOUNT"; break; case LIBOLECF_SUMMARY_INFORMATION_PID_NUMBER_OF_CHARACTERS: property_value_identifier_string = "PIDSI_CHARCOUNT"; break; case LIBOLECF_SUMMARY_INFORMATION_PID_SECURITY: property_value_identifier_string = "PIDSI_SECURITY"; break; default: break; } break; case LIBOLECF_VALUE_TYPE_STRING_ASCII: case LIBOLECF_VALUE_TYPE_STRING_UNICODE: switch( property_value_identifier ) { case LIBOLECF_SUMMARY_INFORMATION_PID_TITLE: property_value_identifier_string = "PIDSI_TITLE"; break; case LIBOLECF_SUMMARY_INFORMATION_PID_SUBJECT: property_value_identifier_string = "PIDSI_SUBJECT"; break; case LIBOLECF_SUMMARY_INFORMATION_PID_AUTHOR: property_value_identifier_string = "PIDSI_AUTHOR"; break; case LIBOLECF_SUMMARY_INFORMATION_PID_KEYWORDS: property_value_identifier_string = "PIDSI_KEYWORDS"; break; case LIBOLECF_SUMMARY_INFORMATION_PID_COMMENTS: property_value_identifier_string = "PIDSI_COMMENTS"; break; case LIBOLECF_SUMMARY_INFORMATION_PID_TEMPLATE: property_value_identifier_string = "PIDSI_TEMPLATE"; break; case LIBOLECF_SUMMARY_INFORMATION_PID_LAST_SAVED_BY: property_value_identifier_string = "PIDSI_LASTAUTHOR"; break; case LIBOLECF_SUMMARY_INFORMATION_PID_REVISION_NUMBER: property_value_identifier_string = "PIDSI_REVNUMBER"; break; case LIBOLECF_SUMMARY_INFORMATION_PID_APPLICATION_NAME: property_value_identifier_string = "PIDSI_APPNAME"; break; default: break; } break; case LIBOLECF_VALUE_TYPE_FILETIME: switch( property_value_identifier ) { case LIBOLECF_SUMMARY_INFORMATION_PID_EDITING_TIME: property_value_identifier_string = "PIDSI_EDITTIME"; break; case LIBOLECF_SUMMARY_INFORMATION_PID_LAST_PRINTED_TIME: property_value_identifier_string = "PIDSI_LASTPRINTED"; break; case LIBOLECF_SUMMARY_INFORMATION_PID_CREATION_TIME: property_value_identifier_string = "PIDSI_CREATE_DTM"; break; case LIBOLECF_SUMMARY_INFORMATION_PID_LAST_WRITTEN_TIME: property_value_identifier_string = "PIDSI_LASTSAVE_DTM"; break; default: break; } break; case LIBOLECF_VALUE_TYPE_CLIPBOARD_FORMAT: switch( property_value_identifier ) { case LIBOLECF_SUMMARY_INFORMATION_PID_THUMBNAIL: property_value_identifier_string = "PIDSI_THUMBNAIL"; break; default: break; } break; default: break; } } fprintf( info_handle->notify_stream, "\tValue identifier\t: " ); if( property_value_identifier_string != NULL ) { fprintf( info_handle->notify_stream, "%s (", property_value_identifier_string ); } fprintf( info_handle->notify_stream, "0x%08" PRIx32 "", property_value_identifier ); if( property_value_identifier_string != NULL ) { fprintf( info_handle->notify_stream, ")" ); } fprintf( info_handle->notify_stream, "\n" ); fprintf( info_handle->notify_stream, "\tValue type\t\t: %s (0x%08" PRIx32 ")\n", libfole_value_type_get_identifier( property_value_type ), property_value_type ); /* TODO print the properties */ if( libolecf_property_value_free( &property_value, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free property value.", function ); goto on_error; } fprintf( info_handle->notify_stream, "\n" ); } if( libolecf_property_section_free( &property_section, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free property section.", function ); goto on_error; } } if( libfguid_identifier_free( &guid, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free GUID.", function ); goto on_error; } if( libolecf_property_set_free( &property_set, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free property set.", function ); goto on_error; } if( libolecf_item_free( &property_set_stream, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free property set stream.", function ); goto on_error; } fprintf( info_handle->notify_stream, "\n" ); } return( 1 ); on_error: if( property_value != NULL ) { libolecf_property_value_free( &property_value, NULL ); } if( property_section != NULL ) { libolecf_property_section_free( &property_section, NULL ); } if( guid != NULL ) { libfguid_identifier_free( &guid, NULL ); } if( property_set != NULL ) { libolecf_property_set_free( &property_set, NULL ); } if( property_set_stream != NULL ) { libolecf_item_free( &property_set_stream, NULL ); } return( -1 ); }