Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/ntfs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/structured_values/object_id.rs')
-rw-r--r--src/structured_values/object_id.rs97
1 files changed, 61 insertions, 36 deletions
diff --git a/src/structured_values/object_id.rs b/src/structured_values/object_id.rs
index 1a327f3..1efec3a 100644
--- a/src/structured_values/object_id.rs
+++ b/src/structured_values/object_id.rs
@@ -4,8 +4,12 @@
use crate::attribute::NtfsAttributeType;
use crate::error::{NtfsError, Result};
use crate::guid::{NtfsGuid, GUID_SIZE};
-use crate::structured_values::{NtfsStructuredValue, NtfsStructuredValueFromSlice};
-use binread::io::Cursor;
+use crate::structured_values::{
+ NtfsStructuredValue, NtfsStructuredValueFromResidentAttributeValue,
+};
+use crate::value::slice::NtfsSliceValue;
+use crate::value::NtfsValue;
+use binread::io::{Cursor, Read, Seek};
use binread::BinReaderExt;
#[derive(Clone, Debug)]
@@ -17,54 +21,34 @@ pub struct NtfsObjectId {
}
impl NtfsObjectId {
- pub fn birth_object_id(&self) -> Option<&NtfsGuid> {
- self.birth_object_id.as_ref()
- }
-
- pub fn birth_volume_id(&self) -> Option<&NtfsGuid> {
- self.birth_volume_id.as_ref()
- }
-
- pub fn domain_id(&self) -> Option<&NtfsGuid> {
- self.domain_id.as_ref()
- }
-
- pub fn object_id(&self) -> &NtfsGuid {
- &self.object_id
- }
-}
-
-impl NtfsStructuredValue for NtfsObjectId {
- const TY: NtfsAttributeType = NtfsAttributeType::ObjectId;
-}
-
-impl<'s> NtfsStructuredValueFromSlice<'s> for NtfsObjectId {
- fn from_slice(slice: &'s [u8], position: u64) -> Result<Self> {
- if slice.len() < GUID_SIZE {
+ fn new<T>(r: &mut T, position: u64, value_length: u64) -> Result<Self>
+ where
+ T: Read + Seek,
+ {
+ if value_length < GUID_SIZE as u64 {
return Err(NtfsError::InvalidStructuredValueSize {
position,
ty: NtfsAttributeType::ObjectId,
- expected: GUID_SIZE,
- actual: slice.len(),
+ expected: GUID_SIZE as u64,
+ actual: value_length,
});
}
- let mut cursor = Cursor::new(slice);
- let object_id = cursor.read_le::<NtfsGuid>()?;
+ let object_id = r.read_le::<NtfsGuid>()?;
let mut birth_volume_id = None;
- if slice.len() >= 2 * GUID_SIZE {
- birth_volume_id = Some(cursor.read_le::<NtfsGuid>()?);
+ if value_length >= 2 * GUID_SIZE as u64 {
+ birth_volume_id = Some(r.read_le::<NtfsGuid>()?);
}
let mut birth_object_id = None;
- if slice.len() >= 3 * GUID_SIZE {
- birth_object_id = Some(cursor.read_le::<NtfsGuid>()?);
+ if value_length >= 3 * GUID_SIZE as u64 {
+ birth_object_id = Some(r.read_le::<NtfsGuid>()?);
}
let mut domain_id = None;
- if slice.len() >= 4 * GUID_SIZE {
- domain_id = Some(cursor.read_le::<NtfsGuid>()?);
+ if value_length >= 4 * GUID_SIZE as u64 {
+ domain_id = Some(r.read_le::<NtfsGuid>()?);
}
Ok(Self {
@@ -74,4 +58,45 @@ impl<'s> NtfsStructuredValueFromSlice<'s> for NtfsObjectId {
domain_id,
})
}
+
+ pub fn birth_object_id(&self) -> Option<&NtfsGuid> {
+ self.birth_object_id.as_ref()
+ }
+
+ pub fn birth_volume_id(&self) -> Option<&NtfsGuid> {
+ self.birth_volume_id.as_ref()
+ }
+
+ pub fn domain_id(&self) -> Option<&NtfsGuid> {
+ self.domain_id.as_ref()
+ }
+
+ pub fn object_id(&self) -> &NtfsGuid {
+ &self.object_id
+ }
+}
+
+impl<'n, 'f> NtfsStructuredValue<'n, 'f> for NtfsObjectId {
+ const TY: NtfsAttributeType = NtfsAttributeType::ObjectId;
+
+ fn from_value<T>(fs: &mut T, value: NtfsValue<'n, 'f>) -> Result<Self>
+ where
+ T: Read + Seek,
+ {
+ let position = value.data_position().unwrap();
+ let value_length = value.len();
+
+ let mut value_attached = value.attach(fs);
+ Self::new(&mut value_attached, position, value_length)
+ }
+}
+
+impl<'n, 'f> NtfsStructuredValueFromResidentAttributeValue<'n, 'f> for NtfsObjectId {
+ fn from_resident_attribute_value(value: NtfsSliceValue<'f>) -> Result<Self> {
+ let position = value.data_position().unwrap();
+ let value_length = value.len();
+
+ let mut cursor = Cursor::new(value.data());
+ Self::new(&mut cursor, position, value_length)
+ }
}