Skip to main content

OwnedProcess

Struct OwnedProcess 

Source
pub struct OwnedProcess(/* private fields */);
Available on crate feature inject-dll only.
Expand description

A struct representing a running process. This struct owns the underlying process handle (see also BorrowedProcess for a borrowed version).

§Note

The underlying handle has the following privileges:

  • PROCESS_CREATE_THREAD
  • PROCESS_QUERY_INFORMATION
  • PROCESS_VM_OPERATION
  • PROCESS_VM_WRITE
  • PROCESS_VM_READ

Implementations§

Source§

impl OwnedProcess

Source

pub fn from_pid(pid: u32) -> Result<OwnedProcess, Error>

Creates a new instance from the given pid.

Source

pub fn all() -> Vec<OwnedProcess>

Returns a list of all currently running processes.

Source

pub fn find_all_by_name(name: impl AsRef<str>) -> Vec<OwnedProcess>

Finds all processes whose name contains the given string.

Source

pub fn find_first_by_name(name: impl AsRef<str>) -> Option<OwnedProcess>

Finds the first process whose name contains the given string.

Source

pub fn from_child(child: Child) -> OwnedProcess

Creates a new instance from the given child process.

Source

pub unsafe fn borrowed_static(&self) -> BorrowedProcess<'static>

Returns a borrowed instance of this process that lives for 'static.

§Safety
  • This method is unsafe as the returned instance can outlive the owned instance, thus the caller must guarantee that the owned instance outlives the returned instance.
Source

pub fn try_clone(&self) -> Result<OwnedProcess, Error>

Creates a new owning Process instance for this process by duplicating the underlying handle.

Source

pub fn leak(self) -> BorrowedProcess<'static>

Leaks the underlying handle and return it as a non-owning BorrowedProcess instance.

Source

pub const fn kill_on_drop(self) -> ProcessKillGuard

Returns a ProcessKillGuard wrapping this process that will automatically kill this process when dropped.

Trait Implementations§

Source§

impl AsHandle for OwnedProcess

Source§

fn as_handle(&self) -> BorrowedHandle<'_>

Borrows the handle. Read more
Source§

impl AsRawHandle for OwnedProcess

Source§

fn as_raw_handle(&self) -> *mut c_void

Extracts the raw handle. Read more
Source§

impl Debug for OwnedProcess

Source§

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

Formats the value using the given formatter. Read more
Source§

impl From<Child> for OwnedProcess

Source§

fn from(child: Child) -> OwnedProcess

Converts to this type from the input type.
Source§

impl FromRawHandle for OwnedProcess

Source§

unsafe fn from_raw_handle(handle: *mut c_void) -> OwnedProcess

Constructs a new I/O object from the specified raw handle. Read more
Source§

impl Hash for OwnedProcess

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl IntoRawHandle for OwnedProcess

Source§

fn into_raw_handle(self) -> *mut c_void

Consumes this object, returning the raw underlying handle. Read more
Source§

impl PartialEq<BorrowedProcess<'_>> for OwnedProcess

Source§

fn eq(&self, other: &BorrowedProcess<'_>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for OwnedProcess

Source§

fn eq(&self, other: &OwnedProcess) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Process for OwnedProcess

Source§

type Handle = OwnedHandle

The underlying handle type.
Source§

fn borrowed(&self) -> BorrowedProcess<'_>

Returns a borrowed instance of this process.
Source§

fn try_clone(&self) -> Result<OwnedProcess, Error>

Tries to clone this process into a new instance.
Source§

fn into_handle(self) -> <OwnedProcess as Process>::Handle

Returns the underlying process handle.
Source§

unsafe fn from_handle_unchecked( handle: <OwnedProcess as Process>::Handle, ) -> OwnedProcess

Creates a new instance from the given handle. Read more
Source§

fn current_handle() -> <OwnedProcess as Process>::Handle

Returns the pseudo handle representing the current process.
Source§

fn find_module_by_name( &self, module_name: impl AsRef<Path>, ) -> Result<Option<ProcessModule<OwnedProcess>>, Error>

Searches the modules in this process for one with the given name. The comparison of names is case-insensitive. If the extension is omitted, the default library extension .dll is appended. Read more
Source§

fn find_module_by_path( &self, module_path: impl AsRef<Path>, ) -> Result<Option<ProcessModule<OwnedProcess>>, Error>

Searches the modules in this process for one with the given path. The comparison of paths is case-insensitive. If the extension is omitted, the default library extension .dll is appended. Read more
Source§

fn wait_for_module_by_name( &self, module_name: impl AsRef<Path>, timeout: Duration, ) -> Result<Option<ProcessModule<OwnedProcess>>, Error>

Searches the modules in this process for one with the given name, repeatedly until a matching module is found or the given timeout elapses. The comparison of names is case-insensitive. If the extension is omitted, the default library extension .dll is appended.
Source§

fn wait_for_module_by_path( &self, module_path: impl AsRef<Path>, timeout: Duration, ) -> Result<Option<ProcessModule<OwnedProcess>>, Error>

Searches the modules in this process for one with the given path, repeatedly until a matching module is found or the given timeout elapses. The comparison of paths is case-insensitive. If the extension is omitted, the default library extension .dll is appended.
Source§

fn raw_current_handle() -> *mut c_void

Returns the raw pseudo handle representing the current process.
Source§

fn current() -> Self
where Self: Sized,

Returns an instance representing the current process.
Source§

fn is_current(&self) -> bool

Returns whether this instance represents the current process.
Source§

fn is_alive(&self) -> bool

Returns whether this process is still alive and running. Read more
Source§

fn pid(&self) -> Result<NonZero<u32>, Error>

Returns the id of this process.
Source§

fn runs_under_wow64(&self) -> Result<bool, Error>

Returns whether this process is running under WOW64. This is the case for 32-bit programs running on a 64-bit platform. Read more
Source§

fn is_x64(&self) -> Result<bool, Error>

Returns whether this process is a 64-bit process.
Source§

fn is_x86(&self) -> Result<bool, Error>

Returns whether this process is a 32-bit process.
Source§

fn path(&self) -> Result<PathBuf, Error>

Returns the executable path of this process.
Source§

fn base_name(&self) -> Result<OsString, Error>

Returns the file name of the executable of this process.
Source§

fn kill(&self) -> Result<(), Error>

Terminates this process with exit code 1.
Source§

fn kill_with_exit_code(&self, exit_code: u32) -> Result<(), Error>

Terminates this process with the given exit code.
Source§

fn run_remote_thread<T>( &self, remote_fn: extern "system" fn(*mut T) -> u32, parameter: *mut T, ) -> Result<u32, Error>

Starts a new thread in this process with the given entry point and argument, and waits for it to finish, returning the exit code.
Source§

fn start_remote_thread<T>( &self, remote_fn: unsafe extern "system" fn(*mut T) -> u32, parameter: *mut T, ) -> Result<OwnedHandle, Error>

Starts a new thread in this process with the given entry point and argument and returns the thread handle.
Source§

fn modules(&self) -> Result<Vec<ProcessModule<Self>>, Error>
where Self: Sized,

Returns a snapshot of all modules currently loaded in this process. Read more
Source§

impl TryFrom<BorrowedProcess<'_>> for OwnedProcess

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from( process: BorrowedProcess<'_>, ) -> Result<OwnedProcess, <OwnedProcess as TryFrom<BorrowedProcess<'_>>>::Error>

Performs the conversion.
Source§

impl Eq for OwnedProcess

Source§

impl Send for OwnedProcess

Source§

impl Sync for OwnedProcess

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> DropFlavorWrapper<T> for T

Source§

type Flavor = MayDrop

The DropFlavor that wraps T into Self
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more