Extract .xip files into a specific folder

泪湿孤枕 提交于 2019-12-19 05:45:07

问题


A XIP file is an analog to zip, but allows for a digital signature to be applied and verified on the receiving system, before the archive is expanded. When a XIP file is opened (by double-clicking), Archive Utility will automatically expand it (but only if the digital signature is intact).

Essentially, a .xip file is just a .zip with a signature to verify that the file has not changed since its creator saved it. This protects from both damage from a disk error and from a third-party tampering with the file.

Does anyone know, how to extract this file, e.g. using Terminal, to a specific folder instead of to the folder where the .xip file resides?


回答1:


Maybe try:

xip -x [path to .xip file]

That will unpack the archive into your current working directory.

As for extracting into a specific directory, there is not explicitly an option for this, but xip -x will extract into the current working directory. Therefore, cding to where you would like to extract the file should work; if you specifically need to automate this, a script to the effect of:

#!/bin/sh

xipfile="$(cd $(dirname "$1"); pwd -P)/$(basename "$1")" # a portable "realpath"

cd "$2"
xip -x "$xipfile"

Should do the trick I think?




回答2:


You can open archive utility itself, go into Preferences and set a specific destination folder and then double click the file. This way you achieved expanding it to a specific destination. ;-)




回答3:


I would recommend to simply extract the archive into the folder you want trying the following:

xar -xf file.xip -C /path/to/target

(and/or)

tar -zxvf file.xip -C /path/to/target

The xar and tar commands extract the .xip "Content" and "Metadata" in a raw format.

Using a pbzx stream parser you'll need to extract the "Content" which is an lzma compressed Payload; the format is similar to that found within a package installer (eg. .pkg). You can compile the pbzx source from here, or download the compiled binary and install to /usr/local/bin then invoke the pbzx command:

pbzx -n Content | cpio -i

After the command finishes parsing the Content you should get the original form of whatever it was within the .xip archive.

Useful / Additional Info:

$ pkgutil --check-signature file.xip 

Xcode_9_beta_2.xip returns:

Package "Xcode_9_beta_2.xip":
   Status: signed Apple Software
   Certificate Chain:
    1. Software Update
       SHA1 fingerprint: 1E 34 E3 91 C6 44 37 DD 24 BE 57 B1 66 7B 2F DA 09 76 E1 FD
       -----------------------------------------------------------------------------
    2. Apple Software Update Certification Authority
       SHA1 fingerprint: FA 02 79 0F CE 9D 93 00 89 C8 C2 51 0B BC 50 B4 85 8E 6F BF
       -----------------------------------------------------------------------------
    3. Apple Root CA
       SHA1 fingerprint: 61 1E 5B 66 2C 59 3A 08 FF 58 D1 4A E2 24 52 D1 98 DF 6C 60

Notes:

Important: Starting with macOS Sierra, only XIP archives signed by Apple will be expanded. Developers who have been using XIP archives will need to move to using signed installer packages or disk images.

↳ OS X manual page : xip




回答4:


There seems to be no single tool to accomplish that, so far. One needs a tool that can decode pbzx streams, and there seems to be no tool for that pre-installed on macOS.

Various solutions are found in these answers:

  • https://stackoverflow.com/a/39489446/
  • https://stackoverflow.com/a/40414863/
  • https://stackoverflow.com/a/41598227/


来源:https://stackoverflow.com/questions/42197588/extract-xip-files-into-a-specific-folder

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