fuzzer.c 5.0 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_set_event_callback_context(app->view_dispatcher, app);
  56. view_dispatcher_set_custom_event_callback(
  57. app->view_dispatcher, fuzzer_app_custom_event_callback);
  58. view_dispatcher_set_navigation_event_callback(
  59. app->view_dispatcher, fuzzer_app_back_event_callback);
  60. view_dispatcher_set_tick_event_callback(
  61. app->view_dispatcher, fuzzer_app_tick_event_callback, 100);
  62. view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
  63. scene_manager_next_scene(app->scene_manager, FuzzerSceneMain);
  64. return app;
  65. }
  66. void fuzzer_app_free(PacsFuzzerApp* app) {
  67. furi_assert(app);
  68. // Remote view
  69. view_dispatcher_remove_view(app->view_dispatcher, FuzzerViewIDMain);
  70. fuzzer_view_main_free(app->main_view);
  71. // Attack view
  72. view_dispatcher_remove_view(app->view_dispatcher, FuzzerViewIDAttack);
  73. fuzzer_view_attack_free(app->attack_view);
  74. // FieldEditor view
  75. view_dispatcher_remove_view(app->view_dispatcher, FuzzerViewIDFieldEditor);
  76. fuzzer_view_field_editor_free(app->field_editor_view);
  77. // Popup
  78. view_dispatcher_remove_view(app->view_dispatcher, FuzzerViewIDPopup);
  79. popup_free(app->popup);
  80. // TextInput
  81. view_dispatcher_remove_view(app->view_dispatcher, FuzzerViewIDTextInput);
  82. text_input_free(app->text_input);
  83. scene_manager_free(app->scene_manager);
  84. view_dispatcher_free(app->view_dispatcher);
  85. // Dialog
  86. furi_record_close(RECORD_DIALOGS);
  87. // Close records
  88. furi_record_close(RECORD_GUI);
  89. // Notifications
  90. furi_record_close(RECORD_NOTIFICATION);
  91. app->notifications = NULL;
  92. furi_string_free(app->file_path);
  93. fuzzer_payload_free(app->payload);
  94. fuzzer_worker_free(app->worker);
  95. free(app);
  96. }
  97. int32_t fuzzer_start_ibtn(void* p) {
  98. UNUSED(p);
  99. PacsFuzzerApp* fuzzer_app = fuzzer_app_alloc();
  100. FuzzerConsts app_const = {
  101. .custom_dict_folder = "/ext/ibutton_fuzzer",
  102. .custom_dict_extension = ".txt",
  103. .key_extension = ".ibtn",
  104. .path_key_folder = "/ext/ibutton",
  105. .key_icon = &I_ibutt_10px,
  106. .file_prefix = "iBtn",
  107. };
  108. fuzzer_app->fuzzer_const = &app_const;
  109. view_dispatcher_run(fuzzer_app->view_dispatcher);
  110. fuzzer_app_free(fuzzer_app);
  111. return 0;
  112. }
  113. int32_t fuzzer_start_rfid(void* p) {
  114. UNUSED(p);
  115. PacsFuzzerApp* fuzzer_app = fuzzer_app_alloc();
  116. FuzzerConsts app_const = {
  117. .custom_dict_folder = "/ext/lfrfid_fuzzer",
  118. .custom_dict_extension = ".txt",
  119. .key_extension = ".rfid",
  120. .path_key_folder = "/ext/lfrfid",
  121. .key_icon = &I_125_10px,
  122. .file_prefix = "RFID",
  123. };
  124. fuzzer_app->fuzzer_const = &app_const;
  125. view_dispatcher_run(fuzzer_app->view_dispatcher);
  126. fuzzer_app_free(fuzzer_app);
  127. return 0;
  128. }