diff --git a/applications/main/bad_usb/helpers/ducky_script_commands.c b/applications/main/bad_usb/helpers/ducky_script_commands.c index 1b4ff55cb2a..0415320da71 100644 --- a/applications/main/bad_usb/helpers/ducky_script_commands.c +++ b/applications/main/bad_usb/helpers/ducky_script_commands.c @@ -1,4 +1,6 @@ +#include #include +#include #include #include "ducky_script.h" #include "ducky_script_i.h" @@ -253,6 +255,28 @@ static int32_t ducky_fnc_mouse_move(BadUsbScript* bad_usb, const char* line, int return 0; } +static int32_t ducky_fnc_string_from_file(BadUsbScript* bad_usb, const char* line, int32_t param) { + UNUSED(param); + char buffer[254]; + size_t read_bytes; + Storage* storage = furi_record_open("storage"); + File* file = storage_file_alloc(storage); + + line = &line[ducky_get_command_len(line) + 1]; + if (file) { + storage_file_open(file, line, FSAM_READ, FSOM_OPEN_EXISTING); + read_bytes = storage_file_read(file, buffer, sizeof(buffer) - 1); + buffer[read_bytes] = '\0'; // Null-terminate the string + furi_string_set_str(bad_usb->string_print, buffer); + storage_file_close(file); + bool state = ducky_string(bad_usb, furi_string_get_cstr(bad_usb->string_print)); + if(!state) { + return ducky_error(bad_usb, "Invalid string %s", line); + } + } + return 0; +} + static const DuckyCmd ducky_commands[] = { {"REM", NULL, -1}, {"ID", NULL, -1}, @@ -279,6 +303,7 @@ static const DuckyCmd ducky_commands[] = { {"MOUSE_MOVE", ducky_fnc_mouse_move, -1}, {"MOUSESCROLL", ducky_fnc_mouse_scroll, -1}, {"MOUSE_SCROLL", ducky_fnc_mouse_scroll, -1}, + {"STRING_FROM_FILE", ducky_fnc_string_from_file, -1}, }; #define TAG "BadUsb" diff --git a/documentation/file_formats/BadUsbScriptFormat.md b/documentation/file_formats/BadUsbScriptFormat.md index a26f124896d..9933c02cd34 100644 --- a/documentation/file_formats/BadUsbScriptFormat.md +++ b/documentation/file_formats/BadUsbScriptFormat.md @@ -79,10 +79,11 @@ Up to 5 keys can be hold simultaneously. ## String -| Command | Parameters | Notes | -| ------- | ----------- | ----------------- | -| STRING | Text string | Print text string | -| STRINGLN | Text string | Print text string and press enter after it | +| Command | Parameters | Notes | +| ---------------- | ----------- | ----------------- | +| STRING | Text string | Print text string | +| STRINGLN | Text string | Print text string and press enter after it | +| STRING_FROM_FILE | File path | Print text contained in a file | ## String delay