Skip to main content

SectionTable

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 SIZE: usize = 40

Size of a section table entry in bytes (40 bytes per section).

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) -> Result<()>

Sets the section name.

PE section names are limited to 8 bytes per the PE specification. This method validates the name length before setting it.

§Arguments
  • name - New section name (must be 8 bytes or less)
§Errors

Returns an error if the name exceeds 8 bytes.

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

Writes this section header to the writer.

Each section header is 40 bytes and describes a section’s location in both the file and virtual memory, along with its characteristics (readable, writable, executable, etc.).

§Arguments
  • writer - The writer to output the section header 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, A> IntoAst<A> for T
where T: Into<A>, A: Ast,

Source§

fn into_ast(self, _a: &A) -> A

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.