|
| 1 | +fn main() { |
| 2 | + for f in std::env::args().skip(1) { |
| 3 | + println!("# File {}:", f); |
| 4 | + let data = std::fs::read(f).expect("unable to read image file"); |
| 5 | + let decompressed = hermit_image_reader::decompress_image(&data[..]) |
| 6 | + .expect("unable to decompress image file"); |
| 7 | + for i in hermit_image_reader::ImageParser::new(&decompressed[..]) { |
| 8 | + let i = i.expect("unable to read image entry"); |
| 9 | + print!(" Entry "); |
| 10 | + let maybe_name = i.name.try_as_str(); |
| 11 | + if let Some(name) = maybe_name { |
| 12 | + print!("{:?}", name); |
| 13 | + } else { |
| 14 | + print!("{:?}", i.name); |
| 15 | + } |
| 16 | + if i.is_exec { |
| 17 | + print!(" (executable)"); |
| 18 | + } |
| 19 | + print!(" :: {:?} :: starts with: ", i.value_range); |
| 20 | + let value_start = &i.value[..core::cmp::min(20, i.value.len())]; |
| 21 | + |
| 22 | + if let Ok(value_start) = str::from_utf8(value_start) { |
| 23 | + println!("{:?}", value_start); |
| 24 | + } else { |
| 25 | + println!("{:?}", value_start); |
| 26 | + } |
| 27 | + |
| 28 | + if let Some(name) = maybe_name { |
| 29 | + if name |
| 30 | + == hermit_image_reader::StrFilename::One( |
| 31 | + hermit_image_reader::config::DEFAULT_CONFIG_NAME, |
| 32 | + ) { |
| 33 | + match hermit_image_reader::config::parse(i.value) { |
| 34 | + Ok(config) => println!("parsed config ::\n{:#?}\n", config), |
| 35 | + Err(e) => eprintln!("failed to parse config :: {}", e), |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + } |
| 40 | + } |
| 41 | +} |
0 commit comments