Add support for DEFAULT_STRING_DELAY in Bad USB App (#3476)

* Add support for `DEFAULT_STRING_DELAY` in bad_usb
* Format Sources

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
Jaroslav Nesterov 2024-03-21 02:18:02 +04:00 committed by MX
parent e0469ae1ed
commit 760deb66c5
No known key found for this signature in database
GPG key ID: 7CCC66B7DBDD1C83
4 changed files with 27 additions and 6 deletions

View file

@ -436,6 +436,7 @@ static int32_t bad_usb_worker(void* context) {
bad_usb->st.line_cur = 0; bad_usb->st.line_cur = 0;
bad_usb->defdelay = 0; bad_usb->defdelay = 0;
bad_usb->stringdelay = 0; bad_usb->stringdelay = 0;
bad_usb->defstringdelay = 0;
bad_usb->repeat_cnt = 0; bad_usb->repeat_cnt = 0;
bad_usb->key_hold_nb = 0; bad_usb->key_hold_nb = 0;
bad_usb->file_end = false; bad_usb->file_end = false;
@ -459,6 +460,7 @@ static int32_t bad_usb_worker(void* context) {
bad_usb->st.line_cur = 0; bad_usb->st.line_cur = 0;
bad_usb->defdelay = 0; bad_usb->defdelay = 0;
bad_usb->stringdelay = 0; bad_usb->stringdelay = 0;
bad_usb->defstringdelay = 0;
bad_usb->repeat_cnt = 0; bad_usb->repeat_cnt = 0;
bad_usb->file_end = false; bad_usb->file_end = false;
storage_file_seek(script_file, 0, true); storage_file_seek(script_file, 0, true);
@ -586,9 +588,11 @@ static int32_t bad_usb_worker(void* context) {
continue; continue;
} }
} else if(worker_state == BadUsbStateStringDelay) { // State: print string with delays } else if(worker_state == BadUsbStateStringDelay) { // State: print string with delays
uint32_t delay = (bad_usb->stringdelay == 0) ? bad_usb->defstringdelay :
bad_usb->stringdelay;
uint32_t flags = bad_usb_flags_get( uint32_t flags = bad_usb_flags_get(
WorkerEvtEnd | WorkerEvtStartStop | WorkerEvtPauseResume | WorkerEvtDisconnect, WorkerEvtEnd | WorkerEvtStartStop | WorkerEvtPauseResume | WorkerEvtDisconnect,
bad_usb->stringdelay); delay);
if(!(flags & FuriFlagError)) { if(!(flags & FuriFlagError)) {
if(flags & WorkerEvtEnd) { if(flags & WorkerEvtEnd) {

View file

@ -46,6 +46,17 @@ static int32_t ducky_fnc_strdelay(BadUsbScript* bad_usb, const char* line, int32
return 0; return 0;
} }
static int32_t ducky_fnc_defstrdelay(BadUsbScript* bad_usb, const char* line, int32_t param) {
UNUSED(param);
line = &line[ducky_get_command_len(line) + 1];
bool state = ducky_get_number(line, &bad_usb->defstringdelay);
if(!state) {
return ducky_error(bad_usb, "Invalid number %s", line);
}
return 0;
}
static int32_t ducky_fnc_string(BadUsbScript* bad_usb, const char* line, int32_t param) { static int32_t ducky_fnc_string(BadUsbScript* bad_usb, const char* line, int32_t param) {
line = &line[ducky_get_command_len(line) + 1]; line = &line[ducky_get_command_len(line) + 1];
furi_string_set_str(bad_usb->string_print, line); furi_string_set_str(bad_usb->string_print, line);
@ -53,7 +64,8 @@ static int32_t ducky_fnc_string(BadUsbScript* bad_usb, const char* line, int32_t
furi_string_cat(bad_usb->string_print, "\n"); furi_string_cat(bad_usb->string_print, "\n");
} }
if(bad_usb->stringdelay == 0) { // stringdelay not set - run command immediately if(bad_usb->stringdelay == 0 &&
bad_usb->defstringdelay == 0) { // stringdelay not set - run command immediately
bool state = ducky_string(bad_usb, furi_string_get_cstr(bad_usb->string_print)); bool state = ducky_string(bad_usb, furi_string_get_cstr(bad_usb->string_print));
if(!state) { if(!state) {
return ducky_error(bad_usb, "Invalid string %s", line); return ducky_error(bad_usb, "Invalid string %s", line);
@ -161,6 +173,8 @@ static const DuckyCmd ducky_commands[] = {
{"DEFAULTDELAY", ducky_fnc_defdelay, -1}, {"DEFAULTDELAY", ducky_fnc_defdelay, -1},
{"STRINGDELAY", ducky_fnc_strdelay, -1}, {"STRINGDELAY", ducky_fnc_strdelay, -1},
{"STRING_DELAY", ducky_fnc_strdelay, -1}, {"STRING_DELAY", ducky_fnc_strdelay, -1},
{"DEFAULT_STRING_DELAY", ducky_fnc_defstrdelay, -1},
{"DEFAULTSTRINGDELAY", ducky_fnc_defstrdelay, -1},
{"REPEAT", ducky_fnc_repeat, -1}, {"REPEAT", ducky_fnc_repeat, -1},
{"SYSRQ", ducky_fnc_sysrq, -1}, {"SYSRQ", ducky_fnc_sysrq, -1},
{"ALTCHAR", ducky_fnc_altchar, -1}, {"ALTCHAR", ducky_fnc_altchar, -1},

View file

@ -30,6 +30,7 @@ struct BadUsbScript {
uint32_t defdelay; uint32_t defdelay;
uint32_t stringdelay; uint32_t stringdelay;
uint32_t defstringdelay;
uint16_t layout[128]; uint16_t layout[128];
FuriString* line; FuriString* line;

View file

@ -97,10 +97,12 @@ Will wait indefinitely for a button to be pressed
## String delay ## String delay
Delay between keypresses. Delay between keypresses.
| Command | Parameters | Notes | | Command | Parameters | Notes |
| ------------ | ----------------- | --------------------------------------------- | | -------------------- | ----------------- | --------------------------------------------- |
| STRING_DELAY | Delay value in ms | Applied once to next appearing STRING command | | STRING_DELAY | Delay value in ms | Applied once to next appearing STRING command |
| STRINGDELAY | Delay value in ms | Same as STRING_DELAY | | STRINGDELAY | Delay value in ms | Same as STRING_DELAY |
| DEFAULT_STRING_DELAY | Delay value in ms | Apply to every appearing STRING command |
| DEFAULTSTRINGDELAY | Delay value in ms | Same as DEFAULT_STRING_DELAY |
### Repeat ### Repeat