Skip to content

Commit

Permalink
patch collect_modules bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ohchase committed Aug 11, 2024
1 parent f56a3e8 commit 0d5b7b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/dump_plt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use plt_rs::{collect_modules, DynamicLibrary, RelocationTable};

fn main() -> Result<()> {
let entries = collect_modules();
println!("collected modules");

for entry in entries.into_iter() {
println!("[{:?}] Addr: {:#X?}", entry.name(), entry.addr());
Expand Down
12 changes: 10 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,8 @@ impl<'a> DynamicLibrary<'a> {
symbols
.resolve_name(e.symbol_index() as usize, string_table)
.map(|s| (e, s))
}).find(|(_, s)| s.eq(symbol_name))
})
.find(|(_, s)| s.eq(symbol_name))
.map(|(target_function, _)| target_function)
{
return Some(symbol);
Expand All @@ -519,7 +520,8 @@ impl<'a> DynamicLibrary<'a> {
symbols
.resolve_name(e.symbol_index() as usize, string_table)
.map(|s| (e, s))
}).find(|(_, s)| s.eq(symbol_name))
})
.find(|(_, s)| s.eq(symbol_name))
.map(|(target_function, _)| target_function)
{
return Some(symbol);
Expand Down Expand Up @@ -630,6 +632,12 @@ pub fn collect_modules<'a>() -> Vec<LoadedLibrary<'a>> {
// We have to copy sthe `dl_phdr_info` struct out, as the same memory buffer is used for
// each entry during the iteration process. Otherwise we could have used a vector of
// pointers.
println!("{} {}", dl_info.dlpi_addr, dl_info.dlpi_phnum);

if dl_info.dlpi_phnum == 0 {
return;
}

let program_headers =
unsafe { std::slice::from_raw_parts(dl_info.dlpi_phdr, dl_info.dlpi_phnum as usize) };
objs.push(LoadedLibrary {
Expand Down

0 comments on commit 0d5b7b0

Please sign in to comment.