Einzelnen Beitrag anzeigen

Andreas L.
(Gast)

n/a Beiträge
 
#41

Re: CookieCrumbler 1.2.6

  Alt 21. Jun 2009, 10:45
Zitat von toms:
Zitat von Andreas L.:
Zitat:
---------------------------
CookieCrumbler
---------------------------
Ungültiges Argument zum Codieren des Datums.
---------------------------
OK
---------------------------
Welche der oben aufgelisteten Programme hast du denn installiert?
IE, Chrome. Fehler kommt immer noch bei der neusten Version.
Welche Windows-Version hast du? Evtl. eine englische Ausgabe? Kann mir das nicht erklären. Der einzige Punkt an dem ich ein Datum auslese ist beim Laden der Cookies. Kannst du evtl. mal die Datei %LOCAL_APPDATA%\Google\Chrome\UserData\Default\Coo kies mit einem SQLite-Editor öffnen und mir die Spalten creation_utc, last_access_utc und expires_utc per PN schicken? Alternativ die komplette Cookie-Datei. Danke

Zitat von xZise:
Ehm ...
A simple Delphi wrapper for Sqlite 3
Und wenn mir deinen Code oben angucke benutzt du ihn ebenfalls
Ja, genau den.
Zitat von xZise:
Weil dieses "GetTable" mich irgendwie ankotzt, da man kein Objekt zurückgeben sollte.
Wie machst du es denn in deinen Projekten?

Zitat von xZise:
Es waren 4 "gefährliche"... Also Durchschnittlich 3 Sekunden pro Cookie! Dürfte man denn in die Unit gucken?
Du hast insgesamt nur 4 Cookies?

CookieCrumblerApp.pas
Ich lege alle Cookies in einer, naja, universellen Cookie-Liste ab. Beim speichern kopiere ich mir die Cookies wieder in die spezielle "Format-Cookie-List" und speichere.
Delphi-Quellcode:
procedure TCookieCrumblerApp.SaveCookies;
var
  iCookie, iFile: Integer;
  MozillaCookies: TBcMozillaCookies;
  FirefoxCookies: TBcFirefoxCookies;
  FlashCookies: TBcFlashSharedObjectsCookies;
  ChromeCookies: TBcChromeCookies;
  IECookies: TBcIECookies;
  IEDHTMLCookies: TBcIEDHTMLBehaviorsCookies;
  MozillaDOM: TBcMozillaDOMStorageCookies;
  //SafariCookies: TBcSafariCookies;
  TempCookies: TBcMultiCookieHolder;
begin
  MozillaCookies := TBcMozillaCookies.Create(nil);
  FirefoxCookies := TBcFirefoxCookies.Create(nil);
  FlashCookies := TBcFlashSharedObjectsCookies.Create(nil);
  ChromeCookies := TBcChromeCookies.Create(nil);
  IECookies := TBcIECookies.Create(nil);
  IEDHTMLCookies := TBcIEDHTMLBehaviorsCookies.Create(nil);
  MozillaDOM := TBcMozillaDOMStorageCookies.Create(nil);
  //SafariCookies := TBcSafariCookies.Create(nil);
  TempCookies := TBcMultiCookieHolder.Create(nil);

  for iFile := 0 to Files.Count -1 do
  begin
    TempCookies.Clear;

    if FDebugMode then
    begin
      Log.Add(DateTimeToStr(now) + #9 + 'Save' + #9 + IntToStr(Integer(Files[iFile].Format)) + #9 + Files[iFile].FileName + '(start)' + #9 + IntToStr(iFile + 1) + '/' + IntToStr(Files.Count));
      Log.SaveToFile(IncludeTrailingPathDelimiter(GetShellFolder(CSIDL_DESKTOP)) + 'CookieCrumbler.log');
    end;

    for iCookie := 0 to Cookies.Count -1 do
    begin
      if StrToInt(Cookies[iCookie].Source) = iFile then
        TempCookies[TempCookies.Add].Assign(Cookies[iCookie]);
    end;

    case Files[iFile].Format of
      cfFirefox: begin
        FirefoxCookies.Clear;
        for iCookie := 0 to TempCookies.Count -1 do
          FirefoxCookies[FirefoxCookies.Add].Assign(TempCookies[iCookie]);
        FirefoxCookies.SaveToFile(Files[iFile].FileName);
      end;
      cfFlash: begin
        FlashCookies.Clear;
        for iCookie := 0 to TempCookies.Count -1 do
          FlashCookies[FlashCookies.Add].Assign(TempCookies[iCookie]);
        FlashCookies.SaveToDirectory(Files[iFile].FileName);
      end;
      cfChrome: begin
        ChromeCookies.Clear;
        for iCookie := 0 to TempCookies.Count -1 do
          ChromeCookies[ChromeCookies.Add].Assign(TempCookies[iCookie]);
        ChromeCookies.SaveToFile(Files[iFile].FileName);
      end;
      cfIE: begin
        IECookies.Clear;
        for iCookie := 0 to TempCookies.Count -1 do
          IECookies[IECookies.Add].Assign(TempCookies[iCookie]);
        IECookies.SaveToDirectory(Files[iFile].FileName, True);
      end;
      cfIEDHTML: begin
        IEDHTMLCookies.Clear;
        for iCookie := 0 to TempCookies.Count -1 do
          IEDHTMLCookies[IEDHTMLCookies.Add].Assign(TempCookies[iCookie]);
        IEDHTMLCookies.SaveToDirectory(Files[iFile].FileName);
      end;
      cfMozilla: begin
        MozillaCookies.Clear;
        for iCookie := 0 to TempCookies.Count -1 do
          MozillaCookies[MozillaCookies.Add].Assign(TempCookies[iCookie]);
        MozillaCookies.SaveToFile(Files[iFile].FileName);
      end;
      cfMozillaDOM: begin
        MozillaDOM.Clear;
        for iCookie := 0 to TempCookies.Count -1 do
          MozillaDOM[MozillaDOM.Add].Assign(TempCookies[iCookie]);
        MozillaDOM.SaveToFile(Files[iFile].FileName);
      end;
      {cfSafari: begin
        SafariCookies.Clear;
        for iCookie := 0 to TempCookies.Count -1 do
          SafariCookies[SafariCookies.Add].Assign(TempCookies[iCookie]);
        SafariCookies.SaveToFile(Files[iFile].FileName);
      end; }

    end;

    if FDebugMode then
    begin
      Log.Add(DateTimeToStr(now) + #9 + 'Save' + #9 + IntToStr(Integer(Files[iFile].Format)) + #9 + Files[iFile].FileName + '(end)' + #9 + IntToStr(iFile + 1) + '/' + IntToStr(Files.Count));
      Log.SaveToFile(IncludeTrailingPathDelimiter(GetShellFolder(CSIDL_DESKTOP)) + 'CookieCrumbler.log');
    end;

  end;
  TempCookies.Free;
  MozillaCookies.Free;
  FirefoxCookies.Free;
  FlashCookies.Free;
  ChromeCookies.Free;
  IECookies.Free;
  IEDHTMLCookies.Free;
  MozillaDOM.Free;
  //SafariCookies.Free;
end;
BCCookies.pas
Delphi-Quellcode:
type
  ...
  TBcFirefoxCookies = class(TBcHTTPCookies)
  protected
    procedure SetCookie(Index: Integer; Value: TBcFirefoxCookie);
    function GetCookie(Index: Integer):TBcFirefoxCookie;
    function PrimaryKeyIsUnique(Value: Int64; ExceptItem: Integer):Boolean;
  public
    function Add:Integer;
    procedure LoadFromFile(FileName: String);
    procedure SaveToFile(FileName: String);
    property Cookies[Index: Integer]: TBcFirefoxCookie read GetCookie write SetCookie; default;
  end;

  ...

  {$WARNINGS OFF}
  TBcCookie = class(TPersistent)
  private
    FName: String;
    FContent: String;
    FDomain: String;
    FPath: String;
    FExpires: TDateTimeEx;
    FSecure: LongBool;
    FWholeDomain: LongBool;
    FLastAccessed: TDateTimeEx;
    FCreated: TDateTimeEx;
    FFlags: Int64;
    FData: String;
    FFileName: String;
    FOwner: String;
  protected
    procedure SetLastAccessed(Value: TDateTimeEx);
    procedure SetCreated(Value: TDateTimeEx);
    procedure SetExpires(Value: TDateTimeEx);
    property Secure: LongBool read FSecure write FSecure;
    property WholeDomain: LongBool read FWholeDomain write FWholeDomain;
    property LastAccessed: TDateTimeEx read FLastAccessed write SetLastAccessed;
    property Created: TDateTimeEx read FCreated write SetCreated;
    property Flags: Int64 read FFlags write FFlags;
    property Name: String read FName write FName;
    property Content: String read FContent write FContent;
    property Domain: String read FDomain write FDomain;
    property Path: String read FPath write FPath;
    property Expires: TDateTimeEx read FExpires write SetExpires;
    property Data: String read FData write FData;
    property FileName: String read FFileName write FFileName;
    property Owner: String read FOwner write FOwner;
  public
    constructor Create;
    destructor Destroy;
    procedure Assign(Source: TBcCookie);
    procedure AssignTo(Dest: TBcCookie);
  end;
  {$WARNINGS ON}  

  TBcHTTPCookie = class(TBcCookie)
  public
    function IsBroken:Boolean;
    function IsExpired:Boolean;
  published
    property Name;
    property Content;
    property Domain;
    property Path;
    property Expires;
  end;

  TBcMozillaCookie = class(TBcHTTPCookie)
  published
    property Secure;
    property WholeDomain;
  end;

  TBcFirefoxCookie = class(TBcMozillaCookie)
  published
    property LastAccessed;
    property Created;
  end;

  ...

{ TBcFirefoxCookies }
procedure TBcFirefoxCookies.SetCookie(Index: Integer; Value: TBcFirefoxCookie);
begin
  FCookies[Index] := Value;
end;

function TBcFirefoxCookies.GetCookie(Index: Integer):TBcFirefoxCookie;
begin
  Result := FCookies[Index] as TBcFirefoxCookie;
end;

function TBcFirefoxCookies.Add:Integer;
var
  NewCookie: TBcFirefoxCookie;
begin
  NewCookie := TBcFirefoxCookie.Create;
  Result := FCookies.Add(NewCookie);
end;

function TBcFirefoxCookies.PrimaryKeyIsUnique(Value: Int64; ExceptItem: Integer):Boolean;
var
  iCookie: Integer;
begin
  Result := True;
  for iCookie := 0 to Count -1 do
  begin
    if (iCookie <> ExceptItem) and (Cookies[iCookie].Created.AsPRTime = Value) then
    begin
      Result := False;
      Break;
    end;
  end;
end;

procedure TBcFirefoxCookies.LoadFromFile(FileName: string);
var
  db: TSQLiteDatabase;
  table: TSQLIteTable;
begin
  Clear;
  db := TSQLiteDatabase.Create(FileName);
  try
    if db.TableExists('moz_cookies') then
    begin
      table := db.GetTable('SELECT id, name, value, host, path, expiry, isSecure, isHTTPOnly, lastAccessed FROM moz_cookies');
      try
        while not table.EOF do
        begin
          with Cookies[Add] do
          begin
            Name := table.FieldAsString(table.FieldIndex['name']);
            Content := table.FieldAsString(table.FieldIndex['value']);
            Domain := table.FieldAsString(table.FieldIndex['host']);
            Path := table.FieldAsString(table.FieldIndex['path']);
            Expires.AsUnixTime(StrToInt64(table.FieldAsString(table.FieldIndex['expiry'])));
            Secure := LongBool(StrToIntDef(table.FieldAsString(table.FieldIndex['isSecure']), 0));
            WholeDomain := LongBool(StrToIntDef(table.FieldAsString(table.FieldIndex['isHTTPOnly']), 0));
            LastAccessed.AsPRTime(StrToInt64(table.FieldAsString(table.FieldIndex['lastAccessed'])));
            Created.AsPRTime(StrToInt64(table.FieldAsString(table.FieldIndex['id'])));
          end;
          table.Next;
        end;
      finally
        table.Free;
      end;
    end;
  finally
    db.Free;
  end;
end;

procedure TBcFirefoxCookies.SaveToFile(FileName: string);
var
  db: TSQLiteDatabase;
  iCookie: Integer;
  ExpiresStr: String;
  LastAccessedStr: String;
  IsUnique: Boolean;
begin
  db := TSQLiteDatabase.Create(FileName);
  try
    if db.TableExists('moz_cookies') then
      db.ExecSQL('DROP TABLE moz_cookies');
    db.ExecSQL('CREATE TABLE moz_cookies (id INTEGER, name TEXT, value TEXT, host TEXT, path TEXT, expiry INTEGER, lastAccessed INTEGER, isSecure INTEGER, isHTTPOnly INTEGER, PRIMARY KEY(id))');
    for iCookie := 0 to Count -1 do
    begin

      //sicherstellen das der Primärschlüssel nur einmal vorkommt
      IsUnique := PrimaryKeyIsUnique(Cookies[iCookie].Created.AsPRTime, iCookie);
      while not IsUnique do
      begin
        Cookies[iCookie].Created.AsPRTime(Cookies[iCookie].Created.AsPRTime + 1000000);
        IsUnique := PrimaryKeyIsUnique(Cookies[iCookie].Created.AsPRTime, iCookie);
      end;

      //sicherstellen das alle anderen Integer-Werte ungleich dem Primärschlüssel sind
      LastAccessedStr := IntToStr(Cookies[iCookie].LastAccessed.AsPRTime);
      if Cookies[iCookie].Created.AsPRTime = Cookies[iCookie].LastAccessed.AsPRTime then
        LastAccessedStr := IntToStr(Cookies[iCookie].LastAccessed.AsPRTime + 1000000);

      ExpiresStr := IntToStr(Cookies[iCookie].Expires.AsUnixTime);
      if Cookies[iCookie].Created.AsPRTime = Cookies[iCookie].Expires.AsUnixTime then
        ExpiresStr := IntToStr(Cookies[iCookie].Expires.AsUnixTime + 1000000);

      db.ExecSQL('INSERT INTO moz_cookies (id, name, value, host, path, expiry, lastAccessed, isSecure, isHTTPOnly)' +
                 ' VALUES ("' + IntToStr(Cookies[iCookie].Created.AsPRTime) + '", "' +
                 EscapeSQLStatement(Cookies[iCookie].Name) + '", "' +
                 EscapeSQLStatement(Cookies[iCookie].Content) + '", "' +
                 EscapeSQLStatement(Cookies[iCookie].Domain) + '", "' +
                 EscapeSQLStatement(Cookies[iCookie].Path) + '", "' +
                 ExpiresStr + '", "' +
                 LastAccessedStr + '", "' +
                 IntToStr(LongBoolToInt(Cookies[iCookie].Secure)) + '", "' +
                 IntToStr(LongBoolToInt(Cookies[iCookie].WholeDomain)) + '")');
    end;
  finally
    db.Free;
  end;
end;
  Mit Zitat antworten Zitat