Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

prepare gctool for use with wii

Layle0520ef1546e3
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 5ce8012..003a3a5 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -60,8 +60,8 @@ jobs:
- name: Build debugger
run: cargo build --release --package debugger --target ${{ matrix.target }}
- - name: Build gctool
- run: cargo build --release --package gctool --target ${{ matrix.target }}
+ - name: Build multitool
+ run: cargo build --release --package multitool --target ${{ matrix.target }}
- name: Package artifacts (Linux)
if: runner.os == 'Linux'
@@ -69,8 +69,8 @@ jobs:
mkdir -p staging artifacts
cp target/${{ matrix.target }}/release/tinyapp staging/
cp target/${{ matrix.target }}/release/debugger staging/
- cp target/${{ matrix.target }}/release/gctool staging/
- cd staging && zip ../artifacts/gecko-${{ matrix.suffix }}.zip tinyapp debugger gctool
+ cp target/${{ matrix.target }}/release/multitool staging/
+ cd staging && zip ../artifacts/gecko-${{ matrix.suffix }}.zip tinyapp debugger multitool
- name: Package artifacts (Windows)
if: runner.os == 'Windows'
@@ -79,8 +79,8 @@ jobs:
mkdir -p staging artifacts
cp target/${{ matrix.target }}/release/tinyapp.exe staging/
cp target/${{ matrix.target }}/release/debugger.exe staging/
- cp target/${{ matrix.target }}/release/gctool.exe staging/
- cd staging && 7z a ../artifacts/gecko-${{ matrix.suffix }}.zip tinyapp.exe debugger.exe gctool.exe
+ cp target/${{ matrix.target }}/release/multitool.exe staging/
+ cd staging && 7z a ../artifacts/gecko-${{ matrix.suffix }}.zip tinyapp.exe debugger.exe multitool.exe
- uses: actions/upload-artifact@v4
with:
diff --git a/Cargo.lock b/Cargo.lock
index cb55270..4f49264 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1254,18 +1254,6 @@ dependencies = [
"slab",
]
-[[package]]
-name = "gctool"
-version = "0.1.0"
-dependencies = [
- "clap",
- "comfy-table",
- "disasm",
- "image 0.1.0",
- "owo-colors",
- "termtree",
-]
-
[[package]]
name = "gecko"
version = "0.1.0"
@@ -2074,6 +2062,18 @@ dependencies = [
"pxfm",
]
+[[package]]
+name = "multitool"
+version = "0.1.0"
+dependencies = [
+ "clap",
+ "comfy-table",
+ "disasm",
+ "image 0.1.0",
+ "owo-colors",
+ "termtree",
+]
+
[[package]]
name = "multiversion"
version = "0.8.0"
diff --git a/Cargo.toml b/Cargo.toml
index 5e6548c..0fc93ba 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,7 +1,7 @@
[workspace]
resolver = "3"
members = [
- "crates/gctool",
+ "crates/multitool",
"crates/disasm",
"crates/gecko",
"crates/tinytracer",
@@ -19,7 +19,7 @@ members = [
"crates/screenshotter",
]
default-members = [
- "crates/gctool",
+ "crates/multitool",
"crates/disasm",
"crates/gecko",
"crates/tinytracer",
diff --git a/README.md b/README.md
index 2fb5be7..b32e58f 100644
--- a/README.md
+++ b/README.md
@@ -19,7 +19,7 @@ Gecko is in early development. The IPL works flawlessly as far as I can tell. Ma
- `wgpu` based renderer backend
- `wesl` based shader compiler
- LUA scripting/hooks system for runtime introspection
-- Probably the prettiest egui-based debugging UI for GC
+- Probably the prettiest egui-based debugging UI for GameCube and Wii
- Symbol parsing from ELFs and IDA Pro databases
- [Support for web browser](https://gecko.layle.dev)
- [incl. debugging capabilities](https://gecko.layle.dev/dbg)
@@ -27,17 +27,17 @@ Gecko is in early development. The IPL works flawlessly as far as I can tell. Ma
## Projects
-| Crate | Description |
-| ---------- | ----------------------------------------------------------------------------------------------------------- |
-| `tinyapp` | Lightweight emulator application with an egui/wgpu GUI, optional Lua scripting and idle-skip optimization |
-| `debugger` | Interactive GUI debugger built on egui with rendering support, hooks and scripting capabilities |
-| `web` | WebAssembly build of the emulator for browser deployment via wasm-bindgen, with optional debug UI |
-| `gctool` | CLI utility for analyzing and disassembling GameCube binaries (DOL, IPL, ISO) with support for PPC and DSP |
+| Crate | Description |
+| ----------- | ------------------------------------------------------------------------------------------------------------------------------- |
+| `tinyapp` | Lightweight emulator application with an egui/wgpu GUI, optional Lua scripting and idle-skip optimization |
+| `debugger` | Interactive GUI debugger built on egui with rendering support, hooks and scripting capabilities |
+| `web` | WebAssembly build of the emulator for browser deployment via wasm-bindgen, with optional debug UI |
+| `multitool` | CLI utility for analyzing, disassembling and extracting GC/Wii binaries/images (DOL, IPL, ISO/RVZ) with support for PPC and DSP |
## Building
```sh
-cargo build -p gctool --release # multi-tool
+cargo build -p multitool --release # multi-tool
cargo build -p tinyapp --release # main application
cargo build -p debugger --release # debugger
wasm-pack build crates/web --target web --out-dir pkg --release # web version
@@ -49,7 +49,7 @@ For more information refer to the GitHub CI actions file. PGO optimized compilat
## Usage
```sh
-gctool ipl --action decode ipl.encoded.bin ipl.decoded.bin
+multitool ipl --action decode ipl.encoded.bin ipl.decoded.bin
tinyapp --dol homebrew.dol # may also require a DSP depending on the DOL
tinyapp --dvd game.iso --ipl ipl.decoded.bin --dsp dsp_rom.bin
```
diff --git a/crates/gctool/src/iso.rs b/crates/gctool/src/iso.rs
deleted file mode 100644
index 3c2e969..0000000
--- a/crates/gctool/src/iso.rs
+++ /dev/null
@@ -1,116 +0,0 @@
-use image::Executable;
-use image::dvd::{DVD_APPLOADER_OFFSET, FstNode};
-use owo_colors::OwoColorize;
-use termtree::Tree;
-
-use image::Iso;
-
-pub fn info(data: Vec<u8>) {
- let dvd = Iso::parse(data);
-
- let game_name = String::from_utf8_lossy(&dvd.header.game_name);
- let game_name = game_name.trim_end_matches('\0');
-
- println!(" {:<24} {}", "Game Name:".bold(), game_name);
- println!(
- " {:<24} {}",
- "Game Code:".bold(),
- String::from_utf8_lossy(&dvd.header.game_code)
- );
- println!(
- " {:<24} {}",
- "Maker Code:".bold(),
- String::from_utf8_lossy(&dvd.header.maker_code)
- );
- println!(
- " {:<24} {} / {}",
- "Disk / Version:".bold(),
- dvd.header.disk_id,
- dvd.header.version
- );
- println!(" {:<24} {:08X}", "Magic:".bold(), u32::from_be_bytes(dvd.header.magic));
- println!(
- " {:<24} {}",
- "Apploader Date:".bold(),
- String::from_utf8_lossy(&dvd.apploader.timestamp)
- );
- println!(
- " {:<24} {:08X}",
- "Apploader Entrypoint:".bold(),
- dvd.apploader.entrypoint.get()
- );
- println!(
- " {:<24} {:08X}",
- "Main DOL Offset:".bold(),
- dvd.header.offset_main_executable.get()
- );
- println!(
- " {:<24} {:08X} ({} bytes)",
- "FST Offset:".bold(),
- dvd.header.offset_filesystem.get(),
- dvd.header.filesystem_size.get()
- );
-
- println!();
- println!("{}", build_tree(&dvd.filesystem));
-}
-
-fn build_tree(node: &FstNode) -> Tree<String> {
- match node {
- FstNode::Directory { name, children } => {
- let label = if name.is_empty() {
- "/".blue().bold().to_string()
- } else {
- format!("{}", name.blue().bold())
- };
- let mut tree = Tree::new(label);
- for child in children {
- tree.push(build_tree(child));
- }
- tree
- }
- FstNode::File { name, size, .. } => {
- let label = format!("{} {}", name, format!("({size} bytes)").dimmed());
- Tree::new(label)
- }
- }
-}
-
-pub fn extract(data: Vec<u8>) {
- let dvd = image::Iso::parse(data);
- let output_path = std::path::Path::new("output");
- extract_filesystem(&dvd, &dvd.filesystem, output_path);
- extract_apploader(&dvd, output_path);
- extract_main_dol(&dvd, output_path);
- println!("Extracted ISO contents to {}", output_path.display());
-}
-
-fn extract_filesystem(dvd: &Iso, node: &FstNode, path: &std::path::Path) {
- match node {
- FstNode::Directory { name, children } => {
- let dir_path = path.join(name);
- std::fs::create_dir_all(&dir_path).unwrap();
- for child in children {
- extract_filesystem(dvd, child, &dir_path);
- }
- }
- FstNode::File { name, offset, size } => {
- let file_path = path.join(name);
- let data = &dvd.data()[*offset as usize..(*offset + *size) as usize];
- std::fs::write(file_path, data).unwrap();
- println!("Extracted file: {}", name);
- }
- }
-}
-
-fn extract_apploader(dvd: &Iso, path: &std::path::Path) {
- let apploader = &dvd.apploader;
- let data = &dvd.data()[DVD_APPLOADER_OFFSET..(DVD_APPLOADER_OFFSET + apploader.size.get() as usize)];
- std::fs::write(path.join("apploader.bin"), data).unwrap();
-}
-
-fn extract_main_dol(dvd: &Iso, path: &std::path::Path) {
- let dol_offset = dvd.header.offset_main_executable.get() as usize;
- let main_dol = image::dol::Dol::parse(dvd.data()[dol_offset..].to_vec());
- std::fs::write(path.join("main.dol"), &main_dol.data()[..main_dol.size()]).unwrap();
-}
diff --git a/crates/image/src/lib.rs b/crates/image/src/lib.rs
index a898a49..d0e8a87 100644
--- a/crates/image/src/lib.rs
+++ b/crates/image/src/lib.rs
@@ -45,14 +45,15 @@ pub fn load_dvd(data: Vec<u8>) -> Box<dyn Dvd> {
};
if data.starts_with(b"RVZ\x01") {
- Box::new(rvz::Rvz::parse(data))
+ Box::new(Rvz::parse(data))
} else {
- Box::new(iso::Iso::parse(data))
+ Box::new(Iso::parse(data))
}
}
fn extract_from_zip(data: Vec<u8>) -> Vec<u8> {
use std::io::Read;
+
let cursor = std::io::Cursor::new(data);
let mut archive = zip::ZipArchive::new(cursor).expect("failed to open ZIP archive");
let index = (0..archive.len())
@@ -62,6 +63,7 @@ fn extract_from_zip(data: Vec<u8>) -> Vec<u8> {
})
.expect("no disc image found in ZIP");
let mut entry = archive.by_index(index).unwrap();
+
let mut buf = Vec::with_capacity(entry.size() as usize);
entry.read_to_end(&mut buf).expect("failed to read ZIP entry");
buf
diff --git a/crates/gctool/Cargo.lock b/crates/multitool/Cargo.lock
similarity index 100%
rename from crates/gctool/Cargo.lock
rename to crates/multitool/Cargo.lock
diff --git a/crates/gctool/Cargo.toml b/crates/multitool/Cargo.toml
similarity index 84%
rename from crates/gctool/Cargo.toml
rename to crates/multitool/Cargo.toml
index 5250a95..0124bad 100644
--- a/crates/gctool/Cargo.toml
+++ b/crates/multitool/Cargo.toml
@@ -1,5 +1,5 @@
[package]
-name = "gctool"
+name = "multitool"
version = "0.1.0"
edition = "2024"
diff --git a/crates/gctool/src/cli.rs b/crates/multitool/src/cli.rs
similarity index 84%
rename from crates/gctool/src/cli.rs
rename to crates/multitool/src/cli.rs
index d95f728..d61ee02 100644
--- a/crates/gctool/src/cli.rs
+++ b/crates/multitool/src/cli.rs
@@ -48,18 +48,18 @@ pub enum Command {
/// Output file path (defaults to <name>.encoded.bin or <name>.decoded.bin)
output: Option<String>,
},
- /// Dump ISO file information
- Iso {
- /// Input ISO file
+ /// Dump GameCube/Wii disc image (ISO or RVZ) information
+ Dvd {
+ /// Input disc image (auto-detected: ISO, RVZ, or ZIP-wrapped)
file: String,
- /// Extract files from the ISO to an "output" directory
+ /// Extract files from the disc image to an "output" directory
#[arg(long)]
extract: bool,
},
}
#[derive(Parser)]
-#[command(about = "GameCube multi-tool", long_about = None)]
+#[command(about = "GameCube/Wii multi-tool", long_about = None)]
pub struct Args {
#[command(subcommand)]
pub command: Command,
diff --git a/crates/gctool/src/disassembly.rs b/crates/multitool/src/disassembly.rs
similarity index 100%
rename from crates/gctool/src/disassembly.rs
rename to crates/multitool/src/disassembly.rs
diff --git a/crates/gctool/src/dol.rs b/crates/multitool/src/dol.rs
similarity index 100%
rename from crates/gctool/src/dol.rs
rename to crates/multitool/src/dol.rs
diff --git a/crates/multitool/src/dvd.rs b/crates/multitool/src/dvd.rs
new file mode 100644
index 0000000..811336a
--- /dev/null
+++ b/crates/multitool/src/dvd.rs
@@ -0,0 +1,135 @@
+use image::Dvd;
+use image::dvd::{DVD_APPLOADER_OFFSET, FstNode};
+use owo_colors::OwoColorize;
+use termtree::Tree;
+
+pub fn info(data: Vec<u8>) {
+ let dvd = image::load_dvd(data);
+ let header = dvd.header();
+ let apploader = dvd.apploader();
+
+ let game_name = String::from_utf8_lossy(&header.game_name);
+ let game_name = game_name.trim_end_matches('\0');
+
+ println!(" {:<24} {}", "Game Name:".bold(), game_name);
+ println!(
+ " {:<24} {}",
+ "Game Code:".bold(),
+ String::from_utf8_lossy(&header.game_code)
+ );
+ println!(
+ " {:<24} {}",
+ "Maker Code:".bold(),
+ String::from_utf8_lossy(&header.maker_code)
+ );
+ println!(
+ " {:<24} {} / {}",
+ "Disk / Version:".bold(),
+ header.disk_id,
+ header.version
+ );
+ println!(" {:<24} {:08X}", "Magic:".bold(), u32::from_be_bytes(header.magic));
+ println!(
+ " {:<24} {}",
+ "Apploader Date:".bold(),
+ String::from_utf8_lossy(&apploader.timestamp)
+ );
+ println!(
+ " {:<24} {:08X}",
+ "Apploader Entrypoint:".bold(),
+ apploader.entrypoint.get()
+ );
+ println!(
+ " {:<24} {:08X}",
+ "Main DOL Offset:".bold(),
+ header.offset_main_executable.get()
+ );
+ println!(
+ " {:<24} {:08X} ({} bytes)",
+ "FST Offset:".bold(),
+ header.offset_filesystem.get(),
+ header.filesystem_size.get()
+ );
+
+ let filesystem = self::read_filesystem(dvd.as_ref());
+ println!();
+ println!("{}", self::build_tree(&filesystem));
+}
+
+fn read_filesystem(dvd: &dyn Dvd) -> FstNode {
+ let header = dvd.header();
+ let fst_offset = header.offset_filesystem.get() as usize;
+ let fst_size = header.filesystem_size.get() as usize;
+ let mut buf = vec![0u8; fst_size];
+ dvd.read_disc_into(fst_offset, &mut buf);
+ FstNode::parse(&buf)
+}
+
+fn build_tree(node: &FstNode) -> Tree<String> {
+ match node {
+ FstNode::Directory { name, children } => {
+ let label = if name.is_empty() {
+ "/".blue().bold().to_string()
+ } else {
+ format!("{}", name.blue().bold())
+ };
+ let mut tree = Tree::new(label);
+ for child in children {
+ tree.push(self::build_tree(child));
+ }
+ tree
+ }
+ FstNode::File { name, size, .. } => {
+ let label = format!("{} {}", name, format!("({size} bytes)").dimmed());
+ Tree::new(label)
+ }
+ }
+}
+
+pub fn extract(data: Vec<u8>) {
+ let dvd = image::load_dvd(data);
+ let output_path = std::path::Path::new("output");
+ let filesystem = self::read_filesystem(dvd.as_ref());
+ self::extract_filesystem(dvd.as_ref(), &filesystem, output_path);
+ self::extract_apploader(dvd.as_ref(), output_path);
+ self::extract_main_dol(dvd.as_ref(), output_path);
+ println!("Extracted disc contents to {}", output_path.display());
+}
+
+fn extract_filesystem(dvd: &dyn Dvd, node: &FstNode, path: &std::path::Path) {
+ match node {
+ FstNode::Directory { name, children } => {
+ let dir_path = path.join(name);
+ std::fs::create_dir_all(&dir_path).unwrap();
+ for child in children {
+ self::extract_filesystem(dvd, child, &dir_path);
+ }
+ }
+ FstNode::File { name, offset, size } => {
+ let file_path = path.join(name);
+ let mut data = vec![0u8; *size as usize];
+ dvd.read_disc_into(*offset as usize, &mut data);
+ std::fs::write(file_path, &data).unwrap();
+ println!("Extracted file: {}", name);
+ }
+ }
+}
+
+fn extract_apploader(dvd: &dyn Dvd, path: &std::path::Path) {
+ let apploader_size = dvd.apploader().size.get() as usize;
+ let mut data = vec![0u8; apploader_size];
+ dvd.read_disc_into(DVD_APPLOADER_OFFSET, &mut data);
+ std::fs::write(path.join("apploader.bin"), &data).unwrap();
+}
+
+fn extract_main_dol(dvd: &dyn Dvd, path: &std::path::Path) {
+ let dol_offset = dvd.header().offset_main_executable.get() as usize;
+
+ let mut header_bytes = vec![0u8; 0x100];
+ dvd.read_disc_into(dol_offset, &mut header_bytes);
+ let dol_size = image::dol::Dol::parse(header_bytes).size();
+
+ let mut full = vec![0u8; dol_size];
+ dvd.read_disc_into(dol_offset, &mut full);
+ std::fs::write(path.join("main.dol"), &full).unwrap();
+}
diff --git a/crates/gctool/src/ipl.rs b/crates/multitool/src/ipl.rs
similarity index 100%
rename from crates/gctool/src/ipl.rs
rename to crates/multitool/src/ipl.rs
diff --git a/crates/gctool/src/main.rs b/crates/multitool/src/main.rs
similarity index 89%
rename from crates/gctool/src/main.rs
rename to crates/multitool/src/main.rs
index ed2af9d..8d50266 100644
--- a/crates/gctool/src/main.rs
+++ b/crates/multitool/src/main.rs
@@ -1,8 +1,8 @@
mod cli;
mod disassembly;
mod dol;
+mod dvd;
mod ipl;
-mod iso;
use crate::cli::{Args, Command, DisasmArch};
use crate::disassembly::{disassemble_dsp, disassemble_ppc};
@@ -45,11 +45,11 @@ fn main() {
Command::Ipl { action, file, output } => {
ipl::process(file, output.as_deref(), *action);
}
- Command::Iso { file, extract } => {
+ Command::Dvd { file, extract } => {
if *extract {
- iso::extract(read_file_or_exit(file));
+ dvd::extract(read_file_or_exit(file));
} else {
- iso::info(read_file_or_exit(file));
+ dvd::info(read_file_or_exit(file));
}
}
}