From e478835c6e8b0c4ba584936b8668a6e6e68fd34b Mon Sep 17 00:00:00 2001 From: angie Date: Fri, 15 Dec 2023 14:15:00 -0300 Subject: [PATCH] cargo fmt --- src/rs/checksum.rs | 25 ++++++++++++++----------- src/rs/cickinds.rs | 2 +- src/rs/lib.rs | 15 ++++++++++----- src/rs/utils.rs | 4 ++-- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/rs/checksum.rs b/src/rs/checksum.rs index 7dab6bc..a7542dd 100644 --- a/src/rs/checksum.rs +++ b/src/rs/checksum.rs @@ -2,7 +2,7 @@ /* SPDX-License-Identifier: MIT */ use crate::cickinds::CICKind; -use crate::{utils, detect}; +use crate::{detect, utils}; fn read_word_from_ram(rom_words: &[u32], entrypoint_ram: u32, ram_addr: u32) -> u32 { rom_words[((ram_addr - entrypoint_ram + 0x1000) / 4) as usize] @@ -26,14 +26,14 @@ pub fn calculate_checksum(rom_bytes: &[u8], kind: &CICKind) -> Option<(u32, u32) return None; } - let rom_words = utils::read_u32_vec(rom_bytes, 0, 0x101000/4); + let rom_words = utils::read_u32_vec(rom_bytes, 0, 0x101000 / 4); let seed = kind.get_seed(); let magic = kind.get_magic(); let mut s6 = seed; - let mut a0 = rom_words[8/4]; + let mut a0 = rom_words[8 / 4]; if *kind == CICKind::CIC_X103 { a0 = a0.wrapping_sub(0x100000); } @@ -94,7 +94,6 @@ pub fn calculate_checksum(rom_bytes: &[u8], kind: &CICKind) -> Option<(u32, u32) //t7 = utils.u32(t5 - v1) let t7: u32 = t5.wrapping_sub(v1); - //let t8 = utils.u32(v0 >> t7) //let t6 = utils.u32(v0 << v1) let t8 = v0.wrapping_shr(t7); @@ -116,12 +115,11 @@ pub fn calculate_checksum(rom_bytes: &[u8], kind: &CICKind) -> Option<(u32, u32) a2 = t9 ^ a2; // goto LA4000640; - // LA400063C: + // LA400063C: } else { a2 = a2 ^ a0; } - // LA4000640: if *kind == CICKind::CIC_X105 { // ipl3 6105 copies 0x330 bytes from the ROM's offset 0x000554 (or offset 0x000514 into IPL3) to vram 0xA0000004 @@ -157,7 +155,6 @@ pub fn calculate_checksum(rom_bytes: &[u8], kind: &CICKind) -> Option<(u32, u32) t4 = t7.wrapping_add(t4); } - // if (t0 != ra) goto LA40005F0; if t0 == ra { loop_variable = false; @@ -190,7 +187,7 @@ pub fn calculate_checksum(rom_bytes: &[u8], kind: &CICKind) -> Option<(u32, u32) s0 = t8 ^ t4; } - return Some((a3, s0)) + Some((a3, s0)) } pub fn calculate_checksum_autodetect(rom_bytes: &[u8]) -> Option<(u32, u32)> { @@ -243,7 +240,7 @@ mod tests { }; println!("CIC Kind: {:?}", kind); - for bin_path_result in fs::read_dir(ipl3_folder.path() ).unwrap() { + for bin_path_result in fs::read_dir(ipl3_folder.path()).unwrap() { let bin_path = bin_path_result.unwrap(); println!("{:?}", bin_path); @@ -255,12 +252,18 @@ mod tests { println!(" Calculating checksum..."); let checksum = super::calculate_checksum(&bin_bytes, &kind).unwrap(); - println!(" Calculated checksum is: 0x{:08X} 0x{:08X}", checksum.0, checksum.1); + println!( + " Calculated checksum is: 0x{:08X} 0x{:08X}", + checksum.0, checksum.1 + ); println!(" Checking checksum..."); let bin_checksum = utils::read_u32_vec(&bin_bytes, 0x10, 2); - println!(" Expected checksum is: 0x{:08X} 0x{:08X}", bin_checksum[0], bin_checksum[1]); + println!( + " Expected checksum is: 0x{:08X} 0x{:08X}", + bin_checksum[0], bin_checksum[1] + ); assert_eq!(checksum.0, bin_checksum[0]); assert_eq!(checksum.1, bin_checksum[1]); diff --git a/src/rs/cickinds.rs b/src/rs/cickinds.rs index 3ae1a2e..07ff445 100644 --- a/src/rs/cickinds.rs +++ b/src/rs/cickinds.rs @@ -71,7 +71,7 @@ impl CICKind { 6103 | 7103 => Some(CICKind::CIC_X103), 6105 | 7105 => Some(CICKind::CIC_X105), 6106 | 7106 => Some(CICKind::CIC_X106), - _ => None + _ => None, } } } diff --git a/src/rs/lib.rs b/src/rs/lib.rs index acec691..3612687 100644 --- a/src/rs/lib.rs +++ b/src/rs/lib.rs @@ -1,8 +1,8 @@ /* SPDX-FileCopyrightText: © 2023 Decompollaborate */ /* SPDX-License-Identifier: MIT */ -pub mod cickinds; pub mod checksum; +pub mod cickinds; pub mod detect; mod utils; @@ -14,13 +14,18 @@ use pyo3::prelude::*; #[pymodule] fn ipl3checksum(_py: Python<'_>, m: &PyModule) -> PyResult<()> { m.add_class::()?; - m.add_function(wrap_pyfunction!(checksum::python_bindings::calculateChecksum, m)?)?; - m.add_function(wrap_pyfunction!(checksum::python_bindings::calculateChecksumAutodetect, m)?)?; + m.add_function(wrap_pyfunction!( + checksum::python_bindings::calculateChecksum, + m + )?)?; + m.add_function(wrap_pyfunction!( + checksum::python_bindings::calculateChecksumAutodetect, + m + )?)?; m.add_function(wrap_pyfunction!(detect::python_bindings::detectCICRaw, m)?)?; m.add_function(wrap_pyfunction!(detect::python_bindings::detectCIC, m)?)?; Ok(()) } #[cfg(test)] -mod tests { -} +mod tests {} diff --git a/src/rs/utils.rs b/src/rs/utils.rs index 48ef42d..8ef06e2 100644 --- a/src/rs/utils.rs +++ b/src/rs/utils.rs @@ -23,10 +23,10 @@ pub(crate) fn read_u32(bytes: &[u8], offset: usize) -> u32 { } pub(crate) fn read_u32_vec(bytes: &[u8], offset: usize, len: usize) -> Vec { - let mut ret = vec![0;len]; + let mut ret = vec![0; len]; for i in 0..len { - ret[i] = read_u32(bytes, offset + i*4); + ret[i] = read_u32(bytes, offset + i * 4); } ret