diff --git a/src/Tools/psxreadmap/readmap/src/lib.rs b/src/Tools/psxreadmap/readmap/src/lib.rs index 4bf8b38e..1a1d9586 100644 --- a/src/Tools/psxreadmap/readmap/src/lib.rs +++ b/src/Tools/psxreadmap/readmap/src/lib.rs @@ -67,36 +67,43 @@ fn scan_symbols Option>(next_line: &mut F, memory_map: &mu } while let Some(line) = next_line() { + fn read_symbol(line: String) -> Result, Error> { + let split_count = line.split_whitespace().count(); + let mut split_line = line.split_whitespace(); + let adr = split_line_radix(&mut split_line, 16, "Address of Symbol")?; + let _type = split_line.next().ok_or(Error::from_str("Failed obtaining type of symbol"))?; + if split_count > 5 { + let _flag = split_line.next().ok_or(Error::from_str("Failed obtaining flag of symbol"))?; + } + let section = split_line.next().ok_or(Error::from_str("Failed obtaining section of symbol"))?; + let size = split_line_radix(&mut split_line, 16, "Size of Symbol")? as usize; + let name = split_line.next().ok_or(Error::from_str("Failed obtaining name of symbol"))?; + + if skip_symbol(name, section) { + // Not of interest + Ok(None) + } + + else { + Ok(Some((Symbol::new(name.to_string(), adr, size), section.to_owned()))) + } + } + if line.chars().all(char::is_whitespace) { return Ok(line); } - let split_count = line.split_whitespace().count(); - let mut split_line = line.split_whitespace(); - let adr = split_line_radix(&mut split_line, 16, "Address of Symbol")?; - let _type = split_line.next().ok_or(Error::from_str("Failed obtaining type of symbol"))?; - if split_count > 5 { - let _flag = split_line.next().ok_or(Error::from_str("Failed obtaining flag of symbol"))?; - } - let section = split_line.next().ok_or(Error::from_str("Failed obtaining section of symbol"))?; - let size = split_line_radix(&mut split_line, 16, "Size of Symbol")? as usize; - let name = split_line.next().ok_or(Error::from_str("Failed obtaining name of symbol"))?; - - if skip_symbol(name, section) { - // Not of interest - continue; - } - - let symbol = Symbol::new(name.to_string(), adr, size); - if let Some(section) = find_section(section, memory_map) { - if section.contains_adr(adr) { - section.symbols.push(symbol); - // Do not add to global cause they have a section - continue; + if let Ok(Some((symbol, section))) = read_symbol(line) { + if let Some(section) = find_section(section.as_str(), memory_map) { + if section.contains_adr(symbol.adr) { + section.symbols.push(symbol); + // Do not add to global cause they have a section + continue; + } } - } - memory_map.global.push(symbol); + memory_map.global.push(symbol); + } } Err(Error::from_str("Failed obtaining all Symbols")) @@ -124,8 +131,9 @@ fn scan_sections Option>(next_line: &mut F, sections: &mut } fn split_line_radix<'a>(split_line: &mut std::str::SplitWhitespace<'a>, radix: u32, value_name: &str) -> Result { - match u64::from_str_radix(split_line.next().ok_or(Error::from_text(format!("Failed reading: {}", value_name)))?, radix) { + let text = split_line.next().ok_or(Error::from_text(format!("Failed reading: {}", value_name)))?; + match u64::from_str_radix(text, radix) { Ok(value) => Ok(value), - Err(error) => Err(Error::from_text(format!("Converting value for {} failed with: {}", value_name, error))) + Err(error) => Err(Error::from_text(format!("Converting value ({}) for {} failed with: {}", text, value_name, error))) } } \ No newline at end of file diff --git a/src/Tools/psxreadmap/src/lib.rs b/src/Tools/psxreadmap/src/lib.rs index cc89f836..9e4f11b2 100644 --- a/src/Tools/psxreadmap/src/lib.rs +++ b/src/Tools/psxreadmap/src/lib.rs @@ -10,6 +10,8 @@ use ratatui::{ widgets::{Block, Borders, BorderType, Gauge, List, ListItem, ListState, Paragraph, Tabs, block::Title} }; +pub use readmap_helper::get_tool_output; + pub type EventReceiver = std::sync::mpsc::Receiver>; pub type Terminal = ratatui::Terminal>; type ConsoleFrame<'a> = ratatui::Frame<'a, ratatui::backend::CrosstermBackend>; diff --git a/src/Tools/psxreadmap/src/main.rs b/src/Tools/psxreadmap/src/main.rs index 83fa81df..a3a60ef1 100644 --- a/src/Tools/psxreadmap/src/main.rs +++ b/src/Tools/psxreadmap/src/main.rs @@ -2,7 +2,7 @@ use clap::Parser; use crossterm::{event::{self, Event as CEvent, KeyboardEnhancementFlags, KeyEventKind, PushKeyboardEnhancementFlags}, execute, terminal}; use psxreadmap::{ConsoleUI, Event, EventReceiver, Terminal, load_memory_map, UIState}; use std::{io::{self, Stdout}, path::PathBuf, sync::mpsc, thread, time::{Duration, Instant}}; -use tool_helper::{Error, exit_with_error}; +use tool_helper::{Error, exit_with_error, open_output}; use ratatui::backend::CrosstermBackend; pub const RUN_DUMP_TOOL_IN_WSL:bool = cfg!(windows); @@ -14,6 +14,8 @@ struct CommandLine { input: PathBuf, #[clap(long="wsl", help="Run \"objdump\" in WSL", default_value_t=RUN_DUMP_TOOL_IN_WSL)] use_wsl: bool, + #[clap(long="raw", default_value_t=false)] + raw_dump: bool, #[clap(short='o', help="Output a memory map file with running the tool")] output: Option } @@ -33,6 +35,11 @@ pub fn main() { } fn run_main(cmd: CommandLine) -> Result<(), Error> { + if cmd.raw_dump { + psxreadmap::get_tool_output(cmd.use_wsl, cmd.input, open_output(cmd.output)?)?; + return Ok(()); + } + let memory_map = load_memory_map(cmd.use_wsl, cmd.input)?; dump_memory_map(cmd.output, &memory_map)?; let rx = start_event_loop(); let terminal = setup_console()?; diff --git a/src/Tools/psxreadmap/src/readmap_helper/mod.rs b/src/Tools/psxreadmap/src/readmap_helper/mod.rs index a202febc..1318929c 100644 --- a/src/Tools/psxreadmap/src/readmap_helper/mod.rs +++ b/src/Tools/psxreadmap/src/readmap_helper/mod.rs @@ -1,4 +1,4 @@ -use tool_helper::Error; +use tool_helper::{Error, Output}; use readmap::types::MemoryMap; use std::{io::{BufRead, BufReader}, path::PathBuf, process::{Child, Command, Stdio}}; @@ -17,6 +17,22 @@ pub fn generate_memory_map(use_wsl: bool, input: PathBuf) -> Result Result { + let mut child = run_objdump(use_wsl, input)?; + if let Some(stdout) = &mut child.stdout { + let line_iter = BufReader::new(stdout).lines().map(|l| l.unwrap()).into_iter(); + + for line in line_iter { + writeln!(output, "{}", line)?; + } + Ok(output) + } + + else { + Err(Error::from_str("Failed opening \"stdout\" for objdump")) + } +} + fn run_objdump(use_wsl: bool, input: PathBuf) -> Result { let command_list = ["wsl", "objdump", "-x"]; let start_idx = {