Just Call Me Koko 5 лет назад
Родитель
Сommit
a1dd40a928

+ 10 - 9
esp32_marauder/Display.cpp

@@ -7,9 +7,9 @@ Big thanks to bodmer for having great TFT and JPEG libraries
 https://github.com/bodmer
 https://github.com/bodmer
 */
 */
 
 
-PROGMEM lv_obj_t * slider_label;
-PROGMEM lv_obj_t * ta1;
-PROGMEM lv_obj_t * ta2;
+//PROGMEM lv_obj_t * slider_label;
+//PROGMEM lv_obj_t * ta1;
+//PROGMEM lv_obj_t * ta2;
 
 
 Display::Display()
 Display::Display()
 {
 {
@@ -56,7 +56,7 @@ void Display::RunSetup()
     while (1) yield(); // Stay here twiddling thumbs waiting
     while (1) yield(); // Stay here twiddling thumbs waiting
   }
   }
 
 
-  this->initLVGL();
+  //this->initLVGL();
 
 
 
 
   // Draw the title screen
   // Draw the title screen
@@ -71,13 +71,14 @@ void Display::RunSetup()
 }
 }
 
 
 /* Interrupt driven periodic handler */
 /* Interrupt driven periodic handler */
-
+/*
 void Display::lv_tick_handler()
 void Display::lv_tick_handler()
 {
 {
   lv_tick_inc(LVGL_TICK_PERIOD);
   lv_tick_inc(LVGL_TICK_PERIOD);
-}
+}*/
 
 
 /* Display flushing */
 /* Display flushing */
+/*
 void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
 void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
 {
 {
   extern Display display_obj;
   extern Display display_obj;
@@ -137,7 +138,7 @@ bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data)
   }
   }
 
 
   return false;
   return false;
-}
+}*/
 
 
 void Display::tftDrawGraphObjects(byte x_scale)
 void Display::tftDrawGraphObjects(byte x_scale)
 {
 {
@@ -818,7 +819,7 @@ void Display::buildBanner(String msg, int xpos)
   img.print(msg);
   img.print(msg);
 }
 }
 
 
-
+/*
 void Display::initLVGL() {
 void Display::initLVGL() {
   tick.attach_ms(LVGL_TICK_PERIOD, lv_tick_handler);
   tick.attach_ms(LVGL_TICK_PERIOD, lv_tick_handler);
   
   
@@ -922,7 +923,7 @@ void ta_event_cb(lv_obj_t * ta, lv_event_t event)
   //    printf("Ready\n");
   //    printf("Ready\n");
   //  }
   //  }
   //}
   //}
-}
+}*/
 
 
 void Display::main(uint8_t scan_mode)
 void Display::main(uint8_t scan_mode)
 {  
 {  

+ 7 - 5
esp32_marauder/Display.h

@@ -58,6 +58,7 @@
 
 
 #define STATUSBAR_COLOR 0x4A49
 #define STATUSBAR_COLOR 0x4A49
 
 
+/*
 PROGMEM void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p);
 PROGMEM void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p);
 PROGMEM bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data);
 PROGMEM bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data);
 
 
@@ -69,6 +70,7 @@ PROGMEM static void keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event);
 
 
 // lvgl stuff
 // lvgl stuff
 PROGMEM static lv_obj_t *kb;
 PROGMEM static lv_obj_t *kb;
+*/
 
 
 class Display
 class Display
 {
 {
@@ -86,11 +88,11 @@ class Display
     //void addNodes(Menu* menu, String name, Menu* child, std::function<void()> callable);
     //void addNodes(Menu* menu, String name, Menu* child, std::function<void()> callable);
     //void changeMenu(Menu* menu);
     //void changeMenu(Menu* menu);
     //void showMenuList(Menu* menu, int layer);
     //void showMenuList(Menu* menu, int layer);
-    static void lv_tick_handler();
+    //static void lv_tick_handler();
 
 
   public:
   public:
     Display();
     Display();
-    Ticker tick;
+    //Ticker tick;
     TFT_eSPI tft = TFT_eSPI();
     TFT_eSPI tft = TFT_eSPI();
     TFT_eSprite img = TFT_eSprite(&tft);
     TFT_eSprite img = TFT_eSprite(&tft);
     TFT_eSPI_Button key[BUTTON_ARRAY_LEN];
     TFT_eSPI_Button key[BUTTON_ARRAY_LEN];
@@ -130,9 +132,9 @@ class Display
     // We can speed up scrolling of short text lines by just blanking the character we drew
     // We can speed up scrolling of short text lines by just blanking the character we drew
     int blank[19]; // We keep all the strings pixel lengths to optimise the speed of the top line blanking
     int blank[19]; // We keep all the strings pixel lengths to optimise the speed of the top line blanking
 
 
-    void initLVGL();
-    void deinitLVGL();
-    void joinWiFiGFX();
+    //void initLVGL();
+    //void deinitLVGL();
+    //void joinWiFiGFX();
     void tftDrawGraphObjects(byte x_scale);
     void tftDrawGraphObjects(byte x_scale);
     void tftDrawEapolColorKey();
     void tftDrawEapolColorKey();
     void tftDrawColorKey();
     void tftDrawColorKey();

+ 191 - 2
esp32_marauder/MenuFunctions.cpp

@@ -2,11 +2,192 @@
 //#include "icons.h"
 //#include "icons.h"
 
 
 extern const unsigned char menu_icons[][66];
 extern const unsigned char menu_icons[][66];
+PROGMEM lv_obj_t * slider_label;
+PROGMEM lv_obj_t * ta1;
+PROGMEM lv_obj_t * ta2;
 
 
 MenuFunctions::MenuFunctions()
 MenuFunctions::MenuFunctions()
 {
 {
 }
 }
 
 
+// LVGL Stuff
+/* Interrupt driven periodic handler */
+
+void MenuFunctions::lv_tick_handler()
+{
+  lv_tick_inc(LVGL_TICK_PERIOD);
+}
+
+/* Display flushing */
+void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
+{
+  extern Display display_obj;
+  uint16_t c;
+
+  display_obj.tft.startWrite();
+  display_obj.tft.setAddrWindow(area->x1, area->y1, (area->x2 - area->x1 + 1), (area->y2 - area->y1 + 1));
+  for (int y = area->y1; y <= area->y2; y++) {
+    for (int x = area->x1; x <= area->x2; x++) {
+      c = color_p->full;
+      display_obj.tft.writeColor(c, 1);
+      color_p++;
+    }
+  }
+  display_obj.tft.endWrite();
+  lv_disp_flush_ready(disp);
+}
+
+
+bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data)
+{
+  extern Display display_obj;
+  
+  uint16_t touchX, touchY;
+
+  bool touched = display_obj.tft.getTouch(&touchX, &touchY, 600);
+
+  if(!touched)
+  {
+    return false;
+  }
+
+  if(touchX>WIDTH_1 || touchY > HEIGHT_1)
+  {
+    Serial.println("Y or y outside of expected parameters..");
+    Serial.print("y:");
+    Serial.print(touchX);
+    Serial.print(" x:");
+    Serial.print(touchY);
+  }
+  else
+  {
+
+    data->state = touched ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL; 
+
+    //if(data->state == LV_INDEV_STATE_PR) touchpad_get_xy(&last_x, &last_y);
+   
+    data->point.x = touchX;
+    data->point.y = touchY;
+
+    Serial.print("Data x");
+    Serial.println(touchX);
+    
+    Serial.print("Data y");
+    Serial.println(touchY);
+
+  }
+
+  return false;
+}
+
+void MenuFunctions::initLVGL() {
+  tick.attach_ms(LVGL_TICK_PERIOD, lv_tick_handler);
+  
+  lv_init();
+
+  lv_disp_buf_init(&disp_buf, buf, NULL, LV_HOR_RES_MAX * 10);
+
+  lv_disp_drv_t disp_drv;
+  lv_disp_drv_init(&disp_drv);
+  disp_drv.hor_res = WIDTH_1;
+  disp_drv.ver_res = HEIGHT_1;
+  disp_drv.flush_cb = my_disp_flush;
+  disp_drv.buffer = &disp_buf;
+  lv_disp_drv_register(&disp_drv);
+
+  lv_indev_drv_t indev_drv;
+  lv_indev_drv_init(&indev_drv);             
+  indev_drv.type = LV_INDEV_TYPE_POINTER;    
+  indev_drv.read_cb = my_touchpad_read;      
+  lv_indev_drv_register(&indev_drv);         
+}
+
+
+void MenuFunctions::deinitLVGL() {
+  Serial.println(F("Deinit LVGL"));
+  //lv_deinit();
+}
+
+
+
+void MenuFunctions::joinWiFiGFX(){
+
+  // Create one text area
+  ta1 = lv_textarea_create(lv_scr_act(), NULL);
+  lv_textarea_set_one_line(ta1, true);
+  lv_obj_set_width(ta1, LV_HOR_RES / 2 - 20);
+  lv_obj_set_pos(ta1, 5, 20);
+  //lv_ta_set_cursor_type(ta, LV_CURSOR_BLOCK);
+  lv_textarea_set_text(ta1, "");
+  lv_obj_set_event_cb(ta1, ta_event_cb);
+
+  // Create first label
+  lv_obj_t * ssid_label = lv_label_create(lv_scr_act(), NULL);
+  lv_label_set_text(ssid_label, "SSID:");
+  lv_obj_align(ssid_label, ta1, LV_ALIGN_OUT_TOP_LEFT, 0, 0);
+
+  // Create second text area
+  ta2 = lv_textarea_create(lv_scr_act(), ta1);
+  //lv_textarea_set_pwd_mode(ta2, true); // This shit makes it so backspace does not work
+  //lv_textarea_set_pwd_show_time(ta2, 1000);
+  lv_textarea_set_cursor_hidden(ta2, true);
+  lv_obj_align(ta2, NULL, LV_ALIGN_IN_TOP_RIGHT, -5, 20);
+
+  // Create second label
+  lv_obj_t * pw_label = lv_label_create(lv_scr_act(), NULL);
+  lv_label_set_text(pw_label, "Password:");
+  lv_obj_align(pw_label, ta2, LV_ALIGN_OUT_TOP_LEFT, 0, 0);
+
+  // Create a keyboard and apply the styles
+  kb = lv_keyboard_create(lv_scr_act(), NULL);
+  lv_obj_set_size(kb, LV_HOR_RES, LV_VER_RES / 2);
+  lv_obj_set_event_cb(kb, keyboard_event_cb);
+
+  // Focus it on one of the text areas to start
+  lv_keyboard_set_textarea(kb, ta1);
+  lv_keyboard_set_cursor_manage(kb, true);
+  
+}
+
+
+void keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event){
+  extern Display display_obj;
+  extern MenuFunctions menu_function_obj;
+  extern WiFiScan wifi_scan_obj;
+  lv_keyboard_def_event_cb(kb, event);
+  if(event == LV_EVENT_APPLY){
+    printf("LV_EVENT_APPLY\n");
+    //String ta1_text = lv_textarea_get_text(lv_keyboard_get_textarea(kb));
+    String ta1_text = lv_textarea_get_text(ta1);
+    String ta2_text = lv_textarea_get_text(ta2);
+    Serial.println(ta1_text);
+    Serial.println(ta2_text);
+    wifi_scan_obj.joinWiFi(ta1_text, ta2_text);
+  }else if(event == LV_EVENT_CANCEL){
+    printf("LV_EVENT_CANCEL\n");
+    //lv_textarea_set_text(lv_keyboard_get_textarea(kb), "");
+    menu_function_obj.deinitLVGL();
+    wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
+    display_obj.exit_draw = true; // set everything back to normal
+  }
+}
+
+
+void ta_event_cb(lv_obj_t * ta, lv_event_t event)
+{
+  if(event == LV_EVENT_CLICKED) {
+    if(kb != NULL)
+      lv_keyboard_set_textarea(kb, ta);
+  }
+
+  //else if(event == LV_EVENT_INSERT) {
+  //  const char * str = lv_event_get_data();
+  //  if(str[0] == '\n') {
+  //    printf("Ready\n");
+  //  }
+  //}
+}
+
 // Function to check menu input
 // Function to check menu input
 void MenuFunctions::main(uint32_t currentTime)
 void MenuFunctions::main(uint32_t currentTime)
 {
 {
@@ -414,6 +595,8 @@ void MenuFunctions::orientDisplay()
 // Function to build the menus
 // Function to build the menus
 void MenuFunctions::RunSetup()
 void MenuFunctions::RunSetup()
 {
 {
+  this->initLVGL();
+  
   // root menu stuff
   // root menu stuff
   mainMenu.list = new LinkedList<MenuNode>(); // Get list in first menu ready
   mainMenu.list = new LinkedList<MenuNode>(); // Get list in first menu ready
 
 
@@ -547,6 +730,13 @@ void MenuFunctions::RunSetup()
     this->drawStatusBar();
     this->drawStatusBar();
     wifi_scan_obj.StartScan(WIFI_ATTACK_RICK_ROLL, TFT_YELLOW);
     wifi_scan_obj.StartScan(WIFI_ATTACK_RICK_ROLL, TFT_YELLOW);
   });
   });
+  addNodes(&wifiAttackMenu, "Join WiFi", TFT_DARKCYAN, NULL, SNIFFERS, [this](){
+    display_obj.clearScreen(); 
+    wifi_scan_obj.currentScanMode = LV_JOIN_WIFI; 
+    wifi_scan_obj.StartScan(LV_JOIN_WIFI, TFT_YELLOW); 
+    joinWiFiGFX();
+  });
+
 
 
   // Build Bluetooth Menu
   // Build Bluetooth Menu
   bluetoothMenu.parentMenu = &mainMenu; // Second Menu is third menu parent
   bluetoothMenu.parentMenu = &mainMenu; // Second Menu is third menu parent
@@ -609,8 +799,7 @@ void MenuFunctions::RunSetup()
     changeMenu(&infoMenu);
     changeMenu(&infoMenu);
     wifi_scan_obj.RunInfo();
     wifi_scan_obj.RunInfo();
   });
   });
-  addNodes(&deviceMenu, "Join WiFi", TFT_YELLOW, NULL, SNIFFERS, [this](){display_obj.clearScreen(); wifi_scan_obj.currentScanMode = LV_JOIN_WIFI; wifi_scan_obj.StartScan(LV_JOIN_WIFI, TFT_YELLOW);});
-
+ 
   // Select update
   // Select update
   whichUpdateMenu.parentMenu = &deviceMenu;
   whichUpdateMenu.parentMenu = &deviceMenu;
   addNodes(&whichUpdateMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {
   addNodes(&whichUpdateMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {

+ 20 - 0
esp32_marauder/MenuFunctions.h

@@ -65,6 +65,18 @@ extern BatteryInterface battery_obj;
 #define PWNAGOTCHI 24
 #define PWNAGOTCHI 24
 #define ESPRESSIF 25
 #define ESPRESSIF 25
 
 
+PROGMEM void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p);
+PROGMEM bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data);
+
+PROGMEM static lv_disp_buf_t disp_buf;
+PROGMEM static lv_color_t buf[LV_HOR_RES_MAX * 10];
+
+PROGMEM static void ta_event_cb(lv_obj_t * ta, lv_event_t event);
+PROGMEM static void keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event);
+
+// lvgl stuff
+PROGMEM static lv_obj_t *kb;
+
 struct Menu;
 struct Menu;
 
 
 // Individual Nodes of a menu
 // Individual Nodes of a menu
@@ -120,6 +132,8 @@ class MenuFunctions
     Menu bluetoothSnifferMenu;
     Menu bluetoothSnifferMenu;
     Menu bluetoothScannerMenu;
     Menu bluetoothScannerMenu;
 
 
+    static void lv_tick_handler();
+
     // Menu icons
     // Menu icons
 
 
 
 
@@ -136,9 +150,15 @@ class MenuFunctions
   public:
   public:
     MenuFunctions();
     MenuFunctions();
 
 
+    Ticker tick;
+
     uint16_t x = -1, y = -1;
     uint16_t x = -1, y = -1;
     boolean pressed = false;
     boolean pressed = false;
 
 
+    void initLVGL();
+    void deinitLVGL();
+    void joinWiFiGFX();
+
     void buildButtons(Menu* menu);
     void buildButtons(Menu* menu);
     void changeMenu(Menu* menu);
     void changeMenu(Menu* menu);
     void displayCurrentMenu();
     void displayCurrentMenu();

+ 54 - 2
esp32_marauder/WiFiScan.cpp

@@ -135,6 +135,57 @@ void WiFiScan::RunSetup() {
   this->shutdownBLE();
   this->shutdownBLE();
 }
 }
 
 
+void WiFiScan::joinWiFi(String ssid, String password)
+{
+  static const char * btns[] ={"Close", ""};
+  int count = 0;
+  
+  if ((WiFi.status() == WL_CONNECTED) && (ssid == connected_network) && (ssid != "")) {
+    lv_obj_t * mbox1 = lv_msgbox_create(lv_scr_act(), NULL);
+    lv_msgbox_set_text(mbox1, "Already Connected");
+    lv_msgbox_add_btns(mbox1, btns);
+    lv_obj_set_width(mbox1, 200);
+    //lv_obj_set_event_cb(mbox1, event_handler);
+    lv_obj_align(mbox1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align to the corner*/
+    return;
+  }
+  else if (WiFi.status() == WL_CONNECTED)
+    WiFi.disconnect();
+    
+  WiFi.begin(ssid.c_str(), password.c_str());
+
+  Serial.print("Connecting to WiFi");
+  while (WiFi.status() != WL_CONNECTED) {
+    delay(500);
+    Serial.print(".");
+    count++;
+    if (count == 10)
+    {
+      Serial.println("\nCould not connect to WiFi network");
+      lv_obj_t * mbox1 = lv_msgbox_create(lv_scr_act(), NULL);
+      lv_msgbox_set_text(mbox1, "Failed to connect");
+      lv_msgbox_add_btns(mbox1, btns);
+      lv_obj_set_width(mbox1, 200);
+      //lv_obj_set_event_cb(mbox1, event_handler);
+      lv_obj_align(mbox1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align to the corner*/
+      return;
+    }
+  }
+
+  lv_obj_t * mbox1 = lv_msgbox_create(lv_scr_act(), NULL);
+  lv_msgbox_set_text(mbox1, "Connected");
+  lv_msgbox_add_btns(mbox1, btns);
+  lv_obj_set_width(mbox1, 200);
+  //lv_obj_set_event_cb(mbox1, event_handler);
+  lv_obj_align(mbox1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align to the corner*/
+
+  connected_network = ssid;
+  
+  Serial.println("\nConnected to the WiFi network");
+  Serial.print("IP address: ");
+  Serial.println(WiFi.localIP());
+}
+
 // Function to prepare to run a specific scan
 // Function to prepare to run a specific scan
 void WiFiScan::StartScan(uint8_t scan_mode, uint16_t color)
 void WiFiScan::StartScan(uint8_t scan_mode, uint16_t color)
 {  
 {  
@@ -211,7 +262,8 @@ void WiFiScan::StopScan(uint8_t scan_mode)
   (currentScanMode == WIFI_SCAN_DEAUTH) ||
   (currentScanMode == WIFI_SCAN_DEAUTH) ||
   (currentScanMode == WIFI_ATTACK_BEACON_SPAM) ||
   (currentScanMode == WIFI_ATTACK_BEACON_SPAM) ||
   (currentScanMode == WIFI_ATTACK_RICK_ROLL) ||
   (currentScanMode == WIFI_ATTACK_RICK_ROLL) ||
-  (currentScanMode == WIFI_PACKET_MONITOR))
+  (currentScanMode == WIFI_PACKET_MONITOR) ||
+  (currentScanMode == LV_JOIN_WIFI))
   {
   {
     this->shutdownWiFi();
     this->shutdownWiFi();
   }
   }
@@ -322,7 +374,7 @@ void WiFiScan::RunLvJoinWiFi(uint8_t scan_mode, uint16_t color) {
   lv_obj_t * scr = lv_cont_create(NULL, NULL);
   lv_obj_t * scr = lv_cont_create(NULL, NULL);
   lv_disp_load_scr(scr);
   lv_disp_load_scr(scr);
 
 
-  display_obj.joinWiFiGFX();
+  //display_obj.joinWiFiGFX();
 }
 }
 
 
 void WiFiScan::RunInfo()
 void WiFiScan::RunInfo()

+ 3 - 1
esp32_marauder/WiFiScan.h

@@ -82,7 +82,7 @@ class WiFiScan
     const wifi_promiscuous_filter_t filt = {.filter_mask=WIFI_PROMIS_FILTER_MASK_MGMT | WIFI_PROMIS_FILTER_MASK_DATA};
     const wifi_promiscuous_filter_t filt = {.filter_mask=WIFI_PROMIS_FILTER_MASK_MGMT | WIFI_PROMIS_FILTER_MASK_DATA};
     BLEScan* pBLEScan;
     BLEScan* pBLEScan;
 
 
-    String connected_network = "";
+    //String connected_network = "";
     String alfa = "1234567890qwertyuiopasdfghjkklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM_";
     String alfa = "1234567890qwertyuiopasdfghjkklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM_";
 
 
     char* rick_roll[8] = {
     char* rick_roll[8] = {
@@ -162,6 +162,7 @@ class WiFiScan
 
 
     String free_ram = "";
     String free_ram = "";
     String old_free_ram = "";
     String old_free_ram = "";
+    String connected_network = "";
 
 
     //lv_obj_t * scr = lv_cont_create(NULL, NULL);
     //lv_obj_t * scr = lv_cont_create(NULL, NULL);
 
 
@@ -170,6 +171,7 @@ class WiFiScan
     void RunSetup();
     void RunSetup();
     void shutdownWiFi();
     void shutdownWiFi();
     void shutdownBLE();
     void shutdownBLE();
+    void joinWiFi(String ssid, String password);
     String getStaMAC();
     String getStaMAC();
     String getApMAC();
     String getApMAC();
     String freeRAM();
     String freeRAM();