| 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 "ble_mouse.h" |
| 13 | #include "sysinfo.h" |
| 14 | #include "BleMouse.h" |
| 15 | |
| 16 | // ================= MENU DATA ================= |
| 17 | extern BleMouse bleMouse; |
| 18 | |
| 19 | // Root menu |
| 20 | const char *mainMenuItems[] = { |
| 21 | "BadUSB", |
| 22 | "RF Capture", |
| 23 | "NRF Tools", |
| 24 | "BLE Scan", |
| 25 | "Wifi Scan", |
| 26 | "Wifi Analyzer", |
| 27 | "System Info", |
| 28 | "Device Check", |
| 29 | "Restart", |
| 30 | "Ble Mouse" |
| 31 | }; |
| 32 | |
| 33 | Menu mainMenu = {mainMenuItems, sizeof(mainMenuItems) / sizeof(mainMenuItems[0])}; |
| 34 | |
| 35 | |
| 36 | // NRF Tools menu |
| 37 | const char *nrfToolsItems[] = { |
| 38 | "BLE Jammer", |
| 39 | "Bluetooth Jammer", |
| 40 | "Wifi Jammer" |
| 41 | }; |
| 42 | |
| 43 | Menu nrfToolsMenu = {nrfToolsItems, sizeof(nrfToolsItems) / sizeof(nrfToolsItems[0])}; |
| 44 | |
| 45 | |
| 46 | // BadUSB submenu |
| 47 | const char *badusbItems[] = {"DEMO", |
| 48 | "KEYBOARD", |
| 49 | "HID SCRIPT", |
| 50 | "Open Notepad", |
| 51 | "Open CMD", |
| 52 | "Show IP", |
| 53 | "Shutdown", |
| 54 | "RickRoll", |
| 55 | "Create Admin", |
| 56 | "Disable Defender", |
| 57 | "Open YouTube", |
| 58 | "Lock PC", |
| 59 | "Fake Update", |
| 60 | "Endless Notepad", |
| 61 | "Fake BSOD", |
| 62 | "Flip Screen", |
| 63 | "Matrix Effect", |
| 64 | "I'm Watching U", |
| 65 | "Open Google", |
| 66 | "Open telegram", |
| 67 | "Play Alarm Sound", |
| 68 | "Endless CMD", |
| 69 | "Type Gibberish", |
| 70 | "Spam CAPSLOCK", |
| 71 | "Open Calc", |
| 72 | "Auto 'Hacked!'", |
| 73 | "Turn Off Monitor", |
| 74 | "Open RegEdit", |
| 75 | "Kill Explorer", |
| 76 | "Flash Screen", |
| 77 | "Rename Desktop", |
| 78 | "Toggle WiFi", |
| 79 | "Auto Screenshot", |
| 80 | "Spam Emojis", |
| 81 | "Open Ctrl Panel", |
| 82 | "Troll Wallpaper", |
| 83 | "Open MS Paint", |
| 84 | "Tab Switcher"}; |
| 85 | |
| 86 | |
| 87 | Menu badusbMenu = {badusbItems, sizeof(badusbItems) / sizeof(badusbItems[0])}; |
| 88 | |
| 89 | // ================= MENU STATE ================= |
| 90 | |
| 91 | Menu *currentMenu = &mainMenu; |
| 92 | |
| 93 | int menuIndex = 0; |
| 94 | int menuOffset = 0; |
| 95 | |
| 96 | #define MENU_VISIBLE_ROWS 4 |
| 97 | |
| 98 | bool insideFeature = false; |
| 99 | |
| 100 | // ================= DRAW ================= |
| 101 | |
| 102 | void drawMenu() |
| 103 | { |
| 104 | u8g2.clearBuffer(); |
| 105 | |
| 106 | // scroll handling |
| 107 | if (menuIndex < menuOffset) |
| 108 | menuOffset = menuIndex; |
| 109 | |
| 110 | if (menuIndex >= menuOffset + MENU_VISIBLE_ROWS) |
| 111 | menuOffset = menuIndex - MENU_VISIBLE_ROWS + 1; |
| 112 | |
| 113 | for (int i = 0; i < MENU_VISIBLE_ROWS; i++) |
| 114 | { |
| 115 | int item = menuOffset + i; |
| 116 | |
| 117 | if (item >= currentMenu->size) |
| 118 | break; |
| 119 | |
| 120 | if (item == menuIndex) |
| 121 | u8g2.drawStr(0, 14 + i * 14, ">"); |
| 122 | |
| 123 | u8g2.drawStr(10, 14 + i * 14, currentMenu->items[item]); |
| 124 | } |
| 125 | |
| 126 | // scroll indicators |
| 127 | if (menuOffset > 0) |
| 128 | u8g2.drawStr(118, 10, "^"); |
| 129 | |
| 130 | if (menuOffset + MENU_VISIBLE_ROWS < currentMenu->size) |
| 131 | u8g2.drawStr(118, 62, "v"); |
| 132 | |
| 133 | u8g2.sendBuffer(); |
| 134 | } |
| 135 | |
| 136 | // ================= FEATURE EXECUTION ================= |
| 137 | |
| 138 | void launchFeature() |
| 139 | { |
| 140 | insideFeature = true; |
| 141 | |
| 142 | if (currentMenu == &mainMenu) |
| 143 | { |
| 144 | switch (menuIndex) |
| 145 | { |
| 146 | case 0: // BadUSB → enter submenu |
| 147 | currentMenu = &badusbMenu; |
| 148 | menuIndex = 0; |
| 149 | menuOffset = 0; |
| 150 | break; |
| 151 | |
| 152 | case 1: |
| 153 | if (!isCC1101Ready()) { |
| 154 | if (!initCC1101()) { |
| 155 | Serial.println("CC1101 failed"); |
| 156 | return; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | Serial.println("Ready to capture..."); |
| 161 | |
| 162 | startCapture(); |
| 163 | delay(5000); |
| 164 | stopCapture(); |
| 165 | printCapture(); |
| 166 | break; |
| 167 | case 2: |
| 168 | // startNRFJammer(); |
| 169 | //startBleJammer(); |
| 170 | //startBluetoothJammer(); |
| 171 | currentMenu = &nrfToolsMenu; |
| 172 | menuIndex = 0; |
| 173 | menuOffset = 0; |
| 174 | break; |
| 175 | |
| 176 | break; |
| 177 | case 3: |
| 178 | ble_scan(); |
| 179 | ble_drawMenu(); |
| 180 | while (1) { |
| 181 | ble_loop(); |
| 182 | if (btnBack()) |
| 183 | break; |
| 184 | } |
| 185 | break; |
| 186 | |
| 187 | case 4: |
| 188 | { |
| 189 | // Start scan once |
| 190 | wifi_scan_start(); |
| 191 | wifi_scan_draw(); |
| 192 | |
| 193 | while (1) { |
| 194 | wifi_scan_loop(); |
| 195 | // EXIT condition handled ONLY here |
| 196 | if (btnBack()) { |
| 197 | delay(150); // debounce |
| 198 | break; |
| 199 | } |
| 200 | } |
| 201 | break; |
| 202 | } |
| 203 | case 5: |
| 204 | { |
| 205 | |
| 206 | wifi_analyzer_start(); |
| 207 | |
| 208 | bool prevBack = false; |
| 209 | while (1) |
| 210 | { |
| 211 | wifi_analyzer_loop(); |
| 212 | bool nowBack = btnBack(); |
| 213 | if (nowBack && !prevBack) |
| 214 | { |
| 215 | delay(150); |
| 216 | break; |
| 217 | } |
| 218 | prevBack = nowBack; |
| 219 | } |
| 220 | break; |
| 221 | } |
| 222 | |
| 223 | case 6: |
| 224 | runSystemInfoFeature(); |
| 225 | break; |
| 226 | case 7: |
| 227 | device_check_run(); |
| 228 | break; |
| 229 | case 8: |
| 230 | { |
| 231 | // wait for button release |
| 232 | delay(200); |
| 233 | |
| 234 | while (btnSelect()) |
| 235 | delay(10); |
| 236 | bool confirm = false; |
| 237 | |
| 238 | while (1) |
| 239 | { |
| 240 | u8g2.clearBuffer(); |
| 241 | u8g2.setFont(u8g2_font_6x13_tr); |
| 242 | |
| 243 | u8g2.drawStr(18, 18, "Restart Device?"); |
| 244 | |
| 245 | if (confirm) |
| 246 | { |
| 247 | u8g2.drawBox(10, 35, 45, 15); |
| 248 | u8g2.setDrawColor(0); |
| 249 | u8g2.drawStr(20, 47, "YES"); |
| 250 | u8g2.setDrawColor(1); |
| 251 | |
| 252 | u8g2.drawStr(75, 47, "NO"); |
| 253 | } |
| 254 | else |
| 255 | { |
| 256 | u8g2.drawStr(20, 47, "YES"); |
| 257 | |
| 258 | u8g2.drawBox(65, 35, 45, 15); |
| 259 | u8g2.setDrawColor(0); |
| 260 | u8g2.drawStr(78, 47, "NO"); |
| 261 | u8g2.setDrawColor(1); |
| 262 | } |
| 263 | |
| 264 | u8g2.sendBuffer(); |
| 265 | |
| 266 | if (btnLeft() || btnUp()) |
| 267 | { |
| 268 | confirm = true; |
| 269 | delay(150); |
| 270 | } |
| 271 | |
| 272 | if (btnRight() || btnDown()) |
| 273 | { |
| 274 | confirm = false; |
| 275 | delay(150); |
| 276 | } |
| 277 | |
| 278 | if (btnSelect()) |
| 279 | { |
| 280 | delay(150); |
| 281 | |
| 282 | if (confirm) |
| 283 | { |
| 284 | u8g2.clearBuffer(); |
| 285 | u8g2.drawStr(28, 30, "Restarting..."); |
| 286 | u8g2.sendBuffer(); |
| 287 | |
| 288 | delay(1000); |
| 289 | ESP.restart(); |
| 290 | } |
| 291 | else |
| 292 | { |
| 293 | break; |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | if (btnBack()) |
| 298 | { |
| 299 | delay(150); |
| 300 | break; |
| 301 | } |
| 302 | } |
| 303 | } |
| 304 | break; |
| 305 | |
| 306 | case 9: |
| 307 | // Begin Ble mouse |
| 308 | bleMouse.begin(); |
| 309 | ble_mouse_run(); |
| 310 | break; |
| 311 | } |
| 312 | } |
| 313 | else if (currentMenu == &badusbMenu) |
| 314 | { |
| 315 | badUSBMenu(menuIndex); |
| 316 | } else if (currentMenu == &nrfToolsMenu) { |
| 317 | NRFToolsMenu(menuIndex); |
| 318 | } |
| 319 | |
| 320 | insideFeature = false; |
| 321 | |
| 322 | drawMenu(); |
| 323 | } |
| 324 | |
| 325 | // ================= INIT ================= |
| 326 | |
| 327 | void menuInit() |
| 328 | { |
| 329 | currentMenu = &mainMenu; |
| 330 | menuIndex = 0; |
| 331 | menuOffset = 0; |
| 332 | |
| 333 | drawMenu(); |
| 334 | } |
| 335 | |
| 336 | // ================= LOOP ================= |
| 337 | |
| 338 | void menuLoop() |
| 339 | { |
| 340 | static uint32_t lastPress = 0; |
| 341 | |
| 342 | if (insideFeature) |
| 343 | return; |
| 344 | |
| 345 | if (millis() - lastPress < 150) |
| 346 | return; |
| 347 | |
| 348 | if (btnUp()) |
| 349 | { |
| 350 | menuIndex--; |
| 351 | |
| 352 | if (menuIndex < 0) |
| 353 | menuIndex = currentMenu->size - 1; |
| 354 | |
| 355 | drawMenu(); |
| 356 | lastPress = millis(); |
| 357 | } |
| 358 | |
| 359 | else if (btnDown()) |
| 360 | { |
| 361 | menuIndex++; |
| 362 | |
| 363 | if (menuIndex >= currentMenu->size) |
| 364 | menuIndex = 0; |
| 365 | |
| 366 | drawMenu(); |
| 367 | lastPress = millis(); |
| 368 | } |
| 369 | |
| 370 | else if (btnSelect()) |
| 371 | { |
| 372 | launchFeature(); |
| 373 | lastPress = millis(); |
| 374 | } |
| 375 | |
| 376 | else if (btnBack()) |
| 377 | { |
| 378 | if (currentMenu != &mainMenu) |
| 379 | { |
| 380 | currentMenu = &mainMenu; |
| 381 | menuIndex = 0; |
| 382 | menuOffset = 0; |
| 383 | |
| 384 | drawMenu(); |
| 385 | } |
| 386 | |
| 387 | lastPress = millis(); |
| 388 | } |
| 389 | } |