Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
…into dev
  • Loading branch information
Leeroy committed Oct 23, 2023
2 parents 1562e03 + eee662f commit 59e746d
Show file tree
Hide file tree
Showing 15 changed files with 275 additions and 39 deletions.
2 changes: 1 addition & 1 deletion applications/external/ble_spam/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ App(
fap_category="Bluetooth",
fap_author="@Willy-JL @ECTO-1A @Spooks4576",
fap_weburl="https://github.com/Flipper-XFW/Xtreme-Apps/tree/dev/ble_spam",
fap_version="3.1",
fap_version="3.3",
fap_description="Flood BLE advertisements to cause spammy and annoying popups/notifications",
fap_icon_assets="icons",
fap_icon_assets_symbol="ble_spam",
Expand Down
100 changes: 88 additions & 12 deletions applications/external/ble_spam/ble_spam.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,39 @@ static uint16_t delays[] = {20, 50, 100, 200};

typedef struct {
Ctx ctx;
View* main_view;
bool lock_warning;
uint8_t lock_count;
FuriTimer* lock_timer;

bool resume;
bool advertising;
uint8_t delay;
FuriThread* thread;
int8_t index;
} State;

NotificationMessage blink_message = {
.type = NotificationMessageTypeLedBlinkStart,
.data.led_blink.color = LightBlue | LightGreen,
.data.led_blink.on_time = 10,
.data.led_blink.period = 100,
};
const NotificationSequence blink_sequence = {
&blink_message,
&message_do_not_reset,
NULL,
};
static void start_blink(State* state) {
uint16_t period = delays[state->delay];
if(period <= 100) period += 30;
blink_message.data.led_blink.period = period;
notification_message_block(state->ctx.notification, &blink_sequence);
}
static void stop_blink(State* state) {
notification_message_block(state->ctx.notification, &sequence_blink_stop);
}

static int32_t adv_thread(void* _ctx) {
State* state = _ctx;
uint8_t size;
Expand All @@ -158,6 +184,7 @@ static int32_t adv_thread(void* _ctx) {
Payload* payload = &attacks[state->index].payload;
const Protocol* protocol = attacks[state->index].protocol;
if(!payload->random_mac) furi_hal_random_fill_buf(mac, sizeof(mac));
if(state->ctx.led_indicator) start_blink(state);

while(state->advertising) {
if(protocol) {
Expand All @@ -175,6 +202,7 @@ static int32_t adv_thread(void* _ctx) {
furi_hal_bt_custom_adv_stop();
}

if(state->ctx.led_indicator) stop_blink(state);
return 0;
}

Expand All @@ -185,9 +213,9 @@ static void toggle_adv(State* state) {
furi_thread_join(state->thread);
if(state->resume) furi_hal_bt_start_advertising();
} else {
state->advertising = true;
state->resume = furi_hal_bt_is_active();
furi_hal_bt_stop_advertising();
state->advertising = true;
furi_thread_start(state->thread);
}
}
Expand Down Expand Up @@ -315,11 +343,15 @@ static void draw_callback(Canvas* canvas, void* _ctx) {
"App+Spam: \e#WillyJL\e# XFW\n"
"Apple+Crash: \e#ECTO-1A\e#\n"
"Android+Win: \e#Spooks4576\e#\n"
" Version \e#3.1\e#",
" Version \e#3.3\e#",
false);
break;
default: {
if(!attack) break;
if(state->ctx.lock_keyboard && !state->advertising) {
// Forgive me Lord for I have sinned by handling state in draw
toggle_adv(state);
}
char str[32];

canvas_set_font(canvas, FontBatteryPercent);
Expand Down Expand Up @@ -355,15 +387,40 @@ static void draw_callback(Canvas* canvas, void* _ctx) {
if(state->index < PAGE_MAX) {
elements_button_right(canvas, next);
}

if(state->lock_warning) {
canvas_set_font(canvas, FontSecondary);
elements_bold_rounded_frame(canvas, 14, 8, 99, 48);
elements_multiline_text(canvas, 65, 26, "To unlock\npress:");
canvas_draw_icon(canvas, 65, 42, &I_Pin_back_arrow_10x8);
canvas_draw_icon(canvas, 80, 42, &I_Pin_back_arrow_10x8);
canvas_draw_icon(canvas, 95, 42, &I_Pin_back_arrow_10x8);
canvas_draw_icon(canvas, 16, 13, &I_WarningDolphin_45x42);
canvas_draw_dot(canvas, 17, 61);
}
}

static bool input_callback(InputEvent* input, void* _ctx) {
View* view = _ctx;
State* state = *(State**)view_get_model(view);
bool consumed = false;

if(input->type == InputTypeShort || input->type == InputTypeLong ||
input->type == InputTypeRepeat) {
if(state->ctx.lock_keyboard) {
consumed = true;
with_view_model(
state->main_view, State * *model, { (*model)->lock_warning = true; }, true);
if(state->lock_count == 0) {
furi_timer_start(state->lock_timer, pdMS_TO_TICKS(1000));
}
if(input->type == InputTypeShort && input->key == InputKeyBack) {
state->lock_count++;
}
if(state->lock_count >= 3) {
furi_timer_start(state->lock_timer, 1);
}
} else if(
input->type == InputTypeShort || input->type == InputTypeLong ||
input->type == InputTypeRepeat) {
consumed = true;

bool is_attack = state->index >= 0 && state->index <= ATTACKS_COUNT - 1;
Expand All @@ -385,11 +442,13 @@ static bool input_callback(InputEvent* input, void* _ctx) {
case InputKeyUp:
if(is_attack && state->delay < COUNT_OF(delays) - 1) {
state->delay++;
if(advertising) start_blink(state);
}
break;
case InputKeyDown:
if(is_attack && state->delay > 0) {
state->delay--;
if(advertising) start_blink(state);
}
break;
case InputKeyLeft:
Expand Down Expand Up @@ -417,6 +476,18 @@ static bool input_callback(InputEvent* input, void* _ctx) {
return consumed;
}

static void lock_timer_callback(void* _ctx) {
State* state = _ctx;
if(state->lock_count < 3) {
notification_message_block(state->ctx.notification, &sequence_display_backlight_off);
} else {
state->ctx.lock_keyboard = false;
}
with_view_model(
state->main_view, State * *model, { (*model)->lock_warning = false; }, true);
state->lock_count = 0;
}

static bool back_event_callback(void* _ctx) {
Ctx* ctx = _ctx;
return scene_manager_handle_back_event(ctx->scene_manager);
Expand All @@ -429,22 +500,25 @@ int32_t ble_spam(void* p) {
furi_thread_set_callback(state->thread, adv_thread);
furi_thread_set_context(state->thread, state);
furi_thread_set_stack_size(state->thread, 4096);
state->ctx.led_indicator = true;
state->lock_timer = furi_timer_alloc(lock_timer_callback, FuriTimerTypeOnce, state);

state->ctx.notification = furi_record_open(RECORD_NOTIFICATION);
Gui* gui = furi_record_open(RECORD_GUI);
state->ctx.view_dispatcher = view_dispatcher_alloc();
view_dispatcher_enable_queue(state->ctx.view_dispatcher);
view_dispatcher_set_event_callback_context(state->ctx.view_dispatcher, &state->ctx);
view_dispatcher_set_navigation_event_callback(state->ctx.view_dispatcher, back_event_callback);
state->ctx.scene_manager = scene_manager_alloc(&scene_handlers, &state->ctx);

View* view_main = view_alloc();
view_allocate_model(view_main, ViewModelTypeLockFree, sizeof(State*));
state->main_view = view_alloc();
view_allocate_model(state->main_view, ViewModelTypeLocking, sizeof(State*));
with_view_model(
view_main, State * *model, { *model = state; }, false);
view_set_context(view_main, view_main);
view_set_draw_callback(view_main, draw_callback);
view_set_input_callback(view_main, input_callback);
view_dispatcher_add_view(state->ctx.view_dispatcher, ViewMain, view_main);
state->main_view, State * *model, { *model = state; }, false);
view_set_context(state->main_view, state->main_view);
view_set_draw_callback(state->main_view, draw_callback);
view_set_input_callback(state->main_view, input_callback);
view_dispatcher_add_view(state->ctx.view_dispatcher, ViewMain, state->main_view);

state->ctx.byte_input = byte_input_alloc();
view_dispatcher_add_view(
Expand Down Expand Up @@ -481,12 +555,14 @@ int32_t ble_spam(void* p) {
variable_item_list_free(state->ctx.variable_item_list);

view_dispatcher_remove_view(state->ctx.view_dispatcher, ViewMain);
view_free(view_main);
view_free(state->main_view);

scene_manager_free(state->ctx.scene_manager);
view_dispatcher_free(state->ctx.view_dispatcher);
furi_record_close(RECORD_GUI);
furi_record_close(RECORD_NOTIFICATION);

furi_timer_free(state->lock_timer);
furi_thread_free(state->thread);
free(state);
return 0;
Expand Down
7 changes: 7 additions & 0 deletions applications/external/ble_spam/ble_spam.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <notification/notification_messages.h>
#include <gui/view_dispatcher.h>
#include <gui/modules/byte_input.h>
#include <gui/modules/submenu.h>
Expand All @@ -19,14 +20,20 @@ enum {
enum {
ConfigRandomMac,
ConfigExtraStart = ConfigRandomMac,
ConfigLedIndicator,
ConfigLockKeyboard,
};

typedef struct Attack Attack;

typedef struct {
Attack* attack;
uint8_t byte_store[3];
VariableItemListEnterCallback fallback_config_enter;
bool led_indicator;
bool lock_keyboard;

NotificationApp* notification;
ViewDispatcher* view_dispatcher;
SceneManager* scene_manager;

Expand Down
1 change: 1 addition & 0 deletions applications/external/ble_spam/protocols/_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ typedef struct {
const char* (*get_name)(const ProtocolCfg* _cfg);
void (*make_packet)(uint8_t* _size, uint8_t** _packet, const ProtocolCfg* _cfg);
void (*extra_config)(Ctx* ctx);
uint8_t (*config_count)(const ProtocolCfg* _cfg);
} Protocol;
38 changes: 38 additions & 0 deletions applications/external/ble_spam/protocols/continuity.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,19 @@ enum {
_ConfigPpExtraStart = ConfigExtraStart,
ConfigPpModel,
ConfigPpPrefix,
ConfigPpCOUNT,
};
enum {
_ConfigNaExtraStart = ConfigExtraStart,
ConfigNaAction,
ConfigNaFlags,
ConfigNaCOUNT,
};
enum {
_ConfigCcExtraStart = ConfigExtraStart,
ConfigCcInfoLock,
ConfigCcInfoDevice,
ConfigCcCOUNT,
};
static void config_callback(void* _ctx, uint32_t index) {
Ctx* ctx = _ctx;
Expand All @@ -297,6 +305,7 @@ static void config_callback(void* _ctx, uint32_t index) {
scene_manager_next_scene(ctx->scene_manager, SceneContinuityPpPrefix);
break;
default:
ctx->fallback_config_enter(ctx, index);
break;
}
break;
Expand All @@ -310,11 +319,24 @@ static void config_callback(void* _ctx, uint32_t index) {
scene_manager_next_scene(ctx->scene_manager, SceneContinuityNaFlags);
break;
default:
ctx->fallback_config_enter(ctx, index);
break;
}
break;
}
case ContinuityTypeCustomCrash: {
switch(index) {
case ConfigCcInfoLock:
case ConfigCcInfoDevice:
break;
default:
ctx->fallback_config_enter(ctx, index);
break;
}
break;
}
default:
ctx->fallback_config_enter(ctx, index);
break;
}
}
Expand Down Expand Up @@ -470,11 +492,27 @@ static void continuity_extra_config(Ctx* ctx) {
variable_item_list_set_enter_callback(list, config_callback, ctx);
}

static uint8_t config_counts[ContinuityTypeCOUNT] = {
[ContinuityTypeAirDrop] = 0,
[ContinuityTypeProximityPair] = ConfigPpCOUNT - ConfigExtraStart - 1,
[ContinuityTypeAirplayTarget] = 0,
[ContinuityTypeHandoff] = 0,
[ContinuityTypeTetheringSource] = 0,
[ContinuityTypeNearbyAction] = ConfigNaCOUNT - ConfigExtraStart - 1,
[ContinuityTypeNearbyInfo] = 0,
[ContinuityTypeCustomCrash] = ConfigCcCOUNT - ConfigExtraStart - 1,
};
static uint8_t continuity_config_count(const ProtocolCfg* _cfg) {
const ContinuityCfg* cfg = &_cfg->continuity;
return config_counts[cfg->type];
}

const Protocol protocol_continuity = {
.icon = &I_apple,
.get_name = continuity_get_name,
.make_packet = continuity_make_packet,
.extra_config = continuity_extra_config,
.config_count = continuity_config_count,
};

static void pp_model_callback(void* _ctx, uint32_t index) {
Expand Down
18 changes: 18 additions & 0 deletions applications/external/ble_spam/protocols/easysetup.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,13 @@ void easysetup_make_packet(uint8_t* out_size, uint8_t** out_packet, const Protoc
enum {
_ConfigBudsExtraStart = ConfigExtraStart,
ConfigBudsModel,
ConfigBudsInfoVersion,
ConfigBudsCOUNT,
};
enum {
_ConfigWatchExtraStart = ConfigExtraStart,
ConfigWatchModel,
ConfigWatchCOUNT,
};
static void config_callback(void* _ctx, uint32_t index) {
Ctx* ctx = _ctx;
Expand All @@ -186,7 +189,10 @@ static void config_callback(void* _ctx, uint32_t index) {
case ConfigBudsModel:
scene_manager_next_scene(ctx->scene_manager, SceneEasysetupBudsModel);
break;
case ConfigBudsInfoVersion:
break;
default:
ctx->fallback_config_enter(ctx, index);
break;
}
break;
Expand All @@ -197,11 +203,13 @@ static void config_callback(void* _ctx, uint32_t index) {
scene_manager_next_scene(ctx->scene_manager, SceneEasysetupWatchModel);
break;
default:
ctx->fallback_config_enter(ctx, index);
break;
}
break;
}
default:
ctx->fallback_config_enter(ctx, index);
break;
}
}
Expand Down Expand Up @@ -297,11 +305,21 @@ static void easysetup_extra_config(Ctx* ctx) {
variable_item_list_set_enter_callback(list, config_callback, ctx);
}

static uint8_t config_counts[EasysetupTypeCOUNT] = {
[EasysetupTypeBuds] = ConfigBudsCOUNT - ConfigExtraStart - 1,
[EasysetupTypeWatch] = ConfigWatchCOUNT - ConfigExtraStart - 1,
};
static uint8_t easysetup_config_count(const ProtocolCfg* _cfg) {
const EasysetupCfg* cfg = &_cfg->easysetup;
return config_counts[cfg->type];
}

const Protocol protocol_easysetup = {
.icon = &I_android,
.get_name = easysetup_get_name,
.make_packet = easysetup_make_packet,
.extra_config = easysetup_extra_config,
.config_count = easysetup_config_count,
};

static void buds_model_callback(void* _ctx, uint32_t index) {
Expand Down
Loading

0 comments on commit 59e746d

Please sign in to comment.