-
-
Save meeuw/3e37381992f2a212a97f to your computer and use it in GitHub Desktop.
Pure python reimplementation of .cpio.xz content extraction from pbzx file payload for OS X packages.without any third party tools
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# tar -Oxf /Volumes/install_app/Packages/Essentials.pkg Payload|python pbzx.py|tar t | |
import subprocess | |
import struct | |
import sys | |
def pbzx(): | |
if sys.stdin.read(4) != "pbzx": | |
print "Not a pbzx stream" | |
sys.exit(1) | |
flags = struct.unpack(">Q", sys.stdin.read(8))[0] | |
print >> sys.stderr, hex(flags) | |
while (flags & 1 << 24): | |
flags, length = struct.unpack(">QQ", sys.stdin.read(16)) | |
xz = None | |
while length: | |
xbuf = sys.stdin.read(min(4*1024, length)) | |
if xz == None: | |
xz = xbuf[:8] == "\xfd7zXZ\x00\x00\x00" | |
if xz: | |
p = subprocess.Popen("zcat", stdin=subprocess.PIPE) | |
length -= len(xbuf) | |
if xz: | |
p.stdin.write(xbuf) | |
else: | |
sys.stdout.write(xbuf) | |
if xz: | |
p.stdin.close() | |
p.wait() | |
# This is required because Popen seems to flush stdout | |
sys.stdout.flush() | |
if __name__ == "__main__": | |
pbzx() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment