8 Commits
Author SHA1 Message Date
xiaozhou233 9d419c7a85 [skip ci] Add LICENSE 2026-10-20 13:15:16 +08:00
xiaozhou233 6acff33c11 Simplify CI to three build jobs v1.0.0 2026-10-20 13:08:58 +08:00
xiaozhou233 259a4baf29 Build the 22.04 shared library with GCC 2026-10-20 13:08:06 +08:00
xiaozhou233 1ac402394f Version 1.0.0 2026-10-20 13:00:45 +08:00
xiaozhou233 9dfbdc5b6e Add GitHub Actions CI that builds and uploads artifacts 2026-10-20 12:49:22 +08:00
xiaozhou233 04d39842ba Rename project to ptrace-inject-cpp
Rename the CMake project and CLI to ptrace-inject-cpp to distinguish this
C++ port from the original Rust project. The library artifact, public
header, and C API keep the name ptrace_inject; the READMEs state this
explicitly and use the new project name and tagline.
2026-10-18 21:49:46 +08:00
xiaozhou233 50135e5f87 Add acknowledgements for the original ptrace-inject project
Credit Artemis21/ptrace-inject (https://github.com/Artemis21/ptrace-inject)
as the original Rust project this C++ port is based on, in both READMEs
and the public header.
2026-10-18 21:40:12 +08:00
xiaozhou233 b78aa07f78 Port ptrace library injection to C++ as a reusable library
Add a C ABI library (libptrace_inject), a thin CLI (ptrace-inject), and
C/C++ examples that inject a .so into a running x86-64 Linux process.

Injection flow:
- stop every thread with PTRACE_ATTACH, re-scanning /proc/<pid>/task for
  threads created while attaching
- patch a 6-byte shellcode (nop; nop; call r9; int3) into a private,
  file-backed executable mapping, then call target malloc/dlopen/free via
  PTRACE_SETREGS + PTRACE_CONT and read the result from rax
- write the library path with /proc/<pid>/mem, free it, restore the
  original bytes and registers, then PTRACE_DETACH all threads

Safety:
- validate before modifying anything: library path, libc/libdl build
  identity via device:inode, relocated symbol addresses are executable,
  patch site avoids stopped threads' RIPs, stack pointer is writable
- only accept the SIGTRAP whose RIP is shellcode+6
- forward unexpected signals back to the target on detach
- best-effort rollback of code and registers on failure
- shared library exports only the two public entry points

API: ptrace_inject_by_pid() and ptrace_inject_by_name(), with an optional
log callback and an error buffer; silent by default.

Build with CMake (no install rules); docs in README.md (EN) and
README.ZH.md (ZH).
2026-10-18 21:38:52 +08:00