-
-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
frida: clarify runtime lifetimes #160
Draft
ajwerner
wants to merge
1
commit into
frida:main
Choose a base branch
from
ajwerner:better-apis
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
|
||
use frida_sys::_FridaDeviceManager; | ||
use std::ffi::CString; | ||
use std::marker::PhantomData; | ||
|
||
use crate::device::{self, Device}; | ||
use crate::DeviceType; | ||
|
@@ -15,29 +14,24 @@ use crate::Frida; | |
use crate::Result; | ||
|
||
/// Platform-independent device manager abstraction access. | ||
pub struct DeviceManager<'a> { | ||
#[derive(Clone)] | ||
pub struct DeviceManager { | ||
frida: Frida, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we call this |
||
manager_ptr: *mut _FridaDeviceManager, | ||
phantom: PhantomData<&'a _FridaDeviceManager>, | ||
} | ||
|
||
impl<'a> DeviceManager<'a> { | ||
impl DeviceManager { | ||
/// Obtain an DeviceManager handle, ensuring that the runtime is properly initialized. This may be called as many | ||
/// times as needed, and results in a no-op if the DeviceManager is already initialized. | ||
pub fn obtain<'b>(_frida: &'b Frida) -> Self | ||
where | ||
'b: 'a, | ||
{ | ||
pub fn obtain(frida: &Frida) -> Self { | ||
DeviceManager { | ||
manager_ptr: unsafe { frida_sys::frida_device_manager_new() }, | ||
phantom: PhantomData, | ||
frida: frida.clone(), | ||
} | ||
} | ||
|
||
/// Returns all devices. | ||
pub fn enumerate_all_devices<'b>(&'a self) -> Vec<Device<'b>> | ||
where | ||
'a: 'b, | ||
{ | ||
pub fn enumerate_all_devices(&self) -> Vec<Device> { | ||
let mut devices = Vec::new(); | ||
let mut error: *mut frida_sys::GError = std::ptr::null_mut(); | ||
|
||
|
@@ -54,8 +48,9 @@ impl<'a> DeviceManager<'a> { | |
devices.reserve(num_devices as usize); | ||
|
||
for i in 0..num_devices { | ||
let device = | ||
Device::from_raw(unsafe { frida_sys::frida_device_list_get(devices_ptr, i) }); | ||
let device = Device::from_raw(self.frida.clone(), unsafe { | ||
frida_sys::frida_device_list_get(devices_ptr, i) | ||
}); | ||
devices.push(device); | ||
} | ||
} | ||
|
@@ -65,7 +60,7 @@ impl<'a> DeviceManager<'a> { | |
} | ||
|
||
/// Returns the device of the specified type. | ||
pub fn get_device_by_type(&'a self, r#type: DeviceType) -> Result<Device<'a>> { | ||
pub fn get_device_by_type(&self, r#type: DeviceType) -> Result<Device> { | ||
let mut error: *mut frida_sys::GError = std::ptr::null_mut(); | ||
|
||
let device_ptr = unsafe { | ||
|
@@ -82,11 +77,11 @@ impl<'a> DeviceManager<'a> { | |
return Err(Error::DeviceLookupFailed); | ||
} | ||
|
||
return Ok(Device::from_raw(device_ptr)); | ||
return Ok(Device::from_raw(self.frida.clone(), device_ptr)); | ||
} | ||
|
||
/// Returns the remote device with the specified host. | ||
pub fn get_remote_device(&'a self, host: &str) -> Result<Device<'a>> { | ||
pub fn get_remote_device(self, host: &str) -> Result<Device> { | ||
let mut error: *mut frida_sys::GError = std::ptr::null_mut(); | ||
let host_cstring = CString::new(host).map_err(|_| Error::CStringFailed)?; | ||
|
||
|
@@ -104,11 +99,11 @@ impl<'a> DeviceManager<'a> { | |
return Err(Error::DeviceLookupFailed); | ||
} | ||
|
||
return Ok(Device::from_raw(device_ptr)); | ||
return Ok(Device::from_raw(self.frida.clone(), device_ptr)); | ||
} | ||
|
||
/// Returns the local device. | ||
pub fn get_local_device(&'a self) -> Result<Device<'a>> { | ||
pub fn get_local_device(&self) -> Result<Device> { | ||
self.get_device_by_type(device::DeviceType::Local) | ||
} | ||
|
||
|
@@ -123,7 +118,7 @@ impl<'a> DeviceManager<'a> { | |
/// let device = device_manager.get_device_by_id(id).unwrap(); | ||
/// assert_eq!(device.get_id(), id); | ||
/// | ||
pub fn get_device_by_id(&'a self, device_id: &str) -> Result<Device<'a>> { | ||
pub fn get_device_by_id(&self, device_id: &str) -> Result<Device> { | ||
let mut error: *mut frida_sys::GError = std::ptr::null_mut(); | ||
let cstring = CString::new(device_id).unwrap(); | ||
|
||
|
@@ -141,11 +136,11 @@ impl<'a> DeviceManager<'a> { | |
return Err(Error::DeviceLookupFailed); | ||
} | ||
|
||
return Ok(Device::from_raw(device_ptr)); | ||
return Ok(Device::from_raw(self.frida.clone(), device_ptr)); | ||
} | ||
} | ||
|
||
impl<'a> Drop for DeviceManager<'a> { | ||
impl Drop for DeviceManager { | ||
fn drop(&mut self) { | ||
unsafe { frida_sys::frida_unref(self.manager_ptr as _) } | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this not call the
ptr()
function above?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for the rest of the
self.0.ptr()
calls...