diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2025-02-09 09:15:30 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2025-02-09 09:18:33 +0100 |
| commit | 106adcb98390d41ced28ecbbd0b661d3056023d2 (patch) | |
| tree | 4c2af2b0b6b09c5d70eaf882df6990345f147ca2 /dev | |
| parent | b4bcdc8482f8deae2d25018b4f91593570cf9cf5 (diff) | |
ADD: Add LibDebugger as a separate dylib, fix depreciation warning for
ptrace.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev')
| -rw-r--r-- | dev/LibDebugger/IDebuggerEngine.h (renamed from dev/LibDebugger/IDebugger.h) | 34 | ||||
| -rw-r--r-- | dev/LibDebugger/src/DebuggerEnginePOSIX.cc (renamed from dev/LibCompiler/src/DebuggerPOSIX.cc) | 12 |
2 files changed, 28 insertions, 18 deletions
diff --git a/dev/LibDebugger/IDebugger.h b/dev/LibDebugger/IDebuggerEngine.h index 957cea9..aefe117 100644 --- a/dev/LibDebugger/IDebugger.h +++ b/dev/LibDebugger/IDebuggerEngine.h @@ -13,7 +13,7 @@ #include <stdint.h> #ifdef __APPLE__ -#define PTRACE_ATTACH PT_ATTACH +#define PTRACE_ATTACH PT_ATTACHEXC #define PTRACE_DETACH PT_DETACH #define PTRACE_POKETEXT PT_WRITE_I #define PTRACE_CONT PT_CONTINUE @@ -22,38 +22,43 @@ namespace LibDebugger { - typedef char* VmAddress; +#ifdef __APPLE__ + typedef caddr_t CAddr; +#else + typedef char* CAddr; +#endif - /// \brief Debugger interface class in C++ + /// \brief Debugger engine interface class in C++ /// \author Amlal El Mahrouss - class IDebugger final + class IDebuggerEngine final { public: - IDebugger() = default; - ~IDebugger() = default; + explicit IDebuggerEngine() = default; + ~IDebuggerEngine() = default; - IDebugger& operator=(const IDebugger&) = default; - IDebugger(const IDebugger&) = default; + public: + IDebuggerEngine& operator=(const IDebuggerEngine&) = default; + IDebuggerEngine(const IDebuggerEngine&) = default; public: void Attach(pid_t pid) { - this->m_pid = pid; - - if (ptrace(PTRACE_ATTACH, this->m_pid, nullptr, 0) == -1) + if (ptrace(PTRACE_ATTACH, pid, nullptr, 0) == -1) { perror("dbg: Attach"); return; } + this->m_pid = pid; + waitpid(m_pid, nullptr, 0); std::cout << "[+] Attached to process: " << m_pid << std::endl; } - void SetBreakpoint(VmAddress addr) + void SetBreakpoint(CAddr addr) { - long original_data = ptrace(PTRACE_PEEKTEXT, m_pid, addr, 0); + auto original_data = ptrace(PTRACE_PEEKTEXT, m_pid, addr, 0); if (original_data == -1) { @@ -61,7 +66,8 @@ namespace LibDebugger return; } - long data_with_int3 = (original_data & ~0xFF) | 0xCC; // Insert INT3 (0xCC) + auto data_with_int3 = (original_data & ~0xFF) | 0xCC; // Insert INT3 (0xCC) + if (ptrace(PTRACE_POKETEXT, m_pid, addr, data_with_int3) == -1) { perror("dbg: Poke"); diff --git a/dev/LibCompiler/src/DebuggerPOSIX.cc b/dev/LibDebugger/src/DebuggerEnginePOSIX.cc index a5e663e..e8a394e 100644 --- a/dev/LibCompiler/src/DebuggerPOSIX.cc +++ b/dev/LibDebugger/src/DebuggerEnginePOSIX.cc @@ -3,11 +3,13 @@ */ #include <LibCompiler/Defines.h> -#include <LibDebugger/IDebugger.h> +#include <LibDebugger/IDebuggerEngine.h> + +#ifndef _WIN32 LIBCOMPILER_MODULE(DebuggerPOSIX) { - LibDebugger::IDebugger debugger; + LibDebugger::IDebuggerEngine debugger; pid_t pid = 0L; if (argc >= 3 && std::string(argv[1]) == "-p" && @@ -49,13 +51,13 @@ LIBCOMPILER_MODULE(DebuggerPOSIX) } if (cmd == "break" || - cmd == "bp") + cmd == "b") { std::cout << "[?] Enter an address to add a breakpoint on: "; std::getline(std::cin, cmd); - LibDebugger::VmAddress breakpoint_addr = reinterpret_cast<LibDebugger::VmAddress>(std::stoul(cmd.c_str(), nullptr, 16)); + LibDebugger::CAddr breakpoint_addr = reinterpret_cast<LibDebugger::CAddr>(std::stoul(cmd.c_str(), nullptr, 16)); if (breakpoint_addr) debugger.SetBreakpoint(breakpoint_addr); @@ -64,3 +66,5 @@ LIBCOMPILER_MODULE(DebuggerPOSIX) return 0; } + +#endif
\ No newline at end of file |
