Skip to main content

OptionalHeader

Struct OptionalHeader 

Source
pub struct OptionalHeader {
Show 31 fields pub magic: u16, pub major_linker_version: u8, pub minor_linker_version: u8, pub size_of_code: u32, pub size_of_initialized_data: u32, pub size_of_uninitialized_data: u32, pub address_of_entry_point: u32, pub base_of_code: u32, pub base_of_data: Option<u32>, pub image_base: u64, pub section_alignment: u32, pub file_alignment: u32, pub major_operating_system_version: u16, pub minor_operating_system_version: u16, pub major_image_version: u16, pub minor_image_version: u16, pub major_subsystem_version: u16, pub minor_subsystem_version: u16, pub win32_version_value: u32, pub size_of_image: u32, pub size_of_headers: u32, pub checksum: u32, pub subsystem: SubsystemType, pub dll_characteristics: u16, pub size_of_stack_reserve: u64, pub size_of_stack_commit: u64, pub size_of_heap_reserve: u64, pub size_of_heap_commit: u64, pub loader_flags: u32, pub number_of_rva_and_sizes: u32, pub data_directories: Vec<DataDirectory>,
}
Expand description

可选头结构

包含 PE 文件的加载和运行时信息,如入口点地址、内存布局、 版本信息等。这个结构对于 Windows 加载器正确加载和执行程序至关重要。

Fields§

§magic: u16

魔数,标识 PE32 或 PE32+ 格式

§major_linker_version: u8

链接器的主版本号

§minor_linker_version: u8

链接器的次版本号

§size_of_code: u32

代码节的总大小(以字节为单位)

§size_of_initialized_data: u32

已初始化数据的总大小

§size_of_uninitialized_data: u32

未初始化数据的总大小

§address_of_entry_point: u32

程序入口点的 RVA(相对虚拟地址)

§base_of_code: u32

代码节的起始 RVA

§base_of_data: Option<u32>

数据节的起始 RVA,仅 PE32 格式有效

§image_base: u64

映像的首选加载地址

§section_alignment: u32

节在内存中的对齐粒度

§file_alignment: u32

节在文件中的对齐粒度

§major_operating_system_version: u16

所需操作系统的主版本号

§minor_operating_system_version: u16

所需操作系统的次版本号

§major_image_version: u16

映像的主版本号

§minor_image_version: u16

映像的次版本号

§major_subsystem_version: u16

子系统的主版本号

§minor_subsystem_version: u16

子系统的次版本号

§win32_version_value: u32

保留字段,必须为 0

§size_of_image: u32

映像的总大小,包括所有头文件和节

§size_of_headers: u32

所有头文件的总大小

§checksum: u32

映像的校验和,用于内核模式和系统 DLL

§subsystem: SubsystemType

子系统类型,定义程序运行环境

§dll_characteristics: u16

DLL 特征标志,描述 DLL 的各种属性

§size_of_stack_reserve: u64

为线程栈保留的虚拟内存大小

§size_of_stack_commit: u64

为线程栈提交的虚拟内存大小

§size_of_heap_reserve: u64

为进程堆保留的虚拟内存大小

§size_of_heap_commit: u64

为进程堆提交的虚拟内存大小

§loader_flags: u32

保留字段,必须为 0

§number_of_rva_and_sizes: u32

数据目录表的条目数量

§data_directories: Vec<DataDirectory>

数据目录表,包含各种数据目录的信息

Implementations§

Source§

impl OptionalHeader

Source

pub fn new( entry_point: u32, image_base: u64, size_of_code: u32, size_of_headers: u32, size_of_image: u32, subsystem: SubsystemType, ) -> Self

创建一个标准的可选头,适用于 .NET 程序

Source

pub fn new_for_architecture( architecture: &Architecture, entry_point: u32, image_base: u64, size_of_code: u32, size_of_headers: u32, size_of_image: u32, subsystem: SubsystemType, ) -> Self

根据架构创建可选头

Source§

impl OptionalHeader

Source

pub fn read<R: Read>(reader: R) -> Result<Self, GaiaError>

从 ExeReader 读取可选头

Trait Implementations§

Source§

impl Clone for OptionalHeader

Source§

fn clone(&self) -> OptionalHeader

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OptionalHeader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for OptionalHeader

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for OptionalHeader

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,