ajout de console de debogage
This commit is contained in:
Binary file not shown.
+13
-1
@@ -9,7 +9,14 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
Breakpoint::Breakpoint(pid_t pid, std::intptr_t addr)
|
Breakpoint::Breakpoint(pid_t pid, std::intptr_t addr)
|
||||||
: m_pid(pid), m_addr(addr) {}
|
: m_pid(pid), m_addr(addr) {
|
||||||
|
std::cout << "Creating breakpoint at address: " << std::hex << addr << std::dec << " for process: " << pid << std::endl;
|
||||||
|
if (addr % 4 != 0) {
|
||||||
|
throw std::runtime_error("[!] Breakpoint address is not 4-byte aligned (AArch64 requires alignment).");
|
||||||
|
}
|
||||||
|
m_enabled = false;
|
||||||
|
m_saved_data = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void Breakpoint::enable() {
|
void Breakpoint::enable() {
|
||||||
if (m_addr % 4 != 0) {
|
if (m_addr % 4 != 0) {
|
||||||
@@ -63,3 +70,8 @@ bool Breakpoint::is_enabled() const {
|
|||||||
return m_enabled;
|
return m_enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, const Breakpoint& bp) {
|
||||||
|
os << "pid: " << bp.m_pid << "Breakpoint at " << std::hex << bp.m_addr << (bp.m_enabled ? " (enabled)" : " (disabled)");
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
+12
-6
@@ -2,11 +2,18 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <vector>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
class Breakpoint {
|
class Breakpoint {
|
||||||
|
private:
|
||||||
|
pid_t m_pid;
|
||||||
|
std::intptr_t m_addr;
|
||||||
|
bool m_enabled = false;
|
||||||
|
uint8_t m_saved_data;
|
||||||
public:
|
public:
|
||||||
Breakpoint(pid_t pid, std::intptr_t addr);
|
|
||||||
|
|
||||||
|
Breakpoint(pid_t pid, std::intptr_t addr);
|
||||||
void enable();
|
void enable();
|
||||||
void disable();
|
void disable();
|
||||||
|
|
||||||
@@ -14,10 +21,9 @@ public:
|
|||||||
|
|
||||||
bool is_enabled() const;
|
bool is_enabled() const;
|
||||||
|
|
||||||
private:
|
friend std::ostream& operator<<(std::ostream& os, const Breakpoint& bp);
|
||||||
pid_t m_pid;
|
|
||||||
std::intptr_t m_addr;
|
|
||||||
bool m_enabled = false;
|
|
||||||
uint8_t m_saved_data;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+54
-1
@@ -6,7 +6,9 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
Debugger::Debugger(const std::string& prog_name) : program_name(prog_name) {}
|
Debugger::Debugger(const std::string& prog_name) : program_name(prog_name) {
|
||||||
|
std::cout << "[+] Debugger initialized for program: " << program_name << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
void Debugger::run() {
|
void Debugger::run() {
|
||||||
child_pid = fork();
|
child_pid = fork();
|
||||||
@@ -30,9 +32,60 @@ void Debugger::run_debugger() {
|
|||||||
waitpid(child_pid, &status, 0);
|
waitpid(child_pid, &status, 0);
|
||||||
std::cout << "[+] Debugger attached to PID: " << child_pid << "\n";
|
std::cout << "[+] Debugger attached to PID: " << child_pid << "\n";
|
||||||
|
|
||||||
|
DEBUGING();
|
||||||
|
|
||||||
ptrace(PTRACE_CONT, child_pid, nullptr, nullptr);
|
ptrace(PTRACE_CONT, child_pid, nullptr, nullptr);
|
||||||
waitpid(child_pid, &status, 0);
|
waitpid(child_pid, &status, 0);
|
||||||
|
|
||||||
std::cout << "[+] Child process exited.\n";
|
std::cout << "[+] Child process exited.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Debugger::breakpoint_list() {
|
||||||
|
std::cout << "Breakpoints:\n";
|
||||||
|
for (const auto& bp : breakpoints) {
|
||||||
|
std::cout << bp << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Debugger::set_breakpoint(pid_t pid, std::intptr_t addr) {
|
||||||
|
Breakpoint bp(pid, addr);
|
||||||
|
bp.enable();
|
||||||
|
breakpoints.push_back(bp);
|
||||||
|
std::cout << "[+] Breakpoint set at address: " << std::hex << addr << std::dec << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void Debugger::remove_breakpoint(pid_t pid, std::intptr_t addr) {
|
||||||
|
auto it = std::remove_if(breakpoints.begin(), breakpoints.end(),
|
||||||
|
[pid, addr](const Breakpoint& bp) {
|
||||||
|
return bp.get_address() == addr && bp.is_enabled();
|
||||||
|
});
|
||||||
|
if (it != breakpoints.end()) {
|
||||||
|
it->disable();
|
||||||
|
breakpoints.erase(it, breakpoints.end());
|
||||||
|
std::cout << "[+] Breakpoint removed at address: " << std::hex << addr << std::dec << "\n";
|
||||||
|
} else {
|
||||||
|
std::cout << "[-] No breakpoint found at address: " << std::hex << addr << std::dec << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Debugger::DEBUGING() {
|
||||||
|
std::cout << "[+] Entering debugging loop. Type 'exit' to quit.\n";
|
||||||
|
std::string command;
|
||||||
|
while (true) {
|
||||||
|
std::cout << "debugger> ";
|
||||||
|
std::getline(std::cin, command);
|
||||||
|
if (command == "exit") {
|
||||||
|
break;
|
||||||
|
} else if (command == "list") {
|
||||||
|
breakpoint_list();
|
||||||
|
} else if (command.substr(0, 3) == "set") {
|
||||||
|
std::intptr_t addr = std::stol(command.substr(4), nullptr, 16);
|
||||||
|
set_breakpoint(child_pid, addr);
|
||||||
|
} else if (command.substr(0, 6) == "remove") {
|
||||||
|
std::intptr_t addr = std::stol(command.substr(7), nullptr, 16);
|
||||||
|
remove_breakpoint(child_pid, addr);
|
||||||
|
} else {
|
||||||
|
std::cout << "Unknown command: " << command << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,11 +2,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
#include "Breakpoint.hpp"
|
||||||
|
|
||||||
class Debugger {
|
class Debugger {
|
||||||
public:
|
public:
|
||||||
Debugger(const std::string& prog_name);
|
Debugger(const std::string& prog_name);
|
||||||
|
~Debugger() {std::cout << "Debugger destroyed." << std::endl;}
|
||||||
|
void breakpoint_list();
|
||||||
|
void set_breakpoint(pid_t pid, std::intptr_t addr);
|
||||||
|
void remove_breakpoint(pid_t pid, std::intptr_t addr);
|
||||||
void run();
|
void run();
|
||||||
|
void DEBUGING(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void run_target();
|
void run_target();
|
||||||
@@ -14,5 +22,6 @@ private:
|
|||||||
|
|
||||||
std::string program_name;
|
std::string program_name;
|
||||||
pid_t child_pid;
|
pid_t child_pid;
|
||||||
|
std::vector<Breakpoint> breakpoints;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user