/* Read from a handle in the pool * Returns the amount of bytes read or -1 on error */ ssize_t libbfio_pool_read( libbfio_pool_t *pool, int entry, uint8_t *buffer, size_t size, liberror_error_t **error ) { libbfio_internal_pool_t *internal_pool = NULL; static char *function = "libbfio_pool_read"; ssize_t read_count = 0; int flags = 0; int is_open = 0; if( pool == NULL ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_ARGUMENTS, LIBERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid pool.", function ); return( -1 ); } internal_pool = (libbfio_internal_pool_t *) pool; if( internal_pool->handles == NULL ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_RUNTIME, LIBERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid pool - missing handles.", function ); return( -1 ); } if( ( entry < 0 ) || ( entry >= internal_pool->amount_of_handles ) ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_ARGUMENTS, LIBERROR_ARGUMENT_ERROR_VALUE_OUT_OF_RANGE, "%s: invalid entry.", function ); return( -1 ); } /* Make sure the handle is open */ is_open = libbfio_handle_is_open( internal_pool->handles[ entry ], error ); if( is_open == -1 ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_RUNTIME, LIBERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine if entry: %d is open.", function, entry ); return( -1 ); } else if( is_open == 0 ) { if( libbfio_handle_get_flags( internal_pool->handles[ entry ], &flags, error ) != 1 ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_RUNTIME, LIBERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve flags.", function ); return( -1 ); } if( libbfio_pool_open_handle( internal_pool, internal_pool->handles[ entry ], flags, error ) != 1 ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_IO, LIBERROR_IO_ERROR_OPEN_FAILED, "%s: unable to open entry: %d.", function, entry ); return( -1 ); } } read_count = libbfio_handle_read( internal_pool->handles[ entry ], buffer, size, error ); if( read_count < 0 ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_IO, LIBERROR_IO_ERROR_READ_FAILED, "%s: unable to read from entry: %d.", function, entry ); return( -1 ); } return( read_count ); }
/* Determines if a file is an EDB file (check for the EDB file signature) using a Basic File IO (bfio) handle * Returns 1 if true, 0 if not or -1 on error */ int libesedb_check_file_signature_file_io_handle( libbfio_handle_t *file_io_handle, liberror_error_t **error ) { uint8_t signature[ 4 ]; static char *function = "libesedb_check_file_signature_file_io_handle"; ssize_t read_count = 0; int file_io_handle_is_open = 0; if( file_io_handle == NULL ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_ARGUMENTS, LIBERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid file IO handle.", function ); return( -1 ); } file_io_handle_is_open = libbfio_handle_is_open( file_io_handle, error ); if( file_io_handle_is_open == -1 ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_IO, LIBERROR_IO_ERROR_OPEN_FAILED, "%s: unable to open file.", function ); return( -1 ); } else if( file_io_handle_is_open == 0 ) { if( libbfio_handle_open( file_io_handle, LIBBFIO_OPEN_READ, error ) != 1 ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_IO, LIBERROR_IO_ERROR_OPEN_FAILED, "%s: unable to open file.", function ); return( -1 ); } } if( libbfio_handle_seek_offset( file_io_handle, 4, SEEK_SET, error ) == -1 ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_IO, LIBERROR_IO_ERROR_SEEK_FAILED, "%s: unable to seek file header offset: 4.", function ); if( file_io_handle_is_open == 0 ) { libbfio_handle_close( file_io_handle, error ); } return( -1 ); } read_count = libbfio_handle_read( file_io_handle, signature, 4, error ); if( read_count != 4 ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_IO, LIBERROR_IO_ERROR_READ_FAILED, "%s: unable to read signature.", function ); if( file_io_handle_is_open == 0 ) { libbfio_handle_close( file_io_handle, error ); } return( -1 ); } if( file_io_handle_is_open == 0 ) { if( libbfio_handle_close( file_io_handle, error ) != 0 ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_IO, LIBERROR_IO_ERROR_CLOSE_FAILED, "%s: unable to close file.", function ); return( -1 ); } } if( memory_compare( esedb_file_signature, signature, 4 ) == 0 ) { return( 1 ); } return( 0 ); }