pub struct TaskDumper { /* private fields */ }
Expand description

Similarly to PtraceDumper for Linux, this provides access to information for a task (MacOS process)

Implementations§

source§

impl TaskDumper

source

pub fn new(task: task_t) -> Self

Constructs a TaskDumper for the specified task

source

pub fn read_task_memory<T>( &self, address: u64, count: usize ) -> Result<Vec<T>, TaskDumpError>
where T: Sized + Clone,

Reads a block of memory from the task

§Errors

The syscall to read the task’s memory fails for some reason, eg bad address.

source

pub fn read_string( &self, addr: u64, expected_size: Option<usize> ) -> Result<Option<String>, TaskDumpError>

Reads a null terminated string starting at the specified address. This is a specialization of [read_task_memory] since strings can span VM regions.

If not specified, the string is capped at 8k which should never be close to being hit in normal scenarios, at least for “system” strings, which is all this interface is used to retrieve

§Errors

Fails if the address cannot be read for some reason, or the string is not utf-8.

source

pub fn get_vm_region(&self, addr: u64) -> Result<VMRegionInfo, TaskDumpError>

Retrives information on the virtual memory region the specified address is located within.

§Errors

The syscall to retrieve the VM region information fails for some reason, eg. a bad address.

source

pub fn read_thread_state(&self, tid: u32) -> Result<ThreadState, TaskDumpError>

Retrieves the state of the specified thread. The state is an architecture specific block of CPU context ie register state.

§Errors

The specified thread id is invalid, or the thread is in a task that is compiled for a different architecture than this local task.

source

pub fn task_info<T: TaskInfo>(&self) -> Result<T, TaskDumpError>

Reads the specified task information.

§Errors

The syscall to receive the task information failed for some reason, eg. the specified type and the flavor are mismatched and considered invalid.

source

pub fn thread_info<T: ThreadInfo>(&self, tid: u32) -> Result<T, TaskDumpError>

Reads the specified task information.

§Errors

The syscall to receive the task information failed for some reason, eg. the specified type and the flavor are mismatched and considered invalid, or the thread no longer exists

source

pub fn read_images( &self ) -> Result<(AllImagesInfo, Vec<ImageInfo>), TaskDumpError>

Retrieves all of the images loaded in the task.

Note that there may be multiple images with the same load address.

§Errors

The syscall to retrieve the location of the loaded images fails, or the syscall to read the loaded images from the process memory fails

source

pub fn read_executable_image(&self) -> Result<ImageInfo, TaskDumpError>

Retrieves the main executable image for the task.

Note that this method is currently only used for tests due to deficiencies in otool

§Errors

Any of the errors that apply to Self::read_images apply here, in addition to not being able to find the main executable image

source

pub fn read_load_commands( &self, img: &ImageInfo ) -> Result<LoadCommands, TaskDumpError>

Retrieves the load commands for the specified image

§Errors

We fail to read the image header for the specified image, the header we read is determined to be invalid, or we fail to read the block of memory containing the load commands themselves.

source

pub fn read_threads(&self) -> Result<&'static [u32], TaskDumpError>

Gets a list of all of the thread ids in the task

§Errors

The syscall to retrieve the list of threads fails

source

pub fn pid_for_task(&self) -> Result<i32, TaskDumpError>

Retrieves the PID for the task

§Errors

Presumably the only way this would fail would be if the task we are dumping disappears.

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

§

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

§

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.