static int fewf_pwrite(disk_t *disk, const void *buffer, const unsigned int count, const uint64_t offset) { struct info_fewf_struct *data=(struct info_fewf_struct *)disk->data; int64_t taille; #if defined( HAVE_LIBEWF_V2_API ) taille = libewf_handle_write_random( data->handle, buffer, count, offset, NULL ); #else taille=libewf_write_random(data->handle, buffer, count, offset); #endif if(taille!=count) { log_error("fewf_pwrite(xxx,%u,buffer,%lu(%u/%u/%u)) write err: ", (unsigned)(count/disk->sector_size), (long unsigned)(offset/disk->sector_size), offset2cylinder(disk,offset), offset2head(disk,offset), offset2sector(disk,offset)); log_error("%s\n", strerror(errno)); return -1; } return taille; }
int main( int argc, char * const argv[] ) #endif { #ifndef HAVE_GLOB_H EWFGLOB *glob = NULL; int32_t glob_count = 0; #endif LIBEWF_HANDLE *handle = NULL; uint8_t *buffer = NULL; INT_T option = 0; int64_t count = 0; uint64_t size = 0; uint64_t alter_offset = 0; uint64_t alter_size = 0; uint8_t swap_byte_pairs = 0; uint8_t verbose = 0; ewfsignal_initialize(); fprintf( stderr, "ewfalter is for expirimental usage only.\n" ); ewfcommon_version_fprint( stderr, _S_LIBEWF_CHAR( "ewfalter" ) ); while( ( option = ewfgetopt( argc, argv, _S_CHAR_T( "hsqvV" ) ) ) != (INT_T) -1 ) { switch( option ) { case (INT_T) '?': default: fprintf( stderr, "Invalid argument: %" PRIs ".\n", argv[ optind ] ); usage(); return( EXIT_FAILURE ); case (INT_T) 'h': usage(); return( EXIT_SUCCESS ); case (INT_T) 's': swap_byte_pairs = 1; break; case (INT_T) 'q': break; case (INT_T) 'v': verbose = 1; break; case (INT_T) 'V': ewfcommon_copyright_fprint( stderr ); return( EXIT_SUCCESS ); } } if( optind == argc ) { fprintf( stderr, "Missing EWF image file(s).\n" ); usage(); return( EXIT_FAILURE ); } libewf_set_notify_values( stderr, verbose ); #ifndef HAVE_GLOB_H glob = ewfglob_alloc(); if( glob == NULL ) { fprintf( stderr, "Unable to create glob.\n" ); return( EXIT_FAILURE ); } glob_count = ewfglob_resolve( glob, &argv[ optind ], ( argc - optind ) ); if( glob_count <= 0 ) { fprintf( stderr, "Unable to resolve glob.\n" ); ewfglob_free( glob ); return( EXIT_FAILURE ); } handle = libewf_open( glob->results, glob->amount, LIBEWF_OPEN_READ_WRITE ); ewfglob_free( glob ); #else handle = libewf_open( &argv[ optind ], ( argc - optind ), LIBEWF_OPEN_READ_WRITE ); #endif if( handle == NULL ) { fprintf( stderr, "Unable to open EWF image file(s).\n" ); return( EXIT_FAILURE ); } if( libewf_set_swap_byte_pairs( handle, swap_byte_pairs ) != 1 ) { fprintf( stderr, "Unable to set swap byte pairs in handle.\n" ); return( EXIT_FAILURE ); } size = libewf_get_media_size( handle ); if( size == 0 ) { fprintf( stderr, "Error altering data from EWF file(s) - media size is 0.\n" ); return( EXIT_FAILURE ); } /* Request the necessary case data */ fprintf( stderr, "Information for alter required, please provide the necessary input\n" ); alter_offset = ewfcommon_get_user_input_size_variable( stderr, _S_LIBEWF_CHAR( "Start altering at offset" ), 0, size, 0 ); alter_size = ewfcommon_get_user_input_size_variable( stderr, _S_LIBEWF_CHAR( "Amount of bytes to alter" ), 0, size, size ); buffer = libewf_common_alloc( alter_size * sizeof( uint8_t ) ); if( buffer == NULL ) { fprintf( stderr, "Unable to allocate buffer.\n" ); if( libewf_close( handle ) != 0 ) { fprintf( stdout, "Unable to close EWF file handle.\n" ); } return( EXIT_FAILURE ); } if( libewf_common_memset( buffer, 'X', alter_size ) == NULL ) { fprintf( stderr, "Unable to set buffer.\n" ); if( libewf_close( handle ) != 0 ) { fprintf( stdout, "Unable to close EWF file handle.\n" ); } return( EXIT_FAILURE ); } count = libewf_write_random( handle, buffer, alter_size, alter_offset ); if( count <= -1 ) { fprintf( stderr, "Alteration failed.\n" ); if( libewf_close( handle ) != 0 ) { fprintf( stdout, "Unable to close EWF file handle.\n" ); } return( EXIT_FAILURE ); } fprintf( stderr, "Alteration completed.\n" ); if( libewf_close( handle ) != 0 ) { fprintf( stdout, "Unable to close EWF file handle.\n" ); return( EXIT_FAILURE ); } return( EXIT_SUCCESS ); }