Minor cleanup, commented-out beginnings of elf support

This commit is contained in:
Keenan Tims 2023-11-06 00:35:21 -08:00
parent b07c8cd8c8
commit 2de6345f96
Signed by: ktims
GPG Key ID: 11230674D69038D4

View File

@ -1,14 +1,10 @@
extern crate object;
use std::fs::File;
use std::io::prelude::*;
use std::iter::repeat;
use std::path::Path;
use std::path::PathBuf;
use clap::ValueEnum;
use log::debug;
use log::warn;
use log::{debug, warn};
use object::elf;
use object::Endianness;
@ -34,7 +30,9 @@ struct ElfWriter;
struct IhexWriter;
struct BinWriter;
struct ElfReader;
struct ElfReader {
file_contents: Vec<u8>,
}
struct IhexReader {
file_contents: String,
}
@ -350,3 +348,52 @@ impl ObjectFileReader for IhexReader {
})
}
}
//TODO: This is getting a bit hairy to figure out which sections to include, so forget about it for now.
// impl ObjectFileReader for ElfReader {
// fn new(file: &PathBuf) -> Result<Box<dyn ObjectFileReader>, std::io::Error>
// where
// Self: Sized,
// {
// let file_contents = std::fs::read(file)?;
// Ok(Box::new(ElfReader { file_contents }))
// }
// fn read_all(&mut self, size: Option<u32>) -> Result<MemorySection, Box<dyn std::error::Error>> {
// let object = object::File::parse(&*self.file_contents).unwrap();
// let data = Vec::new();
// let file_base = None;
// debug!(
// "Opened object file, found sections: {:?}",
// object
// .sections()
// .map(|x| x.name().unwrap().to_owned())
// .collect::<Vec<String>>()
// );
// for sec in object.sections() {
// if let SectionFlags::Elf{ sh_flags: flags } = sec.flags() {
// if flags & elf::SHT_PROGBITS {
// if file_base.is_none() {
// file_base = Some(sec.address());
// } else if sec.address() < file_base.unwrap() {
// // Make space at the beginning of data
// data.
// file_base = Some(sec.address());
// }
// }
// }
// }
// Ok(MemorySection {
// data: section
// .data_range(section.address(), size)?
// .ok_or("section is empty or smaller than given size")?
// .to_vec(),
// address: section.address() as u32,
// })
// }
// }