Skip to content

Commit

Permalink
Merge pull request ReFirmLabs#789 from ReFirmLabs/dkbs_le
Browse files Browse the repository at this point in the history
Add support for DKBS little endian
  • Loading branch information
devttys0 authored Dec 2, 2024
2 parents 487c34d + ef2c3de commit 240478a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/signatures/dkbs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ pub fn dkbs_parser(file_data: &[u8], offset: usize) -> Result<SignatureResult, S
// Report header size and description
result.size = dkbs_header.header_size;
result.description = format!(
"{}, board ID: {}, firmware version: {}, boot device: {}, header size: {} bytes, data size: {}",
result.description, dkbs_header.board_id, dkbs_header.version, dkbs_header.boot_device, dkbs_header.header_size, dkbs_header.data_size
"{}, board ID: {}, firmware version: {}, boot device: {}, endianness: {}, header size: {} bytes, data size: {}",
result.description, dkbs_header.board_id, dkbs_header.version, dkbs_header.boot_device, dkbs_header.endianness, dkbs_header.header_size, dkbs_header.data_size
);

// Return OK
Expand Down
26 changes: 18 additions & 8 deletions src/structures/dkbs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct DKBSHeader {
pub board_id: String,
pub version: String,
pub boot_device: String,
pub endianness: String,
}

/// Parses a DKBS header
Expand Down Expand Up @@ -45,14 +46,23 @@ pub fn parse_dkbs_header(dkbs_data: &[u8]) -> Result<DKBSHeader, StructureError>
&& !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);
}
}
}
}
Expand Down

0 comments on commit 240478a

Please sign in to comment.