Applied a couple of Clippy lints

This commit is contained in:
2026-03-11 14:21:10 -04:00
parent 9472c049ee
commit 755b6583f1
5 changed files with 12 additions and 7 deletions

View File

@@ -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<String>) -> 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<String>) -> 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!");

View File

@@ -173,7 +173,7 @@ pub fn wad_add(input: &str, content: &str, output: &Option<String>, 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());

View File

@@ -203,13 +203,13 @@ 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()?)?;
// The "footer" (officially "meta") is installed to /meta/<tid_high>/<tid_low>/title.met.
// The "override meta" option installs the content at index 0 to title.met instead, as that

View File

@@ -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;

View File

@@ -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;