mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-13 01:58:36 -07:00
updated nrf24 sniffer & mousejacker
This commit is contained in:
@@ -517,4 +517,14 @@ uint8_t nrf24_find_channel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return ch;
|
return ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool nrf24_check_connected(FuriHalSpiBusHandle* handle) {
|
||||||
|
uint8_t status = nrf24_status(handle);
|
||||||
|
|
||||||
|
if(status != 0x00) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -361,6 +361,13 @@ void int32_to_bytes(uint32_t val, uint8_t* out, bool bigendian);
|
|||||||
*/
|
*/
|
||||||
uint32_t bytes_to_int32(uint8_t* bytes, bool bigendian);
|
uint32_t bytes_to_int32(uint8_t* bytes, bool bigendian);
|
||||||
|
|
||||||
|
/** Check if the nrf24 is connected
|
||||||
|
* @param handle - pointer to FuriHalSpiHandle
|
||||||
|
*
|
||||||
|
* @return true if connected, otherwise false
|
||||||
|
*/
|
||||||
|
bool nrf24_check_connected(FuriHalSpiBusHandle* handle);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -16,9 +16,10 @@
|
|||||||
#define TAG "mousejacker"
|
#define TAG "mousejacker"
|
||||||
#define LOGITECH_MAX_CHANNEL 85
|
#define LOGITECH_MAX_CHANNEL 85
|
||||||
#define NRFSNIFF_APP_PATH_FOLDER EXT_PATH("apps_data/nrf24sniff")
|
#define NRFSNIFF_APP_PATH_FOLDER EXT_PATH("apps_data/nrf24sniff")
|
||||||
|
#define NRFSNIFF_APP_PATH_FOLDER_ADDRESSES EXT_PATH("apps_data/nrf24sniff/addresses.txt")
|
||||||
#define NRFSNIFF_APP_PATH_EXTENSION ".txt"
|
#define NRFSNIFF_APP_PATH_EXTENSION ".txt"
|
||||||
#define NRFSNIFF_APP_FILENAME "addresses.txt"
|
#define NRFSNIFF_APP_FILENAME "addresses.txt"
|
||||||
#define MOUSEJACKER_APP_PATH_FOLDER STORAGE_APP_DATA_PATH_PREFIX
|
#define MOUSEJACKER_APP_PATH_FOLDER EXT_PATH("apps_data/mousejacker")
|
||||||
#define MOUSEJACKER_APP_PATH_EXTENSION ".txt"
|
#define MOUSEJACKER_APP_PATH_EXTENSION ".txt"
|
||||||
#define MAX_ADDRS 100
|
#define MAX_ADDRS 100
|
||||||
|
|
||||||
@@ -33,12 +34,13 @@ typedef struct {
|
|||||||
} PluginEvent;
|
} PluginEvent;
|
||||||
|
|
||||||
uint8_t addrs_count = 0;
|
uint8_t addrs_count = 0;
|
||||||
uint8_t addr_idx = 0;
|
int8_t addr_idx = 0;
|
||||||
uint8_t loaded_addrs[MAX_ADDRS][6]; // first byte is rate, the rest are the address
|
uint8_t loaded_addrs[MAX_ADDRS][6]; // first byte is rate, the rest are the address
|
||||||
|
|
||||||
char target_fmt_text[] = "Target addr: %s";
|
char target_fmt_text[] = "Target addr: %s";
|
||||||
char target_address_str[12] = "None";
|
char target_address_str[12] = "None";
|
||||||
char target_text[30];
|
char target_text[30];
|
||||||
|
char index_text[30];
|
||||||
|
|
||||||
static void render_callback(Canvas* const canvas, void* ctx) {
|
static void render_callback(Canvas* const canvas, void* ctx) {
|
||||||
furi_assert(ctx);
|
furi_assert(ctx);
|
||||||
@@ -54,8 +56,15 @@ static void render_callback(Canvas* const canvas, void* ctx) {
|
|||||||
snprintf(target_text, sizeof(target_text), target_fmt_text, target_address_str);
|
snprintf(target_text, sizeof(target_text), target_fmt_text, target_address_str);
|
||||||
canvas_draw_str_aligned(canvas, 7, 10, AlignLeft, AlignBottom, target_text);
|
canvas_draw_str_aligned(canvas, 7, 10, AlignLeft, AlignBottom, target_text);
|
||||||
canvas_draw_str_aligned(canvas, 22, 20, AlignLeft, AlignBottom, "<- select address ->");
|
canvas_draw_str_aligned(canvas, 22, 20, AlignLeft, AlignBottom, "<- select address ->");
|
||||||
canvas_draw_str_aligned(canvas, 10, 30, AlignLeft, AlignBottom, "Press Ok button to ");
|
snprintf(
|
||||||
canvas_draw_str_aligned(canvas, 10, 40, AlignLeft, AlignBottom, "browse for ducky script");
|
index_text, sizeof(index_text), "Address index: %d/%d", addr_idx + 1, addrs_count);
|
||||||
|
canvas_draw_str_aligned(canvas, 10, 30, AlignLeft, AlignBottom, index_text);
|
||||||
|
canvas_draw_str_aligned(canvas, 10, 40, AlignLeft, AlignBottom, "Press Ok button to ");
|
||||||
|
canvas_draw_str_aligned(canvas, 10, 50, AlignLeft, AlignBottom, "browse for ducky script");
|
||||||
|
if(!plugin_state->is_nrf24_connected) {
|
||||||
|
canvas_draw_str_aligned(
|
||||||
|
canvas, 10, 60, AlignLeft, AlignBottom, "Connect NRF24 to GPIO!");
|
||||||
|
}
|
||||||
} else if(plugin_state->addr_err) {
|
} else if(plugin_state->addr_err) {
|
||||||
canvas_draw_str_aligned(
|
canvas_draw_str_aligned(
|
||||||
canvas, 10, 10, AlignLeft, AlignBottom, "Error: No nrfsniff folder");
|
canvas, 10, 10, AlignLeft, AlignBottom, "Error: No nrfsniff folder");
|
||||||
@@ -95,6 +104,7 @@ static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queu
|
|||||||
|
|
||||||
static void mousejacker_state_init(PluginState* const plugin_state) {
|
static void mousejacker_state_init(PluginState* const plugin_state) {
|
||||||
plugin_state->is_thread_running = false;
|
plugin_state->is_thread_running = false;
|
||||||
|
plugin_state->is_nrf24_connected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hexlify(uint8_t* in, uint8_t size, char* out) {
|
static void hexlify(uint8_t* in, uint8_t size, char* out) {
|
||||||
@@ -133,27 +143,17 @@ static bool open_ducky_script(Stream* stream, PluginState* plugin_state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool open_addrs_file(Stream* stream) {
|
static bool open_addrs_file(Stream* stream) {
|
||||||
DialogsApp* dialogs = furi_record_open("dialogs");
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
FuriString* path;
|
FuriString* path;
|
||||||
path = furi_string_alloc();
|
path = furi_string_alloc();
|
||||||
furi_string_set(path, NRFSNIFF_APP_PATH_FOLDER);
|
furi_string_set(path, NRFSNIFF_APP_PATH_FOLDER_ADDRESSES);
|
||||||
|
|
||||||
DialogsFileBrowserOptions browser_options;
|
if(!file_stream_open(stream, furi_string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) {
|
||||||
dialog_file_browser_set_basic_options(
|
FURI_LOG_D(TAG, "Cannot open file \"%s\"", furi_string_get_cstr(path));
|
||||||
&browser_options, NRFSNIFF_APP_PATH_EXTENSION, &I_sub1_10px);
|
} else {
|
||||||
browser_options.hide_ext = false;
|
result = true;
|
||||||
|
|
||||||
bool ret = dialog_file_browser_show(dialogs, path, path, &browser_options);
|
|
||||||
|
|
||||||
furi_record_close("dialogs");
|
|
||||||
if(ret) {
|
|
||||||
if(!file_stream_open(stream, furi_string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) {
|
|
||||||
FURI_LOG_D(TAG, "Cannot open file \"%s\"", furi_string_get_cstr(path));
|
|
||||||
} else {
|
|
||||||
result = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
furi_string_free(path);
|
furi_string_free(path);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -278,12 +278,6 @@ static int32_t mj_worker_thread(void* ctx) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void start_mjthread(PluginState* plugin_state) {
|
|
||||||
if(!plugin_state->is_thread_running) {
|
|
||||||
furi_thread_start(plugin_state->mjthread);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t mousejacker_app(void* p) {
|
int32_t mousejacker_app(void* p) {
|
||||||
UNUSED(p);
|
UNUSED(p);
|
||||||
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent));
|
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent));
|
||||||
@@ -320,6 +314,10 @@ int32_t mousejacker_app(void* p) {
|
|||||||
furi_thread_set_context(plugin_state->mjthread, plugin_state);
|
furi_thread_set_context(plugin_state->mjthread, plugin_state);
|
||||||
furi_thread_set_callback(plugin_state->mjthread, mj_worker_thread);
|
furi_thread_set_callback(plugin_state->mjthread, mj_worker_thread);
|
||||||
|
|
||||||
|
while(!furi_hal_speaker_acquire(100)) {
|
||||||
|
furi_delay_ms(100);
|
||||||
|
}
|
||||||
|
|
||||||
// spawn load file dialog to choose sniffed addresses file
|
// spawn load file dialog to choose sniffed addresses file
|
||||||
if(load_addrs_file(plugin_state->file_stream)) {
|
if(load_addrs_file(plugin_state->file_stream)) {
|
||||||
addr_idx = 0;
|
addr_idx = 0;
|
||||||
@@ -348,21 +346,27 @@ int32_t mousejacker_app(void* p) {
|
|||||||
case InputKeyRight:
|
case InputKeyRight:
|
||||||
if(!plugin_state->addr_err) {
|
if(!plugin_state->addr_err) {
|
||||||
addr_idx++;
|
addr_idx++;
|
||||||
if(addr_idx > addrs_count) addr_idx = 0;
|
if(addr_idx >= addrs_count) addr_idx = 0;
|
||||||
hexlify(loaded_addrs[addr_idx] + 1, 5, target_address_str);
|
hexlify(loaded_addrs[addr_idx] + 1, 5, target_address_str);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case InputKeyLeft:
|
case InputKeyLeft:
|
||||||
if(!plugin_state->addr_err) {
|
if(!plugin_state->addr_err) {
|
||||||
addr_idx--;
|
addr_idx--;
|
||||||
if(addr_idx == 0) addr_idx = addrs_count - 1;
|
if(addr_idx < 0) addr_idx = addrs_count - 1;
|
||||||
hexlify(loaded_addrs[addr_idx] + 1, 5, target_address_str);
|
hexlify(loaded_addrs[addr_idx] + 1, 5, target_address_str);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case InputKeyOk:
|
case InputKeyOk:
|
||||||
if(!plugin_state->addr_err) {
|
if(!plugin_state->addr_err) {
|
||||||
if(!plugin_state->is_thread_running) {
|
if(!nrf24_check_connected(nrf24_HANDLE)) {
|
||||||
start_mjthread(plugin_state);
|
plugin_state->is_nrf24_connected = false;
|
||||||
|
view_port_update(view_port);
|
||||||
|
furi_hal_speaker_start(100, 100);
|
||||||
|
furi_delay_ms(100);
|
||||||
|
furi_hal_speaker_stop();
|
||||||
|
} else if(!plugin_state->is_thread_running) {
|
||||||
|
furi_thread_start(plugin_state->mjthread);
|
||||||
view_port_update(view_port);
|
view_port_update(view_port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -389,6 +393,7 @@ int32_t mousejacker_app(void* p) {
|
|||||||
|
|
||||||
furi_thread_free(plugin_state->mjthread);
|
furi_thread_free(plugin_state->mjthread);
|
||||||
nrf24_deinit();
|
nrf24_deinit();
|
||||||
|
furi_hal_speaker_release();
|
||||||
view_port_enabled_set(view_port, false);
|
view_port_enabled_set(view_port, false);
|
||||||
gui_remove_view_port(gui, view_port);
|
gui_remove_view_port(gui, view_port);
|
||||||
furi_record_close(RECORD_GUI);
|
furi_record_close(RECORD_GUI);
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ typedef struct {
|
|||||||
bool addr_err;
|
bool addr_err;
|
||||||
bool is_thread_running;
|
bool is_thread_running;
|
||||||
bool is_ducky_running;
|
bool is_ducky_running;
|
||||||
|
bool is_nrf24_connected;
|
||||||
bool close_thread_please;
|
bool close_thread_please;
|
||||||
Storage* storage;
|
Storage* storage;
|
||||||
FuriThread* mjthread;
|
FuriThread* mjthread;
|
||||||
|
|||||||
@@ -517,4 +517,14 @@ uint8_t nrf24_find_channel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return ch;
|
return ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool nrf24_check_connected(FuriHalSpiBusHandle* handle) {
|
||||||
|
uint8_t status = nrf24_status(handle);
|
||||||
|
|
||||||
|
if(status != 0x00) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -361,6 +361,13 @@ void int32_to_bytes(uint32_t val, uint8_t* out, bool bigendian);
|
|||||||
*/
|
*/
|
||||||
uint32_t bytes_to_int32(uint8_t* bytes, bool bigendian);
|
uint32_t bytes_to_int32(uint8_t* bytes, bool bigendian);
|
||||||
|
|
||||||
|
/** Check if the nrf24 is connected
|
||||||
|
* @param handle - pointer to FuriHalSpiHandle
|
||||||
|
*
|
||||||
|
* @return true if connected, otherwise false
|
||||||
|
*/
|
||||||
|
bool nrf24_check_connected(FuriHalSpiBusHandle* handle);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
31
applications/external/nrf24sniff/nrfsniff.c
vendored
31
applications/external/nrf24sniff/nrfsniff.c
vendored
@@ -11,11 +11,11 @@
|
|||||||
|
|
||||||
#define LOGITECH_MAX_CHANNEL 85
|
#define LOGITECH_MAX_CHANNEL 85
|
||||||
#define COUNT_THRESHOLD 2
|
#define COUNT_THRESHOLD 2
|
||||||
#define DEFAULT_SAMPLE_TIME 8000
|
#define DEFAULT_SAMPLE_TIME 4000
|
||||||
#define MAX_ADDRS 100
|
#define MAX_ADDRS 100
|
||||||
#define MAX_CONFIRMED 32
|
#define MAX_CONFIRMED 32
|
||||||
|
|
||||||
#define NRFSNIFF_APP_PATH_FOLDER STORAGE_APP_DATA_PATH_PREFIX
|
#define NRFSNIFF_APP_PATH_FOLDER EXT_PATH("apps_data/nrf24sniff")
|
||||||
#define NRFSNIFF_APP_FILENAME "addresses.txt"
|
#define NRFSNIFF_APP_FILENAME "addresses.txt"
|
||||||
#define TAG "nrfsniff"
|
#define TAG "nrfsniff"
|
||||||
|
|
||||||
@@ -346,6 +346,10 @@ int32_t nrfsniff_app(void* p) {
|
|||||||
storage_common_migrate(storage, EXT_PATH("nrfsniff"), NRFSNIFF_APP_PATH_FOLDER);
|
storage_common_migrate(storage, EXT_PATH("nrfsniff"), NRFSNIFF_APP_PATH_FOLDER);
|
||||||
storage_common_mkdir(storage, NRFSNIFF_APP_PATH_FOLDER);
|
storage_common_mkdir(storage, NRFSNIFF_APP_PATH_FOLDER);
|
||||||
|
|
||||||
|
while(!furi_hal_speaker_acquire(100)) {
|
||||||
|
furi_delay_ms(100);
|
||||||
|
}
|
||||||
|
|
||||||
PluginEvent event;
|
PluginEvent event;
|
||||||
for(bool processing = true; processing;) {
|
for(bool processing = true; processing;) {
|
||||||
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
|
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
|
||||||
@@ -390,13 +394,21 @@ int32_t nrfsniff_app(void* p) {
|
|||||||
break;
|
break;
|
||||||
case InputKeyOk:
|
case InputKeyOk:
|
||||||
// toggle sniffing
|
// toggle sniffing
|
||||||
sniffing_state = !sniffing_state;
|
if(nrf24_check_connected(nrf24_HANDLE)) {
|
||||||
if(sniffing_state) {
|
sniffing_state = !sniffing_state;
|
||||||
clear_cache();
|
if(sniffing_state) {
|
||||||
start_sniffing();
|
clear_cache();
|
||||||
start = furi_get_tick();
|
start_sniffing();
|
||||||
} else
|
start = furi_get_tick();
|
||||||
wrap_up(storage, notification);
|
} else {
|
||||||
|
wrap_up(storage, notification);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
furi_hal_speaker_start(100, 100);
|
||||||
|
furi_delay_ms(100);
|
||||||
|
furi_hal_speaker_stop();
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case InputKeyBack:
|
case InputKeyBack:
|
||||||
if(event.input.type == InputTypeLong) processing = false;
|
if(event.input.type == InputTypeLong) processing = false;
|
||||||
@@ -445,6 +457,7 @@ int32_t nrfsniff_app(void* p) {
|
|||||||
target_rate = 8; // rate can be either 8 (2Mbps) or 0 (1Mbps)
|
target_rate = 8; // rate can be either 8 (2Mbps) or 0 (1Mbps)
|
||||||
sniffing_state = false;
|
sniffing_state = false;
|
||||||
nrf24_deinit();
|
nrf24_deinit();
|
||||||
|
furi_hal_speaker_release();
|
||||||
view_port_enabled_set(view_port, false);
|
view_port_enabled_set(view_port, false);
|
||||||
gui_remove_view_port(gui, view_port);
|
gui_remove_view_port(gui, view_port);
|
||||||
furi_record_close(RECORD_GUI);
|
furi_record_close(RECORD_GUI);
|
||||||
|
|||||||
Reference in New Issue
Block a user