IE cookie file format description

Source: Internet
Author: User

The cookie file of IE is saved in? : \ Documents and Settings \ <user> \ cookies, suffixed with .txt
You can directly use the API shgetfolderpath to obtain the directory for storing cookie files.
But I didn't find delphi2007 had this API declaration, So I declared it myself.
Code As follows (we found that code highlighting supports Pascal, huh, huh)

GetcookiefolderCopy codeThe Code is 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 that the shell32 constant is defined in shellapi. Pas, And the csidl_cookies are defined in shlobj. Pas. Remember to reference

Enumerate cookie files
GetcookiefilesCopy codeThe Code is 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 focus: the format of the cookie file.
The cookie file is a pure text file with the line break (ASCII = 10) as the Separator
You can use tstringlist to read data.
The format is as follows:Copy codeThe Code is as follows: a_cookie
. 123
My. Demo. Site

*

Where
1st behavior cookie name
The first row is the cookie value.
Row 3rd is the address of the site to which the cookie belongs.
Row 4th is a flag value (Note: it should be accurate to indicate whether the cookie is encrypted)
5th low behavior timeout (Cardinal/DWORD)
6th high behavior timeout time
7th low level of behavior Creation Time
8th high behavior Creation Time
The fixed row 9th is *, indicating the end of a section.
Note that the time used here is not Delphi's tdatetime, but filetime (the corresponding tfiletime in D)
A file may contain multiple sections, which can be recycled in the preceding format.

The following code converts the preceding time to tdatetime in D.

ConverttodatetimeCopy codeThe Code is 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;

How is it really easy? Haha

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.