Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

GameCube Tooling: Difference between revisions

No edit summary
 
(36 intermediate revisions by 3 users not shown)
Line 1: Line 1:
__TOC__
[[Gotcha Force | ← Gotcha Force]]


Le DVD GameCube est au format GCM (extension gcm ou iso) et peut [https://discourse.world/h/2017/07/24/Gamecube-file-system-device se diviser en 6 parties] :
== Tools ==
* boot.bin (Informations de base)
=== [https://fr.dolphin-emu.org/download/ Dolphin Emulator] ===
* bi2.bin (Informations additionnelles)
Dolphin allows for the extraction of GameCube ISO files. It can be used in debug mode for stepping through PowerPC instructions, setting breakpoints, memory inspection/dumping, and more.
* apploader.img (Chargeur de l’exécutable principal)
==== [https://github.com/aldelaro5/Dolphin-memory-engine Dolphin Memory Engine] ====
* fst.bin (FileStringTable)
Dolphin Memory Engine utilizes Dolphin dumps (in debug mode: add -d when running Dolphin) to assign names to fixed memory addresses during execution. This enables sharing reverse engineering work on the game's memory.
* boot.dol / elf (Exécutable principal)
 
* Fichiers
Documentation on symbol generation: [https://github.com/sepalani/MHTrIDA/wiki/Symbols Symbols]
 
==== [https://github.com/Felk/dolphin Python Support for Dolphin Emulator] ====
Python support for AI/CPU scripting. The API allows reading and writing to memory, among other capabilities.
 
=== [https://github.com/Virtual-World-RE/NeoGF/tree/main/gcmtool gcmtool.py] (Virtual World RE) ===
gcmtool.py allows manipulation of GameCube files (GCM ISO format). It can extract all game files, as well as files related to GCM format operations. Its primary feature is patching the FST and the boot.bin file with a new boot.[[DOL_(File_format)|DOL]] file, a new apploader.img, and added, deleted, or modified game files. It aligns all file offsets according to a specified value, with a default alignment of 4. DVD files are also optimally positioned to minimize the GCM ISO size.
 
Open-source & MIT license.
 
=== [https://github.com/Virtual-World-RE/NeoGF/tree/main/afstool afstool.py] (Virtual World RE) ===
<div class="toccolours mw-collapsible mw-collapsed">
Python3 script for unpacking/packing/rebuilding the [[AFS_(File_format)|AFS]] file format. Reconstruction of the Table of Contents (TOC) and Filename Directory (FD) is possible with control over all possible format parameters.
<div class="mw-collapsible-content">
==== User Manual ====
'''Unpack source_afs.afs''' into the new default folder ''source_afs''. If optional_dest_folder is specified, unpack into ''optional_dest_folder''. If the AFS has an FD, it will use the OS modification date (mtime) to store the file's date.
 
afstool.py --unpack source_afs.afs optional_dest_folder
 
Pack '''source_folder''' into the new default folder ''source_folder.afs''. If optional_dest_file.afs is specified, pack into ''optional_dest_file.afs''. If the AFS has an FD, it will use the OS modification date (mtime) to update the file's date in the AFS. The maximum size of each file is determined by the next offset in the [[AFS_(File_format)|AFS]] (file or system file). Without an FD, there are no restrictions on the size of the last file in the [[AFS_(File_format)|AFS]]. The names in the FD remain unchanged by this command.
 
afstool.py --pack source_folder optional_dest_file.afs
 
Rebuilds the file system of an unpacked [[AFS_(File_format)|AFS]] folder using the afs_rebuild.conf and afs_rebuild.csv files. See below for more information on afs_rebuild.conf.


Le fichier dol et la fst peuvent être l'un avant l'autre ou non. On retrouvera cependant souvent le dol avant la fst. On notera que l'ensemble des ROMs GCM ont une taille fixe liée au format du mini DVD : 1 459 978 240 octets. De ce fait, il existe pour de nombreux jeux des espaces "libres" entre les fichiers pouvant être considérablement grands. Ces espaces contiennent souvent des données qui n'ont aucune utilité lors de l'exécution du jeu. Il pourrait s'agir de données aléatoires, ou de données écrasées lors de réécritures sur un même DVD par les développeurs. Il reste à déterminer si ces données sont identiques sur tous les exemplaires de DVDs d'un même jeu.
afstool.py --rebuild source_folder


== Structure du format GCM/ISO ==
Displays statistics of the [[AFS_(File_format)|AFS]] or the unpacked folder of the [[AFS_(File_format)|AFS]]. Provides information about the header, TOC, FD, the entire memory mapping sorted by offsets (files and system files), information about the address space, and grouped duplicate file names.
=== boot.bin ===
Le fichier boot.bin est au début du DVD et a une taille de 0x440 octets. On y retrouve :
* L'offset du fichier boot.dol par rapport au début du DVD, à l'offset boot.bin:0x420.
* L'offset de la File String Table (fst.bin), à l'offset boot.bin:0x424.
* La taille de la FST, à l'offset boot.bin:0x428
* La taille max de la FST, à l'offset boot.bin:0x42c


=== bi2.bin ===
afstool.py --stats path
Le fichier bi2.bin a une taille de 0x2000 octets et se situe à la suite du fichier boot.bin (donc à l'offset 0x440 de l'iso). Il contient des informations de debug.


=== boot.dol ===
==== Extracted Files Structure ====
Le fichier au format dol est un exécutable compilé pour l'architecture Gekko (powerpc). Son [http://wiki.tockdom.com/wiki/DOL_(File_Format) header] fait 0x100 octets, et on trouvera la taille totale du dol en additionnant la taille du header et la taille de l'ensemble des 18 sections de celui-ci. A partir de l'offset 0x90, on trouvera 18 uint de 4 octets (big endian) contenant les tailles des 18 sections.


=== Apploader ===
The '''root''' folder contains all files from the [[AFS_(File_format)|AFS]].
L'[https://www.gc-forever.com/wiki/index.php?title=Apploader apploader] est un fichier, lancé par le BIOS de la GameCube (aussi appelé l'[https://wiki.dolphin-emu.org/index.php?title=GameCube_Main_Menu Initial Program Loader / IPL]), qui permet de créer les différents espaces mémoires pour lancer l'exécutable du jeu (généralement au format dol). Il se situe à l'offset 0x2440, à la suite du fichier bi2.bin. Il portera un nom différent selon les programmes que l'on utilisera pour ouvrir l'image DVD du jeu : AppLoader.ldr / apploader.img (dolphin Emulator) etc.


La taille de l'apploader se calcul à partir de son header :
The '''sys''' folder contains all system files of the [[AFS_(File_format)|AFS]] and files generated by the program for various [[AFS_(File_format)|AFS]] manipulations:
* Le header fait 0x20 octets
    tableofcontent.bin - TOC system file: This file can be directly edited and is managed by the --pack command.
* apploader_size à l'offset 0x14, donc à l'offset 0x2454 de l'iso GCM.
    filenamedirectory.bin - FD system file: This file is created only if there is an FD in the [[AFS_(File_format)|AFS]].
* trailer_size à l'offset 0x18, donc à l'offset 0x458 de l'iso GCM. La trailer_size est un espace réservé à d'éventuelles évolutions de l'apploader.
    filename_resolver.csv - Created when multiple files have the same name in the FD.
    afs_rebuild.conf - Modify this file to rebuild the [[AFS_(File_format)|AFS]].
    afs_rebuild.csv - Modify this file while taking into account the configurations from afs_rebuild.conf to reconstruct the [[AFS_(File_format)|AFS]].


=== File String Table ===
==== filename_resolver.csv ====
La FST permet de packer l'arborescence de fichiers et de dossiers du jeu dans la suite de l'iso. Elle se divise en deux blocks :
The --pack command does not change the names in the FD. This file is used in the packing process to automatically detect renamed files in the '''root''' folder and keep their initial index in the TOC (and FD). This file is generated automatically when:
* Le premier contient les entrées de la FST (dossiers et fichiers). (Big endian)
* The FD is present and contains duplicates in the names; extracted files are then renamed "filename '''(N)'''.ext" with N: Integer,
* Le second, le name_block, contient tous les noms des dossiers et des fichiers chacun terminés par un NULL byte (0x00). (Little endian)
* The FD is absent, and files are named by their index, for example: "00000000" for the very first file.


Dans la première partie, on indexera tous les dossiers et les fichiers à partir du numéro 1. Chaque dossier ou fichier est traduit en 12 octets, et la toute première entrée est le nœud racine, portant l'index 0.
Each line in the CSV contains an "index/unpacked_filename" pair. This CSV can be used to rename files, for example: "0/my_new_filename.ext".


Les 12 octets d'une entrée pour un dossier :
==== afs_rebuild.conf ====
* 1 octet pour le type, dossier=0x01.
Each offset or index is written in hexadecimal with the prefix '''0x''': 0xabcdef. The value '''auto''' will be used where possible.
* 3 octets uint pour l'offset du nom dans le name_block, commençant à l'offset 0 au début du name_block.
* 4 octets uint pour l'index du dossier parent.
* 4 octets uint pour l'index du dossier ou fichier suivant.


Les 12 octets d'une entrée pour un fichier :
===== [Default] section =====
* 1 octet pour le type, fichier=0x01.
* 3 octets uint pour l'offset du nom dans le name_block, commençant à l'offset 0 au début du name_block.
* 4 octets uint pour l'offset du fichier par rapport au début de l'iso GCM.
* 4 octets uint pour la taille du fichier.


Le nœud racine se situe au tout début de la fst, c'est un dossier avec les 3 octets de l'offset du nom et les 4 octets du dossier parent à 0x00. L'index du fichier suivant est égal au nombre total de dossiers et de fichiers du DVD. On trouvera alors l'offset du name_block en multipliant cet index par 12 et en y ajoutant 12 (taille du nœud racine).
'''AFS_MAGIC''' : 0x41465300 or 0x41465320


L'alignement de l'ensemble des fichiers est important lors de la construction du boot.bin et de la fst. En effet, on alignera par exemple sur 4 octets, l'iso GCM ne fonctionnant pas au cas contraire.
'''files_rebuild_strategy''' : auto, index, offset, or mixed


Les DVD GCM JAP contiennent des caractères non utf-8 dans le name_block. L'application [https://github.com/Virtual-World-RE/NeoGF/blob/main/gcmtool.py gcmtool.py], permettant de parser les iso GCM et de les patcher ne prends pas en charge ces jeux là. Dolphin Emulator extraira les fichiers en traduisant le charset original en utf-8.
'''files_rebuild_strategy''' is used to organize files (indexes, offsets, packed filenames if the FD is present) in the AFS. The rebuild strategy uses the automatically generated afs_rebuild.csv file during unpacking. If the root folder's file is absent from afs_rebuild.csv, all values will be generated automatically. Four strategies are available:


Le tris des dossiers et fichiers est non sensible à la casse (tous les noms en majuscules), et fait apparaître les caractères spéciaux avant les lettres.
    '''auto''' : Automatically rebuild all indexes and offsets of specified files (uses packed_filename to specify the filename in the FD if present). Indexes and offsets in the afs_rebuild.csv file will be ignored.
== Formats d'extraction ==
    '''index''' : Keeps the indexes of specified files (uses packed_filename if the FD is present). Offsets will be ignored.
    '''offset''' : Keeps the offsets of specified files (uses packed_filename if the FD is present). Indexes will be ignored.
    '''mixed''' : Keeps both indexes and offsets of specified files (uses packed_filename if the FD is present).


Le format GCReEx comporte les informations suivantes :
'''filename_directory''' : True if the FD is present, False otherwise. If the value is True, the [FilenameDirectory] section must be present.
sys:
|- apploader.img
|- boot.bin (Information de base)
|- bi2.bin  (Information supplémentaires)
|- fst.bin  (FileStringTable)
\- main.dol ("Executable" DOL)
root:
|- banner.bnr
\+ ALL GAME DATA (AFS, etc)


Le format DiscEx comporte moins d'informations :
===== [FilenameDirectory] section =====
sys:
|- apploader.img
|- boot.bin (Information de base du jeu)
\- bi2.bin  (Information supplémentaires)
game.iso : Copie repack de l'iso d'origine.


On retrouvera d'autres formats.
'''toc_offset_of_fd_offset''' : The offset in the TOC of the FD offset is at the end of the TOC. In some AFS, there is padding at the end of the offset/length series. The value '''auto''' will be used where possible.


Ce wiki sur le [https://wiki.gbatemp.net/wiki/NKit/Discs#Disc_Header format nkit] offre une très bonne documentation sur le format GCM.
'''fd_offset''' : The FD is at the end of the [[AFS_(File_format)|AFS]]. The value '''auto''' will be used where possible.


== Outils ==
'''fd_last_attribute_type''' : The type of the last 4 bytes of each FD entry. Four values are possible:
=== [https://fr.dolphin-emu.org/download/ Emulateur Dolphin] ===
    '''length''' : Use the file size.
Dolphin permet l'extraction des fichiers de l'iso GameCube. On pourra l'utiliser en mode debug :
    '''offset-length''' : Use the "offset/length/offset/length..." series.
Exécution pas à pas des instructions powerpc, breakpoints, inspection / dumps mémoires etc.
    '''0xabcdef''' : Use a hexadecimal constant.
==== [https://github.com/aldelaro5/Dolphin-memory-engine Dolphin Memory Engine] ====
    '''unknown''' : The value is unknown. The Null value will be used.
Dolphin Memory Engine se sert des dumps dolphin (en mode débug : ajoutez -d lors de l'exécution de dolphin) afin de mettre des noms sur des adresses mémoires fixes lors de l'exécution. Ceci permettra de partager des travaux de reverse engineering sur la mémoire du jeu.
 
==== afs_rebuild.csv ====
'''afs_rebuild.csv''' contains entries describing how to pack files from the '''root''' folder into the AFS. Each offset or index value is stored in hexadecimal with the prefix '''0x''': 0xabcdef. The value '''auto''' will be used for indexes and offsets where possible. Offsets must be aligned to the value 0x800 (2048). One line per selected file is added with constraints for packing using the format: "unpacked_filename/index/offset/packed_filename", for example: "dummy (5).bin/0x12/0x80000/dummy.bin". You can use the value '''auto''', for example: "dummy (5).bin/auto/auto/dummy.bin". For each empty block, only an offset/length pair with values aligned to 0x800 will be added, for example: "0x80000/0x5000".


=== [https://github.com/Virtual-World-RE/NeoGF/blob/main/gcmtool.py gcmtool.py] (Virtual World RE) ===
When configuring the rebuild, all lines containing files with no constraints from the afs_rebuild.csv file will be removed. Then, the '''auto''' value will be added to offsets and indexes with no constraints. During the rebuild, the filename_resolver.csv file is automatically deleted. Changes to file names will be preserved by adding entries with unpacked_filename and index (and packed_filename if the FD is present) in this file.
gcmtool.py permet de manipuler les fichiers gamecube (format iso GCM). On pourra extraire l'ensemble des fichiers du jeu, ainsi que les fichiers relatif au fonctionnement du format GCM. Sa qualité principale, c'est de permettre de patcher la fst et le fichier boot.bin avec un nouveau fichier boot.dol, un nouvel apploader.img, ainsi que des fichiers du jeu ajoutés, supprimés ou modifiés. Il permet d'aligner l'ensemble des offsets des fichiers selon une valeur passée en argument. On choisira un alignement de 4 par défaut. Les fichiers du DVD sont aussi positionnés de manière optimisée pour réduire la taille de l'iso GCM à son minimum.<br>
</div></div>
Open source & licence MIT.
Open-source & MIT license.


=== [https://github.com/Virtual-World-RE/NeoGF/blob/main/afstool.py afstool.py] (Virtual World RE) ===
=== [https://github.com/Virtual-World-RE/NeoGF/tree/main/doltool doltool.py] ===
afstool.py (en cours de développement - les options ne sont pas encore toutes implémentées) est un programme qui permet de manipuler les fichiers au format [[AFS (Format de fichier)|afs]] :
Python 3 script for manipulating the [[DOL_(File_format)|DOL]] file format. It also provides detailed statistics on the [[DOL_(File_format)|DOL]] and its composition, and can patch a [[DOL_(File_format)|DOL]] using an Action Replay Codes file.
* unpack - extraction de tous les fichiers,
* pack - met à jour les fichiers modifiés sur la base de la date de modification, dans la limite ou le fichier ne dépasse pas sa taille initiale en blocks ( multiple de 0x800 octets),
* rebuild - de la table of content (TOC) et du filename directory (FD), deux fichiers qui font la structure de l'afs, avec la possibilité de préciser l'offset de "l'offset de la FD" dans la TOC.
* list - description des informations de l'afs.


=== [https://github.com/MaikelChan/AFSPacker AFS Packer] ===
Open-source & MIT license.
AFS Packer est simple d'utilisation et fonctionnel. Ce logiciel permet d'extraire et patcher les fichier au format afs.<br>
Open source & licence MIT.


=== [https://wit.wiimm.de/ Wiimms ISO Tool] ===
=== [https://github.com/MaikelChan/AFSPacker AFSPacker] ===
wit permet de manipuler les ISO GameCube. Sur windows, on pourra utiliser wit sans passer par l'installation en utilisant le fichier bin/wit.exe.
AFSPacker is user-friendly and functional. This software allows for extraction and patching of files in the [[AFS_(File_format)|AFS]] format.


Extraction des fichiers d'une ISO (au format [https://wit.wiimm.de/info/composing.html fst]) :
* AFSPacker considers the last 4 bytes of FD entries as unknown. These bytes are sometimes used to describe the size of packed files.
wit extract mkw.iso --dest=mkw/
* It is not possible to specify the offset of the FD in the TOC. This offset can be placed directly after the TOC or after padding following the TOC. This can be important if the main executable handles files with a hardcoded file offset relative to the start of the [[AFS_(File_format)|AFS]].
* Dates are not retained during extraction, resulting in data loss with each repack.


Attention, le rapack dans l'iso via la commande copy ne produit à priori pas la même ISO (fichier de + de 4 Go). A voir si des options permettent de reproduire la bonne ISO.
Open-source & MIT license.


=== [https://www.moddingway.com/file/270.html AFS Explorer] ===
=== [https://www.moddingway.com/file/270.html AFS Explorer] ===
On évitera d'utiliser AFS Explorer dans les projets quand AFS Packer peut être utilisé. En effet, les conditions d'utilisation sont restrictives et la ligne de commande est absente.
AFS Explorer should be avoided in projects where afstool.py can be used. The terms of use are restrictive, and command-line functionality is absent.
Les sources ne sont à priori pas accessibles, ce qui est un autre point limitant.
The source code does not appear to be accessible, which is another limiting factor.


=== [http://www.wiibackupmanager.co.uk/gcit.html GameCube Iso Tools] ===
=== [http://www.wiibackupmanager.co.uk/gcit.html GameCube Iso Tools] ===
Outil de manipulation d'iso GameCube. Permet d'extraire l'iso dans un dossier au format GCReEx ou DiscEx. Permet ensuite de repack dans une ISO.<br>
A tool for manipulating GameCube ISOs. It allows extraction of the ISO into a GCReEx or DiscEx format folder. It can also repack into an ISO format.<br>
Note : L'iso repack est automatiquement "compressée" sous windows. Le dossier de destination doit être créé au préalable.<br>
Note: The repacked ISO is automatically "compressed" on Windows. The destination folder must be created in advance.<br>


Commandes :<br>
Commands:<br>
'''gcit.exe iso.iso -f gcreex -d extract -q'''<br>
gcit.exe iso.iso -f gcreex -d extract -q
'''gcit.exe extract\Game_folder -f fulliso -d repack.iso -q'''<br>
gcit.exe extract\Game_folder -f fulliso -d repack.iso -q


L'ISO repack diffère de l'ISO originale, il est à déterminer ce qui cause cette différence. Dolphin Emulator renvoie une erreur sur repack.iso : "repack.iso n'est pas un fichier GCM/ISO valide, ou n'est pas une ISO GC/Wii."
Dolphin Emulator may return an error for repack.iso: "repack.iso is not a valid GCM/ISO file, or is not a GC/Wii ISO."
Au format GCReEx, on remarque que le padding à la fin de l'apploader est différent de celui généré par Dolphin Emu. De même, de nombreux fichiers sont extraits avec gcit.exe avec un padding ajouté à la fin comparé à la taille réelle indiquée dans le fst.bin du DVD.
In GCReEx format, it is noticed that the padding at the end of the apploader is different from that generated by Dolphin Emulator. Additionally, many files extracted with gcit.exe have padding added to the end compared to the actual size indicated in the DVD's fst.bin.
 
=== [https://wit.wiimm.de/ Wiimms ISO Tool] ===
wit allows manipulation of GameCube ISOs. On Windows, wit can be used without installation by using the bin/wit.exe file.
 
Extraction of files from an ISO (in [https://wit.wiimm.de/info/composing.html fst] format):
wit extract mkw.iso --dest=mkw/
 
Please note that repacking into the ISO via the copy command does not seem to produce the same ISO (over 4 GB file). It needs to be investigated if there are options to reproduce the correct ISO.
 
https://github.com/Wiimm/wiimms-iso-tools
 
Open-source & GPL v2+ license.


=== GC Rebuilder 1.1 ===
=== GC Rebuilder 1.1 ===
Attention, ce projet n'est plus développé, et la taille de l'exécutable principal n'est pas la bonne.
Please note that this project is no longer developed, and the size of the main executable is incorrect.
Code source : https://github.com/bsv798/gcrebuilder
 
Source code: https://github.com/bsv798/gcrebuilder
 
The command-line interface is present, but no specific documentation is provided.
 
=== [https://github.com/sup39/GeckoLoader GeckoLoader] ===
Gecko Loader allows patching a [[DOL_(File_format)|DOL]] using a list of [https://github.com/dolphin-emu/dolphin/tree/master/docs/ActionReplay Action Replay Codes] or [http://wiigeckocodes.github.io/codetypedocumentation.html GeckoCodes]. The software also allows hooking functions (VI, etc.).
 
For example, there may be a .bss patch with PowerPC bytecode and values to patch. The EntryPoint is changed to reach this new code, and after loading into memory, the code modifies the values in memory.
 
This is considered a bad practice because .bss contains uninitialized variables (int a;). Normally, they should be Null / 0. Additionally, for write-only codes, it is preferable to patch the .text or .data sections of the [[DOL_(File_format)|DOL]] directly when possible.
 
Open-source & GPL v3 license.


[[Catégorie:Format de fichier]]
[[Category:GameCube]]
[[Catégorie:Gotcha Force]]
[[Category:Tools]]
[[Category:Gotcha Force]]

Latest revision as of 12:33, 7 October 2023

← Gotcha Force

Tools

Dolphin Emulator

Dolphin allows for the extraction of GameCube ISO files. It can be used in debug mode for stepping through PowerPC instructions, setting breakpoints, memory inspection/dumping, and more.

Dolphin Memory Engine

Dolphin Memory Engine utilizes Dolphin dumps (in debug mode: add -d when running Dolphin) to assign names to fixed memory addresses during execution. This enables sharing reverse engineering work on the game's memory.

Documentation on symbol generation: Symbols

Python Support for Dolphin Emulator

Python support for AI/CPU scripting. The API allows reading and writing to memory, among other capabilities.

gcmtool.py (Virtual World RE)

gcmtool.py allows manipulation of GameCube files (GCM ISO format). It can extract all game files, as well as files related to GCM format operations. Its primary feature is patching the FST and the boot.bin file with a new boot.DOL file, a new apploader.img, and added, deleted, or modified game files. It aligns all file offsets according to a specified value, with a default alignment of 4. DVD files are also optimally positioned to minimize the GCM ISO size.

Open-source & MIT license.

afstool.py (Virtual World RE)

Python3 script for unpacking/packing/rebuilding the AFS file format. Reconstruction of the Table of Contents (TOC) and Filename Directory (FD) is possible with control over all possible format parameters.

User Manual

Unpack source_afs.afs into the new default folder source_afs. If optional_dest_folder is specified, unpack into optional_dest_folder. If the AFS has an FD, it will use the OS modification date (mtime) to store the file's date.

afstool.py --unpack source_afs.afs optional_dest_folder

Pack source_folder into the new default folder source_folder.afs. If optional_dest_file.afs is specified, pack into optional_dest_file.afs. If the AFS has an FD, it will use the OS modification date (mtime) to update the file's date in the AFS. The maximum size of each file is determined by the next offset in the AFS (file or system file). Without an FD, there are no restrictions on the size of the last file in the AFS. The names in the FD remain unchanged by this command.

afstool.py --pack source_folder optional_dest_file.afs

Rebuilds the file system of an unpacked AFS folder using the afs_rebuild.conf and afs_rebuild.csv files. See below for more information on afs_rebuild.conf.

afstool.py --rebuild source_folder

Displays statistics of the AFS or the unpacked folder of the AFS. Provides information about the header, TOC, FD, the entire memory mapping sorted by offsets (files and system files), information about the address space, and grouped duplicate file names.

afstool.py --stats path

Extracted Files Structure

The root folder contains all files from the AFS.

The sys folder contains all system files of the AFS and files generated by the program for various AFS manipulations:

   tableofcontent.bin - TOC system file: This file can be directly edited and is managed by the --pack command.
   filenamedirectory.bin - FD system file: This file is created only if there is an FD in the AFS.
   filename_resolver.csv - Created when multiple files have the same name in the FD.
   afs_rebuild.conf - Modify this file to rebuild the AFS.
   afs_rebuild.csv - Modify this file while taking into account the configurations from afs_rebuild.conf to reconstruct the AFS.

filename_resolver.csv

The --pack command does not change the names in the FD. This file is used in the packing process to automatically detect renamed files in the root folder and keep their initial index in the TOC (and FD). This file is generated automatically when:

  • The FD is present and contains duplicates in the names; extracted files are then renamed "filename (N).ext" with N: Integer,
  • The FD is absent, and files are named by their index, for example: "00000000" for the very first file.

Each line in the CSV contains an "index/unpacked_filename" pair. This CSV can be used to rename files, for example: "0/my_new_filename.ext".

afs_rebuild.conf

Each offset or index is written in hexadecimal with the prefix 0x: 0xabcdef. The value auto will be used where possible.

[Default] section

AFS_MAGIC : 0x41465300 or 0x41465320

files_rebuild_strategy : auto, index, offset, or mixed

files_rebuild_strategy is used to organize files (indexes, offsets, packed filenames if the FD is present) in the AFS. The rebuild strategy uses the automatically generated afs_rebuild.csv file during unpacking. If the root folder's file is absent from afs_rebuild.csv, all values will be generated automatically. Four strategies are available:

   auto : Automatically rebuild all indexes and offsets of specified files (uses packed_filename to specify the filename in the FD if present). Indexes and offsets in the afs_rebuild.csv file will be ignored.
   index : Keeps the indexes of specified files (uses packed_filename if the FD is present). Offsets will be ignored.
   offset : Keeps the offsets of specified files (uses packed_filename if the FD is present). Indexes will be ignored.
   mixed : Keeps both indexes and offsets of specified files (uses packed_filename if the FD is present).

filename_directory : True if the FD is present, False otherwise. If the value is True, the [FilenameDirectory] section must be present.

[FilenameDirectory] section

toc_offset_of_fd_offset : The offset in the TOC of the FD offset is at the end of the TOC. In some AFS, there is padding at the end of the offset/length series. The value auto will be used where possible.

fd_offset : The FD is at the end of the AFS. The value auto will be used where possible.

fd_last_attribute_type : The type of the last 4 bytes of each FD entry. Four values are possible:

   length : Use the file size.
   offset-length : Use the "offset/length/offset/length..." series.
   0xabcdef : Use a hexadecimal constant.
   unknown : The value is unknown. The Null value will be used.

afs_rebuild.csv

afs_rebuild.csv contains entries describing how to pack files from the root folder into the AFS. Each offset or index value is stored in hexadecimal with the prefix 0x: 0xabcdef. The value auto will be used for indexes and offsets where possible. Offsets must be aligned to the value 0x800 (2048). One line per selected file is added with constraints for packing using the format: "unpacked_filename/index/offset/packed_filename", for example: "dummy (5).bin/0x12/0x80000/dummy.bin". You can use the value auto, for example: "dummy (5).bin/auto/auto/dummy.bin". For each empty block, only an offset/length pair with values aligned to 0x800 will be added, for example: "0x80000/0x5000".

When configuring the rebuild, all lines containing files with no constraints from the afs_rebuild.csv file will be removed. Then, the auto value will be added to offsets and indexes with no constraints. During the rebuild, the filename_resolver.csv file is automatically deleted. Changes to file names will be preserved by adding entries with unpacked_filename and index (and packed_filename if the FD is present) in this file.

Open-source & MIT license.

doltool.py

Python 3 script for manipulating the DOL file format. It also provides detailed statistics on the DOL and its composition, and can patch a DOL using an Action Replay Codes file.

Open-source & MIT license.

AFSPacker

AFSPacker is user-friendly and functional. This software allows for extraction and patching of files in the AFS format.

  • AFSPacker considers the last 4 bytes of FD entries as unknown. These bytes are sometimes used to describe the size of packed files.
  • It is not possible to specify the offset of the FD in the TOC. This offset can be placed directly after the TOC or after padding following the TOC. This can be important if the main executable handles files with a hardcoded file offset relative to the start of the AFS.
  • Dates are not retained during extraction, resulting in data loss with each repack.

Open-source & MIT license.

AFS Explorer

AFS Explorer should be avoided in projects where afstool.py can be used. The terms of use are restrictive, and command-line functionality is absent. The source code does not appear to be accessible, which is another limiting factor.

GameCube Iso Tools

A tool for manipulating GameCube ISOs. It allows extraction of the ISO into a GCReEx or DiscEx format folder. It can also repack into an ISO format.
Note: The repacked ISO is automatically "compressed" on Windows. The destination folder must be created in advance.

Commands:

gcit.exe iso.iso -f gcreex -d extract -q
gcit.exe extract\Game_folder -f fulliso -d repack.iso -q

Dolphin Emulator may return an error for repack.iso: "repack.iso is not a valid GCM/ISO file, or is not a GC/Wii ISO." In GCReEx format, it is noticed that the padding at the end of the apploader is different from that generated by Dolphin Emulator. Additionally, many files extracted with gcit.exe have padding added to the end compared to the actual size indicated in the DVD's fst.bin.

Wiimms ISO Tool

wit allows manipulation of GameCube ISOs. On Windows, wit can be used without installation by using the bin/wit.exe file.

Extraction of files from an ISO (in fst format): wit extract mkw.iso --dest=mkw/

Please note that repacking into the ISO via the copy command does not seem to produce the same ISO (over 4 GB file). It needs to be investigated if there are options to reproduce the correct ISO.

https://github.com/Wiimm/wiimms-iso-tools

Open-source & GPL v2+ license.

GC Rebuilder 1.1

Please note that this project is no longer developed, and the size of the main executable is incorrect.

Source code: https://github.com/bsv798/gcrebuilder

The command-line interface is present, but no specific documentation is provided.

GeckoLoader

Gecko Loader allows patching a DOL using a list of Action Replay Codes or GeckoCodes. The software also allows hooking functions (VI, etc.).

For example, there may be a .bss patch with PowerPC bytecode and values to patch. The EntryPoint is changed to reach this new code, and after loading into memory, the code modifies the values in memory.

This is considered a bad practice because .bss contains uninitialized variables (int a;). Normally, they should be Null / 0. Additionally, for write-only codes, it is preferable to patch the .text or .data sections of the DOL directly when possible.

Open-source & GPL v3 license.