Struct Rewriter

Source
pub struct Rewriter<'data> { /* private fields */ }
Expand description

A rewriter for object and executable files.

This struct provides a way to read a file, modify it, and write it back.

Implementations§

Source§

impl<'data> Rewriter<'data>

Source

pub fn read(data: &'data [u8]) -> Result<Self>

Read a file and create a new rewriter.

Source

pub fn write<W: Write>(self, w: W) -> Result<()>

Write the file to an output stream.

Source

pub fn modify(&mut self, options: Options) -> Result<()>

Modify the file according to the given options.

Source

pub fn delete_symbols(&mut self, names: &HashSet<Vec<u8>>)

Delete symbols from the symbol table.

For ELF files, this deletes symbols from both the symbol table and the dynamic symbol table.

Source

pub fn rename_symbols(&mut self, names: &HashMap<Vec<u8>, Vec<u8>>)

Rename symbols in the symbol table.

For ELF files, this renames symbols in both the symbol table and the dynamic symbol table.

The names map is from old names to new names.

Source

pub fn delete_sections(&mut self, names: &HashSet<Vec<u8>>)

Delete sections from the file.

Source

pub fn rename_sections(&mut self, names: &HashMap<Vec<u8>, Vec<u8>>)

Rename sections in the file.

The names map is from old names to new names.

Source§

impl<'data> Rewriter<'data>

Source

pub fn elf_delete_symbols(&mut self, names: &HashSet<Vec<u8>>)

Delete symbols from the symbol table.

Source

pub fn elf_delete_dynamic_symbols(&mut self, names: &HashSet<Vec<u8>>)

Delete symbols from the dynamic symbol table.

Source

pub fn elf_rename_symbols(&mut self, names: &HashMap<Vec<u8>, Vec<u8>>)

Rename symbols in the symbol table.

The names map is from old names to new names.

Source

pub fn elf_rename_dynamic_symbols(&mut self, names: &HashMap<Vec<u8>, Vec<u8>>)

Rename symbols in the dynamic symbol table.

The names map is from old names to new names.

Source

pub fn elf_add_dynamic_debug(&mut self) -> Result<()>

Add a DT_DEBUG entry to the dynamic section.

Source

pub fn elf_runpath(&self) -> Option<&[u8]>

Find the first DT_RUNPATH or DT_RPATH entry in the dynamic section.

Source

pub fn elf_delete_runpath(&mut self) -> Result<()>

Delete any DT_RUNPATH or DT_RPATH entries in the dynamic section.

Source

pub fn elf_set_runpath(&mut self, runpath: Vec<u8>) -> Result<()>

Set the path for any DT_RUNPATH or DT_RPATH entry in the dynamic section.

Source

pub fn elf_add_runpath(&mut self, runpaths: &[Vec<u8>]) -> Result<()>

Add additional paths to any DT_RUNPATH or DT_RPATH entry in the dynamic section.

Source

pub fn elf_use_runpath(&mut self) -> Result<()>

Change any DT_RPATH entry in the dynamic section to DT_RUNPATH.

Source

pub fn elf_use_rpath(&mut self) -> Result<()>

Change any DT_RUNPATH entry in the dynamic section to DT_RPATH.

Source

pub fn elf_needed(&self) -> impl Iterator<Item = &[u8]>

Find the DT_NEEDED entries in the dynamic section.

Source

pub fn elf_delete_needed(&mut self, names: &HashSet<Vec<u8>>) -> Result<()>

Delete DT_NEEDED entries from the dynamic section.

Source

pub fn elf_replace_needed( &mut self, names: &HashMap<Vec<u8>, Vec<u8>>, ) -> Result<()>

Replace DT_NEEDED entries in the dynamic section.

Source

pub fn elf_add_needed(&mut self, names: &[Vec<u8>]) -> Result<()>

Add DT_NEEDED entries to the start of the dynamic section.

This does not add a DT_NEEDED entry if the library is already listed.

Source

pub fn elf_soname(&self) -> Option<&[u8]>

Find the DT_SONAME entry in the dynamic section.

Source

pub fn elf_set_soname(&mut self, soname: Vec<u8>) -> Result<()>

Set the DT_SONAME entry in the dynamic section.

Source

pub fn elf_interpreter(&self) -> Option<&[u8]>

Find the interpreter path in the PT_INTERP segment.

Source

pub fn elf_set_interpreter(&mut self, interpreter: Vec<u8>) -> Result<()>

Set the interpreter path in the PT_INTERP segment.

The null terminator is automatically added if needed.

Trait Implementations§

Source§

impl<'data> Debug for Rewriter<'data>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'data> Freeze for Rewriter<'data>

§

impl<'data> RefUnwindSafe for Rewriter<'data>

§

impl<'data> Send for Rewriter<'data>

§

impl<'data> Sync for Rewriter<'data>

§

impl<'data> Unpin for Rewriter<'data>

§

impl<'data> UnwindSafe for Rewriter<'data>

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.