[delphizip] Re: Memory leak in Inflate.c in Unzip.dll

  • From: "James Turner" <james.d.h.turner@xxxxxxxxxxxx>
  • To: <delphizip@xxxxxxxxxxxxx>
  • Date: Thu, 8 May 2003 20:47:31 +0100


Roger,

I don't have any reference code, but I have included the password checking
code I use in Zipfusion.
I arrived at this solution partially from code analysis and partially from
experimentation using the debugger to watch variables.

James Turner
SKARO.NET


procedure EnterPassword(WND:HWND; Attempts:integer);
{ The file pointer is assumed to be located at the start }
{ of the file data or the 12-byte encryption prefix.     }
{ Failure will raise an exception.                       }
type TCryptBlock = array [0..(SizeOf(TZipCryptKey) div 2) - 1] of Word;

    function Decrypt(CryptBlock:TCryptBlock):Boolean;
    { CryptBlock must be passed as a value parameter otherwise the }
    { password has to be entered correctly at the first attempt.   }
    const InitKey : TZipCryptKey = (305419896,591751049,878082192);
    var   i       : integer;
          w       : Word;
    begin
      Result   := False; if Password = '' then exit;
      CryptKey := InitKey;

      for i := 1 to Length(Password) do UpdateCryptKey(byte(Password[i]));

      DecryptBuff(@CryptBlock,SizeOf(CryptBlock));
      w := CryptBlock[High(CryptBlock)];

      with Header do if Flags and 8 = 0 then result := w = HiWord(CRC32)
                                        else result := w = LoWord(FileDate);
    end;

var CryptBlock : TCryptBlock;
begin { EnterPassword }
  if (Header.Flags and 1) = 0 then exit; { Not password protected }

  { If AutoRun is true, SkipFile should always be called }
  if not AutoRun then begin
    InfileRead(CryptBlock,SizeOf(CryptBlock));

    if Password <> '' then inc(Attempts);

    repeat
      if Decrypt(CryptBlock) then Exit;

      if (Attempts > 0) then begin
        dec(Attempts);
        case DialogBoxParam(HInstance,'DIALOG_Password',WND,@DP_Password,0)
of
          ID_OK     : Continue;
          ID_No     : Break; { Skip button : return false }
          ID_Cancel : SkipFile('',sfAbort);
        else end;
      end
      else Break;

    until false;
  end;

  SkipFile(SourceFileName,sfWrongPassword);
end;


-----------
To unsubscribe from this list, send an empty e-mail 
message to:
  delphizip-request@xxxxxxxxxxxxx 
and put the word unsubscribe in the subject.

Other related posts: