Skip to content

Commit

Permalink
remove unused Option<T>s
Browse files Browse the repository at this point in the history
  • Loading branch information
kkent030315 committed Jan 10, 2025
1 parent 737cc6a commit d0be14a
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/pe/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,14 @@ impl<'a> DebugData<'a> {
codeview_pdb20_debug_info = CodeviewPDB20DebugInfo::parse_with_opts(bytes, idd, opts)?;
}
if let Some(idd) = &it.find_type(IMAGE_DEBUG_TYPE_VC_FEATURE) {
vcfeature_info = VCFeatureInfo::parse_with_opts(bytes, idd, opts)?;
vcfeature_info = Some(VCFeatureInfo::parse_with_opts(bytes, idd, opts)?);
}
if let Some(idd) = &it.find_type(IMAGE_DEBUG_TYPE_EX_DLLCHARACTERISTICS) {
ex_dll_characteristics_info =
ExDllCharacteristicsInfo::parse_with_opts(bytes, idd, opts)?;
Some(ExDllCharacteristicsInfo::parse_with_opts(bytes, idd, opts)?);
}
if let Some(idd) = &it.find_type(IMAGE_DEBUG_TYPE_REPRO) {
repro_info = ReproInfo::parse_with_opts(bytes, idd, opts)?;
repro_info = Some(ReproInfo::parse_with_opts(bytes, idd, opts)?);
}
if let Some(idd) = &it.find_type(IMAGE_DEBUG_TYPE_POGO) {
pogo_info = POGOInfo::parse_with_opts(bytes, idd, opts)?;
Expand Down Expand Up @@ -415,15 +415,15 @@ pub struct VCFeatureInfo {
}

impl<'a> VCFeatureInfo {
pub fn parse(bytes: &'a [u8], idd: &ImageDebugDirectory) -> error::Result<Option<Self>> {
pub fn parse(bytes: &'a [u8], idd: &ImageDebugDirectory) -> error::Result<Self> {
Self::parse_with_opts(bytes, idd, &options::ParseOptions::default())
}

pub fn parse_with_opts(
bytes: &'a [u8],
idd: &ImageDebugDirectory,
opts: &options::ParseOptions,
) -> error::Result<Option<Self>> {
) -> error::Result<Self> {
let mut offset: usize = match opts.resolve_rva {
true => idd.pointer_to_raw_data as usize,
false => idd.address_of_raw_data as usize,
Expand All @@ -435,13 +435,13 @@ impl<'a> VCFeatureInfo {
let sdl_count: u32 = bytes.gread_with(&mut offset, scroll::LE)?;
let guard_count: u32 = bytes.gread_with(&mut offset, scroll::LE)?;

Ok(Some(VCFeatureInfo {
Ok(VCFeatureInfo {
pre_vc_plusplus_count,
c_and_cplusplus_count,
guard_stack_count,
sdl_count,
guard_count,
}))
})
}
}

Expand Down Expand Up @@ -536,15 +536,15 @@ pub enum ReproInfo<'a> {
}

impl<'a> ReproInfo<'a> {
pub fn parse(bytes: &'a [u8], idd: &ImageDebugDirectory) -> error::Result<Option<Self>> {
pub fn parse(bytes: &'a [u8], idd: &ImageDebugDirectory) -> error::Result<Self> {
Self::parse_with_opts(bytes, idd, &options::ParseOptions::default())
}

pub fn parse_with_opts(
bytes: &'a [u8],
idd: &ImageDebugDirectory,
opts: &options::ParseOptions,
) -> error::Result<Option<Self>> {
) -> error::Result<Self> {
let mut offset: usize = match opts.resolve_rva {
true => idd.pointer_to_raw_data as usize,
false => idd.address_of_raw_data as usize,
Expand All @@ -555,15 +555,15 @@ impl<'a> ReproInfo<'a> {
if idd.size_of_data > 0 {
let length: u32 = bytes.gread_with(&mut offset, scroll::LE)?;
if let Some(buffer) = bytes.get(offset..offset + length as usize) {
Ok(Some(Self::Buffer { length, buffer }))
Ok(Self::Buffer { length, buffer })
} else {
Err(error::Error::Malformed(format!(
"ImageDebugDirectory seems corrupted: {:?}",
idd
)))
}
} else {
Ok(Some(Self::TimeDateStamp(idd.time_date_stamp)))
Ok(Self::TimeDateStamp(idd.time_date_stamp))
}
}
}
Expand Down Expand Up @@ -627,15 +627,15 @@ pub const IMAGE_DLLCHARACTERISTICS_EX_FORWARD_CFI_COMPAT: u32 = 0x40;
pub const IMAGE_DLLCHARACTERISTICS_EX_HOTPATCH_COMPATIBLE: u32 = 0x80;

impl<'a> ExDllCharacteristicsInfo {
pub fn parse(bytes: &'a [u8], idd: &ImageDebugDirectory) -> error::Result<Option<Self>> {
pub fn parse(bytes: &'a [u8], idd: &ImageDebugDirectory) -> error::Result<Self> {
Self::parse_with_opts(bytes, idd, &options::ParseOptions::default())
}

pub fn parse_with_opts(
bytes: &'a [u8],
idd: &ImageDebugDirectory,
opts: &options::ParseOptions,
) -> error::Result<Option<Self>> {
) -> error::Result<Self> {
// ImageDebugDirectory.pointer_to_raw_data stores a raw offset -- not a virtual offset -- which we can use directly
let mut offset: usize = match opts.resolve_rva {
true => idd.pointer_to_raw_data as usize,
Expand All @@ -644,7 +644,7 @@ impl<'a> ExDllCharacteristicsInfo {

let characteristics_ex: u32 = bytes.gread_with(&mut offset, scroll::LE)?;

Ok(Some(ExDllCharacteristicsInfo { characteristics_ex }))
Ok(ExDllCharacteristicsInfo { characteristics_ex })
}
}

Expand Down

0 comments on commit d0be14a

Please sign in to comment.