chore: whole swoop of enhanced documentation
This commit is contained in:
45
src/aout.rs
45
src/aout.rs
@@ -1,12 +1,12 @@
|
||||
//! Internal a.out File abstraction.
|
||||
|
||||
use core::fmt;
|
||||
use std::ffi::{c_uchar, c_ushort};
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
pub type c_long = i32; // we use a a.out with 32 byte
|
||||
|
||||
#[derive(Debug)]
|
||||
#[allow(dead_code)]
|
||||
/// Internal representation of the a.out binary format.
|
||||
pub struct Aout {
|
||||
pub header: Header,
|
||||
@@ -14,6 +14,14 @@ pub struct Aout {
|
||||
pub data: Vec<u8>,
|
||||
}
|
||||
|
||||
impl fmt::Display for Aout {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "Header: {:#?}\n", self.header).unwrap();
|
||||
write!(f, "Text: {:#?}\n", self.text).unwrap();
|
||||
write!(f, "Data: {:#?}\n", self.data)
|
||||
}
|
||||
}
|
||||
|
||||
impl Aout {
|
||||
pub fn new(buf: Vec<u8>) -> Self {
|
||||
let hdr = Header {
|
||||
@@ -48,7 +56,6 @@ impl Aout {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[allow(dead_code)]
|
||||
pub struct Header {
|
||||
pub magic: [c_uchar; 2], // magic number
|
||||
pub flags: c_uchar, // flags, see below
|
||||
@@ -63,3 +70,37 @@ pub struct Header {
|
||||
pub total: c_long, // total memory allocated
|
||||
pub syms: c_long, // size of symbol table
|
||||
}
|
||||
|
||||
impl fmt::Display for Header {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"Header:
|
||||
Magic: {:02X?}
|
||||
Flags: {:#04X}
|
||||
CPU: {}
|
||||
Header Length: {}
|
||||
Unused: {}
|
||||
Version: {:#06X}
|
||||
Text Size: {}
|
||||
Data Size: {}
|
||||
BSS Size: {}
|
||||
Entry Point: {:#X}
|
||||
Total Allocated: {}
|
||||
Symbol Table Size: {}
|
||||
",
|
||||
self.magic,
|
||||
self.flags,
|
||||
self.cpu,
|
||||
self.hdrlen,
|
||||
self.unused,
|
||||
self.version,
|
||||
self.text,
|
||||
self.data,
|
||||
self.bss,
|
||||
self.entry,
|
||||
self.total,
|
||||
self.syms
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user