pub struct Rom<'a>(pub &'a [u8]);
Tuple Fields§
§0: &'a [u8]
Implementations§
Source§impl<'a> Rom<'a>
impl<'a> Rom<'a>
Sourcepub fn new(data: &'a [u8]) -> Self
pub fn new(data: &'a [u8]) -> Self
Examples found in repository?
examples/file.rs (line 6)
4fn inner(path: &str) -> io::Result<()> {
5 let data = fs::read(path)?;
6 let rom = Rom::new(&data);
7
8 if let Some(fmap) = rom.fmap() {
9 let mut name = String::new();
10 for &b in fmap.name.iter() {
11 if b == 0 {
12 break;
13 }
14 name.push(b as char);
15 }
16
17 eprintln!(" {}", name);
18
19 for i in 0..fmap.nareas {
20 let area = fmap.area(i);
21
22 let mut name = String::new();
23 for &b in area.name.iter() {
24 if b == 0 {
25 break;
26 }
27 name.push(b as char);
28 }
29
30 eprintln!(" {}: {}", i, name);
31 }
32 }
33
34 if let Some(header) = rom.header() {
35 eprintln!(" CBFS");
36
37 let align = u32::from(header.align) as usize;
38 let mut offset = u32::from(header.offset) as usize;
39 while let Some(file) = rom.file(offset) {
40 let name_bytes = file.name();
41
42 let mut name = String::new();
43 for &b in name_bytes.iter() {
44 if b == 0 {
45 break;
46 }
47 name.push(b as char);
48 }
49
50 eprintln!(" {:#X}: {}", offset, name);
51
52 let file_offset = u32::from(file.offset) as usize;
53 let file_len = u32::from(file.len) as usize;
54 offset = ((offset + file_offset + file_len + align - 1) / align) * align;
55 }
56 } else {
57 eprintln!("coreboot header not found");
58 }
59
60 Ok(())
61}
Sourcepub fn fmap(&self) -> Option<&Fmap>
pub fn fmap(&self) -> Option<&Fmap>
Examples found in repository?
examples/file.rs (line 8)
4fn inner(path: &str) -> io::Result<()> {
5 let data = fs::read(path)?;
6 let rom = Rom::new(&data);
7
8 if let Some(fmap) = rom.fmap() {
9 let mut name = String::new();
10 for &b in fmap.name.iter() {
11 if b == 0 {
12 break;
13 }
14 name.push(b as char);
15 }
16
17 eprintln!(" {}", name);
18
19 for i in 0..fmap.nareas {
20 let area = fmap.area(i);
21
22 let mut name = String::new();
23 for &b in area.name.iter() {
24 if b == 0 {
25 break;
26 }
27 name.push(b as char);
28 }
29
30 eprintln!(" {}: {}", i, name);
31 }
32 }
33
34 if let Some(header) = rom.header() {
35 eprintln!(" CBFS");
36
37 let align = u32::from(header.align) as usize;
38 let mut offset = u32::from(header.offset) as usize;
39 while let Some(file) = rom.file(offset) {
40 let name_bytes = file.name();
41
42 let mut name = String::new();
43 for &b in name_bytes.iter() {
44 if b == 0 {
45 break;
46 }
47 name.push(b as char);
48 }
49
50 eprintln!(" {:#X}: {}", offset, name);
51
52 let file_offset = u32::from(file.offset) as usize;
53 let file_len = u32::from(file.len) as usize;
54 offset = ((offset + file_offset + file_len + align - 1) / align) * align;
55 }
56 } else {
57 eprintln!("coreboot header not found");
58 }
59
60 Ok(())
61}
pub fn header_offset(&self) -> Option<usize>
Sourcepub fn header(&self) -> Option<&Header>
pub fn header(&self) -> Option<&Header>
Examples found in repository?
examples/file.rs (line 34)
4fn inner(path: &str) -> io::Result<()> {
5 let data = fs::read(path)?;
6 let rom = Rom::new(&data);
7
8 if let Some(fmap) = rom.fmap() {
9 let mut name = String::new();
10 for &b in fmap.name.iter() {
11 if b == 0 {
12 break;
13 }
14 name.push(b as char);
15 }
16
17 eprintln!(" {}", name);
18
19 for i in 0..fmap.nareas {
20 let area = fmap.area(i);
21
22 let mut name = String::new();
23 for &b in area.name.iter() {
24 if b == 0 {
25 break;
26 }
27 name.push(b as char);
28 }
29
30 eprintln!(" {}: {}", i, name);
31 }
32 }
33
34 if let Some(header) = rom.header() {
35 eprintln!(" CBFS");
36
37 let align = u32::from(header.align) as usize;
38 let mut offset = u32::from(header.offset) as usize;
39 while let Some(file) = rom.file(offset) {
40 let name_bytes = file.name();
41
42 let mut name = String::new();
43 for &b in name_bytes.iter() {
44 if b == 0 {
45 break;
46 }
47 name.push(b as char);
48 }
49
50 eprintln!(" {:#X}: {}", offset, name);
51
52 let file_offset = u32::from(file.offset) as usize;
53 let file_len = u32::from(file.len) as usize;
54 offset = ((offset + file_offset + file_len + align - 1) / align) * align;
55 }
56 } else {
57 eprintln!("coreboot header not found");
58 }
59
60 Ok(())
61}
Sourcepub fn file(&self, offset: usize) -> Option<&File>
pub fn file(&self, offset: usize) -> Option<&File>
Examples found in repository?
examples/file.rs (line 39)
4fn inner(path: &str) -> io::Result<()> {
5 let data = fs::read(path)?;
6 let rom = Rom::new(&data);
7
8 if let Some(fmap) = rom.fmap() {
9 let mut name = String::new();
10 for &b in fmap.name.iter() {
11 if b == 0 {
12 break;
13 }
14 name.push(b as char);
15 }
16
17 eprintln!(" {}", name);
18
19 for i in 0..fmap.nareas {
20 let area = fmap.area(i);
21
22 let mut name = String::new();
23 for &b in area.name.iter() {
24 if b == 0 {
25 break;
26 }
27 name.push(b as char);
28 }
29
30 eprintln!(" {}: {}", i, name);
31 }
32 }
33
34 if let Some(header) = rom.header() {
35 eprintln!(" CBFS");
36
37 let align = u32::from(header.align) as usize;
38 let mut offset = u32::from(header.offset) as usize;
39 while let Some(file) = rom.file(offset) {
40 let name_bytes = file.name();
41
42 let mut name = String::new();
43 for &b in name_bytes.iter() {
44 if b == 0 {
45 break;
46 }
47 name.push(b as char);
48 }
49
50 eprintln!(" {:#X}: {}", offset, name);
51
52 let file_offset = u32::from(file.offset) as usize;
53 let file_len = u32::from(file.len) as usize;
54 offset = ((offset + file_offset + file_len + align - 1) / align) * align;
55 }
56 } else {
57 eprintln!("coreboot header not found");
58 }
59
60 Ok(())
61}
Auto Trait Implementations§
impl<'a> Freeze for Rom<'a>
impl<'a> RefUnwindSafe for Rom<'a>
impl<'a> Send for Rom<'a>
impl<'a> Sync for Rom<'a>
impl<'a> Unpin for Rom<'a>
impl<'a> UnwindSafe for Rom<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more