some more output
This commit is contained in:
26
src/main.rs
26
src/main.rs
@@ -1,11 +1,12 @@
|
||||
use std::fs::File;
|
||||
use std::error::Error;
|
||||
use std::io::{Read, Write, ErrorKind};
|
||||
use std::collections::BTreeMap;
|
||||
use num_enum::TryFromPrimitive;
|
||||
use std::fmt::Display;
|
||||
use chrono::DateTime;
|
||||
|
||||
#[derive(TryFromPrimitive,Debug)]
|
||||
#[derive(TryFromPrimitive,Debug,PartialEq,Eq,Clone,Copy)]
|
||||
#[repr(u16)]
|
||||
enum CommandType {
|
||||
Unspec = 0,
|
||||
@@ -36,7 +37,7 @@ enum CommandType {
|
||||
EncodedWrite = 25,
|
||||
}
|
||||
|
||||
#[derive(TryFromPrimitive,Debug,Clone,Copy)]
|
||||
#[derive(TryFromPrimitive,Debug,Clone,Copy,PartialEq,Eq)]
|
||||
#[repr(u16)]
|
||||
enum TLVType {
|
||||
Unspec = 0,
|
||||
@@ -140,6 +141,8 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
let mut offset: usize = 17;
|
||||
|
||||
let mut paths: BTreeMap<String, Vec<CommandType>> = BTreeMap::new();
|
||||
|
||||
while offset < contents.len() {
|
||||
let len = u32::from_le_bytes(contents[offset .. offset + 4].try_into()?);
|
||||
let cmd = CommandType::try_from_primitive(
|
||||
@@ -149,7 +152,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
)?;
|
||||
let _checksum = u32::from_le_bytes(contents[offset + 6.. offset + 10].try_into()?);
|
||||
|
||||
out!("{cmd:?}");
|
||||
// out!("{cmd:?}");
|
||||
|
||||
let mut inner_offset: usize = 0;
|
||||
while inner_offset < len as usize {
|
||||
@@ -160,15 +163,12 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
)?;
|
||||
let tlvlen = u16::from_le_bytes(contents[offset + inner_offset + 12 .. offset + inner_offset + 14].try_into()?);
|
||||
|
||||
let tlvvalue = parse_tlv(
|
||||
tlvtype,
|
||||
&contents[offset + inner_offset + 14 .. offset + inner_offset + 14 + tlvlen as usize]
|
||||
);
|
||||
|
||||
if let Some(tlv) = tlvvalue {
|
||||
out!(" {tlvtype:?}: {tlv}");
|
||||
} else {
|
||||
out!(" {tlvtype:?}: ({tlvlen} bytes)");
|
||||
if tlvtype == TLVType::Path {
|
||||
let data = &contents[offset + inner_offset + 14 .. offset + inner_offset + 14 + tlvlen as usize];
|
||||
let path = String::from_utf8(data.to_vec())?;
|
||||
paths.entry(path)
|
||||
.or_insert(Vec::new())
|
||||
.push(cmd);
|
||||
}
|
||||
|
||||
inner_offset += tlvlen as usize + 4;
|
||||
@@ -177,5 +177,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
offset += len as usize + 10; // 10 byte header
|
||||
}
|
||||
|
||||
out!("{:#?}", paths);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user