/* Reads an index node * Returns 1 if successful or -1 on error */ int libpff_index_node_read( libpff_index_node_t *index_node, libpff_io_handle_t *io_handle, libbfio_handle_t *file_io_handle, off64_t node_offset, libcerror_error_t **error ) { uint8_t *index_node_footer_data = NULL; static char *function = "libpff_index_node_read"; ssize_t read_count = 0; uint32_t calculated_checksum = 0; uint32_t stored_checksum = 0; uint8_t calculated_entry_size = 0; uint8_t calculated_maximum_number_of_entries = 0; uint8_t index_node_type_copy = 0; int result = 0; #if defined( HAVE_DEBUG_OUTPUT ) uint8_t *index_node_entry_data = NULL; uint64_t value_64bit = 0; uint32_t value_32bit = 0; uint16_t entry_index = 0; uint16_t index_node_entry_data_size = 0; uint16_t value_16bit = 0; #endif if( index_node == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid index node.", function ); return( -1 ); } if( index_node->data != NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, "%s: invalid index node - data already set.", function ); return( -1 ); } if( io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid IO handle.", function ); return( -1 ); } if( ( io_handle->file_type != LIBPFF_FILE_TYPE_32BIT ) && ( io_handle->file_type != LIBPFF_FILE_TYPE_64BIT ) && ( io_handle->file_type != LIBPFF_FILE_TYPE_64BIT_4K_PAGE ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, "%s: unsupported file type.", function ); return( -1 ); } if( io_handle->file_type == LIBPFF_FILE_TYPE_32BIT ) { index_node->data_size = 512; index_node->maximum_entries_data_size = 512 - sizeof( pff_index_node_32bit_footer_t ); } else if( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT ) { index_node->data_size = 512; index_node->maximum_entries_data_size = 512 - sizeof( pff_index_node_64bit_footer_t ); } else if( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT_4K_PAGE ) { index_node->data_size = 4096; index_node->maximum_entries_data_size = 4096 - sizeof( pff_index_node_64bit_4k_page_footer_t ); } index_node->data = (uint8_t *) memory_allocate( sizeof( uint8_t ) * index_node->data_size ); if( index_node->data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create index node data.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: reading index node data at offset: %" PRIi64 " (0x%08" PRIx64 ")\n", function, node_offset, node_offset ); } #endif if( libbfio_handle_seek_offset( file_io_handle, node_offset, SEEK_SET, error ) == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_SEEK_FAILED, "%s: unable to seek node offset: %" PRIi64 ".", function, node_offset ); goto on_error; } read_count = libbfio_handle_read_buffer( file_io_handle, index_node->data, index_node->data_size, error ); if( read_count != (ssize_t) index_node->data_size ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read index node data.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: index node data:\n", function ); libcnotify_print_data( index_node->data, index_node->data_size, LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); } #endif index_node_footer_data = &( index_node->data[ index_node->maximum_entries_data_size ] ); if( io_handle->file_type == LIBPFF_FILE_TYPE_32BIT ) { index_node->type = ( (pff_index_node_32bit_footer_t *) index_node_footer_data )->type; index_node_type_copy = ( (pff_index_node_32bit_footer_t *) index_node_footer_data )->type_copy; byte_stream_copy_to_uint32_little_endian( ( (pff_index_node_32bit_footer_t *) index_node_footer_data )->back_pointer, index_node->back_pointer ); byte_stream_copy_to_uint32_little_endian( ( (pff_index_node_32bit_footer_t *) index_node_footer_data )->checksum, stored_checksum ); index_node->number_of_entries = ( (pff_index_node_32bit_footer_t *) index_node_footer_data )->number_of_entries; index_node->maximum_number_of_entries = ( (pff_index_node_32bit_footer_t *) index_node_footer_data )->maximum_number_of_entries; index_node->entry_size = ( (pff_index_node_32bit_footer_t *) index_node_footer_data )->entry_size; index_node->level = ( (pff_index_node_32bit_footer_t *) index_node_footer_data )->level; if( ( index_node->type == LIBPFF_INDEX_TYPE_DESCRIPTOR ) && ( index_node->level == LIBPFF_INDEX_NODE_LEVEL_LEAF ) ) { calculated_entry_size = 16; calculated_maximum_number_of_entries = 496 / 16; } else { calculated_entry_size = 12; calculated_maximum_number_of_entries = 496 / 12; } } else if( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT ) { index_node->type = ( (pff_index_node_64bit_footer_t *) index_node_footer_data )->type; index_node_type_copy = ( (pff_index_node_64bit_footer_t *) index_node_footer_data )->type_copy; byte_stream_copy_to_uint32_little_endian( ( (pff_index_node_64bit_footer_t *) index_node_footer_data )->checksum, stored_checksum ); byte_stream_copy_to_uint64_little_endian( ( (pff_index_node_64bit_footer_t *) index_node_footer_data )->back_pointer, index_node->back_pointer ); index_node->number_of_entries = ( (pff_index_node_64bit_footer_t *) index_node_footer_data )->number_of_entries; index_node->maximum_number_of_entries = ( (pff_index_node_64bit_footer_t *) index_node_footer_data )->maximum_number_of_entries; index_node->entry_size = ( (pff_index_node_64bit_footer_t *) index_node_footer_data )->entry_size; index_node->level = ( (pff_index_node_64bit_footer_t *) index_node_footer_data )->level; if( ( index_node->type == LIBPFF_INDEX_TYPE_DESCRIPTOR ) && ( index_node->level == LIBPFF_INDEX_NODE_LEVEL_LEAF ) ) { calculated_entry_size = 32; calculated_maximum_number_of_entries = 488 / 32; } else { calculated_entry_size = 24; calculated_maximum_number_of_entries = 488 / 24; } } else if( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT_4K_PAGE ) { index_node->type = ( (pff_index_node_64bit_4k_page_footer_t *) index_node_footer_data )->type; index_node_type_copy = ( (pff_index_node_64bit_4k_page_footer_t *) index_node_footer_data )->type_copy; byte_stream_copy_to_uint32_little_endian( ( (pff_index_node_64bit_4k_page_footer_t *) index_node_footer_data )->checksum, stored_checksum ); byte_stream_copy_to_uint64_little_endian( ( (pff_index_node_64bit_4k_page_footer_t *) index_node_footer_data )->back_pointer, index_node->back_pointer ); byte_stream_copy_to_uint16_little_endian( ( (pff_index_node_64bit_4k_page_footer_t *) index_node_footer_data )->number_of_entries, index_node->number_of_entries ); byte_stream_copy_to_uint16_little_endian( ( (pff_index_node_64bit_4k_page_footer_t *) index_node_footer_data )->maximum_number_of_entries, index_node->maximum_number_of_entries ); index_node->entry_size = ( (pff_index_node_64bit_4k_page_footer_t *) index_node_footer_data )->entry_size; index_node->level = ( (pff_index_node_64bit_4k_page_footer_t *) index_node_footer_data )->level; if( ( index_node->type == LIBPFF_INDEX_TYPE_DESCRIPTOR ) && ( index_node->level == LIBPFF_INDEX_NODE_LEVEL_LEAF ) ) { calculated_entry_size = 32; calculated_maximum_number_of_entries = 4056 / 32; } else { calculated_entry_size = 24; calculated_maximum_number_of_entries = 4056 / 24; } } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: number of entries\t\t\t\t: %" PRIu16 "\n", function, index_node->number_of_entries ); libcnotify_printf( "%s: maximum number of entries\t\t\t: %" PRIu16 "\n", function, index_node->maximum_number_of_entries ); libcnotify_printf( "%s: entry size\t\t\t\t\t: %" PRIu8 "\n", function, index_node->entry_size ); libcnotify_printf( "%s: node level\t\t\t\t\t: %" PRIu8 "\n", function, index_node->level ); if( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT ) { libcnotify_printf( "%s: padding:\n", function ); libcnotify_print_data( ( (pff_index_node_64bit_footer_t *) index_node_footer_data )->padding1, 4, 0 ); } else if( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT_4K_PAGE ) { libcnotify_printf( "%s: padding:\n", function ); libcnotify_print_data( ( (pff_index_node_64bit_4k_page_footer_t *) index_node_footer_data )->padding1, 10, 0 ); } libcnotify_printf( "%s: index node type\t\t\t\t\t: 0x%02" PRIx8 "\n", function, index_node->type ); libcnotify_printf( "%s: index node type copy\t\t\t\t: 0x%02" PRIx8 "\n", function, index_node_type_copy ); if( io_handle->file_type == LIBPFF_FILE_TYPE_32BIT ) { byte_stream_copy_to_uint16_little_endian( ( (pff_index_node_32bit_footer_t *) index_node_footer_data )->signature, value_16bit ); libcnotify_printf( "%s: signature\t\t\t\t\t: 0x%04" PRIx16 "\n", function, value_16bit ); libcnotify_printf( "%s: back pointer\t\t\t\t\t: 0x%08" PRIx64 "\n", function, index_node->back_pointer ); libcnotify_printf( "%s: checksum\t\t\t\t\t: 0x%08" PRIx32 "\n", function, stored_checksum ); } else if( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT ) { byte_stream_copy_to_uint16_little_endian( ( (pff_index_node_64bit_footer_t *) index_node_footer_data )->signature, value_16bit ); libcnotify_printf( "%s: signature\t\t\t\t\t: 0x%04" PRIx16 "\n", function, value_16bit ); libcnotify_printf( "%s: checksum\t\t\t\t\t: 0x%08" PRIx32 "\n", function, stored_checksum ); libcnotify_printf( "%s: back pointer\t\t\t\t\t: 0x%08" PRIx64 "\n", function, index_node->back_pointer ); } else if( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT_4K_PAGE ) { byte_stream_copy_to_uint16_little_endian( ( (pff_index_node_64bit_4k_page_footer_t *) index_node_footer_data )->signature, value_16bit ); libcnotify_printf( "%s: signature\t\t\t\t\t: 0x%04" PRIx16 "\n", function, value_16bit ); libcnotify_printf( "%s: checksum\t\t\t\t\t: 0x%08" PRIx32 "\n", function, stored_checksum ); libcnotify_printf( "%s: back pointer\t\t\t\t\t: 0x%08" PRIx64 "\n", function, index_node->back_pointer ); byte_stream_copy_to_uint64_little_endian( ( (pff_index_node_64bit_4k_page_footer_t *) index_node_footer_data )->unknown1, value_64bit ); libcnotify_printf( "%s: unknown1\t\t\t\t\t: 0x%08" PRIx64 "\n", function, value_64bit ); } libcnotify_printf( "\n" ); } #endif if( index_node->type != index_node_type_copy ) { #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: mismatch in index node type (0x%02" PRIx8 " != 0x%02" PRIx8 ").\n", function, index_node->type, index_node_type_copy ); } #endif if( ( index_node->type != LIBPFF_INDEX_TYPE_DESCRIPTOR ) && ( index_node->type != LIBPFF_INDEX_TYPE_OFFSET ) && ( ( index_node_type_copy == LIBPFF_INDEX_TYPE_DESCRIPTOR ) || ( index_node_type_copy == LIBPFF_INDEX_TYPE_OFFSET ) ) ) { index_node->type = index_node_type_copy; } } if( ( index_node->type != LIBPFF_INDEX_TYPE_DESCRIPTOR ) && ( index_node->type != LIBPFF_INDEX_TYPE_OFFSET ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, "%s: unsupported index node type: 0x%02" PRIx8 ".", function, index_node->type ); goto on_error; } if( io_handle->file_type == LIBPFF_FILE_TYPE_32BIT ) { result = libfmapi_checksum_calculate_weak_crc32( &calculated_checksum, index_node->data, 500, 0, error ); } else if( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT ) { result = libfmapi_checksum_calculate_weak_crc32( &calculated_checksum, index_node->data, 496, 0, error ); } else if( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT_4K_PAGE ) { result = libfmapi_checksum_calculate_weak_crc32( &calculated_checksum, index_node->data, 4072, 0, error ); } if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to calculate weak CRC-32.", function ); goto on_error; } if( stored_checksum != calculated_checksum ) { #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: mismatch in checksum ( 0x%08" PRIx32 " != 0x%08" PRIx32 " ).\n", function, stored_checksum, calculated_checksum ); } #endif /* TODO smart error handling */ } if( ( index_node->entry_size != 0 ) && ( index_node->entry_size != calculated_entry_size ) ) { #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: entry size mismatch (calculated: %" PRIu8 ", stored: %" PRIu8 ").\n", function, calculated_entry_size, index_node->entry_size ); } #endif index_node->entry_size = calculated_entry_size; } if( ( index_node->maximum_number_of_entries != 0 ) && ( index_node->maximum_number_of_entries != calculated_maximum_number_of_entries ) ) { #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: maximum number of entries mismatch (calculated: %" PRIu8 ", stored: %" PRIu8 ").\n", function, calculated_maximum_number_of_entries, index_node->maximum_number_of_entries ); } #endif index_node->maximum_number_of_entries = calculated_maximum_number_of_entries; } if( index_node->number_of_entries > index_node->maximum_number_of_entries ) { #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: number of entries: %" PRIu8 ", exceeds maximum: %" PRIu8 ".", function, index_node->number_of_entries, index_node->maximum_number_of_entries ); } #endif index_node->number_of_entries = index_node->maximum_number_of_entries; } if( ( (uint16_t) index_node->number_of_entries * (uint16_t) index_node->entry_size ) > index_node->maximum_entries_data_size ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: size of entries: %" PRIu16 ", exceeds maximum: %" PRIu16 ".", function, index_node->number_of_entries * index_node->entry_size, index_node->maximum_entries_data_size ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { index_node_entry_data = index_node->data; index_node_entry_data_size = index_node->maximum_entries_data_size; /* Print all the entries */ for( entry_index = 0; entry_index < index_node->maximum_number_of_entries; entry_index++ ) { if( entry_index == index_node->number_of_entries ) { result = libpff_index_node_check_for_empty_block( index_node_entry_data, index_node_entry_data_size, error ); if( result == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine if remaining index nodes are empty.", function ); return( -1 ); } else if( result != 0 ) { break; } libcnotify_printf( "\n" ); libcnotify_printf( "%s: remaining node entries\n", function ); } if( io_handle->file_type == LIBPFF_FILE_TYPE_32BIT ) { byte_stream_copy_to_uint32_little_endian( index_node_entry_data, value_64bit ); } else if( ( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT ) || ( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT_4K_PAGE ) ) { byte_stream_copy_to_uint64_little_endian( index_node_entry_data, value_64bit ); } libcnotify_printf( "%s: entry: %03" PRIu16 " index node identifier\t\t: 0x%08" PRIx64 " (%" PRIu64 ")\n", function, entry_index, value_64bit, value_64bit ); /* Process descriptor index node leaf nodes */ if( ( index_node->type == LIBPFF_INDEX_TYPE_DESCRIPTOR ) && ( index_node->level == LIBPFF_INDEX_NODE_LEVEL_LEAF ) ) { if( io_handle->file_type == LIBPFF_FILE_TYPE_32BIT ) { byte_stream_copy_to_uint32_little_endian( ( (pff_index_node_descriptor_entry_32bit_t *) index_node_entry_data )->data_identifier, value_64bit ); } else if( ( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT ) || ( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT_4K_PAGE ) ) { byte_stream_copy_to_uint64_little_endian( ( (pff_index_node_descriptor_entry_64bit_t *) index_node_entry_data )->data_identifier, value_64bit ); } libcnotify_printf( "%s: entry: %03" PRIu16 " data identifier\t\t\t: 0x%08" PRIx64 " (%" PRIu64 ")\n", function, entry_index, value_64bit, value_64bit ); if( io_handle->file_type == LIBPFF_FILE_TYPE_32BIT ) { byte_stream_copy_to_uint32_little_endian( ( (pff_index_node_descriptor_entry_32bit_t *) index_node_entry_data )->local_descriptors_identifier, value_64bit ); } else if( ( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT ) || ( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT_4K_PAGE ) ) { byte_stream_copy_to_uint64_little_endian( ( (pff_index_node_descriptor_entry_64bit_t *) index_node_entry_data )->local_descriptors_identifier, value_64bit ); } libcnotify_printf( "%s: entry: %03" PRIu16 " local descriptors identifier\t\t: 0x%08" PRIx64 " (%" PRIu64 ")\n", function, entry_index, value_64bit, value_64bit ); if( io_handle->file_type == LIBPFF_FILE_TYPE_32BIT ) { byte_stream_copy_to_uint32_little_endian( ( (pff_index_node_descriptor_entry_32bit_t *) index_node_entry_data )->parent_identifier, value_32bit ); } else if( ( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT ) || ( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT_4K_PAGE ) ) { byte_stream_copy_to_uint32_little_endian( ( (pff_index_node_descriptor_entry_64bit_t *) index_node_entry_data )->parent_identifier, value_32bit ); } libcnotify_printf( "%s: entry: %03" PRIu16 " parent identifier\t\t\t: 0x%08" PRIx32 " (%" PRIu32 ")\n", function, entry_index, value_32bit, value_32bit ); if( ( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT ) || ( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT_4K_PAGE ) ) { byte_stream_copy_to_uint32_little_endian( ( (pff_index_node_descriptor_entry_64bit_t *) index_node_entry_data )->unknown1, value_32bit ); libcnotify_printf( "%s: entry: %03" PRIu16 " unknown1\t\t\t\t: 0x%08" PRIx32 " (%" PRIu32 ")\n", function, entry_index, value_32bit, value_32bit ); } } /* Process offset and descriptor index node branch nodes and offset index node leaf nodes */ else { if( index_node->level != LIBPFF_INDEX_NODE_LEVEL_LEAF ) { if( io_handle->file_type == LIBPFF_FILE_TYPE_32BIT ) { byte_stream_copy_to_uint32_little_endian( ( (pff_index_node_branch_entry_32bit_t *) index_node_entry_data )->back_pointer, value_64bit ); } else if( ( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT ) || ( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT_4K_PAGE ) ) { byte_stream_copy_to_uint64_little_endian( ( (pff_index_node_branch_entry_64bit_t *) index_node_entry_data )->back_pointer, value_64bit ); } libcnotify_printf( "%s: entry: %03" PRIu16 " back pointer\t\t\t\t: 0x%08" PRIx64 "\n", function, entry_index, value_64bit ); } if( index_node->level == LIBPFF_INDEX_NODE_LEVEL_LEAF ) { if( io_handle->file_type == LIBPFF_FILE_TYPE_32BIT ) { byte_stream_copy_to_uint32_little_endian( ( (pff_index_node_offset_entry_32bit_t *) index_node_entry_data )->file_offset, value_64bit ); } else if( ( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT ) || ( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT_4K_PAGE ) ) { byte_stream_copy_to_uint64_little_endian( ( (pff_index_node_offset_entry_64bit_t *) index_node_entry_data )->file_offset, value_64bit ); } } else { if( io_handle->file_type == LIBPFF_FILE_TYPE_32BIT ) { byte_stream_copy_to_uint32_little_endian( ( (pff_index_node_branch_entry_32bit_t *) index_node_entry_data )->file_offset, value_64bit ); } else if( ( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT ) || ( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT_4K_PAGE ) ) { byte_stream_copy_to_uint64_little_endian( ( (pff_index_node_branch_entry_64bit_t *) index_node_entry_data )->file_offset, value_64bit ); } } libcnotify_printf( "%s: entry: %03" PRIu16 " file offset\t\t\t\t: 0x%08" PRIx64 " (%" PRIu64 ")\n", function, entry_index, value_64bit, value_64bit ); if( index_node->level == LIBPFF_INDEX_NODE_LEVEL_LEAF ) { if( io_handle->file_type == LIBPFF_FILE_TYPE_32BIT ) { byte_stream_copy_to_uint16_little_endian( ( (pff_index_node_offset_entry_32bit_t *) index_node_entry_data )->data_size, value_16bit ); } else if( ( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT ) || ( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT_4K_PAGE ) ) { byte_stream_copy_to_uint16_little_endian( ( (pff_index_node_offset_entry_64bit_t *) index_node_entry_data )->data_size, value_16bit ); } libcnotify_printf( "%s: entry: %03" PRIu16 " data size\t\t\t\t: %" PRIu16 "\n", function, entry_index, value_16bit ); if( io_handle->file_type == LIBPFF_FILE_TYPE_32BIT ) { byte_stream_copy_to_uint16_little_endian( ( (pff_index_node_offset_entry_32bit_t *) index_node_entry_data )->reference_count, value_16bit ); } else if( ( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT ) || ( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT_4K_PAGE ) ) { byte_stream_copy_to_uint16_little_endian( ( (pff_index_node_offset_entry_64bit_t *) index_node_entry_data )->reference_count, value_16bit ); } libcnotify_printf( "%s: entry: %03" PRIu16 " reference count\t\t\t: %" PRIu16 "\n", function, entry_index, value_16bit ); if( ( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT ) || ( io_handle->file_type == LIBPFF_FILE_TYPE_64BIT_4K_PAGE ) ) { byte_stream_copy_to_uint32_little_endian( ( (pff_index_node_offset_entry_64bit_t *) index_node_entry_data )->data_allocation_table_file_offset, value_32bit ); libcnotify_printf( "%s: entry: %03" PRIu16 " data allocation table offset\t\t: 0x%08" PRIx32 " (%" PRIu32 ")\n", function, entry_index, value_32bit, value_32bit ); } } } index_node_entry_data += index_node->entry_size; index_node_entry_data_size -= index_node->entry_size; } libcnotify_printf( "\n" ); } #endif index_node->entries_data = index_node->data; return( 1 ); on_error: if( index_node->data != NULL ) { memory_free( index_node->data ); index_node->data = NULL; } return( -1 ); }
/* Reads a compressed grain data header * The number of bytes read or -1 on error */ ssize_t libvmdk_grain_data_read_compressed_header( libvmdk_grain_data_t *grain_data, libvmdk_io_handle_t *io_handle, libbfio_pool_t *file_io_pool, int file_io_pool_entry, libcerror_error_t **error ) { uint8_t compressed_data_header[ 12 ]; static char *function = "libvmdk_grain_data_read_compressed_header"; ssize_t read_count = 0; if( grain_data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid grain data.", function ); return( -1 ); } if( io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid IO handle.", function ); return( -1 ); } read_count = libbfio_pool_read_buffer( file_io_pool, file_io_pool_entry, compressed_data_header, 12, error ); if( read_count != (ssize_t) 12 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read compressed grain data header.", function ); return( -1 ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: compressed grain data header:\n", function ); libcnotify_print_data( compressed_data_header, 12, 0 ); } #endif byte_stream_copy_to_uint64_little_endian( compressed_data_header, grain_data->uncompressed_data_offset ); byte_stream_copy_to_uint32_little_endian( &( compressed_data_header[ 8 ] ), grain_data->compressed_data_size ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: uncompressed data offset\t: %" PRIu64 " grains (0x%08" PRIx64 ")\n", function, grain_data->uncompressed_data_offset, grain_data->uncompressed_data_offset * io_handle->grain_size ); libcnotify_printf( "%s: compressed data size\t\t: %" PRIu32 "\n", function, grain_data->compressed_data_size ); libcnotify_printf( "\n" ); } #endif grain_data->uncompressed_data_offset *= io_handle->grain_size; return( read_count ); }
/* Reads the record * Returns 1 if successful or -1 on error */ int libftxf_record_read( libftxf_record_t *record, const uint8_t *record_data, size_t record_data_size, libcerror_error_t **error ) { libftxf_internal_record_t *internal_record = NULL; static char *function = "libftxf_record_read"; size_t record_data_offset = 0; uint16_t record_type = 0; uint16_t name_offset = 0; uint16_t name_size = 0; #if defined( HAVE_DEBUG_OUTPUT ) libcstring_system_character_t date_time_string[ 32 ]; libcstring_system_character_t guid_string[ 48 ]; libcstring_system_character_t *value_string = NULL; libfdatetime_filetime_t *filetime = NULL; libfguid_identifier_t *guid = NULL; size_t value_string_size = 0; uint64_t value_64bit = 0; uint32_t value_32bit = 0; uint16_t value_16bit = 0; int result = 0; #endif if( record == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid record.", function ); return( -1 ); } internal_record = (libftxf_internal_record_t *) record; if( record_data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid record data.", function ); return( -1 ); } if( record_data_size > (size_t) SSIZE_MAX ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid record data size value exceeds maximum.", function ); return( -1 ); } if( record_data_size < sizeof( ftxf_record_header_t ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, "%s: invalid record data value too small.", function ); return( -1 ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: record header data:\n", function ); libcnotify_print_data( record_data, sizeof( ftxf_record_header_t ), 0 ); } #endif byte_stream_copy_to_uint16_little_endian( ( (ftxf_record_header_t *) record_data )->record_type, record_type ); byte_stream_copy_to_uint32_little_endian( ( (ftxf_record_header_t *) record_data )->record_size, internal_record->size ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { byte_stream_copy_to_uint32_little_endian( ( (ftxf_record_header_t *) record_data )->unknown1, value_32bit ); libcnotify_printf( "%s: unknown1\t\t\t\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); libcnotify_printf( "%s: record type\t\t\t\t\t: 0x%04" PRIx16 "\n", function, record_type ); byte_stream_copy_to_uint16_little_endian( ( (ftxf_record_header_t *) record_data )->unknown2, value_16bit ); libcnotify_printf( "%s: unknown2\t\t\t\t\t\t: 0x%04" PRIx16 "\n", function, value_16bit ); byte_stream_copy_to_uint64_little_endian( ( (ftxf_record_header_t *) record_data )->file_identifier, value_64bit ); libcnotify_printf( "%s: file identifier\t\t\t\t\t: 0x%08" PRIx64 "\n", function, value_64bit ); byte_stream_copy_to_uint64_little_endian( ( (ftxf_record_header_t *) record_data )->file_reference, value_64bit ); libcnotify_printf( "%s: file reference\t\t\t\t\t: MFT entry: %" PRIu64 ", sequence: %" PRIu64 "\n", function, value_64bit & 0xffffffffffffUL, value_64bit >> 48 ); byte_stream_copy_to_uint32_little_endian( ( (ftxf_record_header_t *) record_data )->unknown4, value_32bit ); libcnotify_printf( "%s: unknown4\t\t\t\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); byte_stream_copy_to_uint32_little_endian( ( (ftxf_record_header_t *) record_data )->unknown5, value_32bit ); libcnotify_printf( "%s: unknown5\t\t\t\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); 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( libfguid_identifier_copy_from_byte_stream( guid, ( (ftxf_record_header_t *) record_data )->unknown6, 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; } 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; } libcnotify_printf( "%s: unknown6 guid\t\t\t\t\t: %" PRIs_LIBCSTRING_SYSTEM "\n", function, guid_string ); byte_stream_copy_to_uint64_little_endian( ( (ftxf_record_header_t *) record_data )->unknown7, value_64bit ); libcnotify_printf( "%s: unknown7\t\t\t\t\t\t: 0x%08" PRIx64 "\n", function, value_64bit ); if( libfdatetime_filetime_initialize( &filetime, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create filetime.", function ); goto on_error; } if( libfdatetime_filetime_copy_from_byte_stream( filetime, ( (ftxf_record_header_t *) record_data )->unknown8, 8, LIBFDATETIME_ENDIAN_LITTLE, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to copy filetime from byte stream.", function ); goto on_error; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libfdatetime_filetime_copy_to_utf16_string( filetime, (uint16_t *) date_time_string, 32, LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS, error ); #else result = libfdatetime_filetime_copy_to_utf8_string( filetime, (uint8_t *) date_time_string, 32, LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to copy filetime to date time string.", function ); goto on_error; } libcnotify_printf( "%s: unknown8 filetime\t\t\t\t\t: %" PRIs_LIBCSTRING_SYSTEM " UTC\n", function, date_time_string ); if( libfdatetime_filetime_free( &filetime, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free filetime.", function ); goto on_error; } libcnotify_printf( "%s: record size\t\t\t\t\t: %" PRIu32 "\n", function, internal_record->size ); byte_stream_copy_to_uint32_little_endian( ( (ftxf_record_header_t *) record_data )->unknown9, value_32bit ); libcnotify_printf( "%s: unknown9\t\t\t\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); byte_stream_copy_to_uint64_little_endian( ( (ftxf_record_header_t *) record_data )->unknown10, value_64bit ); libcnotify_printf( "%s: unknown10\t\t\t\t\t\t: 0x%08" PRIx64 "\n", function, value_64bit ); libcnotify_printf( "\n" ); }
/* Reads the block descriptor * Returns 1 if successful, 0 if block list entry is empty or -1 on error */ int libvshadow_block_descriptor_read( libvshadow_block_descriptor_t *block_descriptor, const uint8_t *block_list_entry_data, size_t block_list_entry_size, int store_index LIBVSHADOW_ATTRIBUTE_UNUSED, libcerror_error_t **error ) { static char *function = "libvshadow_block_descriptor_read"; LIBVSHADOW_UNREFERENCED_PARAMETER( store_index ) if( block_descriptor == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid block descriptor.", function ); return( -1 ); } if( block_list_entry_data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid block list entry data.", function ); return( -1 ); } if( block_list_entry_size > (size_t) SSIZE_MAX ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid block list entry size value exceeds maximum.", function ); return( -1 ); } if( memory_compare( block_list_entry_data, vshadow_empty_store_block_list_entry, sizeof( vshadow_store_block_list_entry_t ) ) == 0 ) { return( 0 ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: store: %02d block list entry data:\n", function, store_index ); libcnotify_print_data( block_list_entry_data, sizeof( vshadow_store_block_list_entry_t ), 0 ); } #endif byte_stream_copy_to_uint64_little_endian( ( (vshadow_store_block_list_entry_t *) block_list_entry_data )->original_offset, block_descriptor->original_offset ); byte_stream_copy_to_uint64_little_endian( ( (vshadow_store_block_list_entry_t *) block_list_entry_data )->relative_offset, block_descriptor->relative_offset ); byte_stream_copy_to_uint64_little_endian( ( (vshadow_store_block_list_entry_t *) block_list_entry_data )->offset, block_descriptor->offset ); byte_stream_copy_to_uint32_little_endian( ( (vshadow_store_block_list_entry_t *) block_list_entry_data )->flags, block_descriptor->flags ); byte_stream_copy_to_uint32_little_endian( ( (vshadow_store_block_list_entry_t *) block_list_entry_data )->allocation_bitmap, block_descriptor->bitmap ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: store: %02d original offset\t\t: 0x%08" PRIx64 "\n", function, store_index, block_descriptor->original_offset ); libcnotify_printf( "%s: store: %02d relative offset\t\t: 0x%08" PRIx64 "\n", function, store_index, block_descriptor->relative_offset ); libcnotify_printf( "%s: store: %02d offset\t\t\t: 0x%08" PRIx64 "\n", function, store_index, block_descriptor->offset ); libcnotify_printf( "%s: store: %02d flags\t\t\t: 0x%08" PRIx32 "\n", function, store_index, block_descriptor->flags ); libcnotify_printf( "%s: store: %02d allocation bitmap\t\t: 0x%08" PRIx32 "\n", function, store_index, block_descriptor->bitmap ); libcnotify_printf( "\n" ); } #endif if( ( block_descriptor->flags & LIBVSHADOW_BLOCK_FLAG_IS_FORWARDER ) != 0 ) { if( block_descriptor->offset != 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, "%s: unsupported offset - value not zero.", function ); return( -1 ); } } return( 1 ); }
/* Converts the value data into a 64-bit value * Returns 1 if successful or -1 on error */ int libregf_value_type_copy_to_64bit( uint8_t *value_data, size_t value_data_size, uint8_t byte_order, uint64_t *value_64bit, libcerror_error_t **error ) { static char *function = "libregf_value_type_copy_to_64bit"; if( value_data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid value data.", function ); return( -1 ); } if( value_64bit == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid value 64-bit.", function ); return( -1 ); } /* The value data size of a 64-bit value is 8 */ if( value_data_size != 8 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid value data size value out of bounds.", function ); return( -1 ); } if( ( byte_order != LIBREGF_ENDIAN_BIG ) && ( byte_order != LIBREGF_ENDIAN_LITTLE ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, "%s: unsupported byte order: 0x%02" PRIx8 ".", function, byte_order ); return( -1 ); } if( byte_order == LIBREGF_ENDIAN_BIG ) { byte_stream_copy_to_uint64_big_endian( value_data, *value_64bit ); } else { byte_stream_copy_to_uint64_little_endian( value_data, *value_64bit ); } return( 1 ); }
/* Reads the block descriptor * Returns 1 if successful, 0 if block list entry is empty or -1 on error */ int libvshadow_block_range_descriptor_read( libvshadow_block_range_descriptor_t *block_range_descriptor, const uint8_t *block_list_entry_data, size_t block_list_entry_size, int store_index LIBVSHADOW_ATTRIBUTE_UNUSED, libcerror_error_t **error ) { static char *function = "libvshadow_block_range_descriptor_read"; LIBVSHADOW_UNREFERENCED_PARAMETER( store_index ) if( block_range_descriptor == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid block descriptor.", function ); return( -1 ); } if( block_list_entry_data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid block list entry data.", function ); return( -1 ); } if( block_list_entry_size > (size_t) SSIZE_MAX ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid block list entry size value exceeds maximum.", function ); return( -1 ); } if( memory_compare( block_list_entry_data, vshadow_empty_store_block_range_list_entry, sizeof( vshadow_store_block_range_list_entry_t ) ) == 0 ) { return( 0 ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: store: %02d block range list entry data:\n", function, store_index ); libcnotify_print_data( block_list_entry_data, sizeof( vshadow_store_block_range_list_entry_t ), 0 ); } #endif byte_stream_copy_to_uint64_little_endian( ( (vshadow_store_block_range_list_entry_t *) block_list_entry_data )->offset, block_range_descriptor->offset ); byte_stream_copy_to_uint64_little_endian( ( (vshadow_store_block_range_list_entry_t *) block_list_entry_data )->relative_offset, block_range_descriptor->relative_offset ); byte_stream_copy_to_uint64_little_endian( ( (vshadow_store_block_range_list_entry_t *) block_list_entry_data )->size, block_range_descriptor->size ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: store: %02d offset\t\t: 0x%08" PRIx64 "\n", function, store_index, block_range_descriptor->offset ); libcnotify_printf( "%s: store: %02d relative offset\t: 0x%08" PRIx64 "\n", function, store_index, block_range_descriptor->relative_offset ); libcnotify_printf( "%s: store: %02d size\t\t\t: %" PRIu64 "\n", function, store_index, block_range_descriptor->size ); libcnotify_printf( "\n" ); } #endif return( 1 ); }
/* Reads an allocation table * Returns 1 if successful or -1 on error */ int libpff_allocation_table_read( libcdata_range_list_t *unallocated_block_list, libbfio_handle_t *file_io_handle, off64_t allocation_table_offset, uint8_t file_type, libcerror_error_t **error ) { uint8_t *allocation_table_data = NULL; uint8_t *table_data = NULL; static char *function = "libpff_allocation_table_read"; off64_t back_pointer_offset = 0; off64_t unallocated_offset = 0; size_t read_size = 0; size_t unallocated_size = 0; size_t allocation_block_size = 0; ssize_t read_count = 0; uint32_t stored_checksum = 0; uint32_t calculated_checksum = 0; uint16_t table_data_index = 0; uint16_t table_data_size = 0; uint8_t allocation_table_entry = 0; uint8_t allocation_table_type = 0; uint8_t allocation_table_type_copy = 0; uint8_t bit_index = 0; #if defined( HAVE_DEBUG_OUTPUT ) uint64_t value_64bit = 0; uint16_t value_16bit = 0; #endif if( unallocated_block_list == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid unallocated block list.", function ); return( -1 ); } if( file_io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid file IO handle.", function ); return( -1 ); } if( ( file_type != LIBPFF_FILE_TYPE_32BIT ) && ( file_type != LIBPFF_FILE_TYPE_64BIT ) && ( file_type != LIBPFF_FILE_TYPE_64BIT_4K_PAGE ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, "%s: unsupported file type.", function ); return( -1 ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: reading allocation table at offset: 0x%08" PRIx64 "\n", function, allocation_table_offset ); } #endif if( libbfio_handle_seek_offset( file_io_handle, allocation_table_offset, SEEK_SET, error ) == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_SEEK_FAILED, "%s: unable to seek allocation table offset: 0x%08" PRIx64 ".", function, allocation_table_offset ); goto on_error; } if( file_type == LIBPFF_FILE_TYPE_32BIT ) { read_size = sizeof( pff_allocation_table_32bit_t ); table_data_size = 496; } else if( file_type == LIBPFF_FILE_TYPE_64BIT ) { read_size = sizeof( pff_allocation_table_64bit_t ); table_data_size = 496; } else if( file_type == LIBPFF_FILE_TYPE_64BIT_4K_PAGE ) { read_size = sizeof( pff_allocation_table_64bit_4k_page_t ); table_data_size = 4072; } allocation_table_data = (uint8_t *) memory_allocate( sizeof( uint8_t ) * read_size ); if( allocation_table_data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create alloction table data.", function ); goto on_error; } read_count = libbfio_handle_read_buffer( file_io_handle, allocation_table_data, read_size, error ); if( read_count != (ssize_t) read_size ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read allocation table.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: allocation table:\n", function ); libcnotify_print_data( allocation_table_data, read_size, LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); } #endif if( file_type == LIBPFF_FILE_TYPE_32BIT ) { table_data = ( (pff_allocation_table_32bit_t *) allocation_table_data )->data; allocation_table_type = ( (pff_allocation_table_32bit_t *) allocation_table_data )->type; allocation_table_type_copy = ( (pff_allocation_table_32bit_t *) allocation_table_data )->type_copy; byte_stream_copy_to_uint32_little_endian( ( (pff_allocation_table_32bit_t *) allocation_table_data )->back_pointer, back_pointer_offset ); byte_stream_copy_to_uint32_little_endian( ( (pff_allocation_table_32bit_t *) allocation_table_data )->checksum, stored_checksum ); } else if( file_type == LIBPFF_FILE_TYPE_64BIT ) { table_data = ( (pff_allocation_table_64bit_t *) allocation_table_data )->data; allocation_table_type = ( (pff_allocation_table_64bit_t *) allocation_table_data )->type; allocation_table_type_copy = ( (pff_allocation_table_64bit_t *) allocation_table_data )->type_copy; byte_stream_copy_to_uint32_little_endian( ( (pff_allocation_table_64bit_t *) allocation_table_data )->checksum, stored_checksum ); byte_stream_copy_to_uint64_little_endian( ( (pff_allocation_table_64bit_t *) allocation_table_data )->back_pointer, back_pointer_offset ); } else if( file_type == LIBPFF_FILE_TYPE_64BIT_4K_PAGE ) { table_data = ( (pff_allocation_table_64bit_4k_page_t *) allocation_table_data )->data; allocation_table_type = ( (pff_allocation_table_64bit_4k_page_t *) allocation_table_data )->type; allocation_table_type_copy = ( (pff_allocation_table_64bit_4k_page_t *) allocation_table_data )->type_copy; byte_stream_copy_to_uint32_little_endian( ( (pff_allocation_table_64bit_4k_page_t *) allocation_table_data )->checksum, stored_checksum ); byte_stream_copy_to_uint64_little_endian( ( (pff_allocation_table_64bit_4k_page_t *) allocation_table_data )->back_pointer, back_pointer_offset ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: type\t\t: 0x%02" PRIx8 "\n", function, allocation_table_type ); libcnotify_printf( "%s: type copy\t\t: 0x%02" PRIx8 "\n", function, allocation_table_type_copy ); if( file_type == LIBPFF_FILE_TYPE_32BIT ) { byte_stream_copy_to_uint16_little_endian( ( (pff_allocation_table_32bit_t *) allocation_table_data )->signature, value_16bit ); libcnotify_printf( "%s: signature\t\t: 0x%04" PRIx16 "\n", function, value_16bit ); libcnotify_printf( "%s: back pointer\t: %" PRIu64 "\n", function, back_pointer_offset ); libcnotify_printf( "%s: checksum\t\t: 0x%" PRIx32 "\n", function, stored_checksum ); } else if( ( file_type == LIBPFF_FILE_TYPE_64BIT ) || ( file_type == LIBPFF_FILE_TYPE_64BIT_4K_PAGE ) ) { if( file_type == LIBPFF_FILE_TYPE_64BIT ) { byte_stream_copy_to_uint16_little_endian( ( (pff_allocation_table_64bit_t *) allocation_table_data )->signature, value_16bit ); } else { byte_stream_copy_to_uint16_little_endian( ( (pff_allocation_table_64bit_4k_page_t *) allocation_table_data )->signature, value_16bit ); } libcnotify_printf( "%s: signature\t\t: 0x%04" PRIx16 "\n", function, value_16bit ); libcnotify_printf( "%s: checksum\t\t: 0x%" PRIx32 "\n", function, stored_checksum ); libcnotify_printf( "%s: back pointer\t: %" PRIu64 "\n", function, back_pointer_offset ); if( file_type == LIBPFF_FILE_TYPE_64BIT_4K_PAGE ) { byte_stream_copy_to_uint64_little_endian( ( (pff_allocation_table_64bit_4k_page_t *) allocation_table_data )->unknown1, value_64bit ); libcnotify_printf( "%s: unknown1\t\t: 0x%08" PRIx64 "\n", function, value_64bit ); } } libcnotify_printf( "\n" ); } #endif if( libfmapi_checksum_calculate_weak_crc32( &calculated_checksum, table_data, (size_t) table_data_size, 0, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to calculate weak CRC-32.", function ); goto on_error; } if( stored_checksum != calculated_checksum ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_INPUT, LIBCERROR_INPUT_ERROR_CHECKSUM_MISMATCH, "%s: mismatch in checksum ( %" PRIu32 " != %" PRIu32 " ).", function, stored_checksum, calculated_checksum ); /* TODO implement error tollerance */ goto on_error; } if( allocation_table_type != allocation_table_type_copy ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_INPUT, LIBCERROR_INPUT_ERROR_CHECKSUM_MISMATCH, "%s: mismatch in allocation table type ( 0x%02" PRIx8 " != 0x%02" PRIx8 " ).", function, allocation_table_type, allocation_table_type_copy ); /* TODO implement error tollerance */ goto on_error; } if( ( allocation_table_type != LIBPFF_ALLOCATION_TABLE_TYPE_DATA ) && ( allocation_table_type != LIBPFF_ALLOCATION_TABLE_TYPE_PAGE ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, "%s: unsupported allocation table type: 0x%08" PRIx32 "", function, allocation_table_type ); /* TODO implement error tollerance */ goto on_error; } if( allocation_table_type == LIBPFF_ALLOCATION_TABLE_TYPE_PAGE ) { /* The page type allocation has not yet been seen i.c.w. 4k pages */ if( file_type == LIBPFF_FILE_TYPE_64BIT_4K_PAGE ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, "%s: unsupported file type.", function ); goto on_error; } allocation_block_size = 512; back_pointer_offset -= 0x200; } else if( allocation_table_type == LIBPFF_ALLOCATION_TABLE_TYPE_DATA ) { allocation_block_size = 64; } for( table_data_index = 0; table_data_index < table_data_size; table_data_index++ ) { allocation_table_entry = table_data[ table_data_index ]; for( bit_index = 0; bit_index < 8; bit_index++ ) { if( ( allocation_table_entry & 0x80 ) == 0 ) { if( unallocated_size == 0 ) { unallocated_offset = back_pointer_offset; } unallocated_size += allocation_block_size; } else if( unallocated_size > 0 ) { #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: unallocated block: 0x%08" PRIx64 " - 0x%08" PRIx64 " (%" PRIu64 ")\n", function, unallocated_offset, unallocated_offset + unallocated_size, unallocated_size ); } #endif if( libcdata_range_list_insert_range( unallocated_block_list, unallocated_offset, unallocated_size, NULL, NULL, NULL, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, "%s: unable to append unallocated block to list.", function ); goto on_error; } unallocated_size = 0; } allocation_table_entry <<= 1; back_pointer_offset += allocation_block_size; } } if( unallocated_size > 0 ) { #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: unallocated block: 0x%08" PRIx64 " - 0x%08" PRIx64 " (%" PRIu64 ")\n", function, unallocated_offset, unallocated_offset + unallocated_size, unallocated_size ); } #endif if( libcdata_range_list_insert_range( unallocated_block_list, unallocated_offset, unallocated_size, NULL, NULL, NULL, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, "%s: unable to append unallocated block to list.", function ); goto on_error; } unallocated_size = 0; } memory_free( allocation_table_data ); return( 1 ); on_error: if( allocation_table_data != NULL ) { memory_free( allocation_table_data ); } return( -1 ); }
/* Reads an free map * Returns 1 if successful or -1 on error */ int libpff_free_map_read( libcdata_range_list_t *unallocated_block_list, libbfio_handle_t *file_io_handle, off64_t free_map_offset, uint8_t file_type, libcerror_error_t **error ) { uint8_t *free_map_data = NULL; uint8_t *table_data = NULL; static char *function = "libpff_free_map_read"; off64_t back_pointer_offset = 0; off64_t unallocated_offset = 0; size_t read_size = 0; size_t unallocated_size = 0; size_t allocation_block_size = 0; ssize_t read_count = 0; uint32_t stored_checksum = 0; uint32_t calculated_checksum = 0; uint16_t table_iterator = 0; uint8_t bit_iterator = 0; uint8_t free_map_entry = 0; uint8_t free_map_type = 0; uint8_t free_map_type_copy = 0; int result = 0; #if defined( HAVE_DEBUG_OUTPUT ) uint16_t value_16bit = 0; #endif if( unallocated_block_list == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid unallocated block list.", function ); return( -1 ); } if( file_io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid file IO handle.", function ); return( -1 ); } if( ( file_type != LIBPFF_FILE_TYPE_32BIT ) && ( file_type != LIBPFF_FILE_TYPE_64BIT ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, "%s: unsupported file type.", function ); return( -1 ); } if( libbfio_handle_seek_offset( file_io_handle, free_map_offset, SEEK_SET, error ) == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_SEEK_FAILED, "%s: unable to seek free map offset: %" PRIi64 ".", function, free_map_offset ); goto on_error; } if( file_type == LIBPFF_FILE_TYPE_32BIT ) { read_size = sizeof( pff_free_map_32bit_t ); } else if( file_type == LIBPFF_FILE_TYPE_64BIT ) { read_size = sizeof( pff_free_map_64bit_t ); } free_map_data = (uint8_t *) memory_allocate( sizeof( uint8_t ) * read_size ); if( free_map_data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create alloction table data.", function ); goto on_error; } read_count = libbfio_handle_read_buffer( file_io_handle, free_map_data, read_size, error ); if( read_count != (ssize_t) read_size ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read free map.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: free map:\n", function ); libcnotify_print_data( free_map_data, read_size, 0 ); } #endif if( file_type == LIBPFF_FILE_TYPE_32BIT ) { table_data = ( (pff_free_map_32bit_t *) free_map_data )->data; free_map_type = ( (pff_free_map_32bit_t *) free_map_data )->type; free_map_type_copy = ( (pff_free_map_32bit_t *) free_map_data )->type_copy; byte_stream_copy_to_uint32_little_endian( ( (pff_free_map_32bit_t *) free_map_data )->back_pointer, back_pointer_offset ); byte_stream_copy_to_uint32_little_endian( ( (pff_free_map_32bit_t *) free_map_data )->checksum, stored_checksum ); } else if( file_type == LIBPFF_FILE_TYPE_64BIT ) { table_data = ( (pff_free_map_64bit_t *) free_map_data )->data; free_map_type = ( (pff_free_map_64bit_t *) free_map_data )->type; free_map_type_copy = ( (pff_free_map_64bit_t *) free_map_data )->type_copy; byte_stream_copy_to_uint32_little_endian( ( (pff_free_map_64bit_t *) free_map_data )->checksum, stored_checksum ); byte_stream_copy_to_uint64_little_endian( ( (pff_free_map_64bit_t *) free_map_data )->back_pointer, back_pointer_offset ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: type\t\t: 0x%02" PRIx8 "\n", function, free_map_type ); libcnotify_printf( "%s: type copy\t: 0x%02" PRIx8 "\n", function, free_map_type_copy ); if( file_type == LIBPFF_FILE_TYPE_32BIT ) { byte_stream_copy_to_uint16_little_endian( ( (pff_free_map_32bit_t *) free_map_data )->signature, value_16bit ); libcnotify_printf( "%s: signature\t: 0x%04" PRIx16 "\n", function, value_16bit ); libcnotify_printf( "%s: back pointer\t: %" PRIu64 "\n", function, back_pointer_offset ); libcnotify_printf( "%s: checksum\t: 0x%" PRIx32 "\n", function, stored_checksum ); } else if( file_type == LIBPFF_FILE_TYPE_64BIT ) { byte_stream_copy_to_uint16_little_endian( ( (pff_free_map_64bit_t *) free_map_data )->signature, value_16bit ); libcnotify_printf( "%s: signature\t: 0x%04" PRIx16 "\n", function, value_16bit ); libcnotify_printf( "%s: checksum\t\t: 0x%" PRIx32 "\n", function, stored_checksum ); libcnotify_printf( "%s: back pointer\t: %" PRIu64 "\n", function, back_pointer_offset ); } libcnotify_printf( "\n" ); } #endif if( libfmapi_checksum_calculate_weak_crc32( &calculated_checksum, table_data, 496, 0, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to calculate weak CRC-32.", function ); goto on_error; } if( stored_checksum != calculated_checksum ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_INPUT, LIBCERROR_INPUT_ERROR_CHECKSUM_MISMATCH, "%s: mismatch in checksum ( %" PRIu32 " != %" PRIu32 " ).", function, stored_checksum, calculated_checksum ); /* TODO implement error tollerance */ goto on_error; } if( free_map_type != free_map_type_copy ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_INPUT, LIBCERROR_INPUT_ERROR_CHECKSUM_MISMATCH, "%s: mismatch in allocation table type ( 0x%02" PRIx8 " != 0x%02" PRIx8 " ).", function, free_map_type, free_map_type_copy ); /* TODO implement error tollerance */ goto on_error; } if( ( free_map_type != LIBPFF_FREE_MAP_TYPE_DATA ) && ( free_map_type != LIBPFF_FREE_MAP_TYPE_PAGE ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, "%s: unsupported allocation table type: 0x%08" PRIx32 "", function, free_map_type ); /* TODO implement error tollerance */ goto on_error; } /* TODO */ if( free_map_type == LIBPFF_FREE_MAP_TYPE_PAGE ) { allocation_block_size = 512; back_pointer_offset -= 0x200; } else if( free_map_type == LIBPFF_FREE_MAP_TYPE_DATA ) { allocation_block_size = 64; } for( table_iterator = 0; table_iterator < 496; table_iterator++ ) { free_map_entry = table_data[ table_iterator ]; for( bit_iterator = 0; bit_iterator < 8; bit_iterator++ ) { if( ( free_map_entry & 0x80 ) == 0 ) { if( unallocated_size == 0 ) { unallocated_offset = back_pointer_offset; } unallocated_size += allocation_block_size; } else if( unallocated_size > 0 ) { result = libcdata_range_list_insert_range( unallocated_block_list, unallocated_offset, unallocated_size, NULL, NULL, NULL, error ); if( result == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, "%s: unable to append unallocated block to list.", function ); goto on_error; } unallocated_size = 0; } free_map_entry <<= 1; back_pointer_offset += allocation_block_size; } } if( unallocated_size > 0 ) { result = libcdata_range_list_insert_range( unallocated_block_list, unallocated_offset, unallocated_size, NULL, NULL, NULL, error ); if( result == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, "%s: unable to append unallocated block to list.", function ); goto on_error; } unallocated_size = 0; } memory_free( free_map_data ); return( 1 ); on_error: if( free_map_data != NULL ) { memory_free( free_map_data ); } return( -1 ); }
/* Reads the unencrypted volume header * Returns 1 if successful or -1 on error */ int libbde_io_handle_read_unencrypted_volume_header( libbde_io_handle_t *io_handle, libbfio_handle_t *file_io_handle, libcerror_error_t **error ) { libbde_sector_data_t *sector_data = NULL; uint8_t *volume_header_data = NULL; static char *function = "libbde_io_handle_read_unencrypted_volume_header"; off64_t volume_header_offset = 0; uint64_t total_number_of_sectors = 0; if( io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid IO handle.", function ); goto on_error; } if( ( io_handle->version == LIBBDE_VERSION_WINDOWS_7 ) || ( io_handle->version == LIBBDE_VERSION_TO_GO ) ) { volume_header_offset = io_handle->volume_header_offset; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: reading unencrypted volume header at offset: %" PRIi64 " (0x%08" PRIx64 ")\n", function, volume_header_offset, volume_header_offset ); } #endif if( libbde_sector_data_initialize( §or_data, io_handle->bytes_per_sector, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create sector data.", function ); goto on_error; } if( libbde_sector_data_read( sector_data, io_handle, file_io_handle, volume_header_offset, io_handle->encryption_context, 0, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read volume header sector data.", function ); goto on_error; } volume_header_data = sector_data->data; if( io_handle->volume_size == 0 ) { if( memory_compare( &( volume_header_data[ 3 ] ), bde_ntfs_volume_file_system_signature, 8 ) == 0 ) { byte_stream_copy_to_uint16_little_endian( ( (bde_volume_header_windows_vista_t *) volume_header_data )->total_number_of_sectors_16bit, total_number_of_sectors ); if( total_number_of_sectors == 0 ) { byte_stream_copy_to_uint32_little_endian( ( (bde_volume_header_windows_vista_t *) volume_header_data )->total_number_of_sectors_32bit, total_number_of_sectors ); } if( total_number_of_sectors == 0 ) { byte_stream_copy_to_uint64_little_endian( ( (bde_volume_header_windows_vista_t *) volume_header_data )->total_number_of_sectors_64bit, total_number_of_sectors ); } if( total_number_of_sectors == 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: missing total number of sectors.", function ); goto on_error; } io_handle->volume_size = total_number_of_sectors; io_handle->volume_size *= io_handle->bytes_per_sector; } else { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine volume size.", function ); goto on_error; } } if( libbde_sector_data_free( §or_data, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free sector data.", function ); goto on_error; } sector_data = NULL; return( 1 ); on_error: if( sector_data != NULL ) { libbde_sector_data_free( §or_data, NULL ); } return( -1 ); }
/* Reads the file information * Returns 1 if successful or -1 on error */ int libscca_file_information_read_data( libscca_file_information_t *file_information, libscca_io_handle_t *io_handle, const uint8_t *data, size_t data_size, libcerror_error_t **error ) { static char *function = "libscca_file_information_read_data"; size_t file_information_data_size = 0; int last_run_time_index = 0; int number_of_last_run_times = 0; #if defined( HAVE_DEBUG_OUTPUT ) uint64_t value_64bit = 0; uint32_t value_32bit = 0; int result = 0; #endif if( file_information == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid file information.", function ); return( -1 ); } if( io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid IO handle.", function ); return( -1 ); } if( ( io_handle->format_version != 17 ) && ( io_handle->format_version != 23 ) && ( io_handle->format_version != 26 ) && ( io_handle->format_version != 30 ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, "%s: invalid IO handle - unsupported format version.", function ); return( -1 ); } if( data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid data.", function ); return( -1 ); } if( data_size < file_information_data_size ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, "%s: invalid data size value too small.", function ); return( -1 ); } if( data_size > (size_t) SSIZE_MAX ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid data size value exceeds maximum.", function ); return( -1 ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: file information data:\n", function ); libcnotify_print_data( data, file_information_data_size, LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); } #endif byte_stream_copy_to_uint32_little_endian( ( (scca_file_information_v17_t *) data )->metrics_array_offset, file_information->metrics_array_offset ); byte_stream_copy_to_uint32_little_endian( ( (scca_file_information_v17_t *) data )->number_of_file_metrics_entries, file_information->number_of_file_metrics_entries ); byte_stream_copy_to_uint32_little_endian( ( (scca_file_information_v17_t *) data )->trace_chain_array_offset, file_information->trace_chain_array_offset ); byte_stream_copy_to_uint32_little_endian( ( (scca_file_information_v17_t *) data )->number_of_trace_chain_array_entries, file_information->number_of_trace_chain_array_entries ); byte_stream_copy_to_uint32_little_endian( ( (scca_file_information_v17_t *) data )->filename_strings_offset, file_information->filename_strings_offset ); byte_stream_copy_to_uint32_little_endian( ( (scca_file_information_v17_t *) data )->filename_strings_size, file_information->filename_strings_size ); byte_stream_copy_to_uint32_little_endian( ( (scca_file_information_v17_t *) data )->volumes_information_offset, file_information->volumes_information_offset ); byte_stream_copy_to_uint32_little_endian( ( (scca_file_information_v17_t *) data )->number_of_volumes, file_information->number_of_volumes ); byte_stream_copy_to_uint32_little_endian( ( (scca_file_information_v17_t *) data )->volumes_information_size, file_information->volumes_information_size ); if( io_handle->format_version < 26 ) { number_of_last_run_times = 1; } else { number_of_last_run_times = 8; } for( last_run_time_index = 0; last_run_time_index < number_of_last_run_times; last_run_time_index++ ) { if( io_handle->format_version == 17 ) { byte_stream_copy_to_uint64_little_endian( &( ( (scca_file_information_v17_t *) data )->last_run_time[ last_run_time_index * 8 ] ), file_information->last_run_time[ last_run_time_index ] ); } else if( io_handle->format_version == 23 ) { byte_stream_copy_to_uint64_little_endian( &( ( (scca_file_information_v23_t *) data )->last_run_time[ last_run_time_index * 8 ] ), file_information->last_run_time[ last_run_time_index ] ); } else if( ( io_handle->format_version == 26 ) || ( io_handle->format_version == 30 ) ) { byte_stream_copy_to_uint64_little_endian( &( ( (scca_file_information_v26_t *) data )->last_run_time[ last_run_time_index * 8 ] ), file_information->last_run_time[ last_run_time_index ] ); } } if( io_handle->format_version == 17 ) { byte_stream_copy_to_uint32_little_endian( ( (scca_file_information_v17_t *) data )->run_count, file_information->run_count ); } else if( io_handle->format_version == 23 ) { byte_stream_copy_to_uint32_little_endian( ( (scca_file_information_v23_t *) data )->run_count, file_information->run_count ); } else if( ( io_handle->format_version == 26 ) || ( io_handle->format_version == 30 ) ) { byte_stream_copy_to_uint32_little_endian( ( (scca_file_information_v26_t *) data )->run_count, file_information->run_count ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: metrics array offset\t\t\t: 0x%08" PRIx32 "\n", function, file_information->metrics_array_offset ); libcnotify_printf( "%s: number of file metrics entries\t\t: %" PRIu32 "\n", function, file_information->number_of_file_metrics_entries ); libcnotify_printf( "%s: trace chain array offset\t\t\t: 0x%08" PRIx32 "\n", function, file_information->trace_chain_array_offset ); libcnotify_printf( "%s: number of trace chain array entries\t\t: %" PRIu32 "\n", function, file_information->number_of_trace_chain_array_entries ); libcnotify_printf( "%s: filename strings offset\t\t\t: 0x%08" PRIx32 "\n", function, file_information->filename_strings_offset ); libcnotify_printf( "%s: filename strings size\t\t\t: %" PRIu32 "\n", function, file_information->filename_strings_size ); libcnotify_printf( "%s: volumes information offset\t\t\t: 0x%08" PRIx32 "\n", function, file_information->volumes_information_offset ); libcnotify_printf( "%s: number of volumes\t\t\t\t: %" PRIu32 "\n", function, file_information->number_of_volumes ); libcnotify_printf( "%s: volumes information size\t\t\t: %" PRIu32 "\n", function, file_information->volumes_information_size ); if( io_handle->format_version == 23 ) { byte_stream_copy_to_uint32_little_endian( ( (scca_file_information_v23_t *) data )->unknown3c, value_32bit ); libcnotify_printf( "%s: unknown3c\t\t\t\t: 0x%08" PRIx64 "\n", function, value_64bit ); } for( last_run_time_index = 0; last_run_time_index < number_of_last_run_times; last_run_time_index++ ) { if( io_handle->format_version == 17 ) { result = libscca_debug_print_filetime_value( function, "last run time:\t\t\t\t", &( ( (scca_file_information_v17_t *) data )->last_run_time[ last_run_time_index * 8 ] ), 8, LIBFDATETIME_ENDIAN_LITTLE, LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS, error ); } else if( io_handle->format_version == 23 ) { result = libscca_debug_print_filetime_value( function, "last run time:\t\t\t\t", &( ( (scca_file_information_v23_t *) data )->last_run_time[ last_run_time_index * 8 ] ), 8, LIBFDATETIME_ENDIAN_LITTLE, LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS, error ); } else if( ( io_handle->format_version == 26 ) || ( io_handle->format_version == 30 ) ) { result = libscca_debug_print_filetime_value( function, "last run time:\t\t\t\t", &( ( (scca_file_information_v26_t *) data )->last_run_time[ last_run_time_index * 8 ] ), 8, LIBFDATETIME_ENDIAN_LITTLE, LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS, error ); } if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, "%s: unable to print filetime value.", function ); return( -1 ); } } libcnotify_printf( "%s: unknown4:\n", function ); if( io_handle->format_version == 17 ) { libcnotify_print_data( ( (scca_file_information_v17_t *) data )->unknown4, 16, 0 ); } else if( io_handle->format_version == 23 ) { libcnotify_print_data( ( (scca_file_information_v23_t *) data )->unknown4, 16, 0 ); } else if( ( io_handle->format_version == 26 ) || ( io_handle->format_version == 30 ) ) { libcnotify_print_data( ( (scca_file_information_v26_t *) data )->unknown4, 16, 0 ); } libcnotify_printf( "%s: run count\t\t\t\t: %" PRIu32 "\n", function, file_information->run_count ); if( io_handle->format_version == 17 ) { byte_stream_copy_to_uint32_little_endian( ( (scca_file_information_v17_t *) data )->unknown5, value_32bit ); libcnotify_printf( "%s: unknown5\t\t\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); libcnotify_printf( "\n" ); } else if( io_handle->format_version == 23 ) { byte_stream_copy_to_uint32_little_endian( ( (scca_file_information_v23_t *) data )->unknown5, value_32bit ); libcnotify_printf( "%s: unknown5\t\t\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); libcnotify_printf( "%s: unknown6:\n", function ); libcnotify_print_data( ( (scca_file_information_v23_t *) data )->unknown6, 80, LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); } else if( ( io_handle->format_version == 26 ) || ( io_handle->format_version == 30 ) ) { byte_stream_copy_to_uint32_little_endian( ( (scca_file_information_v26_t *) data )->unknown5a, value_32bit ); libcnotify_printf( "%s: unknown5a\t\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); byte_stream_copy_to_uint32_little_endian( ( (scca_file_information_v26_t *) data )->unknown5b, value_32bit ); libcnotify_printf( "%s: unknown5b\t\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); libcnotify_printf( "%s: unknown6:\n", function ); libcnotify_print_data( ( (scca_file_information_v26_t *) data )->unknown6, 88, LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); } } #endif return( 1 ); }
/* Reads the memory image information * Returns 1 if successful or -1 on error */ int libhibr_io_handle_read_memory_image_information( libhibr_io_handle_t *io_handle, libbfio_handle_t *file_io_handle, libcerror_error_t **error ) { uint8_t *page_data = NULL; static char *function = "libhibr_io_handle_read_memory_image_information"; ssize_t read_count = 0; uint64_t page_size = 0; uint32_t memory_image_information_data_size = 0; #if defined( HAVE_DEBUG_OUTPUT ) libcstring_system_character_t filetime_string[ 32 ]; libfdatetime_filetime_t *filetime = NULL; uint64_t value_64bit = 0; uint32_t value_32bit = 0; uint8_t value_8bit = 0; int result = 0; #endif if( io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid IO handle.", function ); return( -1 ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: reading memory image information at offset: 0.\n", function ); } #endif if( libbfio_handle_seek_offset( file_io_handle, 0, SEEK_SET, error ) == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_SEEK_FAILED, "%s: unable to seek memory image information offset: 0.", function ); goto on_error; } page_data = (uint8_t *) memory_allocate( sizeof( uint8_t ) * io_handle->page_size ); if( page_data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create memory image information data.", function ); goto on_error; } read_count = libbfio_handle_read_buffer( file_io_handle, page_data, io_handle->page_size, error ); if( read_count != (ssize_t) io_handle->page_size ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read memory image information.", function ); goto on_error; } /* TODO do empty page test */ byte_stream_copy_to_uint32_little_endian( ( (hibr_memory_image_information_t *) page_data )->size, memory_image_information_data_size ); if( memory_image_information_data_size > 0 ) { #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: memory image information data:\n", function ); libcnotify_print_data( page_data, (size_t) memory_image_information_data_size, 0 ); } #endif /* TODO if( memory_compare( ( (hibr_memory_image_information_t *) page_data )->signature, hibr_file_signature, 8 ) != 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, "%s: unsupported file signature.", function ); goto on_error; } */ if( memory_image_information_data_size == sizeof( hibr_memory_image_information_winxp_32bit_t ) ) { io_handle->file_type = LIBHIBR_FILE_TYPE_WINDOWS_XP_32BIT; } else if( memory_image_information_data_size == sizeof( hibr_memory_image_information_winxp_64bit_t ) ) { io_handle->file_type = LIBHIBR_FILE_TYPE_WINDOWS_XP_64BIT; } else if( memory_image_information_data_size == sizeof( hibr_memory_image_information_win7_32bit_t ) ) { io_handle->file_type = LIBHIBR_FILE_TYPE_WINDOWS_7_32BIT; } else if( memory_image_information_data_size == sizeof( hibr_memory_image_information_win7_64bit_t ) ) { io_handle->file_type = LIBHIBR_FILE_TYPE_WINDOWS_7_64BIT; } if( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_32BIT ) { byte_stream_copy_to_uint32_little_endian( ( (hibr_memory_image_information_winxp_32bit_t *) page_data )->page_size, page_size ); } else if( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_64BIT ) { byte_stream_copy_to_uint32_little_endian( ( (hibr_memory_image_information_winxp_64bit_t *) page_data )->page_size, page_size ); } else if( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_7_32BIT ) { byte_stream_copy_to_uint32_little_endian( ( (hibr_memory_image_information_win7_32bit_t *) page_data )->page_size, page_size ); } else if( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_7_64BIT ) { byte_stream_copy_to_uint32_little_endian( ( (hibr_memory_image_information_win7_64bit_t *) page_data )->page_size, page_size ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: signature\t\t: %c%c%c%c\n", function, ( (hibr_memory_image_information_t *) page_data )->signature[ 0 ], ( (hibr_memory_image_information_t *) page_data )->signature[ 1 ], ( (hibr_memory_image_information_t *) page_data )->signature[ 2 ], ( (hibr_memory_image_information_t *) page_data )->signature[ 3 ] ); if( ( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_32BIT ) || ( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_64BIT ) ) { byte_stream_copy_to_uint32_little_endian( ( (hibr_memory_image_information_winxp_32bit_t *) page_data )->version, value_32bit ); libcnotify_printf( "%s: version\t\t: %" PRIu32 "\n", function, value_32bit ); } else if( ( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_7_32BIT ) || ( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_7_64BIT ) ) { byte_stream_copy_to_uint32_little_endian( ( (hibr_memory_image_information_win7_32bit_t *) page_data )->image_type, value_32bit ); libcnotify_printf( "%s: image type\t\t: %" PRIu32 "\n", function, value_32bit ); } byte_stream_copy_to_uint32_little_endian( ( (hibr_memory_image_information_t *) page_data )->checksum, value_32bit ); libcnotify_printf( "%s: checksum\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); libcnotify_printf( "%s: size\t\t\t: %" PRIu32 "\n", function, memory_image_information_data_size ); if( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_32BIT ) { byte_stream_copy_to_uint32_little_endian( ( (hibr_memory_image_information_winxp_32bit_t *) page_data )->page_number, value_64bit ); } else if( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_64BIT ) { byte_stream_copy_to_uint64_little_endian( ( (hibr_memory_image_information_winxp_64bit_t *) page_data )->page_number, value_64bit ); } else if( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_7_32BIT ) { byte_stream_copy_to_uint32_little_endian( ( (hibr_memory_image_information_win7_32bit_t *) page_data )->page_number, value_64bit ); } else if( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_7_64BIT ) { byte_stream_copy_to_uint64_little_endian( ( (hibr_memory_image_information_win7_64bit_t *) page_data )->page_number, value_64bit ); } libcnotify_printf( "%s: page number\t\t: %" PRIu64 "\n", function, value_64bit ); libcnotify_printf( "%s: page size\t\t: %" PRIu64 "\n", function, page_size ); if( ( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_32BIT ) || ( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_64BIT ) ) { if( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_32BIT ) { byte_stream_copy_to_uint32_little_endian( ( (hibr_memory_image_information_winxp_32bit_t *) page_data )->image_type, value_32bit ); } else { byte_stream_copy_to_uint32_little_endian( ( (hibr_memory_image_information_winxp_64bit_t *) page_data )->image_type, value_32bit ); } libcnotify_printf( "%s: image type\t\t: %" PRIu32 "\n", function, value_32bit ); } if( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_32BIT ) { byte_stream_copy_to_uint32_little_endian( ( (hibr_memory_image_information_winxp_32bit_t *) page_data )->unknown1, value_32bit ); libcnotify_printf( "%s: unknown1\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); } if( ( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_32BIT ) || ( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_64BIT ) ) { byte_stream_copy_to_uint64_little_endian( ( (hibr_memory_image_information_winxp_32bit_t *) page_data )->system_time, value_64bit ); } else if( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_7_32BIT ) { byte_stream_copy_to_uint64_little_endian( ( (hibr_memory_image_information_win7_32bit_t *) page_data )->system_time, value_64bit ); } else if( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_7_64BIT ) { byte_stream_copy_to_uint64_little_endian( ( (hibr_memory_image_information_win7_64bit_t *) page_data )->system_time, value_64bit ); } if( libfdatetime_filetime_initialize( &filetime, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create filetime.", function ); goto on_error; } if( libfdatetime_filetime_copy_from_64bit( filetime, value_64bit, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy byte stream to filetime.", function ); goto on_error; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libfdatetime_filetime_copy_to_utf16_string( filetime, (uint16_t *) filetime_string, 32, LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS, error ); #else result = libfdatetime_filetime_copy_to_utf8_string( filetime, (uint8_t *) filetime_string, 32, LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy filetime to string.", function ); goto on_error; } libcnotify_printf( "%s: system time\t\t: %" PRIs_LIBCSTRING_SYSTEM " UTC\n", function, filetime_string ); if( libfdatetime_filetime_free( &filetime, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free filetime.", function ); goto on_error; } if( ( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_32BIT ) || ( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_64BIT ) ) { byte_stream_copy_to_uint64_little_endian( ( (hibr_memory_image_information_winxp_32bit_t *) page_data )->interrupt_time, value_64bit ); } libcnotify_printf( "%s: interrupt time\t\t: 0x%08" PRIx64 "\n", function, value_64bit ); if( ( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_32BIT ) || ( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_64BIT ) ) { byte_stream_copy_to_uint32_little_endian( ( (hibr_memory_image_information_winxp_32bit_t *) page_data )->feature_flags, value_32bit ); } libcnotify_printf( "%s: feature flags\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); if( ( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_32BIT ) || ( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_64BIT ) ) { value_8bit = ( (hibr_memory_image_information_winxp_32bit_t *) page_data )->hibernation_flags; } libcnotify_printf( "%s: hibernation flags\t: 0x%02" PRIx8 "\n", function, value_8bit ); if( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_32BIT ) { libcnotify_printf( "%s: unknown2:\n", function ); libcnotify_print_data( ( (hibr_memory_image_information_winxp_32bit_t *) page_data )->unknown2, 3, 0 ); } else if( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_64BIT ) { libcnotify_printf( "%s: unknown1:\n", function ); libcnotify_print_data( ( (hibr_memory_image_information_winxp_64bit_t *) page_data )->unknown1, 3, 0 ); byte_stream_copy_to_uint32_little_endian( ( (hibr_memory_image_information_winxp_64bit_t *) page_data )->unknown2, value_32bit ); libcnotify_printf( "%s: unknown2\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); } if( ( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_32BIT ) || ( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_64BIT ) ) { byte_stream_copy_to_uint32_little_endian( ( (hibr_memory_image_information_winxp_32bit_t *) page_data )->unknown3, value_32bit ); } libcnotify_printf( "%s: unknown3\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); if( ( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_32BIT ) || ( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_64BIT ) ) { byte_stream_copy_to_uint32_little_endian( ( (hibr_memory_image_information_winxp_32bit_t *) page_data )->unknown4, value_32bit ); } libcnotify_printf( "%s: unknown4\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); if( ( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_32BIT ) || ( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_64BIT ) ) { byte_stream_copy_to_uint64_little_endian( ( (hibr_memory_image_information_winxp_32bit_t *) page_data )->unknown5, value_64bit ); } libcnotify_printf( "%s: unknown5\t\t: 0x%08" PRIx64 "\n", function, value_64bit ); if( ( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_32BIT ) || ( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_64BIT ) ) { byte_stream_copy_to_uint32_little_endian( ( (hibr_memory_image_information_winxp_32bit_t *) page_data )->number_of_free_pages, value_32bit ); } libcnotify_printf( "%s: number of free pages\t: %" PRIu32 "\n", function, value_32bit ); if( ( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_32BIT ) || ( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_64BIT ) ) { byte_stream_copy_to_uint32_little_endian( ( (hibr_memory_image_information_winxp_32bit_t *) page_data )->unknown6, value_32bit ); } libcnotify_printf( "%s: unknown6\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); if( ( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_32BIT ) || ( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_64BIT ) ) { byte_stream_copy_to_uint32_little_endian( ( (hibr_memory_image_information_winxp_32bit_t *) page_data )->unknown7, value_32bit ); } libcnotify_printf( "%s: unknown7\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); if( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_64BIT ) { byte_stream_copy_to_uint32_little_endian( ( (hibr_memory_image_information_winxp_64bit_t *) page_data )->unknown8, value_32bit ); libcnotify_printf( "%s: unknown8\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); } if( ( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_32BIT ) || ( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_64BIT ) ) { byte_stream_copy_to_uint32_little_endian( ( (hibr_memory_image_information_winxp_32bit_t *) page_data )->number_of_pages, value_32bit ); } libcnotify_printf( "%s: number of pages\t: %" PRIu32 "\n", function, value_32bit ); if( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_32BIT ) { byte_stream_copy_to_uint32_little_endian( ( (hibr_memory_image_information_winxp_32bit_t *) page_data )->unknown8, value_32bit ); libcnotify_printf( "%s: unknown8\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); byte_stream_copy_to_uint32_little_endian( ( (hibr_memory_image_information_winxp_32bit_t *) page_data )->unknown9, value_32bit ); libcnotify_printf( "%s: unknown9\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); libcnotify_printf( "%s: unknown10:\n", function ); libcnotify_print_data( ( (hibr_memory_image_information_winxp_32bit_t *) page_data )->unknown10, 72, 0 ); } else if( io_handle->file_type == LIBHIBR_FILE_TYPE_WINDOWS_XP_64BIT ) { byte_stream_copy_to_uint32_little_endian( ( (hibr_memory_image_information_winxp_64bit_t *) page_data )->unknown8, value_32bit ); libcnotify_printf( "%s: unknown8\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); byte_stream_copy_to_uint32_little_endian( ( (hibr_memory_image_information_winxp_64bit_t *) page_data )->unknown9, value_32bit ); libcnotify_printf( "%s: unknown9\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); libcnotify_printf( "%s: unknown10:\n", function ); libcnotify_print_data( ( (hibr_memory_image_information_winxp_64bit_t *) page_data )->unknown10, 72, 0 ); } else { libcnotify_printf( "\n" ); } } #endif } #if defined( HAVE_DEBUG_OUTPUT ) else if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: page data:\n", function ); libcnotify_print_data( page_data, io_handle->page_size, LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); } #endif /* TODO print trailing data */ /* TODO page size sanity check */ io_handle->page_size = (size_t) page_size; /* TODO memory blocks page number sanity check */ memory_free( page_data ); page_data = NULL; return( 1 ); on_error: #if defined( HAVE_DEBUG_OUTPUT ) if( filetime != NULL ) { libfdatetime_filetime_free( &filetime, NULL ); } #endif if( page_data != NULL ) { memory_free( page_data ); } return( -1 ); }
/* Reads the store block * Returns 1 if successful or -1 on error */ int libvshadow_store_block_read( libvshadow_store_block_t *store_block, libbfio_handle_t *file_io_handle, off64_t file_offset, libcerror_error_t **error ) { static char *function = "libvshadow_store_block_read"; ssize_t read_count = 0; #if defined( HAVE_DEBUG_OUTPUT ) libcstring_system_character_t guid_string[ 48 ]; libfguid_identifier_t *guid = NULL; uint64_t value_64bit = 0; int result = 0; #endif if( store_block == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid store block.", function ); return( -1 ); } if( store_block->data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid store block - missing data.", function ); return( -1 ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: reading store block at offset: %" PRIi64 " (0x%08" PRIx64 ")\n", function, file_offset, file_offset ); } #endif if( libbfio_handle_seek_offset( file_io_handle, file_offset, SEEK_SET, error ) == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_SEEK_FAILED, "%s: unable to seek store block offset: %" PRIi64 ".", function, file_offset ); return( -1 ); } read_count = libbfio_handle_read_buffer( file_io_handle, store_block->data, store_block->data_size, error ); if( read_count != (ssize_t) store_block->data_size ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read block data.", function ); return( -1 ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: store block header:\n", function ); libcnotify_print_data( store_block->data, sizeof( vshadow_store_block_header_t ), LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); } #endif if( memory_compare( ( (vshadow_store_block_header_t *) store_block->data )->identifier, vshadow_vss_identifier, 8 ) != 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, "%s: invalid store block list header identifier.", function ); return( -1 ); } byte_stream_copy_to_uint32_little_endian( ( (vshadow_store_block_header_t *) store_block->data )->version, store_block->version ); byte_stream_copy_to_uint32_little_endian( ( (vshadow_store_block_header_t *) store_block->data )->record_type, store_block->record_type ); byte_stream_copy_to_uint64_little_endian( ( (vshadow_store_block_header_t *) store_block->data )->relative_offset, store_block->relative_offset ); byte_stream_copy_to_uint64_little_endian( ( (vshadow_store_block_header_t *) store_block->data )->offset, store_block->offset ); byte_stream_copy_to_uint64_little_endian( ( (vshadow_store_block_header_t *) store_block->data )->next_offset, store_block->next_offset ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { 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 ); return( -1 ); } if( libfguid_identifier_copy_from_byte_stream( guid, ( (vshadow_store_block_header_t *) store_block->data )->identifier, 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 ); return( -1 ); } #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 ); return( -1 ); } libcnotify_printf( "%s: identifier\t\t\t\t\t: %" PRIs_LIBCSTRING_SYSTEM "\n", function, guid_string ); libcnotify_printf( "%s: version\t\t\t\t\t: %" PRIu32 "\n", function, store_block->version ); libcnotify_printf( "%s: record type\t\t\t\t: %" PRIu32 "\n", function, store_block->record_type ); libcnotify_printf( "%s: relative offset\t\t\t\t: 0x%08" PRIx64 "\n", function, store_block->relative_offset ); libcnotify_printf( "%s: offset\t\t\t\t\t: 0x%08" PRIx64 "\n", function, store_block->offset ); libcnotify_printf( "%s: next offset\t\t\t\t: 0x%08" PRIx64 "\n", function, store_block->next_offset ); byte_stream_copy_to_uint64_little_endian( ( (vshadow_store_block_header_t *) store_block->data )->unknown1, value_64bit ); libcnotify_printf( "%s: unknown1\t\t\t\t\t: %" PRIu64 "\n", function, value_64bit ); libcnotify_printf( "%s: unknown2:\n", function ); libcnotify_print_data( ( (vshadow_store_block_header_t *) store_block->data )->unknown2, 72, LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); 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 ); return( -1 ); } } #endif if( store_block->version != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, "%s: unsupported version: %" PRIu32 ".", function, store_block->version ); return( -1 ); } return( 1 ); }
/* Reads a physical volume label * Returns 1 if successful, 0 if not found or -1 on error */ int libvslvm_physical_volume_read_label( libvslvm_physical_volume_t *physical_volume, libbfio_pool_t *file_io_pool, int file_io_pool_entry, off64_t file_offset, libcerror_error_t **error ) { vslvm_data_area_descriptor_t data_area_descriptor_data; vslvm_physical_volume_label_header_t physical_volume_label_header; vslvm_physical_volume_header_t physical_volume_header; libvslvm_data_area_descriptor_t *data_area_descriptor = NULL; libvslvm_internal_physical_volume_t *internal_physical_volume = NULL; static char *function = "libvslvm_physical_volume_read_label"; ssize_t read_count = 0; uint64_t offset = 0; uint64_t size = 0; int entry_index = 0; int result = 0; #if defined( HAVE_DEBUG_OUTPUT ) uint64_t value_64bit = 0; uint32_t value_32bit = 0; #endif if( physical_volume == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid physical volume.", function ); return( -1 ); } internal_physical_volume = (libvslvm_internal_physical_volume_t *) physical_volume; #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: reading physical volume label at offset: %" PRIi64 "\n", function, file_offset ); } #endif if( libbfio_pool_seek_offset( file_io_pool, file_io_pool_entry, file_offset, SEEK_SET, error ) == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_SEEK_FAILED, "%s: unable to seek offset: %" PRIi64 " (0x%08" PRIx64 ").", function, file_offset, file_offset ); goto on_error; } read_count = libbfio_pool_read_buffer( file_io_pool, file_io_pool_entry, (uint8_t *) &physical_volume_label_header, sizeof( vslvm_physical_volume_label_header_t ), error ); if( read_count != (ssize_t) sizeof( vslvm_physical_volume_label_header_t ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read physical volume label header.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: physical volume label header data:\n", function ); libcnotify_print_data( (uint8_t *) &physical_volume_label_header, sizeof( vslvm_physical_volume_label_header_t ), 0 ); } #endif if( memory_compare( physical_volume_label_header.signature, vslvm_physical_volume_label_signature, 8 ) != 0 ) { return( 0 ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: signature\t\t\t\t: %c%c%c%c%c%c%c%c\n", function, physical_volume_label_header.signature[ 0 ], physical_volume_label_header.signature[ 1 ], physical_volume_label_header.signature[ 2 ], physical_volume_label_header.signature[ 3 ], physical_volume_label_header.signature[ 4 ], physical_volume_label_header.signature[ 5 ], physical_volume_label_header.signature[ 6 ], physical_volume_label_header.signature[ 7 ] ); byte_stream_copy_to_uint64_little_endian( physical_volume_label_header.sector_number, value_64bit ); libcnotify_printf( "%s: sector number\t\t\t: %" PRIu64 "\n", function, value_64bit ); byte_stream_copy_to_uint32_little_endian( physical_volume_label_header.checksum, value_32bit ); libcnotify_printf( "%s: checksum\t\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); byte_stream_copy_to_uint32_little_endian( physical_volume_label_header.data_offset, value_32bit ); libcnotify_printf( "%s: data offset\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); libcnotify_printf( "%s: type indicator\t\t\t: %c%c%c%c%c%c%c%c\n", function, physical_volume_label_header.type_indicator[ 0 ], physical_volume_label_header.type_indicator[ 1 ], physical_volume_label_header.type_indicator[ 2 ], physical_volume_label_header.type_indicator[ 3 ], physical_volume_label_header.type_indicator[ 4 ], physical_volume_label_header.type_indicator[ 5 ], physical_volume_label_header.type_indicator[ 6 ], physical_volume_label_header.type_indicator[ 7 ] ); libcnotify_printf( "\n" ); } #endif /* TODO calculate checksum */ read_count = libbfio_pool_read_buffer( file_io_pool, file_io_pool_entry, (uint8_t *) &physical_volume_header, sizeof( vslvm_physical_volume_header_t ), error ); if( read_count != (ssize_t) sizeof( vslvm_physical_volume_header_t ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read physical volume header.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: physical volume header data:\n", function ); libcnotify_print_data( (uint8_t *) &physical_volume_header, sizeof( vslvm_physical_volume_header_t ), 0 ); } #endif #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: identifier\t\t\t\t: %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n", function, physical_volume_header.identifier[ 0 ], physical_volume_header.identifier[ 1 ], physical_volume_header.identifier[ 2 ], physical_volume_header.identifier[ 3 ], physical_volume_header.identifier[ 4 ], physical_volume_header.identifier[ 5 ], physical_volume_header.identifier[ 6 ], physical_volume_header.identifier[ 7 ], physical_volume_header.identifier[ 8 ], physical_volume_header.identifier[ 9 ], physical_volume_header.identifier[ 10 ], physical_volume_header.identifier[ 11 ], physical_volume_header.identifier[ 12 ], physical_volume_header.identifier[ 13 ], physical_volume_header.identifier[ 14 ], physical_volume_header.identifier[ 15 ], physical_volume_header.identifier[ 16 ], physical_volume_header.identifier[ 17 ], physical_volume_header.identifier[ 18 ], physical_volume_header.identifier[ 19 ], physical_volume_header.identifier[ 20 ], physical_volume_header.identifier[ 21 ], physical_volume_header.identifier[ 22 ], physical_volume_header.identifier[ 23 ], physical_volume_header.identifier[ 24 ], physical_volume_header.identifier[ 25 ], physical_volume_header.identifier[ 26 ], physical_volume_header.identifier[ 27 ], physical_volume_header.identifier[ 28 ], physical_volume_header.identifier[ 29 ], physical_volume_header.identifier[ 30 ], physical_volume_header.identifier[ 31 ] ); byte_stream_copy_to_uint64_little_endian( physical_volume_header.volume_size, value_64bit ); libcnotify_printf( "%s: volume size\t\t\t: %" PRIu64 "\n", function, value_64bit ); libcnotify_printf( "\n" ); } #endif do { read_count = libbfio_pool_read_buffer( file_io_pool, file_io_pool_entry, (uint8_t *) &data_area_descriptor_data, sizeof( vslvm_data_area_descriptor_t ), error ); if( read_count != (ssize_t) sizeof( vslvm_data_area_descriptor_t ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read data area descriptor.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: data area descriptor data:\n", function ); libcnotify_print_data( (uint8_t *) &data_area_descriptor_data, sizeof( vslvm_data_area_descriptor_t ), 0 ); } #endif result = memory_compare( (uint8_t *) &data_area_descriptor_data, vslvm_empty_data_area_descriptor, sizeof( vslvm_data_area_descriptor_t ) ); if( result != 0 ) { byte_stream_copy_to_uint64_little_endian( data_area_descriptor_data.offset, offset ); byte_stream_copy_to_uint64_little_endian( data_area_descriptor_data.size, size ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: data area offset\t\t\t: 0x%08" PRIx64 "\n", function, offset ); libcnotify_printf( "%s: data area size\t\t\t: %" PRIu64 "\n", function, size ); libcnotify_printf( "\n" ); } #endif if( libvslvm_data_area_descriptor_initialize( &data_area_descriptor, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create data area descriptor.", function ); goto on_error; } if( libvslvm_data_area_descriptor_set( data_area_descriptor, (off64_t) offset, (size64_t) size, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set data area descriptor.", function ); goto on_error; } if( libcdata_array_append_entry( internal_physical_volume->data_area_descriptors_array, &entry_index, (intptr_t *) data_area_descriptor, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, "%s: unable to append entry to data area descriptors array.", function ); goto on_error; } data_area_descriptor = NULL; } } while( result != 0 ); do { read_count = libbfio_pool_read_buffer( file_io_pool, file_io_pool_entry, (uint8_t *) &data_area_descriptor_data, sizeof( vslvm_data_area_descriptor_t ), error ); if( read_count != (ssize_t) sizeof( vslvm_data_area_descriptor_t ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read metadata area descriptor.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: metadata area descriptor data:\n", function ); libcnotify_print_data( (uint8_t *) &data_area_descriptor_data, sizeof( vslvm_data_area_descriptor_t ), 0 ); } #endif result = memory_compare( (uint8_t *) &data_area_descriptor_data, vslvm_empty_data_area_descriptor, sizeof( vslvm_data_area_descriptor_t ) ); if( result != 0 ) { byte_stream_copy_to_uint64_little_endian( data_area_descriptor_data.offset, offset ); byte_stream_copy_to_uint64_little_endian( data_area_descriptor_data.size, size ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: metadata area offset\t\t: 0x%08" PRIx64 "\n", function, offset ); libcnotify_printf( "%s: metadata area size\t\t\t: %" PRIu64 "\n", function, size ); libcnotify_printf( "\n" ); } #endif if( libvslvm_data_area_descriptor_initialize( &data_area_descriptor, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create data area descriptor.", function ); goto on_error; } if( libvslvm_data_area_descriptor_set( data_area_descriptor, (off64_t) offset, (size64_t) size, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set data area descriptor.", function ); goto on_error; } if( libcdata_array_append_entry( internal_physical_volume->metadata_area_descriptors_array, &entry_index, (intptr_t *) data_area_descriptor, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, "%s: unable to append entry to metadata area descriptors array.", function ); goto on_error; } data_area_descriptor = NULL; } } while( result != 0 ); return( 1 ); on_error: if( data_area_descriptor != NULL ) { libvslvm_data_area_descriptor_free( &data_area_descriptor, NULL ); } libcdata_array_empty( internal_physical_volume->metadata_area_descriptors_array, (int (*)(intptr_t **, libcerror_error_t **)) &libvslvm_data_area_descriptor_free, NULL ); libcdata_array_empty( internal_physical_volume->data_area_descriptors_array, (int (*)(intptr_t **, libcerror_error_t **)) &libvslvm_data_area_descriptor_free, NULL ); return( -1 ); }
/* Reads the level 1 metadata * Returns 1 if successful or -1 on error */ int libfsrefs_level1_metadata_read( libfsrefs_level1_metadata_t *level1_metadata, libfsrefs_io_handle_t *io_handle, libbfio_handle_t *file_io_handle, off64_t file_offset, libcerror_error_t **error ) { libfsrefs_block_descriptor_t *block_descriptor = NULL; libfsrefs_metadata_block_t *metadata_block = NULL; static char *function = "libfsrefs_level1_metadata_read"; size_t metadata_block_data_offset = 0; uint32_t entry_index = 0; uint32_t entry_offset = 0; uint32_t number_of_entries = 0; int array_entry_index = 0; #if defined( HAVE_DEBUG_OUTPUT ) uint64_t value_64bit = 0; uint32_t value_32bit = 0; uint16_t value_16bit = 0; #endif if( level1_metadata == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid level 1 metadata.", function ); return( -1 ); } if( libfsrefs_metadata_block_initialize( &metadata_block, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create metadata block.", function ); goto on_error; } if( libfsrefs_metadata_block_read( metadata_block, io_handle, file_io_handle, file_offset, 1, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read metadata block.", function ); goto on_error; } if( metadata_block->data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid metadata block - missing data.", function ); goto on_error; } level1_metadata->sequence_number = metadata_block->sequence_number; /* TODO add structures */ byte_stream_copy_to_uint32_little_endian( &( metadata_block->data[ 56 ] ), entry_offset ); byte_stream_copy_to_uint32_little_endian( &( metadata_block->data[ 88 ] ), number_of_entries ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { byte_stream_copy_to_uint32_little_endian( &( metadata_block->data[ 48 ] ), value_32bit ); libcnotify_printf( "%s: unknown1\t\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); byte_stream_copy_to_uint16_little_endian( &( metadata_block->data[ 52 ] ), value_16bit ); libcnotify_printf( "%s: unknown2\t\t\t\t: 0x%04" PRIx16 "\n", function, value_16bit ); byte_stream_copy_to_uint16_little_endian( &( metadata_block->data[ 54 ] ), value_16bit ); libcnotify_printf( "%s: unknown3\t\t\t\t: 0x%04" PRIx16 "\n", function, value_16bit ); libcnotify_printf( "%s: unknown4 offset\t\t\t\t: 0x%08" PRIx32 "\n", function, entry_offset ); byte_stream_copy_to_uint32_little_endian( &( metadata_block->data[ 60 ] ), value_32bit ); libcnotify_printf( "%s: table entry size\t\t\t: %" PRIu32 "\n", function, value_32bit ); byte_stream_copy_to_uint64_little_endian( &( metadata_block->data[ 64 ] ), value_64bit ); libcnotify_printf( "%s: sequence number\t\t\t\t: %" PRIu64 "\n", function, value_64bit ); byte_stream_copy_to_uint32_little_endian( &( metadata_block->data[ 72 ] ), value_32bit ); libcnotify_printf( "%s: unknown5\t\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); byte_stream_copy_to_uint32_little_endian( &( metadata_block->data[ 76 ] ), value_32bit ); libcnotify_printf( "%s: unknown6\t\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); libcnotify_printf( "%s: unknown7:\n", function ); libcnotify_print_data( &( metadata_block->data[ 80 ] ), 8, LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); libcnotify_printf( "%s: number of table entries\t\t\t: %" PRIu32 "\n", function, number_of_entries ); libcnotify_printf( "%s: table entry offsets data:\n", function ); libcnotify_print_data( &( metadata_block->data[ 92 ] ), 4 * number_of_entries, LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); } #endif /* TODO check if entry offset is in bounds */ #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { byte_stream_copy_to_uint64_little_endian( &( metadata_block->data[ entry_offset ] ), value_64bit ); libcnotify_printf( "%s: self entry: block number\t\t: %" PRIu64 "\n", function, value_64bit ); byte_stream_copy_to_uint64_little_endian( &( metadata_block->data[ entry_offset + 8 ] ), value_64bit ); libcnotify_printf( "%s: self entry: unknown1\t\t\t: 0x%08" PRIx64 "\n", function, value_64bit ); byte_stream_copy_to_uint64_little_endian( &( metadata_block->data[ entry_offset + 16 ] ), value_64bit ); libcnotify_printf( "%s: self entry: checksum\t\t\t: 0x%08" PRIx64 "\n", function, value_64bit ); libcnotify_printf( "\n" ); } #endif metadata_block_data_offset = 92; for( entry_index = 0; entry_index < number_of_entries; entry_index++ ) { byte_stream_copy_to_uint32_little_endian( &( metadata_block->data[ metadata_block_data_offset ] ), entry_offset ); metadata_block_data_offset += 4; #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: entry: %02" PRIu32 " offset\t\t\t: 0x%08" PRIx32 "\n", function, entry_index, entry_offset ); } #endif if( libfsrefs_block_descriptor_initialize( &block_descriptor, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create block descriptor.", function ); goto on_error; } /* TODO check if entry offset is in bounds */ byte_stream_copy_to_uint64_little_endian( &( metadata_block->data[ entry_offset ] ), block_descriptor->block_number ); byte_stream_copy_to_uint64_little_endian( &( metadata_block->data[ entry_offset + 8 ] ), block_descriptor->unknown ); byte_stream_copy_to_uint64_little_endian( &( metadata_block->data[ entry_offset + 16 ] ), block_descriptor->checksum ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: entry: %02" PRIu32 " block number\t\t\t: %" PRIu64 "\n", function, entry_index, block_descriptor->block_number ); libcnotify_printf( "%s: entry: %02" PRIu32 " unknown1\t\t\t: 0x%08" PRIx64 "\n", function, entry_index, block_descriptor->unknown ); libcnotify_printf( "%s: entry: %02" PRIu32 " checksum\t\t\t: 0x%08" PRIx64 "\n", function, entry_index, block_descriptor->checksum ); libcnotify_printf( "\n" ); } #endif if( libcdata_array_append_entry( level1_metadata->level2_metadata_block_descriptors_array, &array_entry_index, (intptr_t *) block_descriptor, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, "%s: unable to append block descriptor to array.", function ); goto on_error; } block_descriptor = NULL; } if( libfsrefs_metadata_block_free( &metadata_block, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free metadata block.", function ); goto on_error; } return( 1 ); on_error: if( block_descriptor != NULL ) { libfsrefs_block_descriptor_free( &block_descriptor, NULL ); } if( metadata_block != NULL ) { libfsrefs_metadata_block_free( &metadata_block, NULL ); } return( -1 ); }
/* Reads the metadata area * Returns 1 if successful or -1 on error */ int libvslvm_metadata_area_read( libvslvm_metadata_area_t *metadata_area, libbfio_handle_t *file_io_handle, off64_t file_offset, libcerror_error_t **error ) { vslvm_raw_location_descriptor_t raw_location_descriptor_data; vslvm_metadata_area_header_t metadata_area_header; libvslvm_raw_location_descriptor_t *raw_location_descriptor = NULL; static char *function = "libvslvm_metadata_area_read"; ssize_t read_count = 0; uint64_t offset = 0; uint64_t size = 0; uint32_t checksum = 0; uint32_t flags = 0; int entry_index = 0; int result = 0; #if defined( HAVE_DEBUG_OUTPUT ) uint64_t value_64bit = 0; uint32_t value_32bit = 0; #endif if( metadata_area == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid metadata area.", function ); return( -1 ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: reading metadata area at offset: %" PRIi64 "\n", function, file_offset ); } #endif if( libbfio_handle_seek_offset( file_io_handle, file_offset, SEEK_SET, error ) == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_SEEK_FAILED, "%s: unable to seek offset: %" PRIi64 " (0x%08" PRIx64 ").", function, file_offset, file_offset ); goto on_error; } read_count = libbfio_handle_read_buffer( file_io_handle, (uint8_t *) &metadata_area_header, sizeof( vslvm_metadata_area_header_t ), error ); if( read_count != (ssize_t) sizeof( vslvm_metadata_area_header_t ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read metadata area header.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: metadata area header data:\n", function ); libcnotify_print_data( (uint8_t *) &metadata_area_header, sizeof( vslvm_metadata_area_header_t ), 0 ); } #endif if( memory_compare( metadata_area_header.signature, vslvm_metadata_area_signature, 8 ) != 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, "%s: unsupported metadata area signature.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { byte_stream_copy_to_uint32_little_endian( metadata_area_header.checksum, value_32bit ); libcnotify_printf( "%s: checksum\t\t\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); libcnotify_printf( "%s: signature\t\t\t\t\t: %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n", function, metadata_area_header.signature[ 0 ], metadata_area_header.signature[ 1 ], metadata_area_header.signature[ 2 ], metadata_area_header.signature[ 3 ], metadata_area_header.signature[ 4 ], metadata_area_header.signature[ 5 ], metadata_area_header.signature[ 6 ], metadata_area_header.signature[ 7 ], metadata_area_header.signature[ 8 ], metadata_area_header.signature[ 9 ], metadata_area_header.signature[ 10 ], metadata_area_header.signature[ 11 ], metadata_area_header.signature[ 12 ], metadata_area_header.signature[ 13 ], metadata_area_header.signature[ 14 ], metadata_area_header.signature[ 15 ] ); byte_stream_copy_to_uint32_little_endian( metadata_area_header.version, value_32bit ); libcnotify_printf( "%s: version\t\t\t\t\t: %" PRIu32 "\n", function, value_32bit ); byte_stream_copy_to_uint64_little_endian( metadata_area_header.data_offset, value_64bit ); libcnotify_printf( "%s: data offset\t\t\t\t: 0x%08" PRIx64 "\n", function, value_64bit ); byte_stream_copy_to_uint64_little_endian( metadata_area_header.data_size, value_64bit ); libcnotify_printf( "%s: data size\t\t\t\t\t: %" PRIu64 "\n", function, value_64bit ); libcnotify_printf( "\n" ); } #endif /* TODO calculate checksum */ do { read_count = libbfio_handle_read_buffer( file_io_handle, (uint8_t *) &raw_location_descriptor_data, sizeof( vslvm_raw_location_descriptor_t ), error ); if( read_count != (ssize_t) sizeof( vslvm_raw_location_descriptor_t ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read raw location descriptor.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: raw location descriptor data:\n", function ); libcnotify_print_data( (uint8_t *) &raw_location_descriptor_data, sizeof( vslvm_raw_location_descriptor_t ), 0 ); } #endif result = memory_compare( (uint8_t *) &raw_location_descriptor_data, vslvm_empty_raw_location_descriptor, sizeof( vslvm_raw_location_descriptor_t ) ); if( result != 0 ) { byte_stream_copy_to_uint64_little_endian( raw_location_descriptor_data.offset, offset ); byte_stream_copy_to_uint64_little_endian( raw_location_descriptor_data.size, size ); byte_stream_copy_to_uint32_little_endian( raw_location_descriptor_data.checksum, checksum ); byte_stream_copy_to_uint32_little_endian( raw_location_descriptor_data.flags, flags ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: offset\t\t\t\t\t: 0x%08" PRIx64 "\n", function, offset ); libcnotify_printf( "%s: size\t\t\t\t\t: %" PRIu64 "\n", function, size ); libcnotify_printf( "%s: checksum\t\t\t\t\t: 0x%08" PRIx32 "\n", function, checksum ); libcnotify_printf( "%s: flags\t\t\t\t\t: 0x%08" PRIx32 "\n", function, flags ); libcnotify_printf( "\n" ); } #endif if( ( flags & LIBVSLVM_RAW_LOCATION_DESCRIPTOR_FLAG_IGNORE ) == 0 ) { if( libvslvm_raw_location_descriptor_initialize( &raw_location_descriptor, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create raw location descriptor.", function ); goto on_error; } if( libvslvm_raw_location_descriptor_set( raw_location_descriptor, (off64_t) ( file_offset + offset ), (size64_t) size, checksum, flags, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set raw location descriptor.", function ); goto on_error; } if( libcdata_array_append_entry( metadata_area->raw_location_descriptors_array, &entry_index, (intptr_t *) raw_location_descriptor, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, "%s: unable to append entry to raw location descriptors array.", function ); goto on_error; } raw_location_descriptor = NULL; } } } while( result != 0 ); return( 1 ); on_error: if( raw_location_descriptor != NULL ) { libvslvm_raw_location_descriptor_free( &raw_location_descriptor, NULL ); } libcdata_array_empty( metadata_area->raw_location_descriptors_array, (int (*)(intptr_t **, libcerror_error_t **)) &libvslvm_raw_location_descriptor_free, NULL ); return( -1 ); }
/* Reads the volume header * Returns 1 if successful or -1 on error */ int libbde_io_handle_read_volume_header( libbde_io_handle_t *io_handle, libbfio_handle_t *file_io_handle, off64_t file_offset, libcerror_error_t **error ) { uint8_t *volume_header_data = NULL; static char *function = "libbde_io_handle_read_volume_header"; size_t read_size = 512; ssize_t read_count = 0; uint64_t total_number_of_sectors = 0; #if defined( HAVE_DEBUG_OUTPUT ) libcstring_system_character_t guid_string[ 48 ]; libfguid_identifier_t *guid = NULL; uint64_t value_64bit = 0; uint32_t value_32bit = 0; uint16_t value_16bit = 0; int result = 0; #endif if( io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid IO handle.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: reading volume header at offset: %" PRIi64 " (0x%08" PRIx64 ")\n", function, file_offset, file_offset ); } #endif if( libbfio_handle_seek_offset( file_io_handle, file_offset, SEEK_SET, error ) == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_SEEK_FAILED, "%s: unable to seek volume header offset: %" PRIi64 ".", function, file_offset ); goto on_error; } volume_header_data = (uint8_t *) memory_allocate( sizeof( uint8_t ) * read_size ); if( volume_header_data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create volume header data.", function ); goto on_error; } read_count = libbfio_handle_read_buffer( file_io_handle, volume_header_data, read_size, error ); if( read_count != (ssize_t) read_size ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read volume header data.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: volume header data:\n", function ); libcnotify_print_data( volume_header_data, read_size, 0 ); } #endif if( memory_compare( volume_header_data, bde_boot_entry_point_vista, 3 ) == 0 ) { io_handle->version = LIBBDE_VERSION_WINDOWS_VISTA; } else if( memory_compare( volume_header_data, bde_boot_entry_point_win7, 3 ) == 0 ) { if( memory_compare( ( (bde_volume_header_windows_7_t *) volume_header_data )->identifier, bde_identifier, 16 ) == 0 ) { io_handle->version = LIBBDE_VERSION_WINDOWS_7; } else if( memory_compare( ( (bde_volume_header_to_go_t *) volume_header_data )->identifier, bde_identifier, 16 ) == 0 ) { io_handle->version = LIBBDE_VERSION_TO_GO; } else { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, "%s: unsupported identifier.", function ); goto on_error; } } else { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, "%s: unsupported volume boot entry point.", function ); goto on_error; } if( ( io_handle->version == LIBBDE_VERSION_WINDOWS_VISTA ) || ( io_handle->version == LIBBDE_VERSION_WINDOWS_7 ) ) { if( memory_compare( &( volume_header_data[ 3 ] ), bde_signature, 8 ) != 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, "%s: invalid volume signature.", function ); goto on_error; } } byte_stream_copy_to_uint16_little_endian( ( (bde_volume_header_windows_vista_t *) volume_header_data )->bytes_per_sector, io_handle->bytes_per_sector ); io_handle->sectors_per_cluster_block = ( (bde_volume_header_windows_vista_t *) volume_header_data )->sectors_per_cluster_block; byte_stream_copy_to_uint16_little_endian( ( (bde_volume_header_windows_vista_t *) volume_header_data )->total_number_of_sectors_16bit, total_number_of_sectors ); if( total_number_of_sectors == 0 ) { byte_stream_copy_to_uint32_little_endian( ( (bde_volume_header_windows_vista_t *) volume_header_data )->total_number_of_sectors_32bit, total_number_of_sectors ); } if( io_handle->version == LIBBDE_VERSION_WINDOWS_VISTA ) { byte_stream_copy_to_uint64_little_endian( ( (bde_volume_header_windows_vista_t *) volume_header_data )->first_metadata_cluster_block_number, io_handle->first_metadata_offset ); if( total_number_of_sectors == 0 ) { byte_stream_copy_to_uint64_little_endian( ( (bde_volume_header_windows_vista_t *) volume_header_data )->total_number_of_sectors_64bit, total_number_of_sectors ); } } else if( io_handle->version == LIBBDE_VERSION_WINDOWS_7 ) { byte_stream_copy_to_uint64_little_endian( ( (bde_volume_header_windows_7_t *) volume_header_data )->first_metadata_offset, io_handle->first_metadata_offset ); byte_stream_copy_to_uint64_little_endian( ( (bde_volume_header_windows_7_t *) volume_header_data )->second_metadata_offset, io_handle->second_metadata_offset ); byte_stream_copy_to_uint64_little_endian( ( (bde_volume_header_windows_7_t *) volume_header_data )->third_metadata_offset, io_handle->third_metadata_offset ); } else if( io_handle->version == LIBBDE_VERSION_TO_GO ) { byte_stream_copy_to_uint64_little_endian( ( (bde_volume_header_to_go_t *) volume_header_data )->first_metadata_offset, io_handle->first_metadata_offset ); byte_stream_copy_to_uint64_little_endian( ( (bde_volume_header_to_go_t *) volume_header_data )->second_metadata_offset, io_handle->second_metadata_offset ); byte_stream_copy_to_uint64_little_endian( ( (bde_volume_header_to_go_t *) volume_header_data )->third_metadata_offset, io_handle->third_metadata_offset ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: boot entry point:\n", function ); libcnotify_print_data( volume_header_data, 3, 0 ); libcnotify_printf( "%s: signature\t\t\t\t: %c%c%c%c%c%c%c%c\n", function, volume_header_data[ 3 ], volume_header_data[ 4 ], volume_header_data[ 5 ], volume_header_data[ 6 ], volume_header_data[ 7 ], volume_header_data[ 8 ], volume_header_data[ 9 ], volume_header_data[ 10 ] ); libcnotify_printf( "%s: bytes per sector\t\t\t: %" PRIu16 "\n", function, io_handle->bytes_per_sector ); libcnotify_printf( "%s: sectors per cluster block\t\t: %" PRIu8 "\n", function, io_handle->sectors_per_cluster_block ); libcnotify_printf( "%s: unknown1\n", function ); libcnotify_print_data( ( (bde_volume_header_windows_vista_t *) volume_header_data )->unknown1, 5, 0 ); byte_stream_copy_to_uint16_little_endian( ( (bde_volume_header_windows_vista_t *) volume_header_data )->total_number_of_sectors_16bit, value_16bit ); libcnotify_printf( "%s: total number of sectors (16-bit)\t: %" PRIu16 "\n", function, value_16bit ); libcnotify_printf( "%s: media descriptor\t\t\t: 0x%02" PRIx8 "\n", function, ( (bde_volume_header_windows_vista_t *) volume_header_data )->media_descriptor ); byte_stream_copy_to_uint16_little_endian( ( (bde_volume_header_windows_vista_t *) volume_header_data )->unknown2, value_16bit ); libcnotify_printf( "%s: unknown2\t\t\t\t: %" PRIu16 "\n", function, value_16bit ); byte_stream_copy_to_uint16_little_endian( ( (bde_volume_header_windows_vista_t *) volume_header_data )->sectors_per_track, value_16bit ); libcnotify_printf( "%s: sectors per track\t\t\t: %" PRIu16 "\n", function, value_16bit ); byte_stream_copy_to_uint16_little_endian( ( (bde_volume_header_windows_vista_t *) volume_header_data )->number_of_heads, value_16bit ); libcnotify_printf( "%s: number of heads\t\t\t: %" PRIu16 "\n", function, value_16bit ); byte_stream_copy_to_uint32_little_endian( ( (bde_volume_header_windows_vista_t *) volume_header_data )->number_of_hidden_sectors, value_32bit ); libcnotify_printf( "%s: number of hidden sectors\t\t: %" PRIu32 "\n", function, value_32bit ); byte_stream_copy_to_uint32_little_endian( ( (bde_volume_header_windows_vista_t *) volume_header_data )->total_number_of_sectors_32bit, value_32bit ); libcnotify_printf( "%s: total number of sectors (32-bit)\t: %" PRIu32 "\n", function, value_32bit ); if( io_handle->version == LIBBDE_VERSION_WINDOWS_VISTA ) { byte_stream_copy_to_uint32_little_endian( ( (bde_volume_header_windows_vista_t *) volume_header_data )->unknown4, value_32bit ); libcnotify_printf( "%s: unknown4\t\t\t\t: 0x%08" PRIx32 " (%" PRIu32 ")\n", function, value_32bit, value_32bit ); byte_stream_copy_to_uint32_little_endian( ( (bde_volume_header_windows_vista_t *) volume_header_data )->total_number_of_sectors_64bit, value_64bit ); libcnotify_printf( "%s: total number of sectors (64-bit)\t: %" PRIu64 "\n", function, value_64bit ); byte_stream_copy_to_uint64_little_endian( ( (bde_volume_header_windows_vista_t *) volume_header_data )->mft_cluster_block_number, value_64bit ); libcnotify_printf( "%s: MFT cluster block number\t\t: %" PRIu64 "\n", function, value_64bit ); libcnotify_printf( "%s: first metadata cluster block\t: 0x%08" PRIx64 "\n", function, io_handle->first_metadata_offset ); byte_stream_copy_to_uint32_little_endian( ( (bde_volume_header_windows_vista_t *) volume_header_data )->mft_entry_size, value_32bit ); libcnotify_printf( "%s: MFT entry size\t\t\t: %" PRIu32 "\n", function, value_32bit ); byte_stream_copy_to_uint32_little_endian( ( (bde_volume_header_windows_vista_t *) volume_header_data )->index_entry_size, value_32bit ); libcnotify_printf( "%s: index entry size\t\t: %" PRIu32 "\n", function, value_32bit ); byte_stream_copy_to_uint64_little_endian( ( (bde_volume_header_windows_vista_t *) volume_header_data )->volume_serial_number, value_64bit ); libcnotify_printf( "%s: volume serial number\t\t: 0x%08" PRIx64 "\n", function, value_64bit ); byte_stream_copy_to_uint32_little_endian( ( (bde_volume_header_windows_vista_t *) volume_header_data )->checksum, value_32bit ); libcnotify_printf( "%s: checksum\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); libcnotify_printf( "%s: bootcode\n", function ); libcnotify_print_data( ( (bde_volume_header_windows_vista_t *) volume_header_data )->bootcode, 426, 0 ); } else if( ( io_handle->version == LIBBDE_VERSION_WINDOWS_7 ) || ( io_handle->version == LIBBDE_VERSION_TO_GO ) ) { libcnotify_printf( "%s: unknown4:\n", function ); libcnotify_print_data( ( (bde_volume_header_windows_7_t *) volume_header_data )->unknown4, 31, 0 ); byte_stream_copy_to_uint32_little_endian( ( (bde_volume_header_windows_7_t *) volume_header_data )->volume_serial_number, value_64bit ); libcnotify_printf( "%s: volume serial number\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); libcnotify_printf( "%s: volume label\t\t\t: %c%c%c%c%c%c%c%c%c%c%c\n", function, ( (bde_volume_header_windows_7_t *) volume_header_data )->volume_label[ 0 ], ( (bde_volume_header_windows_7_t *) volume_header_data )->volume_label[ 1 ], ( (bde_volume_header_windows_7_t *) volume_header_data )->volume_label[ 2 ], ( (bde_volume_header_windows_7_t *) volume_header_data )->volume_label[ 3 ], ( (bde_volume_header_windows_7_t *) volume_header_data )->volume_label[ 4 ], ( (bde_volume_header_windows_7_t *) volume_header_data )->volume_label[ 5 ], ( (bde_volume_header_windows_7_t *) volume_header_data )->volume_label[ 6 ], ( (bde_volume_header_windows_7_t *) volume_header_data )->volume_label[ 7 ], ( (bde_volume_header_windows_7_t *) volume_header_data )->volume_label[ 8 ], ( (bde_volume_header_windows_7_t *) volume_header_data )->volume_label[ 9 ], ( (bde_volume_header_windows_7_t *) volume_header_data )->volume_label[ 10 ] ); libcnotify_printf( "%s: file system signature\t\t: %c%c%c%c%c%c%c%c\n", function, ( (bde_volume_header_windows_7_t *) volume_header_data )->file_system_signature[ 0 ], ( (bde_volume_header_windows_7_t *) volume_header_data )->file_system_signature[ 1 ], ( (bde_volume_header_windows_7_t *) volume_header_data )->file_system_signature[ 2 ], ( (bde_volume_header_windows_7_t *) volume_header_data )->file_system_signature[ 3 ], ( (bde_volume_header_windows_7_t *) volume_header_data )->file_system_signature[ 4 ], ( (bde_volume_header_windows_7_t *) volume_header_data )->file_system_signature[ 5 ], ( (bde_volume_header_windows_7_t *) volume_header_data )->file_system_signature[ 6 ], ( (bde_volume_header_windows_7_t *) volume_header_data )->file_system_signature[ 7 ] ); } if( io_handle->version == LIBBDE_VERSION_WINDOWS_7 ) { libcnotify_printf( "%s: bootcode\n", function ); libcnotify_print_data( ( (bde_volume_header_windows_7_t *) volume_header_data )->bootcode, 47, 0 ); 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( libfguid_identifier_copy_from_byte_stream( guid, ( (bde_volume_header_windows_7_t *) volume_header_data )->identifier, 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; } libcnotify_printf( "%s: identifier\t\t\t\t: %" PRIs_LIBCSTRING_SYSTEM "\n", function, guid_string ); 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; } } else if( io_handle->version == LIBBDE_VERSION_TO_GO ) { libcnotify_printf( "%s: bootcode\n", function ); libcnotify_print_data( ( (bde_volume_header_to_go_t *) volume_header_data )->bootcode, 335, 0 ); 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( libfguid_identifier_copy_from_byte_stream( guid, ( (bde_volume_header_to_go_t *) volume_header_data )->identifier, 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; } libcnotify_printf( "%s: identifier\t\t\t\t: %" PRIs_LIBCSTRING_SYSTEM "\n", function, guid_string ); 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( ( io_handle->version == LIBBDE_VERSION_WINDOWS_7 ) || ( io_handle->version == LIBBDE_VERSION_TO_GO ) ) { libcnotify_printf( "%s: first metadata offset\t\t: 0x%08" PRIx64 "\n", function, io_handle->first_metadata_offset ); libcnotify_printf( "%s: second metadata offset\t\t: 0x%08" PRIx64 "\n", function, io_handle->second_metadata_offset ); libcnotify_printf( "%s: third metadata offset\t\t: 0x%08" PRIx64 "\n", function, io_handle->third_metadata_offset ); } if( io_handle->version == LIBBDE_VERSION_WINDOWS_7 ) { libcnotify_printf( "%s: unknown5:\n", function ); libcnotify_print_data( ( (bde_volume_header_windows_7_t *) volume_header_data )->unknown5, 310, 0 ); } else if( io_handle->version == LIBBDE_VERSION_TO_GO ) { libcnotify_printf( "%s: unknown5:\n", function ); libcnotify_print_data( ( (bde_volume_header_to_go_t *) volume_header_data )->unknown5, 46, 0 ); } byte_stream_copy_to_uint16_little_endian( ( (bde_volume_header_windows_vista_t *) volume_header_data )->sector_signature, value_16bit ); libcnotify_printf( "%s: sector signature\t\t\t: 0x%04" PRIx16 "\n", function, value_16bit ); libcnotify_printf( "\n" ); } #endif if( total_number_of_sectors != 0 ) { io_handle->volume_size = total_number_of_sectors; io_handle->volume_size *= io_handle->bytes_per_sector; } if( io_handle->version == LIBBDE_VERSION_WINDOWS_VISTA ) { io_handle->first_metadata_offset *= io_handle->sectors_per_cluster_block; io_handle->first_metadata_offset *= io_handle->bytes_per_sector; io_handle->metadata_size = 16384; } else if( ( io_handle->version == LIBBDE_VERSION_WINDOWS_7 ) || ( io_handle->version == LIBBDE_VERSION_TO_GO ) ) { io_handle->metadata_size = 65536; } memory_free( volume_header_data ); volume_header_data = NULL; return( 1 ); on_error: #if defined( HAVE_DEBUG_OUTPUT ) if( guid != NULL ) { libfguid_identifier_free( &guid, NULL ); } #endif if( volume_header_data != NULL ) { memory_free( volume_header_data ); } return( -1 ); }
/* Reads the compressed folder values * Returns the number of bytes read if successful, 0 if not able to read or -1 on error */ ssize_t libfwsi_compressed_folder_values_read( libfwsi_compressed_folder_values_t *compressed_folder_values, const uint8_t *shell_item_data, size_t shell_item_data_size, libcerror_error_t **error ) { static char *function = "libfwsi_compressed_folder_values_read"; size_t shell_item_data_offset = 0; uint32_t string_size = 0; #if defined( HAVE_DEBUG_OUTPUT ) libcstring_system_character_t date_time_string[ 32 ]; libcstring_system_character_t *value_string = NULL; libfdatetime_fat_date_time_t *fat_date_time = NULL; size_t value_string_size = 0; uint64_t value_64bit = 0; uint32_t value_32bit = 0; uint16_t value_16bit = 0; int result = 0; #endif if( compressed_folder_values == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid compressed folder values.", function ); return( -1 ); } if( shell_item_data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid shell item data.", function ); return( -1 ); } if( shell_item_data_size > (size_t) SSIZE_MAX ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: shell item data size exceeds maximum.", function ); return( -1 ); } /* Do not try to parse unsupported shell item data sizes */ if( shell_item_data_size < 6 ) { return( 0 ); } /* Do not try to parse unknown class type indicators */ if( shell_item_data[ 2 ] != 0x52 ) { return( 0 ); } /* TODO: other variants not supported yet */ if( ( shell_item_data[ 3 ] != 0x67 ) || ( shell_item_data[ 4 ] != 0xb1 ) || ( shell_item_data[ 5 ] != 0xac ) ) { return( 0 ); } if( ( shell_item_data[ 3 ] == 0x67 ) && ( shell_item_data[ 4 ] == 0xb1 ) && ( shell_item_data[ 5 ] == 0xac ) ) { if( shell_item_data_size < 50 ) { return( 0 ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: unknown1\t\t\t\t: 0x%02" PRIx8 "\n", function, shell_item_data[ 3 ] ); byte_stream_copy_to_uint16_little_endian( &( shell_item_data[ 4 ] ), value_16bit ); libcnotify_printf( "%s: unknown2\t\t\t\t: 0x%04" PRIx16 "\n", function, value_16bit ); byte_stream_copy_to_uint32_little_endian( &( shell_item_data[ 6 ] ), value_32bit ); libcnotify_printf( "%s: unknown3\t\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); byte_stream_copy_to_uint64_little_endian( &( shell_item_data[ 10 ] ), value_64bit ); libcnotify_printf( "%s: unknown4\t\t\t\t: 0x%08" PRIx64 "\n", function, value_64bit ); byte_stream_copy_to_uint32_little_endian( &( shell_item_data[ 18 ] ), value_32bit ); libcnotify_printf( "%s: unknown5\t\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); byte_stream_copy_to_uint32_little_endian( &( shell_item_data[ 22 ] ), value_32bit ); libcnotify_printf( "%s: unknown6\t\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); if( libfdatetime_fat_date_time_initialize( &fat_date_time, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create FAT date time.", function ); goto on_error; } if( libfdatetime_fat_date_time_copy_from_byte_stream( fat_date_time, &( shell_item_data[ 26 ] ), 4, LIBFDATETIME_ENDIAN_LITTLE, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy byte stream to FAT date time.", function ); goto on_error; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libfdatetime_fat_date_time_copy_to_utf16_string( fat_date_time, (uint16_t *) date_time_string, 32, LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME, error ); #else result = libfdatetime_fat_date_time_copy_to_utf8_string( fat_date_time, (uint8_t *) date_time_string, 32, LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy FAT date time to string.", function ); goto on_error; } libcnotify_printf( "%s: unknown time\t\t\t: %" PRIs_LIBCSTRING_SYSTEM " UTC\n", function, date_time_string ); byte_stream_copy_to_uint32_little_endian( &( shell_item_data[ 30 ] ), value_32bit ); libcnotify_printf( "%s: unknown7\t\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); if( libfdatetime_fat_date_time_copy_from_byte_stream( fat_date_time, &( shell_item_data[ 34 ] ), 4, LIBFDATETIME_ENDIAN_LITTLE, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy byte stream to FAT date time.", function ); goto on_error; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libfdatetime_fat_date_time_copy_to_utf16_string( fat_date_time, (uint16_t *) date_time_string, 32, LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME, error ); #else result = libfdatetime_fat_date_time_copy_to_utf8_string( fat_date_time, (uint8_t *) date_time_string, 32, LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy FAT date time to string.", function ); goto on_error; } libcnotify_printf( "%s: unknown time\t\t\t: %" PRIs_LIBCSTRING_SYSTEM " UTC\n", function, date_time_string ); if( libfdatetime_fat_date_time_free( &fat_date_time, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free FAT date time.", function ); goto on_error; } byte_stream_copy_to_uint64_little_endian( &( shell_item_data[ 38 ] ), value_64bit ); libcnotify_printf( "%s: unknown8\t\t\t\t: 0x%08" PRIx64 "\n", function, value_64bit ); } #endif shell_item_data_offset = 46; } byte_stream_copy_to_uint32_little_endian( &( shell_item_data[ shell_item_data_offset ] ), string_size ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: string size\t\t\t: %" PRIu32 "\n", function, string_size ); } #endif shell_item_data_offset += 4; string_size *= 2; if( ( string_size > 0 ) && ( string_size <= shell_item_data_size ) && ( shell_item_data_offset <= ( shell_item_data_size - string_size ) ) ) { #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_size_from_utf16_stream( &( shell_item_data[ shell_item_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, &value_string_size, error ); #else result = libuna_utf8_string_size_from_utf16_stream( &( shell_item_data[ shell_item_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, &value_string_size, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine size of value string.", function ); goto on_error; } if( value_string_size > (size_t) ( SSIZE_MAX / sizeof( libcstring_system_character_t ) ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid value string size value exceeds maximum.", function ); goto on_error; } value_string = libcstring_system_string_allocate( value_string_size ); if( value_string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create value string.", function ); goto on_error; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_copy_from_utf16_stream( (libuna_utf16_character_t *) value_string, value_string_size, &( shell_item_data[ shell_item_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, error ); #else result = libuna_utf8_string_copy_from_utf16_stream( (libuna_utf8_character_t *) value_string, value_string_size, &( shell_item_data[ shell_item_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set value string.", function ); goto on_error; } libcnotify_printf( "%s: string\t\t\t\t: %" PRIs_LIBCSTRING_SYSTEM "\n", function, value_string ); memory_free( value_string ); value_string = NULL; } #endif shell_item_data_offset += string_size; } byte_stream_copy_to_uint32_little_endian( &( shell_item_data[ shell_item_data_offset ] ), string_size ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: string size\t\t\t: %" PRIu32 "\n", function, string_size ); } #endif shell_item_data_offset += 4; string_size *= 2; if( ( string_size > 0 ) && ( string_size <= shell_item_data_size ) && ( shell_item_data_offset <= ( shell_item_data_size - string_size ) ) ) { #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_size_from_utf16_stream( &( shell_item_data[ shell_item_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, &value_string_size, error ); #else result = libuna_utf8_string_size_from_utf16_stream( &( shell_item_data[ shell_item_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, &value_string_size, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine size of value string.", function ); goto on_error; } if( value_string_size > (size_t) ( SSIZE_MAX / sizeof( libcstring_system_character_t ) ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid value string size value exceeds maximum.", function ); goto on_error; } value_string = libcstring_system_string_allocate( value_string_size ); if( value_string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create value string.", function ); goto on_error; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_copy_from_utf16_stream( (libuna_utf16_character_t *) value_string, value_string_size, &( shell_item_data[ shell_item_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, error ); #else result = libuna_utf8_string_copy_from_utf16_stream( (libuna_utf8_character_t *) value_string, value_string_size, &( shell_item_data[ shell_item_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set value string.", function ); goto on_error; } libcnotify_printf( "%s: string\t\t\t\t: %" PRIs_LIBCSTRING_SYSTEM "\n", function, value_string ); memory_free( value_string ); value_string = NULL; } #endif shell_item_data_offset += string_size; } byte_stream_copy_to_uint32_little_endian( &( shell_item_data[ shell_item_data_offset ] ), string_size ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: string size\t\t\t: %" PRIu32 "\n", function, string_size ); } #endif shell_item_data_offset += 4; string_size *= 2; if( ( string_size > 0 ) && ( string_size <= shell_item_data_size ) && ( shell_item_data_offset <= ( shell_item_data_size - string_size ) ) ) { #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_size_from_utf16_stream( &( shell_item_data[ shell_item_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, &value_string_size, error ); #else result = libuna_utf8_string_size_from_utf16_stream( &( shell_item_data[ shell_item_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, &value_string_size, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine size of value string.", function ); goto on_error; } if( value_string_size > (size_t) ( SSIZE_MAX / sizeof( libcstring_system_character_t ) ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid value string size value exceeds maximum.", function ); goto on_error; } value_string = libcstring_system_string_allocate( value_string_size ); if( value_string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create value string.", function ); goto on_error; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_copy_from_utf16_stream( (libuna_utf16_character_t *) value_string, value_string_size, &( shell_item_data[ shell_item_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, error ); #else result = libuna_utf8_string_copy_from_utf16_stream( (libuna_utf8_character_t *) value_string, value_string_size, &( shell_item_data[ shell_item_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set value string.", function ); goto on_error; } libcnotify_printf( "%s: string\t\t\t\t: %" PRIs_LIBCSTRING_SYSTEM "\n", function, value_string ); memory_free( value_string ); value_string = NULL; } #endif shell_item_data_offset += string_size; } byte_stream_copy_to_uint32_little_endian( &( shell_item_data[ shell_item_data_offset ] ), string_size ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: string size\t\t\t: %" PRIu32 "\n", function, string_size ); } #endif shell_item_data_offset += 4; string_size *= 2; if( ( string_size > 0 ) && ( string_size <= shell_item_data_size ) && ( shell_item_data_offset <= ( shell_item_data_size - string_size ) ) ) { #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_size_from_utf16_stream( &( shell_item_data[ shell_item_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, &value_string_size, error ); #else result = libuna_utf8_string_size_from_utf16_stream( &( shell_item_data[ shell_item_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, &value_string_size, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine size of value string.", function ); goto on_error; } if( value_string_size > (size_t) ( SSIZE_MAX / sizeof( libcstring_system_character_t ) ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid value string size value exceeds maximum.", function ); goto on_error; } value_string = libcstring_system_string_allocate( value_string_size ); if( value_string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create value string.", function ); goto on_error; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_copy_from_utf16_stream( (libuna_utf16_character_t *) value_string, value_string_size, &( shell_item_data[ shell_item_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, error ); #else result = libuna_utf8_string_copy_from_utf16_stream( (libuna_utf8_character_t *) value_string, value_string_size, &( shell_item_data[ shell_item_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set value string.", function ); goto on_error; } libcnotify_printf( "%s: string\t\t\t\t: %" PRIs_LIBCSTRING_SYSTEM "\n", function, value_string ); memory_free( value_string ); value_string = NULL; } #endif shell_item_data_offset += string_size; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "\n" ); } #endif return( (ssize_t) shell_item_data_offset ); on_error: #if defined( HAVE_DEBUG_OUTPUT ) if( value_string != NULL ) { memory_free( value_string ); } if( fat_date_time != NULL ) { libfdatetime_fat_date_time_free( &fat_date_time, NULL ); } #endif return( -1 ); }
/* Copies the record from the byte stream * Returns 1 if successful or -1 on error */ int libfusn_record_copy_from_byte_stream( libfusn_record_t *record, const uint8_t *byte_stream, size_t byte_stream_size, libcerror_error_t **error ) { libfusn_internal_record_t *internal_record = NULL; static char *function = "libfusn_record_copy_from_byte_stream"; size_t byte_stream_offset = 0; uint16_t name_offset = 0; uint16_t name_size = 0; #if defined( HAVE_DEBUG_OUTPUT ) uint32_t value_32bit = 0; #endif if( record == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid record.", function ); return( -1 ); } internal_record = (libfusn_internal_record_t *) record; if( internal_record->name != NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, "%s: invalid record - name value already set.", function ); return( -1 ); } if( byte_stream == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid byte stream.", function ); return( -1 ); } if( byte_stream_size > (size_t) SSIZE_MAX ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid byte stream size value exceeds maximum.", function ); return( -1 ); } if( byte_stream_size < sizeof( fusn_record_header_t ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, "%s: invalid byte stream value too small.", function ); return( -1 ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: record header data:\n", function ); libcnotify_print_data( byte_stream, sizeof( fusn_record_header_t ), 0 ); } #endif byte_stream_copy_to_uint32_little_endian( ( (fusn_record_header_t *) byte_stream )->record_size, internal_record->size ); byte_stream_copy_to_uint16_little_endian( ( (fusn_record_header_t *) byte_stream )->major_version, internal_record->major_version ); byte_stream_copy_to_uint16_little_endian( ( (fusn_record_header_t *) byte_stream )->minor_version, internal_record->minor_version ); byte_stream_copy_to_uint64_little_endian( ( (fusn_record_header_t *) byte_stream )->update_time, internal_record->update_time ); byte_stream_copy_to_uint64_little_endian( ( (fusn_record_header_t *) byte_stream )->file_reference, internal_record->file_reference ); byte_stream_copy_to_uint32_little_endian( ( (fusn_record_header_t *) byte_stream )->file_attribute_flags, internal_record->file_attribute_flags ); byte_stream_copy_to_uint64_little_endian( ( (fusn_record_header_t *) byte_stream )->parent_file_reference, internal_record->parent_file_reference ); byte_stream_copy_to_uint64_little_endian( ( (fusn_record_header_t *) byte_stream )->update_sequence_number, internal_record->update_sequence_number ); byte_stream_copy_to_uint32_little_endian( ( (fusn_record_header_t *) byte_stream )->update_reason_flags, internal_record->update_reason_flags ); byte_stream_copy_to_uint32_little_endian( ( (fusn_record_header_t *) byte_stream )->update_source_flags, internal_record->update_source_flags ); byte_stream_copy_to_uint16_little_endian( ( (fusn_record_header_t *) byte_stream )->name_size, name_size ); byte_stream_copy_to_uint16_little_endian( ( (fusn_record_header_t *) byte_stream )->name_offset, name_offset ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: record size\t\t\t: %" PRIu32 "\n", function, internal_record->size ); libcnotify_printf( "%s: major version\t\t\t: %" PRIu16 "\n", function, internal_record->major_version ); libcnotify_printf( "%s: minor version\t\t\t: %" PRIu16 "\n", function, internal_record->minor_version ); libcnotify_printf( "%s: file reference\t\t\t: MFT entry: %" PRIu64 ", sequence: %" PRIu64 "\n", function, internal_record->file_reference & 0xffffffffffffUL, internal_record->file_reference >> 48 ); libcnotify_printf( "%s: parent file reference\t\t: MFT entry: %" PRIu64 ", sequence: %" PRIu64 "\n", function, internal_record->parent_file_reference & 0xffffffffffffUL, internal_record->parent_file_reference >> 48 ); libcnotify_printf( "%s: update sequence number\t\t: 0x%08" PRIx64 "\n", function, internal_record->update_sequence_number ); if( libfusn_debug_print_filetime_value( function, "update time\t\t\t", ( (fusn_record_header_t *) byte_stream )->update_time, 8, LIBFDATETIME_ENDIAN_LITTLE, LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, "%s: unable to print FILETIME value.", function ); goto on_error; } libcnotify_printf( "%s: update reason flags\t\t: 0x%08" PRIx32 "\n", function, internal_record->update_reason_flags ); libfusn_debug_print_update_reason_flags( internal_record->update_reason_flags ); libcnotify_printf( "\n" ); libcnotify_printf( "%s: update source flags\t\t: 0x%08" PRIx32 "\n", function, internal_record->update_source_flags ); libfusn_debug_print_update_source_flags( internal_record->update_source_flags ); libcnotify_printf( "\n" ); byte_stream_copy_to_uint32_little_endian( ( (fusn_record_header_t *) byte_stream )->security_identifier_index, value_32bit ); libcnotify_printf( "%s: security identifier index\t\t: %" PRIu32 "\n", function, value_32bit ); libcnotify_printf( "%s: file attribute flags\t\t: 0x%08" PRIx32 "\n", function, internal_record->file_attribute_flags ); libfusn_debug_print_file_attribute_flags( internal_record->file_attribute_flags ); libcnotify_printf( "\n" ); libcnotify_printf( "%s: name size\t\t\t\t: %" PRIu16 "\n", function, name_size ); libcnotify_printf( "%s: name offset\t\t\t: %" PRIu16 "\n", function, name_offset ); }
/* Reads a page and its values * Returns 1 if successful or -1 on error */ int libesedb_page_read( libesedb_page_t *page, libesedb_io_handle_t *io_handle, libbfio_handle_t *file_io_handle, off64_t file_offset, libcerror_error_t **error ) { libcdata_array_t *page_tags_array = NULL; uint8_t *page_values_data = NULL; static char *function = "libesedb_page_read"; size_t page_values_data_offset = 0; size_t page_values_data_size = 0; ssize_t read_count = 0; uint32_t calculated_ecc32_checksum = 0; uint32_t calculated_page_number = 0; uint32_t calculated_xor32_checksum = 0; uint32_t stored_ecc32_checksum = 0; uint32_t stored_page_number = 0; uint32_t stored_xor32_checksum = 0; uint16_t available_data_size = 0; uint16_t available_page_tag = 0; #if defined( HAVE_DEBUG_OUTPUT ) uint64_t value_64bit = 0; uint16_t value_16bit = 0; #endif if( page == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid page.", function ); return( -1 ); } if( page->data != NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, "%s: invalid page data already set.", function ); return( -1 ); } if( io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid IO handle.", function ); return( -1 ); } calculated_page_number = (uint32_t) ( ( file_offset - io_handle->page_size ) / io_handle->page_size ); page->offset = file_offset; #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: reading page: %" PRIu32 " at offset: %" PRIi64 " (0x%08" PRIx64 ")\n", function, calculated_page_number, page->offset, page->offset ); } #endif if( libbfio_handle_seek_offset( file_io_handle, page->offset, SEEK_SET, error ) == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_SEEK_FAILED, "%s: unable to seek page offset: %" PRIi64 ".", function, page->offset ); goto on_error; } page->data = (uint8_t *) memory_allocate( (size_t) io_handle->page_size ); if( page->data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create page data.", function ); goto on_error; } page->data_size = (size_t) io_handle->page_size; read_count = libbfio_handle_read_buffer( file_io_handle, page->data, page->data_size, error ); if( read_count != (ssize_t) page->data_size ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read page data.", function ); goto on_error; } page_values_data = page->data; page_values_data_size = page->data_size; #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: page header:\n", function ); libcnotify_print_data( page_values_data, sizeof( esedb_page_header_t ), 0 ); } #endif page->page_number = calculated_page_number; byte_stream_copy_to_uint16_little_endian( ( (esedb_page_header_t *) page_values_data )->available_data_size, available_data_size ); byte_stream_copy_to_uint32_little_endian( ( (esedb_page_header_t *) page_values_data )->previous_page, page->previous_page_number ); byte_stream_copy_to_uint32_little_endian( ( (esedb_page_header_t *) page_values_data )->next_page, page->next_page_number ); byte_stream_copy_to_uint32_little_endian( ( (esedb_page_header_t *) page_values_data )->father_data_page_object_identifier, page->father_data_page_object_identifier ); byte_stream_copy_to_uint16_little_endian( ( (esedb_page_header_t *) page_values_data )->available_page_tag, available_page_tag ); byte_stream_copy_to_uint32_little_endian( ( (esedb_page_header_t *) page_values_data )->page_flags, page->flags ); /* Make sure to read after the page flags */ if( ( io_handle->format_revision >= LIBESEDB_FORMAT_REVISION_EXTENDED_PAGE_HEADER ) && ( io_handle->page_size >= 16384 ) ) { /* TODO handle checksum */ } else { byte_stream_copy_to_uint32_little_endian( ( (esedb_page_header_t *) page_values_data )->xor_checksum, stored_xor32_checksum ); if( ( io_handle->format_revision >= LIBESEDB_FORMAT_REVISION_NEW_RECORD_FORMAT ) && ( ( page->flags & LIBESEDB_PAGE_FLAG_IS_NEW_RECORD_FORMAT ) != 0 ) ) { byte_stream_copy_to_uint32_little_endian( ( (esedb_page_header_t *) page_values_data )->ecc_checksum, stored_ecc32_checksum ); } else { byte_stream_copy_to_uint32_little_endian( ( (esedb_page_header_t *) page_values_data )->page_number, stored_page_number ); } } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: current page number\t\t\t\t\t: %" PRIu32 "\n", function, calculated_page_number ); if( ( io_handle->format_revision >= LIBESEDB_FORMAT_REVISION_EXTENDED_PAGE_HEADER ) && ( io_handle->page_size >= 16384 ) ) { /* TODO handle checksum */ byte_stream_copy_to_uint64_little_endian( page_values_data, value_64bit ); libcnotify_printf( "%s: checksum\t\t\t\t\t\t: 0x%08" PRIx64 "\n", function, value_64bit ); } else { libcnotify_printf( "%s: XOR checksum\t\t\t\t\t: 0x%08" PRIx32 "\n", function, stored_xor32_checksum ); if( ( io_handle->format_revision >= LIBESEDB_FORMAT_REVISION_NEW_RECORD_FORMAT ) && ( ( page->flags & LIBESEDB_PAGE_FLAG_IS_NEW_RECORD_FORMAT ) != 0 ) ) { libcnotify_printf( "%s: ECC checksum\t\t\t\t\t: 0x%08" PRIx32 "\n", function, stored_ecc32_checksum ); } else { libcnotify_printf( "%s: page number\t\t\t\t\t\t: %" PRIu32 "\n", function, stored_page_number ); } } libcnotify_printf( "%s: database modification time:\n", function ); libcnotify_print_data( ( (esedb_page_header_t *) page_values_data )->database_modification_time, 8, 0 ); libcnotify_printf( "%s: previous page number\t\t\t\t: %" PRIu32 "\n", function, page->previous_page_number ); libcnotify_printf( "%s: next page number\t\t\t\t\t: %" PRIu32 "\n", function, page->next_page_number ); libcnotify_printf( "%s: father data page (FDP) object identifier\t\t: %" PRIu32 "\n", function, page->father_data_page_object_identifier ); libcnotify_printf( "%s: available data size\t\t\t\t\t: %" PRIu32 "\n", function, available_data_size ); byte_stream_copy_to_uint16_little_endian( ( (esedb_page_header_t *) page_values_data )->available_uncommitted_data_size, value_16bit ); libcnotify_printf( "%s: available uncommitted data size\t\t\t: %" PRIu16 "\n", function, value_16bit ); byte_stream_copy_to_uint16_little_endian( ( (esedb_page_header_t *) page_values_data )->available_data_offset, value_16bit ); libcnotify_printf( "%s: available data offset\t\t\t\t: %" PRIu16 "\n", function, value_16bit ); libcnotify_printf( "%s: available page tag\t\t\t\t\t: %" PRIu32 "\n", function, available_page_tag ); libcnotify_printf( "%s: page flags\t\t\t\t\t\t: 0x%08" PRIx32 "\n", function, page->flags ); libesedb_debug_print_page_flags( page->flags ); libcnotify_printf( "\n" ); } #endif /* TODO for now don't bother calculating a checksum for uninitialized pages */ if( ( page_values_data[ 0 ] != 0 ) || ( page_values_data[ 1 ] != 0 ) || ( page_values_data[ 2 ] != 0 ) || ( page_values_data[ 3 ] != 0 ) ) { if( ( io_handle->format_revision >= LIBESEDB_FORMAT_REVISION_EXTENDED_PAGE_HEADER ) && ( io_handle->page_size >= 16384 ) ) { /* TODO handle checksum */ } else if( ( io_handle->format_revision >= LIBESEDB_FORMAT_REVISION_NEW_RECORD_FORMAT ) && ( ( page->flags & LIBESEDB_PAGE_FLAG_IS_NEW_RECORD_FORMAT ) != 0 ) ) { if( libesedb_checksum_calculate_little_endian_ecc32( &calculated_ecc32_checksum, &calculated_xor32_checksum, page_values_data, page_values_data_size, 8, calculated_page_number, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, "%s: unable to calculate ECC-32 and XOR-32 checksum.", function ); goto on_error; } } else { if( libesedb_checksum_calculate_little_endian_xor32( &calculated_xor32_checksum, &( page_values_data[ 4 ] ), page_values_data_size - 4, 0x89abcdef, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, "%s: unable to calculate XOR-32 checksum.", function ); goto on_error; } } if( stored_xor32_checksum != calculated_xor32_checksum ) { #ifdef TODO libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_INPUT, LIBCERROR_INPUT_ERROR_CRC_MISMATCH, "%s: mismatch in page XOR-32 checksum ( 0x%08" PRIx32 " != 0x%08" PRIx32 " ).", function, stored_xor32_checksum, calculated_xor32_checksum ); goto on_error; #else if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: mismatch in page XOR-32 checksum ( 0x%08" PRIx32 " != 0x%08" PRIx32 " ).\n", function, stored_xor32_checksum, calculated_xor32_checksum ); } #endif } if( stored_ecc32_checksum != calculated_ecc32_checksum ) { #ifdef TODO libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_INPUT, LIBCERROR_INPUT_ERROR_CRC_MISMATCH, "%s: mismatch in page ECC-32 checksum ( 0x%08" PRIx32 " != 0x%08" PRIx32 " ).", function, stored_ecc32_checksum, calculated_ecc32_checksum ); goto on_error; #else if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: mismatch in page ECC-32 checksum ( 0x%08" PRIx32 " != 0x%08" PRIx32 " ).\n", function, stored_ecc32_checksum, calculated_ecc32_checksum ); } #endif } } page_values_data += sizeof( esedb_page_header_t ); page_values_data_size -= sizeof( esedb_page_header_t ); page_values_data_offset += sizeof( esedb_page_header_t ); if( ( io_handle->format_revision >= LIBESEDB_FORMAT_REVISION_EXTENDED_PAGE_HEADER ) && ( io_handle->page_size >= 16384 ) ) { #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: extended page header:\n", function ); libcnotify_print_data( page_values_data, 40, 0 ); } #endif #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { byte_stream_copy_to_uint64_little_endian( ( (esedb_extended_page_header_t *) page_values_data )->checksum1, value_64bit ); libcnotify_printf( "%s: checksum1\t\t\t\t\t\t: 0x%08" PRIx64 "\n", function, value_64bit ); byte_stream_copy_to_uint64_little_endian( ( (esedb_extended_page_header_t *) page_values_data )->checksum2, value_64bit ); libcnotify_printf( "%s: checksum2\t\t\t\t\t\t: 0x%08" PRIx64 "\n", function, value_64bit ); byte_stream_copy_to_uint64_little_endian( ( (esedb_extended_page_header_t *) page_values_data )->checksum3, value_64bit ); libcnotify_printf( "%s: checksum3\t\t\t\t\t\t: 0x%08" PRIx64 "\n", function, value_64bit ); byte_stream_copy_to_uint64_little_endian( ( (esedb_extended_page_header_t *) page_values_data )->page_number, value_64bit ); libcnotify_printf( "%s: page number\t\t\t\t\t\t: %" PRIu64 "\n", function, value_64bit ); libcnotify_printf( "%s: unknown1:\n", function ); libcnotify_print_data( ( (esedb_extended_page_header_t *) page_values_data )->unknown1, 8, 0 ); } #endif page_values_data += sizeof( esedb_extended_page_header_t ); page_values_data_size -= sizeof( esedb_extended_page_header_t ); page_values_data_offset += sizeof( esedb_extended_page_header_t ); } if( available_page_tag > 0 ) { /* Create the page tags array */ if( libcdata_array_initialize( &page_tags_array, 0, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create page tags array.", function ); goto on_error; } if( libesedb_page_read_tags( page_tags_array, io_handle, available_page_tag, page->data, page->data_size, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read page tags.", function ); goto on_error; } /* The offsets in the page tags are relative after the page header */ if( libesedb_page_read_values( page, io_handle, page_tags_array, page_values_data, page_values_data_size, page_values_data_offset, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read page values.", function ); goto on_error; } if( libcdata_array_free( &page_tags_array, (int (*)(intptr_t **, libcerror_error_t **)) &libesedb_page_tags_value_free, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free the page tags array.", function ); goto on_error; } } return( 1 ); on_error: if( page_tags_array != NULL ) { libcdata_array_free( &page_tags_array, (int (*)(intptr_t **, libcerror_error_t **)) &libesedb_page_tags_value_free, NULL ); } if( page->data != NULL ) { memory_free( page->data ); page->data = NULL; } return( -1 ); }
/* Reads the URL values from an URL record * Returns 1 if successful or -1 on error */ int libmsiecf_url_values_read( libmsiecf_url_values_t *url_values, libmsiecf_io_handle_t *io_handle, libbfio_handle_t *file_io_handle, off64_t url_record_offset, size32_t record_size, uint8_t item_flags, libcerror_error_t **error ) { uint8_t *url_record_data = NULL; static char *function = "libmsiecf_url_values_read"; ssize_t read_count = 0; ssize_t value_size = 0; uint32_t data_offset = 0; uint32_t data_size = 0; uint32_t filename_offset = 0; uint32_t location_offset = 0; uint32_t cache_entry_flags = 0; uint32_t unknown_offset = 0; uint16_t first_year = 0; uint16_t second_year = 0; uint8_t first_day_of_month = 0; uint8_t first_month = 0; uint8_t number_of_days = 0; uint8_t second_day_of_month = 0; uint8_t second_month = 0; #if defined( HAVE_DEBUG_OUTPUT ) system_character_t date_time_string[ 32 ]; libfdatetime_filetime_t *filetime = NULL; libfdatetime_fat_date_time_t *fat_date_time = NULL; uint8_t *visited_entry_data = NULL; size_t string_index = 0; uint32_t value_32bit = 0; uint16_t value_16bit = 0; int result = 0; int visited_entry_index = 0; #endif if( url_values == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid URL values.", function ); return( -1 ); } if( io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid IO handle.", function ); return( -1 ); } if( file_io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid file IO handle.", function ); return( -1 ); } if( record_size == 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_ZERO_OR_LESS, "%s: invalid record size value zero or less.", function ); return( -1 ); } #if SIZEOF_SIZE_T <= 4 if( record_size > (size32_t) SSIZE_MAX ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid record size value exceeds maximum.", function ); return( -1 ); } #endif if( ( record_size % 8 ) != 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, "%s: unsupported URL record size.", function ); return( -1 ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: reading URL record at offset: %" PRIi64 " (0x%08" PRIx64 ")\n", function, url_record_offset, url_record_offset ); } #endif if( libbfio_handle_seek_offset( file_io_handle, url_record_offset, SEEK_SET, error ) == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_SEEK_FAILED, "%s: unable to seek URL record offset: %" PRIi64 ".", function, url_record_offset ); goto on_error; } /* Add one block for tainted records */ if( ( item_flags & LIBMSIECF_ITEM_FLAG_TAINTED ) != 0 ) { record_size += LIBMSIECF_DEFAULT_BLOCK_SIZE; } url_record_data = (uint8_t *) memory_allocate( record_size ); if( url_record_data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create URL record data.", function ); goto on_error; } read_count = libbfio_handle_read_buffer( file_io_handle, url_record_data, record_size, error ); if( read_count != (ssize_t) record_size ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read URL record data.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: URL record data:\n", function ); libcnotify_print_data( url_record_data, record_size, 0 ); } #endif if( memory_compare( url_record_data, "URL ", 4 ) != 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, "%s: unsupported signature.", function ); goto on_error; } if( ( io_handle->major_version == 4 ) && ( io_handle->minor_version == 7 ) ) { byte_stream_copy_to_uint64_little_endian( ( (msiecf_url_record_header_v47_t *) url_record_data )->secondary_filetime, url_values->secondary_time ); byte_stream_copy_to_uint64_little_endian( ( (msiecf_url_record_header_v47_t *) url_record_data )->primary_filetime, url_values->primary_time ); byte_stream_copy_to_uint64_little_endian( ( (msiecf_url_record_header_v47_t *) url_record_data )->expiration_time, url_values->expiration_time ); byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v47_t *) url_record_data )->cached_file_size, url_values->cached_file_size ); byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v47_t *) url_record_data )->unknown_offset, unknown_offset ); byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v47_t *) url_record_data )->location_offset, location_offset ); url_values->cache_directory_index = ( (msiecf_url_record_header_v47_t *) url_record_data )->cache_directory_index; byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v47_t *) url_record_data )->filename_offset, filename_offset ); byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v47_t *) url_record_data )->data_offset, data_offset ); byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v47_t *) url_record_data )->data_size, data_size ); byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v47_t *) url_record_data )->last_checked_time, url_values->last_checked_time ); byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v47_t *) url_record_data )->number_of_hits, url_values->number_of_hits ); byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v47_t *) url_record_data )->cache_entry_flags, cache_entry_flags ); } else if( ( io_handle->major_version == 5 ) && ( io_handle->minor_version == 2 ) ) { byte_stream_copy_to_uint64_little_endian( ( (msiecf_url_record_header_v52_t *) url_record_data )->secondary_filetime, url_values->secondary_time ); byte_stream_copy_to_uint64_little_endian( ( (msiecf_url_record_header_v52_t *) url_record_data )->primary_filetime, url_values->primary_time ); byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v52_t *) url_record_data )->expiration_time, url_values->expiration_time ); byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v52_t *) url_record_data )->cached_file_size, url_values->cached_file_size ); byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v52_t *) url_record_data )->unknown_offset, unknown_offset ); byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v52_t *) url_record_data )->location_offset, location_offset ); url_values->cache_directory_index = ( (msiecf_url_record_header_v52_t *) url_record_data )->cache_directory_index; byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v52_t *) url_record_data )->filename_offset, filename_offset ); byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v52_t *) url_record_data )->data_offset, data_offset ); byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v52_t *) url_record_data )->data_size, data_size ); byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v52_t *) url_record_data )->last_checked_time, url_values->last_checked_time ); byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v52_t *) url_record_data )->number_of_hits, url_values->number_of_hits ); byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v52_t *) url_record_data )->cache_entry_flags, cache_entry_flags ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( libfdatetime_fat_date_time_initialize( &fat_date_time, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create FAT date time.", function ); goto on_error; } if( libfdatetime_filetime_initialize( &filetime, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create filetime.", function ); goto on_error; } libcnotify_printf( "%s: signature\t\t\t\t\t: %c%c%c%c\n", function, url_record_data[ 0 ], url_record_data[ 1 ], url_record_data[ 2 ], url_record_data[ 3 ] ); byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v47_t *) url_record_data )->number_of_blocks, value_32bit ); libcnotify_printf( "%s: number of blocks\t\t\t\t: %" PRIu32 "\n", function, value_32bit ); if( libfdatetime_filetime_copy_from_byte_stream( filetime, ( (msiecf_url_record_header_v47_t *) url_record_data )->secondary_filetime, 8, LIBFDATETIME_ENDIAN_LITTLE, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to copy filetime from byte stream.", function ); goto on_error; } #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) result = libfdatetime_filetime_copy_to_utf16_string( filetime, (uint16_t *) date_time_string, 32, LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS, error ); #else result = libfdatetime_filetime_copy_to_utf8_string( filetime, (uint8_t *) date_time_string, 32, LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to copy filetime to date time string.", function ); goto on_error; } libcnotify_printf( "%s: secondary time\t\t\t\t: %" PRIs_SYSTEM "\n", function, date_time_string ); if( libfdatetime_filetime_copy_from_byte_stream( filetime, ( (msiecf_url_record_header_v47_t *) url_record_data )->primary_filetime, 8, LIBFDATETIME_ENDIAN_LITTLE, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to copy filetime from byte stream.", function ); goto on_error; } #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) result = libfdatetime_filetime_copy_to_utf16_string( filetime, (uint16_t *) date_time_string, 32, LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS, error ); #else result = libfdatetime_filetime_copy_to_utf8_string( filetime, (uint8_t *) date_time_string, 32, LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to copy filetime to date time string.", function ); goto on_error; } libcnotify_printf( "%s: primary time\t\t\t\t\t: %" PRIs_SYSTEM "\n", function, date_time_string ); if( ( io_handle->major_version == 4 ) && ( io_handle->minor_version == 7 ) ) { if( libfdatetime_filetime_copy_from_byte_stream( filetime, ( (msiecf_url_record_header_v47_t *) url_record_data )->expiration_time, 8, LIBFDATETIME_ENDIAN_LITTLE, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to copy filetime from byte stream.", function ); goto on_error; } #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) result = libfdatetime_filetime_copy_to_utf16_string( filetime, (uint16_t *) date_time_string, 32, LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS, error ); #else result = libfdatetime_filetime_copy_to_utf8_string( filetime, (uint8_t *) date_time_string, 32, LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to copy filetime to date time string.", function ); goto on_error; } } else if( ( io_handle->major_version == 5 ) && ( io_handle->minor_version == 2 ) ) { if( libfdatetime_fat_date_time_copy_from_byte_stream( fat_date_time, ( (msiecf_url_record_header_v52_t *) url_record_data )->expiration_time, 4, LIBFDATETIME_ENDIAN_LITTLE, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_CONVERSION, LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to copy FAT date time from byte stream.", function ); goto on_error; } #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) result = libfdatetime_fat_date_time_copy_to_utf16_string( fat_date_time, (uint16_t *) date_time_string, 32, LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME, LIBFDATETIME_DATE_TIME_FORMAT_CTIME, error ); #else result = libfdatetime_fat_date_time_copy_to_utf8_string( fat_date_time, (uint8_t *) date_time_string, 32, LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_CONVERSION, LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to copy FAT date time to date time string.", function ); goto on_error; } } libcnotify_printf( "%s: expiration time\t\t\t\t: %" PRIs_SYSTEM "\n", function, date_time_string ); if( ( io_handle->major_version == 5 ) && ( io_handle->minor_version == 2 ) ) { byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v52_t *) url_record_data )->unknown1, value_32bit ); libcnotify_printf( "%s: unknown1\t\t\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); } libcnotify_printf( "%s: cached file size\t\t\t\t: %" PRIu32 " bytes\n", function, url_values->cached_file_size ); if( ( io_handle->major_version == 4 ) && ( io_handle->minor_version == 7 ) ) { byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v47_t *) url_record_data )->unknown1, value_32bit ); libcnotify_printf( "%s: unknown1\t\t\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); } if( ( io_handle->major_version == 4 ) && ( io_handle->minor_version == 7 ) ) { byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v47_t *) url_record_data )->unknown3, value_32bit ); } else if( ( io_handle->major_version == 5 ) && ( io_handle->minor_version == 2 ) ) { byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v52_t *) url_record_data )->unknown3, value_32bit ); } libcnotify_printf( "%s: unknown3\t\t\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); if( ( io_handle->major_version == 4 ) && ( io_handle->minor_version == 7 ) ) { byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v47_t *) url_record_data )->unknown4, value_32bit ); } else if( ( io_handle->major_version == 5 ) && ( io_handle->minor_version == 2 ) ) { byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v52_t *) url_record_data )->unknown4, value_32bit ); } libcnotify_printf( "%s: unknown4\t\t\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); if( ( io_handle->major_version == 4 ) && ( io_handle->minor_version == 7 ) ) { byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v47_t *) url_record_data )->non_releasable_time_delta, value_32bit ); } else if( ( io_handle->major_version == 5 ) && ( io_handle->minor_version == 2 ) ) { byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v52_t *) url_record_data )->non_releasable_time_delta, value_32bit ); } libcnotify_printf( "%s: non-releasable time delta\t\t\t: %" PRIu32 " seconds\n", function, value_32bit ); libcnotify_printf( "%s: unknown offset\t\t\t\t: %" PRIu32 "\n", function, unknown_offset ); libcnotify_printf( "%s: location offset\t\t\t\t: %" PRIu32 "\n", function, location_offset ); libcnotify_printf( "%s: cache directory index\t\t\t: %" PRIu8 "\n", function, url_values->cache_directory_index ); if( ( io_handle->major_version == 4 ) && ( io_handle->minor_version == 7 ) ) { libcnotify_printf( "%s: unknown6\t\t\t\t\t: 0x%02" PRIx8 " 0x%02" PRIx8 " 0x%02" PRIx8 "\n", function, ( (msiecf_url_record_header_v47_t *) url_record_data )->unknown6[ 0 ], ( (msiecf_url_record_header_v47_t *) url_record_data )->unknown6[ 1 ], ( (msiecf_url_record_header_v47_t *) url_record_data )->unknown6[ 2 ] ); } else if( ( io_handle->major_version == 5 ) && ( io_handle->minor_version == 2 ) ) { libcnotify_printf( "%s: unknown6\t\t\t\t\t: 0x%02" PRIx8 " 0x%02" PRIx8 " 0x%02" PRIx8 "\n", function, ( (msiecf_url_record_header_v52_t *) url_record_data )->unknown6[ 0 ], ( (msiecf_url_record_header_v52_t *) url_record_data )->unknown6[ 1 ], ( (msiecf_url_record_header_v52_t *) url_record_data )->unknown6[ 2 ] ); } libcnotify_printf( "%s: filename offset\t\t\t\t: %" PRIu32 "\n", function, filename_offset ); libcnotify_printf( "%s: cache entry flags\t\t\t\t: 0x%08" PRIx32 "\n", function, cache_entry_flags ); libmsiecf_debug_print_cache_entry_flags( cache_entry_flags ); libcnotify_printf( "\n" ); libcnotify_printf( "%s: data offset\t\t\t\t\t: %" PRIu32 "\n", function, data_offset ); libcnotify_printf( "%s: data size\t\t\t\t\t: %" PRIu32 "\n", function, data_size ); if( ( io_handle->major_version == 4 ) && ( io_handle->minor_version == 7 ) ) { byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v47_t *) url_record_data )->unknown8, value_32bit ); } else if( ( io_handle->major_version == 5 ) && ( io_handle->minor_version == 2 ) ) { byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v52_t *) url_record_data )->unknown8, value_32bit ); } libcnotify_printf( "%s: unknown8\t\t\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); if( ( io_handle->major_version == 4 ) && ( io_handle->minor_version == 7 ) ) { result = libfdatetime_fat_date_time_copy_from_byte_stream( fat_date_time, ( (msiecf_url_record_header_v47_t *) url_record_data )->last_checked_time, 4, LIBFDATETIME_ENDIAN_LITTLE, error ); } else if( ( io_handle->major_version == 5 ) && ( io_handle->minor_version == 2 ) ) { result = libfdatetime_fat_date_time_copy_from_byte_stream( fat_date_time, ( (msiecf_url_record_header_v52_t *) url_record_data )->last_checked_time, 4, LIBFDATETIME_ENDIAN_LITTLE, error ); } if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_CONVERSION, LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to copy FAT date time from byte stream.", function ); goto on_error; } #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) result = libfdatetime_fat_date_time_copy_to_utf16_string( fat_date_time, (uint16_t *) date_time_string, 32, LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME, error ); #else result = libfdatetime_fat_date_time_copy_to_utf8_string( fat_date_time, (uint8_t *) date_time_string, 32, LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_CONVERSION, LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to copy FAT date time to date time string.", function ); goto on_error; } libcnotify_printf( "%s: last checked time\t\t\t\t: %" PRIs_SYSTEM "\n", function, date_time_string ); libcnotify_printf( "%s: number of hits\t\t\t\t: %" PRIu32 "\n", function, url_values->number_of_hits ); if( ( io_handle->major_version == 4 ) && ( io_handle->minor_version == 7 ) ) { byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v47_t *) url_record_data )->unknown9, value_32bit ); } else if( ( io_handle->major_version == 5 ) && ( io_handle->minor_version == 2 ) ) { byte_stream_copy_to_uint32_little_endian( ( (msiecf_url_record_header_v52_t *) url_record_data )->unknown9, value_32bit ); } libcnotify_printf( "%s: unknown9\t\t\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); if( ( io_handle->major_version == 4 ) && ( io_handle->minor_version == 7 ) ) { result = libfdatetime_fat_date_time_copy_from_byte_stream( fat_date_time, ( (msiecf_url_record_header_v47_t *) url_record_data )->unknown_time, 4, LIBFDATETIME_ENDIAN_LITTLE, error ); } else if( ( io_handle->major_version == 5 ) && ( io_handle->minor_version == 2 ) ) { result = libfdatetime_fat_date_time_copy_from_byte_stream( fat_date_time, ( (msiecf_url_record_header_v52_t *) url_record_data )->unknown_time, 4, LIBFDATETIME_ENDIAN_LITTLE, error ); } if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_CONVERSION, LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to copy FAT date time from byte stream.", function ); goto on_error; } #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) result = libfdatetime_fat_date_time_copy_to_utf16_string( fat_date_time, (uint16_t *) date_time_string, 32, LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME, error ); #else result = libfdatetime_fat_date_time_copy_to_utf8_string( fat_date_time, (uint8_t *) date_time_string, 32, LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_CONVERSION, LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to create FAT date time string.", function ); goto on_error; } libcnotify_printf( "%s: unknown time\t\t\t\t\t: %" PRIs_SYSTEM "\n", function, date_time_string ); if( libfdatetime_filetime_free( &filetime, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free filetime.", function ); goto on_error; } if( libfdatetime_fat_date_time_free( &fat_date_time, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free FAT date time.", function ); goto on_error; } } #endif if( unknown_offset > 0 ) { if( unknown_offset > record_size ) { if( ( item_flags & LIBMSIECF_ITEM_FLAG_PARTIAL ) == 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, "%s: unknown offset exceeds URL record data.", function ); goto on_error; } else { memory_free( url_record_data ); return( 1 ); } } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: unknown:\n", function ); libcnotify_print_data( &( url_record_data[ unknown_offset ] ), 8, 0 ); } #endif } if( location_offset > 0 ) { if( location_offset > record_size ) { if( ( item_flags & LIBMSIECF_ITEM_FLAG_PARTIAL ) == 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, "%s: location offset exceeds size of URL record data.", function ); return( -1 ); } } else { if( libfvalue_value_type_initialize( &( url_values->location ), LIBFVALUE_VALUE_TYPE_STRING_BYTE_STREAM, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create location value.", function ); goto on_error; } value_size = libfvalue_value_type_set_data_string( url_values->location, &( url_record_data[ location_offset ] ), record_size - location_offset, io_handle->ascii_codepage, LIBFVALUE_VALUE_DATA_FLAG_MANAGED, error ); if( value_size == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set data of location value.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: location\t\t\t\t\t: ", function ); if( libfvalue_value_print( url_values->location, 0, 0, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, "%s: unable to print location value.", function ); goto on_error; } libcnotify_printf( "\n" ); if( libmsiecf_hash_calculate( &value_32bit, &( url_record_data[ location_offset ] ), record_size - location_offset, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, "%s: unable to calculate location hash.", function ); goto on_error; } libcnotify_printf( "%s: hash value\t\t\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); } #endif if( ( url_record_data[ location_offset + value_size - 1 ] != 0 ) && ( ( item_flags & LIBMSIECF_ITEM_FLAG_PARTIAL ) == 0 ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, "%s: unsupported unterminated location string.", function ); goto on_error; } if( url_values->type == LIBMSIECF_URL_ITEM_TYPE_UNDEFINED ) { if( value_size >= 18 ) { if( ( url_record_data[ location_offset ] == (uint8_t) ':' ) && ( url_record_data[ location_offset + 1 ] >= (uint8_t) '0' ) && ( url_record_data[ location_offset + 1 ] <= (uint8_t) '9' ) && ( url_record_data[ location_offset + 2 ] >= (uint8_t) '0' ) && ( url_record_data[ location_offset + 2 ] <= (uint8_t) '9' ) && ( url_record_data[ location_offset + 3 ] >= (uint8_t) '0' ) && ( url_record_data[ location_offset + 3 ] <= (uint8_t) '9' ) && ( url_record_data[ location_offset + 4 ] >= (uint8_t) '0' ) && ( url_record_data[ location_offset + 4 ] <= (uint8_t) '9' ) && ( url_record_data[ location_offset + 5 ] >= (uint8_t) '0' ) && ( url_record_data[ location_offset + 5 ] <= (uint8_t) '9' ) && ( url_record_data[ location_offset + 6 ] >= (uint8_t) '0' ) && ( url_record_data[ location_offset + 6 ] <= (uint8_t) '9' ) && ( url_record_data[ location_offset + 7 ] >= (uint8_t) '0' ) && ( url_record_data[ location_offset + 7 ] <= (uint8_t) '9' ) && ( url_record_data[ location_offset + 8 ] >= (uint8_t) '0' ) && ( url_record_data[ location_offset + 8 ] <= (uint8_t) '9' ) && ( url_record_data[ location_offset + 9 ] >= (uint8_t) '0' ) && ( url_record_data[ location_offset + 9 ] <= (uint8_t) '9' ) && ( url_record_data[ location_offset + 10 ] >= (uint8_t) '0' ) && ( url_record_data[ location_offset + 10 ] <= (uint8_t) '9' ) && ( url_record_data[ location_offset + 11 ] >= (uint8_t) '0' ) && ( url_record_data[ location_offset + 11 ] <= (uint8_t) '9' ) && ( url_record_data[ location_offset + 12 ] >= (uint8_t) '0' ) && ( url_record_data[ location_offset + 12 ] <= (uint8_t) '9' ) && ( url_record_data[ location_offset + 13 ] >= (uint8_t) '0' ) && ( url_record_data[ location_offset + 13 ] <= (uint8_t) '9' ) && ( url_record_data[ location_offset + 14 ] >= (uint8_t) '0' ) && ( url_record_data[ location_offset + 14 ] <= (uint8_t) '9' ) && ( url_record_data[ location_offset + 15 ] >= (uint8_t) '0' ) && ( url_record_data[ location_offset + 15 ] <= (uint8_t) '9' ) && ( url_record_data[ location_offset + 16 ] >= (uint8_t) '0' ) && ( url_record_data[ location_offset + 16 ] <= (uint8_t) '9' ) && ( url_record_data[ location_offset + 17 ] == (uint8_t) ':' ) ) { first_year = (uint16_t) url_record_data[ location_offset + 1 ] - (uint8_t) '0'; first_year *= 10; first_year += (uint16_t) url_record_data[ location_offset + 2 ] - (uint8_t) '0'; first_year *= 10; first_year += (uint16_t) url_record_data[ location_offset + 3 ] - (uint8_t) '0'; first_year *= 10; first_year += (uint16_t) url_record_data[ location_offset + 4 ] - (uint8_t) '0'; first_month = url_record_data[ location_offset + 5 ] - (uint8_t) '0'; first_month *= 10; first_month += url_record_data[ location_offset + 6 ] - (uint8_t) '0'; first_day_of_month = url_record_data[ location_offset + 7 ] - (uint8_t) '0'; first_day_of_month *= 10; first_day_of_month += url_record_data[ location_offset + 8 ] - (uint8_t) '0'; second_year = (uint16_t) url_record_data[ location_offset + 9 ] - (uint8_t) '0'; second_year *= 10; second_year += (uint16_t) url_record_data[ location_offset + 10 ] - (uint8_t) '0'; second_year *= 10; second_year += (uint16_t) url_record_data[ location_offset + 11 ] - (uint8_t) '0'; second_year *= 10; second_year += (uint16_t) url_record_data[ location_offset + 12 ] - (uint8_t) '0'; second_month = url_record_data[ location_offset + 13 ] - (uint8_t) '0'; second_month *= 10; second_month += url_record_data[ location_offset + 14 ] - (uint8_t) '0'; second_day_of_month = url_record_data[ location_offset + 15 ] - (uint8_t) '0'; second_day_of_month *= 10; second_day_of_month += url_record_data[ location_offset + 16 ] - (uint8_t) '0'; number_of_days = 0; if( first_year == second_year ) { if( first_month == second_month ) { if( first_day_of_month < second_day_of_month ) { number_of_days = second_day_of_month - first_day_of_month; } } else if( ( first_month + 1 ) == second_month ) { switch( first_month ) { case 3: case 5: case 7: case 8: case 10: case 12: number_of_days = ( 31 + second_day_of_month ) - first_day_of_month; break; case 2: if( ( ( ( first_year % 4 ) == 0 ) && ( ( first_year % 100 ) != 0 ) ) || ( ( first_year % 400 ) == 0 ) ) { number_of_days = ( 29 + second_day_of_month ) - first_day_of_month; } else { number_of_days = ( 28 + second_day_of_month ) - first_day_of_month; } break; case 4: case 6: case 9: case 11: number_of_days = ( 30 + second_day_of_month ) - first_day_of_month; break; } } } else if( ( first_year + 1 ) == second_year ) { if( ( first_month == 12 ) && ( second_month == 1 ) ) { number_of_days = ( 31 + second_day_of_month ) - first_day_of_month; } } if( number_of_days == 1 ) { url_values->type = LIBMSIECF_URL_ITEM_TYPE_HISTORY_DAILY; } else if( number_of_days == 7 ) { url_values->type = LIBMSIECF_URL_ITEM_TYPE_HISTORY_WEEKLY; } } } } if( url_values->type == LIBMSIECF_URL_ITEM_TYPE_UNDEFINED ) { if( value_size >= 11 ) { if( memory_compare( &( url_record_data[ location_offset ] ), "iedownload:", 11 ) == 0 ) { url_values->type = LIBMSIECF_URL_ITEM_TYPE_DOWNLOAD; } } } if( url_values->type == LIBMSIECF_URL_ITEM_TYPE_UNDEFINED ) { if( value_size >= 9 ) { if( memory_compare( &( url_record_data[ location_offset ] ), "DOMStore:", 9 ) == 0 ) { url_values->type = LIBMSIECF_URL_ITEM_TYPE_DOM_STORE; } else if( memory_compare( &( url_record_data[ location_offset ] ), "feedplat:", 9 ) == 0 ) { url_values->type = LIBMSIECF_URL_ITEM_TYPE_RSS_FEED; } else if( memory_compare( &( url_record_data[ location_offset ] ), "iecompat:", 9 ) == 0 ) { url_values->type = LIBMSIECF_URL_ITEM_TYPE_COMPATIBILITY; } else if( memory_compare( &( url_record_data[ location_offset ] ), "PrivacIE:", 9 ) == 0 ) { url_values->type = LIBMSIECF_URL_ITEM_TYPE_INPRIVATE_FILTERING; } else if( memory_compare( &( url_record_data[ location_offset ] ), "userdata:", 9 ) == 0 ) { url_values->type = LIBMSIECF_URL_ITEM_TYPE_USER_DATA; } } } if( url_values->type == LIBMSIECF_URL_ITEM_TYPE_UNDEFINED ) { if( value_size >= 8 ) { if( memory_compare( &( url_record_data[ location_offset ] ), "Visited:", 8 ) == 0 ) { url_values->type = LIBMSIECF_URL_ITEM_TYPE_HISTORY; } } } if( url_values->type == LIBMSIECF_URL_ITEM_TYPE_UNDEFINED ) { if( value_size >= 7 ) { if( memory_compare( &( url_record_data[ location_offset ] ), "Cookie:", 7 ) == 0 ) { url_values->type = LIBMSIECF_URL_ITEM_TYPE_COOKIE; } } } if( url_values->type == LIBMSIECF_URL_ITEM_TYPE_UNDEFINED ) { if( value_size >= 6 ) { if( memory_compare( &( url_record_data[ location_offset ] ), "ietld:", 6 ) == 0 ) { url_values->type = LIBMSIECF_URL_ITEM_TYPE_TLD; } } } if( url_values->type == LIBMSIECF_URL_ITEM_TYPE_UNDEFINED ) { url_values->type = LIBMSIECF_URL_ITEM_TYPE_CACHE; /* TODO way to determine unknown url_values->type = LIBMSIECF_URL_ITEM_TYPE_UNKNOWN; */ } } } if( filename_offset > 0 ) { if( filename_offset > record_size ) { if( ( item_flags & LIBMSIECF_ITEM_FLAG_PARTIAL ) == 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, "%s: filename offset exceeds size of URL record data.", function ); goto on_error; } } else { if( libfvalue_value_type_initialize( &( url_values->filename ), LIBFVALUE_VALUE_TYPE_STRING_BYTE_STREAM, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create filename value.", function ); goto on_error; } value_size = libfvalue_value_type_set_data_string( url_values->filename, &( url_record_data[ filename_offset ] ), record_size - filename_offset, io_handle->ascii_codepage, LIBFVALUE_VALUE_DATA_FLAG_MANAGED, error ); if( value_size == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set data of filename value.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: filename\t\t\t\t\t: ", function ); if( libfvalue_value_print( url_values->filename, 0, 0, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, "%s: unable to print filename value.", function ); goto on_error; } libcnotify_printf( "\n" ); } #endif if( ( url_record_data[ filename_offset + value_size - 1 ] != 0 ) && ( ( item_flags & LIBMSIECF_ITEM_FLAG_PARTIAL ) == 0 ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, "%s: unsupported unterminated filename string.", function ); goto on_error; } } } if( data_offset > 0 ) { if( data_offset > record_size ) { if( ( item_flags & LIBMSIECF_ITEM_FLAG_PARTIAL ) == 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, "%s: data offset exceeds size of URL record data.", function ); goto on_error; } } else { if( ( data_offset + data_size ) > record_size ) { if( ( item_flags & LIBMSIECF_ITEM_FLAG_PARTIAL ) == 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, "%s: data size exceeds size of URL record data.", function ); goto on_error; } else { data_size = record_size - data_offset; } } url_values->data_size = (size_t) data_size; url_values->data = (uint8_t *) memory_allocate( sizeof( uint8_t ) * url_values->data_size ); if( url_values->data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create data.", function ); goto on_error; } if( memory_copy( url_values->data, &( url_record_data[ data_offset ] ), url_values->data_size ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to copy data.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: data:\n", function ); libcnotify_print_data( &( url_record_data[ data_offset ] ), data_size, 0 ); if( url_values->type == LIBMSIECF_URL_ITEM_TYPE_CACHE ) { /* The data string in not necessarily terminated by an end-of-string character */ libcnotify_printf( "%s: data string\t\t\t\t\t: ", function ); for( string_index = 0; string_index < data_size; string_index++ ) { libcnotify_printf( "%c", url_record_data[ data_offset + string_index ] ); } libcnotify_printf( "\n" ); } else if( url_values->type == LIBMSIECF_URL_ITEM_TYPE_HISTORY ) { visited_entry_data = &( url_record_data[ data_offset ] ); do { visited_entry_index++; byte_stream_copy_to_uint16_little_endian( visited_entry_data, value_16bit ); visited_entry_data += 2; libcnotify_printf( "%s: data entry: %02d size\t\t\t\t: %" PRIu16 "\n", function, visited_entry_index, value_16bit ); libcnotify_printf( "%s: data entry: %02d type\t\t\t\t: 0x%02" PRIx8 " (%s : %s)\n", function, visited_entry_index, visited_entry_data[ 0 ], libmsiecf_property_type_get_identifier( NULL, (uint32_t) visited_entry_data[ 0 ], (uint32_t) visited_entry_data[ 1 ] ), libmsiecf_property_type_get_description( NULL, (uint32_t) visited_entry_data[ 0 ], (uint32_t) visited_entry_data[ 1 ] ) ); libcnotify_printf( "%s: data entry: %02d value type\t\t\t: 0x%02" PRIx8 " (%s : %s)\n", function, visited_entry_index, visited_entry_data[ 1 ], libfole_value_type_get_identifier( (uint32_t) visited_entry_data[ 1 ] ), libfole_value_type_get_description( (uint32_t) visited_entry_data[ 1 ] ) ); visited_entry_data += 2; if( value_16bit > 4 ) { value_16bit -= 4; libcnotify_printf( "%s: data entry: %02d value:\n", function, visited_entry_index ); libcnotify_print_data( visited_entry_data, value_16bit, 0 ); visited_entry_data += value_16bit; } } while( value_16bit > 0 ); } } #endif } } memory_free( url_record_data ); url_record_data = NULL; #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "\n" ); } #endif #if defined( HAVE_VERBOSE_OUTPUT ) switch( url_values->type ) { case LIBMSIECF_URL_ITEM_TYPE_COOKIE: if ( ( cache_entry_flags & LIBMSIECF_CACHE_ENTRY_FLAG_COOKIE ) == 0 ) { libcnotify_printf( "%s: detected type cookie but corresponding cache entry flag (COOKIE_CACHE_ENTRY) is not set.\n", function ); } break; case LIBMSIECF_URL_ITEM_TYPE_HISTORY: if ( ( cache_entry_flags & LIBMSIECF_CACHE_ENTRY_FLAG_URLHISTORY ) == 0 ) { libcnotify_printf( "%s: detected type history but corresponding cache entry flag (URLHISTORY_CACHE_ENTRY) is not set.\n", function ); } break; case LIBMSIECF_URL_ITEM_TYPE_HISTORY_DAILY: case LIBMSIECF_URL_ITEM_TYPE_HISTORY_WEEKLY: if ( ( cache_entry_flags & LIBMSIECF_CACHE_ENTRY_FLAG_URLHISTORY ) == 0 ) { libcnotify_printf( "%s: detected type history periodic but corresponding cache entry flag (URLHISTORY_CACHE_ENTRY) is not set.\n", function ); } break; } #endif return( 1 ); on_error: #if defined( HAVE_DEBUG_OUTPUT ) if( filetime != NULL ) { libfdatetime_filetime_free( &filetime, NULL ); } if( fat_date_time != NULL ) { libfdatetime_fat_date_time_free( &fat_date_time, NULL ); } #endif if( url_record_data != NULL ) { memory_free( url_record_data ); } return( -1 ); }