diff --git a/applications/main/bad_kb/helpers/ducky_script.c b/applications/main/bad_kb/helpers/ducky_script.c index b94ab73b3d..e7f41b3ed3 100644 --- a/applications/main/bad_kb/helpers/ducky_script.c +++ b/applications/main/bad_kb/helpers/ducky_script.c @@ -382,6 +382,7 @@ static void ducky_script_preload(BadKbScript* bad_kb, File* script_file) { app->has_usb_id = strncmp(line_tmp, ducky_cmd_id, strlen(ducky_cmd_id)) == 0; app->has_bt_id = strncmp(line_tmp, ducky_cmd_bt_id, strlen(ducky_cmd_bt_id)) == 0; + // Auto-switch to mode chosen with ID/BT_ID, can override manually in config screen if(app->has_usb_id) { app->is_bt = false; app->set_usb_id = ducky_set_usb_id(bad_kb, &line_tmp[strlen(ducky_cmd_id) + 1]); diff --git a/applications/main/bad_kb/scenes/bad_kb_scene_config.c b/applications/main/bad_kb/scenes/bad_kb_scene_config.c index ca5ec64000..3083e86960 100644 --- a/applications/main/bad_kb/scenes/bad_kb_scene_config.c +++ b/applications/main/bad_kb/scenes/bad_kb_scene_config.c @@ -52,11 +52,6 @@ void bad_kb_scene_config_on_enter(void* context) { var_item_list, "Connection", 2, bad_kb_scene_config_connection_callback, bad_kb); variable_item_set_current_value_index(item, bad_kb->is_bt); variable_item_set_current_value_text(item, bad_kb->is_bt ? "BT" : "USB"); - if(bad_kb->has_usb_id) { - variable_item_set_locked(item, true, "Script has\nID cmd!\nLocked to\nUSB Mode!"); - } else if(bad_kb->has_bt_id) { - variable_item_set_locked(item, true, "Script has\nBT_ID cmd!\nLocked to\nBT Mode!"); - } if(bad_kb->is_bt) { item = variable_item_list_add( @@ -65,43 +60,24 @@ void bad_kb_scene_config_on_enter(void* context) { variable_item_set_current_value_text(item, bad_kb->bt_remember ? "ON" : "OFF"); item = variable_item_list_add(var_item_list, "BT Device Name", 0, NULL, bad_kb); - if(bad_kb->set_bt_id) { - variable_item_set_locked(item, true, "Script has\nBT_ID cmd!\nLocked to\nset Name!"); - } item = variable_item_list_add(var_item_list, "BT MAC Address", 0, NULL, bad_kb); if(bad_kb->bt_remember) { variable_item_set_locked(item, true, "Remember\nmust be Off!"); - } else if(bad_kb->set_bt_id) { - variable_item_set_locked(item, true, "Script has\nBT_ID cmd!\nLocked to\nset MAC!"); } item = variable_item_list_add(var_item_list, "Randomize BT MAC", 0, NULL, bad_kb); if(bad_kb->bt_remember) { variable_item_set_locked(item, true, "Remember\nmust be Off!"); - } else if(bad_kb->set_bt_id) { - variable_item_set_locked(item, true, "Script has\nBT_ID cmd!\nLocked to\nset MAC!"); } } else { item = variable_item_list_add(var_item_list, "USB Manufacturer", 0, NULL, bad_kb); - if(bad_kb->set_usb_id) { - variable_item_set_locked(item, true, "Script has\nID cmd!\nLocked to\nset Mname!"); - } item = variable_item_list_add(var_item_list, "USB Product Name", 0, NULL, bad_kb); - if(bad_kb->set_usb_id) { - variable_item_set_locked(item, true, "Script has\nID cmd!\nLocked to\nset Pname!"); - } item = variable_item_list_add(var_item_list, "USB VID and PID", 0, NULL, bad_kb); - if(bad_kb->set_usb_id) { - variable_item_set_locked(item, true, "Script has\nID cmd!\nLocked to\nset IDs!"); - } item = variable_item_list_add(var_item_list, "Randomize USB VID:PID", 0, NULL, bad_kb); - if(bad_kb->set_usb_id) { - variable_item_set_locked(item, true, "Script has\nID cmd!\nLocked to\nset IDs!"); - } } variable_item_list_set_enter_callback( @@ -142,7 +118,15 @@ bool bad_kb_scene_config_on_event(void* context, SceneManagerEvent event) { scene_manager_next_scene(bad_kb->scene_manager, BadKbSceneConfigBtMac); break; case VarItemListIndexBtRandomizeMac: + // Set user config and remember furi_hal_random_fill_buf(bad_kb->config.ble.mac, sizeof(bad_kb->config.ble.mac)); + // Apply to ID config so its temporarily overridden + if(bad_kb->set_bt_id) { + memcpy( + bad_kb->id_config.ble.mac, + bad_kb->config.ble.mac, + sizeof(bad_kb->id_config.ble.mac)); + } bad_kb_config_refresh(bad_kb); break; default: @@ -166,8 +150,14 @@ bool bad_kb_scene_config_on_event(void* context, SceneManagerEvent event) { case VarItemListIndexUsbRandomizeVidPid: furi_hal_random_fill_buf( (void*)bad_kb->usb_vidpid_buf, sizeof(bad_kb->usb_vidpid_buf)); + // Set user config and remember bad_kb->config.usb.vid = bad_kb->usb_vidpid_buf[0]; bad_kb->config.usb.pid = bad_kb->usb_vidpid_buf[1]; + // Apply to ID config so its temporarily overridden + if(bad_kb->set_usb_id) { + bad_kb->id_config.usb.vid = bad_kb->config.usb.vid; + bad_kb->id_config.usb.pid = bad_kb->config.usb.pid; + } bad_kb_config_refresh(bad_kb); break; default: diff --git a/applications/main/bad_kb/scenes/bad_kb_scene_config_bt_mac.c b/applications/main/bad_kb/scenes/bad_kb_scene_config_bt_mac.c index 5439c0bc4c..ea9849448e 100644 --- a/applications/main/bad_kb/scenes/bad_kb_scene_config_bt_mac.c +++ b/applications/main/bad_kb/scenes/bad_kb_scene_config_bt_mac.c @@ -10,7 +10,10 @@ void bad_kb_scene_config_bt_mac_on_enter(void* context) { BadKbApp* bad_kb = context; ByteInput* byte_input = bad_kb->byte_input; - memcpy(bad_kb->bt_mac_buf, bad_kb->config.ble.mac, sizeof(bad_kb->bt_mac_buf)); + memcpy( + bad_kb->bt_mac_buf, + bad_kb->set_bt_id ? bad_kb->id_config.ble.mac : bad_kb->config.ble.mac, + sizeof(bad_kb->bt_mac_buf)); furi_hal_bt_reverse_mac_addr(bad_kb->bt_mac_buf); byte_input_set_header_text(byte_input, "Set BT MAC address"); @@ -33,7 +36,15 @@ bool bad_kb_scene_config_bt_mac_on_event(void* context, SceneManagerEvent event) consumed = true; if(event.event == BadKbAppCustomEventByteInputDone) { furi_hal_bt_reverse_mac_addr(bad_kb->bt_mac_buf); + // Set user config and remember memcpy(bad_kb->config.ble.mac, bad_kb->bt_mac_buf, sizeof(bad_kb->config.ble.mac)); + // Apply to ID config so its temporarily overridden + if(bad_kb->set_bt_id) { + memcpy( + bad_kb->id_config.ble.mac, + bad_kb->bt_mac_buf, + sizeof(bad_kb->id_config.ble.mac)); + } bad_kb_config_refresh(bad_kb); } scene_manager_previous_scene(bad_kb->scene_manager); diff --git a/applications/main/bad_kb/scenes/bad_kb_scene_config_bt_name.c b/applications/main/bad_kb/scenes/bad_kb_scene_config_bt_name.c index 04a02aed40..67a92c6bf1 100644 --- a/applications/main/bad_kb/scenes/bad_kb_scene_config_bt_name.c +++ b/applications/main/bad_kb/scenes/bad_kb_scene_config_bt_name.c @@ -10,7 +10,10 @@ void bad_kb_scene_config_bt_name_on_enter(void* context) { BadKbApp* bad_kb = context; TextInput* text_input = bad_kb->text_input; - strlcpy(bad_kb->bt_name_buf, bad_kb->config.ble.name, sizeof(bad_kb->bt_name_buf)); + strlcpy( + bad_kb->bt_name_buf, + bad_kb->set_bt_id ? bad_kb->id_config.ble.name : bad_kb->config.ble.name, + sizeof(bad_kb->bt_name_buf)); text_input_set_header_text(text_input, "Set BT device name"); text_input_set_result_callback( @@ -31,7 +34,15 @@ bool bad_kb_scene_config_bt_name_on_event(void* context, SceneManagerEvent event if(event.type == SceneManagerEventTypeCustom) { consumed = true; if(event.event == BadKbAppCustomEventTextInputDone) { + // Set user config and remember strlcpy(bad_kb->config.ble.name, bad_kb->bt_name_buf, sizeof(bad_kb->config.ble.name)); + // Apply to ID config so its temporarily overridden + if(bad_kb->set_bt_id) { + strlcpy( + bad_kb->id_config.ble.name, + bad_kb->bt_name_buf, + sizeof(bad_kb->id_config.ble.name)); + } bad_kb_config_refresh(bad_kb); } scene_manager_previous_scene(bad_kb->scene_manager); diff --git a/applications/main/bad_kb/scenes/bad_kb_scene_config_usb_name.c b/applications/main/bad_kb/scenes/bad_kb_scene_config_usb_name.c index c7dd7a2fa3..0cd9da1c86 100644 --- a/applications/main/bad_kb/scenes/bad_kb_scene_config_usb_name.c +++ b/applications/main/bad_kb/scenes/bad_kb_scene_config_usb_name.c @@ -11,10 +11,16 @@ void bad_kb_scene_config_usb_name_on_enter(void* context) { TextInput* text_input = bad_kb->text_input; if(scene_manager_get_scene_state(bad_kb->scene_manager, BadKbSceneConfigUsbName)) { - strlcpy(bad_kb->usb_name_buf, bad_kb->config.usb.manuf, sizeof(bad_kb->usb_name_buf)); + strlcpy( + bad_kb->usb_name_buf, + bad_kb->set_usb_id ? bad_kb->id_config.usb.manuf : bad_kb->config.usb.manuf, + sizeof(bad_kb->usb_name_buf)); text_input_set_header_text(text_input, "Set USB manufacturer name"); } else { - strlcpy(bad_kb->usb_name_buf, bad_kb->config.usb.product, sizeof(bad_kb->usb_name_buf)); + strlcpy( + bad_kb->usb_name_buf, + bad_kb->set_usb_id ? bad_kb->id_config.usb.product : bad_kb->config.usb.product, + sizeof(bad_kb->usb_name_buf)); text_input_set_header_text(text_input, "Set USB product name"); } @@ -37,15 +43,31 @@ bool bad_kb_scene_config_usb_name_on_event(void* context, SceneManagerEvent even consumed = true; if(event.event == BadKbAppCustomEventTextInputDone) { if(scene_manager_get_scene_state(bad_kb->scene_manager, BadKbSceneConfigUsbName)) { + // Set user config and remember strlcpy( bad_kb->config.usb.manuf, bad_kb->usb_name_buf, - sizeof(bad_kb->config.usb.product)); + sizeof(bad_kb->config.usb.manuf)); + // Apply to ID config so its temporarily overridden + if(bad_kb->set_usb_id) { + strlcpy( + bad_kb->id_config.usb.manuf, + bad_kb->usb_name_buf, + sizeof(bad_kb->id_config.usb.manuf)); + } } else { + // Set user config and remember strlcpy( bad_kb->config.usb.product, bad_kb->usb_name_buf, sizeof(bad_kb->config.usb.product)); + // Apply to ID config so its temporarily overridden + if(bad_kb->set_usb_id) { + strlcpy( + bad_kb->id_config.usb.product, + bad_kb->usb_name_buf, + sizeof(bad_kb->id_config.usb.product)); + } } bad_kb_config_refresh(bad_kb); } diff --git a/applications/main/bad_kb/scenes/bad_kb_scene_config_usb_vidpid.c b/applications/main/bad_kb/scenes/bad_kb_scene_config_usb_vidpid.c index 33f899f410..43b1314655 100644 --- a/applications/main/bad_kb/scenes/bad_kb_scene_config_usb_vidpid.c +++ b/applications/main/bad_kb/scenes/bad_kb_scene_config_usb_vidpid.c @@ -10,8 +10,13 @@ void bad_kb_scene_config_usb_vidpid_on_enter(void* context) { BadKbApp* bad_kb = context; ByteInput* byte_input = bad_kb->byte_input; - bad_kb->usb_vidpid_buf[0] = __REVSH(bad_kb->config.usb.vid); - bad_kb->usb_vidpid_buf[1] = __REVSH(bad_kb->config.usb.pid); + if(bad_kb->set_usb_id) { + bad_kb->usb_vidpid_buf[0] = __REVSH(bad_kb->id_config.usb.vid); + bad_kb->usb_vidpid_buf[1] = __REVSH(bad_kb->id_config.usb.pid); + } else { + bad_kb->usb_vidpid_buf[0] = __REVSH(bad_kb->config.usb.vid); + bad_kb->usb_vidpid_buf[1] = __REVSH(bad_kb->config.usb.pid); + } byte_input_set_header_text(byte_input, "Set USB VID:PID"); byte_input_set_result_callback( @@ -32,8 +37,14 @@ bool bad_kb_scene_config_usb_vidpid_on_event(void* context, SceneManagerEvent ev if(event.type == SceneManagerEventTypeCustom) { consumed = true; if(event.event == BadKbAppCustomEventByteInputDone) { + // Set user config and remember bad_kb->config.usb.vid = __REVSH(bad_kb->usb_vidpid_buf[0]); bad_kb->config.usb.pid = __REVSH(bad_kb->usb_vidpid_buf[1]); + // Apply to ID config so its temporarily overridden + if(bad_kb->set_usb_id) { + bad_kb->id_config.usb.vid = bad_kb->config.usb.vid; + bad_kb->id_config.usb.pid = bad_kb->config.usb.pid; + } bad_kb_config_refresh(bad_kb); } scene_manager_previous_scene(bad_kb->scene_manager);