diff --git a/src/bin/rustwii/nand/setting.rs b/src/bin/rustwii/nand/setting.rs index db081db..783f809 100644 --- a/src/bin/rustwii/nand/setting.rs +++ b/src/bin/rustwii/nand/setting.rs @@ -8,7 +8,6 @@ use std::path::{Path, PathBuf}; use anyhow::{bail, Context, Result}; use clap::Subcommand; use regex::RegexBuilder; -use rustwii::nand::setting; use rustwii::nand::setting::SettingTxt; #[derive(Subcommand)] @@ -49,7 +48,7 @@ pub fn decrypt_setting(input: &str, output: &Option) -> Result<()> { } else { PathBuf::from("setting_dec.txt") }; - let setting = setting::SettingTxt::from_bytes(&fs::read(in_path)?).with_context(|| "The provided setting.txt could not be parsed, and is likely invalid.")?; + let setting = SettingTxt::from_bytes(&fs::read(in_path)?).with_context(|| "The provided setting.txt could not be parsed, and is likely invalid.")?; fs::write(out_path, setting.to_string()?)?; println!("Successfully decrypted setting.txt!"); @@ -67,7 +66,7 @@ pub fn encrypt_setting(input: &str, output: &Option) -> Result<()> { } else { PathBuf::from("setting_enc.txt") }; - let setting = setting::SettingTxt::from_string(String::from_utf8(fs::read(in_path)?).with_context(|| "Invalid characters found in input file!")?)?; + let setting = SettingTxt::from_string(String::from_utf8(fs::read(in_path)?).with_context(|| "Invalid characters found in input file!")?)?; fs::write(out_path, setting.to_bytes()?)?; println!("Successfully encrypted setting.txt!"); diff --git a/src/bin/rustwii/title/wad.rs b/src/bin/rustwii/title/wad.rs index 11b9226..6fcacdc 100644 --- a/src/bin/rustwii/title/wad.rs +++ b/src/bin/rustwii/title/wad.rs @@ -173,7 +173,7 @@ pub fn wad_add(input: &str, content: &str, output: &Option, cid: &Option println!("Generated new random Content ID \"{:08X}\" ({}) because no Content ID was specified.", cid, cid); cid }; - title.add_content(&new_content, target_cid, target_type.clone()).with_context(|| "An unknown error occurred while setting the new content.")?; + title.add_content(&new_content, target_cid, target_type).with_context(|| "An unknown error occurred while setting the new content.")?; title.fakesign().with_context(|| "An unknown error occurred while fakesigning the modified WAD.")?; fs::write(&out_path, title.to_wad()?.to_bytes()?).with_context(|| "Could not open output file for writing.")?; println!("Successfully added new content with Content ID \"{:08X}\" ({}) and type \"{}\" to WAD file \"{}\"!", target_cid, target_cid, target_type, out_path.display()); diff --git a/src/nand/emunand.rs b/src/nand/emunand.rs index 8cbc979..b625350 100644 --- a/src/nand/emunand.rs +++ b/src/nand/emunand.rs @@ -203,11 +203,11 @@ impl EmuNAND { sharedcontentmap::SharedContentMap::new() }; for i in 0..title.tmd().content_records().len() { - if matches!(title.tmd().content_records()[i].content_type, tmd::ContentType::Shared) { - if let Some(file_name) = content_map.add(&title.tmd().content_records()[i].content_hash)? { + if matches!(title.tmd().content_records()[i].content_type, tmd::ContentType::Shared) && + let Some(file_name) = content_map.add(&title.tmd().content_records()[i].content_hash)? + { let content_path = self.emunand_dirs["shared1"].join(format!("{}.app", file_name.to_ascii_lowercase())); fs::write(content_path, title.get_content_by_index(i)?)?; - } } } fs::write(&content_map_path, content_map.to_bytes()?)?; diff --git a/src/title/ticket.rs b/src/title/ticket.rs index ee6c47e..30710d4 100644 --- a/src/title/ticket.rs +++ b/src/title/ticket.rs @@ -289,6 +289,9 @@ impl Ticket { self.signature = [0; 256]; let mut current_int: u16 = 0; let mut test_hash: [u8; 20] = [255; 20]; + + // We're using the "unknown2" field as a 16-bit integer and incrementing it to brute force + // the hash that we need. while test_hash[0] != 0 { if current_int == 65535 { return Err(TicketError::CannotFakesign); } current_int += 1; diff --git a/src/title/tmd.rs b/src/title/tmd.rs index db438ad..ce6667e 100644 --- a/src/title/tmd.rs +++ b/src/title/tmd.rs @@ -351,6 +351,9 @@ impl TMD { self.signature = [0; 256]; let mut current_int: u16 = 0; let mut test_hash: [u8; 20] = [255; 20]; + + // We're using the unused "minor version" field of the TMD as a 16-bit integer and + // incrementing it to brute force the hash that we need. while test_hash[0] != 0 { if current_int == 65535 { return Err(TMDError::CannotFakesign); } current_int += 1;