I'm having a problem with my code for recover.c because it recovers only 1 JPEG and that JPEG isn't a JPEG. It starts with 0x68 and 0x74.
After going through the code with GDB, it seems as that on the 1st iteration of the loop 512B is written to the JPEG even though the value of counter is 1 (it should only execute when counter != 1
as seen on line 57 in the screenshot below). I do not know why this is the case.
Here is the code that I used originally:
https://gist.github.com/ehahehah/1296d5658537b3861a2c
P.S. Could there be something wrong with the way I am checking for EOF? (Just wondering)
I tried fixing the part where the code only wrote 512B into the 1st JPEG and not continue writing into that JPEG. Here's the code with those changes:
https://gist.github.com/ehahehah/4b4038f7da99ab484b86
Even so, the same problem exists. Running recover.c
only recovers 1 JPEG which isn't a JPEG. (It doesn't have the signature.) Running recover.c
with GDB yields the same problem as before: In the image above (line 57 of GDB) the condition if (counter != 1)
executes even on the 1st iteration of the while loop, when counter == 1
. Again, I am puzzled as to why this is happening.