Krolyxon
Commit 097b106

Branches

Tags

Refs →

orion-rffirmwaremenu.cpp

283 lines · 5.8 KB · C++

1#include <Arduino.h>
2#include "menu.h"
3#include "display.h"
4#include "buttons.h"
5#include "badusb.h"
6#include "nrf24.h"
7#include "cc1101.h"
8#include "blescanner.h"
9#include "wifi_scan.h"
10#include "wifi_analyzer.h"
11#include "device_check.h"
12#include "blemouse.h"
13
14// ================= FEATURE HANDLERS =================
15void runSystemInfoFeature();
16void runRFCaptureFeature();
17void runBLEScanFeature();
18
19
20
21// ================= MENU DATA =================
22
23// Root menu
24const char *mainMenuItems[] = {
25 "BadUSB",
26 "RF Capture",
27 "NRF Jammer",
28 "BLE Scan",
29 "Wifi Scan",
30 "Wifi Analyzer",
31 "System Info",
32 "Device Check",
33 "Restart",
34 "Ble Mouse"
35};
36
37Menu mainMenu = {mainMenuItems, sizeof(mainMenuItems) / sizeof(mainMenuItems[0])};
38
39// BadUSB submenu
40const char *badusbItems[] = {
41 "Demo",
42 "Open CMD",
43 "Rickroll"};
44
45Menu badusbMenu = {badusbItems, 3};
46
47// ================= MENU STATE =================
48
49Menu *currentMenu = &mainMenu;
50
51int menuIndex = 0;
52int menuOffset = 0;
53
54#define MENU_VISIBLE_ROWS 4
55
56bool insideFeature = false;
57
58// ================= DRAW =================
59
60void drawMenu()
61{
62 u8g2.clearBuffer();
63
64 // scroll handling
65 if (menuIndex < menuOffset)
66 menuOffset = menuIndex;
67
68 if (menuIndex >= menuOffset + MENU_VISIBLE_ROWS)
69 menuOffset = menuIndex - MENU_VISIBLE_ROWS + 1;
70
71 for (int i = 0; i < MENU_VISIBLE_ROWS; i++)
72 {
73 int item = menuOffset + i;
74
75 if (item >= currentMenu->size)
76 break;
77
78 if (item == menuIndex)
79 u8g2.drawStr(0, 14 + i * 14, ">");
80
81 u8g2.drawStr(10, 14 + i * 14, currentMenu->items[item]);
82 }
83
84 // scroll indicators
85 if (menuOffset > 0)
86 u8g2.drawStr(118, 10, "^");
87
88 if (menuOffset + MENU_VISIBLE_ROWS < currentMenu->size)
89 u8g2.drawStr(118, 62, "v");
90
91 u8g2.sendBuffer();
92}
93
94// ================= FEATURE EXECUTION =================
95
96void launchFeature()
97{
98 insideFeature = true;
99
100 if (currentMenu == &mainMenu)
101 {
102 switch (menuIndex)
103 {
104 case 0: // BadUSB → enter submenu
105 currentMenu = &badusbMenu;
106 menuIndex = 0;
107 menuOffset = 0;
108 break;
109
110 case 1:
111 if (!isCC1101Ready()) {
112 if (!initCC1101()) {
113 Serial.println("CC1101 failed");
114 return;
115 }
116 }
117
118 Serial.println("Ready to capture...");
119
120 startCapture();
121 delay(5000);
122 stopCapture();
123 printCapture();
124 break;
125 case 2:
126 startNRFJammer();
127 break;
128
129 case 3:
130 ble_scan();
131 ble_drawMenu();
132 while (1) {
133 ble_loop();
134 if (btnBack())
135 break;
136 }
137 break;
138
139 case 4:
140 {
141 // Start scan once
142 wifi_scan_start();
143 wifi_scan_draw();
144
145 while (1) {
146 wifi_scan_loop();
147 // EXIT condition handled ONLY here
148 if (btnBack()) {
149 delay(150); // debounce
150 break;
151 }
152 }
153 break;
154 }
155 case 5:
156 {
157
158 wifi_analyzer_start();
159
160 bool prevBack = false;
161 while (1)
162 {
163 wifi_analyzer_loop();
164 bool nowBack = btnBack();
165 if (nowBack && !prevBack)
166 {
167 delay(150);
168 break;
169 }
170 prevBack = nowBack;
171 }
172 break;
173 }
174
175 case 6:
176 runSystemInfoFeature();
177 break;
178 case 7:
179 device_check_run();
180 break;
181 case 8:
182 u8g2.clearBuffer();
183 u8g2.setFont(u8g2_font_6x13_tr);
184 u8g2.drawStr(30, 30, "Restarting...");
185 u8g2.sendBuffer();
186 delay(1000);
187 ESP.restart();
188 break;
189 case 9:
190 ble_mouse_run();
191 break;
192 }
193 }
194 else if (currentMenu == &badusbMenu)
195 {
196 switch (menuIndex)
197 {
198 case 0:
199 runBadUSBDemo();
200 break;
201
202 case 1:
203 Serial.println("Open CMD payload");
204 runBadUSBOpenCMD();
205 break;
206
207 case 2:
208 Serial.println("Rickroll payload");
209 runBadUSBRickroll();
210 break;
211 }
212 }
213
214 insideFeature = false;
215
216 drawMenu();
217}
218
219// ================= INIT =================
220
221void menuInit()
222{
223 currentMenu = &mainMenu;
224 menuIndex = 0;
225 menuOffset = 0;
226
227 drawMenu();
228}
229
230// ================= LOOP =================
231
232void menuLoop()
233{
234 static uint32_t lastPress = 0;
235
236 if (insideFeature)
237 return;
238
239 if (millis() - lastPress < 150)
240 return;
241
242 if (btnUp())
243 {
244 menuIndex--;
245
246 if (menuIndex < 0)
247 menuIndex = currentMenu->size - 1;
248
249 drawMenu();
250 lastPress = millis();
251 }
252
253 else if (btnDown())
254 {
255 menuIndex++;
256
257 if (menuIndex >= currentMenu->size)
258 menuIndex = 0;
259
260 drawMenu();
261 lastPress = millis();
262 }
263
264 else if (btnSelect())
265 {
266 launchFeature();
267 lastPress = millis();
268 }
269
270 else if (btnBack())
271 {
272 if (currentMenu != &mainMenu)
273 {
274 currentMenu = &mainMenu;
275 menuIndex = 0;
276 menuOffset = 0;
277
278 drawMenu();
279 }
280
281 lastPress = millis();
282 }
283}