Struct SectionTable

pub struct SectionTable {
    pub name: String,
    pub virtual_size: u32,
    pub virtual_address: u32,
    pub size_of_raw_data: u32,
    pub pointer_to_raw_data: u32,
    pub pointer_to_relocations: u32,
    pub pointer_to_line_numbers: u32,
    pub number_of_relocations: u16,
    pub number_of_line_numbers: u16,
    pub characteristics: u32,
}
Expand description

Provides access to low-level file and memory parsing utilities.

The crate::Parser type is used for decoding CIL bytecode and metadata streams.

§Usage Examples

use dotscope::{Parser, assembly::decode_instruction};
let code = [0x2A]; // ret
let mut parser = Parser::new(&code);
let instr = decode_instruction(&mut parser, 0x1000)?;
assert_eq!(instr.mnemonic, "ret");

Owned section table entry.

Fields§

§name: String

Section name (up to 8 bytes)

§virtual_size: u32

Virtual size

§virtual_address: u32

Virtual address (RVA)

§size_of_raw_data: u32

Size of raw data

§pointer_to_raw_data: u32

Pointer to raw data

§pointer_to_relocations: u32

Pointer to relocations

§pointer_to_line_numbers: u32

Pointer to line numbers

§number_of_relocations: u16

Number of relocations

§number_of_line_numbers: u16

Number of line numbers

§characteristics: u32

Section characteristics

Implementations§

§

impl SectionTable

pub const HEADER_SIZE: usize = 40usize

Size of a section table header in bytes.

pub fn calculate_table_size(section_count: usize) -> u64

Calculates the total size required for a section table with the given number of sections.

§Arguments
  • section_count - Number of sections in the table
§Returns

Total size in bytes for the section table

pub fn from_layout_info( name: String, virtual_address: u32, virtual_size: u32, file_offset: u64, file_size: u64, characteristics: u32, ) -> Result<Self>

Creates a SectionTable from layout information.

This converts from the layout planning structures used during write operations back to the PE section table format.

§Arguments
  • name - Section name
  • virtual_address - RVA where section is mapped
  • virtual_size - Virtual size of section in memory
  • file_offset - File offset where section data is stored
  • file_size - Size of section data in file
  • characteristics - Section characteristics flags
§Returns

A new SectionTable instance

§Errors

Returns an error if the file offset or size exceed u32 range

pub fn update_virtual_location( &mut self, virtual_address: u32, virtual_size: u32, )

Updates the virtual address and size of this section.

§Arguments
  • virtual_address - New RVA where section is mapped
  • virtual_size - New virtual size of section in memory

pub fn update_file_location( &mut self, file_offset: u64, file_size: u64, ) -> Result<()>

Updates the file location and size of this section.

§Arguments
  • file_offset - New file offset where section data is stored
  • file_size - New size of section data in file
§Errors

Returns an error if the file offset or size exceed u32 range

pub fn update_characteristics(&mut self, characteristics: u32)

Updates the section characteristics flags.

§Arguments
  • characteristics - New section characteristics flags

pub fn set_name(&mut self, name: String)

Sets the section name.

§Arguments
  • name - New section name (will be truncated to 8 bytes if longer)

pub fn write_header_to<W: Write>(&self, writer: &mut W) -> Result<()>

Writes a section header as a standalone 40-byte header.

This method encodes the section information into the PE section table format and writes it to the provided writer. This serializes the current state of the section without making any modifications.

§Arguments
  • writer - Writer to output the header bytes to
§Errors

Returns an error if writing fails

Trait Implementations§

§

impl Clone for SectionTable

§

fn clone(&self) -> SectionTable

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
§

impl Debug for SectionTable

§

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

Formats the value using the given formatter. 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, 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.