Struct ElfPatcher

Source
pub struct ElfPatcher<F> { /* private fields */ }
Expand description

ELF patcher.

Supports modifying the interpreter and RPATH/RUNPATH.

Implementations§

Source§

impl<F: ElfRead + ElfWrite + ElfSeek> ElfPatcher<F>

Source

pub fn new(elf: Elf, file: F) -> Self

Create new patcher from Elf and file.

The file should be open for writing.

Source

pub fn set_page_size(&mut self, value: u64)

Change page size.

Page size is used during validation and to allocate space for new sections and segments.

Source

pub fn elf(&self) -> &Elf

Get the current ELF.

Source

pub fn into_inner(self) -> (Elf, F)

Convert into underlying reperesentation.

Source

pub fn finish(self) -> Result<F, Error>

Finish and write the current ELF to the file.

Before writing this method generates new program header, new section header and validates them.

Source

pub fn read_interpreter(&mut self) -> Result<Option<CString>, Error>

Get the interpreter.

Source

pub fn remove_interpreter(&mut self) -> Result<(), Error>

Remove the interpreter.

Removes all .interp sections and INTERP segments.

Source

pub fn set_interpreter(&mut self, interpreter: &CStr) -> Result<(), Error>

Set the interpreter.

Adds or modifies .interp section and INTERP segment.

Source

pub fn remove_dynamic_tag(&mut self, tag: DynamicTag) -> Result<(), Error>

Remove all entries for the specified dynamic tag from the dynamic table.

Source

pub fn read_dynamic_table(&mut self) -> Result<Option<DynamicTable>, Error>

Read dynamic table.

Source

pub fn read_dynamic_string_table( &mut self, ) -> Result<Option<StringTable>, Error>

Read dynamic string table.

Source

pub fn set_library_search_path<'a>( &mut self, entry_kind: DynamicTag, value: impl Into<DynamicValue<'a>>, ) -> Result<(), Error>

Set the value under the specified dynamic tag in the dynamic table.

Does nothing if the table is not present in the file.

Source

pub fn get_section_names(&mut self) -> Result<&StringTable, Error>

Get string table that contains section names.

Source

pub fn read_section(&mut self, name: &CStr) -> Result<Option<Vec<u8>>, Error>

Read section that has specified name.

Auto Trait Implementations§

§

impl<F> Freeze for ElfPatcher<F>
where F: Freeze,

§

impl<F> RefUnwindSafe for ElfPatcher<F>
where F: RefUnwindSafe,

§

impl<F> Send for ElfPatcher<F>
where F: Send,

§

impl<F> Sync for ElfPatcher<F>
where F: Sync,

§

impl<F> Unpin for ElfPatcher<F>
where F: Unpin,

§

impl<F> UnwindSafe for ElfPatcher<F>
where F: UnwindSafe,

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> 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, 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.