From 7b4355f1eb0d2ac25fd94d59ee985bffa4da27eb Mon Sep 17 00:00:00 2001 From: devttys0 Date: Sun, 1 Dec 2024 22:30:29 -0500 Subject: [PATCH 1/2] Added endianness detection for dkbs signatures --- src/signatures/dkbs.rs | 4 ++-- src/structures/dkbs.rs | 24 ++++++++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/signatures/dkbs.rs b/src/signatures/dkbs.rs index 33ed5685e..c67ae423d 100644 --- a/src/signatures/dkbs.rs +++ b/src/signatures/dkbs.rs @@ -42,8 +42,8 @@ pub fn dkbs_parser(file_data: &[u8], offset: usize) -> Result Result && !header.board_id.is_empty() && !header.boot_device.is_empty() { - // Parse the payload size field - if let Ok(data_size) = common::parse( - &dkbs_data[DATA_SIZE_START..DATA_SIZE_END], - &data_size_field, - "big", - ) { - header.data_size = data_size["size"]; - return Ok(header); + if let Some(data_size_bytes) = dkbs_data.get(DATA_SIZE_START..DATA_SIZE_END) { + // Parse the payload size field + if let Ok(data_size) = common::parse(data_size_bytes, &data_size_field, "big") { + if data_size["size"] & 0xFF000000 == 0 { + header.data_size = data_size["size"]; + header.endianness = "big".to_string(); + } else if let Ok(data_size) = common::parse(data_size_bytes, &data_size_field, "little") { + header.data_size = data_size["size"]; + header.endianness = "little".to_string(); + } + } + + if header.data_size != 0 { + return Ok(header); + } } } } From ef2c3de8d5662ef8b672ca0280861ecfe8196758 Mon Sep 17 00:00:00 2001 From: devttys0 Date: Sun, 1 Dec 2024 22:30:57 -0500 Subject: [PATCH 2/2] Code formatting --- src/structures/dkbs.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/structures/dkbs.rs b/src/structures/dkbs.rs index b8b7afc60..3eac0d857 100644 --- a/src/structures/dkbs.rs +++ b/src/structures/dkbs.rs @@ -52,7 +52,9 @@ pub fn parse_dkbs_header(dkbs_data: &[u8]) -> Result if data_size["size"] & 0xFF000000 == 0 { header.data_size = data_size["size"]; header.endianness = "big".to_string(); - } else if let Ok(data_size) = common::parse(data_size_bytes, &data_size_field, "little") { + } else if let Ok(data_size) = + common::parse(data_size_bytes, &data_size_field, "little") + { header.data_size = data_size["size"]; header.endianness = "little".to_string(); }