subbrute_scene_setup_attack.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #include "../subbrute_i.h"
  2. #include "../subbrute_custom_event.h"
  3. #include "../views/subbrute_attack_view.h"
  4. #define TAG "SubBruteSceneSetupAttack"
  5. static void subbrute_scene_setup_attack_callback(SubBruteCustomEvent event, void* context) {
  6. furi_assert(context);
  7. SubBruteState* instance = (SubBruteState*)context;
  8. view_dispatcher_send_custom_event(instance->view_dispatcher, event);
  9. }
  10. void subbrute_scene_setup_attack_on_enter(void* context) {
  11. furi_assert(context);
  12. SubBruteState* instance = (SubBruteState*)context;
  13. SubBruteAttackView* view = instance->view_attack;
  14. #ifdef FURI_DEBUG
  15. FURI_LOG_D(TAG, "Enter Attack: %d", instance->device->attack);
  16. #endif
  17. subbrute_attack_view_init_values(
  18. view,
  19. instance->device->attack,
  20. instance->device->max_value,
  21. instance->device->key_index,
  22. false);
  23. subbrute_worker_init_manual_transmit(
  24. instance->worker,
  25. instance->device->frequency,
  26. instance->device->preset,
  27. string_get_cstr(instance->device->protocol_name));
  28. instance->current_view = SubBruteViewAttack;
  29. subbrute_attack_view_set_callback(view, subbrute_scene_setup_attack_callback, instance);
  30. view_dispatcher_switch_to_view(instance->view_dispatcher, instance->current_view);
  31. }
  32. void subbrute_scene_setup_attack_on_exit(void* context) {
  33. furi_assert(context);
  34. #ifdef FURI_DEBUG
  35. FURI_LOG_D(TAG, "subbrute_scene_setup_attack_on_exit");
  36. #endif
  37. SubBruteState* instance = (SubBruteState*)context;
  38. subbrute_worker_manual_transmit_stop(instance->worker);
  39. notification_message(instance->notifications, &sequence_blink_stop);
  40. }
  41. bool subbrute_scene_setup_attack_on_event(void* context, SceneManagerEvent event) {
  42. SubBruteState* instance = (SubBruteState*)context;
  43. SubBruteAttackView* view = instance->view_attack;
  44. bool consumed = false;
  45. if(event.type == SceneManagerEventTypeCustom) {
  46. if(event.event == SubBruteCustomEventTypeTransmitStarted) {
  47. subbrute_device_create_packet_parsed(instance->device, instance->device->key_index);
  48. scene_manager_next_scene(instance->scene_manager, SubBruteSceneRunAttack);
  49. } else if(event.event == SubBruteCustomEventTypeSaveFile) {
  50. subbrute_worker_manual_transmit_stop(instance->worker);
  51. subbrute_attack_view_init_values(
  52. view,
  53. instance->device->attack,
  54. instance->device->max_value,
  55. instance->device->key_index,
  56. false);
  57. scene_manager_next_scene(instance->scene_manager, SubBruteSceneSaveName);
  58. } else if(event.event == SubBruteCustomEventTypeBackPressed) {
  59. #ifdef FURI_DEBUG
  60. FURI_LOG_D(TAG, "SubBruteCustomEventTypeBackPressed");
  61. #endif
  62. instance->device->key_index = 0x00;
  63. //subbrute_attack_view_stop_worker(view);
  64. subbrute_attack_view_init_values(
  65. view,
  66. instance->device->attack,
  67. instance->device->max_value,
  68. instance->device->key_index,
  69. false);
  70. scene_manager_next_scene(instance->scene_manager, SubBruteSceneStart);
  71. } else if(event.event == SubBruteCustomEventTypeChangeStepUp) {
  72. // +1
  73. if((instance->device->key_index + 1) - instance->device->max_value == 1) {
  74. instance->device->key_index = 0x00;
  75. } else {
  76. uint64_t value = instance->device->key_index + 1;
  77. if(value == instance->device->max_value) {
  78. instance->device->key_index = value;
  79. } else {
  80. instance->device->key_index = value % instance->device->max_value;
  81. }
  82. }
  83. subbrute_attack_view_set_current_step(view, instance->device->key_index);
  84. } else if(event.event == SubBruteCustomEventTypeChangeStepUpMore) {
  85. // +50
  86. uint64_t value = instance->device->key_index + 50;
  87. if(value == instance->device->max_value) {
  88. instance->device->key_index += value;
  89. } else {
  90. instance->device->key_index = value % instance->device->max_value;
  91. }
  92. subbrute_attack_view_set_current_step(view, instance->device->key_index);
  93. } else if(event.event == SubBruteCustomEventTypeChangeStepDown) {
  94. // -1
  95. if(instance->device->key_index - 1 == 0) {
  96. instance->device->key_index = 0x00;
  97. } else if(instance->device->key_index == 0) {
  98. instance->device->key_index = instance->device->max_value;
  99. } else {
  100. uint64_t value = ((instance->device->key_index - 1) + instance->device->max_value);
  101. if(value == instance->device->max_value) {
  102. instance->device->key_index = value;
  103. } else {
  104. instance->device->key_index = value % instance->device->max_value;
  105. }
  106. }
  107. subbrute_attack_view_set_current_step(view, instance->device->key_index);
  108. } else if(event.event == SubBruteCustomEventTypeChangeStepDownMore) {
  109. // -50
  110. uint64_t value = ((instance->device->key_index - 50) + instance->device->max_value);
  111. if(value == instance->device->max_value) {
  112. instance->device->key_index = value;
  113. } else {
  114. instance->device->key_index = value % instance->device->max_value;
  115. }
  116. subbrute_attack_view_set_current_step(view, instance->device->key_index);
  117. } else if(event.event == SubBruteCustomEventTypeTransmitCustom) {
  118. if(subbrute_worker_can_transmit(instance->worker)) {
  119. // Blink
  120. notification_message(instance->notifications, &sequence_blink_magenta_10);
  121. // if(!subbrute_attack_view_is_worker_running(view)) {
  122. // subbrute_attack_view_start_worker(
  123. // view,
  124. // instance->device->frequency,
  125. // instance->device->preset,
  126. // string_get_cstr(instance->device->protocol_name));
  127. // }
  128. subbrute_device_create_packet_parsed(
  129. instance->device, instance->device->key_index);
  130. subbrute_worker_manual_transmit(instance->worker, instance->device->payload);
  131. // Stop
  132. notification_message(instance->notifications, &sequence_blink_stop);
  133. }
  134. }
  135. consumed = true;
  136. }
  137. // if(event.type == SceneManagerEventTypeCustom) {
  138. // switch(event.event) {
  139. // case SubBruteCustomEventTypeMenuSelected:
  140. // with_view_model(
  141. // view, (SubBruteMainViewModel * model) {
  142. // instance->menu_index = model->index;
  143. // return false;
  144. // });
  145. // scene_manager_next_scene(instance->scene_manager, SubBruteSceneLoadFile);
  146. // consumed = true;
  147. // break;
  148. // case SubBruteCustomEventTypeLoadFile:
  149. // with_view_model(
  150. // view, (SubBruteMainViewModel * model) {
  151. // instance->menu_index = model->index;
  152. // return false;
  153. // });
  154. // scene_manager_next_scene(instance->scene_manager, SubBruteSceneSetupAttack);
  155. // consumed = true;
  156. // break;
  157. // }
  158. // }
  159. return consumed;
  160. }