Integrate all the progress into master #6
|
@ -1,10 +1,5 @@
|
|||
use std::default::Default;
|
||||
|
||||
pub struct MemoryMapInfo {
|
||||
pub sections: Vec<Section>,
|
||||
pub highest_address: u64,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct MemoryMap {
|
||||
pub global: Vec<Symbol>,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
mod readmap_helper;
|
||||
use crossterm::event::KeyCode;
|
||||
use readmap::types::MemoryMapInfo;
|
||||
use readmap::types::MemoryMap;
|
||||
use std::path::PathBuf;
|
||||
use tool_helper::Error;
|
||||
use tui::{
|
||||
|
@ -223,20 +224,20 @@ pub struct ConsoleUIData {
|
|||
impl ConsoleUIData {
|
||||
pub const HIGHEST_RAM_ADDRESS:u64 = 0x80000000 + (2*1024*1024);
|
||||
|
||||
pub fn new(memory_map: &MemoryMapInfo) -> Result<ConsoleUIData, Error> {
|
||||
pub fn new(memory_map: &MemoryMap) -> Result<ConsoleUIData, Error> {
|
||||
let mut ui_data = ConsoleUIData::default();
|
||||
|
||||
ui_data.update(memory_map)?;
|
||||
Ok(ui_data)
|
||||
}
|
||||
|
||||
pub fn update(&mut self, memory_map: &MemoryMapInfo) -> Result<(), Error> {
|
||||
pub fn update(&mut self, _memory_map: &MemoryMap) -> Result<(), Error> {
|
||||
|
||||
self.highest_adr = memory_map.highest_address;
|
||||
self.highest_adr = 0;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_memory_map(file_path: Option<PathBuf>) -> Result<MemoryMapInfo, Error> {
|
||||
readmap::scan(tool_helper::open_input(file_path)?)
|
||||
pub fn load_memory_map(use_wsl: bool, input: PathBuf) -> Result<MemoryMap, Error> {
|
||||
readmap_helper::generate_memory_map(use_wsl, input)
|
||||
}
|
|
@ -9,7 +9,9 @@ use tui::backend::CrosstermBackend;
|
|||
#[clap(about = "Opens and scans a MAP file to print extended information", long_about = None)]
|
||||
struct CommandLine {
|
||||
#[clap(value_parser, help="Input MAP file for scannning")]
|
||||
input: PathBuf
|
||||
input: PathBuf,
|
||||
#[clap(long="wsl", default_value_t=false)]
|
||||
use_wsl: bool
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
|
@ -27,7 +29,7 @@ pub fn main() {
|
|||
}
|
||||
|
||||
fn run_main(cmd: CommandLine) -> Result<(), Error> {
|
||||
let memory_map = load_memory_map(Some(cmd.input))?;
|
||||
let memory_map = load_memory_map(cmd.use_wsl, cmd.input)?;
|
||||
let rx = start_event_loop();
|
||||
let terminal = setup_console()?;
|
||||
let ui_data = ConsoleUIData::new(&memory_map)?;
|
||||
|
@ -89,50 +91,4 @@ fn setup_console() -> Result<Terminal, Error> {
|
|||
|
||||
terminal.clear()?;
|
||||
Ok(terminal)
|
||||
}
|
||||
|
||||
use std::{fs::File, io::{BufWriter, Write}};
|
||||
use readmap::types::{Content::*, Section};
|
||||
fn _write_main(cmd: CommandLine) -> Result<(), Error> {
|
||||
fn value_to_hex<T: std::fmt::UpperHex>(value: T) -> String {
|
||||
return format!("0x{:X}", value);
|
||||
}
|
||||
|
||||
fn option_to_hex<T: std::fmt::UpperHex>(value: Option<T>) -> String {
|
||||
if let Some(value) = value {
|
||||
return value_to_hex(value);
|
||||
}
|
||||
|
||||
else {
|
||||
return String::from("<None>");
|
||||
}
|
||||
}
|
||||
|
||||
let memory_map = load_memory_map(Some(cmd.input))?;
|
||||
let mut file = tool_helper::open_output_file(&PathBuf::from("./planschi.d"))?;
|
||||
|
||||
for section in memory_map.sections {
|
||||
fn print_content(tab_level: usize, file: &mut BufWriter<File>, section: Section) -> Result<(), Error> {
|
||||
for content in section.content {
|
||||
match content {
|
||||
Fill(fill) => {
|
||||
writeln!(file, "{:>tab_level$}*fill* @{}, {}", ' ', value_to_hex(fill.adr), value_to_hex(fill.size), tab_level=tab_level*4)?;
|
||||
},
|
||||
Section(section) => {
|
||||
writeln!(file, "{:>tab_level$} {} @{}, {}", ' ', section.name, option_to_hex(section.adr), option_to_hex(section.size), tab_level=tab_level*4)?;
|
||||
print_content(tab_level + 1, file, section)?;
|
||||
},
|
||||
Symbol(symbol) => {
|
||||
writeln!(file, "{:>tab_level$}{} @{}", ' ', symbol.name, value_to_hex(symbol.adr), tab_level=tab_level*4)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
writeln!(file, "{}: @{}, {}", section.name, option_to_hex(section.adr), option_to_hex(section.size))?;
|
||||
print_content(1, &mut file, section)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
use tool_helper::Error;
|
||||
use readmap::types::MemoryMap;
|
||||
use std::{io::{BufRead, BufReader}, path::PathBuf, process::{Child, Command, Stdio}};
|
||||
|
||||
pub fn generate_memory_map(use_wsl: bool, input: PathBuf) -> Result<MemoryMap, Error> {
|
||||
let mut child = run_objdump(use_wsl, input)?;
|
||||
if let Some(stdout) = &mut child.stdout {
|
||||
let mut line_iter = BufReader::new(stdout).lines().map(|l| l.unwrap()).into_iter();
|
||||
|
||||
readmap::scan(|| {
|
||||
line_iter.next()
|
||||
})
|
||||
}
|
||||
|
||||
else {
|
||||
Err(Error::from_str("Failed opening \"stdout\" for objdump"))
|
||||
}
|
||||
}
|
||||
|
||||
fn run_objdump(use_wsl: bool, input: PathBuf) -> Result<Child, Error> {
|
||||
let command_list = ["wsl", "objdump", "-x"];
|
||||
let start_idx = {
|
||||
if use_wsl {0}
|
||||
else {1}
|
||||
};
|
||||
let mut process = Command::new(command_list[start_idx]);
|
||||
|
||||
for arg in command_list.iter().skip(start_idx + 1) {
|
||||
process.arg(arg);
|
||||
}
|
||||
process.arg(input.to_str().ok_or_else(||{Error::from_str("Failed converting input string")})?);
|
||||
|
||||
Ok(process.stdout(Stdio::piped()).spawn()?)
|
||||
}
|
Loading…
Reference in New Issue