欢迎来到代码驿站!

当前位置:首页 >

IE Cookie文件格式说明

时间:2021-09-04 09:49:08|栏目:|点击:
IE 的 Cookie 文件保存在 ?:\Documents and Settings\<user>\Cookies 目录,后缀为.txt
可以直接使用 API SHGetFolderPath 取得 Cookie 文件的保存目录
不过我没发现 Delphi2007 有这个 API 的声明,所以自己声明了一下
代码如下(发现代码高亮支持 Pascal 了,呵呵)


GetCookieFolder
复制代码 代码如下:

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;

注意 shell32 常量定义在 ShellAPI.pas 里,CSIDL_COOKIES 定义在 ShlObj.pas 里,记得引用

枚举 Cookie 文件
GetCookieFiles
复制代码 代码如下:

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;

下面才是重点,Cookie 文件的格式,呵呵
Cookie 文件只是个纯粹的文本文件,以换行符(ASCII=10)为分隔符
可以使用 TStringList 读取,会自动分行的
格式如下
复制代码 代码如下:

a_cookie
.123
my.demo.site

*

其中
第1行为 Cookie 名称
第2行是 Cookie 的值
第3行是 Cookie 所属站点的地址
第4行是个标记值(注:准确来说应该是表示该Cookie是否被加密)
第5行为超时时间的低位(Cardinal/DWORD)
第6行为超时时间的高位
第7行为创建时间的低位
第8行为创建时间的高位
第9行固定为 * ,表示一节的结束
需要注意的是这里使用的时间并非 Delphi 的 TDateTime,而是 FILETIME(D里为对应的TFileTime)
一个文件可能包含有多个节,按上面的格式循环即可

下面的代码将上述时间转换为 D 里的 TDateTime


ConvertToDateTime
复制代码 代码如下:

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;


怎么样,确实很简单吧?呵呵

上一篇:PowerShell中match命令使用详解

栏    目:

下一篇:docker 容器上编译 go 程序提示找不到文件问题

本文标题:IE Cookie文件格式说明

本文地址:http://www.codeinn.net/misctech/172465.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有