IE's Cookie file is stored in the?: \ Documents and settings\<user>\cookies directory, suffix is. txt
You can use the API SHGetFolderPath to get the Save directory for the Cookie file directly
But I didn't find out that Delphi2007 had this API statement, so I made a statement
Code as follows (found code highlighted to support Pascal, hehe)
Getcookiefolder
Copy Code code as follows:
function SHGetFolderPath (hwndowner:hwnd; nfolder:integer; htoken:hwnd;
Dwflags:word; Pszpath:pchar): Boolean; stdcall; External shell32 name ' Shgetfolderpatha ';
function getcookiefolder:string;
Var
P:array[0..max_path] of Char;
Begin
SHGetFolderPath (0, csidl_cookies, 0, 0, @p[0]);
Result: = Includetrailingbackslash (P);
End
Note Shell32 constants are defined in Shellapi.pas, csidl_cookies defined in Shlobj.pas, remember to quote
Enumerating Cookie Files
Getcookiefiles
Copy Code code as follows:
Procedure Getcookiefiles (apath:string; Alist:tstrings);
Var
Sr:tsearchrec;
Begin
If FindFirst (Apath + ' *.txt ', faarchive, Sr) = 0 Then
Begin
Repeat
If sr.name[1] = '. ' Then Continue;
Alist.add (Sr.name);
Until FindNext (Sr) <> 0;
FindClose (SR);
End
End
The following is the key, Cookie file format, hehe
The Cookie file is just a pure text file, with a newline character (ascii=10) as the separator
Can be read using Tstringlist, will automatically branch the
Format is as follows
Copy Code code as follows:
A_cookie
.123
My.demo.site
*
which
1th Act Cookie Name
Line 2nd is the value of the Cookie
Line 3rd is the address of the site where the Cookie belongs
Line 4th is a tagged value (note: It should be accurate to indicate whether the cookie is encrypted)
The low (Cardinal/dword) of the 5th Act time-out period
6th High level of behavior timeout
The low of the 7th Act creation Time
The high level of the 8th Act creation time
Line 9th is fixed to * to indicate the end of a section
It should be noted that the time used here is not the tdatetime of Delphi, but Filetime (d in the corresponding tfiletime)
A file may contain multiple sections, which can be circulated in the format above
The following code converts the time above to Tdatetime in D
Converttodatetime
Copy Code code as follows:
function Filetimetodatetime (ft:tfiletime): Tdatetime; Inline
Var
St:tsystemtime;
Begin
FileTimeToLocalFileTime (ft, ft);
FileTimeToSystemTime (FT, ST);
Result: = Systemtimetodatetime (ST);
End
function Converttodatetime (L, h:cardinal): Tdatetime;
Var
Ft:tfiletime;
Begin
Ft.dwlowdatetime: = L;
Ft.dwhighdatetime: = H;
Result: = Filetimetodatetime (FT);
End
What, is it really easy? Oh