Skip to main content
Post Undeleted by Cliff B
added 605 characters in body
Source Link
Cliff B
  • 69.3k
  • 4
  • 33
  • 56

Wouldn't it be useful to actually openSo let's look at the first file????code that handles the non-signature blocks.

       else
 // if first jpg{
        // if (countfile ==is 0)open
        {
 if (ftell(img) >= 0)
        count++;
{
            fwrite(buffer, 512, 1, img);
        }
    }

It's supposed to discard the initial garbage blocks and write out blocks after the first signature is found. But what's really happening?

First, the code opens the first output file for write. Then it reads the first block of data (which is garbage and should be thrown away.)

The test is if (ftell(img) >= 0). But if the file is just opened and nothing has been written to it, wouldn't ftell(img) return 0? What happens then?????

BTW, did you actually look at the first 4 bytes of 001.jpg instead of just trying to open the image??? The answers are always in the raw data.

Happy coding! :-)

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

Wouldn't it be useful to actually open the first file????

        // if first jpg
        if (count == 0)
        {
            count++;

            fwrite(buffer, 512, 1, img);
        }

So let's look at the code that handles the non-signature blocks.

    else
    {
        // if file is open
        if (ftell(img) >= 0)
        {
            fwrite(buffer, 512, 1, img);
        }
    }

It's supposed to discard the initial garbage blocks and write out blocks after the first signature is found. But what's really happening?

First, the code opens the first output file for write. Then it reads the first block of data (which is garbage and should be thrown away.)

The test is if (ftell(img) >= 0). But if the file is just opened and nothing has been written to it, wouldn't ftell(img) return 0? What happens then?????

BTW, did you actually look at the first 4 bytes of 001.jpg instead of just trying to open the image??? The answers are always in the raw data.

Happy coding! :-)

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

Post Deleted by Cliff B
Source Link
Cliff B
  • 69.3k
  • 4
  • 33
  • 56

Wouldn't it be useful to actually open the first file????

        // if first jpg
        if (count == 0)
        {
            count++;

            fwrite(buffer, 512, 1, img);
        }