summaryrefslogtreecommitdiffhomepage
path: root/dev/LibDebugger
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2025-01-31 09:17:29 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2025-01-31 09:17:29 +0100
commit9680ed596db87636c33001bd5a205c44d38117e1 (patch)
tree1e94f7d8a596328c958131259d26eab6dcee44e6 /dev/LibDebugger
parenta2b370a300317998dfddce354f8c4000b727d557 (diff)
ADD: port debugger to Mac OS X.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/LibDebugger')
-rw-r--r--dev/LibDebugger/.private0
-rw-r--r--dev/LibDebugger/IDebugger.h (renamed from dev/LibDebugger/Debugger.h)21
2 files changed, 16 insertions, 5 deletions
diff --git a/dev/LibDebugger/.private b/dev/LibDebugger/.private
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/dev/LibDebugger/.private
diff --git a/dev/LibDebugger/Debugger.h b/dev/LibDebugger/IDebugger.h
index d99d8ac..957cea9 100644
--- a/dev/LibDebugger/Debugger.h
+++ b/dev/LibDebugger/IDebugger.h
@@ -12,8 +12,18 @@
#include <unistd.h>
#include <stdint.h>
+#ifdef __APPLE__
+#define PTRACE_ATTACH PT_ATTACH
+#define PTRACE_DETACH PT_DETACH
+#define PTRACE_POKETEXT PT_WRITE_I
+#define PTRACE_CONT PT_CONTINUE
+#define PTRACE_PEEKTEXT PT_READ_I
+#endif
+
namespace LibDebugger
{
+ typedef char* VmAddress;
+
/// \brief Debugger interface class in C++
/// \author Amlal El Mahrouss
class IDebugger final
@@ -30,7 +40,7 @@ namespace LibDebugger
{
this->m_pid = pid;
- if (ptrace(PTRACE_ATTACH, this->m_pid, nullptr, nullptr) == -1)
+ if (ptrace(PTRACE_ATTACH, this->m_pid, nullptr, 0) == -1)
{
perror("dbg: Attach");
return;
@@ -41,9 +51,10 @@ namespace LibDebugger
std::cout << "[+] Attached to process: " << m_pid << std::endl;
}
- void SetBreakpoint(void* addr)
+ void SetBreakpoint(VmAddress addr)
{
- long original_data = ptrace(PTRACE_PEEKTEXT, m_pid, addr, nullptr);
+ long original_data = ptrace(PTRACE_PEEKTEXT, m_pid, addr, 0);
+
if (original_data == -1)
{
perror("dbg: Peek");
@@ -64,7 +75,7 @@ namespace LibDebugger
void ContinueExecution()
{
- if (ptrace(PTRACE_CONT, m_pid, nullptr, nullptr) == -1)
+ if (ptrace(PTRACE_CONT, m_pid, nullptr, 0) == -1)
{
perror("dbg: Cont");
return;
@@ -81,7 +92,7 @@ namespace LibDebugger
void Detach()
{
- if (ptrace(PTRACE_DETACH, m_pid, nullptr, nullptr) == -1)
+ if (ptrace(PTRACE_DETACH, m_pid, nullptr, 0) == -1)
{
perror("dbg: Detach");
return;