Implemented BadUSB
This commit is contained in:
parent
25b444ca95
commit
fce394fd59
5 changed files with 147 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
|||
// Libraries
|
||||
/* Main */
|
||||
#include <furi.h>
|
||||
|
||||
/* Backends */
|
||||
#include "ui/ui.h"
|
||||
|
||||
// Entry Point
|
||||
|
|
|
@ -53,6 +53,7 @@ typedef struct {
|
|||
TextBox* textbox;
|
||||
Popup* popup;
|
||||
|
||||
void* usb_prev_mode;
|
||||
Manager* manager;
|
||||
char* keyboard;
|
||||
int selection;
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
// Header
|
||||
#include "send.h"
|
||||
|
||||
// Libraries
|
||||
#include "../../workers/sender.h"
|
||||
|
||||
// Functions
|
||||
void FP_Scene_Callback_Send(DialogExResult result, void* context) {
|
||||
// Setting context
|
||||
|
@ -16,6 +19,10 @@ void FP_Scene_Enter_Send(void* context) {
|
|||
// Reset view
|
||||
dialog_ex_reset(app->dialog);
|
||||
|
||||
// Sender worker
|
||||
FuriHalUsbInterface* usb_mode_prev = sender_init();
|
||||
app->usb_prev_mode = usb_mode_prev;
|
||||
|
||||
// Adding dialog content
|
||||
dialog_ex_set_header(
|
||||
app->dialog,
|
||||
|
@ -33,11 +40,15 @@ void FP_Scene_Enter_Send(void* context) {
|
|||
);
|
||||
dialog_ex_set_left_button_text(
|
||||
app->dialog,
|
||||
"Username"
|
||||
"User"
|
||||
);
|
||||
dialog_ex_set_center_button_text(
|
||||
app->dialog,
|
||||
"Enter"
|
||||
);
|
||||
dialog_ex_set_right_button_text(
|
||||
app->dialog,
|
||||
"Password"
|
||||
"Pass"
|
||||
);
|
||||
|
||||
// Setting context and callback
|
||||
|
@ -51,6 +62,13 @@ void FP_Scene_Exit_Send(void* context) {
|
|||
// Setting context
|
||||
FP_App* app = context;
|
||||
|
||||
// Exit
|
||||
FuriHalUsbInterface* usb_mode_prev = app->usb_prev_mode;
|
||||
sender_free(usb_mode_prev);
|
||||
|
||||
// Free reference
|
||||
free(usb_mode_prev);
|
||||
|
||||
// Reset menu
|
||||
submenu_reset(app->submenu);
|
||||
}
|
||||
|
@ -68,6 +86,15 @@ bool FP_Scene_Event_Send(void* context, SceneManagerEvent event) {
|
|||
|
||||
// What to do?
|
||||
switch (event.event) {
|
||||
case DialogExResultLeft: // Username
|
||||
sender_execute(app->manager->current->user);
|
||||
break;
|
||||
case DialogExResultCenter:
|
||||
sender_return();
|
||||
break;
|
||||
case DialogExResultRight: // Password
|
||||
sender_execute(app->manager->current->phrase);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
95
project/workers/sender.c
Normal file
95
project/workers/sender.c
Normal file
|
@ -0,0 +1,95 @@
|
|||
// Header
|
||||
#include "sender.h"
|
||||
|
||||
// Structures
|
||||
|
||||
// Functions
|
||||
bool send_string(char* buffer) {
|
||||
// DEBUG
|
||||
FURI_LOG_D(TAG, "Sending: %s", buffer);
|
||||
|
||||
// Going through all characters
|
||||
while (*buffer) {
|
||||
// Turning buffer into keycode
|
||||
uint16_t keycode = HID_ASCII_TO_KEY(*buffer);
|
||||
|
||||
// None?
|
||||
if (keycode != HID_KEYBOARD_NONE) {
|
||||
// Sending it over to the client
|
||||
furi_hal_hid_kb_press(keycode);
|
||||
furi_hal_hid_kb_release(keycode);
|
||||
}
|
||||
|
||||
// Incriment through string
|
||||
buffer++;
|
||||
}
|
||||
|
||||
// Done!
|
||||
return true;
|
||||
}
|
||||
int32_t send_thread(void* context) {
|
||||
// Starting a Mutex
|
||||
FuriMutex* mutex = furi_mutex_alloc(FuriMutexTypeNormal);
|
||||
|
||||
// Setting context
|
||||
char* buffer = context;
|
||||
|
||||
// Sending string
|
||||
send_string(buffer);
|
||||
|
||||
// Free mutex
|
||||
furi_mutex_release(mutex);
|
||||
furi_mutex_free(mutex);
|
||||
|
||||
// Exit
|
||||
return 0;
|
||||
}
|
||||
int32_t send_return() {
|
||||
// Starting a Mutex
|
||||
FuriMutex* mutex = furi_mutex_alloc(FuriMutexTypeNormal);
|
||||
|
||||
// Sending string
|
||||
uint16_t keycode = HID_ASCII_TO_KEY('\n');
|
||||
furi_hal_hid_kb_press(keycode);
|
||||
furi_hal_hid_kb_release(keycode);
|
||||
|
||||
// Free mutex
|
||||
furi_mutex_release(mutex);
|
||||
furi_mutex_free(mutex);
|
||||
|
||||
// Exit
|
||||
return 0;
|
||||
}
|
||||
|
||||
FuriHalUsbInterface* sender_init() {
|
||||
// Getting ready to have USB used for keyboard
|
||||
FuriHalUsbInterface* usb_mode_prev = furi_hal_usb_get_config();
|
||||
furi_hal_usb_unlock();
|
||||
furi_check(furi_hal_usb_set_config(&usb_hid, NULL) == true);
|
||||
|
||||
return usb_mode_prev;
|
||||
}
|
||||
void sender_free(FuriHalUsbInterface* usb_mode_prev) {
|
||||
// Return to normal
|
||||
furi_hal_usb_set_config(usb_mode_prev, NULL);
|
||||
}
|
||||
|
||||
void sender_execute(char* buffer) {
|
||||
// DEBUG
|
||||
FURI_LOG_D(TAG, "Sending %s", buffer);
|
||||
|
||||
FuriThread* thread = furi_thread_alloc();
|
||||
furi_thread_set_name(thread, "FPBadUSBWorker");
|
||||
furi_thread_set_stack_size(thread, 1024);
|
||||
furi_thread_set_context(thread, buffer);
|
||||
furi_thread_set_callback(thread, send_thread);
|
||||
furi_thread_start(thread);
|
||||
}
|
||||
void sender_return() {
|
||||
FuriThread* thread = furi_thread_alloc();
|
||||
furi_thread_set_name(thread, "FPBadUSBWorker");
|
||||
furi_thread_set_stack_size(thread, 1024);
|
||||
furi_thread_set_context(thread, NULL);
|
||||
furi_thread_set_callback(thread, send_return);
|
||||
furi_thread_start(thread);
|
||||
}
|
20
project/workers/sender.h
Normal file
20
project/workers/sender.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
// Define once
|
||||
#ifndef H_SENDER
|
||||
#define H_SENDER
|
||||
|
||||
// Libraries
|
||||
#include <furi.h>
|
||||
#include <furi/core/thread.h>
|
||||
|
||||
#include <furi_hal.h>
|
||||
#include <furi_hal_usb_hid.h>
|
||||
|
||||
#include "../backend/base.h"
|
||||
|
||||
// Functions
|
||||
FuriHalUsbInterface* sender_init();
|
||||
void sender_free(FuriHalUsbInterface* usb_mode_prev);
|
||||
void sender_execute(char* buffer);
|
||||
void sender_return();
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue