Skip to content

Commit

Permalink
get_local_device and example added (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xoffio authored Sep 5, 2024
1 parent 117003b commit 2eea427
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions examples/core/get_processes/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
16 changes: 16 additions & 0 deletions examples/core/get_processes/src/main.rs
Original file line number Diff line number Diff line change
@@ -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());
}
}
7 changes: 6 additions & 1 deletion frida/src/device_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Device<'a>> {
self.get_device_by_type(device::DeviceType::Local)
}

/// Returns the device with the specified id.
///
/// # Example
Expand Down

0 comments on commit 2eea427

Please sign in to comment.