fuzzer.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #include "fuzzer_i.h"
  2. #include "helpers/fuzzer_types.h"
  3. static bool fuzzer_app_custom_event_callback(void* context, uint32_t event) {
  4. furi_assert(context);
  5. PacsFuzzerApp* app = context;
  6. return scene_manager_handle_custom_event(app->scene_manager, event);
  7. }
  8. static bool fuzzer_app_back_event_callback(void* context) {
  9. furi_assert(context);
  10. PacsFuzzerApp* app = context;
  11. return scene_manager_handle_back_event(app->scene_manager);
  12. }
  13. static void fuzzer_app_tick_event_callback(void* context) {
  14. furi_assert(context);
  15. PacsFuzzerApp* app = context;
  16. scene_manager_handle_tick_event(app->scene_manager);
  17. }
  18. PacsFuzzerApp* fuzzer_app_alloc() {
  19. PacsFuzzerApp* app = malloc(sizeof(PacsFuzzerApp));
  20. app->fuzzer_state.menu_index = 0;
  21. app->fuzzer_state.proto_index = 0;
  22. app->worker = fuzzer_worker_alloc();
  23. app->payload = fuzzer_payload_alloc();
  24. app->file_path = furi_string_alloc();
  25. // GUI
  26. app->gui = furi_record_open(RECORD_GUI);
  27. // Dialog
  28. app->dialogs = furi_record_open(RECORD_DIALOGS);
  29. // Open Notification record
  30. app->notifications = furi_record_open(RECORD_NOTIFICATION);
  31. // View Dispatcher
  32. app->view_dispatcher = view_dispatcher_alloc();
  33. // Popup
  34. app->popup = popup_alloc();
  35. view_dispatcher_add_view(app->view_dispatcher, FuzzerViewIDPopup, popup_get_view(app->popup));
  36. // TextInput
  37. app->text_input = text_input_alloc();
  38. view_dispatcher_add_view(
  39. app->view_dispatcher, FuzzerViewIDTextInput, text_input_get_view(app->text_input));
  40. // Main view
  41. app->main_view = fuzzer_view_main_alloc();
  42. view_dispatcher_add_view(
  43. app->view_dispatcher, FuzzerViewIDMain, fuzzer_view_main_get_view(app->main_view));
  44. // Attack view
  45. app->attack_view = fuzzer_view_attack_alloc();
  46. view_dispatcher_add_view(
  47. app->view_dispatcher, FuzzerViewIDAttack, fuzzer_view_attack_get_view(app->attack_view));
  48. // FieldEditor view
  49. app->field_editor_view = fuzzer_view_field_editor_alloc();
  50. view_dispatcher_add_view(
  51. app->view_dispatcher,
  52. FuzzerViewIDFieldEditor,
  53. fuzzer_view_field_editor_get_view(app->field_editor_view));
  54. app->scene_manager = scene_manager_alloc(&fuzzer_scene_handlers, app);
  55. view_dispatcher_enable_queue(app->view_dispatcher);
  56. view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
  57. view_dispatcher_set_custom_event_callback(
  58. app->view_dispatcher, fuzzer_app_custom_event_callback);
  59. view_dispatcher_set_navigation_event_callback(
  60. app->view_dispatcher, fuzzer_app_back_event_callback);
  61. view_dispatcher_set_tick_event_callback(
  62. app->view_dispatcher, fuzzer_app_tick_event_callback, 100);
  63. view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
  64. scene_manager_next_scene(app->scene_manager, FuzzerSceneMain);
  65. return app;
  66. }
  67. void fuzzer_app_free(PacsFuzzerApp* app) {
  68. furi_assert(app);
  69. // Remote view
  70. view_dispatcher_remove_view(app->view_dispatcher, FuzzerViewIDMain);
  71. fuzzer_view_main_free(app->main_view);
  72. // Attack view
  73. view_dispatcher_remove_view(app->view_dispatcher, FuzzerViewIDAttack);
  74. fuzzer_view_attack_free(app->attack_view);
  75. // FieldEditor view
  76. view_dispatcher_remove_view(app->view_dispatcher, FuzzerViewIDFieldEditor);
  77. fuzzer_view_field_editor_free(app->field_editor_view);
  78. // Popup
  79. view_dispatcher_remove_view(app->view_dispatcher, FuzzerViewIDPopup);
  80. popup_free(app->popup);
  81. // TextInput
  82. view_dispatcher_remove_view(app->view_dispatcher, FuzzerViewIDTextInput);
  83. text_input_free(app->text_input);
  84. scene_manager_free(app->scene_manager);
  85. view_dispatcher_free(app->view_dispatcher);
  86. // Dialog
  87. furi_record_close(RECORD_DIALOGS);
  88. // Close records
  89. furi_record_close(RECORD_GUI);
  90. // Notifications
  91. furi_record_close(RECORD_NOTIFICATION);
  92. app->notifications = NULL;
  93. furi_string_free(app->file_path);
  94. fuzzer_payload_free(app->payload);
  95. fuzzer_worker_free(app->worker);
  96. free(app);
  97. }
  98. int32_t fuzzer_start_ibtn(void* p) {
  99. UNUSED(p);
  100. PacsFuzzerApp* fuzzer_app = fuzzer_app_alloc();
  101. FuzzerConsts app_const = {
  102. .custom_dict_folder = "/ext/ibutton_fuzzer",
  103. .custom_dict_extension = ".txt",
  104. .key_extension = ".ibtn",
  105. .path_key_folder = "/ext/ibutton",
  106. .key_icon = &I_ibutt_10px,
  107. .file_prefix = "iBtn",
  108. };
  109. fuzzer_app->fuzzer_const = &app_const;
  110. view_dispatcher_run(fuzzer_app->view_dispatcher);
  111. fuzzer_app_free(fuzzer_app);
  112. return 0;
  113. }
  114. int32_t fuzzer_start_rfid(void* p) {
  115. UNUSED(p);
  116. PacsFuzzerApp* fuzzer_app = fuzzer_app_alloc();
  117. FuzzerConsts app_const = {
  118. .custom_dict_folder = "/ext/lfrfid_fuzzer",
  119. .custom_dict_extension = ".txt",
  120. .key_extension = ".rfid",
  121. .path_key_folder = "/ext/lfrfid",
  122. .key_icon = &I_125_10px,
  123. .file_prefix = "RFID",
  124. };
  125. fuzzer_app->fuzzer_const = &app_const;
  126. view_dispatcher_run(fuzzer_app->view_dispatcher);
  127. fuzzer_app_free(fuzzer_app);
  128. return 0;
  129. }