From 2eea427f35ac57c80ec66f5345500d335a621dc0 Mon Sep 17 00:00:00 2001 From: Xoffio <38369407+Xoffio@users.noreply.github.com> Date: Thu, 5 Sep 2024 05:44:27 +0000 Subject: [PATCH] get_local_device and example added (#146) --- Cargo.toml | 1 + examples/core/get_processes/Cargo.toml | 10 ++++++++++ examples/core/get_processes/src/main.rs | 16 ++++++++++++++++ frida/src/device_manager.rs | 7 ++++++- 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 examples/core/get_processes/Cargo.toml create mode 100644 examples/core/get_processes/src/main.rs diff --git a/Cargo.toml b/Cargo.toml index fb154282..4b3b5234 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ members = [ "examples/core/hello", "examples/core/usb_device", "examples/core/console_log", + "examples/core/get_processes", ] # We miss our linux_no_std example from the default members since `cargo check` # and `cargo test` both attempt to link the `std` library into it in error. diff --git a/examples/core/get_processes/Cargo.toml b/examples/core/get_processes/Cargo.toml new file mode 100644 index 00000000..9a5ce3d0 --- /dev/null +++ b/examples/core/get_processes/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "get_processes" +version = "0.1.0" +edition = "2021" +authors = ["Ricardo J Marques Montilla / Xoffio"] + +[dependencies] +frida = { path = "../../../frida" } +frida-sys = { path = "../../../frida-sys" } +lazy_static = "1.5.0" diff --git a/examples/core/get_processes/src/main.rs b/examples/core/get_processes/src/main.rs new file mode 100644 index 00000000..5a7076de --- /dev/null +++ b/examples/core/get_processes/src/main.rs @@ -0,0 +1,16 @@ +use frida::Frida; +use lazy_static::lazy_static; + +lazy_static! { + static ref FRIDA: Frida = unsafe { Frida::obtain() }; +} + +fn main() { + let device_manager = frida::DeviceManager::obtain(&FRIDA); + let local_device = device_manager.get_local_device().unwrap(); + let processes = local_device.enumerate_processes(); + + for process in processes { + println!("{} {:?}", process.get_name(), process.get_pid()); + } +} diff --git a/frida/src/device_manager.rs b/frida/src/device_manager.rs index 94f47ea7..e57ab111 100644 --- a/frida/src/device_manager.rs +++ b/frida/src/device_manager.rs @@ -8,7 +8,7 @@ use frida_sys::_FridaDeviceManager; use std::ffi::CString; use std::marker::PhantomData; -use crate::device::Device; +use crate::device::{self, Device}; use crate::DeviceType; use crate::Error; use crate::Frida; @@ -107,6 +107,11 @@ impl<'a> DeviceManager<'a> { return Ok(Device::from_raw(device_ptr)); } + /// Returns the local device. + pub fn get_local_device(&'a self) -> Result> { + self.get_device_by_type(device::DeviceType::Local) + } + /// Returns the device with the specified id. /// /// # Example