SARC (File Format)

From Wexos's Wiki
(Redirected from SARC)
Jump to navigationJump to search

SARC Files are archive files used on Nintendo Switch, Wii U and Nintendo 3DS. Common extensions are .arc and .sarc (general), .pack (when the archive contains mostly other archive files), .bars (when it contains audio data), and .bgenv/.genvb (when it contains shader and post-effect files). SARC files are sometimes Yaz0 compressed into .szs files.

File Format

Header

Every SARC file begins with a 0x14 byte SARC header structure.

Offset Type Description
0x00 Char[4] File magic. Always SARC in ASCII.
0x04 UInt16 Size of this header in bytes.
0x06 UInt16 Byte-order-mark. FE FF for big endian, FF FE for little endian.
0x08 UInt32 File size of the entire archive in bytes.
0x0C UInt32 Data start offset.
0x10 UInt16 Version number of the file format. Only version 0x0100 has been seen.
0x12 UInt16 Reserved.

SFAT

The Header is immediately followed by the SFAT section. It has the following structure:

Offset Type Description
0x00 Char[4] Section magic. Always SFAT in ASCII.
0x04 UInt16 Size of this section in bytes.
0x06 UInt16 Number of nodes.
0x08 UInt32 Hash key. Always 0x65.

Node

After the SFAT section comes all node entries. Each entry has the following structure:

Offset Type Description
0x00 UInt32 File Name Hash. Look below for the calculation.
0x04 UInt32 File attribute. If flag 0x01000000 is set, bottom half (0xFFFF) is the name offset divided by 4 (relative to end of SFNT).
0x08 UInt32 Start of file data, relative to the data start offset specified in the Header.
0x0C UInt32 End of file data, relative to the data start offset specified in the Header.

File Name Hash

The hash is calculated like this:

uint GetHash(string name, uint key)
{
    uint result = 0;

    for (int i = 0; i < name.Length; i++)
    {
        result = name[i] + result * key;
    }

    return result;
}

SFNT

The SFAT node array is immediately followed by the SFNT structure. It has the following layout:

Offset Type Description
0x00 Char[4] File magic. Always SFNT in ASCII.
0x04 UInt16 Size of this section in bytes.
0x06 UInt16 Reserved.

After follows 4-byte aligned null-terminated strings that represent the filenames of the packed files.

File Data

The data begins at the data start offset specified in the SARC header. The alignment of the internal files vary between different files, but default is 4.

Tools

The following tools can handle SARC files: