Skip to main content

plthook/
lib.rs

1//! `plthook` is a pure-Rust import-table rebinding engine.
2//!
3//! It enumerates imports in loaded Windows PE, Linux ELF, macOS Mach-O, and
4//! iOS/iPadOS Mach-O modules. Installing a replacement resolves every target first,
5//! changes page protection only as needed, swaps slots atomically, and restores a
6//! slot only when the guard still owns it.
7//!
8//! The binary-format parsers are bounds-checked and host-independent; the live
9//! backends provide module discovery, page protection, and original-symbol lookup.
10
11mod arch;
12mod error;
13mod types;
14
15#[cfg(any(
16    windows,
17    target_os = "linux",
18    target_os = "macos",
19    target_os = "ios",
20    test
21))]
22mod import;
23
24#[cfg(any(target_os = "linux", test))]
25mod elf;
26#[cfg(any(target_os = "macos", target_os = "ios", test))]
27mod macho;
28#[cfg(any(windows, test))]
29mod pe;
30
31pub use error::{Error, Result};
32pub use types::{ImportKind, Symbol};
33
34// The live engine: the Windows PE backend, the Linux ELF backend, and the Darwin
35// Apple targets). Each supplies a `Module` and a `sys` module exposing the same
36// operations the platform-agnostic transaction ([`slot`]) needs; only those
37#[cfg(windows)]
38mod sys;
39#[cfg(target_os = "linux")]
40#[path = "sys_unix.rs"]
41mod sys;
42#[cfg(any(target_os = "macos", target_os = "ios"))]
43#[path = "sys_macos.rs"]
44mod sys;
45
46#[cfg(target_os = "linux")]
47mod dlpi;
48
49#[cfg(windows)]
50mod module;
51#[cfg(target_os = "linux")]
52#[path = "module_elf.rs"]
53mod module;
54#[cfg(any(target_os = "macos", target_os = "ios"))]
55#[path = "module_macho.rs"]
56mod module;
57
58#[cfg(any(windows, target_os = "linux", target_os = "macos", target_os = "ios"))]
59mod slot;
60
61#[cfg(any(windows, target_os = "linux", target_os = "macos", target_os = "ios"))]
62pub use module::Module;
63#[cfg(any(windows, target_os = "linux", target_os = "macos", target_os = "ios"))]
64pub use slot::{HookGuard, ImportSlot, InstalledHook, Replacement, install};