How to unpack and pack pkg file?

后端 未结 5 1085
北恋
北恋 2020-11-30 16:58

I have a pkg file created by Install Maker for Mac. I want to replace one file in pkg. But I must do this under Linux system, because this is a part of download process. Whe

相关标签:
5条回答
  • 2020-11-30 17:06

    Here is a bash script inspired by abarnert's answer which will unpack a package named MyPackage.pkg into a subfolder named MyPackage_pkg and then open the folder in Finder.

        #!/usr/bin/env bash
        filename="$*"
        dirname="${filename/\./_}"
        pkgutil --expand "$filename" "$dirname"
        cd "$dirname"
        tar xvf Payload
        open .
    

    Usage:

        pkg-upack.sh MyPackage.pkg
    

    Warning: This will not work in all cases, and will fail with certain files, e.g. the PKGs inside the OSX system installer. If you want to peek inside the pkg file and see what's inside, you can try SuspiciousPackage (free app), and if you need more options such as selectively unpacking specific files, then have a look at Pacifist (nagware).

    0 讨论(0)
  • 2020-11-30 17:09

    Packages are just .xar archives with a different extension and a specified file hierarchy. Unfortunately, part of that file hierarchy is a cpio.gz archive of the actual installables, and usually that's what you want to edit. And there's also a Bom file that includes information on the files inside that cpio archive, and a PackageInfo file that includes summary information.

    If you really do just need to edit one of the info files, that's simple:

    mkdir Foo
    cd Foo
    xar -xf ../Foo.pkg
    # edit stuff
    xar -cf ../Foo-new.pkg *
    

    But if you need to edit the installable files:

    mkdir Foo
    cd Foo
    xar -xf ../Foo.pkg
    cd foo.pkg
    cat Payload | gunzip -dc |cpio -i
    # edit Foo.app/*
    rm Payload
    find ./Foo.app | cpio -o | gzip -c > Payload
    mkbom Foo.app Bom # or edit Bom
    # edit PackageInfo
    rm -rf Foo.app
    cd ..
    xar -cf ../Foo-new.pkg
    

    I believe you can get mkbom (and lsbom) for most linux distros. (If you can get ditto, that makes things even easier, but I'm not sure if that's nearly as ubiquitously available.)

    0 讨论(0)
  • 2020-11-30 17:09

    @shrx I've succeeded to unpack the BSD.pkg (part of the Yosemite installer) by using "pbzx" command.

    pbzx <pkg> | cpio -idmu

    The "pbzx" command can be downloaded from the following link:

    • pbzx Stream Parser
    0 讨论(0)
  • 2020-11-30 17:11

    In addition to what @abarnert said, I today had to find out that the default cpio utility on Mountain Lion uses a different archive format per default (not sure which), even with the man page stating it would use the old cpio/odc format. So, if anyone stumbles upon the cpio read error: bad file format message while trying to install his/her manipulated packages, be sure to include the format in the re-pack step:

    find ./Foo.app | cpio -o --format odc | gzip -c > Payload
    
    0 讨论(0)
  • 2020-11-30 17:17

    You might want to look into my fork of pbzx here: https://github.com/NiklasRosenstein/pbzx

    It allows you to stream pbzx files that are not wrapped in a XAR archive. I've experienced this with recent XCode Command-Line Tools Disk Images (eg. 10.12 XCode 8).

    pbzx -n Payload | cpio -i
    
    0 讨论(0)
提交回复
热议问题