-
Notifications
You must be signed in to change notification settings - Fork 24
Add NTFS tooling, GUI explorer #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
96c18ab
Add NTFS tooling, GUI explorer, and LFS test fixtures
omerbenamram 125e865
fmt
omerbenamram 38bb92f
aff minimal update
omerbenamram 8d33354
AFF
omerbenamram 0397356
fmt: apply rustfmt
omerbenamram 12ecef1
Add pre-commit rustfmt hook
omerbenamram 47b2ba9
aff: fix AFD reads when subfile imagesize is smaller
omerbenamram cfaf335
aff: verify MODE1 page signatures using logical page length
omerbenamram File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,6 @@ | ||
| *.E?? filter=lfs diff=lfs merge=lfs -text | ||
| *.e?? filter=lfs diff=lfs merge=lfs -text | ||
| *.aff filter=lfs diff=lfs merge=lfs -text | ||
| *.AFF filter=lfs diff=lfs merge=lfs -text | ||
| *.dd filter=lfs diff=lfs merge=lfs -text | ||
| *.DD filter=lfs diff=lfs merge=lfs -text |
This file contains hidden or 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 hidden or 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 hidden or 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,9 @@ | ||
| repos: | ||
| - repo: local | ||
| hooks: | ||
| - id: cargo-fmt | ||
| name: cargo fmt --all --check | ||
| entry: cargo fmt --all --check | ||
| language: system | ||
| pass_filenames: false | ||
| files: '\.rs$' |
This file contains hidden or 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 hidden or 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 hidden or 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,39 @@ | ||
| [package] | ||
| name = "aff" | ||
| version = "0.1.0" | ||
| edition = "2024" | ||
| rust-version = "1.90" | ||
| license = "MIT/Apache-2.0" | ||
| description = "AFF (Advanced Forensic Format) reader with optional crypto/signature verification" | ||
| repository = "https://github.com/omerbenamram/mft" | ||
| readme = "README.md" | ||
|
|
||
| [dependencies] | ||
| forensic-image = { path = "../forensic-image" } | ||
| thiserror = "2" | ||
| log = { version = "0.4", features = ["release_max_level_debug"] } | ||
| lru = "0.16.1" | ||
| flate2 = { version = "1", default-features = false, features = ["rust_backend"] } | ||
|
|
||
| # Optional: decrypt `/aes256` segments + verify `/sha256` signatures (AFFLIB semantics). | ||
| openssl = { version = "0.10", features = ["vendored"], optional = true } | ||
|
|
||
| # Optional: LZMA page decompression (AFFLIB uses LZMA-Alone framing). | ||
| lzma-rs = { version = "0.3", optional = true } | ||
|
|
||
| # CLI tools | ||
| clap = { version = "4", features = ["derive"] } | ||
| anyhow = "1" | ||
|
|
||
| [dev-dependencies] | ||
| tempfile = "3.23" | ||
| assert_cmd = "2.1.1" | ||
| predicates = "3.1" | ||
|
|
||
| [features] | ||
| default = ["crypto", "lzma"] | ||
|
|
||
| crypto = ["dep:openssl"] | ||
| lzma = ["dep:lzma-rs"] | ||
|
|
||
|
|
This file contains hidden or 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 @@ | ||
| # `aff` — Advanced Forensic Format (AFF) reader | ||
|
|
||
| This crate provides **read-only** access to AFF containers with behavior closely aligned to | ||
| **AFFLIBv3**. | ||
|
|
||
| ## Supported containers | ||
|
|
||
| - **AFF1** single-file (`.aff`) | ||
| - **AFM** (`.afm`) metadata + split-raw payload (`.000`, `.001`, …) | ||
| - **AFD** directory container (`file_000.aff`, `file_001.aff`, …) | ||
|
|
||
| ## Quick start | ||
|
|
||
| ```rust | ||
| use aff::AffOpenOptions; | ||
| use forensic_image::ReadAt; | ||
|
|
||
| let img = AffOpenOptions::new().open("image.aff")?; | ||
| let mut buf = [0u8; 512]; | ||
| img.read_exact_at(0, &mut buf)?; | ||
| # Ok::<(), aff::Error>(()) | ||
| ``` | ||
|
|
||
| ## Features | ||
|
|
||
| - **`crypto`** (default): decrypt `/aes256` segments (read-side) + verify `/sha256` signatures (read-side) | ||
| - **`lzma`** (default): LZMA page decompression (`AF_PAGE_COMP_ALG_LZMA`) | ||
|
|
||
| ## Reference materials | ||
|
|
||
| This repo vendors reference materials under `external/refs/` (AFFLIBv3 snapshot + public specs). | ||
| These are used for **correctness** and **parity testing**; the `aff` crate itself does not link to | ||
| AFFLIB. | ||
|
|
||
|
|
This file contains hidden or 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,178 @@ | ||
| //! AFD (AFF directory) backend. | ||
| //! | ||
| //! An AFD container is a directory containing multiple `.aff` files named like: | ||
| //! - `file_000.aff` | ||
| //! - `file_001.aff` | ||
| //! - ... | ||
| //! | ||
| //! Segment lookup follows AFFLIB’s semantics: the first subfile containing a segment wins. | ||
| //! Missing pages are treated as zero-filled regions. | ||
|
|
||
| use super::aff1::Aff1Image; | ||
| use super::backend::{Backend, ContainerKind, Segment}; | ||
| use crate::{Error, Result}; | ||
| use forensic_image::ReadAt; | ||
| use std::collections::{HashMap, HashSet}; | ||
| use std::io; | ||
| use std::path::Path; | ||
| use std::sync::Arc; | ||
|
|
||
| #[derive(Debug)] | ||
| pub(crate) struct AfdImage { | ||
| files: Vec<Arc<Aff1Image>>, | ||
| page_size: usize, | ||
| image_size: u64, | ||
| page_map: HashMap<u64, usize>, // page_index -> file index | ||
| } | ||
|
|
||
| impl AfdImage { | ||
| pub(crate) fn open_with(path: impl AsRef<Path>, page_cache_pages: usize) -> Result<Self> { | ||
| let path = path.as_ref(); | ||
| if !path.is_dir() { | ||
| return Err(Error::InvalidFormat { | ||
| message: "AFD path is not a directory", | ||
| }); | ||
| } | ||
|
|
||
| let mut found = Vec::new(); | ||
| for entry in std::fs::read_dir(path)? { | ||
| let entry = entry?; | ||
| let file_name = entry.file_name(); | ||
| let Some(s) = file_name.to_str() else { | ||
| continue; | ||
| }; | ||
| if let Some(idx) = parse_afd_file_index(s) { | ||
| found.push((idx, entry.path())); | ||
| } | ||
| } | ||
| found.sort_by_key(|(i, _)| *i); | ||
|
|
||
| if found.is_empty() { | ||
| return Err(Error::InvalidFormat { | ||
| message: "AFD directory contains no file_###.aff entries", | ||
| }); | ||
| } | ||
|
|
||
| let mut files = Vec::new(); | ||
| for (_idx, p) in found { | ||
| files.push(Arc::new(Aff1Image::open_with(p, page_cache_pages)?)); | ||
| } | ||
|
|
||
| let page_size = files[0].page_size(); | ||
| if page_size == 0 { | ||
| return Err(Error::InvalidData { | ||
| message: "AFD pagesize cannot be 0".to_string(), | ||
| }); | ||
| } | ||
| for f in &files[1..] { | ||
| if f.page_size() != page_size { | ||
| return Err(Error::InvalidData { | ||
| message: "AFD pagesize mismatch across subfiles".to_string(), | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| let mut image_size = 0u64; | ||
| for f in &files { | ||
| image_size = image_size.max(f.len()); | ||
| } | ||
|
|
||
| // Build a page -> file mapping (first file wins). | ||
| let mut page_map: HashMap<u64, usize> = HashMap::new(); | ||
| for (file_idx, f) in files.iter().enumerate() { | ||
| for page in f.page_indices() { | ||
| page_map.entry(page).or_insert(file_idx); | ||
| } | ||
| } | ||
|
|
||
| Ok(Self { | ||
| files, | ||
| page_size, | ||
| image_size, | ||
| page_map, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| impl ReadAt for AfdImage { | ||
| fn len(&self) -> u64 { | ||
| self.image_size | ||
| } | ||
|
|
||
| fn read_exact_at(&self, offset: u64, buf: &mut [u8]) -> io::Result<()> { | ||
| if offset.saturating_add(buf.len() as u64) > self.len() { | ||
| return Err(io::Error::from(io::ErrorKind::UnexpectedEof)); | ||
| } | ||
|
|
||
| let mut remaining = buf.len(); | ||
| let mut out_pos = 0usize; | ||
| let mut cur = offset; | ||
|
|
||
| while remaining > 0 { | ||
| let page_index = cur / self.page_size as u64; | ||
| let within = (cur % self.page_size as u64) as usize; | ||
| let take = remaining.min(self.page_size - within); | ||
|
|
||
| if let Some(&file_idx) = self.page_map.get(&page_index) { | ||
| let file = &self.files[file_idx]; | ||
| file.read_exact_at(cur, &mut buf[out_pos..out_pos + take])?; | ||
| } else { | ||
| buf[out_pos..out_pos + take].fill(0); | ||
| } | ||
|
|
||
| out_pos += take; | ||
| remaining -= take; | ||
| cur = cur.saturating_add(take as u64); | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| impl Backend for AfdImage { | ||
| fn kind(&self) -> ContainerKind { | ||
| ContainerKind::Afd | ||
| } | ||
|
|
||
| fn page_size(&self) -> usize { | ||
| self.page_size | ||
| } | ||
|
|
||
| fn segment_names(&self) -> Vec<String> { | ||
| // Union across all subfiles (deduped + sorted). | ||
| let mut seen = HashSet::new(); | ||
| for f in &self.files { | ||
| for n in f.segment_names() { | ||
| seen.insert(n); | ||
| } | ||
| } | ||
| let mut out = seen.into_iter().collect::<Vec<_>>(); | ||
| out.sort(); | ||
| out | ||
| } | ||
|
|
||
| fn read_segment(&self, name: &str) -> io::Result<Option<Segment>> { | ||
| for f in &self.files { | ||
| if let Some(seg) = f.read_segment(name)? { | ||
| return Ok(Some(seg)); | ||
| } | ||
| } | ||
| Ok(None) | ||
| } | ||
| } | ||
|
|
||
| fn parse_afd_file_index(name: &str) -> Option<u32> { | ||
| // Matches "file_###.aff" | ||
| let (prefix, rest) = name.split_once('_')?; | ||
| if prefix != "file" { | ||
| return None; | ||
| } | ||
| let (digits, ext) = rest.split_once('.')?; | ||
| if ext != "aff" { | ||
| return None; | ||
| } | ||
| if digits.len() != 3 || !digits.as_bytes().iter().all(|b| b.is_ascii_digit()) { | ||
| return None; | ||
| } | ||
| digits.parse::<u32>().ok() | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.