本文介绍了在Windows命令行中提取带有双引号的密码存档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从PHP中提取存档文件(zip,rar,z7,gz等).因为密码可以包含特殊字符,例如¡¿,并且PHP exec不支持unicode字符(由于某些原因).我使用了一个批处理文件,如此处 php exec()以unicode模式所述那样进行解释?

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?.

但是,就像Windows 10一样可爱,我似乎无法弄清楚如何提取带有单引号作为密码的档案...

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

这是使用7zip提取的默认行. (在下面注意)我有一个 25mb.bin 文件存储在 test.rar 中,该文件存储在 25mb.rar 中,密码为(双引号).

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).

错误是:

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

我尝试过:

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

*:该行询问我是否要覆盖,这意味着-y不会执行,而是被视为密码的一部分.

**:执行,但有错误.提取的文件test.rar无法打开(已损坏)

注意:此方法对于〜`!@#$%^& ()_ +-==}}都没有问题. €¡¿*

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

注意:winRAR具有一项简洁的功能,您可以为文件提供密码以供提取,而不是提供字符串.但是,这仅适用于RAR文件(!),因此在我的情况下是没有用的.

带有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 );

推荐答案

好吧,在测试了随机的东西之后,我设法找到了answear!

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

请注意,-p参数不存在(!)(如果添加,它将不起作用)

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

pass.txt文件包含"\ r \ n(双引号,后跟换行符)

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

-sccutf-8"选项可确保特殊字符也能正常工作!

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

有效!

修改2:当密码文件包含特殊字符(例如°,¡,¿或§)时,此方法仍然有效!您必须设置"-sccutf-8"才能使其正常工作

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

这篇关于在Windows命令行中提取带有双引号的密码存档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 09:40