-
Notifications
You must be signed in to change notification settings - Fork 5
Documentation libPSARC PSARC File Format
PSARC is an archive format for storing file assets used in Playstation games.
It is a binary file format with big-endian byte ordering.
The format consists of a header, an array of file descriptors, an array of chunk sizes and an array of data chunks.
The first file in the archive is always a manifest. It is a text file listing the directory path for each file in the archive, one per line, not including the manifest itself.
Each file asset within the archive is stored in one or more data chunks.
Depending on the compression method, data chunks are compressed, unless the raw file
fits into a single chunk or the size of the raw file is less than the compressed size.
The default compression type is zlib (deflate).
lzma and no compression are also supported.
The format also supports encryption but is currently undocumented here.
| Offset | Size | Type | Name |
|---|---|---|---|
| o0 = 0x0000 | s0 | struct | Header |
| o1 = o0 + s0 | s1 | array | FileDescriptors |
| o2 = o1 + s1 | s2 = o3 - o2 | array | ChunkSizes |
| o3 | s3 = EOF - o3 | byte[] | ChunkData |
Total size = 32 (0x20) bytes
| Offset | Size | Type | Name | Description | ||||||||
| 0x0000 | 0x004 | char[] | Magic | Always "PSAR". | ||||||||
| 0x0004 | 0x004 | uint32 | Version | High short is Major, Low short is Minor version. | ||||||||
| 0x0008 | 0x004 | char[] | CompressionType |
Defines the compression type used for all files.
|
||||||||
| 0x000C | 0x004 | uint32 | DataOffset | The byte position of the first data chunk relative to the start of the file. | ||||||||
| 0x0010 | 0x004 | uint32 | FileDescriptorSize | The size of each entry in the FileDescriptors array. | ||||||||
| 0x0014 | 0x004 | uint32 | FileCount | The number of files stored in the archive. | ||||||||
| 0x0018 | 0x004 | uint32 | MaxChunkSize |
Each uncompressed data chunk is less than or equal to MaxChunkSize. Also determines byte-width of integers stored in ChunkSizes. |
||||||||
| 0x001C | 0x004 | uint32 | Flags |
|
see also: FileDescriptor Entry
see also: FileDescriptors Array
Each entry in the FileDescriptors array is a structure containing the information needed to locate and extract all the chunks for a file.
The size of each entry is explicitly defined in Header.FileDescriptorSize, which could suggest that the FileDescriptor structure may vary, either with custom data or different PSARC format versions.
The default structure (observed in format v1.4 used by No Mans Sky) is described here.
Total size = 30 (0x1E) bytes
| Offset | Size | Type | Name | Description |
| 0x0000 | 0x0010 | byte[] | PathDigest |
A 16-byte MD5 hash computed from the file path that is stored in the manifest. The hash for the manifest entry is all 0's. |
| 0x0010 | 0x0004 | uint32 | ChunkIndex |
The file's first chunk index into the ChunkSizes array. The number of chunks for a file can be derived with ChunkCount = ceil( FileSize / Header.MaxChunkSize ). |
| 0x0014 | 0x0005 | uint40 | FileSize |
The size in bytes of the uncompressed file. Note this field is 5 bytes (uint40). |
| 0x0019 | 0x0005 | uint40 | DataOffset |
The byte position of the file's first data chunk relative to the start of the file. Note this field is 5 bytes (uint40). |