41

Apple occasionally uses a proprietary XIP file format, particularly when distributing versions of Xcode. It is an analog to zip, but is signed, allowing it to verified on the receiving system. When a XIP file is opened (by double-clicking), Archive Utility will expand it, but only if the digital signature is intact.

Does anyone know how to extract a XIP file from the Terminal command line to a specific folder? Is there any way to unarchive this type of file if the signature is invalid?

5
  • If it is "just a zip" then presumably ordinary unzip tools will do the trick. Or are you wanting to verify the signature as well?
    – halfer
    Feb 13, 2017 at 21:16
  • 2
    It's not just a signed zip file; it's a signed xar archive, typically with an LZMA-based compression applied. Jun 13, 2018 at 11:08
  • The answer given by @Geoff Nixon below works for me
    – rexford
    Jun 28, 2018 at 12:44
  • @antony-raphel Does my answer below adequately answer your question? Oct 21, 2018 at 8:10
  • Does this answer your question? How to extract xip archive using command line? Jul 14, 2021 at 4:42

6 Answers 6

56

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?

8
  • 8
    +1 how did you find out about the -x flag? It's neither documented on the man page nor in the command's help ...
    – rexford
    Jun 28, 2018 at 12:51
  • 8
    @rexford I'd dare to say most of Apple's utilities have hidden flags. Unfortunately, finding them is not a straightforward process. In fact, I just asked a question myself about this myself (that is, if there's a better way to find these). But the short answer is to use /usr/bin/strings on the binary and look for likely candidates. Jul 1, 2018 at 8:31
  • 2
    Thank you! This worked for extracting Xcode_9.4.1.xip
    – Patrick D
    Jul 13, 2018 at 7:12
  • 1
    @HappyFace You're right, the x flag is no longer readily apparent in the output of using strings on itself. I believe this is as of Xcode 10. Perhaps Apple has begun to strip their binaries more thoroughly, or perhaps its intentional obfuscation. However, for the portions of Darwin for which code is available, these options can also be found there: opensource.apple.com/source/cctools/cctools-886/misc/… (see line 205). And there are still plenty of other utilities with hidden options to be found this way. Oct 21, 2018 at 7:39
  • 1
    Despite this now being documented behaviour in "man xip", there is a wrinkle. I've just used "xip -x" on Xcode 13.3.1's archive, when cd'd to an external drive, and $TMPDIR, at least transiently, acquired a 17Gb working copy of Xcode. This is why the install is nuts and typically requires 50Gb+: there are three different variants of Xcode in different places at the same time. Apr 30, 2022 at 13:40
25

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

10
  • I got an error: Archive: Xcode_8.1.xip End-of-central-directory signature not found. Either this file is not a zipfile, or it constitutes one disk of a multi-part archive. In the latter case the central directory and zipfile comment will be found on the last disk(s) of this archive. note: Xcode_8.1.xip may be a plain executable, not an archive Feb 14, 2017 at 17:03
  • What happens when you double-click the file?
    – l'L'l
    Feb 14, 2017 at 19:01
  • 1
    it opens the default archive utility to validate the signature and extract. But, before finishing the validation error comes up. Feb 15, 2017 at 4:08
  • Then I think the file is corrupted.
    – l'L'l
    Feb 15, 2017 at 4:10
  • 1
    Note that, undocumented in the man page you cited, there is a simple -x option to the xip utility (see my alternative answer). But this doesn't verify the signature, your "Useful / Additional Info" bit is I think the only practical way to authenticate it. So perhaps the best answer would be something like pkgutil --verify-signature [xip file] && xip -x [xip file]. Jun 13, 2018 at 11:17
22

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

2
  • I feel safer about this solution. Just a note that one should go into "Preferences" actually :)
    – Gobe
    Apr 2, 2018 at 17:42
  • In Monterey (12.6.3) it seems now impossible to unpack an Xcode.xib to a particular folder - it always gets extracted into a tmp folder on the boot volume first - and if that's not having enough space, the entire process will fail. There seems to be no way around that. :( Feb 8 at 1:52
7

You can change the output by opening Archive Utility (either via spotlight search or launchpad). Then Archive Utility > Preferences (Command+,). Then Save expanded files > into... and you can change the output directory. :)

More simply: Opening "Archive Utility" and opening its preferences and changing where it can extract the file to. Also, Archive Utility can open .xip files.

1
  • Pity it doesn't have a "Prompt for folder" option for "Save expanded files" Sep 22, 2021 at 0:55
1

(For an archive with a valid signature.)

From the destination folder, create a symbolic link to the .xip archive, then expand using the link (and then delete the link when done). Example:

cd /Applications
ln -s /Volumes/SomewhereElse/Xcode.xip
xip --expand Xcode.xip
rm Xcode.xip
1
  • The following doesn't involve extraneous symlinks and worked fine for me, could be a simplification of your option: cd /Applications && xip --expand ~/Downloads/Xcode.xip — substitute ~/Downloads/Xcode.xip and /Applications for the source and destination paths as appropriate
    – akasaka
    Jan 13 at 1:21
0

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:

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.