2

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?

Jacob Pollack
  • 3,703
  • 1
  • 17
  • 39
Daniel Szanto
  • 89
  • 1
  • 9
  • @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 Aug 14 '13 at 07:07
  • 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 Aug 14 '13 at 07:23
  • 1
    As a general tip, don't read a binary file as it were a text file. The results will be undefined. – Some programmer dude Aug 14 '13 at 07:25
  • thanks, yes i used fread() instead in the end it was much better suited to the problem – Daniel Szanto Aug 19 '13 at 04:28

1 Answers1

2

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.

This isn't my real name
  • 4,869
  • 3
  • 17
  • 30
  • thanks, yes i abandoned this approach for this reason and because it is extremely inefficient. Instead I used fread, which was a much better solution. – Daniel Szanto Aug 19 '13 at 04:27