Skip to content

Commit

Permalink
Fix rangedetails for real (#122)
Browse files Browse the repository at this point in the history
* rangedetails: don't return dangling pointers

* size is a usize

* Actually build the RangeDetails at the right time

* Use lifetime parameter
  • Loading branch information
s1341 authored Jan 4, 2024
1 parent 89ce25f commit 92cde4e
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions frida-gum/src/range_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ impl<'a> FileMapping<'a> {
}
}

struct SaveRangeDetailsByAddressContext {
struct SaveRangeDetailsByAddressContext<'a> {
address: u64,
details: *const gum_sys::GumRangeDetails,
details: Option<RangeDetails<'a>>,
}

unsafe extern "C" fn save_range_details_by_address(
Expand All @@ -94,7 +94,7 @@ unsafe extern "C" fn save_range_details_by_address(
let start = (*range).base_address as u64;
let end = start + (*range).size as u64;
if start <= context.address && context.address < end {
context.details = details;
context.details = Some(RangeDetails::from_raw(details));
return 0;
}

Expand Down Expand Up @@ -137,7 +137,7 @@ impl<'a> RangeDetails<'a> {
pub fn with_address(address: u64) -> Option<RangeDetails<'a>> {
let mut context = SaveRangeDetailsByAddressContext {
address,
details: core::ptr::null_mut(),
details: None,
};
unsafe {
gum_sys::gum_process_enumerate_ranges(
Expand All @@ -147,11 +147,7 @@ impl<'a> RangeDetails<'a> {
);
}

if !context.details.is_null() {
Some(RangeDetails::from_raw(context.details))
} else {
None
}
context.details
}

/// Enumerate all ranges which match the given [`PageProtection`], calling the callback
Expand Down

0 comments on commit 92cde4e

Please sign in to comment.