diff options
| author | Miquel Sabaté Solà <mssola@mssola.com> | 2026-08-26 08:19:04 +0200 |
|---|---|---|
| committer | Miquel Sabaté Solà <mssola@mssola.com> | 2026-08-26 08:19:04 +0200 |
| commit | eba477358f272e99caf6d3cf99ca345f38eab037 (patch) | |
| tree | 295dfb8d4bb3200ad7c6363be95f6afb25dbdd85 /crates/readrom/src/main.rs | |
| parent | 7feba90e6bec87796a39e53bec81647c64bfd7dc (diff) | |
| download | tools.nes-eba477358f272e99caf6d3cf99ca345f38eab037.tar.gz tools.nes-eba477358f272e99caf6d3cf99ca345f38eab037.zip | |
{run,read}rom: validate the path from --nasm
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
Diffstat (limited to 'crates/readrom/src/main.rs')
| -rw-r--r-- | crates/readrom/src/main.rs | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/crates/readrom/src/main.rs b/crates/readrom/src/main.rs index 8d70e16..f461fe9 100644 --- a/crates/readrom/src/main.rs +++ b/crates/readrom/src/main.rs @@ -16,7 +16,7 @@ struct Args { all: bool, disassemble: Option<String>, mapping: Option<String>, - nasm: Option<String>, + nasm: Option<PathBuf>, raw: bool, config: Option<String>, } @@ -75,7 +75,16 @@ fn parse_arguments() -> Args { } }, "-n" | "--nasm" => match args.next() { - Some(a) => res.nasm = Some(a), + Some(a) => { + let pb = PathBuf::from(a.clone()); + if !pb.exists() { + die(format!("directory '{a}' does not exist")); + } + if !pb.is_dir() { + die(format!("path '{a}' does not point to a directory")); + } + res.nasm = Some(pb); + } None => die("you need to specify a file for the '-n/--nasm' flag".to_string()), }, "-r" | "--raw" => res.raw = true, @@ -336,7 +345,7 @@ fn parse_hex_value(address: &str) -> Option<usize> { fn do_disassemble( bytes: &[u8], address: Option<&str>, - nasm_path: &Option<String>, + nasm_path: &Option<PathBuf>, mut start: Option<usize>, mut end: Option<usize>, raw: bool, @@ -347,7 +356,7 @@ fn do_disassemble( // Fill up the 'addresses' and the 'memories' maps. if let Some(path) = nasm_path { - if let Ok(file) = File::open(PathBuf::from(path).join("addresses.txt")) { + if let Ok(file) = File::open(path.join("addresses.txt")) { let reader = BufReader::new(file); for line in reader.lines() { let line = line.map_err(|e| e.to_string())?; |
