Difference between revisions of "SARC (File Format)"

From MK8
Jump to navigation Jump to search
m
m
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
'''SARC Files''' are archive files used in [[Wii U]] and [[3DS]], including [[Mario Kart 8]]. They are similar to the [[:mkw:U8 (File Format)|U8]] files found in GameCube and Wii games. Common extensions are '''.arc''' and '''.sarc''' (general), '''.pack''' (when the archive contains mostly other archive files), '''.bars''' (when it contains audio data), and '''.bgenv''' (when it contains shader files). SARC files are sometimes [[:mkw:Yaz0 (File Format)|Yaz0]] compressed into '''.szs''' files.
+
'''SARC Files''' are archive files used in [[Wii U]] and [[3DS]], including [[Mario Kart 8]]. They are similar to the [[:mkw:U8 (File Format)|U8]] files found in GameCube and Wii games. 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 [[AAMP]]/shader files). SARC files are sometimes [[:mkw:Yaz0 (File Format)|Yaz0]] compressed into '''.szs''' files.
  
 
= File Format =
 
= File Format =
Line 18: Line 18:
 
| 0x08 || 4 || '''File size''' of the entire archive in bytes.
 
| 0x08 || 4 || '''File size''' of the entire archive in bytes.
 
|-
 
|-
| 0x0c || 4 || '''Beginning of data''' offset.
+
| 0x0C || 4 || '''Beginning of data''' offset.
 
|-
 
|-
| 0x10 || 4 || {{Unknown|'''Unknown'''. Always '''0x01000000'''?}}
+
| 0x10 || 2 || '''Version number''' of the file format. Always 0x0100.
 +
|-
 +
| 0x12 || 2 || Reserved.
 
|-
 
|-
 
| 0x14 || colspan=2 {{Unknown|End of '''SARC''' header}}
 
| 0x14 || colspan=2 {{Unknown|End of '''SARC''' header}}
 
|}
 
|}
  
== File Table ==
+
== File Allocation Table ==
Unlike the U8 format, SARC does generally not contain directory nodes (though files may reside inside subfolders). It is currently unknown if it is able to.
+
Unlike the U8 format, SARC does generally not contain directory nodes (though files may reside inside subfolders).
  
 
=== Header (SFAT) ===
 
=== Header (SFAT) ===
Line 40: Line 42:
 
| 0x06 || 2 || '''Node count'''.
 
| 0x06 || 2 || '''Node count'''.
 
|-
 
|-
| 0x08 || 4 || '''Hash Multiplier'''. Always '''0x00000065'''.
+
| 0x08 || 4 || '''Hash Key'''. Always '''0x00000065'''.
 
|-
 
|-
| 0x0c || colspan=2 {{Unknown|End of '''SFAT''' header}}
+
| 0x0C || colspan=2 {{Unknown|End of '''SFAT''' header}}
 
|}
 
|}
  
Line 57: Line 59:
 
| 0x08 || 4 || '''Beginning of node file data''', relative to the '''Beginning of data''' offset specified in the '''SARC header'''.
 
| 0x08 || 4 || '''Beginning of node file data''', relative to the '''Beginning of data''' offset specified in the '''SARC header'''.
 
|-
 
|-
| 0x0c || 4 || '''End of node file data''', relative to the '''Beginning of data''' offset specified in the '''SARC header'''.
+
| 0x0C || 4 || '''End of node file data''', relative to the '''Beginning of data''' offset specified in the '''SARC header'''.
 
|-
 
|-
 
| 0x10 || colspan=2 {{Unknown|End of node}}
 
| 0x10 || colspan=2 {{Unknown|End of node}}
Line 65: Line 67:
 
The hash is calculated like this:
 
The hash is calculated like this:
 
<pre>
 
<pre>
uint GetHash(char* name, int length, uint multiplier)
+
uint GetHash(char* name, int length, uint key)
 
{
 
{
 
uint result = 0;
 
uint result = 0;
 
for(int i = 0; i < length; i++)
 
for(int i = 0; i < length; i++)
 
{
 
{
result = name[i] + result * multiplier;
+
result = name[i] + result * key;
 
}
 
}
 
return result;
 
return result;
Line 89: Line 91:
 
| 0x04 || 2 || '''Header Length''': the length of this header in bytes. Always '''0x8'''.
 
| 0x04 || 2 || '''Header Length''': the length of this header in bytes. Always '''0x8'''.
 
|-
 
|-
| 0x06 || 2 || {{Unknown|'''Unknown.''' Always '''0'''?}}
+
| 0x06 || 2 || Reserved.
 
|-
 
|-
 
| 0x08 || colspan=2 {{Unknown|End of '''SFNT''' header}}
 
| 0x08 || colspan=2 {{Unknown|End of '''SFNT''' header}}
Line 98: Line 100:
  
 
== File Data ==
 
== File Data ==
The data begins at the '''Beginning of data''' offset specified in the '''SARC Header'''. The padding between the internal files vary between different files. Some files use no padding.
+
The data begins at the '''Beginning of data''' offset specified in the '''SARC Header'''. The alignment of the internal files vary between different files. Some files use 0x4 as the alignment.
  
 
= Tools =
 
= Tools =
 
The following tools can handle SARC files:
 
The following tools can handle SARC files:
 
 
* [http://florian.nouwt.com/wiki/index.php/Every_File_Explorer Every File Explorer], by [[Gericom]]
 
* [http://florian.nouwt.com/wiki/index.php/Every_File_Explorer Every File Explorer], by [[Gericom]]
 +
* [https://github.com/aboood40091/SARC-Tool/releases/tag/v0.3 SARC Tool], by [[User:Aboood40091|AboodXD]]
 
* [https://github.com/NWPlayer123/WiiUTools/tree/master/SARCTools SARCTools], by [[User:NWPlayer123|NwPlayer123]]
 
* [https://github.com/NWPlayer123/WiiUTools/tree/master/SARCTools SARCTools], by [[User:NWPlayer123|NwPlayer123]]
 
* [https://drive.google.com/file/d/0B9ETxoIujjPFLTJOY2pIZ3RfRms/view Uwizard], by [[User:Mr. Mysterio|Mr. Mysterio]]
 
* [https://drive.google.com/file/d/0B9ETxoIujjPFLTJOY2pIZ3RfRms/view Uwizard], by [[User:Mr. Mysterio|Mr. Mysterio]]
 
* [https://github.com/smb123w64gb/Uwizard/releases/tag/1.2.0 Uwizard.Woomy], by [[User:smb123w64gb|smb123w64gb]]
 
* [https://github.com/smb123w64gb/Uwizard/releases/tag/1.2.0 Uwizard.Woomy], by [[User:smb123w64gb|smb123w64gb]]
 +
* [[Wexos's Toolbox]], by [[Wexos]]
 
* [https://www.dropbox.com/sh/tfg2nd6q809oqn3/AADWk3SgQEsqnvlbplcWOfv5a WiiUExplorer], by [[User:Celcodioc|Celcodioc]]
 
* [https://www.dropbox.com/sh/tfg2nd6q809oqn3/AADWk3SgQEsqnvlbplcWOfv5a WiiUExplorer], by [[User:Celcodioc|Celcodioc]]
* [[Wexos's Toolbox]], by [[Wexos]]
 
  
 
[[Category:File Format]]
 
[[Category:File Format]]

Latest revision as of 12:55, 26 May 2022

SARC Files are archive files used in Wii U and 3DS, including Mario Kart 8. They are similar to the U8 files found in GameCube and Wii games. 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 AAMP/shader files). SARC files are sometimes Yaz0 compressed into .szs files.

File Format

The basic structure of the archive is a SARC Header followed by a File Table and a File Name Table. Finally, the content of all files in the archive is stored directly. The File Table references the data.

Header (SARC)

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

Offset Size Description
0x00 4 Magic: 0x53415243 ("SARC" in ASCII).
0x04 2 Header Length: the length of this header in bytes. Always 0x14.
0x06 2 Byte Order Mark (BOM): 0xFEFF for big endian and 0xFFFE for little endian.
0x08 4 File size of the entire archive in bytes.
0x0C 4 Beginning of data offset.
0x10 2 Version number of the file format. Always 0x0100.
0x12 2 Reserved.
0x14 End of SARC header

File Allocation Table

Unlike the U8 format, SARC does generally not contain directory nodes (though files may reside inside subfolders).

Header (SFAT)

The SARC Header is immediately followed by 12 byte SFAT Header structure.

Offset Type Description
0x00 4 Magic: 0x53464154 ("SFAT").
0x04 2 Header Length: the length of this header in bytes. Always 0xC.
0x06 2 Node count.
0x08 4 Hash Key. Always 0x00000065.
0x0C End of SFAT header

Node

The SFAT Header is followed by an array of 16 byte SFAT Node structures.

Offset Size Description
0x00 4 File Name Hash. Look below for the calculation.
0x04 4 File Attributes, if flag 0x01000000 is set, bottom half (0xFFFF) is the Name Table offset (after header), divided by 4.
0x08 4 Beginning of node file data, relative to the Beginning of data offset specified in the SARC header.
0x0C 4 End of node file data, relative to the Beginning of data offset specified in the SARC header.
0x10 End of node

File Name Hash

The hash is calculated like this:

uint GetHash(char* name, int length, uint key)
{
	uint result = 0;
	for(int i = 0; i < length; i++)
	{
		result = name[i] + result * key;
	}
	return result;
}

File Name Table

The File Name Table is a list of null-terminated strings which represent the filenames of the packed files. It is referenced by SFAT Nodes.

Header (SFNT)

The SFAT Node array is immediately followed by an 8 byte SFNT Header structure.

Offset Size Description
0x00 4 Magic: 0x53464E54 ("SFNT").
0x04 2 Header Length: the length of this header in bytes. Always 0x8.
0x06 2 Reserved.
0x08 End of SFNT header

Strings

The SFAT Header is immediately followed by 4-byte aligned null-terminated strings that represent the filenames of the packed files.

File Data

The data begins at the Beginning of data offset specified in the SARC Header. The alignment of the internal files vary between different files. Some files use 0x4 as the alignment.

Tools

The following tools can handle SARC files: