| 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 | #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 | }; |
| 41 | |
| 42 | Menu nrfToolsMenu = {nrfToolsItems, sizeof(nrfToolsItems) / sizeof(nrfToolsItems[0])}; |
| 43 | |
| 44 | |
| 45 | // BadUSB submenu |
| 46 | const char *badusbItems[] = {"DEMO", |
| 47 | "KEYBOARD", |
| 48 | "HID SCRIPT", |
| 49 | "Open Notepad", |
| 50 | "Open CMD", |
| 51 | "Show IP", |
| 52 | "Shutdown", |
| 53 | "RickRoll", |
| 54 | "Create Admin", |
| 55 | "Disable Defender", |
| 56 | "Open YouTube", |
| 57 | "Lock PC", |
| 58 | "Fake Update", |
| 59 | "Endless Notepad", |
| 60 | "Fake BSOD", |
| 61 | "Flip Screen", |
| 62 | "Matrix Effect", |
| 63 | "I'm Watching U", |
| 64 | "Open Google", |
| 65 | "Open telegram", |
| 66 | "Play Alarm Sound", |
| 67 | "Endless CMD", |
| 68 | "Type Gibberish", |
| 69 | "Spam CAPSLOCK", |
| 70 | "Open Calc", |
| 71 | "Auto 'Hacked!'", |
| 72 | "Turn Off Monitor", |
| 73 | "Open RegEdit", |
| 74 | "Kill Explorer", |
| 75 | "Flash Screen", |
| 76 | "Rename Desktop", |
| 77 | "Toggle WiFi", |
| 78 | "Auto Screenshot", |
| 79 | "Spam Emojis", |
| 80 | "Open Ctrl Panel", |
| 81 | "Troll Wallpaper", |
| 82 | "Open MS Paint", |
| 83 | "Tab Switcher"}; |
| 84 | |
| 85 | |
| 86 | Menu badusbMenu = {badusbItems, sizeof(badusbItems) / sizeof(badusbItems[0])}; |
| 87 | |
| 88 | // ================= MENU STATE ================= |
| 89 | |
| 90 | Menu *currentMenu = &mainMenu; |
| 91 | |
| 92 | int menuIndex = 0; |
| 93 | int menuOffset = 0; |
| 94 | |
| 95 | #define MENU_VISIBLE_ROWS 4 |
| 96 | |
| 97 | bool insideFeature = false; |
| 98 | |
| 99 | // ================= DRAW ================= |
| 100 | |
| 101 | void drawMenu() |
| 102 | { |
| 103 | u8g2.clearBuffer(); |
| 104 | |
| 105 | // scroll handling |
| 106 | if (menuIndex < menuOffset) |
| 107 | menuOffset = menuIndex; |
| 108 | |
| 109 | if (menuIndex >= menuOffset + MENU_VISIBLE_ROWS) |
| 110 | menuOffset = menuIndex - MENU_VISIBLE_ROWS + 1; |
| 111 | |
| 112 | for (int i = 0; i < MENU_VISIBLE_ROWS; i++) |
| 113 | { |
| 114 | int item = menuOffset + i; |
| 115 | |
| 116 | if (item >= currentMenu->size) |
| 117 | break; |
| 118 | |
| 119 | if (item == menuIndex) |
| 120 | u8g2.drawStr(0, 14 + i * 14, ">"); |
| 121 | |
| 122 | u8g2.drawStr(10, 14 + i * 14, currentMenu->items[item]); |
| 123 | } |
| 124 | |
| 125 | // scroll indicators |
| 126 | if (menuOffset > 0) |
| 127 | u8g2.drawStr(118, 10, "^"); |
| 128 | |
| 129 | if (menuOffset + MENU_VISIBLE_ROWS < currentMenu->size) |
| 130 | u8g2.drawStr(118, 62, "v"); |
| 131 | |
| 132 | u8g2.sendBuffer(); |
| 133 | } |
| 134 | |
| 135 | // ================= FEATURE EXECUTION ================= |
| 136 | |
| 137 | void launchFeature() |
| 138 | { |
| 139 | insideFeature = true; |
| 140 | |
| 141 | if (currentMenu == &mainMenu) |
| 142 | { |
| 143 | switch (menuIndex) |
| 144 | { |
| 145 | case 0: // BadUSB → enter submenu |
| 146 | currentMenu = &badusbMenu; |
| 147 | menuIndex = 0; |
| 148 | menuOffset = 0; |
| 149 | break; |
| 150 | |
| 151 | case 1: |
| 152 | if (!isCC1101Ready()) { |
| 153 | if (!initCC1101()) { |
| 154 | Serial.println("CC1101 failed"); |
| 155 | return; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | Serial.println("Ready to capture..."); |
| 160 | |
| 161 | startCapture(); |
| 162 | delay(5000); |
| 163 | stopCapture(); |
| 164 | printCapture(); |
| 165 | break; |
| 166 | case 2: |
| 167 | // startNRFJammer(); |
| 168 | //startBleJammer(); |
| 169 | //startBluetoothJammer(); |
| 170 | currentMenu = &nrfToolsMenu; |
| 171 | menuIndex = 0; |
| 172 | menuOffset = 0; |
| 173 | break; |
| 174 | |
| 175 | break; |
| 176 | case 3: |
| 177 | ble_scan(); |
| 178 | ble_drawMenu(); |
| 179 | while (1) { |
| 180 | ble_loop(); |
| 181 | if (btnBack()) |
| 182 | break; |
| 183 | } |
| 184 | break; |
| 185 | |
| 186 | case 4: |
| 187 | { |
| 188 | // Start scan once |
| 189 | wifi_scan_start(); |
| 190 | wifi_scan_draw(); |
| 191 | |
| 192 | while (1) { |
| 193 | wifi_scan_loop(); |
| 194 | // EXIT condition handled ONLY here |
| 195 | if (btnBack()) { |
| 196 | delay(150); // debounce |
| 197 | break; |
| 198 | } |
| 199 | } |
| 200 | break; |
| 201 | } |
| 202 | case 5: |
| 203 | { |
| 204 | |
| 205 | wifi_analyzer_start(); |
| 206 | |
| 207 | bool prevBack = false; |
| 208 | while (1) |
| 209 | { |
| 210 | wifi_analyzer_loop(); |
| 211 | bool nowBack = btnBack(); |
| 212 | if (nowBack && !prevBack) |
| 213 | { |
| 214 | delay(150); |
| 215 | break; |
| 216 | } |
| 217 | prevBack = nowBack; |
| 218 | } |
| 219 | break; |
| 220 | } |
| 221 | |
| 222 | case 6: |
| 223 | runSystemInfoFeature(); |
| 224 | break; |
| 225 | case 7: |
| 226 | device_check_run(); |
| 227 | break; |
| 228 | case 8: |
| 229 | u8g2.clearBuffer(); |
| 230 | u8g2.setFont(u8g2_font_6x13_tr); |
| 231 | u8g2.drawStr(30, 30, "Restarting..."); |
| 232 | u8g2.sendBuffer(); |
| 233 | delay(1000); |
| 234 | ESP.restart(); |
| 235 | break; |
| 236 | case 9: |
| 237 | // Begin Ble mouse |
| 238 | bleMouse.begin(); |
| 239 | ble_mouse_run(); |
| 240 | break; |
| 241 | } |
| 242 | } |
| 243 | else if (currentMenu == &badusbMenu) |
| 244 | { |
| 245 | badUSBMenu(menuIndex); |
| 246 | } else if (currentMenu == &nrfToolsMenu) { |
| 247 | NRFToolsMenu(menuIndex); |
| 248 | } |
| 249 | |
| 250 | insideFeature = false; |
| 251 | |
| 252 | drawMenu(); |
| 253 | } |
| 254 | |
| 255 | // ================= INIT ================= |
| 256 | |
| 257 | void menuInit() |
| 258 | { |
| 259 | currentMenu = &mainMenu; |
| 260 | menuIndex = 0; |
| 261 | menuOffset = 0; |
| 262 | |
| 263 | drawMenu(); |
| 264 | } |
| 265 | |
| 266 | // ================= LOOP ================= |
| 267 | |
| 268 | void menuLoop() |
| 269 | { |
| 270 | static uint32_t lastPress = 0; |
| 271 | |
| 272 | if (insideFeature) |
| 273 | return; |
| 274 | |
| 275 | if (millis() - lastPress < 150) |
| 276 | return; |
| 277 | |
| 278 | if (btnUp()) |
| 279 | { |
| 280 | menuIndex--; |
| 281 | |
| 282 | if (menuIndex < 0) |
| 283 | menuIndex = currentMenu->size - 1; |
| 284 | |
| 285 | drawMenu(); |
| 286 | lastPress = millis(); |
| 287 | } |
| 288 | |
| 289 | else if (btnDown()) |
| 290 | { |
| 291 | menuIndex++; |
| 292 | |
| 293 | if (menuIndex >= currentMenu->size) |
| 294 | menuIndex = 0; |
| 295 | |
| 296 | drawMenu(); |
| 297 | lastPress = millis(); |
| 298 | } |
| 299 | |
| 300 | else if (btnSelect()) |
| 301 | { |
| 302 | launchFeature(); |
| 303 | lastPress = millis(); |
| 304 | } |
| 305 | |
| 306 | else if (btnBack()) |
| 307 | { |
| 308 | if (currentMenu != &mainMenu) |
| 309 | { |
| 310 | currentMenu = &mainMenu; |
| 311 | menuIndex = 0; |
| 312 | menuOffset = 0; |
| 313 | |
| 314 | drawMenu(); |
| 315 | } |
| 316 | |
| 317 | lastPress = millis(); |
| 318 | } |
| 319 | } |