Parcourir la source

allow nrf sniff apps to compile via ufbt on OFW

MX il y a 1 an
Parent
commit
02f84985e2
3 fichiers modifiés avec 175 ajouts et 61 suppressions
  1. 63 61
      mousejacker_ducky.c
  2. 81 0
      stdstring.c
  3. 31 0
      stdstring.h

+ 63 - 61
mousejacker_ducky.c

@@ -1,5 +1,7 @@
 #include "mousejacker_ducky.h"
 
+#include "stdstring.h"
+
 static const char ducky_cmd_comment[] = {"REM"};
 static const char ducky_cmd_delay[] = {"DELAY "};
 static const char ducky_cmd_string[] = {"STRING "};
@@ -17,64 +19,63 @@ static bool holding_shift = false;
 static bool holding_alt = false;
 static bool holding_gui = false;
 
-#define RT_THRESHOLD 50
-#define LOGITECH_MIN_CHANNEL 2
-#define LOGITECH_MAX_CHANNEL 83
-#define LOGITECH_KEEPALIVE_SIZE 5
+#define RT_THRESHOLD               50
+#define LOGITECH_MIN_CHANNEL       2
+#define LOGITECH_MAX_CHANNEL       83
+#define LOGITECH_KEEPALIVE_SIZE    5
 #define LOGITECH_HID_TEMPLATE_SIZE 10
-#define LOGITECH_HELLO_SIZE 10
-#define TAG "mousejacker_ducky"
-
-MJDuckyKey mj_ducky_keys[] = {{" ", 44, 0},         {"!", 30, 2},          {"\"", 52, 2},
-                              {"#", 32, 2},         {"$", 33, 2},          {"%", 34, 2},
-                              {"&", 36, 2},         {"'", 52, 0},          {"(", 38, 2},
-                              {")", 39, 2},         {"*", 37, 2},          {"+", 46, 2},
-                              {",", 54, 0},         {"-", 45, 0},          {".", 55, 0},
-                              {"/", 56, 0},         {"0", 39, 0},          {"1", 30, 0},
-                              {"2", 31, 0},         {"3", 32, 0},          {"4", 33, 0},
-                              {"5", 34, 0},         {"6", 35, 0},          {"7", 36, 0},
-                              {"8", 37, 0},         {"9", 38, 0},          {":", 51, 2},
-                              {";", 51, 0},         {"<", 54, 2},          {"=", 46, 0},
-                              {">", 55, 2},         {"?", 56, 2},          {"@", 31, 2},
-                              {"A", 4, 2},          {"B", 5, 2},           {"C", 6, 2},
-                              {"D", 7, 2},          {"E", 8, 2},           {"F", 9, 2},
-                              {"G", 10, 2},         {"H", 11, 2},          {"I", 12, 2},
-                              {"J", 13, 2},         {"K", 14, 2},          {"L", 15, 2},
-                              {"M", 16, 2},         {"N", 17, 2},          {"O", 18, 2},
-                              {"P", 19, 2},         {"Q", 20, 2},          {"R", 21, 2},
-                              {"S", 22, 2},         {"T", 23, 2},          {"U", 24, 2},
-                              {"V", 25, 2},         {"W", 26, 2},          {"X", 27, 2},
-                              {"Y", 28, 2},         {"Z", 29, 2},          {"[", 47, 0},
-                              {"\\", 49, 0},        {"]", 48, 0},          {"^", 35, 2},
-                              {"_", 45, 2},         {"`", 53, 0},          {"a", 4, 0},
-                              {"b", 5, 0},          {"c", 6, 0},           {"d", 7, 0},
-                              {"e", 8, 0},          {"f", 9, 0},           {"g", 10, 0},
-                              {"h", 11, 0},         {"i", 12, 0},          {"j", 13, 0},
-                              {"k", 14, 0},         {"l", 15, 0},          {"m", 16, 0},
-                              {"n", 17, 0},         {"o", 18, 0},          {"p", 19, 0},
-                              {"q", 20, 0},         {"r", 21, 0},          {"s", 22, 0},
-                              {"t", 23, 0},         {"u", 24, 0},          {"v", 25, 0},
-                              {"w", 26, 0},         {"x", 27, 0},          {"y", 28, 0},
-                              {"z", 29, 0},         {"{", 47, 2},          {"|", 49, 2},
-                              {"}", 48, 2},         {"~", 53, 2},          {"BACKSPACE", 42, 0},
-                              {"", 0, 0},           {"ALT", 0, 4},         {"SHIFT", 0, 2},
-                              {"CTRL", 0, 1},       {"GUI", 0, 8},         {"SCROLLLOCK", 71, 0},
-                              {"ENTER", 40, 0},     {"F12", 69, 0},        {"HOME", 74, 0},
-                              {"F10", 67, 0},       {"F9", 66, 0},         {"ESCAPE", 41, 0},
-                              {"PAGEUP", 75, 0},    {"TAB", 43, 0},        {"PRINTSCREEN", 70, 0},
-                              {"F2", 59, 0},        {"CAPSLOCK", 57, 0},   {"F1", 58, 0},
-                              {"F4", 61, 0},        {"F6", 63, 0},         {"F8", 65, 0},
-                              {"DOWNARROW", 81, 0}, {"DELETE", 42, 0},     {"RIGHT", 79, 0},
-                              {"F3", 60, 0},        {"DOWN", 81, 0},       {"DEL", 76, 0},
-                              {"END", 77, 0},       {"INSERT", 73, 0},
-                              {"NUMLOCK", 83, 0},     {"F5", 62, 0},
-                              {"LEFTARROW", 80, 0}, {"RIGHTARROW", 79, 0}, {"PAGEDOWN", 78, 0},
-                              {"PAUSE", 72, 0},     {"SPACE", 44, 0},      {"UPARROW", 82, 0},
-                              {"F11", 68, 0},       {"F7", 64, 0},         {"UP", 82, 0},
-                              {"LEFT", 80, 0},      {"NUM 1", 89, 0},      {"NUM 2", 90, 0},
-                              {"NUM 3", 91, 0},     {"NUM 4", 92, 0},      {"NUM 5", 93, 0},
-                              {"NUM 6", 94, 0},     {"NUM 7", 95, 0},      {"NUM 8", 96, 0},
-                              {"NUM 9", 97, 0},     {"NUM 0", 98, 0}};
+#define LOGITECH_HELLO_SIZE        10
+#define TAG                        "mousejacker_ducky"
+
+MJDuckyKey mj_ducky_keys[] = {{" ", 44, 0},         {"!", 30, 2},         {"\"", 52, 2},
+                              {"#", 32, 2},         {"$", 33, 2},         {"%", 34, 2},
+                              {"&", 36, 2},         {"'", 52, 0},         {"(", 38, 2},
+                              {")", 39, 2},         {"*", 37, 2},         {"+", 46, 2},
+                              {",", 54, 0},         {"-", 45, 0},         {".", 55, 0},
+                              {"/", 56, 0},         {"0", 39, 0},         {"1", 30, 0},
+                              {"2", 31, 0},         {"3", 32, 0},         {"4", 33, 0},
+                              {"5", 34, 0},         {"6", 35, 0},         {"7", 36, 0},
+                              {"8", 37, 0},         {"9", 38, 0},         {":", 51, 2},
+                              {";", 51, 0},         {"<", 54, 2},         {"=", 46, 0},
+                              {">", 55, 2},         {"?", 56, 2},         {"@", 31, 2},
+                              {"A", 4, 2},          {"B", 5, 2},          {"C", 6, 2},
+                              {"D", 7, 2},          {"E", 8, 2},          {"F", 9, 2},
+                              {"G", 10, 2},         {"H", 11, 2},         {"I", 12, 2},
+                              {"J", 13, 2},         {"K", 14, 2},         {"L", 15, 2},
+                              {"M", 16, 2},         {"N", 17, 2},         {"O", 18, 2},
+                              {"P", 19, 2},         {"Q", 20, 2},         {"R", 21, 2},
+                              {"S", 22, 2},         {"T", 23, 2},         {"U", 24, 2},
+                              {"V", 25, 2},         {"W", 26, 2},         {"X", 27, 2},
+                              {"Y", 28, 2},         {"Z", 29, 2},         {"[", 47, 0},
+                              {"\\", 49, 0},        {"]", 48, 0},         {"^", 35, 2},
+                              {"_", 45, 2},         {"`", 53, 0},         {"a", 4, 0},
+                              {"b", 5, 0},          {"c", 6, 0},          {"d", 7, 0},
+                              {"e", 8, 0},          {"f", 9, 0},          {"g", 10, 0},
+                              {"h", 11, 0},         {"i", 12, 0},         {"j", 13, 0},
+                              {"k", 14, 0},         {"l", 15, 0},         {"m", 16, 0},
+                              {"n", 17, 0},         {"o", 18, 0},         {"p", 19, 0},
+                              {"q", 20, 0},         {"r", 21, 0},         {"s", 22, 0},
+                              {"t", 23, 0},         {"u", 24, 0},         {"v", 25, 0},
+                              {"w", 26, 0},         {"x", 27, 0},         {"y", 28, 0},
+                              {"z", 29, 0},         {"{", 47, 2},         {"|", 49, 2},
+                              {"}", 48, 2},         {"~", 53, 2},         {"BACKSPACE", 42, 0},
+                              {"", 0, 0},           {"ALT", 0, 4},        {"SHIFT", 0, 2},
+                              {"CTRL", 0, 1},       {"GUI", 0, 8},        {"SCROLLLOCK", 71, 0},
+                              {"ENTER", 40, 0},     {"F12", 69, 0},       {"HOME", 74, 0},
+                              {"F10", 67, 0},       {"F9", 66, 0},        {"ESCAPE", 41, 0},
+                              {"PAGEUP", 75, 0},    {"TAB", 43, 0},       {"PRINTSCREEN", 70, 0},
+                              {"F2", 59, 0},        {"CAPSLOCK", 57, 0},  {"F1", 58, 0},
+                              {"F4", 61, 0},        {"F6", 63, 0},        {"F8", 65, 0},
+                              {"DOWNARROW", 81, 0}, {"DELETE", 42, 0},    {"RIGHT", 79, 0},
+                              {"F3", 60, 0},        {"DOWN", 81, 0},      {"DEL", 76, 0},
+                              {"END", 77, 0},       {"INSERT", 73, 0},    {"NUMLOCK", 83, 0},
+                              {"F5", 62, 0},        {"LEFTARROW", 80, 0}, {"RIGHTARROW", 79, 0},
+                              {"PAGEDOWN", 78, 0},  {"PAUSE", 72, 0},     {"SPACE", 44, 0},
+                              {"UPARROW", 82, 0},   {"F11", 68, 0},       {"F7", 64, 0},
+                              {"UP", 82, 0},        {"LEFT", 80, 0},      {"NUM 1", 89, 0},
+                              {"NUM 2", 90, 0},     {"NUM 3", 91, 0},     {"NUM 4", 92, 0},
+                              {"NUM 5", 93, 0},     {"NUM 6", 94, 0},     {"NUM 7", 95, 0},
+                              {"NUM 8", 96, 0},     {"NUM 9", 97, 0},     {"NUM 0", 98, 0}};
 
 /*
 static bool mj_ducky_get_number(const char* param, uint32_t* val) {
@@ -112,7 +113,8 @@ static void checksum(uint8_t* payload, size_t len) {
     // This is also from the KeyKeriki paper
     // Thanks Thorsten and Max!
     uint8_t cksum = 0xff;
-    for(size_t n = 0; n < len - 2; n++) cksum = (cksum - payload[n]) & 0xff;
+    for(size_t n = 0; n < len - 2; n++)
+        cksum = (cksum - payload[n]) & 0xff;
     cksum = (cksum + 1) & 0xff;
     payload[len - 1] = cksum;
 }
@@ -443,7 +445,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 = nrf_strtok(script, "\n");
     while(line != NULL) {
         if(strcmp(&line[strlen(line) - 1], "\r") == 0) line[strlen(line) - 1] = (char)0;
 
@@ -451,7 +453,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 = nrf_strtok(NULL, "\n");
     }
     build_hid_packet(0, 0, hid_payload);
     inject_packet(
@@ -462,4 +464,4 @@ void mj_process_ducky_script(
         hid_payload,
         LOGITECH_HID_TEMPLATE_SIZE,
         plugin_state); // empty hid packet at end
-}
+}

+ 81 - 0
stdstring.c

@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 1988 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <string.h>
+
+char* nrf_strcat(char* s, const char* append) {
+    char* save = s;
+    for(; *s; ++s)
+        ;
+    while((*s++ = *append++) != '\0')
+        ;
+    return (save);
+}
+static char* nrfstrtok_r(char* s, const char* delim, char** last) {
+    char* spanp;
+    int c, sc;
+    char* tok;
+    if(s == NULL && (s = *last) == NULL) return (NULL);
+    /*
+	 * Skip (span) leading delimiters (s += strspn(s, delim), sort of).
+	 */
+cont:
+    c = *s++;
+    for(spanp = (char*)delim; (sc = *spanp++) != 0;) {
+        if(c == sc) goto cont;
+    }
+    if(c == 0) { /* no non-delimiter characters */
+        *last = NULL;
+        return (NULL);
+    }
+    tok = s - 1;
+    /*
+	 * Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
+	 * Note that delim must have one NUL; we stop if we see that, too.
+	 */
+    for(;;) {
+        c = *s++;
+        spanp = (char*)delim;
+        do {
+            if((sc = *spanp++) == c) {
+                if(c == 0)
+                    s = NULL;
+                else
+                    s[-1] = 0;
+                *last = s;
+                return (tok);
+            }
+        } while(sc != 0);
+    }
+    /* NOTREACHED */
+}
+char* nrf_strtok(char* s, const char* delim) {
+    static char* last;
+    return nrfstrtok_r(s, delim, &last);
+}

+ 31 - 0
stdstring.h

@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 1988 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+char* nrf_strcat(char* s, const char* append);
+char* nrf_strtok(char* s, const char* delim);