From 94ceccd5acda2fd035eb55235126b944b0915576 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 14 May 2025 14:27:43 +0200 Subject: dev(kdbg): Working on NeKernel Debugger. how: - Load vmkrnl.efi. - Keep track of IP, Stack, and debugging information related to the kernel. - Make use of breakpoints and provide lldb grade experience. Signed-off-by: Amlal El Mahrouss --- dev/LibDebugger/src/NeKernelContract.cc | 34 ++++++++++ dev/LibDebugger/src/NeKernelContractCLI.cc | 35 ++++++++++ dev/LibDebugger/src/POSIXMachContract.cc | 102 ---------------------------- dev/LibDebugger/src/POSIXMachContractCLI.cc | 95 ++++++++++++++++++++++++++ 4 files changed, 164 insertions(+), 102 deletions(-) create mode 100644 dev/LibDebugger/src/NeKernelContract.cc create mode 100644 dev/LibDebugger/src/NeKernelContractCLI.cc delete mode 100644 dev/LibDebugger/src/POSIXMachContract.cc create mode 100644 dev/LibDebugger/src/POSIXMachContractCLI.cc (limited to 'dev/LibDebugger/src') diff --git a/dev/LibDebugger/src/NeKernelContract.cc b/dev/LibDebugger/src/NeKernelContract.cc new file mode 100644 index 0000000..e653d12 --- /dev/null +++ b/dev/LibDebugger/src/NeKernelContract.cc @@ -0,0 +1,34 @@ +/*** + LibDebugger + (C) 2025 Amlal El Mahrouss + File: NeKernelContract.cc + Purpose: NeKernel Debugger +*/ + +#ifdef LD_NEKERNEL_DEBUGGER + +#include +#include +#include + +#include +#include +#include + +using namespace LibDebugger::NeKernel; + +NeKernelContract::NeKernelContract() = default; + +NeKernelContract::~NeKernelContract() = default; + +bool NeKernelContract::Attach(std::string path, std::string argv, ProcessID& pid) noexcept { return false; } + +bool NeKernelContract::Breakpoint(std::string symbol) noexcept { return false; } + +bool NeKernelContract::Break() noexcept { return false; } + +bool NeKernelContract::Continue() noexcept { return false; } + +bool NeKernelContract::Detach() noexcept { return false; } + +#endif // LD_NEKERNEL_DEBUGGER \ No newline at end of file diff --git a/dev/LibDebugger/src/NeKernelContractCLI.cc b/dev/LibDebugger/src/NeKernelContractCLI.cc new file mode 100644 index 0000000..1f05ff2 --- /dev/null +++ b/dev/LibDebugger/src/NeKernelContractCLI.cc @@ -0,0 +1,35 @@ +/*** + LibDebugger + (C) 2025 Amlal El Mahrouss + File: NeKernelContract.cc + Purpose: NeKernel Debugger CLI. +*/ + +#ifdef LD_NEKERNEL_DEBUGGER + +#include +#include +#include + +#include +#include +#include + +#include + +using namespace LibDebugger::NeKernel; + +LIBCOMPILER_MODULE(DebuggerNeKernel) { + pfd::notify("Debugger Event", + "Kernel Debugger\n(C) 2025 Amlal El Mahrouss, all rights reserved."); + + if (argc >= 3 && std::string(argv[1]) == "-p" && argv[2] != nullptr) { + kPath = argv[2]; + kStdOut << "[+] Kernel image set to: " << kPath << "\n"; + } + + + return EXIT_SUCCESS; +} + +#endif // LD_NEKERNEL_DEBUGGER \ No newline at end of file diff --git a/dev/LibDebugger/src/POSIXMachContract.cc b/dev/LibDebugger/src/POSIXMachContract.cc deleted file mode 100644 index 2753e9a..0000000 --- a/dev/LibDebugger/src/POSIXMachContract.cc +++ /dev/null @@ -1,102 +0,0 @@ -/*** - (C) 2025 Amlal El Mahrouss - */ - -#ifdef __APPLE__ - -#include -#include -#include -#include -#include -#include - -static BOOL kKeepRunning = false; -static LibDebugger::POSIX::POSIXMachContract kDebugger; -static LibDebugger::ProcessID kPID = 0L; -static LibDebugger::CAddress kActiveAddress = nullptr; -static std::string kPath = ""; - -#define kBlank "\e[0;30m" -#define kRed "\e[0;31m" -#define kWhite "\e[0;97m" - -#define kStdOut (std::cout << kRed << "dbg: " << kWhite) - -/// @internal -/// @brief Handles CTRL-C signal on debugger. -static void dbgi_ctrlc_handler(std::int32_t _) { - if (!kPID) { - return; - } - - auto list = kDebugger.Get(); - - kDebugger.Break(); - - pfd::notify("Debugger Event", "Breakpoint hit!"); - - kKeepRunning = false; -} - -LIBCOMPILER_MODULE(DebuggerMachPOSIX) { - pfd::notify("Debugger Event", - "Userland Debugger\n(C) 2025 Amlal El Mahrouss, all rights reserved."); - - if (argc >= 3 && std::string(argv[1]) == "-p" && argv[2] != nullptr) { - kPath = argv[2]; - kDebugger.SetPath(kPath); - - kStdOut << "[+] Path set to: " << kPath << "\n"; - } - - ::signal(SIGINT, dbgi_ctrlc_handler); - - while (YES) { - if (kKeepRunning) { - continue; - } - - std::string cmd; - std::getline(std::cin, cmd); - - if (cmd == "c" || cmd == "cont" || cmd == "continue") { - if (kDebugger.Continue()) { - kKeepRunning = true; - - kStdOut << "[+] Continuing...\n"; - - pfd::notify("Debugger Event", "Continuing..."); - } - } - - if (cmd == "d" || cmd == "detach") kDebugger.Detach(); - - if (cmd == "start") { - kStdOut << "[?] Enter a argument to use: "; - std::getline(std::cin, cmd); - - kDebugger.Attach(kPath, cmd, kPID); - } - - if (cmd == "exit") { - if (kPID > 0) kDebugger.Detach(); - - break; - } - - if (cmd == "break" || cmd == "b") { - kStdOut << "[?] Enter a symbol to break on: "; - - std::getline(std::cin, cmd); - - if (kDebugger.Breakpoint(cmd)) { - pfd::notify("Debugger Event", "Add Breakpoint at: " + cmd); - } - } - } - - return EXIT_SUCCESS; -} - -#endif \ No newline at end of file diff --git a/dev/LibDebugger/src/POSIXMachContractCLI.cc b/dev/LibDebugger/src/POSIXMachContractCLI.cc new file mode 100644 index 0000000..90cebc3 --- /dev/null +++ b/dev/LibDebugger/src/POSIXMachContractCLI.cc @@ -0,0 +1,95 @@ +/*** + LibDebugger + (C) 2025 Amlal El Mahrouss + File: POSIXMachContract.cc + Purpose: OS X/Darwin Debugger +*/ + +#ifdef LD_MACH_DEBUGGER + +#include +#include +#include +#include +#include +#include + +#include + +/// @internal +/// @brief Handles CTRL-C signal on debugger. +static void dbgi_ctrlc_handler(std::int32_t _) { + if (!kPID) { + return; + } + + auto list = kDebugger.Get(); + + kDebugger.Break(); + + pfd::notify("Debugger Event", "Breakpoint hit!"); + + kKeepRunning = false; +} + +LIBCOMPILER_MODULE(DebuggerMachPOSIX) { + pfd::notify("Debugger Event", + "Userland Debugger\n(C) 2025 Amlal El Mahrouss, all rights reserved."); + + if (argc >= 3 && std::string(argv[1]) == "-p" && argv[2] != nullptr) { + kPath = argv[2]; + kDebugger.SetPath(kPath); + + kStdOut << "[+] Image set to: " << kPath << "\n"; + } + + ::signal(SIGINT, dbgi_ctrlc_handler); + + while (YES) { + if (kKeepRunning) { + continue; + } + + std::string cmd; + std::getline(std::cin, cmd); + + if (cmd == "c" || cmd == "cont" || cmd == "continue") { + if (kDebugger.Continue()) { + kKeepRunning = true; + + kStdOut << "[+] Continuing...\n"; + + pfd::notify("Debugger Event", "Continuing..."); + } + } + + if (cmd == "d" || cmd == "detach") kDebugger.Detach(); + + if (cmd == "start") { + kStdOut << "[?] Enter a argument to use: "; + std::getline(std::cin, cmd); + + kDebugger.Attach(kPath, cmd, kPID); + } + + if (cmd == "exit") { + if (kPID > 0) kDebugger.Detach(); + + break; + } + + if (cmd == "break" || cmd == "b") { + kStdOut << "[?] Enter a symbol to break on: "; + + std::getline(std::cin, cmd); + + if (kDebugger.Breakpoint(cmd)) { + pfd::notify("Debugger Event", "Add Breakpoint at: " + cmd); + } + } + } + + return EXIT_SUCCESS; +} + +#endif \ No newline at end of file -- cgit v1.2.3