UnZipBuffer() fails if archive has a password

Ask for help, how to use AHK_H, etc.
User avatar
RazorHalo
Posts: 45
Joined: 21 Dec 2015, 21:23

UnZipBuffer() fails if archive has a password

13 Apr 2022, 00:59

I can't seem to get UnZipBuffer() to work if the archive has a password.
I created the archive using ZipFileCreate() with a password.

I can successfully unzip the archive to a file with UnZip() and also successfully extract/view it with 7zip GUI app.

UnZipBuffer() will always throw exception stating "password incorrect".

This is the code for creating the archive

Code: Select all

text := "This is a test"

hZip := ZipCreateFile("test.zip", "12345")
ZipAddBuffer(hZip, &text, StrPut(text)*2, "test.txt")
ZipCloseFile(hZip)
Return
And the code I'm using to UnZip() and UnZipBuffer()

Code: Select all

;Extract to file  ---WORKS
Size := UnZip("test.zip", "" , "test.txt", "unzipped.txt", "12345")
msgbox % "Success: " Size

;Unzip to memory --- ALWAYS EXCEPTION "PASSWORD INCORRECT"
Size := UnZipBuffer("test.zip", "test.txt", data, "12345")
msgbox % "Size: " Size "`nData: " data
Am I crazy? Is this a bug or am I just doing it wrong?
Using AHK_H 1.1.33.10 x64 Unicode, Windows 10
User avatar
RazorHalo
Posts: 45
Joined: 21 Dec 2015, 21:23

Re: UnZipBuffer() fails if archive has a password

14 Apr 2022, 14:19

I have taken a look at the source code and it seems that the password is only processed if it is the 5th parameter.
making param #4 blank and the password as param #5 allows the function to work properly.

The documentation states that if param #1 is a file name it ignores the 'size' param that should follow if it was a BufferObject/Address instead of a filename:
Size
The size in bytes of zip archive in memory. When previous parameter is ZipFileName this parameter is skipped, see examples.
@HotKeyIt
I think its a problem (I'm no C++ expert here) with the BIF_DECL(BIF_UnZipBuffer) function in script2.cpp (starting at line 18528) that it only process the password if there is more then 4 params, which if unzipping from a file there should only be 4 total. (If I'm reading the doc correctly, as when unzipping from a file param #2 is recognized as FileToExtract and param #3 is recognized as VariableName

Side note: the .chm help file shows the VariableName and Password as optional parameters but the online help doc only shows Password
Attachments
ONLINE help file UnZipBuffer().jpg
ONLINE help file UnZipBuffer().jpg (76.91 KiB) Viewed 1106 times
CHM help file UnZipBuffer().jpg
CHM help file UnZipBuffer().jpg (79.68 KiB) Viewed 1106 times

Return to “Ask for Help”

Who is online

Users browsing this forum: No registered users and 2 guests