PAK (File Format)/RetroStudios: Difference between revisions

From Wexos's Wiki
Jump to navigationJump to search
(Created page with "'''PAK''' is an archive file format used in games such as Donkey Kong Country Returns created by RetroStudios. = File Format = == Header == The file starts with the following header: {|class="wikitable" ! Offset !! Type !! Description |- | 0x00 || UInt32 || {{Unknown-left|'''Unknown'''. Always 2, possibly a version number.}} |- | 0x04 || UInt32 || '''Header size'''. Always 0x40. |- | 0x08 || Byte[0x10] || '''MD5 hash''' of the file data following the header. |- |...")
 
mNo edit summary
Line 37: Line 37:
|}
|}


Afterwards the section data is layout in the same order as they are specified above.
At 0x80 the section data for each section starts. They are laid out in the same order as they are specified above.


== STRG ==
== STRG ==
The '''STRG''' data starts with the following structure:
The '''STRG''' section specifies files which are named, in other words identified by a string. It starts with the following structure:


{|class="wikitable"
{|class="wikitable"
Line 60: Line 60:
| '''N''' + 1 || Char[4] || '''Resource magic'''. File magic of the resource specifying file type.
| '''N''' + 1 || Char[4] || '''Resource magic'''. File magic of the resource specifying file type.
|-
|-
| '''N''' + 5 || UInt64 || '''Resource ID'''.
| '''N''' + 5 || UInt64 || '''Resource ID'''. There is always an entry in the [[#RSHD|RSHD section]] with the same ''Resource ID''.
|}
|}


== RSHD ==
== RSHD ==
The '''RSHD ''' data starts with the following structure:
The '''RSHD ''' section specifies all files, where the files are identified by a 64-bit integer. All files in [[#STRG|STRG]] are also stores in the RSHD section. It starts with the following structure:


{|class="wikitable"
{|class="wikitable"
Line 80: Line 80:
! Offset !! Type !! Description
! Offset !! Type !! Description
|-
|-
| 0x00 || UInt32 || '''Compression flag'''. Either 0 (uncompressed) or 1 (compressed).
| 0x00 || UInt32 || '''Compression flag'''. Either 0 (uncompressed) or 1 (compressed). In Donkey Kong Country Returns, files may be compressed using ZLib.
|-
|-
| 0x04 || Char[4] || '''Resource magic'''. File magic of the resource specifying file type.
| 0x04 || Char[4] || '''Resource magic'''. File magic of the resource specifying file type.

Revision as of 19:23, 11 July 2025

PAK is an archive file format used in games such as Donkey Kong Country Returns created by RetroStudios.

File Format

Header

The file starts with the following header:

Offset Type Description
0x00 UInt32 Unknown. Always 2, possibly a version number.
0x04 UInt32 Header size. Always 0x40.
0x08 Byte[0x10] MD5 hash of the file data following the header.
0x18 Byte[0x18] Padding.

Table Of Content

After the header, a table of content structure specify what sections are stored in the file. It has the following structure:

Offset Type Description
0x00 UInt32 Section count (N). In practice this will always be 3 with order STRG, RSHD, DATA.

N entries of the following structure follows.

Offset Type Description
0x00 Char[4] Section magic.
0x04 UInt32 Section size in bytes.

At 0x80 the section data for each section starts. They are laid out in the same order as they are specified above.

STRG

The STRG section specifies files which are named, in other words identified by a string. It starts with the following structure:

Offset Type Description
0x00 UInt32 Number of named resources (N).

Immediately afterwards N named resources follows.

Named Resource

Each resource has the following structure:

Offset Type Description
0x00 Char[N + 1] Resource name stored as a null-terminated string of length N.
N + 1 Char[4] Resource magic. File magic of the resource specifying file type.
N + 5 UInt64 Resource ID. There is always an entry in the RSHD section with the same Resource ID.

RSHD

The RSHD section specifies all files, where the files are identified by a 64-bit integer. All files in STRG are also stores in the RSHD section. It starts with the following structure:

Offset Type Description
0x00 UInt32 Number of resources (N).

Immediately afterwards N resources follows.

Resource

Each resource has the following structure:

Offset Type Description
0x00 UInt32 Compression flag. Either 0 (uncompressed) or 1 (compressed). In Donkey Kong Country Returns, files may be compressed using ZLib.
0x04 Char[4] Resource magic. File magic of the resource specifying file type.
0x08 UInt64 Resource ID.
0x10 UInt32 File data size in bytes.
0x14 UInt32 File data offset, relative to the start of the DATA section.

DATA

All file data is stored in the DATA section and references by each resource.

Tools

The following tools can handle PAK files: