Skip to content

Commit

Permalink
Add process.get_module_path
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKnauth committed Oct 31, 2023
1 parent 1acef2e commit 66eb7cd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/runtime/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,23 @@ impl Process {
}
}

/// Gets the path of the given module in the file system.
#[cfg(feature = "alloc")]
#[inline]
pub fn get_module_path(&self, name: &str) -> Result<alloc::string::String, Error> {
unsafe {
let mut len = 0;
sys::process_get_module_path(self.0, name.as_ptr(), name.len(), core::ptr::null_mut(), &mut len);
let mut buf = alloc::vec::Vec::with_capacity(len);
let success = sys::process_get_module_path(self.0, name.as_ptr(), name.len(), buf.as_mut_ptr(), &mut len);
if !success {
return Err(Error {});
}
buf.set_len(len);
Ok(alloc::string::String::from_utf8_unchecked(buf))
}
}

/// Gets the address and size of a module in the process.
#[inline]
pub fn get_module_range(&self, name: &str) -> Result<(Address, u64), Error> {
Expand Down
9 changes: 9 additions & 0 deletions src/runtime/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ extern "C" {
#[cfg(feature = "alloc")]
pub fn process_get_path(process: Process, buf_ptr: *mut u8, buf_len_ptr: *mut usize) -> bool;

#[cfg(feature = "alloc")]
pub fn process_get_module_path(
process: Process,
name_ptr: *const u8,
name_len: usize,
buf_ptr: *mut u8,
buf_len_ptr: *mut usize
) -> bool;

/// Gets the number of memory ranges in a given process.
pub fn process_get_memory_range_count(process: Process) -> Option<NonZeroU64>;
/// Gets the start address of a memory range by its index.
Expand Down

0 comments on commit 66eb7cd

Please sign in to comment.