Skip to content
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

Added Module enumerate_sections #178

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 53 additions & 1 deletion frida-gum/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ use {
core::ffi::c_void,
cstr_core::CString,
frida_gum_sys as gum_sys,
frida_gum_sys::{gboolean, gpointer, GumExportDetails, GumModuleDetails, GumSymbolDetails},
frida_gum_sys::{
gboolean, gpointer, GumExportDetails, GumModuleDetails, GumSectionDetails, GumSymbolDetails,
},
};

#[cfg(not(feature = "std"))]
Expand All @@ -41,6 +43,14 @@ pub struct SymbolDetails {
pub size: usize,
}

/// Module symbol details returned by [`Module::enumerate_sections`].
pub struct SectionDetails {
pub id: String,
pub name: String,
pub address: usize,
pub size: usize,
}

/// Module export details returned by [`Module::enumerate_exports`].
pub struct ExportDetails {
pub typ: u32,
Expand Down Expand Up @@ -270,4 +280,46 @@ impl<'a> Module<'a> {
}
result
}

/// Enumerates sections of module.
pub fn enumerate_sections(&self, module_name: &str) -> Vec<SectionDetails> {
let result: Vec<SectionDetails> = vec![];

unsafe extern "C" fn callback(
details: *const GumSectionDetails,
user_data: gpointer,
) -> gboolean {
let res = &mut *(user_data as *mut Vec<SectionDetails>);

let id: String = NativePointer((*details).id as *mut _)
.try_into()
.unwrap_or_default();
let name: String = NativePointer((*details).name as *mut _)
.try_into()
.unwrap_or_default();
let address = (*details).address as usize;
let size = (*details).size as usize;

let info = SectionDetails {
id,
name,
address,
size,
};
res.push(info);

1
}

let module_name = CString::new(module_name).unwrap();

unsafe {
frida_gum_sys::gum_module_enumerate_sections(
module_name.as_ptr().cast(),
Some(callback),
&result as *const _ as *mut c_void,
);
}
result
}
}
Loading