IE cookie file format

Source: Internet
Author: User

on the Internet over the past few days, many people have accidentally reproduced or partially intercepted some of the content in this article.
in this statement, indicate the source for reprinting, thank you

A tool named cookieadmin was written a few days ago to view ie cookies.
Someone asked about the implementation principle and wrote this article.Article
I am not good at writing documents or articles, so I stillCodeSpeak

The cookie file of IE is stored 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.
The Code is as follows (we found that code highlighting supports Pascal, huh, huh)

Getcookiefolder
1Function Shgetfolderpath (hwndowner: hwnd; nfolder: integer; htoken: hwnd;
2Dwflags: word; pszpath: pchar): Boolean; stdcall; External shell32 name'Shgetfolderpatha' ;
3
4Function Getcookiefolder: string;
5VaR
6P:Array[0.. Max_path]Of Char;
7Begin
8Shgetfolderpath (0, Csidl_cookies,0,0, @ P [0 ]);
9Result:= Includetrailingbackslash (P );
10End;

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

Getcookiefiles
1Procedure Getcookiefiles (apath: string; alist: tstrings );
2VaR
3 SR: tsearchrec;
4Begin
5IfFindfirst (apath+ '*. Txt', Faarchive, Sr)= 0 Then
6Begin
7Repeat
8IfSr. name [1]= '.' Then Continue;
9
10 Alist. Add (Sr. Name );
11UntilFindnext (SR)<> 0 ;
12
13 Findclose (SR );
14End ;
15End;

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:

A_cookie
0.123
My. Demo. Site
1600
1589052800
30634450
672816768
29899592
*

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.

Converttodatetime
1 Function Filetimetodatetime (FT: tfiletime): tdatetime; inline;
2 VaR
3 St: tsystemtime;
4 Begin
5 Filetimetolocalfiletime (FT, ft );
6 Filetimetosystemtime (FT, St );
7 Result: = Systemtimetodatetime (ST );
8 End ;
9
10 Function Converttodatetime (L, H: Cardinal): tdatetime;
11 VaR
12 FT: tfiletime;
13 Begin
14 Ft. dwlowdatetime: = L;
15 Ft. dwhighdatetime: = H;
16 Result: = Filetimetodatetime (FT );
17 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.