diff --git a/mousejacker/mousejacker.c b/mousejacker/mousejacker.c index 99fade1..8a918c9 100644 --- a/mousejacker/mousejacker.c +++ b/mousejacker/mousejacker.c @@ -8,7 +8,8 @@ #include #include #include -#include +#include "shared/lib/drivers/nrf24.h" +#include "shared/shim/string.h" #include "mousejacker_ducky.h" #define TAG "mousejacker" @@ -217,7 +218,7 @@ static bool load_addrs_file(Stream* file_stream) { bytes_read = stream_read(file_stream, file_buf, file_size); if(bytes_read == file_size) { FURI_LOG_D(TAG, "loading addrs file"); - char* line = strtok((char*)file_buf, "\n"); + char* line = mystrtok((char*)file_buf, "\n"); while(line != NULL) { line_ptr = strstr((char*)line, ","); @@ -232,7 +233,7 @@ static bool load_addrs_file(Stream* file_stream) { memset(loaded_addrs[counter], rate, 1); memcpy(&loaded_addrs[counter++][1], addr, addrlen); addrs_count++; - line = strtok(NULL, "\n"); + line = mystrtok(NULL, "\n"); loaded = true; } } else { @@ -391,4 +392,4 @@ int32_t mousejacker_app(void* p) { free(plugin_state); return 0; -} \ No newline at end of file +} diff --git a/mousejacker/mousejacker_ducky.c b/mousejacker/mousejacker_ducky.c index f323a93..a63e42e 100644 --- a/mousejacker/mousejacker_ducky.c +++ b/mousejacker/mousejacker_ducky.c @@ -361,7 +361,7 @@ void mj_process_ducky_script( inject_packet( handle, addr, addr_size, rate, LOGITECH_HELLO, LOGITECH_HELLO_SIZE, plugin_state); - char* line = strtok(script, "\n"); + char* line = mystrtok(script, "\n"); while(line != NULL) { if(strcmp(&line[strlen(line) - 1], "\r") == 0) line[strlen(line) - 1] = (char)0; @@ -369,7 +369,7 @@ void mj_process_ducky_script( FURI_LOG_D(TAG, "unable to process ducky script line: %s", line); prev_line = line; - line = strtok(NULL, "\n"); + line = mystrtok(NULL, "\n"); } build_hid_packet(0, 0, hid_payload); inject_packet( @@ -380,4 +380,4 @@ void mj_process_ducky_script( hid_payload, LOGITECH_HID_TEMPLATE_SIZE, plugin_state); // empty hid packet at end -} \ No newline at end of file +} diff --git a/mousejacker/mousejacker_ducky.h b/mousejacker/mousejacker_ducky.h index b4922ed..b763a65 100644 --- a/mousejacker/mousejacker_ducky.h +++ b/mousejacker/mousejacker_ducky.h @@ -5,10 +5,11 @@ #include #include #include -#include +#include "shared/lib/drivers/nrf24.h" #include #include #include +#include "shared/shim/string.h" #ifdef __cplusplus extern "C" { @@ -41,4 +42,4 @@ void mj_process_ducky_script( #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/mousejacker/shared b/mousejacker/shared new file mode 120000 index 0000000..8fba6b6 --- /dev/null +++ b/mousejacker/shared @@ -0,0 +1 @@ +../shared \ No newline at end of file diff --git a/nrfsniff/nrfsniff.c b/nrfsniff/nrfsniff.c index acf413d..293bafd 100644 --- a/nrfsniff/nrfsniff.c +++ b/nrfsniff/nrfsniff.c @@ -5,7 +5,8 @@ #include #include -#include +#include "shared/lib/drivers/nrf24.h" +#include "shared/shim/string.h" #include #define LOGITECH_MAX_CHANNEL 85 @@ -159,11 +160,11 @@ static bool save_addr_to_file( if(target_rate == 8) rate = 2; snprintf(ending, sizeof(ending), ",%d\n", rate); hexlify(data, size, addrline); - strcat(addrline, ending); + mystrcat(addrline, ending); linesize = strlen(addrline); strcpy(filepath, NRFSNIFF_APP_PATH_FOLDER); - strcat(filepath, "/"); - strcat(filepath, NRFSNIFF_APP_FILENAME); + mystrcat(filepath, "/"); + mystrcat(filepath, NRFSNIFF_APP_FILENAME); stream_seek(stream, 0, StreamOffsetFromStart); // check if address already exists in file @@ -175,14 +176,14 @@ static bool save_addr_to_file( file_contents = malloc(file_size + 1); memset(file_contents, 0, file_size + 1); if(stream_read(stream, file_contents, file_size) > 0) { - char* line = strtok((char*)file_contents, "\n"); + char* line = mystrtok((char*)file_contents, "\n"); while(line != NULL) { if(!memcmp(line, addrline, 12)) { found = true; break; } - line = strtok(NULL, "\n"); + line = mystrtok(NULL, "\n"); } } free(file_contents); diff --git a/nrfsniff/shared b/nrfsniff/shared new file mode 120000 index 0000000..8fba6b6 --- /dev/null +++ b/nrfsniff/shared @@ -0,0 +1 @@ +../shared \ No newline at end of file diff --git a/shared/shim/string.c b/shared/shim/string.c new file mode 100644 index 0000000..de11eb2 --- /dev/null +++ b/shared/shim/string.c @@ -0,0 +1,42 @@ +#include "string.h" + +#include +#include +#include + +char* mystrtok(char* s, char* delm) { + static int currIndex = 0; + if(!s || !delm || s[currIndex] == '\0') return NULL; + char* W = (char*)malloc(sizeof(char) * 100); + int i = currIndex, k = 0, j = 0; + + while(s[i] != '\0') { + j = 0; + while(delm[j] != '\0') { + if(s[i] != delm[j]) + W[k] = s[i]; + else + goto It; + j++; + } + + i++; + k++; + } +It: + W[i] = 0; + currIndex = i + 1; + //Iterator = ++ptr; + return W; +} + +char* mystrcat(char *dest, const char *src) +{ + char *rdest = dest; + + while (*dest) + dest++; + while ((*dest++ = *src++)); + + return rdest; +} diff --git a/shared/shim/string.h b/shared/shim/string.h new file mode 100644 index 0000000..4d71369 --- /dev/null +++ b/shared/shim/string.h @@ -0,0 +1,4 @@ +#pragma once + +char* mystrtok(char* s, char* delm); +char* mystrcat(char *dest, const char *src);