1use crate::*;
2use super::Wrap;
3
4use std::slice;
5
6#[derive(Copy, Clone, Debug, Eq, PartialEq)]
8#[cfg_attr(feature = "serde", derive(::serde::Serialize))]
9pub enum Import<'a> {
10 ByName { hint: usize, name: &'a util::CStr },
15 ByOrdinal { ord: u16 },
17}
18
19impl<'a, Pe32: pe32::Pe<'a>, Pe64: pe64::Pe<'a>> Wrap<pe32::imports::Imports<'a, Pe32>, pe64::imports::Imports<'a, Pe64>> {
21 #[inline]
23 pub fn pe(&self) -> Wrap<Pe32, Pe64> {
24 match self {
25 Wrap::T32(imports) => Wrap::T32(imports.pe()),
26 Wrap::T64(imports) => Wrap::T64(imports.pe()),
27 }
28 }
29 #[inline]
31 pub fn image(&self) -> &'a [image::IMAGE_IMPORT_DESCRIPTOR] {
32 match self {
33 Wrap::T32(imports) => imports.image(),
34 Wrap::T64(imports) => imports.image(),
35 }
36 }
37 #[inline]
39 pub fn iter(&self) -> Wrap<pe32::imports::Iter<'a, Pe32>, pe64::imports::Iter<'a, Pe64>> {
40 match self {
41 Wrap::T32(imports) => Wrap::T32(imports.iter()),
42 Wrap::T64(imports) => Wrap::T64(imports.iter()),
43 }
44 }
45}
46impl<'a, Pe32: pe32::Pe<'a>, Pe64: pe64::Pe<'a>> IntoIterator for Wrap<pe32::imports::Imports<'a, Pe32>, pe64::imports::Imports<'a, Pe64>> {
47 type Item = Wrap<pe32::imports::Desc<'a, Pe32>, pe64::imports::Desc<'a, Pe64>>;
48 type IntoIter = Wrap<pe32::imports::Iter<'a, Pe32>, pe64::imports::Iter<'a, Pe64>>;
49 #[inline]
50 fn into_iter(self) -> Self::IntoIter {
51 match self {
52 Wrap::T32(imports) => Wrap::T32(imports.into_iter()),
53 Wrap::T64(imports) => Wrap::T64(imports.into_iter()),
54 }
55 }
56}
57
58impl<'a, Pe32: pe32::Pe<'a>, Pe64: pe64::Pe<'a>> Wrap<pe32::imports::IAT<'a, Pe32>, pe64::imports::IAT<'a, Pe64>> {
60 #[inline]
62 pub fn pe(&self) -> Wrap<Pe32, Pe64> {
63 match self {
64 Wrap::T32(iat) => Wrap::T32(iat.pe()),
65 Wrap::T64(iat) => Wrap::T64(iat.pe()),
66 }
67 }
68 #[inline]
70 pub fn image(&self) -> Wrap<&'a [u32], &'a [u64]> {
71 match self {
72 Wrap::T32(iat) => Wrap::T32(iat.image()),
73 Wrap::T64(iat) => Wrap::T64(iat.image()),
74 }
75 }
76 #[inline]
78 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>>)>> {
79 match self {
80 Wrap::T32(iat) => Wrap::T32(iat.iter()),
81 Wrap::T64(iat) => Wrap::T64(iat.iter()),
82 }
83 }
84}
85
86impl<'a, Pe32: pe32::Pe<'a>, Pe64: pe64::Pe<'a>> Wrap<pe32::imports::Desc<'a, Pe32>, pe64::imports::Desc<'a, Pe64>> {
88 #[inline]
90 pub fn pe(&self) -> Wrap<Pe32, Pe64> {
91 match self {
92 Wrap::T32(desc) => Wrap::T32(desc.pe()),
93 Wrap::T64(desc) => Wrap::T64(desc.pe()),
94 }
95 }
96 #[inline]
98 pub fn image(&self) -> &'a image::IMAGE_IMPORT_DESCRIPTOR {
99 match self {
100 Wrap::T32(desc) => desc.image(),
101 Wrap::T64(desc) => desc.image(),
102 }
103 }
104 #[inline]
106 pub fn dll_name(&self) -> Result<&'a util::CStr> {
107 match self {
108 Wrap::T32(desc) => desc.dll_name(),
109 Wrap::T64(desc) => desc.dll_name(),
110 }
111 }
112 #[inline]
114 pub fn iat(&self) -> Result<Wrap<slice::Iter<'a, u32>, slice::Iter<'a, u64>>> {
115 match self {
116 Wrap::T32(desc) => Wrap::T32(desc.iat()).transpose(),
117 Wrap::T64(desc) => Wrap::T64(desc.iat()).transpose(),
118 }
119 }
120 #[inline]
122 pub fn int(&self) -> Result<impl Clone + Iterator<Item = Result<Import<'a>>>> {
123 match self {
124 Wrap::T32(desc) => Ok(Wrap::T32(desc.int()?).map(Wrap::into)),
125 Wrap::T64(desc) => Ok(Wrap::T64(desc.int()?).map(Wrap::into)),
126 }
127 }
128}