2
votes

I am writing a program that prints out the Firefox cookies.sqlite file.

int printfile(FILE* cookiesfile)
{
    int c;
    //fseek(cookiesfile,0x18260,SEEK_SET);
    do{
        c=fgetc(cookiesfile);
        printf("%c",c);
    }while(c != EOF);
    printf("\n\n%x",c);
    if (ferror(cookiesfile) != 0)printf("\nchareror!\n");
    return 0;
}

The code returns EOF at various points before the end of the file. Opening the file in a hex editor or notepad shows that the file is much larger. The EOF always appears at the same points. Skipping past these points, data is read until the next EOF. Characters that the EOF occurs on have often been fgot previously without any problem (i.e. 0x1a, 0x13).

Checking the result from ferror() does not help (as no error is present).

I am not sure how to proceed in my debugging process, can someone lead me in the right direction?

1
@JoachimPileborg No, it may not. fgetc would not return -1 in that case. (though you could get the appearance that it did if you assign the return value of fgetc to a char instead of an int) - nos
Use feof to read a binary file .I have modify my code, Since I don't have you file , hope you can try my code. and give me a result. - Lidong Guo
As a general tip, don't read a binary file as it were a text file. The results will be undefined. - Some programmer dude
thanks, yes i used fread() instead in the end it was much better suited to the problem - Daniel Szanto

1 Answers

2
votes

Without knowing how you opened the file, we can't say for sure, but SQLite database files are not text files. If you open a SQLite database file in text mode on a Windows machine, you're going to be receiving EOF every time you try to read at a location that contains a value of 26 (0x1A, Ctrl-Z) (and there's no reason to assume that such locations will remain stationary). There are a number of free (and commercial) tools for dealing with SQLite database files, not least of which is the SQLite Manager plugin for FireFox itself. If you still want to do it in C, I recommend that you go to the SQLite website, download the code, and read the introductions and documentation.