Skip to content

Commit

Permalink
BLE Spam add basic config page (parameters later)
Browse files Browse the repository at this point in the history
  • Loading branch information
Willy-JL committed Oct 19, 2023
1 parent b090d28 commit cb2c00a
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 8 deletions.
26 changes: 18 additions & 8 deletions applications/external/ble_spam/ble_spam.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@
// Research on behaviors and parameters by @Willy-JL, @ECTO-1A and @Spooks4576
// Controversy explained at https://willyjl.dev/blog/the-controversy-behind-apple-ble-spam

typedef struct {
const char* title;
const char* text;
const Protocol* protocol;
Payload payload;
} Attack;

static Attack attacks[] = {
{
.title = "+ Kitchen Sink",
Expand Down Expand Up @@ -323,7 +316,15 @@ static bool input_callback(InputEvent* input, void* ctx) {

switch(input->key) {
case InputKeyOk:
if(is_attack) toggle_adv(state);
if(is_attack) {
if(input->type == InputTypeLong) {
if(advertising) toggle_adv(state);
state->ctx.attack = &attacks[state->index];
scene_manager_next_scene(state->ctx.scene_manager, SceneConfig);
} else if(input->type == InputTypeShort) {
toggle_adv(state);
}
}
break;
case InputKeyUp:
if(is_attack && state->delay < COUNT_OF(delays) - 1) {
Expand Down Expand Up @@ -389,10 +390,19 @@ int32_t ble_spam(void* p) {
view_set_input_callback(view_main, input_callback);
view_dispatcher_add_view(state->ctx.view_dispatcher, ViewMain, view_main);

state->ctx.variable_item_list = variable_item_list_alloc();
view_dispatcher_add_view(
state->ctx.view_dispatcher,
ViewVariableItemList,
variable_item_list_get_view(state->ctx.variable_item_list));

view_dispatcher_attach_to_gui(state->ctx.view_dispatcher, gui, ViewDispatcherTypeFullscreen);
scene_manager_next_scene(state->ctx.scene_manager, SceneMain);
view_dispatcher_run(state->ctx.view_dispatcher);

view_dispatcher_remove_view(state->ctx.view_dispatcher, ViewVariableItemList);
variable_item_list_free(state->ctx.variable_item_list);

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

Expand Down
8 changes: 8 additions & 0 deletions applications/external/ble_spam/ble_spam.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
#pragma once

#include <gui/view_dispatcher.h>
#include <gui/modules/variable_item_list.h>

#include "scenes/_setup.h"

enum {
ViewMain,
ViewVariableItemList,
};

typedef struct Attack Attack;

typedef struct {
Attack* attack;

ViewDispatcher* view_dispatcher;
SceneManager* scene_manager;

VariableItemList* variable_item_list;
} Ctx;
7 changes: 7 additions & 0 deletions applications/external/ble_spam/protocols/_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@ typedef struct {
bool random_mac;
ProtocolCfg cfg;
} Payload;

struct Attack {
const char* title;
const char* text;
const Protocol* protocol;
Payload payload;
};
3 changes: 3 additions & 0 deletions applications/external/ble_spam/protocols/_scenes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "continuity_scenes.h"
#include "fastpair_scenes.h"
#include "swiftpair_scenes.h"
Empty file.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions applications/external/ble_spam/scenes/_scenes.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ADD_SCENE(main, Main)
ADD_SCENE(config, Config)
#include "../protocols/_scenes.h"
34 changes: 34 additions & 0 deletions applications/external/ble_spam/scenes/config.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "../ble_spam.h"

#include "protocols/_registry.h"

static void random_mac_changed(VariableItem* item) {
Ctx* ctx = variable_item_get_context(item);
ctx->attack->payload.random_mac = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, ctx->attack->payload.random_mac ? "ON" : "OFF");
}

void scene_config_on_enter(void* _ctx) {
Ctx* ctx = _ctx;
VariableItem* item;
VariableItemList* list = ctx->variable_item_list;
variable_item_list_reset(list);

variable_item_list_set_header(list, ctx->attack->title);

item = variable_item_list_add(list, "Random MAC", 2, random_mac_changed, ctx);
variable_item_set_current_value_index(item, ctx->attack->payload.random_mac);
variable_item_set_current_value_text(item, ctx->attack->payload.random_mac ? "ON" : "OFF");

view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewVariableItemList);
}

bool scene_config_on_event(void* _ctx, SceneManagerEvent event) {
UNUSED(_ctx);
UNUSED(event);
return false;
}

void scene_config_on_exit(void* _ctx) {
UNUSED(_ctx);
}

0 comments on commit cb2c00a

Please sign in to comment.