Skip to content

Commit

Permalink
Changes to libmfdata for EWF write
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz committed Nov 23, 2020
1 parent 4bd6810 commit bd01ca2
Show file tree
Hide file tree
Showing 21 changed files with 1,028 additions and 190 deletions.
30 changes: 8 additions & 22 deletions ewftools/device_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -2811,13 +2811,13 @@ int device_handle_media_information_fprint(
*/
int device_handle_read_errors_fprint(
device_handle_t *device_handle,
uint32_t bytes_per_sector,
FILE *stream,
libcerror_error_t **error )
{
static char *function = "device_handle_read_errors_fprint";
off64_t read_error_offset = 0;
size64_t read_error_size = 0;
uint32_t bytes_per_sector = 0;
int number_of_read_errors = 0;
int read_error_index = 0;
int result = 1;
Expand All @@ -2833,38 +2833,24 @@ int device_handle_read_errors_fprint(

return( -1 );
}
if( stream == NULL )
if( bytes_per_sector == 0 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid stream.",
function );

return( -1 );
}
if( device_handle_get_bytes_per_sector(
device_handle,
&bytes_per_sector,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_GET_FAILED,
"%s: unable to retrieve bytes per sector.",
LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid bytes per sector value out of bounds.",
function );

return( -1 );
}
if( bytes_per_sector == 0 )
if( stream == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
"%s: invalid bytes per sector returned.",
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid stream.",
function );

return( -1 );
Expand Down
3 changes: 2 additions & 1 deletion ewftools/device_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ int device_handle_media_information_fprint(

int device_handle_read_errors_fprint(
device_handle_t *device_handle,
uint32_t bytes_per_sector,
FILE *stream,
libcerror_error_t **error );

Expand All @@ -294,5 +295,5 @@ int device_handle_tracks_fprint(
}
#endif

#endif
#endif /* !defined( _DEVICE_HANDLE_H ) */

30 changes: 24 additions & 6 deletions ewftools/ewfacquire.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ int ewfacquire_read_input(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
"%s: invalid imaging handle - acquire size value exceeds maximum.",
"%s: invalid imaging handle - acquiry size value exceeds maximum.",
function );

return( -1 );
Expand All @@ -640,14 +640,13 @@ int ewfacquire_read_input(

return( -1 );
}
if( ( imaging_handle->acquiry_size > imaging_handle->input_media_size )
|| ( imaging_handle->acquiry_size > (ssize64_t) INT64_MAX ) )
if( imaging_handle->acquiry_size > imaging_handle->input_media_size )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid acquire size value out of bounds.",
"%s: invalid acquiry size value exceeds input media size.",
function );

return( -1 );
Expand Down Expand Up @@ -1191,6 +1190,7 @@ int ewfacquire_read_input(
{
if( device_handle_read_errors_fprint(
device_handle,
ewfacquire_imaging_handle->bytes_per_sector,
imaging_handle->notify_stream,
error ) != 1 )
{
Expand Down Expand Up @@ -1221,6 +1221,7 @@ int ewfacquire_read_input(
{
if( device_handle_read_errors_fprint(
device_handle,
ewfacquire_imaging_handle->bytes_per_sector,
log_handle->log_stream,
error ) != 1 )
{
Expand Down Expand Up @@ -2007,11 +2008,20 @@ int main( int argc, char * const argv[] )
&( ewfacquire_imaging_handle->bytes_per_sector ),
&error ) != 1 )
{
ewfacquire_imaging_handle->bytes_per_sector = 512;

fprintf(
stderr,
"Unable to retrieve bytes per sector from device.\n" );
"Unable to retrieve bytes per sector from device defaulting to: %" PRIu32 ".\n",
ewfacquire_imaging_handle->bytes_per_sector );

#if defined( HAVE_VERBOSE_OUTPUT )
libcnotify_print_error_backtrace(
error );
#endif
libcerror_error_free(
&error );

goto on_error;
}
}
if( option_sectors_per_chunk != NULL )
Expand Down Expand Up @@ -2175,6 +2185,14 @@ int main( int argc, char * const argv[] )
*/
if( ewfacquire_imaging_handle->acquiry_size == 0 )
{
if( ewfacquire_imaging_handle->input_media_size == 0 )
{
fprintf(
stderr,
"Unable to determine input media size.\n" );

goto on_error;
}
ewfacquire_imaging_handle->acquiry_size = ewfacquire_imaging_handle->input_media_size
- ewfacquire_imaging_handle->acquiry_offset;
}
Expand Down
4 changes: 2 additions & 2 deletions ewftools/imaging_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -3052,10 +3052,10 @@ int imaging_handle_set_compression_values(
const system_character_t *string,
libcerror_error_t **error )
{
system_character_t *string_segment = NULL;
system_character_t *string_segment = NULL;
static char *function = "imaging_handle_set_compression_values";
size_t string_segment_size = 0;
size_t string_length = 0;
size_t string_segment_size = 0;
int number_of_segments = 0;
int result = 0;
int segment_index = 0;
Expand Down
2 changes: 1 addition & 1 deletion libewf/ewf_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@
*/
#define EWF_MAXIMUM_OFFSETS_IN_TABLE_ENCASE6 65534

#endif
#endif /* !defined( _EWF_DEFINIONS_H ) */

2 changes: 1 addition & 1 deletion libewf/libewf_compression.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ int libewf_decompress_data(
result = -1;
}
#else
result = libewf_deflate_decompress(
result = libewf_deflate_decompress_zlib(
compressed_data,
compressed_data_size,
uncompressed_data,
Expand Down
2 changes: 1 addition & 1 deletion libewf/libewf_deflate.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extern "C" {
enum LIBEWF_DEFLATE_BLOCK_TYPES
{
LIBEWF_DEFLATE_BLOCK_TYPE_UNCOMPRESSED = 0x00,
LIBEWF_DEFLATE_BLOCK_TYPE_HUFFMAN_FIXED = 0x01,
LIBEWF_DEFLATE_BLOCK_TYPE_HUFFMAN_FIXED = 0x01,
LIBEWF_DEFLATE_BLOCK_TYPE_HUFFMAN_DYNAMIC = 0x02,
LIBEWF_DEFLATE_BLOCK_TYPE_RESERVED = 0x03
};
Expand Down
16 changes: 8 additions & 8 deletions libewf/libewf_section.c
Original file line number Diff line number Diff line change
Expand Up @@ -6702,42 +6702,42 @@ ssize_t libewf_section_volume_e01_write(
if( libcnotify_verbose != 0 )
{
libcnotify_printf(
"%s: media type\t\t\t\t\t: 0x%02" PRIx8 "\n",
"%s: media type\t\t\t\t: 0x%02" PRIx8 "\n",
function,
media_values->media_type );

libcnotify_printf(
"%s: number of chunks\t\t\t\t: %" PRIu32 "\n",
"%s: number of chunks\t\t\t: %" PRIu32 "\n",
function,
media_values->number_of_chunks );

libcnotify_printf(
"%s: sectors per chunk\t\t\t\t: %" PRIu32 "\n",
"%s: sectors per chunk\t\t\t: %" PRIu32 "\n",
function,
media_values->sectors_per_chunk );

libcnotify_printf(
"%s: bytes per sector\t\t\t\t: %" PRIu32 "\n",
"%s: bytes per sector\t\t\t: %" PRIu32 "\n",
function,
media_values->bytes_per_sector );

libcnotify_printf(
"%s: number of sectors\t\t: %" PRIu64 "\n",
"%s: number of sectors\t\t\t: %" PRIu64 "\n",
function,
media_values->number_of_sectors );

libcnotify_printf(
"%s: media flags\t\t\t\t\t: 0x%02" PRIx8 "\n",
"%s: media flags\t\t\t\t: 0x%02" PRIx8 "\n",
function,
media_values->media_flags );

libcnotify_printf(
"%s: compression level\t\t\t\t: 0x%02" PRIx8 "\n",
"%s: compression level\t\t\t: 0x%02" PRIx8 "\n",
function,
io_handle->compression_level );

libcnotify_printf(
"%s: error granularity\t\t\t\t: %" PRIu32 "\n",
"%s: error granularity\t\t\t: %" PRIu32 "\n",
function,
media_values->error_granularity );

Expand Down
2 changes: 1 addition & 1 deletion libewf/libewf_write_io_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ int libewf_write_io_handle_initialize_resume(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: number of unusable chunk cannot be greater than number of chunk.",
"%s: number of unusable chunks cannot be greater than number of chunks.",
function );

return( -1 );
Expand Down
2 changes: 1 addition & 1 deletion libmfdata/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ AM_CPPFLAGS = \
noinst_LTLIBRARIES = libmfdata.la

libmfdata_la_SOURCES = \
libmfdata_array.c libmfdata_array.h \
libmfdata_date_time.h \
libmfdata_definitions.h \
libmfdata_error.c libmfdata_error.h \
Expand All @@ -24,7 +25,6 @@ libmfdata_la_SOURCES = \
libmfdata_group.c libmfdata_group.h \
libmfdata_inline.h \
libmfdata_libbfio.h \
libmfdata_libcdata.h \
libmfdata_libcerror.h \
libmfdata_libcnotify.h \
libmfdata_libfcache.h \
Expand Down
Loading

0 comments on commit bd01ca2

Please sign in to comment.