libyal / libewf

Libewf is a library to access the Expert Witness Compression Format (EWF)
GNU Lesser General Public License v3.0
263 stars 76 forks source link

How do I use the library? #193

Closed ishitar2021 closed 10 months ago

ishitar2021 commented 10 months ago

Test code for my compressed imaging using libewf library. I am need a test code for my project which is disk imaging of storage media. And my purpose is build a code for compressed imaging using this library. So i understood that ewfacquire is used and found that ewfqcquire.c is the main c file that i used, am i correct?

can anyone help me with what all functions has to be called for my test code and its flow to get E01 files of my storage media.

Thanks in advance.

joachimmetz commented 10 months ago

@ishitar2021 you'll have to be more specific, if you want people to be able to help you.

I am need a test code for my project which is disk imaging of storage media.

what is your project? where can someone find the source? what license has the source?

So i understood that ewfacquire is used and found that ewfqcquire.c is the main c file that i used, am i correct?

What do you mean with "main c file" ? the C source code file that contains the entry point (main function)?

can anyone help me with what all functions has to be called for my test code

this highly depends on your source code, or is your question on how to use libewf to create an EWF image file set ?

ishitar2021 commented 10 months ago

I am need a test code for my project which is disk imaging of storage media.

what is your project? where can someone find the source? what license has the source?

my project is based on imaging disk or storage media for forensic purpose. so my firmware do imaging task with file format DD , but now my requirement is to integrate this EWF compression mode of imaging technique so the file format will be E01 ,to compress my imaging files .

What do you mean with "main c file" ? the C source code file that contains the entry point (main function)? I NEED A TEST code with a main function in thaat the compression function should be written with all the parameters required. so how can i do that?

this highly depends on your source code, or is your question on how to use libewf to create an EWF image file set ? how to use libewf library to get the compressed image file

joachimmetz commented 10 months ago

@ishitar2021 you'll need to be more specific, I cannot help you otherwise.

ishitar2021 commented 10 months ago

@ishitar2021 you'll need to be more specific, I cannot help you otherwise.

my project is based on imaging disk or storage media for forensic purpose. so my firmware do imaging task with file format DD , but now my requirement is to integrate this EWF compression mode of imaging technique so the file format will be E01 ,to compress my imaging files .

I NEED A TEST code with a main function in thaat the compression function should be written with all the parameters required. so how can i do that?how to use libewf library to get the compressed image file. a sample i have done is this correct?

#include <libewf.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <memory.h>
//#include "libewf_handle.h"
 //#include"common.h"

#include <memory.h>

/*
  ewfacquire -t /home/pooja/Desktop/pooja/WORK/EWF/EWF_Sample/pooja_ewf /dev/sdb1
ewfacquire 20140608

Device information:
Bus type:               USB
Vendor:                 SanDisk
Model:                  Cruzer Blade
Serial:                 4C530000060928115490

Storage media information:
Type:                   Device
Media type:             Removable
Media size:             15 GB (15662579712 bytes)
Bytes per sector:           512
*/
#define EWF_TEST_WRITE_BUFFER_SIZE      100

int main()
{
        libewf_error_t **error=0;
        libewf_handle_t *handle = NULL;
        uint8_t *buffer         = NULL;
        static char *function   = "ewf_test_write";
       size_t write_size       = 0;
        ssize_t write_count     = 0;
        int sector_iterator     = 0;
        char* filename = "/home/pooja/Desktop/pooja/WORK/EWF/EWF_Sample/output.txt";
        size64_t media_size =15662579712;                //15662579712 bytes
        size64_t maximum_segment_size=512;
        int8_t compression_level=1;
        uint8_t compression_flags=1;

        if( libewf_handle_initialize(
             &handle,
             error ) != 1 )
        {
            printf("handle_initialize FAILED");
        }

       if( libewf_handle_open(
             handle,
             (char * const *) &filename,
             1,
             LIBEWF_OPEN_WRITE,
             error ) != 1 )

        {
            printf("OPEN FAILED");
        }

        if( media_size > 0 )
        {
                if( libewf_handle_set_media_size(
                     handle,
                     media_size,
                     error ) != 1 )
                {
                    printf("set_media_size");
                }
        }

        if( maximum_segment_size > 0 )
        {
               if( libewf_handle_set_maximum_segment_size(
                     handle,
                     maximum_segment_size,
                     error ) != 1 )
                {
                    printf("set_maximum_segment_size");
                }
        }

        if( libewf_handle_set_compression_values(
             handle,
             compression_level,
             compression_flags,
             error ) != 1 )
        {
            printf("set_compression_values");
        }

       // uint8_t* memory_allocate(size_t size);

        //buffer = (uint8_t *) memory_allocate(EWF_TEST_WRITE_BUFFER_SIZE );

        buffer = (uint8_t *)malloc(EWF_TEST_WRITE_BUFFER_SIZE);

        if( buffer == NULL )
        {
            printf("unable created buffer");
        }
        printf(" buffer %d ",&buffer);
     write_size = 512;

        for( sector_iterator = 0;
             sector_iterator < 26;
             sector_iterator++ )
        {  printf("\n test\n ");

            if( memset(
                 buffer,
                 (int) 'A' + sector_iterator,
                 write_size ) == NULL )
            {
                printf("\n memory_set FAILED\n");
            }

                write_count = libewf_handle_write_buffer(
                               handle,
                               buffer,
                               write_size,
                               error );
/*
               if( write_count < 0 )
                {
                    printf("write_count FAILED");
                }
                if( write_count != (ssize_t) write_size )
                {
                        if( (size64_t) write_count != media_size )
                        {

                        printf("write FAILED");
                        }
                }
                if( media_size > 0 )
                {
                        printf("media_size FAILED");
                        media_size -= write_count;
                }*/
        }

/*
        write_size = 3751;

        for( sector_iterator = 0;
             sector_iterator < 26;
             sector_iterator++ )
        {

                write_count = libewf_handle_write_buffer(
                               handle,
                               buffer,
                               write_size,
                               error );
                printf("file write\n");

                 FILE *file;
                 file = fopen("output.txt", "w");
                 if (file == NULL) {
                        printf("Error opening the file.\n");
                        return 1;
                    }

                    fwrite(buffer, sizeof(char), strlen(buffer), file);
                    printf("file done\n");
                    fclose(file);

                    printf("Content has been written to the file successfully.\n");

                if( write_count < 0 )
                {

                }
                if( write_count != (ssize_t) write_size )
                {
                        if( (size64_t) write_count != media_size )
                        {
                        }
                }
                if( media_size > 0 )
                {
                        media_size -= write_count;
                }
        }

        buffer = NULL;

        if( libewf_handle_close(
             handle,
             error ) != 0 )
        {
                        }
        if( libewf_handle_free(
             &handle,
             error ) != 1 )
        {

        }
        return( 1 );
*/

}

i have taken a test code from the library, ewf_test_write.c and line by line iam decoding but facing lots of issues, so how can i do the compression function for my imaging task in c

joachimmetz commented 10 months ago

i have taken a test code from the library, ewf_test_write.c and line by line iam decoding but facing lots of issues,

if you copy code from the project make sure to give it the same license

what issues? be more specific please, I cannot help you if I have to guess

I NEED A TEST code with a main function in thaat the compression function should be written with all the parameters required.

what do you mean with "TEST" in this context, sounds like you want to use libewf to compress data you are reading.

how to use libewf library to get the compressed image file. a sample i have done is this correct?

the outline of the functions called looks about right but can you clean up your example, e.g. remove the commented out code and debug code, it is very hard to follow what you are intending to do and why

also why such a small write buffer?

ishitar2021 commented 10 months ago
#include <libewf.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <memory.h>

#include <memory.h>
#define EWF_TEST_WRITE_BUFFER_SIZE      100

int main()
{
        libewf_error_t **error=0;
        libewf_handle_t *handle = NULL;
        uint8_t *buffer         = NULL;
        static char *function   = "ewf_test_write";
       size_t write_size       = 0;
        ssize_t write_count     = 0;
        int sector_iterator     = 0;
        char* filename = "/home/pooja/Desktop/pooja/WORK/EWF/EWF_Sample/output.txt";
        size64_t media_size =15662579712;                //15662579712 bytes
        size64_t maximum_segment_size=512;
        int8_t compression_level=1;
        uint8_t compression_flags=1;

        if( libewf_handle_initialize(
             &handle,
             error ) != 1 )
        {
            printf("handle_initialize FAILED");
        }

       if( libewf_handle_open(
             handle,
             (char * const *) &filename,
             1,
             LIBEWF_OPEN_WRITE,
             error ) != 1 )

        {
            printf("OPEN FAILED");
        }

        if( media_size > 0 )
        {
                if( libewf_handle_set_media_size(
                     handle,
                     media_size,
                     error ) != 1 )
                {
                    printf("set_media_size");
                }
        }

        if( maximum_segment_size > 0 )
        {
               if( libewf_handle_set_maximum_segment_size(
                     handle,
                     maximum_segment_size,
                     error ) != 1 )
                {
                    printf("set_maximum_segment_size");
                }
        }

        if( libewf_handle_set_compression_values(
             handle,
             compression_level,
             compression_flags,
             error ) != 1 )
        {
            printf("set_compression_values");
        }

        buffer = (uint8_t *)malloc(EWF_TEST_WRITE_BUFFER_SIZE);

        if( buffer == NULL )
        {
            printf("unable created buffer");
        }
        printf(" buffer %d ",&buffer);
     write_size = 512;
        for( sector_iterator = 0;
             sector_iterator < 26;
             sector_iterator++ )
        {  printf("\n test\n ");

            if( memset(
                 buffer,
                 (int) 'A' + sector_iterator,
                 write_size ) == NULL )
            {
                printf("\n memory_set FAILED\n");
            }

                write_count = libewf_handle_write_buffer(
                               handle,
                               buffer,
                               write_size,
                               error );

               if( write_count < 0 )
                {
                    printf("write_count FAILED");
                }
                if( write_count != (ssize_t) write_size )
                {
                        if( (size64_t) write_count != media_size )
                        {

                        printf("write FAILED");
                        }
                }
                if( media_size > 0 )
                {
                        printf("media_size FAILED");
                        media_size -= write_count;
                }
        }
        write_size = 3751;

        for( sector_iterator = 0;
             sector_iterator < 26;
             sector_iterator++ )
        {

                write_count = libewf_handle_write_buffer(
                               handle,
                               buffer,
                               write_size,
                               error );
                printf("file write\n");

                 FILE *file;
                 file = fopen("output.txt", "w");
                 if (file == NULL) {
                        printf("Error opening the file.\n");
                        return 1;
                    }

                    fwrite(buffer, sizeof(char), strlen(buffer), file);
                    printf("file done\n");
                    fclose(file);

                    printf("Content has been written to the file successfully.\n");

                if( write_count < 0 )
                {

                }
                if( write_count != (ssize_t) write_size )
                {
                        if( (size64_t) write_count != media_size )
                        {
                        }
                }
                if( media_size > 0 )
                {
                        media_size -= write_count;
                }
        }

        buffer = NULL;

        if( libewf_handle_close(
             handle,
             error ) != 0 )
        {
                        }
        if( libewf_handle_free(
             &handle,
             error ) != 1 )
        {

        }
        return( 1 );
}

in this will i be able to get the ewf files?

ishitar2021 commented 10 months ago

test code means a testing purpose code for testing the feature ewf

i have taken a test code from the library, ewf_test_write.c and line by line iam decoding but facing lots of issues,

if you copy code from the project make sure to give it the same license

what issues? be more specific please, I cannot help you if I have to guess

I NEED A TEST code with a main function in thaat the compression function should be written with all the parameters required.

what do you mean with "TEST" in this context, sounds like you want to use libewf to compress data you are reading.

how to use libewf library to get the compressed image file. a sample i have done is this correct?

the outline of the functions called looks about right but can you clean up your example, e.g. remove the commented out code and debug code, it is very hard to follow what you are intending to do and why

also why such a small write buffer?

test code means a testing purpose code for testing the feature ewf in a sepatate .c file and after that only implemenation

joachimmetz commented 10 months ago

test code means a testing purpose code for testing the feature ewf in a sepatate .c file and after that only implemenation

Ah you mean "example" and not test

no such examples available at this moment, you have to wait until the project is less experimental as per README, the interface is very straight forward, just: initialize, set, open, write, close, free.

joachimmetz commented 10 months ago

in this will i be able to get the ewf files?

eyeballing it, looks like you have the right sequence of API calls, make sure to pass error to figure out if something goes wrong, why

but realize your write buffer size is very small compared to the sector and/or chunk size, see format documentation for more details

ishitar2021 commented 10 months ago

test code means a testing purpose code for testing the feature ewf in a sepatate .c file and after that only implemenation

Ah you mean "example" and not test

no such examples available at this moment, you have to wait until the project is less experimental as per README, the interface is very straight forward, just: initialize, set, open, write, close, free.

sir, so initialize, set, open, write, close, free these steps can you elaborate with actual functions and its parameters. as iam totally confused with all the library functions.

joachimmetz commented 10 months ago

sir, so initialize, set, open, write, close, free these steps can you elaborate with actual functions and its parameters. as iam totally confused with all the library functions.

This is documented in the the include file and the man page, if this insufficient then I would recommend not to try to use an experimental library at this point.

ishitar2021 commented 10 months ago

where the source and destination adding in the code?

joachimmetz commented 10 months ago

I have no idea what you are asking and have limited time.

joachimmetz commented 10 months ago

no clarification from reporter, closing issue.