Categories
OSX

Unpacking OSX .PKG Files

It used to be that .PKG files were simply folders wrapped up as a bundle using a special “bundle” folder attribute which you could either right-click and use “Show Contents” or just cd into the .pkg files from the command line. For Mac applications that you drag and drop into the “/Applications” folder this is still the case.

However more recently, the format of the installation packages seems to have changed, making it more difficult into extracting the application from pkg file in case you are not interested in installing a pkg.
As an example I will extract the TeamViewer application from the PKG-File in the disc image that can be provided from Teamviewer’s Download Site

Unpacking the .PKG File

The .pkg file itself is an “xar” – archive, an archive format that is able to handle files of arbitrary large file size by storing the toc (“table of content”) at the beginning of the archive and thereby allowing for a efficient stream-like handling of the files within an archive.

First copy the .pkg file from the disk image into a temporary folder and unpack it using the xar cmd tool.
[bash]
chris@chris-rmbp:~/Downloads$ cp /Volumes/TeamViewer/Install\ TeamViewer.pkg ~/Downloads/_tmp/
chris@chris-rmbp:~/Downloads/_tmp$ xar -xf Install\ TeamViewer.pkg
chris@chris-rmbp:~/Downloads/_tmp$ ls -la
total 32336
drwxr-xr-x 11 chris staff 374B Feb 18 21:56 ./
drwx—r-x+ 155 chris staff 5.1K Feb 18 21:02 ../
-rw-r–r–@ 1 chris staff 6.0K Feb 18 21:56 .DS_Store
-rw-r–r– 1 chris staff 2.0K Feb 18 21:56 Distribution
drwx—— 5 chris staff 170B Jan 1 1970 Font.pkg/
-rw-r–r–@ 1 chris staff 16M Feb 18 21:48 Install TeamViewer.pkg
drwx—— 6 chris staff 204B Jan 1 1970 LauncherFull.pkg/
drwx—— 4 chris staff 136B Jan 1 1970 Resources/
drwx—— 6 chris staff 204B Jan 1 1970 TeamViewerApp.pkg/
chris@chris-rmbp:~/Downloads/_tmp$ cd TeamViewerApp.pkg/
chris@chris-rmbp:~/Downloads/_tmp/TeamViewerApp.pkg$ ls -la
total 32632
drwx—— 6 chris staff 204B Jan 1 1970 ./
drwxr-xr-x 11 chris staff 374B Feb 18 21:56 ../
-rw-r–r– 1 chris staff 262K Feb 5 15:20 Bom
-rw-r–r– 1 chris staff 795B Feb 18 21:56 PackageInfo
-rw-r–r– 1 chris staff 16M Feb 5 15:20 Payload
-rw-r–r– 1 chris staff 542B Feb 5 15:20 Scripts
chris@chris-rmbp:~/Downloads/_tmp/TeamViewerApp.pkg$
[/bash]

Simply judging by the size you can tell that Payload must contain the application we are interested in. The Payload itself is a cpio archive compressed with gzip. The file can be extracted using the cpio archiver after piping it through gzip:

[bash]
chris@chris-rmbp:~/Downloads/_tmp/TeamViewerApp.pkg$ cat Payload | gzip -d – | cpio -id
93074 blocks
chris@chris-rmbp:~/Downloads/_tmp/TeamViewerApp.pkg$ ls -la
total 32632
drwxr-xr-x 7 chris staff 238B Feb 18 22:08 ./
drwxr-xr-x 11 chris staff 374B Feb 18 21:56 ../
-rw-r–r– 1 chris staff 262K Feb 5 15:20 Bom
-rw-r–r– 1 chris staff 795B Feb 18 21:56 PackageInfo
-rw-r–r– 1 chris staff 16M Feb 5 15:20 Payload
-rw-r–r– 1 chris staff 542B Feb 5 15:20 Scripts
drwxr-xr-x 3 chris staff 102B Feb 18 22:08 TeamViewer.app/
chris@chris-rmbp:~/Downloads/_tmp/TeamViewerApp.pkg$
[/bash]
In case new folders and files appear such as usr, private folders they contain the files and folders that would be installed relative to the root directory of the hard drive when the installer would be run normally.
In this case the only interesting file is the TeamViewer.app that contains the TeamViewer application which you can drag and drop this file to the /Application folder without having to install the launchagents that automatically start TeamViewer on login.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.