1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
/***
DebuggerKit
(C) 2025 Amlal El Mahrouss
File: NeKernelContract.cc
Purpose: NeKernel Debugger CLI.
*/
#ifdef DK_NEKERNEL_DEBUGGER
#include <CompilerKit/Defines.h>
#include <DebuggerKit/NeKernelContract.h>
#include <ThirdParty/Dialogs.h>
#include <string>
#include <DebuggerKit/CommonCLI.inl>
using namespace DebuggerKit::NeKernel;
static void dbgi_ctrlc_handler(std::int32_t _) {
if (!kPID || kPath.empty()) {
return;
}
kKernelDebugger.Break();
pfd::notify("Debugger Event", "Breakpoint hit!");
kKeepRunning = false;
}
NECTI_MODULE(DebuggerNeKernel) {
pfd::notify("Debugger Event",
"NeKernel Debugger\n(C) 2025 Amlal El Mahrouss and NeKernel.org contributors, all "
"rights reserved.");
if (argc >= 5 && std::string(argv[1]) == "-k" && argv[2] != nullptr &&
std::string(argv[3]) == "-ip" && argv[4] != nullptr) {
kPath = argv[2];
kPath += ":";
kPath += argv[4];
kStdOut << "[+] KIP (Kernel:IP) set to: " << kPath << "\n";
CompilerKit::install_signal(SIGINT, dbgi_ctrlc_handler);
kKernelDebugger.Attach(kPath, argv[4], kPID);
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.BreakAt(cmd)) {
pfd::notify("Debugger Event", "Add BreakAt at: " + cmd);
}
}
}
return EXIT_SUCCESS;
}
kStdOut << "usage: " << argv[0] << " -k <kernel_path> -ip <ip4>\n";
kStdOut << "example: " << argv[0] << " -k /path/to/ne_kernel -ip 127.0.0.1\n";
return EXIT_FAILURE;
}
#endif // DK_NEKERNEL_DEBUGGER
|