mousejacker_ducky.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  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++) cksum = (cksum - payload[n]) & 0xff;
  105. cksum = (cksum + 1) & 0xff;
  106. payload[len - 1] = cksum;
  107. }
  108. static void inject_packet(
  109. FuriHalSpiBusHandle* handle,
  110. uint8_t* addr,
  111. uint8_t addr_size,
  112. uint8_t rate,
  113. uint8_t* payload,
  114. size_t payload_size,
  115. PluginState* plugin_state) {
  116. uint8_t rt_count = 0;
  117. while(1) {
  118. if(!plugin_state->is_thread_running || plugin_state->close_thread_please) {
  119. return;
  120. }
  121. if(nrf24_txpacket(handle, payload, payload_size, true)) {
  122. break;
  123. }
  124. rt_count++;
  125. // retransmit threshold exceeded, scan for new channel
  126. if(rt_count > RT_THRESHOLD) {
  127. if(nrf24_find_channel(
  128. handle,
  129. addr,
  130. addr,
  131. addr_size,
  132. rate,
  133. LOGITECH_MIN_CHANNEL,
  134. LOGITECH_MAX_CHANNEL,
  135. true) > LOGITECH_MAX_CHANNEL) {
  136. return; // fail
  137. }
  138. //FURI_LOG_D("mj", "find channel passed, %d", tessst);
  139. rt_count = 0;
  140. }
  141. }
  142. }
  143. static void build_hid_packet(uint8_t mod, uint8_t hid, uint8_t* payload) {
  144. memcpy(payload, LOGITECH_HID_TEMPLATE, LOGITECH_HID_TEMPLATE_SIZE);
  145. payload[2] = mod;
  146. payload[3] = hid;
  147. checksum(payload, LOGITECH_HID_TEMPLATE_SIZE);
  148. }
  149. static void release_key(
  150. FuriHalSpiBusHandle* handle,
  151. uint8_t* addr,
  152. uint8_t addr_size,
  153. uint8_t rate,
  154. PluginState* plugin_state) {
  155. // This function release keys currently pressed, but keep pressing special keys
  156. // if holding mod keys variable are set to true
  157. uint8_t hid_payload[LOGITECH_HID_TEMPLATE_SIZE] = {0};
  158. build_hid_packet(
  159. 0 | holding_ctrl | holding_shift << 1 | holding_alt << 2 | holding_gui << 3,
  160. 0,
  161. hid_payload);
  162. inject_packet(
  163. handle,
  164. addr,
  165. addr_size,
  166. rate,
  167. hid_payload,
  168. LOGITECH_HID_TEMPLATE_SIZE,
  169. plugin_state); // empty hid packet
  170. }
  171. static void send_hid_packet(
  172. FuriHalSpiBusHandle* handle,
  173. uint8_t* addr,
  174. uint8_t addr_size,
  175. uint8_t rate,
  176. uint8_t mod,
  177. uint8_t hid,
  178. PluginState* plugin_state) {
  179. uint8_t hid_payload[LOGITECH_HID_TEMPLATE_SIZE] = {0};
  180. if(hid == prev_hid) release_key(handle, addr, addr_size, rate, plugin_state);
  181. prev_hid = hid;
  182. build_hid_packet(
  183. mod | holding_ctrl | holding_shift << 1 | holding_alt << 2 | holding_gui << 3,
  184. hid,
  185. hid_payload);
  186. inject_packet(
  187. handle, addr, addr_size, rate, hid_payload, LOGITECH_HID_TEMPLATE_SIZE, plugin_state);
  188. furi_delay_ms(12);
  189. }
  190. static bool ducky_end_line(const char chr) {
  191. return ((chr == ' ') || (chr == '\0') || (chr == '\r') || (chr == '\n'));
  192. }
  193. // returns false if there was an error processing script line
  194. static bool mj_process_ducky_line(
  195. FuriHalSpiBusHandle* handle,
  196. uint8_t* addr,
  197. uint8_t addr_size,
  198. uint8_t rate,
  199. char* line,
  200. char* prev_line,
  201. PluginState* plugin_state) {
  202. MJDuckyKey dk;
  203. uint8_t hid_payload[LOGITECH_HID_TEMPLATE_SIZE] = {0};
  204. char* line_tmp = line;
  205. uint32_t line_len = strlen(line);
  206. if(!plugin_state->is_thread_running || plugin_state->close_thread_please) {
  207. return true;
  208. }
  209. for(uint32_t i = 0; i < line_len; i++) {
  210. if((line_tmp[i] != ' ') && (line_tmp[i] != '\t') && (line_tmp[i] != '\n')) {
  211. line_tmp = &line_tmp[i];
  212. break; // Skip spaces and tabs
  213. }
  214. if(i == line_len - 1) return true; // Skip empty lines
  215. }
  216. FURI_LOG_D(TAG, "line: %s", line_tmp);
  217. // General commands
  218. if(strncmp(line_tmp, ducky_cmd_comment, strlen(ducky_cmd_comment)) == 0) {
  219. // REM - comment line
  220. return true;
  221. } else if(strncmp(line_tmp, ducky_cmd_delay, strlen(ducky_cmd_delay)) == 0) {
  222. // DELAY
  223. line_tmp = &line_tmp[mj_ducky_get_command_len(line_tmp) + 1];
  224. uint32_t delay_val = 0;
  225. delay_val = atoi(line_tmp);
  226. if(delay_val > 0) {
  227. uint32_t delay_count = delay_val / 10;
  228. build_hid_packet(0, 0, hid_payload);
  229. inject_packet(
  230. handle,
  231. addr,
  232. addr_size,
  233. rate,
  234. hid_payload,
  235. LOGITECH_HID_TEMPLATE_SIZE,
  236. plugin_state); // empty hid packet
  237. for(uint32_t i = 0; i < delay_count; i++) {
  238. if(!plugin_state->is_thread_running || plugin_state->close_thread_please) {
  239. return true;
  240. }
  241. inject_packet(
  242. handle,
  243. addr,
  244. addr_size,
  245. rate,
  246. LOGITECH_KEEPALIVE,
  247. LOGITECH_KEEPALIVE_SIZE,
  248. plugin_state);
  249. furi_delay_ms(10);
  250. }
  251. return true;
  252. }
  253. return false;
  254. } else if(strncmp(line_tmp, ducky_cmd_string, strlen(ducky_cmd_string)) == 0) {
  255. // STRING
  256. line_tmp = &line_tmp[mj_ducky_get_command_len(line_tmp) + 1];
  257. for(size_t i = 0; i < strlen(line_tmp); i++) {
  258. if(!mj_get_ducky_key(&line_tmp[i], 1, &dk)) return false;
  259. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  260. }
  261. return true;
  262. } else if(strncmp(line_tmp, ducky_cmd_altstring, strlen(ducky_cmd_altstring)) == 0) {
  263. // ALTSTRING
  264. line_tmp = &line_tmp[mj_ducky_get_command_len(line_tmp) + 1];
  265. for(size_t i = 0; i < strlen(line_tmp); i++) {
  266. if((line_tmp[i] < ' ') || (line_tmp[i] > '~')) {
  267. continue; // Skip non-printable chars
  268. }
  269. char alt_code[4];
  270. // Getting altcode of the char
  271. snprintf(alt_code, 4, "%u", line_tmp[i]);
  272. uint8_t j = 0;
  273. while(!ducky_end_line(alt_code[j])) {
  274. char pad_num[5] = {'N', 'U', 'M', ' ', alt_code[j]};
  275. if(!mj_get_ducky_key(pad_num, 5, &dk)) return false;
  276. holding_alt = true;
  277. FURI_LOG_D(TAG, "Sending %s", pad_num);
  278. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  279. j++;
  280. }
  281. holding_alt = false;
  282. release_key(handle, addr, addr_size, rate, plugin_state);
  283. }
  284. return true;
  285. } else if(strncmp(line_tmp, ducky_cmd_repeat, strlen(ducky_cmd_repeat)) == 0) {
  286. // REPEAT
  287. uint32_t repeat_cnt = 0;
  288. if(prev_line == NULL) return false;
  289. line_tmp = &line_tmp[mj_ducky_get_command_len(line_tmp) + 1];
  290. repeat_cnt = atoi(line_tmp);
  291. if(repeat_cnt < 2) return false;
  292. FURI_LOG_D(TAG, "repeating %s %ld times", prev_line, repeat_cnt);
  293. for(uint32_t i = 0; i < repeat_cnt; i++)
  294. mj_process_ducky_line(handle, addr, addr_size, rate, prev_line, NULL, plugin_state);
  295. return true;
  296. } else if(strncmp(line_tmp, "ALT", strlen("ALT")) == 0) {
  297. line_tmp = &line_tmp[mj_ducky_get_command_len(line_tmp) + 1];
  298. if(!mj_get_ducky_key(line_tmp, strlen(line_tmp), &dk)) return false;
  299. holding_alt = true;
  300. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  301. holding_alt = false;
  302. return true;
  303. } else if(
  304. strncmp(line_tmp, "GUI", strlen("GUI")) == 0 ||
  305. strncmp(line_tmp, "WINDOWS", strlen("WINDOWS")) == 0 ||
  306. strncmp(line_tmp, "COMMAND", strlen("COMMAND")) == 0) {
  307. line_tmp = &line_tmp[mj_ducky_get_command_len(line_tmp) + 1];
  308. if(!mj_get_ducky_key(line_tmp, strlen(line_tmp), &dk)) return false;
  309. holding_gui = true;
  310. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  311. holding_gui = false;
  312. return true;
  313. } else if(
  314. strncmp(line_tmp, "CTRL-ALT", strlen("CTRL-ALT")) == 0 ||
  315. strncmp(line_tmp, "CONTROL-ALT", strlen("CONTROL-ALT")) == 0) {
  316. line_tmp = &line_tmp[mj_ducky_get_command_len(line_tmp) + 1];
  317. if(!mj_get_ducky_key(line_tmp, strlen(line_tmp), &dk)) return false;
  318. holding_ctrl = true;
  319. holding_alt = true;
  320. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  321. holding_ctrl = false;
  322. holding_alt = false;
  323. return true;
  324. } else if(
  325. strncmp(line_tmp, "CTRL-SHIFT", strlen("CTRL-SHIFT")) == 0 ||
  326. strncmp(line_tmp, "CONTROL-SHIFT", strlen("CONTROL-SHIFT")) == 0) {
  327. line_tmp = &line_tmp[mj_ducky_get_command_len(line_tmp) + 1];
  328. if(!mj_get_ducky_key(line_tmp, strlen(line_tmp), &dk)) return false;
  329. holding_ctrl = true;
  330. holding_shift = true;
  331. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  332. holding_ctrl = false;
  333. holding_shift = false;
  334. return true;
  335. } else if(
  336. strncmp(line_tmp, "CTRL", strlen("CTRL")) == 0 ||
  337. strncmp(line_tmp, "CONTROL", strlen("CONTROL")) == 0) {
  338. line_tmp = &line_tmp[mj_ducky_get_command_len(line_tmp) + 1];
  339. if(!mj_get_ducky_key(line_tmp, strlen(line_tmp), &dk)) return false;
  340. holding_ctrl = true;
  341. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  342. holding_ctrl = false;
  343. return true;
  344. } else if(strncmp(line_tmp, "SHIFT", strlen("SHIFT")) == 0) {
  345. line_tmp = &line_tmp[mj_ducky_get_command_len(line_tmp) + 1];
  346. if(!mj_get_ducky_key(line_tmp, strlen(line_tmp), &dk)) return false;
  347. holding_shift = true;
  348. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  349. holding_shift = false;
  350. return true;
  351. } else if(
  352. strncmp(line_tmp, "ESC", strlen("ESC")) == 0 ||
  353. strncmp(line_tmp, "APP", strlen("APP")) == 0 ||
  354. strncmp(line_tmp, "ESCAPE", strlen("ESCAPE")) == 0) {
  355. if(!mj_get_ducky_key("ESCAPE", 6, &dk)) return false;
  356. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  357. return true;
  358. } else if(strncmp(line_tmp, "ENTER", strlen("ENTER")) == 0) {
  359. if(!mj_get_ducky_key("ENTER", 5, &dk)) return false;
  360. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  361. return true;
  362. } else if(
  363. strncmp(line_tmp, "UP", strlen("UP")) == 0 ||
  364. strncmp(line_tmp, "UPARROW", strlen("UPARROW")) == 0) {
  365. if(!mj_get_ducky_key("UP", 2, &dk)) return false;
  366. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  367. return true;
  368. } else if(
  369. strncmp(line_tmp, "DOWN", strlen("DOWN")) == 0 ||
  370. strncmp(line_tmp, "DOWNARROW", strlen("DOWNARROW")) == 0) {
  371. if(!mj_get_ducky_key("DOWN", 4, &dk)) return false;
  372. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  373. return true;
  374. } else if(
  375. strncmp(line_tmp, "LEFT", strlen("LEFT")) == 0 ||
  376. strncmp(line_tmp, "LEFTARROW", strlen("LEFTARROW")) == 0) {
  377. if(!mj_get_ducky_key("LEFT", 4, &dk)) return false;
  378. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  379. return true;
  380. } else if(
  381. strncmp(line_tmp, "RIGHT", strlen("RIGHT")) == 0 ||
  382. strncmp(line_tmp, "RIGHTARROW", strlen("RIGHTARROW")) == 0) {
  383. if(!mj_get_ducky_key("RIGHT", 5, &dk)) return false;
  384. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  385. return true;
  386. } else if(strncmp(line_tmp, "SPACE", strlen("SPACE")) == 0) {
  387. if(!mj_get_ducky_key("SPACE", 5, &dk)) return false;
  388. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  389. return true;
  390. } else if(strncmp(line_tmp, "TAB", strlen("TAB")) == 0) {
  391. if(!mj_get_ducky_key("TAB", 3, &dk)) return false;
  392. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  393. return true;
  394. } else if(strncmp(line_tmp, "NUMLOCK", strlen("NUMLOCK")) == 0) {
  395. if(!mj_get_ducky_key("NUMLOCK", 7, &dk)) return false;
  396. send_hid_packet(handle, addr, addr_size, rate, dk.mod, dk.hid, plugin_state);
  397. return true;
  398. }
  399. return false;
  400. }
  401. void mj_process_ducky_script(
  402. FuriHalSpiBusHandle* handle,
  403. uint8_t* addr,
  404. uint8_t addr_size,
  405. uint8_t rate,
  406. char* script,
  407. PluginState* plugin_state) {
  408. uint8_t hid_payload[LOGITECH_HID_TEMPLATE_SIZE] = {0};
  409. char* prev_line = NULL;
  410. inject_packet(
  411. handle, addr, addr_size, rate, LOGITECH_HELLO, LOGITECH_HELLO_SIZE, plugin_state);
  412. char* line = strtok(script, "\n");
  413. while(line != NULL) {
  414. if(strcmp(&line[strlen(line) - 1], "\r") == 0) line[strlen(line) - 1] = (char)0;
  415. if(!mj_process_ducky_line(handle, addr, addr_size, rate, line, prev_line, plugin_state))
  416. FURI_LOG_D(TAG, "unable to process ducky script line: %s", line);
  417. prev_line = line;
  418. line = strtok(NULL, "\n");
  419. }
  420. build_hid_packet(0, 0, hid_payload);
  421. inject_packet(
  422. handle,
  423. addr,
  424. addr_size,
  425. rate,
  426. hid_payload,
  427. LOGITECH_HID_TEMPLATE_SIZE,
  428. plugin_state); // empty hid packet at end
  429. }