first commit
This commit is contained in:
@@ -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";
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user