usecrate::endian::{LittleEndian as LE, U16}; usecrate::pe; usecrate::read::{Bytes, Error, ReadError, Result};
/// An iterator over the relocation blocks in the `.reloc` section of a PE file. /// /// Returned by [`DataDirectories::relocation_blocks`](super::DataDirectories::relocation_blocks). #[derive(Debug, Default, Clone, Copy)] pubstruct RelocationBlockIterator<'data> {
data: Bytes<'data>,
}
impl<'data> RelocationBlockIterator<'data> { /// Construct a new iterator from the data of the `.reloc` section. pubfn new(data: &'data [u8]) -> Self {
RelocationBlockIterator { data: Bytes(data) }
}
/// Read the next relocation page. pubfn next(&mutself) -> Result<Option<RelocationIterator<'data>>> { ifself.data.is_empty() { return Ok(None);
}
let result = self.parse().map(Some); if result.is_err() { self.data = Bytes(&[]);
}
result
}
fn parse(&mutself) -> Result<RelocationIterator<'data>> { let header = self
.data
.read::<pe::ImageBaseRelocation>()
.read_error("Invalid PE reloc section size")?; let virtual_address = header.virtual_address.get(LE); let size = header.size_of_block.get(LE); if size <= 8 || size & 3 != 0 { return Err(Error("Invalid PE reloc block size"));
} let count = (size - 8) / 2; let relocs = self
.data
.read_slice::<U16<LE>>(count as usize)
.read_error("Invalid PE reloc block size")?
.iter();
Ok(RelocationIterator {
virtual_address,
size,
relocs,
})
}
}
impl<'data> Iterator for RelocationBlockIterator<'data> { type Item = Result<RelocationIterator<'data>>;
/// An iterator of the relocations in a block in the `.reloc` section of a PE file. #[derive(Debug, Clone)] pubstruct RelocationIterator<'data> {
virtual_address: u32,
size: u32,
relocs: slice::Iter<'data, U16<LE>>,
}
impl<'data> RelocationIterator<'data> { /// Return the virtual address of the page that this block of relocations applies to. pubfn virtual_address(&self) -> u32 { self.virtual_address
}
/// Return the size in bytes of this block of relocations. pubfn size(&self) -> u32 { self.size
}
}
impl<'data> Iterator for RelocationIterator<'data> { type Item = Relocation;
/// A relocation in the `.reloc` section of a PE file. #[derive(Debug, Default, Clone, Copy)] pubstruct Relocation { /// The virtual address of the relocation. pub virtual_address: u32, /// One of the `pe::IMAGE_REL_BASED_*` constants. pub typ: u16,
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet am 2026-06-18)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.