网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的范文:

 

标题 IE Cookie文件格式说明
范文
    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;
    怎么样,确实很简单吧?呵呵
随便看

 

在线学习网范文大全提供好词好句、学习总结、工作总结、演讲稿等写作素材及范文模板,是学习及工作的有利工具。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/14 0:46:02