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 | |
| 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>
| -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 | ||||
| -rw-r--r-- | osx.json | 2 | ||||
| -rw-r--r-- | osx_dbg.json | 16 | ||||
| -rw-r--r-- | posix.json | 2 | ||||
| -rw-r--r-- | tools/asm.cc | 2 | ||||
| -rw-r--r-- | tools/dbg.json | 2 | ||||
| -rw-r--r-- | tools/necc.cc | 2 |
8 files changed, 49 insertions, 23 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 @@ -8,7 +8,7 @@ "./dev/LibCompiler/src/Detail" ], "sources_path": ["dev/LibCompiler/src/*.cc"], - "output_name": "/usr/local/lib/libCCDyn.dylib", + "output_name": "/usr/local/lib/libCompiler.dylib", "compiler_flags": ["-fPIC", "-shared"], "cpp_macros": [ "__LIBCOMPILER_DLL__=202401", diff --git a/osx_dbg.json b/osx_dbg.json new file mode 100644 index 0000000..8b44257 --- /dev/null +++ b/osx_dbg.json @@ -0,0 +1,16 @@ +{ + "compiler_path": "g++", + "compiler_std": "c++20", + "headers_path": [ + "./dev/LibDebugger", + "./dev" + ], + "sources_path": ["dev/LibDebugger/src/*.cc"], + "output_name": "/usr/local/lib/libDebugger.dylib", + "compiler_flags": ["-fPIC", "-shared"], + "cpp_macros": [ + "__LIBCOMPILER_DLL__=202401", + "LC_USE_STRUCTS=1", + "kDistReleaseBranch=$(git rev-parse --abbrev-ref HEAD)-$(uuidgen)" + ] +} @@ -8,7 +8,7 @@ "./dev/LibCompiler/src/Detail" ], "sources_path": ["dev/LibCompiler/src/*.cc"], - "output_name": "/usr/lib/libCCDyn.so", + "output_name": "/usr/lib/libCompiler.so", "compiler_flags": ["-fPIC", "-shared"], "cpp_macros": [ "__LIBCOMPILER_DLL__=202401", diff --git a/tools/asm.cc b/tools/asm.cc index 9645ca7..6f4d43d 100644 --- a/tools/asm.cc +++ b/tools/asm.cc @@ -43,7 +43,7 @@ int main(int argc, char const* argv[]) std::printf("asm.exe: Frontend Assembler (64x0, power64, arm64, x64).\n"); std::printf("asm.exe: Version: %s, Release: %s.\n", kDistVersion, kDistRelease); std::printf("asm.exe: Designed by Amlal EL Mahrouss, Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved.\n"); - std::printf("libCCDyn.dylib: Designed by Amlal EL Mahrouss, Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved.\n"); + std::printf("libCompiler.dylib: Designed by Amlal EL Mahrouss, Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved.\n"); return 0; } diff --git a/tools/dbg.json b/tools/dbg.json index a6039ec..faab78e 100644 --- a/tools/dbg.json +++ b/tools/dbg.json @@ -4,7 +4,7 @@ "headers_path": ["../dev/LibCompiler", "../dev/", "../dev/LibCompiler/src/Detail"], "sources_path": ["dbg.cc"], "output_name": "dbg", - "compiler_flags": ["-L/usr/lib", "-lCCDyn"], + "compiler_flags": ["-L/usr/lib", "-lDebugger"], "cpp_macros": [ "__DBG__=202401", "kDistReleaseBranch=$(git rev-parse --abbrev-ref HEAD)-$(uuidgen)" diff --git a/tools/necc.cc b/tools/necc.cc index 62c4b75..b044a51 100644 --- a/tools/necc.cc +++ b/tools/necc.cc @@ -26,7 +26,7 @@ int main(int argc, char const* argv[]) std::printf("necc: Frontend C++ Compiler.\n"); std::printf("necc: Version: %s, Release: %s.\n", kDistVersion, kDistRelease); std::printf("necc: Designed by Amlal EL Mahrouss, Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved.\n"); - std::printf("libCCDyn.dylib: Designed by Amlal EL Mahrouss, Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved.\n"); + std::printf("libCompiler.dylib: Designed by Amlal EL Mahrouss, Copyright (C) 2024-2025 Amlal EL Mahrouss, all rights reserved.\n"); return 0; } |
