diff --git a/Cargo.toml b/Cargo.toml index 84a884a..7c6e376 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,19 +38,19 @@ images = ["std", "dep:image"] [dependencies] -indexmap = { version = "2.5", default-features = false } +indexmap = { version = "2.6", default-features = false } log = { version = "0.4" } -zerocopy = { version = "0.7", features = ["derive"] } +zerocopy = { version = "0.8", features = ["derive"] } debug-ignore = { version = "1.0" } ahash = { version = "0.8", default-features = false, features = ["compile-time-rng"] } -image = { version = "0.25", default-features = false, optional = true, features = ["ico"] } +image = { version = "0.25.2", default-features = false, optional = true, features = ["ico"] } thiserror = { version = "1.0", optional = true } [dev-dependencies] editpe = { path = ".", features = ["std", "images"] } -image = { version = "0.25", default-features = false, features = ["png"] } +image = { version = "0.25.2", default-features = false, features = ["png"] } env_logger = { version = "0.11" } diff --git a/src/image.rs b/src/image.rs index 4534397..dccc3e6 100644 --- a/src/image.rs +++ b/src/image.rs @@ -7,7 +7,7 @@ use alloc::{borrow::Cow, string::ToString, vec::Vec}; use ahash::RandomState; use indexmap::IndexMap; use log::{debug, error, info, warn}; -use zerocopy::AsBytes; +use zerocopy::IntoBytes; use crate::{constants::*, errors::*, resource::*, types::*, util::*}; @@ -54,7 +54,7 @@ pub struct Image<'a> { directories_offset: u64, } -impl<'a> PartialEq for Image<'a> { +impl PartialEq for Image<'_> { fn eq(&self, other: &Self) -> bool { self.pe_dos_magic == other.pe_dos_magic && self.pe_signature == other.pe_signature @@ -66,7 +66,7 @@ impl<'a> PartialEq for Image<'a> { && self.resource_directory == other.resource_directory } } -impl<'a> Eq for Image<'a> {} +impl Eq for Image<'_> {} impl<'a> Image<'a> { /// Parse a portable executable image from a byte slice. diff --git a/src/resource.rs b/src/resource.rs index 69222ed..490dd7e 100644 --- a/src/resource.rs +++ b/src/resource.rs @@ -14,7 +14,7 @@ use ahash::RandomState; use debug_ignore::DebugIgnore; use indexmap::{IndexMap, IndexSet}; use log::{error, trace, warn}; -use zerocopy::AsBytes; +use zerocopy::IntoBytes; #[cfg(feature = "images")] pub use image::DynamicImage; @@ -60,7 +60,7 @@ impl ToIcon for Vec { #[cfg(feature = "images")] impl ToIcon for &DynamicImage { fn icons(&self) -> Result>, ResourceError> { - use image::{imageops::FilterType::Lanczos3, ImageFormat}; + use image::{ImageFormat, imageops::FilterType::Lanczos3}; use std::io::Cursor; const RESOLUTIONS: &[u32] = &[256, 128, 48, 32, 24, 16]; RESOLUTIONS diff --git a/src/types.rs b/src/types.rs index f958ed8..c47e4ab 100644 --- a/src/types.rs +++ b/src/types.rs @@ -5,11 +5,11 @@ use alloc::string::{String, ToString}; use core::{mem, slice}; -use zerocopy::{AsBytes, FromBytes, FromZeroes}; +use zerocopy::{FromBytes, Immutable, IntoBytes}; #[repr(C, packed(1))] #[derive( - Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, FromBytes, FromZeroes, AsBytes, Default, + Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, FromBytes, IntoBytes, Immutable, Default, )] pub struct VersionU8 { pub major: u8, @@ -17,7 +17,7 @@ pub struct VersionU8 { } #[repr(C, packed(2))] #[derive( - Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, FromBytes, FromZeroes, AsBytes, Default, + Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, FromBytes, IntoBytes, Immutable, Default, )] pub struct VersionU16 { pub major: u16, @@ -25,7 +25,7 @@ pub struct VersionU16 { } #[repr(C, packed(4))] #[derive( - Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, FromBytes, FromZeroes, AsBytes, Default, + Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, FromBytes, IntoBytes, Immutable, Default, )] pub struct VersionU32 { pub major: u32, @@ -33,7 +33,7 @@ pub struct VersionU32 { } #[repr(C, packed(2))] #[derive( - Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, FromBytes, FromZeroes, AsBytes, Default, + Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, FromBytes, IntoBytes, Immutable, Default, )] pub struct CoffHeader { pub machine: u16, @@ -46,7 +46,7 @@ pub struct CoffHeader { } #[repr(C, packed(2))] #[derive( - Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, FromBytes, FromZeroes, AsBytes, Default, + Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, FromBytes, IntoBytes, Immutable, Default, )] pub struct StandardHeader { pub magic: u16, @@ -58,7 +58,7 @@ pub struct StandardHeader { pub base_of_code: u32, } #[repr(C)] -#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, FromBytes, FromZeroes, Default)] +#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, FromBytes, Default)] pub struct WindowsHeader { pub image_base: UXX, pub section_alignment: u32, @@ -81,7 +81,7 @@ pub struct WindowsHeader { } impl WindowsHeader where - UXX: AsBytes, + UXX: IntoBytes, { pub fn as_bytes(&self) -> &[u8] { // manually implement this here because zerocopy doesn't support derive for generic types @@ -199,7 +199,7 @@ impl GenericWindowsHeader { #[repr(C, packed(4))] #[derive( - Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, FromBytes, FromZeroes, AsBytes, Default, + Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, FromBytes, IntoBytes, Immutable, Default, )] pub struct ImageDataDirectory { pub virtual_address: u32, @@ -208,7 +208,7 @@ pub struct ImageDataDirectory { #[repr(C, packed(4))] #[derive( - Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, FromBytes, FromZeroes, AsBytes, Default, + Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, FromBytes, IntoBytes, Immutable, Default, )] pub struct SectionHeader { pub name: u64, @@ -236,7 +236,7 @@ impl SectionHeader { #[repr(C, packed(2))] #[derive( - Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, FromBytes, FromZeroes, AsBytes, Default, + Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, FromBytes, IntoBytes, Immutable, Default, )] pub struct ResourceDirectoryTable { pub characteristics: u32, @@ -248,7 +248,7 @@ pub struct ResourceDirectoryTable { #[repr(C, packed(4))] #[derive( - Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, FromBytes, FromZeroes, AsBytes, Default, + Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, FromBytes, IntoBytes, Immutable, Default, )] pub struct ResourceDirectoryEntry { pub name_offset_or_integer_id: u32, @@ -257,7 +257,7 @@ pub struct ResourceDirectoryEntry { #[repr(C, packed(4))] #[derive( - Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, FromBytes, FromZeroes, AsBytes, Default, + Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, FromBytes, IntoBytes, Immutable, Default, )] pub struct ResourceDataEntry { pub data_rva: u32, @@ -268,7 +268,7 @@ pub struct ResourceDataEntry { #[repr(C, packed(2))] #[derive( - Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, FromBytes, FromZeroes, AsBytes, Default, + Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, FromBytes, IntoBytes, Immutable, Default, )] pub struct IconDirectory { pub reserved: u16, @@ -278,7 +278,7 @@ pub struct IconDirectory { #[repr(C, packed(1))] #[derive( - Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, FromBytes, FromZeroes, AsBytes, Default, + Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, FromBytes, IntoBytes, Immutable, Default, )] pub struct IconDirectoryEntry { pub width: u8, @@ -292,7 +292,7 @@ pub struct IconDirectoryEntry { } #[repr(C, packed(4))] -#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, FromBytes, FromZeroes, AsBytes)] +#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, FromBytes, IntoBytes, Immutable)] pub struct FixedFileInfo { pub signature: u32, pub struct_version: VersionU16, @@ -324,7 +324,7 @@ impl Default for FixedFileInfo { #[repr(C, packed(2))] #[derive( - Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, FromBytes, FromZeroes, AsBytes, Default, + Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, FromBytes, IntoBytes, Immutable, Default, )] pub struct VersionHeader { pub length: u16, diff --git a/src/util.rs b/src/util.rs index df4694e..e1bd1ad 100644 --- a/src/util.rs +++ b/src/util.rs @@ -12,7 +12,9 @@ use zerocopy::FromBytes; use crate::ReadError; pub fn read(resource: &[u8]) -> Result { - T::read_from_prefix(resource).ok_or_else(|| ReadError(type_name::().to_string())) + T::read_from_prefix(resource) + .map_err(|_| ReadError(type_name::().to_string())) + .map(|(value, _)| value) } pub fn aligned_to + Sub + Rem + Eq + Copy + Default>(