From befc10f9e391ebe538d9e40eb3ed42baf28829d5 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 30 Jun 2025 10:22:15 +0200 Subject: feat: Kernel+IP system for NeDBG. Signed-off-by: Amlal El Mahrouss --- dev/LibDebugger/src/NeKernelContract.cc | 2 + dev/LibDebugger/src/NeKernelContractCLI.cc | 70 +++++++++++++++++++++++++++-- dev/LibDebugger/src/POSIXMachContractCLI.cc | 2 +- 3 files changed, 69 insertions(+), 5 deletions(-) (limited to 'dev/LibDebugger/src') diff --git a/dev/LibDebugger/src/NeKernelContract.cc b/dev/LibDebugger/src/NeKernelContract.cc index 41d3fd1..5c0243b 100644 --- a/dev/LibDebugger/src/NeKernelContract.cc +++ b/dev/LibDebugger/src/NeKernelContract.cc @@ -12,6 +12,8 @@ #include #include +constexpr static UInt16 kDebugPort = 51820; + using namespace LibDebugger::NeKernel; NeKernelContract::NeKernelContract() = default; diff --git a/dev/LibDebugger/src/NeKernelContractCLI.cc b/dev/LibDebugger/src/NeKernelContractCLI.cc index b284595..ec73788 100644 --- a/dev/LibDebugger/src/NeKernelContractCLI.cc +++ b/dev/LibDebugger/src/NeKernelContractCLI.cc @@ -16,22 +16,84 @@ using namespace LibDebugger::NeKernel; +static void dbgi_ctrlc_handler(std::int32_t _) { + if (!kPID || kPath.empty()) { + return; + } + + kKernelDebugger.Break(); + + pfd::notify("Debugger Event", "Breakpoint hit!"); + + kKeepRunning = false; +} + 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]) == "-k" && argv[2] != nullptr) { + if (argc >= 5 && std::string(argv[1]) == "-k" && argv[2] != nullptr && + std::string(argv[3]) == "-ip" && argv[4] != nullptr) { kPath = argv[2]; - kStdOut << "[+] Kernel (ne_kernel) set to: " << kPath << "\n"; + kPath += ":"; + kPath += argv[4]; + + kStdOut << "[+] KIP (Kernel:IP) set to: " << kPath << "\n"; + + LibCompiler::install_signal(SIGINT, dbgi_ctrlc_handler); kKernelDebugger.Attach(kPath, "", kPID); kKernelDebugger.Breakpoint("$HANDOVER_START"); + while (YES) { + if (kKeepRunning) { + continue; + } + + std::string cmd; + if (!std::getline(std::cin, cmd)) break; + + if (cmd == "c" || cmd == "cont" || cmd == "continue") { + if (kKernelDebugger.Continue()) { + kKeepRunning = true; + + kStdOut << "[+] Continuing...\n"; + + pfd::notify("Debugger Event", "Continuing..."); + } + } + + if (cmd == "d" || cmd == "detach") kKernelDebugger.Detach(); + + if (cmd == "start") { + kStdOut << "[?] Enter a argument to use: "; + std::getline(std::cin, cmd); + + kKernelDebugger.Attach(kPath, cmd, kPID); + } + + if (cmd == "exit") { + if (kPID > 0) kKernelDebugger.Detach(); + + break; + } + + if (cmd == "break" || cmd == "b") { + kStdOut << "[?] Enter a symbol to break on: "; + + std::getline(std::cin, cmd); + + if (kKernelDebugger.Breakpoint(cmd)) { + pfd::notify("Debugger Event", "Add Breakpoint at: " + cmd); + } + } + } + return EXIT_SUCCESS; } - kStdOut << "Usage: " << argv[0] << " -k \n"; - kStdOut << "Example: " << argv[0] << " -k /path/to/ne_kernel\n"; + kStdOut << "Usage: " << argv[0] << " -k -ip \n"; + kStdOut << "Example: " << argv[0] << " -k /path/to/ne_kernel -ip 127.0.0.1\n"; return EXIT_FAILURE; } diff --git a/dev/LibDebugger/src/POSIXMachContractCLI.cc b/dev/LibDebugger/src/POSIXMachContractCLI.cc index 1b3c8a2..d754643 100644 --- a/dev/LibDebugger/src/POSIXMachContractCLI.cc +++ b/dev/LibDebugger/src/POSIXMachContractCLI.cc @@ -41,7 +41,7 @@ LIBCOMPILER_MODULE(DebuggerMachPOSIX) { kStdOut << "[+] Image set to: " << kPath << "\n"; } - ::signal(SIGINT, dbgi_ctrlc_handler); + LibCompiler::(SIGINT, dbgi_ctrlc_handler); while (YES) { if (kKeepRunning) { -- cgit v1.2.3