mirror of
https://github.com/NinjaCheetah/rustii.git
synced 2026-03-03 11:25:29 -05:00
Correct lots of weak warnings, fix CI
This commit is contained in:
@@ -45,7 +45,7 @@ fn ash_bit_reader_feed_word(reader: &mut ASHBitReader) -> Result<(), ASHError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn ash_bit_reader_init(src: &[u8], size: u32, startpos: u32) -> Result<ASHBitReader, ASHError> {
|
||||
fn ash_bit_reader_init(src: &'_ [u8], size: u32, startpos: u32) -> Result<ASHBitReader<'_>, ASHError> {
|
||||
// Load data into a bit reader, then have it read its first word.
|
||||
let mut reader = ASHBitReader {
|
||||
src,
|
||||
|
||||
@@ -20,8 +20,8 @@ fn print_tid(title_id: [u8; 8]) -> Result<()> {
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if ascii_tid.is_some() {
|
||||
println!(" Title ID: {} ({})", hex::encode(title_id).to_uppercase(), ascii_tid.unwrap());
|
||||
if let Some(ascii_tid) = ascii_tid {
|
||||
println!(" Title ID: {} ({})", hex::encode(title_id).to_uppercase(), ascii_tid);
|
||||
} else {
|
||||
println!(" Title ID: {}", hex::encode(title_id).to_uppercase());
|
||||
}
|
||||
@@ -74,7 +74,7 @@ fn print_tmd_info(tmd: tmd::TMD, cert: Option<cert::Certificate>) -> Result<()>
|
||||
println!(" Certificate Info: {} (Unknown)", signature_issuer);
|
||||
}
|
||||
let region = if hex::encode(tmd.title_id()).eq("0000000100000002") {
|
||||
match versions::dec_to_standard(tmd.title_version(), &hex::encode(tmd.title_id()), Some(tmd.is_vwii() != false))
|
||||
match versions::dec_to_standard(tmd.title_version(), &hex::encode(tmd.title_id()), Some(tmd.is_vwii()))
|
||||
.unwrap_or_default().chars().last() {
|
||||
Some('U') => "USA",
|
||||
Some('E') => "EUR",
|
||||
@@ -89,11 +89,11 @@ fn print_tmd_info(tmd: tmd::TMD, cert: Option<cert::Certificate>) -> Result<()>
|
||||
};
|
||||
println!(" Region: {}", region);
|
||||
println!(" Title Type: {}", tmd.title_type()?);
|
||||
println!(" vWii Title: {}", tmd.is_vwii() != false);
|
||||
println!(" vWii Title: {}", tmd.is_vwii());
|
||||
println!(" DVD Video Access: {}", tmd.check_access_right(tmd::AccessRight::DVDVideo));
|
||||
println!(" AHB Access: {}", tmd.check_access_right(tmd::AccessRight::AHB));
|
||||
if cert.is_some() {
|
||||
let signing_str = match cert::verify_tmd(&cert.unwrap(), &tmd) {
|
||||
if let Some(cert) = cert {
|
||||
let signing_str = match cert::verify_tmd(&cert, &tmd) {
|
||||
Ok(result) => match result {
|
||||
true => "Valid (Unmodified TMD)",
|
||||
false => {
|
||||
@@ -161,8 +161,8 @@ fn print_ticket_info(ticket: ticket::Ticket, cert: Option<cert::Certificate>) ->
|
||||
println!(" Decryption Key: {}", key);
|
||||
println!(" Title Key (Encrypted): {}", hex::encode(ticket.title_key()));
|
||||
println!(" Title Key (Decrypted): {}", hex::encode(ticket.title_key_dec()));
|
||||
if cert.is_some() {
|
||||
let signing_str = match cert::verify_ticket(&cert.unwrap(), &ticket) {
|
||||
if let Some(cert) = cert {
|
||||
let signing_str = match cert::verify_ticket(&cert, &ticket) {
|
||||
Ok(result) => match result {
|
||||
true => "Valid (Unmodified Ticket)",
|
||||
false => {
|
||||
|
||||
@@ -162,8 +162,8 @@ pub fn info(emunand: &str) -> Result<()> {
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if ascii_tid.is_some() {
|
||||
println!(" {} ({})", title.to_uppercase(), ascii_tid.unwrap());
|
||||
if let Some(ascii_tid) = ascii_tid {
|
||||
println!(" {} ({})", title.to_uppercase(), ascii_tid);
|
||||
} else {
|
||||
println!(" {}", title.to_uppercase());
|
||||
}
|
||||
@@ -192,8 +192,8 @@ pub fn info(emunand: &str) -> Result<()> {
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if ascii_tid.is_some() {
|
||||
println!(" {} ({})", title.to_uppercase(), ascii_tid.unwrap());
|
||||
if let Some(ascii_tid) = ascii_tid {
|
||||
println!(" {} ({})", title.to_uppercase(), ascii_tid);
|
||||
} else {
|
||||
println!(" {}", title.to_uppercase());
|
||||
}
|
||||
|
||||
@@ -214,7 +214,7 @@ pub fn download_title(tid: &str, version: &Option<u16>, output: &TitleOutputType
|
||||
bail!("The specified Title ID is invalid!");
|
||||
}
|
||||
if version.is_some() {
|
||||
println!("Downloading title {} v{}, please wait...", tid, version.clone().unwrap());
|
||||
println!("Downloading title {} v{}, please wait...", tid, version.unwrap());
|
||||
} else {
|
||||
println!("Downloading title {} vLatest, please wait...", tid);
|
||||
}
|
||||
@@ -245,9 +245,9 @@ pub fn download_title(tid: &str, version: &Option<u16>, output: &TitleOutputType
|
||||
let content_region = content::ContentRegion::from_contents(contents, tmd.content_records().clone())?;
|
||||
println!(" - Building certificate chain...");
|
||||
let cert_chain = cert::CertificateChain::from_bytes(&nus::download_cert_chain(true).with_context(|| "Certificate chain could not be built.")?)?;
|
||||
if tik.is_some() {
|
||||
if let Some(tik) = tik {
|
||||
// If we have a Ticket, then build a Title and jump to the output method.
|
||||
let title = title::Title::from_parts(cert_chain, None, tik.unwrap(), tmd, content_region, None)?;
|
||||
let title = title::Title::from_parts(cert_chain, None, tik, tmd, content_region, None)?;
|
||||
if output.wad.is_some() {
|
||||
download_title_wad(title, output.wad.clone().unwrap())?;
|
||||
} else {
|
||||
|
||||
@@ -327,8 +327,8 @@ pub fn edit_wad(input: &str, output: &Option<String>, edits: &WadModifications)
|
||||
let new_tid: Vec<u8> = tid_high.iter().chain(&tid_low).copied().collect();
|
||||
title.set_title_id(new_tid.try_into().unwrap())?;
|
||||
}
|
||||
if edits.ios.is_some() {
|
||||
let new_ios = edits.ios.unwrap();
|
||||
if let Some(ios) = edits.ios {
|
||||
let new_ios = ios;
|
||||
if new_ios < 3 {
|
||||
bail!("The specified IOS version is not valid! The new IOS version must be between 3 and 255.")
|
||||
}
|
||||
@@ -428,12 +428,12 @@ pub fn remove_wad(input: &str, output: &Option<String>, identifier: &ContentIden
|
||||
let mut title = title::Title::from_bytes(&fs::read(in_path)?).with_context(|| "The provided WAD file could not be parsed, and is likely invalid.")?;
|
||||
// Parse the identifier passed to choose how to find and remove the target.
|
||||
// ...maybe don't take the above comment out of context
|
||||
if identifier.index.is_some() {
|
||||
title.content.remove_content(identifier.index.unwrap()).with_context(|| "The specified index does not exist in the provided WAD!")?;
|
||||
if let Some(index) = identifier.index {
|
||||
title.content.remove_content(index).with_context(|| "The specified index does not exist in the provided WAD!")?;
|
||||
println!("{:?}", title.tmd);
|
||||
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 removed content at index {} in WAD file \"{}\".", identifier.index.unwrap(), out_path.display());
|
||||
println!("Successfully removed content at index {} in WAD file \"{}\".", index, out_path.display());
|
||||
} else if identifier.cid.is_some() {
|
||||
let cid = u32::from_str_radix(identifier.cid.clone().unwrap().as_str(), 16).with_context(|| "The specified Content ID is invalid!")?;
|
||||
let index = match title.content.get_index_from_cid(cid) {
|
||||
@@ -476,8 +476,8 @@ pub fn set_wad(input: &str, content: &str, output: &Option<String>, identifier:
|
||||
};
|
||||
}
|
||||
// Parse the identifier passed to choose how to do the find and replace.
|
||||
if identifier.index.is_some() {
|
||||
match title.set_content(&new_content, identifier.index.unwrap(), None, target_type) {
|
||||
if let Some(index) = identifier.index {
|
||||
match title.set_content(&new_content, index, None, target_type) {
|
||||
Err(title::TitleError::Content(content::ContentError::IndexOutOfRange { index, max })) => {
|
||||
bail!("The specified index {} does not exist in this WAD! The maximum index is {}.", index, max)
|
||||
},
|
||||
|
||||
@@ -81,9 +81,9 @@ impl ContentRegion {
|
||||
return Err(ContentError::MissingContents { required: content_records.len(), found: contents.len()});
|
||||
}
|
||||
let mut content_region = Self::new(content_records)?;
|
||||
for i in 0..contents.len() {
|
||||
let target_index = content_region.content_records[i].index;
|
||||
content_region.load_enc_content(&contents[i], target_index as usize)?;
|
||||
for (index, content) in contents.iter().enumerate() {
|
||||
let target_index = content_region.content_records[index].index;
|
||||
content_region.load_enc_content(content, target_index as usize)?;
|
||||
}
|
||||
Ok(content_region)
|
||||
}
|
||||
@@ -213,15 +213,15 @@ impl ContentRegion {
|
||||
}
|
||||
self.content_records[index].content_size = content_size;
|
||||
self.content_records[index].content_hash = content_hash;
|
||||
if cid.is_some() {
|
||||
if let Some(cid) = cid {
|
||||
// Make sure that the new CID isn't already in use.
|
||||
if self.content_records.iter().any(|record| record.content_id == cid.unwrap()) {
|
||||
return Err(ContentError::CIDAlreadyExists(cid.unwrap()));
|
||||
if self.content_records.iter().any(|record| record.content_id == cid) {
|
||||
return Err(ContentError::CIDAlreadyExists(cid));
|
||||
}
|
||||
self.content_records[index].content_id = cid.unwrap();
|
||||
self.content_records[index].content_id = cid;
|
||||
}
|
||||
if content_type.is_some() {
|
||||
self.content_records[index].content_type = content_type.unwrap();
|
||||
if let Some(content_type) = content_type {
|
||||
self.content_records[index].content_type = content_type;
|
||||
}
|
||||
self.contents[index] = content.to_vec();
|
||||
Ok(())
|
||||
@@ -320,12 +320,18 @@ pub struct SharedContentMap {
|
||||
pub records: Vec<ContentMapEntry>,
|
||||
}
|
||||
|
||||
impl Default for SharedContentMap {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl SharedContentMap {
|
||||
/// Creates a new SharedContentMap instance from the binary data of a content.map file.
|
||||
pub fn from_bytes(data: &[u8]) -> Result<SharedContentMap, ContentError> {
|
||||
// The uid.sys file must be divisible by a multiple of 28, or something is wrong, since each
|
||||
// entry is 28 bytes long.
|
||||
if (data.len() % 28) != 0 {
|
||||
if !data.len().is_multiple_of(28) {
|
||||
return Err(ContentError::InvalidSharedContentMapLength);
|
||||
}
|
||||
let record_count = data.len() / 28;
|
||||
|
||||
@@ -190,8 +190,8 @@ impl Title {
|
||||
/// Sets a new Title ID for the Title. This will re-encrypt the Title Key in the Ticket, since
|
||||
/// the Title ID is used as the IV for decrypting the Title Key.
|
||||
pub fn set_title_id(&mut self, title_id: [u8; 8]) -> Result<(), TitleError> {
|
||||
self.tmd.set_title_id(title_id)?;
|
||||
self.ticket.set_title_id(title_id)?;
|
||||
self.tmd.set_title_id(title_id);
|
||||
self.ticket.set_title_id(title_id);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -126,8 +126,8 @@ pub fn download_tmd(title_id: [u8; 8], title_version: Option<u16>, wiiu_endpoint
|
||||
} else {
|
||||
WII_NUS_ENDPOINT.to_owned()
|
||||
};
|
||||
let tmd_url = if title_version.is_some() {
|
||||
format!("{}{}/tmd.{}", endpoint_url, &hex::encode(title_id), title_version.unwrap())
|
||||
let tmd_url = if let Some(title_version) = title_version {
|
||||
format!("{}{}/tmd.{}", endpoint_url, &hex::encode(title_id), title_version)
|
||||
} else {
|
||||
format!("{}{}/tmd", endpoint_url, &hex::encode(title_id))
|
||||
};
|
||||
|
||||
@@ -320,10 +320,9 @@ impl Ticket {
|
||||
|
||||
/// Sets a new Title ID for the Ticket. This will re-encrypt the Title Key, since the Title ID
|
||||
/// is used as the IV for decrypting the Title Key.
|
||||
pub fn set_title_id(&mut self, title_id: [u8; 8]) -> Result<(), TicketError> {
|
||||
pub fn set_title_id(&mut self, title_id: [u8; 8]) {
|
||||
let new_enc_title_key = crypto::encrypt_title_key(self.title_key_dec(), self.common_key_index, title_id, self.is_dev());
|
||||
self.title_key = new_enc_title_key;
|
||||
self.title_id = title_id;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,8 +322,8 @@ impl TMD {
|
||||
}
|
||||
|
||||
/// Sets the content records in the TMD.
|
||||
pub fn set_content_records(&mut self, content_records: &Vec<ContentRecord>) {
|
||||
self.content_records = content_records.clone()
|
||||
pub fn set_content_records(&mut self, content_records: &[ContentRecord]) {
|
||||
self.content_records = content_records.to_vec();
|
||||
}
|
||||
|
||||
/// Gets whether a TMD is fakesigned using the strncmp (trucha) bug or not.
|
||||
@@ -449,9 +449,8 @@ impl TMD {
|
||||
}
|
||||
|
||||
/// Sets a new Title ID for a TMD.
|
||||
pub fn set_title_id(&mut self, title_id: [u8; 8]) -> Result<(), TMDError> {
|
||||
pub fn set_title_id(&mut self, title_id: [u8; 8]) {
|
||||
self.title_id = title_id;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Gets the Title ID of the IOS required by a TMD.
|
||||
|
||||
Reference in New Issue
Block a user