Skip to content

Commit

Permalink
Merge pull request #15 from dfir-dd/14-celliterator-has-an-intranspar…
Browse files Browse the repository at this point in the history
…ent-implementation-and-should-be-rewritten

14 celliterator has an intransparent implementation and should be rewritten
  • Loading branch information
janstarke authored Apr 16, 2024
2 parents fd6e739 + c276868 commit 7b91240
Show file tree
Hide file tree
Showing 12 changed files with 709 additions and 804 deletions.
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nt_hive2"
version = "4.1.0"
version = "4.2.0"
edition = "2021"
authors = ["Jan Starke <[email protected]>", "Muteb Alqahtani <[email protected]>"]
license = "GPL-3.0"
Expand Down Expand Up @@ -30,7 +30,6 @@ memoverlay = ">=0.1.3"
num-traits = "0.2"
num-derive = "0.4"
byteorder = "1.4"


getset = "0.1"
[dev-dependencies]
simplelog = "0.12"
42 changes: 23 additions & 19 deletions src/cell.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::any::Any;

use binread::{BinRead, derive_binread};
use std::{any::Any};
use binread::{derive_binread, BinRead};

#[allow(unused_imports)]
use crate::*;
Expand All @@ -19,12 +19,12 @@ pub struct CellHeader {
size: usize,

#[br(calc(raw_size > 0))]
is_deleted: bool
is_deleted: bool,
}

impl CellHeader {
/// Returns the size of the header.
///
/// Returns the size of this cell, including the header.
///
/// This is *not* the stored size value, but the *absolute* value of it.
pub fn size(&self) -> usize {
self.size
Expand All @@ -38,31 +38,31 @@ impl CellHeader {
}

/// returns [true] iff the [Cell] is considered as being *deleted*
///
///
pub fn is_deleted(&self) -> bool {
self.is_deleted
}
}

/// A [Cell] represents the most basic data structure of hive files.
/// Nearly every other data is stored as content of a [Cell].
///
///
/// As [Cell] is a generic, it receives two generic arguments:
/// - `T` denotes the type contained in the [Cell]
/// - `A` specifies the arguments required by [binread] to correctly parse an object of type `T`
///
///
/// # Usage
/// If you know what kind of data should be stored in a certain [Cell],
/// you can simply read it. Assume you have [Cell] which should contain
/// a [`KeyNode`](struct@KeyNode), you can read it as follows:
///
///
/// ```
/// # use std::error::Error;
/// # use std::fs::File;
/// use nt_hive2::*;
/// use std::io::{Seek, SeekFrom};
/// use binread::BinReaderExt;
///
///
/// # fn main() -> Result<(), Box<dyn Error>> {
/// # let hive_file = File::open("tests/data/testhive")?;
/// # let mut hive = Hive::new(hive_file, HiveParseMode::NormalWithBaseBlock)?;
Expand All @@ -76,35 +76,39 @@ impl CellHeader {
/// # Ok(())
/// # }
/// ```
///
///
/// For conveniance reasons, [Hive] already presents the method [read_structure](Hive::read_structure),
/// which does basically the same.
///
///
#[derive(BinRead, Eq, PartialEq)]
#[br(import_tuple(data_args: A))]
pub struct Cell<T, A: Any + Copy>
where
T: BinRead<Args=A>, {
T: BinRead<Args = A>,
{
header: CellHeader,

#[br(args_tuple(data_args))]
data: T,
}

impl<T, A> Cell<T, A> where T: BinRead<Args=A>, A: Any + Copy {
impl<T, A> Cell<T, A>
where
T: BinRead<Args = A>,
A: Any + Copy,
{
/// returns [true] iff the [Cell] is considered as being *deleted*
///
///
pub fn is_deleted(&self) -> bool {
self.header.is_deleted
}

/// returns [true] iff the [Cell] is considered as being *allocated*.
/// This is a conveniance function which simply calls [is_deleted](Self::is_deleted)
/// and negates the result.
///
///
pub fn is_allocated(&self) -> bool {
! self.is_deleted()
!self.is_deleted()
}

/// returns a reference to the contained data structure
Expand All @@ -116,4 +120,4 @@ impl<T, A> Cell<T, A> where T: BinRead<Args=A>, A: Any + Copy {
pub(crate) fn into_data(self) -> T {
self.data
}
}
}
246 changes: 0 additions & 246 deletions src/cell_iterator.rs

This file was deleted.

3 changes: 1 addition & 2 deletions src/hive/base_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ impl BinRead for CalculatedChecksum {
options: &binread::ReadOptions,
_: Self::Args,
) -> binread::prelude::BinResult<Self> {

reader.seek(std::io::SeekFrom::End(0))?;
reader.seek(std::io::SeekFrom::Start(0))?;

let data: Vec<u32> = count(127)(reader, options, ())?;

let checksum = match data.into_iter().fold(0, |acc, x| acc ^ x) {
0xffff_ffff => 0xffff_fffe,
0 => 1,
Expand Down
Loading

0 comments on commit 7b91240

Please sign in to comment.