mousejacker_ducky.c 19 KB

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