-
Notifications
You must be signed in to change notification settings - Fork 3.1k
string from file function for bad usb #4231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
#include <furi.h> | ||
#include <furi_hal.h> | ||
#include <storage/storage.h> | ||
#include <lib/toolbox/strint.h> | ||
#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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
File* file = storage_file_alloc(storage); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
line = &line[ducky_get_command_len(line) + 1]; | ||
if (file) { | ||
storage_file_open(file, line, FSAM_READ, FSOM_OPEN_EXISTING); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing check if open was successful |
||
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" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works as a hard limit for file size - I think it should either be documented and checked or much higher