Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

iso parser

Layle58b4d32a1b95
diff --git a/Cargo.lock b/Cargo.lock
index c956f59..4a26499 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -484,7 +484,7 @@ version = "3.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "faf9468729b8cbcea668e36183cb69d317348c2e08e994829fb56ebfdfbaac34"
dependencies = [
- "windows-sys 0.52.0",
+ "windows-sys 0.61.2",
]
[[package]]
@@ -839,7 +839,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
dependencies = [
"libc",
- "windows-sys 0.52.0",
+ "windows-sys 0.61.2",
]
[[package]]
@@ -1000,6 +1000,8 @@ dependencies = [
"comfy-table",
"disasm",
"image 0.1.0",
+ "owo-colors",
+ "termtree",
]
[[package]]
@@ -1257,6 +1259,7 @@ name = "image"
version = "0.1.0"
dependencies = [
"object",
+ "zerocopy",
]
[[package]]
@@ -1629,7 +1632,7 @@ version = "0.50.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
dependencies = [
- "windows-sys 0.59.0",
+ "windows-sys 0.61.2",
]
[[package]]
@@ -1992,6 +1995,12 @@ dependencies = [
"ttf-parser",
]
+[[package]]
+name = "owo-colors"
+version = "4.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d211803b9b6b570f68772237e415a029d5a50c65d382910b879fb19d3271f94d"
+
[[package]]
name = "parking_lot"
version = "0.12.5"
@@ -2317,7 +2326,7 @@ dependencies = [
"errno",
"libc",
"linux-raw-sys 0.12.1",
- "windows-sys 0.52.0",
+ "windows-sys 0.61.2",
]
[[package]]
@@ -2606,6 +2615,12 @@ dependencies = [
"winapi-util",
]
+[[package]]
+name = "termtree"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d4d1330fe7f7f872cd05165130b10602d667b205fd85be09be2814b115d4ced9"
+
[[package]]
name = "thiserror"
version = "1.0.69"
@@ -3348,7 +3363,7 @@ version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
dependencies = [
- "windows-sys 0.52.0",
+ "windows-sys 0.61.2",
]
[[package]]
@@ -3785,18 +3800,18 @@ dependencies = [
[[package]]
name = "zerocopy"
-version = "0.8.42"
+version = "0.8.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f2578b716f8a7a858b7f02d5bd870c14bf4ddbbcf3a4c05414ba6503640505e3"
+checksum = "efbb2a062be311f2ba113ce66f697a4dc589f85e78a4aea276200804cea0ed87"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
-version = "0.8.42"
+version = "0.8.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7e6cc098ea4d3bd6246687de65af3f920c430e236bee1e3bf2e441463f08a02f"
+checksum = "0e8bc7269b54418e7aeeef514aa68f8690b8c0489a06b0136e5f57c4c5ccab89"
dependencies = [
"proc-macro2",
"quote",
diff --git a/crates/backend-wgpu/Cargo.toml b/crates/backend-wgpu/Cargo.toml
index d19ddf2..826f0bd 100644
--- a/crates/backend-wgpu/Cargo.toml
+++ b/crates/backend-wgpu/Cargo.toml
@@ -5,5 +5,5 @@ edition = "2024"
[dependencies]
wgpu = "28.0.0"
-bytemuck = { version = "1", features = ["derive"] }
+bytemuck = { version = "1.25.0", features = ["derive"] }
gekko = { path = "../gekko" }
diff --git a/crates/gctool/Cargo.toml b/crates/gctool/Cargo.toml
index f3cad16..5250a95 100644
--- a/crates/gctool/Cargo.toml
+++ b/crates/gctool/Cargo.toml
@@ -7,4 +7,6 @@ edition = "2024"
clap = { version = "4.6.0", features = ["derive"] }
disasm = { path = "../disasm" }
image = { path = "../image" }
-comfy-table = "7.2.2"
\ No newline at end of file
+comfy-table = "7.2.2"
+termtree = "1.0.0"
+owo-colors = "4.3.0"
\ No newline at end of file
diff --git a/crates/gctool/src/cli.rs b/crates/gctool/src/cli.rs
index ede06f7..dc20db8 100644
--- a/crates/gctool/src/cli.rs
+++ b/crates/gctool/src/cli.rs
@@ -48,6 +48,11 @@ 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
+ file: String,
+ },
}
#[derive(Parser)]
diff --git a/crates/gctool/src/ipl.rs b/crates/gctool/src/ipl.rs
index c37305c..bbc5db2 100644
--- a/crates/gctool/src/ipl.rs
+++ b/crates/gctool/src/ipl.rs
@@ -70,7 +70,7 @@ fn is_encoded(data: &[u8]) -> bool {
w != 0x3C800011
}
-pub fn process_ipl(file: &str, output: Option<&str>, action: IplAction) {
+pub fn process(file: &str, output: Option<&str>, action: IplAction) {
let mut data = fs::read(file).unwrap_or_else(|e| {
eprintln!("failed to read {}: {}", file, e);
process::exit(1);
diff --git a/crates/gctool/src/iso.rs b/crates/gctool/src/iso.rs
new file mode 100644
index 0000000..27bc15b
--- /dev/null
+++ b/crates/gctool/src/iso.rs
@@ -0,0 +1,69 @@
+use image::dvd::FstNode;
+use owo_colors::OwoColorize;
+use termtree::Tree;
+
+pub fn info(data: Vec<u8>) {
+ let dvd = image::dvd::Dvd::parse(data);
+
+ let game_name = String::from_utf8_lossy(&dvd.header.game_name);
+ let game_name = game_name.trim_end_matches('\0');
+
+ println!(" {:<16} {}", "Game Name:".bold(), game_name);
+ println!(
+ " {:<16} {}",
+ "Game Code:".bold(),
+ String::from_utf8_lossy(&dvd.header.game_code)
+ );
+ println!(
+ " {:<16} {}",
+ "Maker Code:".bold(),
+ String::from_utf8_lossy(&dvd.header.maker_code)
+ );
+ println!(
+ " {:<16} {} / {}",
+ "Disk / Version:".bold(),
+ dvd.header.disk_id,
+ dvd.header.version
+ );
+ println!(" {:<16} {:08X}", "Magic:".bold(), u32::from_be_bytes(dvd.header.magic));
+ println!(
+ " {:<16} {}",
+ "Apploader Date:".bold(),
+ String::from_utf8_lossy(&dvd.apploader.timestamp)
+ );
+ println!(
+ " {:<16} {:08X}",
+ "Main DOL Offset:".bold(),
+ dvd.header.offset_main_executable.get()
+ );
+ println!(
+ " {:<16} {: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)
+ }
+ }
+}
diff --git a/crates/gctool/src/main.rs b/crates/gctool/src/main.rs
index 6c5db7c..af44e7c 100644
--- a/crates/gctool/src/main.rs
+++ b/crates/gctool/src/main.rs
@@ -2,11 +2,10 @@ mod cli;
mod disassembly;
mod dol;
mod ipl;
+mod iso;
use crate::cli::{Args, Command, DisasmArch};
use crate::disassembly::{disassemble_dsp, disassemble_ppc};
-use crate::dol::info;
-use crate::ipl::process_ipl;
use clap::Parser;
use std::fs;
@@ -24,7 +23,7 @@ fn main() {
match &args.command {
Command::Info { file } => {
- info(read_file_or_exit(file));
+ dol::info(read_file_or_exit(file));
}
Command::Disasm { arch, offset, file } => {
let data = read_file_or_exit(file);
@@ -45,7 +44,10 @@ fn main() {
}
}
Command::Ipl { action, file, output } => {
- process_ipl(file, output.as_deref(), *action);
+ ipl::process(file, output.as_deref(), *action);
+ }
+ Command::Iso { file } => {
+ iso::info(read_file_or_exit(file));
}
}
}
diff --git a/crates/image/Cargo.toml b/crates/image/Cargo.toml
index c6a99e5..6d8043d 100644
--- a/crates/image/Cargo.toml
+++ b/crates/image/Cargo.toml
@@ -5,3 +5,4 @@ edition = "2024"
[dependencies]
object = { version = "0.36", default-features = false, features = ["elf", "read"] }
+zerocopy = { version = "0.8.47", features = ["derive"] }
diff --git a/crates/image/src/dvd.rs b/crates/image/src/dvd.rs
new file mode 100644
index 0000000..a9345d3
--- /dev/null
+++ b/crates/image/src/dvd.rs
@@ -0,0 +1,151 @@
+use zerocopy::byteorder::big_endian::U32;
+use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
+
+pub const DVD_HEADER_SIZE: usize = 0x440;
+pub const DVD_HEADER_INFO_SIZE: usize = 0x2000;
+pub const DVD_APPLOADER_SIZE: usize = 0x2000;
+
+pub const DVD_HEADER_OFFSET: usize = 0x00000000;
+pub const DVD_HEADER_INFO_OFFSET: usize = DVD_HEADER_OFFSET + DVD_HEADER_SIZE;
+pub const DVD_APPLOADER_OFFSET: usize = DVD_HEADER_INFO_OFFSET + DVD_HEADER_INFO_SIZE;
+
+#[repr(C)]
+#[derive(FromBytes, IntoBytes, Immutable, KnownLayout, Debug)]
+pub struct Header {
+ pub game_code: [u8; 4],
+ pub maker_code: [u8; 2],
+ pub disk_id: u8,
+ pub version: u8,
+ pub audio_streaming: u8,
+ pub streaming_buffer_size: u8,
+ _unused1: [u8; 0x12],
+ pub magic: [u8; 4],
+ pub game_name: [u8; 0x3E0],
+ pub offset_debug_monitor: U32,
+ pub vaddr_debug_monitor: U32,
+ _unused2: [u8; 0x18],
+ pub offset_main_executable: U32,
+ pub offset_filesystem: U32,
+ pub filesystem_size: U32,
+ pub filesystem_max_size: U32,
+ pub user_position: U32,
+ pub user_size: U32,
+ _unused3: [u8; 0x8],
+}
+
+#[repr(C)]
+#[derive(FromBytes, IntoBytes, Immutable, KnownLayout, Debug)]
+pub struct HeaderInfo {
+ pub debug_monitor_size: U32,
+ pub simulated_memory_size: U32,
+ pub argument_offset: U32,
+ pub debug_flag: U32,
+ pub track_location: U32,
+ pub track_size: U32,
+ pub country_code: U32,
+ _unused0: [u8; DVD_HEADER_INFO_SIZE - 0x1C],
+}
+
+#[repr(C)]
+#[derive(FromBytes, IntoBytes, Immutable, KnownLayout, Debug)]
+pub struct Apploader {
+ pub timestamp: [u8; 10],
+ _unused0: [u8; 6],
+ pub entrypoint: U32,
+ pub size: U32,
+ pub trailer_size: U32,
+ _unused1: [u8; 4],
+ pub apploader_code: [u8; DVD_APPLOADER_SIZE - 0x20],
+}
+
+pub enum FstNode {
+ File { name: String, dvd_offset: u32, size: u32 },
+ Directory { name: String, children: Vec<FstNode> },
+}
+
+impl FstNode {
+ pub fn parse(fst: &[u8]) -> Self {
+ let total_entries = u32::from_be_bytes(fst[8..12].try_into().unwrap()) as usize;
+ let string_table = &fst[total_entries * 12..];
+
+ let mut index = 1;
+ let children = Self::parse_dir(fst, string_table, &mut index, total_entries);
+
+ Self::Directory {
+ name: String::new(),
+ children,
+ }
+ }
+
+ fn parse_dir(fst: &[u8], strings: &[u8], index: &mut usize, end: usize) -> Vec<Self> {
+ let mut entries = Vec::new();
+ while *index < end {
+ let base = *index * 12;
+ let flags = fst[base];
+ let name_off = u32::from_be_bytes([0, fst[base + 1], fst[base + 2], fst[base + 3]]) as usize;
+ let name = Self::read_cstr(strings, name_off);
+ let offset = u32::from_be_bytes(fst[base + 4..base + 8].try_into().unwrap());
+ let length = u32::from_be_bytes(fst[base + 8..base + 12].try_into().unwrap());
+ *index += 1;
+
+ if flags == 0 {
+ entries.push(Self::File {
+ name,
+ dvd_offset: offset,
+ size: length,
+ });
+ } else {
+ let next = length as usize;
+ let children = Self::parse_dir(fst, strings, index, next);
+ entries.push(Self::Directory { name, children });
+ }
+ }
+ entries
+ }
+
+ fn read_cstr(table: &[u8], offset: usize) -> String {
+ let slice = &table[offset..];
+ let len = slice.iter().position(|&b| b == 0).unwrap_or(slice.len());
+ String::from_utf8_lossy(&slice[..len]).into_owned()
+ }
+
+ pub fn name(&self) -> &str {
+ match self {
+ Self::File { name, .. } => name,
+ Self::Directory { name, .. } => name,
+ }
+ }
+
+ pub fn is_file(&self) -> bool {
+ matches!(self, Self::File { .. })
+ }
+}
+
+pub struct Dvd {
+ pub header: Header,
+ pub header_info: HeaderInfo,
+ pub apploader: Apploader,
+ pub filesystem: FstNode,
+}
+
+impl Dvd {
+ pub fn parse(data: Vec<u8>) -> Self {
+ let header = Header::read_from_bytes(&data[DVD_HEADER_OFFSET..DVD_HEADER_OFFSET + DVD_HEADER_SIZE]).unwrap();
+ let header_info =
+ HeaderInfo::read_from_bytes(&data[DVD_HEADER_INFO_OFFSET..DVD_HEADER_INFO_OFFSET + DVD_HEADER_INFO_SIZE])
+ .unwrap();
+ let apploader =
+ Apploader::read_from_bytes(&data[DVD_APPLOADER_OFFSET..DVD_APPLOADER_OFFSET + DVD_APPLOADER_SIZE]).unwrap();
+
+ let fst_start = header.offset_filesystem.get() as usize;
+ let fst_end = fst_start + header.filesystem_size.get() as usize;
+ let filesystem = FstNode::parse(&data[fst_start..fst_end]);
+
+ Dvd {
+ header,
+ header_info,
+ apploader,
+ filesystem,
+ }
+ }
+}
diff --git a/crates/image/src/lib.rs b/crates/image/src/lib.rs
index 2154e6e..cf08188 100644
--- a/crates/image/src/lib.rs
+++ b/crates/image/src/lib.rs
@@ -1,3 +1,4 @@
+pub mod dvd;
pub mod elf;
pub mod symbols;