Skip to content

Commit

Permalink
BadKB allow overriding mode+options with ID/BT_ID cmd (the right way)
Browse files Browse the repository at this point in the history
  • Loading branch information
Willy-JL committed Mar 3, 2024
1 parent 08afaa6 commit 384c3f1
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 31 deletions.
1 change: 1 addition & 0 deletions applications/main/bad_kb/helpers/ducky_script.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
38 changes: 14 additions & 24 deletions applications/main/bad_kb/scenes/bad_kb_scene_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
13 changes: 12 additions & 1 deletion applications/main/bad_kb/scenes/bad_kb_scene_config_bt_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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);
Expand Down
13 changes: 12 additions & 1 deletion applications/main/bad_kb/scenes/bad_kb_scene_config_bt_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
Expand Down
28 changes: 25 additions & 3 deletions applications/main/bad_kb/scenes/bad_kb_scene_config_usb_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand All @@ -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);
}
Expand Down
15 changes: 13 additions & 2 deletions applications/main/bad_kb/scenes/bad_kb_scene_config_usb_vidpid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
Expand Down

0 comments on commit 384c3f1

Please sign in to comment.