use crate::*;
use super::Wrap;
use std::slice;
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(::serde::Serialize))]
pub enum Import<'a> {
ByName { hint: usize, name: &'a util::CStr },
ByOrdinal { ord: u16 },
}
impl<'a, Pe32: pe32::Pe<'a>, Pe64: pe64::Pe<'a>> Wrap<pe32::imports::Imports<'a, Pe32>, pe64::imports::Imports<'a, Pe64>> {
#[inline]
pub fn pe(&self) -> Wrap<Pe32, Pe64> {
match self {
Wrap::T32(imports) => Wrap::T32(imports.pe()),
Wrap::T64(imports) => Wrap::T64(imports.pe()),
}
}
#[inline]
pub fn image(&self) -> &'a [image::IMAGE_IMPORT_DESCRIPTOR] {
match self {
Wrap::T32(imports) => imports.image(),
Wrap::T64(imports) => imports.image(),
}
}
#[inline]
pub fn iter(&self) -> Wrap<pe32::imports::Iter<'a, Pe32>, pe64::imports::Iter<'a, Pe64>> {
match self {
Wrap::T32(imports) => Wrap::T32(imports.iter()),
Wrap::T64(imports) => Wrap::T64(imports.iter()),
}
}
}
impl<'a, Pe32: pe32::Pe<'a>, Pe64: pe64::Pe<'a>> IntoIterator for Wrap<pe32::imports::Imports<'a, Pe32>, pe64::imports::Imports<'a, Pe64>> {
type Item = Wrap<pe32::imports::Desc<'a, Pe32>, pe64::imports::Desc<'a, Pe64>>;
type IntoIter = Wrap<pe32::imports::Iter<'a, Pe32>, pe64::imports::Iter<'a, Pe64>>;
#[inline]
fn into_iter(self) -> Self::IntoIter {
match self {
Wrap::T32(imports) => Wrap::T32(imports.into_iter()),
Wrap::T64(imports) => Wrap::T64(imports.into_iter()),
}
}
}
impl<'a, Pe32: pe32::Pe<'a>, Pe64: pe64::Pe<'a>> Wrap<pe32::imports::IAT<'a, Pe32>, pe64::imports::IAT<'a, Pe64>> {
#[inline]
pub fn pe(&self) -> Wrap<Pe32, Pe64> {
match self {
Wrap::T32(iat) => Wrap::T32(iat.pe()),
Wrap::T64(iat) => Wrap::T64(iat.pe()),
}
}
#[inline]
pub fn image(&self) -> Wrap<&'a [u32], &'a [u64]> {
match self {
Wrap::T32(iat) => Wrap::T32(iat.image()),
Wrap::T64(iat) => Wrap::T64(iat.image()),
}
}
#[inline]
pub fn iter(&self) -> Wrap<impl Clone + Iterator<Item = (&'a u32, Result<pe32::imports::Import<'a>>)>, impl Clone + Iterator<Item = (&'a u64, Result<pe64::imports::Import<'a>>)>> {
match self {
Wrap::T32(iat) => Wrap::T32(iat.iter()),
Wrap::T64(iat) => Wrap::T64(iat.iter()),
}
}
}
impl<'a, Pe32: pe32::Pe<'a>, Pe64: pe64::Pe<'a>> Wrap<pe32::imports::Desc<'a, Pe32>, pe64::imports::Desc<'a, Pe64>> {
#[inline]
pub fn pe(&self) -> Wrap<Pe32, Pe64> {
match self {
Wrap::T32(desc) => Wrap::T32(desc.pe()),
Wrap::T64(desc) => Wrap::T64(desc.pe()),
}
}
#[inline]
pub fn image(&self) -> &'a image::IMAGE_IMPORT_DESCRIPTOR {
match self {
Wrap::T32(desc) => desc.image(),
Wrap::T64(desc) => desc.image(),
}
}
#[inline]
pub fn dll_name(&self) -> Result<&'a util::CStr> {
match self {
Wrap::T32(desc) => desc.dll_name(),
Wrap::T64(desc) => desc.dll_name(),
}
}
#[inline]
pub fn iat(&self) -> Result<Wrap<slice::Iter<'a, u32>, slice::Iter<'a, u64>>> {
match self {
Wrap::T32(desc) => Wrap::T32(desc.iat()).transpose(),
Wrap::T64(desc) => Wrap::T64(desc.iat()).transpose(),
}
}
#[inline]
pub fn int(&self) -> Result<impl Clone + Iterator<Item = Result<Import<'a>>>> {
match self {
Wrap::T32(desc) => Ok(Wrap::T32(desc.int()?).map(Wrap::into)),
Wrap::T64(desc) => Ok(Wrap::T64(desc.int()?).map(Wrap::into)),
}
}
}