first commit

This commit is contained in:
YANNIS
2025-05-23 00:57:27 +02:00
commit 7bae3bcc57
4 changed files with 93 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
// Debugger.cpp
#include "Debugger.hpp"
#include <iostream>
#include <sys/ptrace.h>
#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>
Debugger::Debugger(const std::string& prog_name) : program_name(prog_name) {}
void Debugger::run() {
child_pid = fork();
if (child_pid == 0) {
run_target();
} else if (child_pid > 0) {
run_debugger();
} else {
std::cerr << "[!] fork() failed.\n";
}
}
void Debugger::run_target() {
std::cout << "[+] Child process started.\n";
ptrace(PTRACE_TRACEME, 0, nullptr, nullptr);
execl(program_name.c_str(), program_name.c_str(), nullptr);
}
void Debugger::run_debugger() {
int status;
waitpid(child_pid, &status, 0);
std::cout << "[+] Debugger attached to PID: " << child_pid << "\n";
ptrace(PTRACE_CONT, child_pid, nullptr, nullptr);
waitpid(child_pid, &status, 0);
std::cout << "[+] Child process exited.\n";
}
+18
View File
@@ -0,0 +1,18 @@
// Debugger.hpp
#pragma once
#include <string>
#include <sys/types.h>
class Debugger {
public:
Debugger(const std::string& prog_name);
void run();
private:
void run_target();
void run_debugger();
std::string program_name;
pid_t child_pid;
};
+22
View File
@@ -0,0 +1,22 @@
# Makefile
CXX = g++
CXXFLAGS = -Wall -Wextra -Werror
SRC = main.cpp Debugger.cpp
OBJ = $(SRC:.cpp=.o)
TARGET = nullDBG
all: $(TARGET)
$(TARGET): $(OBJ)
$(CXX) $(CXXFLAGS) -o $@ $^
clean:
rm -f $(OBJ)
fclean: clean
rm -f $(TARGET)
re: fclean all
.PHONY: all clean fclean re
+15
View File
@@ -0,0 +1,15 @@
// main.cpp
#include "Debugger.hpp"
#include <iostream>
int main(int argc, char* argv[]) {
if (argc < 2) {
std::cerr << "Usage: " << argv[0] << " <program to debug>\n";
return -1;
}
Debugger dbg(argv[1]);
dbg.run();
return 0;
}