|
KittyMemoryEx 1.0.0
Dedicated library for runtime code patching, memory scanning, tracing, injection and some more useful memory utilities. works for both Android and Linux
|
A class for tracing and controlling the execution of processes in a debugging environment. More...
#include <KittyTrace.hpp>
Public Member Functions | |
| KittyTraceMgr (pid_t pid, uintptr_t defaultCaller=0, bool autoRestoreRegs=true, int remoteCallTimeout=0, uintptr_t syscallGadget=0) | |
| Constructs a new KittyTraceMgr object. | |
| pid_t | pid () const |
| Returns the PID of the process being traced. | |
| bool | isAlive () const |
| Check if the process is alive. | |
| bool | isAttached () const |
| Check if the process is currently attached. | |
| std::vector< pid_t > | threads () const |
| Get a list of all threads in the traced process. | |
| bool | attach (int options=0) |
| Attach to the process. | |
| bool | seize (int options=0) |
| Seize the process. | |
| bool | setOptions (int options) |
| Set options for the process being traced. | |
| bool | detach () |
| Detach from the process. | |
| bool | stop () |
| Stop the traced process thread. | |
| bool | cont (int sig=0) |
| Continue the traced process thread. | |
| pid_t | wait (int *status, int options, int timeout_ms=0) const |
| Wait for the process. | |
| bool | waitSyscall () const |
| Wait for the process to enter or exit a syscall. | |
| bool | step (int steps=1) const |
| Single-step the process. | |
| bool | waitStep (int steps=1) const |
| Single-step and wait the process. | |
| bool | getSignalInfo (siginfo_t *si) const |
| Get the signal information of the process. | |
| bool | getRegs (user_regs_struct *regs) const |
| Get the current registers of the process. | |
| bool | setRegs (user_regs_struct *regs) const |
| Set the current registers of the process. | |
| uintptr_t | getReturnAddressFromRegs (user_regs_struct *regs) |
| Get the return address value from registers. | |
| template<typename T> | |
| T | getArgFromRegs (user_regs_struct *regs, uint32_t arg_num) |
| Get the n-th argument value from registers. | |
| size_t | peekMem (uintptr_t addr, void *buf, size_t size) const |
| Reads memory from a traced process using PTRACE_PEEKTEXT. Works around ptrace's word-sized limitation by reading aligned machine words and copying only the requested byte ranges. | |
| size_t | pokeMem (uintptr_t addr, const void *buf, size_t size) const |
| Writes memory from a traced process using PTRACE_POKETEXT. Works around ptrace's word-sized limitation by reading aligned machine words and copying only the requested byte ranges. | |
| uintptr_t | defaultCaller () const |
| Returns the default caller address for remote function calls. | |
| void | setDefaultCaller (uintptr_t caller) |
| Sets the default caller address for remote function calls. | |
| bool | autoRestoreRegs () const |
| Returns true if automatic registers restore for remote function calls is enabled, false otherwise. | |
| void | setAutoRestoreRegs (bool flag) |
| Sets the automatic registers restore flag for remote function calls. | |
| int | remoteCallTimeout () const |
| Returns the default timeout (ms) for remote function calls. | |
| void | setRemoteCallTimeout (int ms) |
| Sets the default remote function call timeout in milliseconds. | |
| uintptr_t | syscallGadget () const |
| Returns the syscall gadget address for remote syscalls. | |
| void | setSyscallGadget (uintptr_t address) |
| Sets the syscall gadget address for remote syscalls. | |
| template<class... Args> | |
| kitty_rp_call_t | callFunctionFrom (uintptr_t callerAddress, uintptr_t functionAddress, Args &&...a) |
| Call a function in the remote process and spoof return address. | |
| template<class... Args> | |
| kitty_rp_call_t | callFunction (uintptr_t functionAddress, Args &&...a) |
| Call a function in the remote process. | |
| template<class... Args> | |
| kitty_rp_call_t | callSyscall (long sysnr, Args &&...a) |
| Call a syscall in the remote process. | |
| KT_BP_RESULT | setSoftBreakpointAndWait (uintptr_t address, const std::function< bool(uintptr_t bp_addr, user_regs_struct regs)> &cb, int timeout_ms) |
| Sets and wait for software breakpoint at a given address. | |
| KT_BP_RESULT | setHardBreakpointAndWait (uintptr_t address, KT_HW_BP_TYPE type, KT_HW_BP_SIZE size, int slot, const std::function< bool(uintptr_t bp_addr, user_regs_struct regs)> &cb, int timeout_ms) |
| Set and wait for a hardware breakpoint/watchpoint at a single address. | |
| KT_BP_RESULT | setHardExecBreakpointsAndWait (const std::vector< uintptr_t > &addresses, const std::function< bool(uintptr_t bp_addr, user_regs_struct regs)> &cb, int timeout_ms) |
| Set hardware execute breakpoints on several addresses (one per debug slot) and wait for whichever is hit first. Thumb/ARM width is chosen per address. | |
| bool | setHwBreakpoint (uintptr_t address, KT_HW_BP_TYPE type, KT_HW_BP_SIZE size, int slot) |
| Sets a hardware breakpoint on a specified address for traced thread. | |
| bool | clearHwBreakpoint (KT_HW_BP_TYPE type, int slot) |
| Clears a hardware breakpoint on a specified address for traced thread. | |
A class for tracing and controlling the execution of processes in a debugging environment.
|
inline |
Constructs a new KittyTraceMgr object.
| pid | The process ID to trace. |
| defaultCaller | The default caller for remote function calls (optional). |
| autoRestoreRegs | Whether to automatically restore registers on remote function calls (optional). |
| remoteCallTimeout | The default remote call timeout (optional). |

| bool KittyTraceMgr::attach | ( | int | options = 0 | ) |
Attach to the process.
| options | PTRACE options to use (optional). |
|
inline |
Call a function in the remote process.
| functionAddress | The address of the function to call. |
| ... | Arguments to pass to the function. |
|
inline |
Call a function in the remote process and spoof return address.
| callerAddress | The address of the caller. |
| functionAddress | The address of the function to call. |
| ... | Arguments to pass to the function. |
|
inline |
Call a syscall in the remote process.
| sysnr | The syscall number. |
| ... | Arguments to pass to the syscall. |
| bool KittyTraceMgr::clearHwBreakpoint | ( | KT_HW_BP_TYPE | type, |
| int | slot ) |
Clears a hardware breakpoint on a specified address for traced thread.
| type | The type of hardware breakpoint (e.g., execute, read, write, access). |
| slot | The slot number for the breakpoint. |
| bool KittyTraceMgr::cont | ( | int | sig = 0 | ) |
Continue the traced process thread.
| sig | Signal to send to the process (optional). |
| bool KittyTraceMgr::detach | ( | ) |
Detach from the process.
|
inline |
Get the n-th argument value from registers.
| regs | Pointer to the registers. |
| arg_num | The zero-indexed argument number (0 for 1st arg, 1 for 2nd, etc.). |

| bool KittyTraceMgr::getRegs | ( | user_regs_struct * | regs | ) | const |
Get the current registers of the process.
| regs | Pointer to store the registers. |
|
inline |
Get the return address value from registers.
| regs | Pointer to the registers. |

|
inline |
Get the signal information of the process.
| si | Pointer to store the signal information. |
| size_t KittyTraceMgr::peekMem | ( | uintptr_t | addr, |
| void * | buf, | ||
| size_t | size ) const |
Reads memory from a traced process using PTRACE_PEEKTEXT. Works around ptrace's word-sized limitation by reading aligned machine words and copying only the requested byte ranges.
| addr | Remote address to read from. |
| buf | Buffer to store the read data. |
| size | Size of the data to read. |

| size_t KittyTraceMgr::pokeMem | ( | uintptr_t | addr, |
| const void * | buf, | ||
| size_t | size ) const |
Writes memory from a traced process using PTRACE_POKETEXT. Works around ptrace's word-sized limitation by reading aligned machine words and copying only the requested byte ranges.
| addr | Remote address to write to. |
| buf | Buffer containing the data to write. |
| size | Size of the data to write. |
| bool KittyTraceMgr::seize | ( | int | options = 0 | ) |
Seize the process.
| options | PTRACE options to use (optional). |
|
inline |
Sets the automatic registers restore flag for remote function calls.
| flag | True to enable automatic restore, false otherwise. |
|
inline |
Sets the default caller address for remote function calls.
| caller | The default caller address. |
| KT_BP_RESULT KittyTraceMgr::setHardBreakpointAndWait | ( | uintptr_t | address, |
| KT_HW_BP_TYPE | type, | ||
| KT_HW_BP_SIZE | size, | ||
| int | slot, | ||
| const std::function< bool(uintptr_t bp_addr, user_regs_struct regs)> & | cb, | ||
| int | timeout_ms ) |
Set and wait for a hardware breakpoint/watchpoint at a single address.
| address | The address to break/watch. |
| type | The type of hardware breakpoint (execute, read, write, access). |
| size | The size to watch (ignored for execute breakpoints; width is picked per address). |
| slot | The debug slot to use. |
| cb | Callback run on a hit; return true to accept (stop), false to skip and keep waiting. |
| timeout_ms | Timeout in milliseconds (0 or negative disables it). |
| KT_BP_RESULT KittyTraceMgr::setHardExecBreakpointsAndWait | ( | const std::vector< uintptr_t > & | addresses, |
| const std::function< bool(uintptr_t bp_addr, user_regs_struct regs)> & | cb, | ||
| int | timeout_ms ) |
Set hardware execute breakpoints on several addresses (one per debug slot) and wait for whichever is hit first. Thumb/ARM width is chosen per address.
| addresses | Code addresses to break on (capped to the number of debug slots). |
| cb | Callback run on a hit; return true to accept (stop), false to skip and keep waiting. |
| timeout_ms | Timeout in milliseconds (0 or negative disables it). |
| bool KittyTraceMgr::setHwBreakpoint | ( | uintptr_t | address, |
| KT_HW_BP_TYPE | type, | ||
| KT_HW_BP_SIZE | size, | ||
| int | slot ) |
Sets a hardware breakpoint on a specified address for traced thread.
| address | The address to set the breakpoint at. |
| type | The type of hardware breakpoint (e.g., execute, read, write, access). |
| size | The size of the data to watch (ignored if bp type is KT_HW_BP_EXECUTE). |
| slot | The slot number for the breakpoint. |
| bool KittyTraceMgr::setOptions | ( | int | options | ) |
Set options for the process being traced.
| options | PTRACE options to set. |
| bool KittyTraceMgr::setRegs | ( | user_regs_struct * | regs | ) | const |
Set the current registers of the process.
| regs | Pointer to the registers to set. |
|
inline |
Sets the default remote function call timeout in milliseconds.
| ms | Timeout in milliseconds (0 or negaive to disable). |
| KT_BP_RESULT KittyTraceMgr::setSoftBreakpointAndWait | ( | uintptr_t | address, |
| const std::function< bool(uintptr_t bp_addr, user_regs_struct regs)> & | cb, | ||
| int | timeout_ms ) |
Sets and wait for software breakpoint at a given address.
| address | The address to set the breakpoint at. |
| cb | Callback function to be executed when the breakpoint is hit. |
| timeout_ms | timeout in milliseconds (0 or negative value, will disable timeout) |
|
inline |
Sets the syscall gadget address for remote syscalls.
| address | The address of syscall gadget. |
| bool KittyTraceMgr::step | ( | int | steps = 1 | ) | const |
Single-step the process.
| steps | Number of steps to single-step (default is 1). |
| bool KittyTraceMgr::stop | ( | ) |
Stop the traced process thread.
|
inline |
Get a list of all threads in the traced process.

| pid_t KittyTraceMgr::wait | ( | int * | status, |
| int | options, | ||
| int | timeout_ms = 0 ) const |
Wait for the process.
| status | Pointer to store the status of the process. |
| options | waitpid options to use. |
| timeout_ms | timeout in milliseconds (optional, default is 0) |
| bool KittyTraceMgr::waitStep | ( | int | steps = 1 | ) | const |
Single-step and wait the process.
| steps | Number of steps to single-step (default is 1). |
| bool KittyTraceMgr::waitSyscall | ( | ) | const |
Wait for the process to enter or exit a syscall.