36475

Extract password archive with double quote in windows command line

<h3>Question</h3>

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. <em>(note below)</em> 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"\"" *

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

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

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

<em>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.</em>

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 );
<h3>Answer1:</h3>

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


<h3>Answer2:</h3>

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

Recommend

  • Ignore inherited class when serializing object
  • SQL Anywhere 11 - Check if event exists
  • Regex - find specific number in string
  • AngularJS reloadOnSearch not working
  • c# closing sqlconnection and sqldatareader or not?
  • Can a C compiler add padding before the first element in a structure?
  • node-webkit equivalent for sinatra?
  • C# linq to sql - selecting tables dynamically
  • What happened to Code Contracts?
  • How to pin parse relation data in local data store?
  • How to fix the beginner's ReactJS error?
  • CSS Flex - I have a list of items can need to make them horizontally scroll with overflow hidden
  • Files:insert - Google Drive SDK - Python Example - What is Drive API service instance?
  • Trying to compile Java source (could not find main class)
  • Address Constant Expressions
  • Java PNG to JPG Bug
  • Synchronize two vobs on two different hosts
  • Java Hibernate Check MySQL Replication is in sync
  • Can Azure AD ADAL (ios) refresh token be revoked from the client?
  • Swift dictionary map - init in closure
  • How deleteLater() actually works in qt?
  • How to read config files with section in bash shell
  • Erlang needs to connect to https server?
  • How to build executable with pyinstaller that uses pycryptodome?
  • The output is not displayed in its entirety [8086 assembly]
  • Identify xml text elements with Schematron
  • Javascript getting the value of an input in a table [duplicate]
  • Authorization Policies/Gates for Laravel 5.3 web app consuming own API w/ Passport
  • Create a log file for a custom DNN module
  • Customize jQuery submenu positioning
  • How to add multiple legend titles (columns) in ggplot
  • CSS style for container with transparent border images
  • Using Java runtime to add registry key, cause process reg.exe to run forever
  • Was there ever a proposal to include the URL fragment into the HTTP request?
  • Simultaneous animation when entering editing mode of UITableViewCell
  • Javascript inside HTML import not affecting imported HTML
  • C# code can't “see” the methods in my C++ dll
  • Copy and paste data from multiple workbooks to a worksheet in another Workbook
  • Create an average of multiple excel chart without the data source
  • Grails - How to implement a foreign key relationship not using an id column?