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