|
| 1 | +#include "nameflood.h" |
| 2 | +#include "_protocols.h" |
| 3 | + |
| 4 | +// Hacked together by @Willy-JL |
| 5 | + |
| 6 | +static const char* names[] = { |
| 7 | + "Assquach💦", |
| 8 | + "Flipper 🐬", |
| 9 | + "iOS 17 🍎", |
| 10 | + "Kink💦", |
| 11 | + "👉👌", |
| 12 | + "🔵🦷", |
| 13 | +}; |
| 14 | +static const uint8_t names_count = COUNT_OF(names); |
| 15 | + |
| 16 | +static const char* get_name(const Payload* payload) { |
| 17 | + UNUSED(payload); |
| 18 | + return "NameFlood"; |
| 19 | +} |
| 20 | + |
| 21 | +static void make_packet(uint8_t* _size, uint8_t** _packet, Payload* payload) { |
| 22 | + NamefloodCfg* cfg = payload ? &payload->cfg.nameflood : NULL; |
| 23 | + |
| 24 | + const char* name; |
| 25 | + switch(cfg ? payload->mode : PayloadModeRandom) { |
| 26 | + case PayloadModeRandom: |
| 27 | + default: |
| 28 | + name = names[rand() % names_count]; |
| 29 | + break; |
| 30 | + case PayloadModeValue: |
| 31 | + name = cfg->name; |
| 32 | + break; |
| 33 | + } |
| 34 | + uint8_t name_len = strlen(name); |
| 35 | + |
| 36 | + uint8_t size = 12 + name_len; |
| 37 | + uint8_t* packet = malloc(size); |
| 38 | + uint8_t i = 0; |
| 39 | + |
| 40 | + packet[i++] = 2; // Size |
| 41 | + packet[i++] = 0x01; // AD Type (Flags) |
| 42 | + packet[i++] = 0x06; // Flags |
| 43 | + |
| 44 | + packet[i++] = name_len + 1; // Size |
| 45 | + packet[i++] = 0x09; // AD Type (Complete Local Name) |
| 46 | + memcpy(&packet[i], name, name_len); // Device Name |
| 47 | + i += name_len; |
| 48 | + |
| 49 | + packet[i++] = 3; // Size |
| 50 | + packet[i++] = 0x02; // AD Type (Incomplete Service UUID List) |
| 51 | + packet[i++] = 0x12; // Service UUID (Human Interface Device) |
| 52 | + packet[i++] = 0x18; // ... |
| 53 | + |
| 54 | + packet[i++] = 2; // Size |
| 55 | + packet[i++] = 0x0A; // AD Type (Tx Power Level) |
| 56 | + packet[i++] = 0x00; // 0dBm |
| 57 | + |
| 58 | + *_size = size; |
| 59 | + *_packet = packet; |
| 60 | +} |
| 61 | + |
| 62 | +enum { |
| 63 | + _ConfigExtraStart = ConfigExtraStart, |
| 64 | + ConfigName, |
| 65 | + ConfigInfoSettings, |
| 66 | + ConfigCOUNT, |
| 67 | +}; |
| 68 | +static void config_callback(void* _ctx, uint32_t index) { |
| 69 | + Ctx* ctx = _ctx; |
| 70 | + scene_manager_set_scene_state(ctx->scene_manager, SceneConfig, index); |
| 71 | + switch(index) { |
| 72 | + case ConfigName: |
| 73 | + scene_manager_next_scene(ctx->scene_manager, SceneNamefloodName); |
| 74 | + break; |
| 75 | + case ConfigInfoSettings: |
| 76 | + break; |
| 77 | + default: |
| 78 | + ctx->fallback_config_enter(ctx, index); |
| 79 | + break; |
| 80 | + } |
| 81 | +} |
| 82 | +static void extra_config(Ctx* ctx) { |
| 83 | + Payload* payload = &ctx->attack->payload; |
| 84 | + NamefloodCfg* cfg = &payload->cfg.nameflood; |
| 85 | + VariableItemList* list = ctx->variable_item_list; |
| 86 | + VariableItem* item; |
| 87 | + |
| 88 | + item = variable_item_list_add(list, "Display Name", 0, NULL, NULL); |
| 89 | + variable_item_set_current_value_text( |
| 90 | + item, payload->mode == PayloadModeRandom ? "Random" : cfg->name); |
| 91 | + |
| 92 | + variable_item_list_add(list, "See in phone BT settings", 0, NULL, NULL); |
| 93 | + |
| 94 | + variable_item_list_set_enter_callback(list, config_callback, ctx); |
| 95 | +} |
| 96 | + |
| 97 | +static uint8_t config_count(const Payload* payload) { |
| 98 | + UNUSED(payload); |
| 99 | + return ConfigCOUNT - ConfigExtraStart - 1; |
| 100 | +} |
| 101 | + |
| 102 | +const Protocol protocol_nameflood = { |
| 103 | + .icon = &I_ble_spam, |
| 104 | + .get_name = get_name, |
| 105 | + .make_packet = make_packet, |
| 106 | + .extra_config = extra_config, |
| 107 | + .config_count = config_count, |
| 108 | +}; |
| 109 | + |
| 110 | +static void name_callback(void* _ctx) { |
| 111 | + Ctx* ctx = _ctx; |
| 112 | + Payload* payload = &ctx->attack->payload; |
| 113 | + payload->mode = PayloadModeValue; |
| 114 | + scene_manager_previous_scene(ctx->scene_manager); |
| 115 | +} |
| 116 | +void scene_nameflood_name_on_enter(void* _ctx) { |
| 117 | + Ctx* ctx = _ctx; |
| 118 | + Payload* payload = &ctx->attack->payload; |
| 119 | + NamefloodCfg* cfg = &payload->cfg.nameflood; |
| 120 | + TextInput* text_input = ctx->text_input; |
| 121 | + |
| 122 | + text_input_set_header_text(text_input, "Press back for random"); |
| 123 | + |
| 124 | + text_input_set_result_callback( |
| 125 | + text_input, name_callback, ctx, cfg->name, sizeof(cfg->name), true); |
| 126 | + |
| 127 | + text_input_set_minimum_length(text_input, 0); |
| 128 | + |
| 129 | + view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewTextInput); |
| 130 | +} |
| 131 | +bool scene_nameflood_name_on_event(void* _ctx, SceneManagerEvent event) { |
| 132 | + Ctx* ctx = _ctx; |
| 133 | + Payload* payload = &ctx->attack->payload; |
| 134 | + if(event.type == SceneManagerEventTypeBack) { |
| 135 | + payload->mode = PayloadModeRandom; |
| 136 | + } |
| 137 | + return false; |
| 138 | +} |
| 139 | +void scene_nameflood_name_on_exit(void* _ctx) { |
| 140 | + Ctx* ctx = _ctx; |
| 141 | + text_input_reset(ctx->text_input); |
| 142 | +} |
0 commit comments