Skip to content

Commit

Permalink
feat: fix mousejacker and nrfsniff compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
vmeurisse committed Sep 24, 2022
1 parent f2234ed commit 8457ad8
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 15 deletions.
9 changes: 5 additions & 4 deletions mousejacker/mousejacker.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#include <furi_hal_spi.h>
#include <furi_hal_interrupt.h>
#include <furi_hal_resources.h>
#include <nrf24.h>
#include "shared/lib/drivers/nrf24.h"
#include "shared/shim/string.h"
#include "mousejacker_ducky.h"

#define TAG "mousejacker"
Expand Down Expand Up @@ -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, ",");
Expand All @@ -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 {
Expand Down Expand Up @@ -391,4 +392,4 @@ int32_t mousejacker_app(void* p) {
free(plugin_state);

return 0;
}
}
6 changes: 3 additions & 3 deletions mousejacker/mousejacker_ducky.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,15 +361,15 @@ 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;

if(!mj_process_ducky_line(handle, addr, addr_size, rate, line, prev_line, plugin_state))
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(
Expand All @@ -380,4 +380,4 @@ void mj_process_ducky_script(
hid_payload,
LOGITECH_HID_TEMPLATE_SIZE,
plugin_state); // empty hid packet at end
}
}
5 changes: 3 additions & 2 deletions mousejacker/mousejacker_ducky.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
#include <furi_hal_spi.h>
#include <stdio.h>
#include <string.h>
#include <nrf24.h>
#include "shared/lib/drivers/nrf24.h"
#include <furi.h>
#include <furi_hal.h>
#include <toolbox/stream/file_stream.h>
#include "shared/shim/string.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -41,4 +42,4 @@ void mj_process_ducky_script(

#ifdef __cplusplus
}
#endif
#endif
1 change: 1 addition & 0 deletions mousejacker/shared
13 changes: 7 additions & 6 deletions nrfsniff/nrfsniff.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#include <notification/notification_messages.h>
#include <stdlib.h>

#include <nrf24.h>
#include "shared/lib/drivers/nrf24.h"
#include "shared/shim/string.h"
#include <toolbox/stream/file_stream.h>

#define LOGITECH_MAX_CHANNEL 85
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions nrfsniff/shared
42 changes: 42 additions & 0 deletions shared/shim/string.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "string.h"

#include <stdio.h>
#include <string.h>
#include <malloc.h>

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;
}
4 changes: 4 additions & 0 deletions shared/shim/string.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once

char* mystrtok(char* s, char* delm);
char* mystrcat(char *dest, const char *src);

0 comments on commit 8457ad8

Please sign in to comment.