Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,15 @@ fn main() {
fpt.header.checksum
);
}
match &me.fpt_area.check_ftpr_sig() {
Ok(()) => println!("FTPR signature is valid"),
Err(e) => println!("FTPR signature error: {e:}"),
match &me.fpt_area.check_ftpr_presence() {
Ok(()) => println!("FTPR exists"),
Err(e) => println!("FTPR error: {e:}"),
}
for (n, r) in me.fpt_area.check_dir_sigs() {
match r {
Ok(()) => println!(" {n}: signature is valid"),
Err(e) => println!(" {n}: signature error: {e}"),
}
}
return;
}
Expand Down
52 changes: 39 additions & 13 deletions src/me.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use crate::dir::{
gen3::{CPD_MAGIC_BYTES, CodePartitionDirectory},
};
use crate::part::fpt::FTPR;
use crate::part::gen2::DirPartition;
use crate::part::gen3::CPDPartition;
use crate::part::part::Partition;
use crate::part::{
fpt::{FPT, MIN_FPT_SIZE},
Expand Down Expand Up @@ -69,26 +71,50 @@ impl FPTArea {
}
}

pub fn check_ftpr_sig(&self) -> Result<(), String> {
pub fn check_dir_sigs(&self) -> Vec<(String, Result<(), String>)> {
match &self.partitions {
Partitions::Gen2(parts) => {
if let Some(ftpr) = parts.iter().find(|p| p.entry().name() == FTPR) {
match ftpr {
Gen2Partition::Dir(dir) => dir.check_signature(),
_ => Err("FTPR partition not recognized as directory".into()),
}
let dirs = parts
.iter()
.filter_map(|p| match p {
Gen2Partition::Dir(d) => Some(d.clone()),
_ => None,
})
.collect::<Vec<DirPartition>>();
dirs.iter()
.map(|d| (d.entry.name(), d.check_signature()))
.collect()
}
Partitions::Gen3(parts) => {
let dirs = parts
.iter()
.filter_map(|p| match p {
Gen3Partition::Dir(d) => Some(d.clone()),
_ => None,
})
.collect::<Vec<CPDPartition>>();
dirs.iter()
.map(|d| (d.entry.name(), d.check_signature()))
.collect()
}
_ => vec![],
}
}

pub fn check_ftpr_presence(&self) -> Result<(), String> {
match &self.partitions {
Partitions::Gen2(parts) => {
if parts.iter().find(|p| p.entry().name() == FTPR).is_some() {
Ok(())
} else {
Err("FTPR partition not found".into())
Err("not found".into())
}
}
Partitions::Gen3(parts) => {
if let Some(ftpr) = parts.iter().find(|p| p.entry().name() == FTPR) {
match ftpr {
Gen3Partition::Dir(dir) => dir.check_signature(),
_ => Err("FTPR partition not recognized as directory".into()),
}
if parts.iter().find(|p| p.entry().name() == FTPR).is_some() {
Ok(())
} else {
Err("FTPR partition not found".into())
Err("not found".into())
}
}
_ => Err("not recognized as ME generation 2 or 3".into()),
Expand Down