/* Prints a backtrace of the error to the stream * Returns the number of printed characters if successful or -1 on error */ int libvmdk_error_backtrace_fprint( libvmdk_error_t *error, FILE *stream ) { return( libcerror_error_backtrace_fprint( (libcerror_error_t *) error, stream ) ); }
/* Prints a backtrace of the error to the stream * Returns the number of printed characters if successful or -1 on error */ int libqcow_error_backtrace_fprint( libqcow_error_t *error, FILE *stream ) { int print_count = 0; print_count = libcerror_error_backtrace_fprint( (libcerror_error_t *) error, stream ); return( print_count ); }
/* Tests libvshadow_store_seek_offset * Returns 1 if successful, 0 if not or -1 on error */ int vshadow_test_seek_offset( libvshadow_store_t *store, off64_t input_offset, int input_whence, off64_t expected_offset ) { libcerror_error_t *error = NULL; off64_t result_offset = 0; int result = 0; if( store == NULL ) { return( -1 ); } result_offset = libvshadow_store_seek_offset( store, input_offset, input_whence, &error ); if( expected_offset != result_offset ) { fprintf( stderr, "Unexpected result offset: %" PRIi64 "\n", result_offset ); } else { result = 1; } if( error != NULL ) { if( result != 1 ) { libcerror_error_backtrace_fprint( error, stderr ); } libcerror_error_free( &error ); } return( result ); }
/* Tests libewf_handle_seek_offset * Returns 1 if successful, 0 if not or -1 on error */ int ewf_test_seek_offset( libewf_handle_t *handle, off64_t input_offset, int input_whence, off64_t output_offset ) { libcerror_error_t *error = NULL; const char *whence_string = NULL; off64_t result_offset = 0; int result = 0; if( handle == NULL ) { return( -1 ); } if( input_whence == SEEK_CUR ) { whence_string = "SEEK_CUR"; } else if( input_whence == SEEK_END ) { whence_string = "SEEK_END"; } else if( input_whence == SEEK_SET ) { whence_string = "SEEK_SET"; } else { whence_string = "UNKNOWN"; } fprintf( stdout, "Testing seek of offset: %" PRIi64 " and whence: %s\t", input_offset, whence_string ); result_offset = libewf_handle_seek_offset( handle, input_offset, input_whence, &error ); if( result_offset == output_offset ) { result = 1; } if( result != 0 ) { fprintf( stdout, "(PASS)" ); } else { fprintf( stdout, "(FAIL)" ); } fprintf( stdout, "\n" ); if( error != NULL ) { if( result != 1 ) { libcerror_error_backtrace_fprint( error, stderr ); } libcerror_error_free( &error ); } return( result ); }
/* Tests single open and close of a file * Returns 1 if successful, 0 if not or -1 on error */ int lnk_test_single_open_close_file( libcstring_system_character_t *filename, int access_flags, int expected_result ) { libcerror_error_t *error = NULL; liblnk_file_t *file = NULL; static char *function = "lnk_test_single_open_close_file"; char *access_string = NULL; int result = 0; if( access_flags == LIBLNK_OPEN_READ ) { access_string = "read"; } else if( access_flags == LIBLNK_OPEN_WRITE ) { access_string = "write"; } else { access_string = "UNKNOWN"; } fprintf( stdout, "Testing single open close of: " ); if( filename != NULL ) { fprintf( stdout, "%" PRIs_LIBCSTRING_SYSTEM "", filename ); } else { fprintf( stdout, "NULL" ); } fprintf( stdout, " with access: %s\t", access_string ); if( liblnk_file_initialize( &file, &error ) != 1 ) { libcerror_error_set( &error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create file.", function ); goto on_error; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = liblnk_file_open_wide( file, filename, access_flags, &error ); #else result = liblnk_file_open( file, filename, access_flags, &error ); #endif if( result == 1 ) { if( liblnk_file_close( file, &error ) != 0 ) { libcerror_error_set( &error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_CLOSE_FAILED, "%s: unable to close file.", function ); goto on_error; } } if( liblnk_file_free( &file, &error ) != 1 ) { libcerror_error_set( &error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free file.", function ); goto on_error; } result = ( expected_result == result ); if( result == 1 ) { fprintf( stdout, "(PASS)" ); } else { fprintf( stdout, "(FAIL)" ); } fprintf( stdout, "\n" ); if( error != NULL ) { libcerror_error_backtrace_fprint( error, stderr ); libcerror_error_free( &error ); } return( result ); on_error: if( error != NULL ) { libcerror_error_backtrace_fprint( error, stderr ); libcerror_error_free( &error ); } if( file != NULL ) { liblnk_file_free( &file, NULL); } return( -1 ); }
/* Tests single open and close of a handle * Returns 1 if successful, 0 if not or -1 on error */ int vslvm_test_single_open_close_handle( libcstring_system_character_t *filename, int access_flags, int expected_result ) { libcerror_error_t *error = NULL; libvslvm_handle_t *handle = NULL; static char *function = "vslvm_test_single_open_close_handle"; int result = 0; if( libvslvm_handle_initialize( &handle, &error ) != 1 ) { libcerror_error_set( &error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create handle.", function ); return( -1 ); } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libvslvm_handle_open_wide( handle, filename, access_flags, &error ); #else result = libvslvm_handle_open( handle, filename, access_flags, &error ); #endif if( result == 1 ) { if( libvslvm_handle_close( handle, &error ) != 0 ) { libcerror_error_set( &error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_CLOSE_FAILED, "%s: unable to close handle.", function ); result = -1; } } if( libvslvm_handle_free( &handle, &error ) != 1 ) { libcerror_error_set( &error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free handle.", function ); result = -1; } result = ( expected_result == result ); if( result == 1 ) { fprintf( stdout, "(PASS)" ); } else { fprintf( stdout, "(FAIL)" ); } fprintf( stdout, "\n" ); if( error != NULL ) { if( result != 1 ) { libcerror_error_backtrace_fprint( error, stderr ); } libcerror_error_free( &error ); } return( result ); }
/* Tests reading chunks at a specific offset * Returns 1 if successful, 0 if not or -1 on error */ int ewf_test_read_chunk_at_offset( libewf_handle_t *handle, size32_t chunk_size, off64_t input_offset, int input_whence, size64_t input_size, off64_t expected_offset, size64_t expected_size ) { libcerror_error_t *error = NULL; uint8_t *chunk_buffer = NULL; uint8_t *data_buffer = NULL; const char *whence_string = NULL; size_t chunk_buffer_size = 0; size_t data_buffer_size = 0; int result = 0; if( chunk_size == 0 ) { return( -1 ); } #if SIZEOF_SIZE_T < 8 if( (size_t) chunk_size > (size_t) SSIZE_MAX ) { return( -1 ); } #endif if( input_whence == SEEK_CUR ) { whence_string = "SEEK_CUR"; } else if( input_whence == SEEK_END ) { whence_string = "SEEK_END"; } else if( input_whence == SEEK_SET ) { whence_string = "SEEK_SET"; } else { whence_string = "UNKNOWN"; } fprintf( stdout, "Testing reading range with offset: %" PRIi64 ", whence: %s and size: %" PRIu64 "\t", input_offset, whence_string, input_size ); result = ewf_test_seek_offset( handle, input_offset, input_whence, expected_offset, &error ); data_buffer_size = chunk_size; data_buffer = (uint8_t *) memory_allocate( sizeof( uint8_t ) * data_buffer_size ); /* The chunk buffer should at least have a size of: chunk_size + 16 */ chunk_buffer_size = chunk_size * 2; chunk_buffer = (uint8_t *) memory_allocate( sizeof( uint8_t ) * chunk_buffer_size ); if( result == 1 ) { if( input_offset >= 0 ) { result = ewf_test_read_chunk( handle, data_buffer, data_buffer_size, chunk_buffer, chunk_buffer_size, input_size, expected_size, &error ); } } memory_free( chunk_buffer ); memory_free( data_buffer ); if( result == 1 ) { if( input_offset >= 0 ) { result = ewf_test_get_offset( handle, input_offset - ( input_offset % chunk_size ) + expected_size, &error ); } } if( result != 0 ) { fprintf( stdout, "(PASS)" ); } else { fprintf( stdout, "(FAIL)" ); } fprintf( stdout, "\n" ); if( result == -1 ) { libcerror_error_backtrace_fprint( error, stderr ); libcerror_error_free( &error ); } return( result ); }
/* Tests reading a buffers at a specific offset * Returns 1 if successful, 0 if not or -1 on error */ int ewf_test_read_buffer_at_offset( libewf_handle_t *handle, off64_t input_offset, int input_whence, size64_t input_size, off64_t expected_offset, size64_t expected_size ) { libcerror_error_t *error = NULL; uint8_t *buffer = NULL; const char *whence_string = NULL; int result = 0; if( input_whence == SEEK_CUR ) { whence_string = "SEEK_CUR"; } else if( input_whence == SEEK_END ) { whence_string = "SEEK_END"; } else if( input_whence == SEEK_SET ) { whence_string = "SEEK_SET"; } else { whence_string = "UNKNOWN"; } fprintf( stdout, "Testing reading range with offset: %" PRIi64 ", whence: %s and size: %" PRIu64 "\t", input_offset, whence_string, input_size ); buffer = (uint8_t *) memory_allocate( EWF_TEST_BUFFER_SIZE ); result = ewf_test_seek_offset( handle, input_offset, input_whence, expected_offset, &error ); if( result == 1 ) { if( input_offset >= 0 ) { result = ewf_test_read_buffer( handle, buffer, EWF_TEST_BUFFER_SIZE, input_size, expected_size, &error ); } } if( result == 1 ) { if( input_offset >= 0 ) { result = ewf_test_get_offset( handle, input_offset + expected_size, &error ); } } memory_free( buffer ); if( result != 0 ) { fprintf( stdout, "(PASS)" ); } else { fprintf( stdout, "(FAIL)" ); } fprintf( stdout, "\n" ); if( result == -1 ) { libcerror_error_backtrace_fprint( error, stderr ); libcerror_error_free( &error ); } return( result ); }
/* Tests libvshadow_store_read_buffer * Returns 1 if successful, 0 if not or -1 on error */ int vshadow_test_read_buffer( libvshadow_store_t *store, size64_t input_size, size64_t expected_size ) { uint8_t buffer[ VSHADOW_TEST_READ_BUFFER_SIZE ]; libcerror_error_t *error = NULL; size64_t remaining_size = 0; size64_t result_size = 0; size_t read_size = 0; ssize_t read_count = 0; int result = 0; if( store == NULL ) { return( -1 ); } remaining_size = input_size; while( remaining_size > 0 ) { read_size = VSHADOW_TEST_READ_BUFFER_SIZE; if( remaining_size < (size64_t) read_size ) { read_size = (size_t) remaining_size; } read_count = libvshadow_store_read_buffer( store, buffer, read_size, &error ); if( read_count < 0 ) { break; } remaining_size -= (size64_t) read_count; result_size += (size64_t) read_count; if( read_count != (ssize_t) read_size ) { break; } } if( expected_size != result_size ) { fprintf( stderr, "Unexpected read count: %" PRIu64 "\n", result_size ); } else { result = 1; } if( error != NULL ) { if( result != 1 ) { libcerror_error_backtrace_fprint( error, stderr ); } libcerror_error_free( &error ); } return( result ); }
/* Tests libvshadow_store_read_buffer_at_offset * Returns 1 if successful, 0 if not or -1 on error */ int vshadow_test_read_buffer_at_offset( libvshadow_store_t *store, off64_t input_offset, size64_t input_size, off64_t expected_offset, size64_t expected_size ) { uint8_t buffer[ VSHADOW_TEST_READ_BUFFER_SIZE ]; libcerror_error_t *error = NULL; off64_t result_offset = 0; size64_t remaining_size = 0; size64_t result_size = 0; size_t read_size = 0; ssize_t read_count = 0; int result = 0; if( store == NULL ) { return( -1 ); } remaining_size = input_size; fprintf( stdout, "Testing reading buffer at offset: %" PRIi64 " and size: %" PRIu64 "\t", input_offset, input_size ); while( remaining_size > 0 ) { read_size = VSHADOW_TEST_READ_BUFFER_SIZE; if( remaining_size < (size64_t) read_size ) { read_size = (size_t) remaining_size; } read_count = libvshadow_store_read_buffer_at_offset( store, buffer, read_size, input_offset, &error ); if( read_count < 0 ) { break; } input_offset += (size64_t) read_count; remaining_size -= (size64_t) read_count; result_size += (size64_t) read_count; if( read_count != (ssize_t) read_size ) { break; } } if( libvshadow_store_get_offset( store, &result_offset, &error ) != 1 ) { result = -1; } if( expected_offset != result_offset ) { fprintf( stderr, "Unexpected offset: %" PRIi64 "\n", result_offset ); } else if( expected_size != result_size ) { fprintf( stderr, "Unexpected read count: %" PRIu64 "\n", result_size ); } else { result = 1; } if( result == 1 ) { fprintf( stdout, "(PASS)" ); } else { fprintf( stdout, "(FAIL)" ); } fprintf( stdout, "\n" ); if( error != NULL ) { if( result != 1 ) { libcerror_error_backtrace_fprint( error, stderr ); } libcerror_error_free( &error ); } return( result ); }
int main( int argc, char * const argv[] ) #endif { libcerror_error_t *error = NULL; libcfile_file_t *file = NULL; libcstring_system_character_t *source = NULL; size64_t file_size = 0; if( argc < 2 ) { fprintf( stderr, "Missing filename.\n" ); return( EXIT_FAILURE ); } source = argv[ 1 ]; #if defined( HAVE_DEBUG_OUTPUT ) && defined( CFILE_TEST_READ_VERBOSE ) libcfile_notify_set_verbose( 1 ); libcfile_notify_set_file( stderr, NULL ); #endif /* Test file read */ if( libcfile_file_initialize( &file, &error ) != 1 ) { fprintf( stderr, "Unable to create file.\n" ); goto on_error; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) if( libcfile_file_open_wide( file, source, LIBCFILE_OPEN_READ, &error ) != 1 ) #else if( libcfile_file_open( file, source, LIBCFILE_OPEN_READ, &error ) != 1 ) #endif { fprintf( stderr, "Unable to open file.\n" ); goto on_error; } if( libcfile_file_get_size( file, &file_size, &error ) != 1 ) { fprintf( stderr, "Unable to retrieve file size.\n" ); goto on_error; } fprintf( stdout, "File size: %" PRIu64 " bytes\n", file_size ); if( cfile_file_test_read_from_file( file, file_size ) != 1 ) { fprintf( stderr, "Unable to read from file.\n" ); goto on_error; } if( libcfile_file_close( file, &error ) != 0 ) { fprintf( stderr, "Unable to close file.\n" ); goto on_error; } if( libcfile_file_free( &file, &error ) != 1 ) { fprintf( stderr, "Unable to free file.\n" ); goto on_error; } /* Test file read with block size */ if( libcfile_file_initialize( &file, &error ) != 1 ) { fprintf( stderr, "Unable to create file.\n" ); goto on_error; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) if( libcfile_file_open_wide( file, source, LIBCFILE_OPEN_READ, &error ) != 1 ) #else if( libcfile_file_open( file, source, LIBCFILE_OPEN_READ, &error ) != 1 ) #endif { fprintf( stderr, "Unable to open file.\n" ); goto on_error; } if( libcfile_file_get_size( file, &file_size, &error ) != 1 ) { fprintf( stderr, "Unable to retrieve file size.\n" ); goto on_error; } fprintf( stdout, "File size: %" PRIu64 " bytes\n", file_size ); if( libcfile_file_set_block_size( file, 512, &error ) != 1 ) { fprintf( stderr, "Unable to set block size.\n" ); goto on_error; } if( cfile_file_test_read_from_file( file, file_size ) != 1 ) { fprintf( stderr, "Unable to read from file.\n" ); goto on_error; } if( libcfile_file_close( file, &error ) != 0 ) { fprintf( stderr, "Unable to close file.\n" ); goto on_error; } if( libcfile_file_free( &file, &error ) != 1 ) { fprintf( stderr, "Unable to free file.\n" ); goto on_error; } return( EXIT_SUCCESS ); on_error: if( error != NULL ) { libcerror_error_backtrace_fprint( error, stderr ); libcerror_error_free( &error ); } if( file != NULL ) { libcfile_file_close( file, NULL ); libcfile_file_free( &file, NULL ); } return( EXIT_FAILURE ); }
/* Tests initializing a lock * Make sure the value lock is referencing, is set to NULL * Returns 1 if successful, 0 if not or -1 on error */ int cthreads_test_lock_initialize( libcthreads_lock_t **lock, int expected_result ) { libcerror_error_t *error = NULL; static char *function = "cthreads_test_lock_initialize"; int result = 0; fprintf( stdout, "Testing initialize\t" ); result = libcthreads_lock_initialize( lock, &error ); if( result == -1 ) { libcerror_error_set( &error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create lock.", function ); } if( result != expected_result ) { fprintf( stdout, "(FAIL)" ); } else { fprintf( stdout, "(PASS)" ); } fprintf( stdout, "\n" ); if( result == -1 ) { libcerror_error_backtrace_fprint( error, stdout ); libcerror_error_free( &error ); } if( result == 1 ) { if( libcthreads_lock_free( lock, &error ) == -1 ) { libcerror_error_set( &error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free lock.", function ); libcerror_error_backtrace_fprint( error, stdout ); libcerror_error_free( &error ); return( -1 ); } } if( result != expected_result ) { return( 0 ); } return( 1 ); }
int main( int argc, char * const argv[] ) #endif { libcerror_error_t *error = NULL; liblnk_file_t *file = NULL; size_t string_length = 0; uint32_t feature_flags = 0; int ascii_codepage = 0; int result = 0; if( argc != 2 ) { fprintf( stderr, "Unsupported number of arguments.\n" ); return( EXIT_FAILURE ); } feature_flags = LIBCLOCALE_CODEPAGE_FEATURE_FLAG_HAVE_ISO_8859 | LIBCLOCALE_CODEPAGE_FEATURE_FLAG_HAVE_KOI8 | LIBCLOCALE_CODEPAGE_FEATURE_FLAG_HAVE_WINDOWS; string_length = libcstring_system_string_length( argv[ 1 ] ); #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libclocale_codepage_copy_from_string_wide( &ascii_codepage, argv[ 1 ], string_length, feature_flags, &error ); #else result = libclocale_codepage_copy_from_string( &ascii_codepage, argv[ 1 ], string_length, feature_flags, &error ); #endif if( result == -1 ) { fprintf( stderr, "Unable to determine ASCII codepage from: %" PRIs_LIBCSTRING_SYSTEM ".\n", argv[ 1 ] ); goto on_error; } if( liblnk_file_initialize( &file, &error ) != 1 ) { fprintf( stderr, "Unable to create file.\n" ); goto on_error; } if( liblnk_file_set_ascii_codepage( file, ascii_codepage, &error ) != 1 ) { fprintf( stderr, "Unable to set codepage: %" PRIs_LIBCSTRING_SYSTEM ".\n", argv[ 1 ] ); goto on_error; } if( liblnk_file_free( &file, &error ) != 1 ) { fprintf( stderr, "Unable to free file.\n" ); goto on_error; } return( EXIT_SUCCESS ); on_error: if( error != NULL ) { libcerror_error_backtrace_fprint( error, stdout ); libcerror_error_free( &error ); } if( file != NULL ) { liblnk_file_free( &file, NULL ); } return( -1 ); }
int main( int argc, char * const argv[] ) #endif { #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) wchar_t *full_path = NULL; #else char *full_path = NULL; #endif libcerror_error_t *error = NULL; size_t full_path_size = 0; if( argc < 2 ) { fprintf( stderr, "Missing filename.\n" ); return( EXIT_FAILURE ); } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) if( libcpath_path_get_full_path_wide( argv[ 1 ], libcstring_wide_string_length( argv[ 1 ] ), &full_path, &full_path_size, &error ) != 1 ) #else if( libcpath_path_get_full_path( argv[ 1 ], libcstring_narrow_string_length( argv[ 1 ] ), &full_path, &full_path_size, &error ) != 1 ) #endif { fprintf( stderr, "Unable to determine full path.\n" ); goto on_error; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) fprintf( stdout, "%ls", full_path ); #else fprintf( stdout, "%s", full_path ); #endif memory_free( full_path ); return( EXIT_SUCCESS ); on_error: if( error != NULL ) { libcerror_error_backtrace_fprint( error, stderr ); libcerror_error_free( &error ); } if( full_path != NULL ) { memory_free( full_path ); } return( EXIT_FAILURE ); }