diff --git a/src/bin/linkle_clap.rs b/src/bin/linkle_clap.rs index ca0f669..5e47df7 100644 --- a/src/bin/linkle_clap.rs +++ b/src/bin/linkle_clap.rs @@ -156,7 +156,7 @@ fn extract_pfs0(input_path: &str, output_directory: &str) -> Result<(), linkle:: match std::fs::create_dir(path) { Ok(()) => (), Err(ref err) if err.kind() == std::io::ErrorKind::AlreadyExists => (), - Err(err) => Err((err, path))? + Err(err) => return Err((err, path).into()) } for file in pfs0.files() { let mut file = file?; diff --git a/src/format/npdm.rs b/src/format/npdm.rs index f301a7d..2bc485f 100644 --- a/src/format/npdm.rs +++ b/src/format/npdm.rs @@ -1,13 +1,6 @@ -use byteorder::{LittleEndian, WriteBytesExt}; -use crate::format::utils; -use std; -use std::fmt; -use std::fs::File; -use std::io::Write; use std::collections::HashMap; use crate::format::utils::HexOrNum; use serde_derive::{Serialize, Deserialize}; -use serde_json; use bit_field::BitField; use std::convert::TryFrom; @@ -49,7 +42,7 @@ impl KernelCapability { lowest_cpu_id, } => { vec![*0b111u32 - .set_bits(04..10, u32::from(*lowest_thread_priority)) + .set_bits( 4..10, u32::from(*lowest_thread_priority)) .set_bits(10..16, u32::from(*highest_thread_priority)) .set_bits(16..24, u32::from(*lowest_cpu_id)) .set_bits(24..32, u32::from(*highest_cpu_id))] @@ -60,7 +53,7 @@ impl KernelCapability { for (idx, mask) in masks.iter_mut().enumerate() { mask.set_bits(29..32, idx as u32); } - for (syscall_name, syscall_val) in syscalls { + for syscall_val in syscalls.values() { masks[syscall_val.0 as usize / 24].set_bit(usize::try_from((syscall_val.0 % 24) + 5).unwrap(), true); used[syscall_val.0 as usize / 24] = true; } @@ -77,7 +70,7 @@ impl KernelCapability { is_ro, is_io, } => { - let mut val = vec![0b111111u32, 0b111111u32]; + let mut val = vec![0b11_1111u32, 0b11_1111u32]; val[0] .set_bits(7..31, u32::try_from(address.0).unwrap()) .set_bit(31, *is_ro); @@ -87,31 +80,31 @@ impl KernelCapability { val }, KernelCapability::MapPage(page) => { - vec![*0b1111111u32 + vec![*0b111_1111u32 .set_bits(8..32, u32::try_from(page.0).unwrap())] }, KernelCapability::IrqPair(irq_pair) => { - vec![*0b11111111111u32 + vec![*0b111_1111_1111u32 .set_bits(12..22, u32::from(irq_pair[0])) .set_bits(22..32, u32::from(irq_pair[1]))] }, KernelCapability::ApplicationType(app_type) => { - vec![*0b1111111111111u32 + vec![*0b1_1111_1111_1111u32 .set_bits(14..17, u32::from(*app_type))] }, KernelCapability::MinKernelVersion(min_kernel) => { - vec![*0b11111111111111u32 + vec![*0b11_1111_1111_1111u32 .set_bits(15..32, u32::try_from(min_kernel.0).unwrap())] }, KernelCapability::HandleTableSize(handle_table_size) => { - vec![*0b111111111111111u32 + vec![*0b111_1111_1111_1111u32 .set_bits(16..26, u32::from(*handle_table_size))] }, KernelCapability::DebugFlags { allow_debug, force_debug, } => { - vec![*0b1111111111111111u32 + vec![*0b1111_1111_1111_1111u32 .set_bit(17, *allow_debug) .set_bit(18, *force_debug)] }, diff --git a/src/format/nxo.rs b/src/format/nxo.rs index 323d8d1..c8eaf77 100644 --- a/src/format/nxo.rs +++ b/src/format/nxo.rs @@ -533,10 +533,10 @@ impl NxoFile { output_writer.write_u8(flags)?; } else if self.machine == EM_AARCH64 { // Compression enable, Is64Bit, IsAddrSpace32Bit, UseSystemPoolPartition - output_writer.write_u8(0b00111111)?; + output_writer.write_u8(0b0011_1111)?; } else if self.machine == EM_ARM { // Compression enable, UseSystemPoolPartition - output_writer.write_u8(0b00100111)?; + output_writer.write_u8(0b0010_0111)?; } else { unimplemented!("Unknown machine type"); } @@ -570,7 +570,7 @@ impl NxoFile { output_writer.write_u32::(0)?; // Empty Sections: - for i in 4..6 { + for _ in 4..6 { output_writer.write_u32::(0)?; output_writer.write_u32::(0)?; output_writer.write_u32::(0)?; diff --git a/src/format/pfs0.rs b/src/format/pfs0.rs index e018e44..710cae8 100644 --- a/src/format/pfs0.rs +++ b/src/format/pfs0.rs @@ -15,7 +15,7 @@ impl ReadSeek for T {} enum Pfs0Meta { HostPath(PathBuf), SubFile { - file: Box, + file: Box, name: String, size: u64 } @@ -67,7 +67,7 @@ impl Pfs0 { let string_table_offset = 0x10 + filecount as u64 * 0x18; let data_offset = string_table_offset + string_table_size as u64; - for file in 0..filecount { + for _ in 0..filecount { let offset = data_offset + f.read_u64::()?; let size = f.read_u64::()?; let filename_offset = string_table_offset + f.read_u32::()? as u64; @@ -168,7 +168,7 @@ impl Pfs0 { output_writter .seek(SeekFrom::Start(data_pos + data_offset))?; - file.seek(SeekFrom::Start(0)); + file.seek(SeekFrom::Start(0))?; let size = io::copy(file, output_writter)?; assert_eq!(size, file_size); diff --git a/src/format/romfs.rs b/src/format/romfs.rs index 4cc7d0e..c6c958d 100644 --- a/src/format/romfs.rs +++ b/src/format/romfs.rs @@ -291,9 +291,9 @@ impl RomFs { ctx.file_table_size += mem::size_of::() as u64 + align64(file.borrow().name.len() as u64, 4); } else if file_type.is_symlink() { - Err(Error::RomFsSymlink(entry.path(), Backtrace::new()))?; + return Err(Error::RomFsSymlink(entry.path(), Backtrace::new())); } else { - Err(Error::RomFsFiletype(entry.path(), Backtrace::new()))?; + return Err(Error::RomFsFiletype(entry.path(), Backtrace::new())); } } parent_dir.borrow_mut().child.sort_by_key(|v| v.borrow().name.clone()); diff --git a/src/format/utils.rs b/src/format/utils.rs index acdc791..bdb0a74 100644 --- a/src/format/utils.rs +++ b/src/format/utils.rs @@ -85,7 +85,7 @@ impl<'de> Deserialize<'de> for HexOrNum { where E: serde::de::Error { - if (v.starts_with("0x")) { + if v.starts_with("0x") { u64::from_str_radix(&v[2..], 16).map_err(|_| { E::invalid_value(Unexpected::Str(v), &"a hex-encoded string") }) diff --git a/src/pki.rs b/src/pki.rs index de5b1b2..06541b4 100644 --- a/src/pki.rs +++ b/src/pki.rs @@ -47,7 +47,7 @@ impl_debug!(Keyblob); impl_debug!(Modulus); impl Keyblob { - fn encrypt(&self, key: &Aes128Key, mac_key: &Aes128Key, keyblob_id: usize) -> Result { + fn encrypt(&self, key: &Aes128Key, mac_key: &Aes128Key, _keyblob_id: usize) -> Result { let mut encrypted_keyblob = [0; 0xB0]; encrypted_keyblob[0x20..].copy_from_slice(&self.0); @@ -349,7 +349,7 @@ impl Keys { } if !succeed { - Err(io::Error::new(ErrorKind::NotFound, "Keyfile not found."))?; + return Err(io::Error::new(ErrorKind::NotFound, "Keyfile not found.").into()); } keys.derive_keys()?; @@ -542,6 +542,7 @@ impl Keys { )) } + #[allow(clippy::cognitive_complexity)] fn read_from_ini(&mut self, mut file: File) -> Result<(), Error> { let config = ini::Ini::read_from(&mut file)?; let section = config.general_section(); @@ -586,6 +587,7 @@ impl Keys { Ok(()) } + #[allow(clippy::cognitive_complexity)] pub fn write(&self, w: &mut W) -> io::Result<()> { make_key_macros_write!(self, w); single_key!(secure_boot_key); diff --git a/src/utils.rs b/src/utils.rs index 3a62d02..6cbd9dd 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -32,12 +32,13 @@ impl ReadRange { pub fn new(stream: R, start_from: u64, max_size: u64) -> ReadRange { ReadRange { inner: stream, - start_from: start_from, + start_from, size: max_size, inner_pos: 0 } } + #[allow(unused)] pub fn pos_in_stream(&self) -> u64 { self.start_from + self.inner_pos }