mirror of
https://github.com/NinjaCheetah/rustii.git
synced 2026-03-17 06:47:49 -04:00
Applied a couple of Clippy lints
This commit is contained in:
@@ -8,7 +8,6 @@ use std::path::{Path, PathBuf};
|
|||||||
use anyhow::{bail, Context, Result};
|
use anyhow::{bail, Context, Result};
|
||||||
use clap::Subcommand;
|
use clap::Subcommand;
|
||||||
use regex::RegexBuilder;
|
use regex::RegexBuilder;
|
||||||
use rustwii::nand::setting;
|
|
||||||
use rustwii::nand::setting::SettingTxt;
|
use rustwii::nand::setting::SettingTxt;
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
@@ -49,7 +48,7 @@ pub fn decrypt_setting(input: &str, output: &Option<String>) -> Result<()> {
|
|||||||
} else {
|
} else {
|
||||||
PathBuf::from("setting_dec.txt")
|
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()?)?;
|
fs::write(out_path, setting.to_string()?)?;
|
||||||
|
|
||||||
println!("Successfully decrypted setting.txt!");
|
println!("Successfully decrypted setting.txt!");
|
||||||
@@ -67,7 +66,7 @@ pub fn encrypt_setting(input: &str, output: &Option<String>) -> Result<()> {
|
|||||||
} else {
|
} else {
|
||||||
PathBuf::from("setting_enc.txt")
|
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()?)?;
|
fs::write(out_path, setting.to_bytes()?)?;
|
||||||
|
|
||||||
println!("Successfully encrypted setting.txt!");
|
println!("Successfully encrypted setting.txt!");
|
||||||
|
|||||||
@@ -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);
|
println!("Generated new random Content ID \"{:08X}\" ({}) because no Content ID was specified.", cid, 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.")?;
|
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.")?;
|
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());
|
println!("Successfully added new content with Content ID \"{:08X}\" ({}) and type \"{}\" to WAD file \"{}\"!", target_cid, target_cid, target_type, out_path.display());
|
||||||
|
|||||||
@@ -203,11 +203,11 @@ impl EmuNAND {
|
|||||||
sharedcontentmap::SharedContentMap::new()
|
sharedcontentmap::SharedContentMap::new()
|
||||||
};
|
};
|
||||||
for i in 0..title.tmd().content_records().len() {
|
for i in 0..title.tmd().content_records().len() {
|
||||||
if matches!(title.tmd().content_records()[i].content_type, tmd::ContentType::Shared) {
|
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)? {
|
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()));
|
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_path, title.get_content_by_index(i)?)?;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fs::write(&content_map_path, content_map.to_bytes()?)?;
|
fs::write(&content_map_path, content_map.to_bytes()?)?;
|
||||||
|
|||||||
@@ -289,6 +289,9 @@ impl Ticket {
|
|||||||
self.signature = [0; 256];
|
self.signature = [0; 256];
|
||||||
let mut current_int: u16 = 0;
|
let mut current_int: u16 = 0;
|
||||||
let mut test_hash: [u8; 20] = [255; 20];
|
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 {
|
while test_hash[0] != 0 {
|
||||||
if current_int == 65535 { return Err(TicketError::CannotFakesign); }
|
if current_int == 65535 { return Err(TicketError::CannotFakesign); }
|
||||||
current_int += 1;
|
current_int += 1;
|
||||||
|
|||||||
@@ -351,6 +351,9 @@ impl TMD {
|
|||||||
self.signature = [0; 256];
|
self.signature = [0; 256];
|
||||||
let mut current_int: u16 = 0;
|
let mut current_int: u16 = 0;
|
||||||
let mut test_hash: [u8; 20] = [255; 20];
|
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 {
|
while test_hash[0] != 0 {
|
||||||
if current_int == 65535 { return Err(TMDError::CannotFakesign); }
|
if current_int == 65535 { return Err(TMDError::CannotFakesign); }
|
||||||
current_int += 1;
|
current_int += 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user