Skip to content

Commit

Permalink
upd blespam
Browse files Browse the repository at this point in the history
  • Loading branch information
xMasterX committed Mar 15, 2024
1 parent 3c15091 commit f37d0d5
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 20 deletions.
1 change: 1 addition & 0 deletions base_pack/ble_spam/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ App(
stack_size=2 * 1024,
fap_icon="ble_spam_10px.png",
fap_category="Bluetooth",
fap_file_assets="assets",
fap_author="@Willy-JL @ECTO-1A @Spooks4576",
fap_weburl="https://github.com/Next-Flip/Momentum-Apps/tree/dev/ble_spam",
fap_version="6.0",
Expand Down
4 changes: 4 additions & 0 deletions base_pack/ble_spam/assets/nameflood.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Hello :)
Flopper :C
Flipper 🐬
👋
4 changes: 4 additions & 0 deletions base_pack/ble_spam/assets/swiftpair.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Hello :)
Flopper :C
Flipper 🐬
👋
3 changes: 3 additions & 0 deletions base_pack/ble_spam/ble_spam.c
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,9 @@ int32_t ble_spam(void* p) {
furi_thread_free(state->thread);
free(state);

if(furi_hal_bt_extra_beacon_is_active()) {
furi_check(furi_hal_bt_extra_beacon_stop());
}
if(prev_cfg_ptr) {
furi_check(furi_hal_bt_extra_beacon_set_config(&prev_cfg));
}
Expand Down
51 changes: 41 additions & 10 deletions base_pack/ble_spam/protocols/nameflood.c
Original file line number Diff line number Diff line change
@@ -1,31 +1,62 @@
#include "nameflood.h"
#include "_protocols.h"

#include <storage/storage.h>
#include <toolbox/stream/file_stream.h>

// Hacked together by @Willy-JL

static const char* names[] = {
"Assquach💦",
"Flipper 🐬",
"iOS 17 🍎",
"Kink💦",
"👉👌",
"🔵🦷",
};
static const uint8_t names_count = COUNT_OF(names);
static char names[256][sizeof(((NamefloodCfg*)0)->name)];
static uint8_t names_count = 0;

static const char* get_name(const Payload* payload) {
UNUSED(payload);
return "NameFlood";
}

static const char* random_name() {
if(names_count == 0) {
// Fill random names
Storage* storage = furi_record_open(RECORD_STORAGE);
Stream* stream = file_stream_alloc(storage);
FuriString* line = furi_string_alloc();
if(!storage_file_exists(storage, APP_DATA_PATH("nameflood.txt"))) {
// Copy default names
storage_common_copy(
storage, APP_ASSETS_PATH("nameflood.txt"), APP_DATA_PATH("nameflood.txt"));
}
if(file_stream_open(
stream, APP_DATA_PATH("nameflood.txt"), FSAM_READ, FSOM_OPEN_EXISTING)) {
while(stream_read_line(stream, line)) {
furi_string_replace_all(line, "\r", "");
furi_string_replace_all(line, "\n", "");
if(furi_string_size(line)) {
strlcpy(names[names_count++], furi_string_get_cstr(line), sizeof(names[0]));
}
}
}
furi_string_free(line);
file_stream_close(stream);
stream_free(stream);
furi_record_close(RECORD_STORAGE);

if(names_count == 0) {
// Add fallback if list is empty
strlcpy(names[names_count++], "NameFlood", sizeof(names[0]));
}
}

return names[rand() % names_count];
}

static void make_packet(uint8_t* _size, uint8_t** _packet, Payload* payload) {
NamefloodCfg* cfg = payload ? &payload->cfg.nameflood : NULL;

const char* name;
switch(cfg ? payload->mode : PayloadModeRandom) {
case PayloadModeRandom:
default:
name = names[rand() % names_count];
name = random_name();
break;
case PayloadModeValue:
name = cfg->name;
Expand Down
51 changes: 41 additions & 10 deletions base_pack/ble_spam/protocols/swiftpair.c
Original file line number Diff line number Diff line change
@@ -1,32 +1,63 @@
#include "swiftpair.h"
#include "_protocols.h"

#include <storage/storage.h>
#include <toolbox/stream/file_stream.h>

// Hacked together by @Willy-JL and @Spooks4576
// Documentation at https://learn.microsoft.com/en-us/windows-hardware/design/component-guidelines/bluetooth-swift-pair

static const char* names[] = {
"Assquach💦",
"Flipper 🐬",
"iOS 17 🍎",
"Kink💦",
"👉👌",
"🔵🦷",
};
static const uint8_t names_count = COUNT_OF(names);
static char names[256][sizeof(((SwiftpairCfg*)0)->name)];
static uint8_t names_count = 0;

static const char* get_name(const Payload* payload) {
UNUSED(payload);
return "SwiftPair";
}

static const char* random_name() {
if(names_count == 0) {
// Fill random names
Storage* storage = furi_record_open(RECORD_STORAGE);
Stream* stream = file_stream_alloc(storage);
FuriString* line = furi_string_alloc();
if(!storage_file_exists(storage, APP_DATA_PATH("swiftpair.txt"))) {
// Copy default names
storage_common_copy(
storage, APP_ASSETS_PATH("swiftpair.txt"), APP_DATA_PATH("swiftpair.txt"));
}
if(file_stream_open(
stream, APP_DATA_PATH("swiftpair.txt"), FSAM_READ, FSOM_OPEN_EXISTING)) {
while(stream_read_line(stream, line)) {
furi_string_replace_all(line, "\r", "");
furi_string_replace_all(line, "\n", "");
if(furi_string_size(line)) {
strlcpy(names[names_count++], furi_string_get_cstr(line), sizeof(names[0]));
}
}
}
furi_string_free(line);
file_stream_close(stream);
stream_free(stream);
furi_record_close(RECORD_STORAGE);

if(names_count == 0) {
// Add fallback if list is empty
strlcpy(names[names_count++], "SwiftPair", sizeof(names[0]));
}
}

return names[rand() % names_count];
}

static void make_packet(uint8_t* _size, uint8_t** _packet, Payload* payload) {
SwiftpairCfg* cfg = payload ? &payload->cfg.swiftpair : NULL;

const char* name;
switch(cfg ? payload->mode : PayloadModeRandom) {
case PayloadModeRandom:
default:
name = names[rand() % names_count];
name = random_name();
break;
case PayloadModeValue:
name = cfg->name;
Expand Down

0 comments on commit f37d0d5

Please sign in to comment.