Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions libdd-gotter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ bench = false

[dependencies]
libc.workspace = true

[dev-dependencies]
tempfile.workspace = true
17 changes: 11 additions & 6 deletions libdd-gotter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ unsafe extern "C" fn my_hook(/* same signature as target */) {
// forward to original via ORIG_FN
}

let mut orig_addr: usize = 0;
unsafe {
hook_symbol(c"__assert_fail", my_hook as *const () as usize, &mut orig_addr);
match unsafe { hook_symbol(c"__assert_fail", my_hook as *const () as usize) } {
Ok(result) => {
// Release pairs with the Acquire load in my_hook, ensuring the GOT
// patches from hook_symbol are visible before the hook reads orig_addr.
ORIG_FN.store(result.orig_addr, Ordering::Release);

// result.entries_patched: number of GOT entries rewritten
// result.entries_failed: matched but mprotect failed
}
Err(HookError::SymbolNotFound) => { /* expected on musl/static libc */ }
Err(HookError::InvalidSymbolName) => { /* bug */ }
}
// Release pairs with the Acquire load in my_hook, ensuring the GOT
// patches from hook_symbol are visible before the hook reads orig_addr.
ORIG_FN.store(orig_addr, Ordering::Release);
```

### Multi-symbol registry (heap profiling hooking malloc/free/calloc/realloc)
Expand Down
Loading
Loading