Extract password archive with double quote in windows command line

雨燕双飞 提交于 2020-06-16 03:39:20

问题


I want to extract archive files (zip,rar,z7,gz,etc) from PHP. Because the passwords can contain special characters like ¡¿, and PHP exec does not support unicode characters (for some reason). I eneded up using a batch file as explained here php exec() in unicode mode?.

But, as lovely as windows 10 is, I can't seem to figure out how to extract an archive that has a single double quote as password...

"C:\Program Files\7-Zip\7z.exe" x "C:\Users\me\Desktop\25mb.rar" -o"C:\Users\me\Desktop\" -p"password here" -y

That is the default line to extract using 7zip. (note below) I have a file 25mb.bin stored in test.rar stored in 25mb.rar with password " (single double quote).

The error is:

7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21

Scanning the drive for archives:
1 file, 13312 bytes (13 KiB)

Extracting archive: C:\Users\me\Desktop\25mb.rar
--
Path = C:\Users\me\Desktop\25mb.rar
Type = Rar
Physical Size = 13312
Solid = -
Blocks = 1
Multivolume = -
Volumes = 1

ERROR: Data Error in encrypted file. Wrong password? : test.rar

Sub items Errors: 1

Archives with Errors: 1

Sub items Errors: 1

I tried:

-p" *
-p"" **
-p"""  *
-p"""" **
-p"^"" * (default escape for CMD)
-p"\"" *

*: The line asks me if i want to overwrite, meaning that the -y is not executed but seen as part of the password.

**: Executes, but with error. The extracted file test.rar cannot be opened (is corrupted)

Note: This method has no problem whatsoever with ~`!@#$%^&()_+-={}[]|:;'<>?,./€¡¿*

Note: winRAR has a neat feature in which you can provide a file with a password, to use to extract, instead of providing a string. This however only works for RAR files(!) and is thus useless in my situation.

Example with rar:

file_put_contents( 'C:\Users\bunny\Desktop\pass.txt', $password );
exec( '"C:\\Program Files\\WinRAR\\winrar" e -ad -p "C:\\Users\\me\\Desktop\\25mb.rar" *.* "C:\\Users\\me\\Desktop\" < "C:\\Usersme\\Desktop\\pass.txt"', $extractStatus );

回答1:


Well, after testing random things, I managed to find the answear!

"C:\Program Files\7-Zip\7z.exe" x "C:\Users\me\Desktop\dq.rar" -o"C:\Users\me\Desktop\" -sccutf-8 -y < C:\Users\me\Desktop\pass.txt

Note that the -p parameter is NOT present(!) (if added, it doesn't work)

The file pass.txt contains "\r\n (double quote followed by a line break)

The "-sccutf-8" option ensures that special characters work as well!

It works!

Edit 2: When the password file contains special characters like °, ¡, ¿ or §, this method still works! You do have to set "-sccutf-8" in order to make it work




回答2:


Yes, this answer helped me well. I used this in my Powershell script on my Win10 notebook:

(First a user puts password to $input_txt)

$input_txt | Out-File ".\pw.txt" -Encoding default
cmd /c ".\7za.exe" e ".\myfile.zip" -o".\" -sccWIN -y `< ".\pw.txt"

And escape "<" as Powershell can understand this using backquote.



来源:https://stackoverflow.com/questions/40438074/extract-password-archive-with-double-quote-in-windows-command-line

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!