0

I've run check50 and I get the following error message.

:) recover.c exists.
:) recover.c compiles.
:) handles lack of forensic image
:( recovers 000.jpg correctly
    expected exit code 0, not 1
:( recovers middle images correctly
    expected exit code 0, not 1
:( recovers 049.jpg correctly
    expected exit code 0, not 1

I'm not sure what it means. Can you please help?

// Recovers JPEGs from a forensic image

#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>

int main(int argc, char *argv[])
{
    // Check usage
    if (argc != 2)
    {
        printf("Usage: ./ recover image \n");
        return 1;
    }

    // Open file
    FILE *card = fopen(argv[1], "r");
    {
        return 1;
    }

    // Create a data type for the file

    typedef uint8_t BYTE;

    // Read 512 bytes into a buffer
    BYTE buffer[512];

    int found = 0;
    char outfile[8] = "";
    FILE *img;
    int x;

    while (fread(buffer, sizeof(BYTE), 512, card) == 512)
    {
        // If a new jpeg file, create jpeg

        if (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && (buffer[3] & 0xf0) == 0xe0)
        {
            if (found == 0)
            {
                sprintf(outfile, "%03i.jpg", 2);
                img = fopen(outfile, "w");
                fwrite(buffer, sizeof(BYTE), 512, img);
                found++;
            }

        // If not a jpeg file, keep searching

        else
            {
                fclose(img);
                sprintf(outfile, "%03i.jpg", 2);
                img = fopen(outfile, "w");
                fwrite(buffer, sizeof(BYTE), 512, img);
                found++;
            }
        }
        // If existing jpeg file already found, keep writing to the jpeg

        else
            {
                if (found >= 1)
                {
                    fwrite(buffer, sizeof(BYTE), 512, img);
                }
            }

    fclose(img);


    }

}
2
  • What error message?
    – Cliff B
    Sep 2 '20 at 21:20
  • Hi Cliff - I forgot to include the error message: :) recover.c exists. :) recover.c compiles. :) handles lack of forensic image :( recovers 000.jpg correctly expected exit code 0, not 1 :( recovers middle images correctly expected exit code 0, not 1 :( recovers 049.jpg correctly expected exit code 0, not 1 Sep 2 '20 at 22:05
2

Simple. The program is terminating early because of this code:

// Open file
FILE *card = fopen(argv[1], "r");
{
    return 1;
}

Perhaps there's a missing if statement?

Did you actually test your code or just run check50?

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

3
  • Thank you. I ran the code and I wasn't getting a result. I will figure this out. Sep 2 '20 at 23:53
  • Just to make sure, you do realize that the code above is not an IF statement, right? The return 1 statement will ALWAYS execute and terminate the program.
    – Cliff B
    Sep 3 '20 at 0:28
  • I revised the code to the following but still getting the same error message. FILE *card = fopen(argv[1], "r"); if(card == NULL) { printf("Usage: Unable to open file \n"); return 1; } Sep 3 '20 at 17:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .