-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #782 from ReFirmLabs/uboot_version
Added U-Boot version signature, fixed openssl signature validation
- Loading branch information
Showing
5 changed files
with
103 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use crate::common::{get_cstring, is_ascii_number}; | ||
use crate::signatures::common::{SignatureError, SignatureResult, CONFIDENCE_MEDIUM}; | ||
|
||
/// Human readable description | ||
pub const DESCRIPTION: &str = "U-Boot version string"; | ||
|
||
/// U-Boot version number magic bytes | ||
pub fn uboot_magic() -> Vec<Vec<u8>> { | ||
vec![b"U-Boot\x20".to_vec()] | ||
} | ||
|
||
/// Validates the U-Boot version number magic | ||
pub fn uboot_parser(file_data: &[u8], offset: usize) -> Result<SignatureResult, SignatureError> { | ||
const NUMBER_OFFSET: usize = 7; | ||
|
||
// Successful return value | ||
let mut result = SignatureResult { | ||
offset, | ||
description: DESCRIPTION.to_string(), | ||
confidence: CONFIDENCE_MEDIUM, | ||
..Default::default() | ||
}; | ||
|
||
if let Some(expected_number_byte) = file_data.get(offset + NUMBER_OFFSET) { | ||
if is_ascii_number(*expected_number_byte) { | ||
let uboot_version_string = get_cstring(&file_data[offset + NUMBER_OFFSET..]); | ||
|
||
if !uboot_version_string.is_empty() { | ||
result.size = uboot_version_string.len(); | ||
result.description = format!("{}: {}", result.description, uboot_version_string); | ||
return Ok(result); | ||
} | ||
} | ||
} | ||
|
||
Err(SignatureError) | ||
} |