mousejacker_ducky.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. #include "mousejacker_ducky.h"
  2. #include "stdstring.h"
  3. static const char ducky_cmd_comment[] = {"REM"};
  4. static const char ducky_cmd_delay[] = {"DELAY "};
  5. static const char ducky_cmd_string[] = {"STRING "};
  6. static const char ducky_cmd_altstring[] = {"ALTSTRING "};
  7. static const char ducky_cmd_repeat[] = {"REPEAT "};
  8. static uint8_t LOGITECH_HID_TEMPLATE[] =
  9. {0x00, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  10. static uint8_t LOGITECH_HELLO[] = {0x00, 0x4F, 0x00, 0x04, 0xB0, 0x10, 0x00, 0x00, 0x00, 0xED};
  11. static uint8_t LOGITECH_KEEPALIVE[] = {0x00, 0x40, 0x00, 0x55, 0x6B};
  12. uint8_t prev_hid = 0;
  13. static bool holding_ctrl = false;
  14. static bool holding_shift = false;
  15. static bool holding_alt = false;
  16. static bool holding_gui = false;
  17. #define RT_THRESHOLD 50
  18. #define LOGITECH_MIN_CHANNEL 2
  19. #define LOGITECH_MAX_CHANNEL 83
  20. #define LOGITECH_KEEPALIVE_SIZE 5
  21. #define LOGITECH_HID_TEMPLATE_SIZE 10
  22. #define LOGITECH_HELLO_SIZE 10
  23. #define TAG "mousejacker_ducky"
  24. MJDuckyKey mj_ducky_keys[] = {{" ", 44, 0}, {"!", 30, 2}, {"\"", 52, 2},
  25. {"#", 32, 2}, {"$", 33, 2}, {"%", 34, 2},
  26. {"&", 36, 2}, {"'", 52, 0}, {"(", 38, 2},
  27. {")", 39, 2}, {"*", 37, 2}, {"+", 46, 2},
  28. {",", 54, 0}, {"-", 45, 0}, {".", 55, 0},
  29. {"/", 56, 0}, {"0", 39, 0}, {"1", 30, 0},
  30. {"2", 31, 0}, {"3", 32, 0}, {"4", 33, 0},
  31. {"5", 34, 0}, {"6", 35, 0}, {"7", 36, 0},
  32. {"8", 37, 0}, {"9", 38, 0}, {":", 51, 2},
  33. {";", 51, 0}, {"<", 54, 2}, {"=", 46, 0},
  34. {">", 55, 2}, {"?", 56, 2}, {"@", 31, 2},
  35. {"A", 4, 2}, {"B", 5, 2}, {"C", 6, 2},
  36. {"D", 7, 2}, {"E", 8, 2}, {"F", 9, 2},
  37. {"G", 10, 2}, {"H", 11, 2}, {"I", 12, 2},
  38. {"J", 13, 2}, {"K", 14, 2}, {"L", 15, 2},
  39. {"M", 16, 2}, {"N", 17, 2}, {"O", 18, 2},
  40. {"P", 19, 2}, {"Q", 20, 2}, {"R", 21, 2},
  41. {"S", 22, 2}, {"T", 23, 2}, {"U", 24, 2},
  42. {"V", 25, 2}, {"W", 26, 2}, {"X", 27, 2},
  43. {"Y", 28, 2}, {"Z", 29, 2}, {"[", 47, 0},
  44. {"\\", 49, 0}, {"]", 48, 0}, {"^", 35, 2},
  45. {"_", 45, 2}, {"`", 53, 0}, {"a", 4, 0},
  46. {"b", 5, 0}, {"c", 6, 0}, {"d", 7, 0},
  47. {"e", 8, 0}, {"f", 9, 0}, {"g", 10, 0},
  48. {"h", 11, 0}, {"i", 12, 0}, {"j", 13, 0},
  49. {"k", 14, 0}, {"l", 15, 0}, {"m", 16, 0},
  50. {"n", 17, 0}, {"o", 18, 0}, {"p", 19, 0},
  51. {"q", 20, 0}, {"r", 21, 0}, {"s", 22, 0},
  52. {"t", 23, 0}, {"u", 24, 0}, {"v", 25, 0},
  53. {"w", 26, 0}, {"x", 27, 0}, {"y", 28, 0},
  54. {"z", 29, 0}, {"{", 47, 2}, {"|", 49, 2},
  55. {"}", 48, 2}, {"~", 53, 2}, {"BACKSPACE", 42, 0},
  56. {"", 0, 0}, {"ALT", 0, 4}, {"SHIFT", 0, 2},
  57. {"CTRL", 0, 1}, {"GUI", 0, 8}, {"SCROLLLOCK", 71, 0},
  58. {"ENTER", 40, 0}, {"F12", 69, 0}, {"HOME", 74, 0},
  59. {"F10", 67, 0}, {"F9", 66, 0}, {"ESCAPE", 41, 0},
  60. {"PAGEUP", 75, 0}, {"TAB", 43, 0}, {"PRINTSCREEN", 70, 0},
  61. {"F2", 59, 0}, {"CAPSLOCK", 57, 0}, {"F1", 58, 0},
  62. {"F4", 61, 0}, {"F6", 63, 0}, {"F8", 65, 0},
  63. {"DOWNARROW", 81, 0}, {"DELETE", 42, 0}, {"RIGHT", 79, 0},
  64. {"F3", 60, 0}, {"DOWN", 81, 0}, {"DEL", 76, 0},
  65. {"END", 77, 0}, {"INSERT", 73, 0}, {"NUMLOCK", 83, 0},
  66. {"F5", 62, 0}, {"LEFTARROW", 80, 0}, {"RIGHTARROW", 79, 0},
  67. {"PAGEDOWN", 78, 0}, {"PAUSE", 72, 0}, {"SPACE", 44, 0},
  68. {"UPARROW", 82, 0}, {"F11", 68, 0}, {"F7", 64, 0},
  69. {"UP", 82, 0}, {"LEFT", 80, 0}, {"NUM 1", 89, 0},
  70. {"NUM 2", 90, 0}, {"NUM 3", 91, 0}, {"NUM 4", 92, 0},
  71. {"NUM 5", 93, 0}, {"NUM 6", 94, 0}, {"NUM 7", 95, 0},
  72. {"NUM 8", 96, 0}, {"NUM 9", 97, 0}, {"NUM 0", 98, 0}};
  73. /*
  74. static bool mj_ducky_get_number(const char* param, uint32_t* val) {
  75. uint32_t value = 0;
  76. if(sscanf(param, "%lu", &value) == 1) {
  77. *val = value;
  78. return true;
  79. }
  80. return false;
  81. }
  82. */
  83. static uint32_t mj_ducky_get_command_len(const char* line) {
  84. uint32_t len = strlen(line);
  85. for(uint32_t i = 0; i < len; i++) {
  86. if(line[i] == ' ') return i;
  87. }
  88. return 0;
  89. }
  90. static bool mj_get_ducky_key(char* key, size_t keylen, MJDuckyKey* dk) {
  91. //FURI_LOG_D(TAG, "looking up key %s with length %d", key, keylen);
  92. for(size_t i = 0; i < sizeof(mj_ducky_keys) / sizeof(MJDuckyKey); i++) {
  93. if(strlen(mj_ducky_keys[i].name) == keylen &&
  94. !strncmp(mj_ducky_keys[i].name, key, keylen)) {
  95. memcpy(dk, &mj_ducky_keys[i], sizeof(MJDuckyKey));
  96. return true;
  97. }
  98. }
  99. return false;
  100. }
  101. static void checksum(uint8_t* payload, size_t len) {
  102. // This is also from the KeyKeriki paper
  103. // Thanks Thorsten and Max!
  104. uint8_t cksum = 0xff;
  105. for(size_t n = 0; n < len - 2; n++)
  106. cksum = (cksum - payload[n]) & 0xff;
  107. cksum = (cksum + 1) & 0xff;
  108. payload[len - 1] = cksum;
  109. }
  110. static void inject_packet(
  111. FuriHalSpiBusHandle* handle,
  112. uint8_t* addr,
  113. uint8_t addr_size,
  114. uint8_t rate,
  115. uint8_t* payload,
  116. size_t payload_size,
  117. PluginState* plugin_state) {
  118. uint8_t rt_count = 0;
  119. while(1) {
  120. if(!plugin_state->is_thread_running || plugin_state->close_thread_please) {
  121. return;
  122. }
  123. if(nrf24_txpacket(handle, payload, payload_size, true)) {
  124. break;
  125. }
  126. rt_count++;
  127. // retransmit threshold exceeded, scan for new channel
  128. if(rt_count > RT_THRESHOLD) {
  129. if(nrf24_find_channel(
  130. handle,
  131. addr,
  132. addr,
  133. addr_size,
  134. rate,
  135. LOGITECH_MIN_CHANNEL,
  136. LOGITECH_MAX_CHANNEL,
  137. true) > LOGITECH_MAX_CHANNEL) {
  138. return; // fail
  139. }
  140. //FURI_LOG_D("mj", "find channel passed, %d", tessst);
  141. rt_count = 0;
  142. }
  143. }
  144. }
  145. static void build_hid_packet(uint8_t mod, uint8_t hid, uint8_t* payload) {
  146. memcpy(payload, LOGITECH_HID_TEMPLATE, LOGITECH_HID_TEMPLATE_SIZE);
  147. payload[2] = mod;
  148. payload[3] = hid;
  149. checksum(payload, LOGITECH_HID_TEMPLATE_SIZE);
  150. }
  151. static void release_key(
  152. FuriHalSpiBusHandle* handle,
  153. uint8_t* addr,
  154. uint8_t addr_size,
  155. uint8_t rate,
  156. PluginState* plugin_state) {
  157. // This function release keys currently pressed, but keep pressing special keys
  158. // if holding mod keys variable are set to true
  159. uint8_t hid_payload[LOGITECH_HID_TEMPLATE_SIZE] = {0};
  160. build_hid_packet(
  161. 0 | holding_ctrl | holding_shift << 1 | holding_alt << 2 | holding_gui << 3,
  162. 0,
  163. hid_payload);
  164. inject_packet(
  165. handle,
  166. addr,
  167. addr_size,
  168. rate,
  169. hid_payload,
  170. LOGITECH_HID_TEMPLATE_SIZE,
  171. plugin_state); // empty hid packet
  172. }
  173. static void send_hid_packet(
  174. FuriHalSpiBusHandle* handle,
  175. uint8_t* addr,
  176. uint8_t addr_size,
  177. uint8_t rate,
  178. uint8_t mod,
  179. uint8_t hid,
  180. PluginState* plugin_state) {
  181. uint8_t hid_payload[LOGITECH_HID_TEMPLATE_SIZE] = {0};
  182. if(hid == prev_hid) release_key(handle, addr, addr_size, rate, plugin_state);
  183. prev_hid = hid;
  184. build_hid_packet(
  185. mod | holding_ctrl | holding_shift << 1 | holding_alt << 2 | holding_gui << 3,
  186. hid,
  187. hid_payload);
  188. inject_packet(
  189. handle, addr, addr_size, rate, hid_payload, LOGITECH_HID_TEMPLATE_SIZE, plugin_state);
  190. furi_delay_ms(12);
  191. }
  192. static bool ducky_end_line(const char chr) {
  193. return ((chr == ' ') || (chr == '\0') || (chr == '\r') || (chr == '\n'));
  194. }
  195. // returns false if there was an error processing script line
  196. static bool mj_process_ducky_line(
  197. FuriHalSpiBusHandle* handle,
  198. uint8_t* addr,
  199. uint8_t addr_size,
  200. uint8_t rate,
  201. char* line,
  202. char* prev_line,
  203. PluginState* plugin_state) {
  204. MJDuckyKey dk;
  205. uint8_t hid_payload[LOGITECH_HID_TEMPLATE_SIZE] = {0};
  206. char* line_tmp = line;
  207. uint32_t line_len = strlen(line);
  208. if(!plugin_state->is_thread_running || plugin_state->close_thread_please) {
  209. return true;
  210. }
  211. for(uint32_t i = 0; i < line_len; i++) {
  212. if((line_tmp[i] != ' ') && (line_tmp[i] != '\t') && (line_tmp[i] != '\n')) {
  213. line_tmp = &line_tmp[i];
  214. break; // Skip spaces and tabs
  215. }
  216. if(i == line_len - 1) return true; // Skip empty lines
  217. }
  218. FURI_LOG_D(TAG, "line: %s", line_tmp);
  219. // General commands
  220. if(strncmp(line_tmp, ducky_cmd_comment, strlen(ducky_cmd_comment)) == 0) {
  221. // REM - comment line
  222. return true;
  223. } else if(strncmp(line_tmp, ducky_cmd_delay, strlen(ducky_cmd_delay)) == 0) {
  224. // DELAY
  225. line_tmp = &line_tmp[mj_ducky_get_command_len(line_tmp) + 1];
  226. uint32_t delay_val = 0;
  227. delay_val = atoi(line_tmp);
  228. if(delay_val > 0) {
  229. uint32_t delay_count = delay_val / 10;
  230. build_hid_packet(0, 0, hid_payload);
  231. inject_packet(
  232. handle,
  233. addr,
  234. addr_size,
  235. rate,
  236. hid_payload,
  237. LOGITECH_HID_TEMPLATE_SIZE,
  238. plugin_state); // empty hid packet
  239. for(uint32_t i = 0; i < delay_count; i++) {
  240. if(!plugin_state->is_thread_running || plugin_state->close_thread_please) {
  241. return true;
  242. }
  243. inject_packet(
  244. handle,
  245. addr,
  246. addr_size,
  247. rate,
  248. LOGITECH_KEEPALIVE,
  249. LOGITECH_KEEPALIVE_SIZE,
  250. plugin_state);
  251. furi_delay_ms(10);
  252. }
  253. return true;
  254. }
  255. return false;
  256. } else if(strncmp(line_tmp, ducky_cmd_string, strlen(ducky_cmd_string)) == 0) {
  257. // STRING
  258. line_tmp = &line_tmp[mj_ducky_get_command_len(line_tmp) + 1];
  259. for(size_t i = 0; i < strlen(line_tmp); i++) {
  260. if(!mj_get_ducky_key(&line_tmp[i], 1, &dk)) return false;
  261. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  262. }
  263. return true;
  264. } else if(strncmp(line_tmp, ducky_cmd_altstring, strlen(ducky_cmd_altstring)) == 0) {
  265. // ALTSTRING
  266. line_tmp = &line_tmp[mj_ducky_get_command_len(line_tmp) + 1];
  267. for(size_t i = 0; i < strlen(line_tmp); i++) {
  268. if((line_tmp[i] < ' ') || (line_tmp[i] > '~')) {
  269. continue; // Skip non-printable chars
  270. }
  271. char alt_code[4];
  272. // Getting altcode of the char
  273. snprintf(alt_code, 4, "%u", line_tmp[i]);
  274. uint8_t j = 0;
  275. while(!ducky_end_line(alt_code[j])) {
  276. char pad_num[5] = {'N', 'U', 'M', ' ', alt_code[j]};
  277. if(!mj_get_ducky_key(pad_num, 5, &dk)) return false;
  278. holding_alt = true;
  279. FURI_LOG_D(TAG, "Sending %s", pad_num);
  280. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  281. j++;
  282. }
  283. holding_alt = false;
  284. release_key(handle, addr, addr_size, rate, plugin_state);
  285. }
  286. return true;
  287. } else if(strncmp(line_tmp, ducky_cmd_repeat, strlen(ducky_cmd_repeat)) == 0) {
  288. // REPEAT
  289. uint32_t repeat_cnt = 0;
  290. if(prev_line == NULL) return false;
  291. line_tmp = &line_tmp[mj_ducky_get_command_len(line_tmp) + 1];
  292. repeat_cnt = atoi(line_tmp);
  293. if(repeat_cnt < 2) return false;
  294. FURI_LOG_D(TAG, "repeating %s %ld times", prev_line, repeat_cnt);
  295. for(uint32_t i = 0; i < repeat_cnt; i++)
  296. mj_process_ducky_line(handle, addr, addr_size, rate, prev_line, NULL, plugin_state);
  297. return true;
  298. } else if(strncmp(line_tmp, "ALT", strlen("ALT")) == 0) {
  299. line_tmp = &line_tmp[mj_ducky_get_command_len(line_tmp) + 1];
  300. if(!mj_get_ducky_key(line_tmp, strlen(line_tmp), &dk)) return false;
  301. holding_alt = true;
  302. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  303. holding_alt = false;
  304. return true;
  305. } else if(
  306. strncmp(line_tmp, "GUI", strlen("GUI")) == 0 ||
  307. strncmp(line_tmp, "WINDOWS", strlen("WINDOWS")) == 0 ||
  308. strncmp(line_tmp, "COMMAND", strlen("COMMAND")) == 0) {
  309. line_tmp = &line_tmp[mj_ducky_get_command_len(line_tmp) + 1];
  310. if(!mj_get_ducky_key(line_tmp, strlen(line_tmp), &dk)) return false;
  311. holding_gui = true;
  312. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  313. holding_gui = false;
  314. return true;
  315. } else if(
  316. strncmp(line_tmp, "CTRL-ALT", strlen("CTRL-ALT")) == 0 ||
  317. strncmp(line_tmp, "CONTROL-ALT", strlen("CONTROL-ALT")) == 0) {
  318. line_tmp = &line_tmp[mj_ducky_get_command_len(line_tmp) + 1];
  319. if(!mj_get_ducky_key(line_tmp, strlen(line_tmp), &dk)) return false;
  320. holding_ctrl = true;
  321. holding_alt = true;
  322. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  323. holding_ctrl = false;
  324. holding_alt = false;
  325. return true;
  326. } else if(
  327. strncmp(line_tmp, "CTRL-SHIFT", strlen("CTRL-SHIFT")) == 0 ||
  328. strncmp(line_tmp, "CONTROL-SHIFT", strlen("CONTROL-SHIFT")) == 0) {
  329. line_tmp = &line_tmp[mj_ducky_get_command_len(line_tmp) + 1];
  330. if(!mj_get_ducky_key(line_tmp, strlen(line_tmp), &dk)) return false;
  331. holding_ctrl = true;
  332. holding_shift = true;
  333. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  334. holding_ctrl = false;
  335. holding_shift = false;
  336. return true;
  337. } else if(
  338. strncmp(line_tmp, "CTRL", strlen("CTRL")) == 0 ||
  339. strncmp(line_tmp, "CONTROL", strlen("CONTROL")) == 0) {
  340. line_tmp = &line_tmp[mj_ducky_get_command_len(line_tmp) + 1];
  341. if(!mj_get_ducky_key(line_tmp, strlen(line_tmp), &dk)) return false;
  342. holding_ctrl = true;
  343. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  344. holding_ctrl = false;
  345. return true;
  346. } else if(strncmp(line_tmp, "SHIFT", strlen("SHIFT")) == 0) {
  347. line_tmp = &line_tmp[mj_ducky_get_command_len(line_tmp) + 1];
  348. if(!mj_get_ducky_key(line_tmp, strlen(line_tmp), &dk)) return false;
  349. holding_shift = true;
  350. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  351. holding_shift = false;
  352. return true;
  353. } else if(
  354. strncmp(line_tmp, "ESC", strlen("ESC")) == 0 ||
  355. strncmp(line_tmp, "APP", strlen("APP")) == 0 ||
  356. strncmp(line_tmp, "ESCAPE", strlen("ESCAPE")) == 0) {
  357. if(!mj_get_ducky_key("ESCAPE", 6, &dk)) return false;
  358. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  359. return true;
  360. } else if(strncmp(line_tmp, "ENTER", strlen("ENTER")) == 0) {
  361. if(!mj_get_ducky_key("ENTER", 5, &dk)) return false;
  362. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  363. return true;
  364. } else if(
  365. strncmp(line_tmp, "UP", strlen("UP")) == 0 ||
  366. strncmp(line_tmp, "UPARROW", strlen("UPARROW")) == 0) {
  367. if(!mj_get_ducky_key("UP", 2, &dk)) return false;
  368. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  369. return true;
  370. } else if(
  371. strncmp(line_tmp, "DOWN", strlen("DOWN")) == 0 ||
  372. strncmp(line_tmp, "DOWNARROW", strlen("DOWNARROW")) == 0) {
  373. if(!mj_get_ducky_key("DOWN", 4, &dk)) return false;
  374. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  375. return true;
  376. } else if(
  377. strncmp(line_tmp, "LEFT", strlen("LEFT")) == 0 ||
  378. strncmp(line_tmp, "LEFTARROW", strlen("LEFTARROW")) == 0) {
  379. if(!mj_get_ducky_key("LEFT", 4, &dk)) return false;
  380. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  381. return true;
  382. } else if(
  383. strncmp(line_tmp, "RIGHT", strlen("RIGHT")) == 0 ||
  384. strncmp(line_tmp, "RIGHTARROW", strlen("RIGHTARROW")) == 0) {
  385. if(!mj_get_ducky_key("RIGHT", 5, &dk)) return false;
  386. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  387. return true;
  388. } else if(strncmp(line_tmp, "SPACE", strlen("SPACE")) == 0) {
  389. if(!mj_get_ducky_key("SPACE", 5, &dk)) return false;
  390. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  391. return true;
  392. } else if(strncmp(line_tmp, "TAB", strlen("TAB")) == 0) {
  393. if(!mj_get_ducky_key("TAB", 3, &dk)) return false;
  394. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  395. return true;
  396. } else if(strncmp(line_tmp, "NUMLOCK", strlen("NUMLOCK")) == 0) {
  397. if(!mj_get_ducky_key("NUMLOCK", 7, &dk)) return false;
  398. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  399. return true;
  400. }
  401. return false;
  402. }
  403. void mj_process_ducky_script(
  404. FuriHalSpiBusHandle* handle,
  405. uint8_t* addr,
  406. uint8_t addr_size,
  407. uint8_t rate,
  408. char* script,
  409. PluginState* plugin_state) {
  410. uint8_t hid_payload[LOGITECH_HID_TEMPLATE_SIZE] = {0};
  411. char* prev_line = NULL;
  412. inject_packet(
  413. handle, addr, addr_size, rate, LOGITECH_HELLO, LOGITECH_HELLO_SIZE, plugin_state);
  414. char* line = nrf_strtok(script, "\n");
  415. while(line != NULL) {
  416. if(strcmp(&line[strlen(line) - 1], "\r") == 0) line[strlen(line) - 1] = (char)0;
  417. if(!mj_process_ducky_line(handle, addr, addr_size, rate, line, prev_line, plugin_state))
  418. FURI_LOG_D(TAG, "unable to process ducky script line: %s", line);
  419. prev_line = line;
  420. line = nrf_strtok(NULL, "\n");
  421. }
  422. build_hid_packet(0, 0, hid_payload);
  423. inject_packet(
  424. handle,
  425. addr,
  426. addr_size,
  427. rate,
  428. hid_payload,
  429. LOGITECH_HID_TEMPLATE_SIZE,
  430. plugin_state); // empty hid packet at end
  431. }