Format:XAR archive
| Magic | 78 61 72 21 (xar!) |
|---|---|
| Extensions | .xar, .pkg, .safariextz |
| Endianness | big-endian |
| License | BSD (mackyle/xar) |
| On this wiki | Facts · Code · Notes · Topics |
The eXtensible ARchive (.xar, and the container of macOS flat .pkg installers): a 28-byte big-endian header with magic "xar!" (78 61 72 21), a zlib-compressed XML table of contents, then a heap of file data addressed from the TOC.
Header
From mackyle/xar (commit 66d451dab1, xar/include/xar.h.in, pack(4), big-endian on disk; archive.c byte-swaps with ntohl/ntohs/xar_ntoh64):
| Offset | Type | Field |
|---|---|---|
| 0 | u32 | magic 0x78617221, "xar!" (XAR_HEADER_MAGIC) |
| 4 | u16 | header size (28 for the plain header; must be at least that; a larger value is skipped) |
| 6 | u16 | version |
| 8 | u64 | TOC length compressed |
| 16 | u64 | TOC length uncompressed |
| 24 | u32 | checksum algorithm: 0 none, 1 SHA-1, 2 MD5, 3 other |
With algorithm 3 ("other") the header is extended by a 36-byte NUL-terminated, padded toc_cksum_name (the header size must then be a multiple of 4 and include the name). The TOC follows the header directly; the library checks the magic and returns an error otherwise.
Table of contents
The TOC is an XML document <xar><toc>...</toc></xar> (archive.c writes and parses elements xar, toc) with a <file> element per entry; each carries a <data> property that holds offset, length, size, encoding and checksums. Unverified: the TOC is zlib-compressed (the header keeps compressed and uncompressed lengths); the data offsets are relative to the end of the TOC plus the TOC checksum, in a heap; the encoding is given by a mime-type attribute (for example application/x-gzip, application/x-bzip2 or octet-stream for raw).
macOS flat packages
Unverified (not read in this source): a flat .pkg installer is a xar archive containing Distribution (XML), <name>.pkg component folders, each with PackageInfo, Bom, Payload (a gzip-compressed cpio archive, see Format:Cpio newc (initramfs) for the cpio layer) and Scripts (also cpio), and optionally a signature in the TOC. Extract with the xar tool, then gunzip and cpio the Payload to reach the Format:Mach-O binaries.
Sources
mackyle/xar (BSD), xar/include/xar.h.in and xar/lib/archive.c, read in a clone.
Code & repositories
- https://github.com/mackyle/xar @
66d451dab1ef859dd0c83995f2379335d35e53c9· license: BSD-3-Clause (declared by the contributor; GitHub's detector did not recognize a license file)
xar library and tool: header struct and TOC reader/writer
Tested on: source read, not run: not run, source read · checked 2026-10-18; last activity 2023-06-13