PureZIP library : ZIP / UNZIP files

All PureFORM, JaPBe, Libs and useful code maintained by gnozal

Moderator: gnozal

User avatar
AL90
Enthusiast
Enthusiast
Posts: 217
Joined: Fri Sep 16, 2005 7:47 pm
Location: Germany
Contact:

Post by AL90 »

gnozal wrote:So it seems to be a ZLIB issue ?
this is possible. Unfortunately, I also can say nothing to it.
I have no more ideas how you can fix it. :cry:
Micko
Enthusiast
Enthusiast
Posts: 244
Joined: Thu May 24, 2007 7:36 pm
Location: Senegal
Contact:

check if the user password is correct

Post by Micko »

hi gnozal
i would like to check if the user password is correct before extract zip files

Code: Select all

MyZIP.s = "C:\Test.zip"
MyZIPFile1.s = "C:\Compressor Xpert.exe"
MyZIPFile2.s = "C:\French.lng"
MyZIPFile3.s = "C:\English.lng"
MyZIPOutPut.s = "C:\TempZip"
If PureZIP_Archive_Create(MyZIP.s, #APPEND_STATUS_CREATE)
   PureZIP_SetArchivePassword("azerty")
   PureZIP_Archive_Compress(MyZIPFile1.s, #False)
   PureZIP_Archive_Compress(MyZIPFile2.s, #False)
   PureZIP_Archive_Compress(MyZIPFile3.s, #False)
   PureZIP_Archive_Close()
EndIf
MessageRequester("Info","Success",0)

; i need to check if the password is correct before unzip files
; but i can't make it work !
Input.s = InputRequester("Zip is crypted", "Password:", "")
If PureZIP_Archive_Read(MyZIP.s)
  If Input
     If PureZIP_SetArchivePassword(Input)
         ReturnValue.l = PureZIP_Archive_FindFirst() = #UNZ_OK
        While ReturnValue = #UNZ_OK
         PureZIP_Archive_Extract(MyZIPOutPut.s, #True)
         ReturnValue = PureZIP_Archive_FindNext()
        Wend:MessageRequester("Info","Files are extracted !",0)
       Else: MessageRequester("Info","Error !",0):EndIf
    Else:MessageRequester("Info","please input password !",0):EndIf
 PureZIP_Archive_Close()
EndIf
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Re: check if the user password is correct

Post by gnozal »

Micko wrote:hi gnozal
i would like to check if the user password is correct before extract zip files
You can't.
The password isn't stored in the archive.
If the password is wrong, you get an error during decompression.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Micko
Enthusiast
Enthusiast
Posts: 244
Joined: Thu May 24, 2007 7:36 pm
Location: Senegal
Contact:

Post by Micko »

thanks gnozal
Micko
Enthusiast
Enthusiast
Posts: 244
Joined: Thu May 24, 2007 7:36 pm
Location: Senegal
Contact:

Post by Micko »

pleaz gnozal can you explain me how the password is stored and test before extraction ?
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

For security reasons I don't think that zip files store that kind of information, I think you only know that a password is incorrect when you get errors during the uncompression.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

DoubleDutch wrote:For security reasons I don't think that zip files store that kind of information, I think you only know that a password is incorrect when you get errors during the uncompression.
Exactly.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Micko: If what you want to do is find the password to a zip file, then you can find this IF one of the files is a known file. A known file is an original file before it was zipped.

That is why you should NEVER make password protected zips with files where some of the files are available unzipped. This would render the password protection virtually useless because it make it possible to reverse the process to find the original password for the encypted files.

See http://www.lostpassword.com/zip.htm and look at the section on "Known plaintext".
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
Micko
Enthusiast
Enthusiast
Posts: 244
Joined: Thu May 24, 2007 7:36 pm
Location: Senegal
Contact:

Post by Micko »

thanks DoubleDutch for these informations :)

know i try to extract files that are password protected and check if there is errors during the uncompression ?
here is the result i have
files are always extracted with size(0) , if the password is incorrect :shock:

Code: Select all

SourceDir .s = "Test.Zip" ;protected with password
Chemin.s = "C:\Temp"
While Valeur_Retour = #UNZ_OK
              myFileinfo.PureZIP_FileInfo
              ExtractValue = PureZIP_ExtractFiles(SourceDir, "*.*", Chemin, #True)
               If ExtractValue  = #Null : Goto MessageError
               Else
              Valeur_Retour = PureZIP_Archive_FindNext() 
              EndIf
 Wend
MessageError :       
              MessageRequester("Error","Incorrect password, can't process files !",#MB_ICONWARNING)
what i need is to avoid files extraction until the password is incorrect
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

The decompression is done after the file has been created, so you have a zero file.
You can avoid it like this :

Code: Select all

If PureZIP_Archive_Read("c:\test.zip")
  IsOk = PureZIP_Archive_FindFirst()
  While IsOk = #Z_OK
    If IsOk = PureZIP_Archive_Extract("c:\", #False)
      Debug "Ok"
    Else
      Debug "Extraction problem"
      PureZIP_Archive_FileInfo(@FileInfo.PureZIP_FileInfo)
      If FileSize("c:\" + FileInfo\FileName) = 0
        Debug "Zero length = deleting"
        DeleteFile("c:\" + FileInfo\FileName)
      EndIf
    EndIf
    IsOk = PureZIP_Archive_FindNext()
  Wend
  PureZIP_Archive_Close()
EndIf
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Micko
Enthusiast
Enthusiast
Posts: 244
Joined: Thu May 24, 2007 7:36 pm
Location: Senegal
Contact:

Post by Micko »

thank you very much gnozal :D
Micko
Enthusiast
Enthusiast
Posts: 244
Joined: Thu May 24, 2007 7:36 pm
Location: Senegal
Contact:

Post by Micko »

gnozal i'm working with your last code but it seems to work when the total files in zip not Exceed 10 else i get this message "Extraction problem", but couldn't delete files.
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Micko wrote:gnozal i'm working with your last code but it seems to work when the total files in zip not Exceed 10 else i get this message "Extraction problem", but couldn't delete files.
?!
I just tested the code with a crypted archive containing 28 files : no problem (all zero length files deleted).

If you can assume the password is the same for all files, this code may suffice : it quits after the first failure.

Code: Select all

If PureZIP_Archive_Read("c:\test.zip") 
  IsOk = PureZIP_Archive_FindFirst() 
  While IsOk = #Z_OK 
    If IsOk = PureZIP_Archive_Extract("c:", #False) 
      Debug "Ok" 
    Else 
      PureZIP_Archive_FileInfo(@FileInfo.PureZIP_FileInfo) 
      Debug "Extraction problem for " + FileInfo\FileName
      If FileSize("c:" + FileInfo\FileName) = 0 
        Debug "Zero length = deleting " + FileInfo\FileName
        DeleteFile("c:" + FileInfo\FileName)
        Debug "And exiting .."
        Break
      EndIf 
    EndIf 
    IsOk = PureZIP_Archive_FindNext() 
  Wend 
  PureZIP_Archive_Close() 
EndIf
Just a thought : if you have read-only files, of course it won't work : you have to reset the read-only attribute before deleting.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Micko
Enthusiast
Enthusiast
Posts: 244
Joined: Thu May 24, 2007 7:36 pm
Location: Senegal
Contact:

Post by Micko »

gnozal wrote:Just a thought : if you have read-only files, of course it won't work : you have to reset the read-only attribute before deleting.
oh yes ! i forgot :cry: sorry for took your times but this always help me :D
thanks a lot
Micko
Enthusiast
Enthusiast
Posts: 244
Joined: Thu May 24, 2007 7:36 pm
Location: Senegal
Contact:

Post by Micko »

Code: Select all

If FileSize("c:\" + FileInfo\FileName) = 0 
this line never return 0 but -1 when i test. if i change 0 to -1 it works.
so i think it is Inexistants file(PB help). every day should be the same to me because i catch something in my mind. :)
thanks gnozal

Gnozal i want to set zip size to quad i process file to support file > 2Go
did i do it like this

Code: Select all

If PureZIP_Archive_Create(MyZIP.s, #APPEND_STATUS_CREATE)
Size.q = FileInfo\unCompressedSize & $FFFFFFFF
Size.q = filesize(MyZIPFile1.s)
 PureZIP_Archive_Compress(MyZIPFile1.s, #FALSE)
  PureZIP_Archive_Close()
EndIf
Post Reply