forked from ReFirmLabs/binwalk
-
Notifications
You must be signed in to change notification settings - Fork 1
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 ReFirmLabs#775 from ReFirmLabs/logfs
Added logfs signature
- Loading branch information
Showing
5 changed files
with
98 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use crate::signatures::common::{SignatureError, SignatureResult, CONFIDENCE_MEDIUM}; | ||
use crate::structures::logfs::{parse_logfs_super_block, LOGFS_MAGIC_OFFSET}; | ||
|
||
/// Human readable description | ||
pub const DESCRIPTION: &str = "LogFS file system"; | ||
|
||
/// LogFS magic bytes | ||
pub fn logfs_magic() -> Vec<Vec<u8>> { | ||
vec![b"\x7A\x3A\x8E\x5C\xB9\xD5\xBF\x67".to_vec()] | ||
} | ||
|
||
/// Validates the LogFS super block | ||
pub fn logfs_parser(file_data: &[u8], offset: usize) -> Result<SignatureResult, SignatureError> { | ||
// Successful return value | ||
let mut result = SignatureResult { | ||
description: DESCRIPTION.to_string(), | ||
confidence: CONFIDENCE_MEDIUM, | ||
..Default::default() | ||
}; | ||
|
||
if offset >= LOGFS_MAGIC_OFFSET { | ||
result.offset = offset - LOGFS_MAGIC_OFFSET; | ||
|
||
if let Some(logfs_sb_data) = file_data.get(result.offset..) { | ||
if let Ok(logfs_super_block) = parse_logfs_super_block(logfs_sb_data) { | ||
result.size = logfs_super_block.total_size; | ||
result.description = | ||
format!("{}, total size: {} bytes", result.description, result.size); | ||
return Ok(result); | ||
} | ||
} | ||
} | ||
|
||
Err(SignatureError) | ||
} |
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,50 @@ | ||
use crate::structures::common::{self, StructureError}; | ||
|
||
/// Offset of the LogFS magic bytes from the start of the file system | ||
pub const LOGFS_MAGIC_OFFSET: usize = 0x18; | ||
|
||
/// Struct to store LogFS info | ||
#[derive(Debug, Default, Clone)] | ||
pub struct LogFSSuperBlock { | ||
pub total_size: usize, | ||
} | ||
|
||
/// Parses a LogFS superblock | ||
pub fn parse_logfs_super_block(logfs_data: &[u8]) -> Result<LogFSSuperBlock, StructureError> { | ||
//const LOGFS_CRC_START: usize = LOGFS_MAGIC_OFFSET + 12; | ||
//const LOGFS_CRC_END: usize = 256; | ||
|
||
let logfs_sb_structure = vec![ | ||
("magic", "u64"), | ||
("crc32", "u32"), | ||
("ifile_levels", "u8"), | ||
("iblock_levels", "u8"), | ||
("data_levels", "u8"), | ||
("segment_shift", "u8"), | ||
("block_shift", "u8"), | ||
("write_shift", "u8"), | ||
("pad0", "u32"), | ||
("pad1", "u16"), | ||
("filesystem_size", "u64"), | ||
("segment_size", "u32"), | ||
("bad_seg_reserved", "u32"), | ||
("feature_incompat", "u64"), | ||
("feature_ro_compat", "u64"), | ||
("feature_compat", "u64"), | ||
("feature_flags", "u64"), | ||
("root_reserve", "u64"), | ||
("speed_reserve", "u64"), | ||
]; | ||
|
||
if let Some(sb_struct_data) = logfs_data.get(LOGFS_MAGIC_OFFSET..) { | ||
if let Ok(super_block) = common::parse(sb_struct_data, &logfs_sb_structure, "big") { | ||
if super_block["pad0"] == 0 && super_block["pad1"] == 0 { | ||
return Ok(LogFSSuperBlock { | ||
total_size: super_block["filesystem_size"], | ||
}); | ||
} | ||
} | ||
} | ||
|
||
Err(StructureError) | ||
} |