mirror of
https://github.com/justcallmekoko/ESP32Marauder.git
synced 2025-12-22 23:26:45 -08:00
Load and modify ducky scripts
This commit is contained in:
@@ -5,6 +5,7 @@ extern const unsigned char menu_icons[][66];
|
||||
PROGMEM lv_obj_t * slider_label;
|
||||
PROGMEM lv_obj_t * ta1;
|
||||
PROGMEM lv_obj_t * ta2;
|
||||
PROGMEM lv_obj_t * save_name;
|
||||
|
||||
MenuFunctions::MenuFunctions()
|
||||
{
|
||||
@@ -137,6 +138,16 @@ void MenuFunctions::writeBadUSB(){
|
||||
label = lv_label_create(load_btn, NULL);
|
||||
lv_label_set_text(label, "Load");
|
||||
|
||||
// Create Save As button
|
||||
lv_obj_t * label2;
|
||||
lv_obj_t * save_as_btn = lv_btn_create(lv_scr_act(), NULL);
|
||||
lv_obj_set_event_cb(save_as_btn, load_btn_cb);
|
||||
lv_obj_set_height(save_as_btn, 35);
|
||||
lv_obj_set_width(save_as_btn, LV_HOR_RES / 3);
|
||||
lv_obj_align(save_as_btn, ta1, LV_ALIGN_IN_TOP_MID, NULL, (LV_VER_RES / 2) - 35); // align to text area
|
||||
label2 = lv_label_create(save_as_btn, NULL);
|
||||
lv_label_set_text(label2, "Save As");
|
||||
|
||||
// Focus it on one of the text areas to start
|
||||
lv_keyboard_set_textarea(kb, ta1);
|
||||
lv_keyboard_set_cursor_manage(kb, true);
|
||||
@@ -222,7 +233,18 @@ void MenuFunctions::joinWiFiGFX(){
|
||||
|
||||
}
|
||||
|
||||
// Function to create keyboard for saving file name
|
||||
void save_as_keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event) {
|
||||
if(event == LV_EVENT_APPLY){
|
||||
String display_string = "";
|
||||
printf("LV_EVENT_APPLY\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void test_btn_cb(lv_obj_t * btn, lv_event_t event) {
|
||||
extern MenuFunctions menu_function_obj;
|
||||
|
||||
if (event == LV_EVENT_CLICKED) {
|
||||
String btn_text = lv_list_get_btn_text(btn);
|
||||
String display_string = "";
|
||||
@@ -249,13 +271,29 @@ void test_btn_cb(lv_obj_t * btn, lv_event_t event) {
|
||||
}
|
||||
}
|
||||
|
||||
// Delete the file list obj
|
||||
lv_obj_del_async(lv_obj_get_parent(lv_obj_get_parent(btn)));
|
||||
menu_function_obj.loaded_file = btn_text;
|
||||
|
||||
// Create Save button
|
||||
lv_obj_t * save_label;
|
||||
lv_obj_t * save_btn = lv_btn_create(lv_scr_act(), NULL);
|
||||
lv_obj_set_event_cb(save_btn, load_btn_cb);
|
||||
lv_obj_set_height(save_btn, 35);
|
||||
lv_obj_set_width(save_btn, LV_HOR_RES / 3);
|
||||
lv_obj_align(save_btn, ta1, LV_ALIGN_IN_TOP_LEFT, NULL, (LV_VER_RES / 2) - 35); // align to text area
|
||||
save_label = lv_label_create(save_btn, NULL);
|
||||
lv_label_set_text(save_label, "Save");
|
||||
}
|
||||
}
|
||||
|
||||
void load_btn_cb(lv_obj_t * load_btn, lv_event_t event) {
|
||||
extern SDInterface sd_obj;
|
||||
extern MenuFunctions menu_function_obj;
|
||||
|
||||
String btn_text = lv_list_get_btn_text(load_btn);
|
||||
|
||||
if (btn_text == "Load") {
|
||||
if (event == LV_EVENT_CLICKED)
|
||||
Serial.println("Load button pressed");
|
||||
else if (event == LV_EVENT_RELEASED) {
|
||||
@@ -270,7 +308,7 @@ void load_btn_cb(lv_obj_t * load_btn, lv_event_t event) {
|
||||
// Load file names into buttons
|
||||
File scripts = SD.open("/SCRIPTS");
|
||||
|
||||
/*Add buttons to the list*/
|
||||
// Build list of files from the SD card
|
||||
lv_obj_t * list_btn;
|
||||
|
||||
while (true) {
|
||||
@@ -295,34 +333,60 @@ void load_btn_cb(lv_obj_t * load_btn, lv_event_t event) {
|
||||
|
||||
scripts.close();
|
||||
|
||||
/*
|
||||
list_btn = lv_list_add_btn(list1, LV_SYMBOL_FILE, "New");
|
||||
lv_obj_set_event_cb(list_btn, test_btn_cb);
|
||||
|
||||
list_btn = lv_list_add_btn(list1, LV_SYMBOL_DIRECTORY, "Open");
|
||||
lv_obj_set_event_cb(list_btn, test_btn_cb);
|
||||
|
||||
list_btn = lv_list_add_btn(list1, LV_SYMBOL_CLOSE, "Delete");
|
||||
lv_obj_set_event_cb(list_btn, test_btn_cb);
|
||||
|
||||
list_btn = lv_list_add_btn(list1, LV_SYMBOL_EDIT, "Edit");
|
||||
lv_obj_set_event_cb(list_btn, test_btn_cb);
|
||||
|
||||
list_btn = lv_list_add_btn(list1, LV_SYMBOL_SAVE, "Save");
|
||||
lv_obj_set_event_cb(list_btn, test_btn_cb);
|
||||
|
||||
list_btn = lv_list_add_btn(list1, LV_SYMBOL_BELL, "Notify");
|
||||
lv_obj_set_event_cb(list_btn, test_btn_cb);
|
||||
|
||||
list_btn = lv_list_add_btn(list1, LV_SYMBOL_BATTERY_FULL, "Battery");
|
||||
lv_obj_set_event_cb(list_btn, test_btn_cb);
|
||||
*/
|
||||
|
||||
list_btn = lv_list_add_btn(list1, LV_SYMBOL_CLOSE, "Cancel");
|
||||
lv_obj_set_event_cb(list_btn, test_btn_cb);
|
||||
}
|
||||
}
|
||||
|
||||
// Save current text bod content to new file
|
||||
else if (btn_text == "Save As") {
|
||||
if (event == LV_EVENT_CLICKED)
|
||||
Serial.println("Save button pressed");
|
||||
else if (event == LV_EVENT_RELEASED) {
|
||||
Serial.println("Save button released");
|
||||
|
||||
save_name = lv_textarea_create(lv_scr_act(), ta2);
|
||||
lv_textarea_set_cursor_hidden(save_name, false);
|
||||
lv_textarea_set_one_line(save_name, true);
|
||||
lv_obj_align(save_name, NULL, LV_ALIGN_IN_TOP_MID, NULL, (LV_VER_RES / 2) - 35);
|
||||
lv_textarea_set_text(save_name, "");
|
||||
lv_textarea_set_placeholder_text(save_name, "File Name");
|
||||
|
||||
// Create a keyboard and apply the styles
|
||||
lv_obj_t * save_as_kb = lv_keyboard_create(lv_scr_act(), NULL);
|
||||
lv_obj_set_size(save_as_kb, LV_HOR_RES, LV_VER_RES / 2);
|
||||
lv_obj_set_event_cb(save_as_kb, save_as_keyboard_event_cb);
|
||||
|
||||
lv_keyboard_set_textarea(save_as_kb, save_name);
|
||||
lv_keyboard_set_cursor_manage(save_as_kb, true);
|
||||
}
|
||||
}
|
||||
|
||||
// Save current text box content to current loaded file
|
||||
else if (btn_text == "Save") {
|
||||
if (event == LV_EVENT_CLICKED)
|
||||
Serial.println("Save button pressed");
|
||||
else if (event == LV_EVENT_RELEASED) {
|
||||
Serial.println("Save button released");
|
||||
|
||||
Serial.println("Writing to file: " + (String)menu_function_obj.loaded_file);
|
||||
|
||||
File script = SD.open(menu_function_obj.loaded_file, FILE_WRITE);
|
||||
|
||||
// Write data to file
|
||||
if (script) {
|
||||
String content = lv_textarea_get_text(ta1);
|
||||
|
||||
Serial.println("Writing content:");
|
||||
Serial.println(content);
|
||||
Serial.println("to file: " + (String)menu_function_obj.loaded_file);
|
||||
script.print(lv_textarea_get_text(ta1));
|
||||
script.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void write_bad_usb_keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event) {
|
||||
extern Display display_obj;
|
||||
extern MenuFunctions menu_function_obj;
|
||||
|
||||
@@ -90,6 +90,7 @@ PROGMEM static void add_ssid_keyboard_event_cb(lv_obj_t * keyboard, lv_event_t e
|
||||
PROGMEM static void write_bad_usb_keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event);
|
||||
PROGMEM static void load_btn_cb(lv_obj_t * load_btn, lv_event_t event);
|
||||
PROGMEM static void test_btn_cb(lv_obj_t * load_btn, lv_event_t event);
|
||||
PROGMEM static void save_as_keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event);
|
||||
|
||||
// lvgl stuff
|
||||
PROGMEM static lv_obj_t *kb;
|
||||
@@ -180,6 +181,8 @@ class MenuFunctions
|
||||
uint16_t x = -1, y = -1;
|
||||
boolean pressed = false;
|
||||
|
||||
String loaded_file = "";
|
||||
|
||||
void initLVGL();
|
||||
void deinitLVGL();
|
||||
void joinWiFiGFX();
|
||||
|
||||
Reference in New Issue
Block a user