Skip to content

Commit

Permalink
Upgrade dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinFinck committed Sep 1, 2023
1 parent 521275a commit d1b6971
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 50 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ keywords = ["windows", "nt", "registry", "hive", "regf"]
categories = ["no-std", "os::windows-apis", "parser-implementations"]

[dependencies]
bitflags = "1.3.2"
bitflags = "2.4.0"
byteorder = { version = "1.4.3", default-features = false }
displaydoc = { version = "0.2.3", default-features = false }
enumn = "0.1.6"
memoffset = "0.8.0"
zerocopy = "0.6.1"
displaydoc = { version = "0.2.4", default-features = false }
enumn = "0.1.11"
memoffset = "0.9.0"
zerocopy = { version = "0.7.1", features = ["derive"] }

[features]
default = ["std"]
Expand Down
14 changes: 5 additions & 9 deletions src/big_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::hive::Hive;
pub(crate) const BIG_DATA_SEGMENT_SIZE: usize = 16344;

/// On-Disk Structure of a Big Data header.
#[derive(AsBytes, FromBytes, Unaligned)]
#[derive(AsBytes, FromBytes, FromZeroes, Unaligned)]
#[repr(packed)]
struct BigDataHeader {
signature: [u8; 2],
Expand All @@ -31,7 +31,7 @@ struct BigDataHeader {
}

/// On-Disk Structure of a Big Data list item.
#[derive(AsBytes, FromBytes, Unaligned)]
#[derive(AsBytes, FromBytes, FromZeroes, Unaligned)]
#[repr(packed)]
struct BigDataListItem {
segment_offset: U32<LittleEndian>,
Expand All @@ -45,8 +45,7 @@ impl BigDataListItemRange {
where
B: ByteSlice,
{
let item =
LayoutVerified::<&[u8], BigDataListItem>::new(&hive.data[self.0.clone()]).unwrap();
let item = Ref::<&[u8], BigDataListItem>::new(&hive.data[self.0.clone()]).unwrap();
item.segment_offset.get()
}
}
Expand Down Expand Up @@ -90,7 +89,7 @@ impl BigDataListItemRanges {
actual: header_cell_range.len(),
})?;

let header = LayoutVerified::new(&hive.data[header_range]).unwrap();
let header = Ref::new(&hive.data[header_range]).unwrap();
Self::validate_signature(hive, &header)?;

// Check the `segment_count` of the `BigDataHeader`.
Expand Down Expand Up @@ -123,10 +122,7 @@ impl BigDataListItemRanges {
Ok(Self { items_range })
}

fn validate_signature<B>(
hive: &Hive<B>,
header: &LayoutVerified<&[u8], BigDataHeader>,
) -> Result<()>
fn validate_signature<B>(hive: &Hive<B>, header: &Ref<&[u8], BigDataHeader>) -> Result<()>
where
B: ByteSlice,
{
Expand Down
12 changes: 6 additions & 6 deletions src/hive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ use ::byteorder::LittleEndian;
use enumn::N;
use memoffset::offset_of;
use zerocopy::{
AsBytes, ByteSlice, ByteSliceMut, FromBytes, LayoutVerified, Unaligned, I32, U16, U32, U64,
AsBytes, ByteSlice, ByteSliceMut, FromBytes, FromZeroes, Ref, Unaligned, I32, U16, U32, U64,
};

use crate::error::{NtHiveError, Result};
use crate::helpers::byte_subrange;
use crate::key_node::{KeyNode, KeyNodeMut};

#[derive(AsBytes, FromBytes, Unaligned)]
#[derive(AsBytes, FromBytes, FromZeroes, Unaligned)]
#[repr(packed)]
struct CellHeader {
size: I32<LittleEndian>,
Expand Down Expand Up @@ -51,7 +51,7 @@ enum HiveFileFormats {
}

#[allow(dead_code)]
#[derive(AsBytes, FromBytes, Unaligned)]
#[derive(AsBytes, FromBytes, FromZeroes, Unaligned)]
#[repr(packed)]
struct HiveBaseBlock {
signature: [u8; 4],
Expand All @@ -75,7 +75,7 @@ struct HiveBaseBlock {

/// Root structure describing a registry hive.
pub struct Hive<B: ByteSlice> {
base_block: LayoutVerified<B, HiveBaseBlock>,
base_block: Ref<B, HiveBaseBlock>,
pub(crate) data: B,
}

Expand All @@ -101,7 +101,7 @@ where
pub fn without_validation(bytes: B) -> Result<Self> {
let length = bytes.len();
let (base_block, data) =
LayoutVerified::new_from_prefix(bytes).ok_or(NtHiveError::InvalidHeaderSize {
Ref::new_from_prefix(bytes).ok_or(NtHiveError::InvalidHeaderSize {
offset: 0,
expected: mem::size_of::<HiveBaseBlock>(),
actual: length,
Expand Down Expand Up @@ -130,7 +130,7 @@ where
let cell_data_offset = header_range.end;

// After the check above, the following operation must succeed, so we can just `unwrap`.
let header = LayoutVerified::<&[u8], CellHeader>::new(&self.data[header_range]).unwrap();
let header = Ref::<&[u8], CellHeader>::new(&self.data[header_range]).unwrap();
let cell_size = header.size.get();

// A cell with size > 0 is unallocated and shouldn't be processed any further by us.
Expand Down
6 changes: 3 additions & 3 deletions src/index_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use core::mem;
use core::ops::{Deref, Range};

use ::byteorder::LittleEndian;
use zerocopy::{AsBytes, ByteSlice, ByteSliceMut, FromBytes, LayoutVerified, Unaligned, U32};
use zerocopy::{AsBytes, ByteSlice, ByteSliceMut, FromBytes, FromZeroes, Ref, Unaligned, U32};

use crate::error::{NtHiveError, Result};
use crate::helpers::byte_subrange;
Expand All @@ -15,7 +15,7 @@ use crate::key_node::{KeyNode, KeyNodeMut};
use crate::leaf::LeafItemRanges;

/// On-Disk Structure of a single Index Root item.
#[derive(AsBytes, FromBytes, Unaligned)]
#[derive(AsBytes, FromBytes, FromZeroes, Unaligned)]
#[repr(packed)]
struct IndexRootItem {
subkeys_list_offset: U32<LittleEndian>,
Expand All @@ -29,7 +29,7 @@ impl IndexRootItemRange {
where
B: ByteSlice,
{
let item = LayoutVerified::<&[u8], IndexRootItem>::new(&hive.data[self.0.clone()]).unwrap();
let item = Ref::<&[u8], IndexRootItem>::new(&hive.data[self.0.clone()]).unwrap();
item.subkeys_list_offset.get()
}
}
Expand Down
15 changes: 6 additions & 9 deletions src/key_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use core::ptr;
use ::byteorder::LittleEndian;
use bitflags::bitflags;
use zerocopy::{
AsBytes, ByteSlice, ByteSliceMut, FromBytes, LayoutVerified, Unaligned, U16, U32, U64,
AsBytes, ByteSlice, ByteSliceMut, FromBytes, FromZeroes, Ref, Unaligned, U16, U32, U64,
};

use crate::error::{NtHiveError, Result};
Expand Down Expand Up @@ -49,7 +49,7 @@ bitflags! {

/// On-Disk Structure of a Key Node header.
#[allow(dead_code)]
#[derive(AsBytes, FromBytes, Unaligned)]
#[derive(AsBytes, FromBytes, FromZeroes, Unaligned)]
#[repr(packed)]
struct KeyNodeHeader {
signature: [u8; 2],
Expand Down Expand Up @@ -245,21 +245,18 @@ impl KeyNodeItemRange {
Some(Ok(NtHiveNameString::Utf16LE(class_name_bytes)))
}

fn header<'h, B>(&self, hive: &'h Hive<B>) -> LayoutVerified<&'h [u8], KeyNodeHeader>
fn header<'h, B>(&self, hive: &'h Hive<B>) -> Ref<&'h [u8], KeyNodeHeader>
where
B: ByteSlice,
{
LayoutVerified::new(&hive.data[self.header_range.clone()]).unwrap()
Ref::new(&hive.data[self.header_range.clone()]).unwrap()
}

fn header_mut<'h, B>(
&self,
hive: &'h mut Hive<B>,
) -> LayoutVerified<&'h mut [u8], KeyNodeHeader>
fn header_mut<'h, B>(&self, hive: &'h mut Hive<B>) -> Ref<&'h mut [u8], KeyNodeHeader>
where
B: ByteSliceMut,
{
LayoutVerified::new(&mut hive.data[self.header_range.clone()]).unwrap()
Ref::new(&mut hive.data[self.header_range.clone()]).unwrap()
}

fn name<'h, B>(&self, hive: &'h Hive<B>) -> Result<NtHiveNameString<'h>>
Expand Down
8 changes: 4 additions & 4 deletions src/key_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ::byteorder::{BigEndian, ByteOrder, LittleEndian};
use bitflags::bitflags;
use enumn::N;
use memoffset::offset_of;
use zerocopy::{AsBytes, ByteSlice, FromBytes, LayoutVerified, Unaligned, U16, U32};
use zerocopy::{AsBytes, ByteSlice, FromBytes, FromZeroes, Ref, Unaligned, U16, U32};

use crate::big_data::{BigDataSlices, BIG_DATA_SEGMENT_SIZE};
use crate::error::{NtHiveError, Result};
Expand Down Expand Up @@ -90,7 +90,7 @@ pub enum KeyValueDataType {

/// On-Disk Structure of a Key Value header.
#[allow(dead_code)]
#[derive(AsBytes, FromBytes, Unaligned)]
#[derive(AsBytes, FromBytes, FromZeroes, Unaligned)]
#[repr(packed)]
struct KeyValueHeader {
signature: [u8; 2],
Expand Down Expand Up @@ -138,8 +138,8 @@ where
Ok(key_value)
}

fn header(&self) -> LayoutVerified<&[u8], KeyValueHeader> {
LayoutVerified::new(&self.hive.data[self.header_range.clone()]).unwrap()
fn header(&self) -> Ref<&[u8], KeyValueHeader> {
Ref::new(&self.hive.data[self.header_range.clone()]).unwrap()
}

/// Returns the raw data bytes as [`KeyValueData`].
Expand Down
7 changes: 3 additions & 4 deletions src/key_values_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use core::mem;
use core::ops::{Deref, Range};

use ::byteorder::LittleEndian;
use zerocopy::{AsBytes, ByteSlice, FromBytes, LayoutVerified, Unaligned, U32};
use zerocopy::{AsBytes, ByteSlice, FromBytes, FromZeroes, Ref, Unaligned, U32};

use crate::error::{NtHiveError, Result};
use crate::helpers::byte_subrange;
Expand All @@ -15,7 +15,7 @@ use crate::key_value::KeyValue;

/// On-Disk Structure of a Key Values List item.
#[allow(dead_code)]
#[derive(AsBytes, FromBytes, Unaligned)]
#[derive(AsBytes, FromBytes, FromZeroes, Unaligned)]
#[repr(packed)]
struct KeyValuesListItem {
key_value_offset: U32<LittleEndian>,
Expand All @@ -29,8 +29,7 @@ impl KeyValuesListItemRange {
where
B: ByteSlice,
{
let item =
LayoutVerified::<&[u8], KeyValuesListItem>::new(&hive.data[self.0.clone()]).unwrap();
let item = Ref::<&[u8], KeyValuesListItem>::new(&hive.data[self.0.clone()]).unwrap();
item.key_value_offset.get()
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/leaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use core::mem;
use core::ops::{Deref, Range};

use ::byteorder::LittleEndian;
use zerocopy::{AsBytes, ByteSlice, ByteSliceMut, FromBytes, LayoutVerified, Unaligned, U32};
use zerocopy::{AsBytes, ByteSlice, ByteSliceMut, FromBytes, FromZeroes, Ref, Unaligned, U32};

use crate::error::{NtHiveError, Result};
use crate::helpers::byte_subrange;
Expand All @@ -18,7 +18,7 @@ use crate::subkeys_list::SubkeysList;
/// On-Disk Structure of a Fast Leaf item (On-Disk Signature: `lf`).
/// They are supported since Windows NT 4.
#[allow(dead_code)]
#[derive(AsBytes, FromBytes, Unaligned)]
#[derive(AsBytes, FromBytes, FromZeroes, Unaligned)]
#[repr(packed)]
struct FastLeafItem {
key_node_offset: U32<LittleEndian>,
Expand All @@ -28,7 +28,7 @@ struct FastLeafItem {
/// On-Disk Structure of a Hash Leaf item (On-Disk Signature: `lh`).
/// They are supported since Windows XP.
#[allow(dead_code)]
#[derive(AsBytes, FromBytes, Unaligned)]
#[derive(AsBytes, FromBytes, FromZeroes, Unaligned)]
#[repr(packed)]
struct HashLeafItem {
key_node_offset: U32<LittleEndian>,
Expand All @@ -37,7 +37,7 @@ struct HashLeafItem {

/// On-Disk Structure of an Index Leaf item (On-Disk Signature: `li`).
/// They are supported in all Windows versions.
#[derive(AsBytes, FromBytes, Unaligned)]
#[derive(AsBytes, FromBytes, FromZeroes, Unaligned)]
#[repr(packed)]
struct IndexLeafItem {
key_node_offset: U32<LittleEndian>,
Expand Down Expand Up @@ -92,8 +92,7 @@ impl LeafItemRange {
// `IndexLeafItem` with additional fields.
// As they all have the `key_node_offset` as their first field, treat them equally.
let (index_leaf_item, _) =
LayoutVerified::<&[u8], IndexLeafItem>::new_from_prefix(&hive.data[self.0.clone()])
.unwrap();
Ref::<&[u8], IndexLeafItem>::new_from_prefix(&hive.data[self.0.clone()]).unwrap();
index_leaf_item.key_node_offset.get()
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/subkeys_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use core::mem;
use core::ops::Range;

use ::byteorder::LittleEndian;
use zerocopy::{AsBytes, ByteSlice, ByteSliceMut, FromBytes, LayoutVerified, Unaligned, U16};
use zerocopy::{AsBytes, ByteSlice, ByteSliceMut, FromBytes, FromZeroes, Ref, Unaligned, U16};

use crate::error::{NtHiveError, Result};
use crate::helpers::byte_subrange;
Expand All @@ -17,7 +17,7 @@ use crate::leaf::{LeafKeyNodes, LeafKeyNodesMut, LeafType};

/// On-Disk Structure of a Subkeys List header.
/// This is common for all subkey types (Fast Leaf, Hash Leaf, Index Leaf, Index Root).
#[derive(AsBytes, FromBytes, Unaligned)]
#[derive(AsBytes, FromBytes, FromZeroes, Unaligned)]
#[repr(packed)]
pub(crate) struct SubkeysListHeader {
pub(crate) signature: [u8; 2],
Expand Down Expand Up @@ -73,8 +73,8 @@ where
Ok(subkeys_list)
}

pub(crate) fn header(&self) -> LayoutVerified<&[u8], SubkeysListHeader> {
LayoutVerified::new(&self.hive.data[self.header_range.clone()]).unwrap()
pub(crate) fn header(&self) -> Ref<&[u8], SubkeysListHeader> {
Ref::new(&self.hive.data[self.header_range.clone()]).unwrap()
}

fn validate_signature(&self, index_root_supported: bool) -> Result<()> {
Expand Down

0 comments on commit d1b6971

Please sign in to comment.