#[repr(C)]pub enum AnyImage<'a> {
Elf(ElfImage<'a>),
Pe(Box<PeImage>),
}Expand description
A PE or ELF image, as detected by AnyImage::load.
Variants§
Implementations§
Source§impl<'a> AnyImage<'a>
impl<'a> AnyImage<'a>
Sourcepub fn load(data: &'a [u8]) -> Result<AnyImage<'a>, PewterError>
pub fn load(data: &'a [u8]) -> Result<AnyImage<'a>, PewterError>
Parses a PE or ELF image, detecting which it is.
Sourcepub fn as_elf_mut(&mut self) -> Option<&mut ElfImage<'a>>
pub fn as_elf_mut(&mut self) -> Option<&mut ElfImage<'a>>
The ELF image, mutably, if this is one.
Sourcepub fn as_pe_mut(&mut self) -> Option<&mut PeImage>
pub fn as_pe_mut(&mut self) -> Option<&mut PeImage>
The PE image, mutably, if this is one — edit it (via
PeImage::file_mut) before write_file.
Sourcepub fn forwarding_proxy(
&self,
config: &ProxyConfig<'_>,
) -> Result<Vec<u8>, PewterError>
pub fn forwarding_proxy( &self, config: &ProxyConfig<'_>, ) -> Result<Vec<u8>, PewterError>
Build a forwarding proxy (PE .dll or ELF .so, matching this image) and
return its bytes. Forwards to the format-specific implementation. See
ProxyConfig.
Sourcepub fn add_section(
&mut self,
name: &str,
data: &[u8],
perms: SectionPermissions,
) -> Result<u64, PewterError>
pub fn add_section( &mut self, name: &str, data: &[u8], perms: SectionPermissions, ) -> Result<u64, PewterError>
Append a new section with the given data and access, returning its virtual
address — for either format. Maps to PE section characteristics or ELF
ALLOC flags; the section is readable and loaded. For finer control use
the typed as_pe_mut / as_elf_mut.
Sourcepub fn write_at_vaddr(
&mut self,
vaddr: u64,
data: &[u8],
) -> Result<(), PewterError>
pub fn write_at_vaddr( &mut self, vaddr: u64, data: &[u8], ) -> Result<(), PewterError>
Overwrite the bytes at virtual address vaddr, for either format — the
format-agnostic way to patch a loaded image before write_file.
Patches in place; adding a section is add_section.
Fails if vaddr is unmapped or the write would overflow the file.
Sourcepub fn write_file(&mut self) -> Result<Vec<u8>, PewterError>
pub fn write_file(&mut self) -> Result<Vec<u8>, PewterError>
Serialize the image back to bytes, reflecting any edits made through
write_at_vaddr, add_section
or the typed as_pe_mut / as_elf_mut.
PE re-serializes (recomputing the header sizes, section offsets and
checksum); ELF applies the recorded patches and appends any new sections
(resizing an existing ELF section in place isn’t supported).
Trait Implementations§
Source§impl LoadedImage for AnyImage<'_>
impl LoadedImage for AnyImage<'_>
Source§fn bytes(&self, vaddr: u64, len: usize) -> Option<&[u8]>
fn bytes(&self, vaddr: u64, len: usize) -> Option<&[u8]>
len bytes at virtual address vaddr, or None if unmapped.Source§fn pointer(&self, vaddr: u64) -> Option<u64>
fn pointer(&self, vaddr: u64) -> Option<u64>
vaddr, after relocation.Source§fn c_str(&self, vaddr: u64) -> Option<String>
fn c_str(&self, vaddr: u64) -> Option<String>
vaddr, decoded as lossy UTF-8, or None
if vaddr is unmapped. Reads to a NUL byte or the end of the mapping.Source§fn data_segments(&self) -> Vec<(u64, u64)>
fn data_segments(&self) -> Vec<(u64, u64)>
Source§fn exports(&self) -> Result<Vec<Export>, PewterError>
fn exports(&self) -> Result<Vec<Export>, PewterError>
Source§fn machine(&self) -> Option<ImageFileMachine>
fn machine(&self) -> Option<ImageFileMachine>
None if PE has no equivalent.fn pointer_size(&self) -> u64
fn u32(&self, vaddr: u64) -> Option<u32>
fn u8(&self, vaddr: u64) -> Option<u8>
Source§fn pointer_at(&self, base: u64, index: u64) -> Option<u64>
fn pointer_at(&self, base: u64, index: u64) -> Option<u64>
indexth pointer of an array at base, i.e. the pointer at
base + index * pointer_size(). Saves spelling out the stride when
walking a table of pointers.Source§fn pointers(&self, vaddr: u64, count: u64) -> Option<Vec<u64>>
fn pointers(&self, vaddr: u64, count: u64) -> Option<Vec<u64>>
count consecutive pointers starting at vaddr, or None if any is
unmapped.Source§fn pointer_slots(&self, segment: (u64, u64)) -> impl Iterator<Item = u64>
fn pointer_slots(&self, segment: (u64, u64)) -> impl Iterator<Item = u64>
segment (a data_segments
range), as the virtual addresses start, start + pointer_size(), … that
each still hold a full pointer. Useful for scanning a segment for a structure.