From d1b6971751d1dda9da282aeb532d873341a3d88b Mon Sep 17 00:00:00 2001 From: Colin Finck Date: Fri, 1 Sep 2023 11:50:49 +0200 Subject: [PATCH] Upgrade dependencies. --- Cargo.toml | 10 +++++----- src/big_data.rs | 14 +++++--------- src/hive.rs | 12 ++++++------ src/index_root.rs | 6 +++--- src/key_node.rs | 15 ++++++--------- src/key_value.rs | 8 ++++---- src/key_values_list.rs | 7 +++---- src/leaf.rs | 11 +++++------ src/subkeys_list.rs | 8 ++++---- 9 files changed, 41 insertions(+), 50 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cbd4037..56dbf27 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] diff --git a/src/big_data.rs b/src/big_data.rs index 4898544..563c7a6 100644 --- a/src/big_data.rs +++ b/src/big_data.rs @@ -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], @@ -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, @@ -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() } } @@ -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`. @@ -123,10 +122,7 @@ impl BigDataListItemRanges { Ok(Self { items_range }) } - fn validate_signature( - hive: &Hive, - header: &LayoutVerified<&[u8], BigDataHeader>, - ) -> Result<()> + fn validate_signature(hive: &Hive, header: &Ref<&[u8], BigDataHeader>) -> Result<()> where B: ByteSlice, { diff --git a/src/hive.rs b/src/hive.rs index e765536..8545e34 100644 --- a/src/hive.rs +++ b/src/hive.rs @@ -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, @@ -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], @@ -75,7 +75,7 @@ struct HiveBaseBlock { /// Root structure describing a registry hive. pub struct Hive { - base_block: LayoutVerified, + base_block: Ref, pub(crate) data: B, } @@ -101,7 +101,7 @@ where pub fn without_validation(bytes: B) -> Result { 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::(), actual: length, @@ -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. diff --git a/src/index_root.rs b/src/index_root.rs index 52234eb..334c87f 100644 --- a/src/index_root.rs +++ b/src/index_root.rs @@ -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; @@ -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, @@ -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() } } diff --git a/src/key_node.rs b/src/key_node.rs index 869755f..9d6db15 100644 --- a/src/key_node.rs +++ b/src/key_node.rs @@ -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}; @@ -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], @@ -245,21 +245,18 @@ impl KeyNodeItemRange { Some(Ok(NtHiveNameString::Utf16LE(class_name_bytes))) } - fn header<'h, B>(&self, hive: &'h Hive) -> LayoutVerified<&'h [u8], KeyNodeHeader> + fn header<'h, B>(&self, hive: &'h Hive) -> 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, - ) -> LayoutVerified<&'h mut [u8], KeyNodeHeader> + fn header_mut<'h, B>(&self, hive: &'h mut Hive) -> 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) -> Result> diff --git a/src/key_value.rs b/src/key_value.rs index 808ea8f..4f5e732 100644 --- a/src/key_value.rs +++ b/src/key_value.rs @@ -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}; @@ -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], @@ -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`]. diff --git a/src/key_values_list.rs b/src/key_values_list.rs index 423533b..6949730 100644 --- a/src/key_values_list.rs +++ b/src/key_values_list.rs @@ -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; @@ -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, @@ -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() } } diff --git a/src/leaf.rs b/src/leaf.rs index 93ece82..9587048 100644 --- a/src/leaf.rs +++ b/src/leaf.rs @@ -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; @@ -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, @@ -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, @@ -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, @@ -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() } } diff --git a/src/subkeys_list.rs b/src/subkeys_list.rs index ae3020a..887f15c 100644 --- a/src/subkeys_list.rs +++ b/src/subkeys_list.rs @@ -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; @@ -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], @@ -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<()> {