mifare_nested_scene_added_keys.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "../mifare_nested_i.h"
  2. void mifare_nested_scene_added_keys_widget_callback(
  3. GuiButtonType result,
  4. InputType type,
  5. void* context) {
  6. MifareNested* mifare_nested = context;
  7. if(type == InputTypeShort) {
  8. view_dispatcher_send_custom_event(mifare_nested->view_dispatcher, result);
  9. }
  10. }
  11. void mifare_nested_scene_added_keys_on_enter(void* context) {
  12. MifareNested* mifare_nested = context;
  13. KeyInfo_t* key_info = mifare_nested->keys;
  14. Widget* widget = mifare_nested->widget;
  15. char draw_str[32] = {};
  16. char append[5] = {'k', 'e', 'y', ' ', '\0'};
  17. if(key_info->added_keys != 1) {
  18. append[3] = 's';
  19. }
  20. widget_add_string_element(
  21. widget, 0, 0, AlignLeft, AlignTop, FontPrimary, "Results of key recovery");
  22. if(key_info->added_keys != 0) {
  23. snprintf(draw_str, sizeof(draw_str), "Added: %lu %s", key_info->added_keys, append);
  24. notification_message(mifare_nested->notifications, &sequence_success);
  25. widget_add_icon_element(widget, 52, 17, &I_DolphinSuccess);
  26. } else {
  27. snprintf(draw_str, sizeof(draw_str), "No new keys were added");
  28. widget_add_string_element(
  29. widget, 0, 22, AlignLeft, AlignTop, FontSecondary, "Try running \"Nested attack\"");
  30. widget_add_string_element(widget, 0, 32, AlignLeft, AlignTop, FontSecondary, "again");
  31. notification_message(mifare_nested->notifications, &sequence_error);
  32. }
  33. widget_add_string_element(widget, 0, 12, AlignLeft, AlignTop, FontSecondary, draw_str);
  34. widget_add_button_element(
  35. widget,
  36. GuiButtonTypeLeft,
  37. "Back",
  38. mifare_nested_scene_added_keys_widget_callback,
  39. mifare_nested);
  40. free(key_info);
  41. KeyInfo_t* new_key_info = malloc(sizeof(KeyInfo_t));
  42. mifare_nested->keys = new_key_info;
  43. // Setup and start worker
  44. view_dispatcher_switch_to_view(mifare_nested->view_dispatcher, MifareNestedViewWidget);
  45. }
  46. bool mifare_nested_scene_added_keys_on_event(void* context, SceneManagerEvent event) {
  47. MifareNested* mifare_nested = context;
  48. bool consumed = false;
  49. if(event.type == SceneManagerEventTypeCustom) {
  50. if(event.event == GuiButtonTypeCenter || event.event == GuiButtonTypeLeft) {
  51. scene_manager_search_and_switch_to_previous_scene(mifare_nested->scene_manager, 0);
  52. consumed = true;
  53. }
  54. } else if(event.type == SceneManagerEventTypeBack) {
  55. scene_manager_search_and_switch_to_previous_scene(mifare_nested->scene_manager, 0);
  56. consumed = true;
  57. }
  58. return consumed;
  59. }
  60. void mifare_nested_scene_added_keys_on_exit(void* context) {
  61. MifareNested* mifare_nested = context;
  62. widget_reset(mifare_nested->widget);
  63. }