summaryrefslogtreecommitdiff
path: root/wk4/pset/recover/recover.c
blob: 69d6adc84e3ab06fb37bf0fbe86df34c0aa587ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    if (argc > 1) {
        printf("Usage: ./recover infile\n");
        return 1;
    }

    // Remember filenames
    char *infile = argv[optind];

    // Open input file
    FILE *inptr = fopen(infile, "r");
    if (inptr == NULL)
    {
        printf("Could not open %s.\n", infile);
        return 1;
    }

    fread(infile, sizeof(RGBTRIPLE), width, inptr);

    /*
    files = 0
    for (file length)
    {
        if (first 3 bytes are 0xff 0xd8 0xff AND 4th byte is 0xe* (* denotes anything))
        {
            this is a photo; remember the pointer (call it point)
            int photolength = 0;
            // look through the blocks ahead of this one for a new photo
            for (file length left)
            {
                photolength++;
                if (first 3 bytes are 0xff 0xd8 0xff AND 4th byte is 0xe* (* denotes anything))
                {
                    // this is the photo length
                    break
                }
            }
            filename = files.jpg
            files++
            Open output file with name (filename)
            Copy data from old to new file -->
            uint32_t data[photolength][16];
            fread(&data, sizeof(uint32_t), 16 * photolength, inptr)
            fwrite()
        }
    }





    */


}