BadUSB ID change (#1046)
* badusb: vid/pid/strings change * demo script update * removed vid/pid values Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -115,15 +115,10 @@ void bad_usb_app_free(BadUsbApp* app) {
|
||||
}
|
||||
|
||||
int32_t bad_usb_app(void* p) {
|
||||
FuriHalUsbInterface* usb_mode_prev = furi_hal_usb_get_config();
|
||||
furi_hal_usb_set_config(&usb_hid);
|
||||
|
||||
BadUsbApp* bad_usb_app = bad_usb_app_alloc((char*)p);
|
||||
|
||||
view_dispatcher_run(bad_usb_app->view_dispatcher);
|
||||
|
||||
furi_hal_usb_set_config(usb_mode_prev);
|
||||
bad_usb_app_free(bad_usb_app);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -24,6 +24,7 @@ typedef enum {
|
||||
} WorkerEvtFlags;
|
||||
|
||||
struct BadUsbScript {
|
||||
FuriHalUsbHidConfig hid_cfg;
|
||||
BadUsbState st;
|
||||
string_t file_path;
|
||||
uint32_t defdelay;
|
||||
@@ -101,6 +102,7 @@ static const DuckyKey ducky_keys[] = {
|
||||
};
|
||||
|
||||
static const char ducky_cmd_comment[] = {"REM"};
|
||||
static const char ducky_cmd_id[] = {"ID"};
|
||||
static const char ducky_cmd_delay[] = {"DELAY "};
|
||||
static const char ducky_cmd_string[] = {"STRING "};
|
||||
static const char ducky_cmd_defdelay_1[] = {"DEFAULT_DELAY "};
|
||||
@@ -240,12 +242,15 @@ static int32_t ducky_parse_line(BadUsbScript* bad_usb, string_t line) {
|
||||
if(i == line_len - 1) return SCRIPT_STATE_NEXT_LINE; // Skip empty lines
|
||||
}
|
||||
|
||||
FURI_LOG_I(WORKER_TAG, "line:%s", line_tmp);
|
||||
FURI_LOG_D(WORKER_TAG, "line:%s", line_tmp);
|
||||
|
||||
// General commands
|
||||
if(strncmp(line_tmp, ducky_cmd_comment, strlen(ducky_cmd_comment)) == 0) {
|
||||
// REM - comment line
|
||||
return (0);
|
||||
} else if(strncmp(line_tmp, ducky_cmd_id, strlen(ducky_cmd_id)) == 0) {
|
||||
// ID - executed in ducky_script_preload
|
||||
return (0);
|
||||
} else if(strncmp(line_tmp, ducky_cmd_delay, strlen(ducky_cmd_delay)) == 0) {
|
||||
// DELAY
|
||||
line_tmp = &line_tmp[ducky_get_command_len(line_tmp) + 1];
|
||||
@@ -302,10 +307,37 @@ static int32_t ducky_parse_line(BadUsbScript* bad_usb, string_t line) {
|
||||
return SCRIPT_STATE_ERROR;
|
||||
}
|
||||
|
||||
static bool ducky_set_usb_id(BadUsbScript* bad_usb, const char* line) {
|
||||
if(sscanf(line, "%lX:%lX", &bad_usb->hid_cfg.vid, &bad_usb->hid_cfg.pid) == 2) {
|
||||
bad_usb->hid_cfg.manuf[0] = '\0';
|
||||
bad_usb->hid_cfg.product[0] = '\0';
|
||||
|
||||
uint8_t id_len = ducky_get_command_len(line);
|
||||
if(!ducky_is_line_end(line[id_len + 1])) {
|
||||
sscanf(
|
||||
&line[id_len + 1],
|
||||
"%31[^\r\n:]:%31[^\r\n]",
|
||||
bad_usb->hid_cfg.manuf,
|
||||
bad_usb->hid_cfg.product);
|
||||
}
|
||||
FURI_LOG_D(
|
||||
WORKER_TAG,
|
||||
"set id: %04X:%04X mfr:%s product:%s",
|
||||
bad_usb->hid_cfg.vid,
|
||||
bad_usb->hid_cfg.pid,
|
||||
bad_usb->hid_cfg.manuf,
|
||||
bad_usb->hid_cfg.product);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool ducky_script_preload(BadUsbScript* bad_usb, File* script_file) {
|
||||
uint8_t ret = 0;
|
||||
uint32_t line_len = 0;
|
||||
|
||||
string_reset(bad_usb->line);
|
||||
|
||||
do {
|
||||
ret = storage_file_read(script_file, bad_usb->file_buf, FILE_BUFFER_LEN);
|
||||
for(uint16_t i = 0; i < ret; i++) {
|
||||
@@ -313,6 +345,9 @@ static bool ducky_script_preload(BadUsbScript* bad_usb, File* script_file) {
|
||||
bad_usb->st.line_nb++;
|
||||
line_len = 0;
|
||||
} else {
|
||||
if(bad_usb->st.line_nb == 0) { // Save first line
|
||||
string_push_back(bad_usb->line, bad_usb->file_buf[i]);
|
||||
}
|
||||
line_len++;
|
||||
}
|
||||
}
|
||||
@@ -324,7 +359,20 @@ static bool ducky_script_preload(BadUsbScript* bad_usb, File* script_file) {
|
||||
}
|
||||
} while(ret > 0);
|
||||
|
||||
const char* line_tmp = string_get_cstr(bad_usb->line);
|
||||
bool id_set = false; // Looking for ID command at first line
|
||||
if(strncmp(line_tmp, ducky_cmd_id, strlen(ducky_cmd_id)) == 0) {
|
||||
id_set = ducky_set_usb_id(bad_usb, &line_tmp[strlen(ducky_cmd_id) + 1]);
|
||||
}
|
||||
|
||||
if(id_set) {
|
||||
furi_hal_usb_set_config(&usb_hid, &bad_usb->hid_cfg);
|
||||
} else {
|
||||
furi_hal_usb_set_config(&usb_hid, NULL);
|
||||
}
|
||||
|
||||
storage_file_seek(script_file, 0, true);
|
||||
string_reset(bad_usb->line);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -403,6 +451,8 @@ static int32_t bad_usb_worker(void* context) {
|
||||
BadUsbWorkerState worker_state = BadUsbStateInit;
|
||||
int32_t delay_val = 0;
|
||||
|
||||
FuriHalUsbInterface* usb_mode_prev = furi_hal_usb_get_config();
|
||||
|
||||
FURI_LOG_I(WORKER_TAG, "Init");
|
||||
File* script_file = storage_file_alloc(furi_record_open("storage"));
|
||||
string_init(bad_usb->line);
|
||||
@@ -522,6 +572,8 @@ static int32_t bad_usb_worker(void* context) {
|
||||
|
||||
furi_hal_hid_set_state_callback(NULL, NULL);
|
||||
|
||||
furi_hal_usb_set_config(usb_mode_prev, NULL);
|
||||
|
||||
storage_file_close(script_file);
|
||||
storage_file_free(script_file);
|
||||
string_clear(bad_usb->line);
|
||||
|
@@ -42,7 +42,7 @@ int32_t usb_mouse_app(void* p) {
|
||||
ViewPort* view_port = view_port_alloc();
|
||||
|
||||
FuriHalUsbInterface* usb_mode_prev = furi_hal_usb_get_config();
|
||||
furi_hal_usb_set_config(&usb_hid);
|
||||
furi_hal_usb_set_config(&usb_hid, NULL);
|
||||
|
||||
view_port_draw_callback_set(view_port, usb_mouse_render_callback, NULL);
|
||||
view_port_input_callback_set(view_port, usb_mouse_input_callback, event_queue);
|
||||
@@ -110,7 +110,7 @@ int32_t usb_mouse_app(void* p) {
|
||||
view_port_update(view_port);
|
||||
}
|
||||
|
||||
furi_hal_usb_set_config(usb_mode_prev);
|
||||
furi_hal_usb_set_config(usb_mode_prev, NULL);
|
||||
|
||||
// remove & free all stuff created by app
|
||||
gui_remove_view_port(gui, view_port);
|
||||
|
@@ -10,6 +10,7 @@ typedef struct {
|
||||
Gui* gui;
|
||||
ViewDispatcher* view_dispatcher;
|
||||
Submenu* submenu;
|
||||
FuriHalUsbHidConfig hid_cfg;
|
||||
} UsbTestApp;
|
||||
|
||||
typedef enum {
|
||||
@@ -19,12 +20,13 @@ typedef enum {
|
||||
UsbTestSubmenuIndexVcpSingle,
|
||||
UsbTestSubmenuIndexVcpDual,
|
||||
UsbTestSubmenuIndexHid,
|
||||
UsbTestSubmenuIndexHidWithParams,
|
||||
UsbTestSubmenuIndexHidU2F,
|
||||
} SubmenuIndex;
|
||||
|
||||
void usb_test_submenu_callback(void* context, uint32_t index) {
|
||||
furi_assert(context);
|
||||
//UsbTestApp* app = context;
|
||||
UsbTestApp* app = context;
|
||||
if(index == UsbTestSubmenuIndexEnable) {
|
||||
furi_hal_usb_enable();
|
||||
} else if(index == UsbTestSubmenuIndexDisable) {
|
||||
@@ -32,13 +34,19 @@ void usb_test_submenu_callback(void* context, uint32_t index) {
|
||||
} else if(index == UsbTestSubmenuIndexRestart) {
|
||||
furi_hal_usb_reinit();
|
||||
} else if(index == UsbTestSubmenuIndexVcpSingle) {
|
||||
furi_hal_usb_set_config(&usb_cdc_single);
|
||||
furi_hal_usb_set_config(&usb_cdc_single, NULL);
|
||||
} else if(index == UsbTestSubmenuIndexVcpDual) {
|
||||
furi_hal_usb_set_config(&usb_cdc_dual);
|
||||
furi_hal_usb_set_config(&usb_cdc_dual, NULL);
|
||||
} else if(index == UsbTestSubmenuIndexHid) {
|
||||
furi_hal_usb_set_config(&usb_hid);
|
||||
furi_hal_usb_set_config(&usb_hid, NULL);
|
||||
} else if(index == UsbTestSubmenuIndexHidWithParams) {
|
||||
app->hid_cfg.vid = 0x1234;
|
||||
app->hid_cfg.pid = 0xabcd;
|
||||
strncpy(app->hid_cfg.manuf, "WEN", sizeof(app->hid_cfg.manuf));
|
||||
strncpy(app->hid_cfg.product, "FLIP", sizeof(app->hid_cfg.product));
|
||||
furi_hal_usb_set_config(&usb_hid, &app->hid_cfg);
|
||||
} else if(index == UsbTestSubmenuIndexHidU2F) {
|
||||
furi_hal_usb_set_config(&usb_hid_u2f);
|
||||
furi_hal_usb_set_config(&usb_hid_u2f, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +79,12 @@ UsbTestApp* usb_test_app_alloc() {
|
||||
app->submenu, "Dual VCP", UsbTestSubmenuIndexVcpDual, usb_test_submenu_callback, app);
|
||||
submenu_add_item(
|
||||
app->submenu, "HID KB+Mouse", UsbTestSubmenuIndexHid, usb_test_submenu_callback, app);
|
||||
submenu_add_item(
|
||||
app->submenu,
|
||||
"HID KB+Mouse custom ID",
|
||||
UsbTestSubmenuIndexHidWithParams,
|
||||
usb_test_submenu_callback,
|
||||
app);
|
||||
submenu_add_item(
|
||||
app->submenu, "HID U2F", UsbTestSubmenuIndexHidU2F, usb_test_submenu_callback, app);
|
||||
view_set_previous_callback(submenu_get_view(app->submenu), usb_test_exit);
|
||||
|
@@ -84,10 +84,10 @@ static void usb_uart_on_irq_cb(UartIrqEvent ev, uint8_t data, void* context) {
|
||||
|
||||
static void usb_uart_vcp_init(UsbUartBridge* usb_uart, uint8_t vcp_ch) {
|
||||
if(vcp_ch == 0) {
|
||||
furi_hal_usb_set_config(&usb_cdc_single);
|
||||
furi_hal_usb_set_config(&usb_cdc_single, NULL);
|
||||
furi_hal_vcp_disable();
|
||||
} else {
|
||||
furi_hal_usb_set_config(&usb_cdc_dual);
|
||||
furi_hal_usb_set_config(&usb_cdc_dual, NULL);
|
||||
}
|
||||
furi_hal_cdc_set_callbacks(vcp_ch, (CdcCallbacks*)&cdc_cb, usb_uart);
|
||||
}
|
||||
@@ -247,7 +247,7 @@ static int32_t usb_uart_worker(void* context) {
|
||||
|
||||
usb_uart_vcp_deinit(usb_uart, usb_uart->cfg.vcp_ch);
|
||||
usb_uart_serial_deinit(usb_uart, usb_uart->cfg.uart_ch);
|
||||
furi_hal_usb_set_config(usb_mode_prev);
|
||||
furi_hal_usb_set_config(usb_mode_prev, NULL);
|
||||
if(usb_uart->cfg.flow_pins != 0) {
|
||||
hal_gpio_init_simple(flow_pins[usb_uart->cfg.flow_pins - 1][0], GpioModeAnalog);
|
||||
hal_gpio_init_simple(flow_pins[usb_uart->cfg.flow_pins - 1][1], GpioModeAnalog);
|
||||
|
@@ -191,7 +191,7 @@ static int32_t u2f_hid_worker(void* context) {
|
||||
FURI_LOG_D(WORKER_TAG, "Init");
|
||||
|
||||
FuriHalUsbInterface* usb_mode_prev = furi_hal_usb_get_config();
|
||||
furi_hal_usb_set_config(&usb_hid_u2f);
|
||||
furi_hal_usb_set_config(&usb_hid_u2f, NULL);
|
||||
|
||||
u2f_hid->lock_timer = osTimerNew(u2f_hid_lock_timeout_callback, osTimerOnce, u2f_hid, NULL);
|
||||
|
||||
@@ -270,7 +270,7 @@ static int32_t u2f_hid_worker(void* context) {
|
||||
osTimerDelete(u2f_hid->lock_timer);
|
||||
|
||||
furi_hal_hid_u2f_set_callback(NULL, NULL);
|
||||
furi_hal_usb_set_config(usb_mode_prev);
|
||||
furi_hal_usb_set_config(usb_mode_prev, NULL);
|
||||
FURI_LOG_D(WORKER_TAG, "End");
|
||||
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user