Struct object::write::pe::Writer [−][src]
pub struct Writer<'a> { /* fields omitted */ }
Expand description
A helper for writing PE files.
Writing uses a two phase approach. The first phase reserves file ranges and virtual address ranges for everything in the order that they will be written.
The second phase writes everything out in order. Thus the caller must ensure writing is in the same order that file ranges were reserved.
Implementations
Create a new Writer
.
Return the current virtual address size that has been reserved.
This is only valid after section headers have been reserved.
Reserve a virtual address range with the given size.
The reserved length will be increased to match the section alignment.
Returns the aligned offset of the start of the range.
Reserve up to the given virtual address.
The reserved length will be increased to match the section alignment.
Return the current file length that has been reserved.
Reserve a file range with the given size and starting alignment.
Returns the aligned offset of the start of the range.
Reserve a file range with the given size and using the file alignment.
Returns the aligned offset of the start of the range.
Reserve alignment padding bytes.
Write alignment padding bytes.
Write padding up to the next multiple of file alignment.
Reserve the file range up to the given file offset.
Reserve the range for the DOS header.
This must be at the start of the file.
When writing, you may use write_custom_dos_header
or write_empty_dos_header
.
Write a custom DOS header.
This must be at the start of the file.
Write the DOS header for a file without a stub.
This must be at the start of the file.
Uses default values for all fields.
Reserve a fixed DOS header and stub.
Use reserve_dos_header
and reserve
if you need a custom stub.
Write a fixed DOS header and stub.
Use write_custom_dos_header
and write
if you need a custom stub.
Return the offset of the NT headers, if reserved.
Reserve the range for the NT headers.
Set the virtual address and size of a data directory.
Write the NT headers.
Reserve the section headers.
The number of reserved section headers must be the same as the number of sections that are later reserved.
Write the section headers.
This uses information that was recorded when the sections were reserved.
pub fn reserve_section(
&mut self,
name: [u8; 8],
characteristics: u32,
virtual_size: u32,
data_size: u32
) -> SectionRange
pub fn reserve_section(
&mut self,
name: [u8; 8],
characteristics: u32,
virtual_size: u32,
data_size: u32
) -> SectionRange
Reserve a section.
Returns the file range and virtual address range that are reserved for the section.
Reserve a .text
section.
Contains executable code.
Reserve a .data
section.
Contains initialized data.
May also contain uninitialized data if virtual_size
is greater than data_size
.
Reserve a .rdata
section.
Contains read-only initialized data.
Reserve a .bss
section.
Contains uninitialized data.
Reserve an .idata
section.
Contains import tables. Note that it is permissible to store import tables in a different section.
This also sets the pe::IMAGE_DIRECTORY_ENTRY_IMPORT
data directory.
Reserve an .edata
section.
Contains export tables.
This also sets the pe::IMAGE_DIRECTORY_ENTRY_EXPORT
data directory.
Reserve a .pdata
section.
Contains exception information.
This also sets the pe::IMAGE_DIRECTORY_ENTRY_EXCEPTION
data directory.
Reserve a .xdata
section.
Contains exception information.
Reserve a .rsrc
section.
Contains the resource directory.
This also sets the pe::IMAGE_DIRECTORY_ENTRY_RESOURCE
data directory.
Add a base relocation.
typ
must be one of the IMAGE_REL_BASED_*
constants.
Return true if a base relocation has been added.
Reserve a .reloc
section.
This contains the base relocations that were added with add_reloc
.
This also sets the pe::IMAGE_DIRECTORY_ENTRY_BASERELOC
data directory.
Write a .reloc
section.
This contains the base relocations that were added with add_reloc
.
Reserve the certificate table.
This also sets the pe::IMAGE_DIRECTORY_ENTRY_SECURITY
data directory.
Write the certificate table.