This commit is contained in:
Mateusz Faderewski 2023-03-03 12:03:03 +01:00
parent b648182586
commit 24a665611e
5 changed files with 70 additions and 27 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 53 KiB

View File

@ -379,7 +379,7 @@ fn handle_info_command(sn: Option<String>) -> Result<(), sc64::Error> {
let datetime = state.datetime.format("%Y-%m-%d %H:%M:%S %Z"); let datetime = state.datetime.format("%Y-%m-%d %H:%M:%S %Z");
println!("{}", "SC64 information and current state:".bold()); println!("{}", "SC64 information and current state:".bold());
println!(" Firmware version: {}.{}", major, minor); println!(" Firmware version: v{}.{}", major, minor);
println!(" RTC datetime: {}", datetime); println!(" RTC datetime: {}", datetime);
println!(" Boot mode: {}", state.boot_mode); println!(" Boot mode: {}", state.boot_mode);
println!(" Save type: {}", state.save_type); println!(" Save type: {}", state.save_type);

View File

@ -4,29 +4,75 @@ use crc32fast::Hasher;
pub const IPL3_OFFSET: u32 = 0x40; pub const IPL3_OFFSET: u32 = 0x40;
pub const IPL3_LENGTH: usize = 0xFC0; pub const IPL3_LENGTH: usize = 0xFC0;
enum CicType {
_5101,
_6101,
_7102,
X102,
X103,
X105,
X106,
_5167,
NDXJ0,
NDDJ0,
NDDJ1,
NDDJ2,
NDDE0,
}
impl From<u32> for CicType {
fn from(value: u32) -> Self {
match value {
0x587BD543 => CicType::_5101,
0x6170A4A1 => CicType::_6101,
0x009E9EA3 => CicType::_7102,
0x90BB6CB5 => CicType::X102,
0x0B050EE0 => CicType::X103,
0x98BC2C86 => CicType::X105,
0xACC8580A => CicType::X106,
0x0E018159 => CicType::_5167,
0x10C68B18 => CicType::NDXJ0,
0xBC605D0A => CicType::NDDJ0,
0x502C4466 => CicType::NDDJ1,
0x0C965795 => CicType::NDDJ2,
0x8FEBA21E => CicType::NDDE0,
_ => CicType::X102,
}
}
}
impl From<CicType> for u8 {
fn from(value: CicType) -> Self {
match value {
CicType::_5101 => 0xAC,
CicType::_6101 => 0x3F,
CicType::_7102 => 0x3F,
CicType::X102 => 0x3F,
CicType::X103 => 0x78,
CicType::X105 => 0x91,
CicType::X106 => 0x85,
CicType::_5167 => 0xDD,
CicType::NDXJ0 => 0xDD,
CicType::NDDJ0 => 0xDD,
CicType::NDDJ1 => 0xDD,
CicType::NDDJ2 => 0xDD,
CicType::NDDE0 => 0xDE,
}
}
}
pub fn guess_ipl3_seed(ipl3: &[u8]) -> Result<u8, Error> { pub fn guess_ipl3_seed(ipl3: &[u8]) -> Result<u8, Error> {
if ipl3.len() < IPL3_LENGTH { if ipl3.len() < IPL3_LENGTH {
return Err(Error::new("Invalid IPL3 length provided")); return Err(Error::new("Invalid IPL3 length provided"));
} }
let mut hasher = Hasher::new(); let mut hasher = Hasher::new();
hasher.update(ipl3); hasher.update(ipl3);
Ok(match hasher.finalize() {
0x587BD543 => 0xAC, // 5101 let cic_type: CicType = hasher.finalize().into();
0x6170A4A1 => 0x3F, // 6101
0x009E9EA3 => 0x3F, // 7102 Ok(cic_type.into())
0x90BB6CB5 => 0x3F, // 6102/7101
0x0B050EE0 => 0x78, // x103
0x98BC2C86 => 0x91, // x105
0xACC8580A => 0x85, // x106
0x0E018159 => 0xDD, // 5167
0x10C68B18 => 0xDD, // NDXJ0
0xBC605D0A => 0xDD, // NDDJ0
0x502C4466 => 0xDD, // NDDJ1
0x0C965795 => 0xDD, // NDDJ2
0x8FEBA21E => 0xDE, // NDDE0
_ => 0x3F,
})
} }
pub fn calculate_ipl3_checksum(ipl3: &[u8], seed: u8) -> Result<[u8; 6], Error> { pub fn calculate_ipl3_checksum(ipl3: &[u8], seed: u8) -> Result<[u8; 6], Error> {
@ -43,7 +89,6 @@ pub fn calculate_ipl3_checksum(ipl3: &[u8], seed: u8) -> Result<[u8; 6], Error>
| ((ipl3[o + 2] as u32) << 8) | ((ipl3[o + 2] as u32) << 8)
| (ipl3[o + 3] as u32); | (ipl3[o + 3] as u32);
}; };
let add = |a1: u32, a2: u32| u32::wrapping_add(a1, a2); let add = |a1: u32, a2: u32| u32::wrapping_add(a1, a2);
let sub = |a1: u32, a2: u32| u32::wrapping_sub(a1, a2); let sub = |a1: u32, a2: u32| u32::wrapping_sub(a1, a2);
let mul = |a1: u32, a2: u32| u32::wrapping_mul(a1, a2); let mul = |a1: u32, a2: u32| u32::wrapping_mul(a1, a2);

View File

@ -17,8 +17,8 @@ use self::{
cic::{calculate_ipl3_checksum, guess_ipl3_seed, IPL3_LENGTH, IPL3_OFFSET}, cic::{calculate_ipl3_checksum, guess_ipl3_seed, IPL3_LENGTH, IPL3_OFFSET},
link::{Command, Link}, link::{Command, Link},
types::{ types::{
get_config, get_setting, ButtonMode, CicSeed, Config, ConfigId, FirmwareStatus, Setting, get_config, get_setting, ButtonMode, ButtonState, CicSeed, Config, ConfigId,
SettingId, UpdateStatus, Switch, ButtonState, FirmwareStatus, Setting, SettingId, Switch, UpdateStatus,
}, },
utils::{args_from_vec, datetime_from_vec, u32_from_vec, vec_from_datetime}, utils::{args_from_vec, datetime_from_vec, u32_from_vec, vec_from_datetime},
}; };
@ -94,7 +94,7 @@ const ISV_BUFFER_LENGTH: usize = 64 * 1024;
pub const MEMORY_LENGTH: usize = 0x0500_2980; pub const MEMORY_LENGTH: usize = 0x0500_2980;
const MEMORY_WRITE_CHUNK_SIZE: usize = 1 * 1024 * 1024; const MEMORY_WRITE_CHUNK_LENGTH: usize = 1 * 1024 * 1024;
impl SC64 { impl SC64 {
fn command_identifier_get(&mut self) -> Result<Vec<u8>, Error> { fn command_identifier_get(&mut self) -> Result<Vec<u8>, Error> {
@ -530,8 +530,7 @@ impl SC64 {
} }
pub fn reset_state(&mut self) -> Result<(), Error> { pub fn reset_state(&mut self) -> Result<(), Error> {
self.command_state_reset()?; self.command_state_reset()
Ok(())
} }
pub fn backup_firmware(&mut self) -> Result<Vec<u8>, Error> { pub fn backup_firmware(&mut self) -> Result<Vec<u8>, Error> {
@ -567,7 +566,7 @@ impl SC64 {
UpdateStatus::Err => { UpdateStatus::Err => {
return Err(Error::new( return Err(Error::new(
format!( format!(
"Firmware update error on step {}, device is most likely bricked", "Firmware update error on step {}, device is, most likely, bricked",
last_update_status last_update_status
) )
.as_str(), .as_str(),
@ -604,8 +603,8 @@ impl SC64 {
length: usize, length: usize,
transform: Option<fn(&mut [u8])>, transform: Option<fn(&mut [u8])>,
) -> Result<(), Error> { ) -> Result<(), Error> {
let mut data: Vec<u8> = vec![0u8; MEMORY_WRITE_CHUNK_SIZE]; let mut data: Vec<u8> = vec![0u8; MEMORY_WRITE_CHUNK_LENGTH];
for offset in (0..length).step_by(MEMORY_WRITE_CHUNK_SIZE) { for offset in (0..length).step_by(MEMORY_WRITE_CHUNK_LENGTH) {
let chunk = reader.read(&mut data)?; let chunk = reader.read(&mut data)?;
if let Some(transform) = transform { if let Some(transform) = transform {
transform(&mut data); transform(&mut data);

View File

@ -107,7 +107,6 @@ impl From<Config> for [u32; 2] {
} }
} }
#[derive(Copy, Clone)]
pub enum Switch { pub enum Switch {
Off, Off,
On, On,