BLE Spam refactor random/set/custom mode handling

This commit is contained in:
Willy-JL
2023-10-25 00:02:36 +01:00
parent 60ec667178
commit 0f3fbd1cd7
7 changed files with 277 additions and 185 deletions

View File

@@ -30,16 +30,13 @@ static Attack attacks[] = {
.payload = .payload =
{ {
.random_mac = false, .random_mac = false,
.cfg = .cfg.specific.continuity =
{
.continuity =
{ {
.type = ContinuityTypeCustomCrash, .type = ContinuityTypeCustomCrash,
.data = {}, .data = {},
}, },
}, },
}, },
},
{ {
.title = "Apple Action Modal", .title = "Apple Action Modal",
.text = "Lock cooldown, long range", .text = "Lock cooldown, long range",
@@ -47,16 +44,13 @@ static Attack attacks[] = {
.payload = .payload =
{ {
.random_mac = false, .random_mac = false,
.cfg = .cfg.specific.continuity =
{
.continuity =
{ {
.type = ContinuityTypeNearbyAction, .type = ContinuityTypeNearbyAction,
.data = {}, .data = {},
}, },
}, },
}, },
},
{ {
.title = "Apple Device Popup", .title = "Apple Device Popup",
.text = "No cooldown, close range", .text = "No cooldown, close range",
@@ -64,16 +58,13 @@ static Attack attacks[] = {
.payload = .payload =
{ {
.random_mac = false, .random_mac = false,
.cfg = .cfg.specific.continuity =
{
.continuity =
{ {
.type = ContinuityTypeProximityPair, .type = ContinuityTypeProximityPair,
.data = {}, .data = {},
}, },
}, },
}, },
},
{ {
.title = "Android Device Connect", .title = "Android Device Connect",
.text = "Reboot cooldown, long range", .text = "Reboot cooldown, long range",
@@ -81,10 +72,7 @@ static Attack attacks[] = {
.payload = .payload =
{ {
.random_mac = true, .random_mac = true,
.cfg = .cfg.specific.fastpair = {},
{
.fastpair = {},
},
}, },
}, },
{ {
@@ -94,16 +82,13 @@ static Attack attacks[] = {
.payload = .payload =
{ {
.random_mac = true, .random_mac = true,
.cfg = .cfg.specific.easysetup =
{
.easysetup =
{ {
.type = EasysetupTypeBuds, .type = EasysetupTypeBuds,
.data = {}, .data = {},
}, },
}, },
}, },
},
{ {
.title = "Samsung Watch Pair", .title = "Samsung Watch Pair",
.text = "No cooldown, long range", .text = "No cooldown, long range",
@@ -111,16 +96,13 @@ static Attack attacks[] = {
.payload = .payload =
{ {
.random_mac = true, .random_mac = true,
.cfg = .cfg.specific.easysetup =
{
.easysetup =
{ {
.type = EasysetupTypeWatch, .type = EasysetupTypeWatch,
.data = {}, .data = {},
}, },
}, },
}, },
},
{ {
.title = "Windows Device Found", .title = "Windows Device Found",
.text = "No cooldown, short range", .text = "No cooldown, short range",
@@ -128,10 +110,7 @@ static Attack attacks[] = {
.payload = .payload =
{ {
.random_mac = true, .random_mac = true,
.cfg = .cfg.specific.swiftpair = {},
{
.swiftpair = {},
},
}, },
}, },
}; };

View File

@@ -10,12 +10,12 @@
#include <core/core_defines.h> #include <core/core_defines.h>
#include "../ble_spam.h" #include "../ble_spam.h"
typedef union ProtocolCfg ProtocolCfg; typedef struct ProtocolCfg ProtocolCfg;
typedef struct { typedef struct {
const Icon* icon; const Icon* icon;
const char* (*get_name)(const ProtocolCfg* _cfg); const char* (*get_name)(const ProtocolCfg* _cfg);
void (*make_packet)(uint8_t* _size, uint8_t** _packet, const ProtocolCfg* _cfg); void (*make_packet)(uint8_t* _size, uint8_t** _packet, ProtocolCfg* _cfg);
void (*extra_config)(Ctx* ctx); void (*extra_config)(Ctx* ctx);
uint8_t (*config_count)(const ProtocolCfg* _cfg); uint8_t (*config_count)(const ProtocolCfg* _cfg);
} Protocol; } Protocol;

View File

@@ -5,11 +5,19 @@
#include "easysetup.h" #include "easysetup.h"
#include "swiftpair.h" #include "swiftpair.h"
union ProtocolCfg { typedef enum {
ProtocolModeRandom,
ProtocolModeValue,
} ProtocolMode;
struct ProtocolCfg {
ProtocolMode mode;
union {
ContinuityCfg continuity; ContinuityCfg continuity;
FastpairCfg fastpair; FastpairCfg fastpair;
EasysetupCfg easysetup; EasysetupCfg easysetup;
SwiftpairCfg swiftpair; SwiftpairCfg swiftpair;
} specific;
}; };
extern const Protocol* protocols[]; extern const Protocol* protocols[];

View File

@@ -72,7 +72,7 @@ static const char* type_names[ContinuityTypeCOUNT] = {
[ContinuityTypeCustomCrash] = "Continuity Custom", [ContinuityTypeCustomCrash] = "Continuity Custom",
}; };
static const char* get_name(const ProtocolCfg* _cfg) { static const char* get_name(const ProtocolCfg* _cfg) {
const ContinuityCfg* cfg = &_cfg->continuity; const ContinuityCfg* cfg = &_cfg->specific.continuity;
return type_names[cfg->type]; return type_names[cfg->type];
} }
@@ -87,8 +87,8 @@ static uint8_t packet_sizes[ContinuityTypeCOUNT] = {
[ContinuityTypeNearbyInfo] = HEADER_LEN + 5, [ContinuityTypeNearbyInfo] = HEADER_LEN + 5,
[ContinuityTypeCustomCrash] = HEADER_LEN + 11, [ContinuityTypeCustomCrash] = HEADER_LEN + 11,
}; };
static void make_packet(uint8_t* _size, uint8_t** _packet, const ProtocolCfg* _cfg) { static void make_packet(uint8_t* _size, uint8_t** _packet, ProtocolCfg* _cfg) {
const ContinuityCfg* cfg = _cfg ? &_cfg->continuity : NULL; ContinuityCfg* cfg = _cfg ? &_cfg->specific.continuity : NULL;
ContinuityType type; ContinuityType type;
if(cfg && cfg->type != 0x00) { if(cfg && cfg->type != 0x00) {
@@ -139,14 +139,18 @@ static void make_packet(uint8_t* _size, uint8_t** _packet, const ProtocolCfg* _c
case ContinuityTypeProximityPair: { case ContinuityTypeProximityPair: {
uint16_t model; uint16_t model;
if(cfg && cfg->data.proximity_pair.model != 0x0000) { switch(cfg ? _cfg->mode : ProtocolModeRandom) {
model = cfg->data.proximity_pair.model; case ProtocolModeRandom:
} else { default:
model = pp_models[rand() % pp_models_count].value; model = pp_models[rand() % pp_models_count].value;
break;
case ProtocolModeValue:
model = cfg->data.proximity_pair.model;
break;
} }
uint8_t prefix; uint8_t prefix;
if(cfg && cfg->data.proximity_pair.prefix == 0x00) { if(cfg && cfg->data.proximity_pair.prefix != 0x00) {
prefix = cfg->data.proximity_pair.prefix; prefix = cfg->data.proximity_pair.prefix;
} else { } else {
if(model == 0x0055 || model == 0x0030) if(model == 0x0055 || model == 0x0030)
@@ -209,10 +213,14 @@ static void make_packet(uint8_t* _size, uint8_t** _packet, const ProtocolCfg* _c
case ContinuityTypeNearbyAction: { case ContinuityTypeNearbyAction: {
uint8_t action; uint8_t action;
if(cfg && cfg->data.nearby_action.action != 0x00) { switch(cfg ? _cfg->mode : ProtocolModeRandom) {
action = cfg->data.nearby_action.action; case ProtocolModeRandom:
} else { default:
action = na_actions[rand() % na_actions_count].value; action = na_actions[rand() % na_actions_count].value;
break;
case ProtocolModeValue:
action = cfg->data.nearby_action.action;
break;
} }
uint8_t flags; uint8_t flags;
@@ -293,7 +301,8 @@ enum {
}; };
static void config_callback(void* _ctx, uint32_t index) { static void config_callback(void* _ctx, uint32_t index) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
scene_manager_set_scene_state(ctx->scene_manager, SceneConfig, index); scene_manager_set_scene_state(ctx->scene_manager, SceneConfig, index);
switch(cfg->type) { switch(cfg->type) {
case ContinuityTypeProximityPair: { case ContinuityTypeProximityPair: {
@@ -341,19 +350,22 @@ static void config_callback(void* _ctx, uint32_t index) {
} }
} }
static void pp_model_changed(VariableItem* item) { static void pp_model_changed(VariableItem* item) {
ContinuityCfg* cfg = variable_item_get_context(item); ProtocolCfg* _cfg = variable_item_get_context(item);
ContinuityCfg* cfg = &_cfg->specific.continuity;
uint8_t index = variable_item_get_current_value_index(item); uint8_t index = variable_item_get_current_value_index(item);
if(index) { if(index) {
index--; index--;
_cfg->mode = ProtocolModeValue;
cfg->data.proximity_pair.model = pp_models[index].value; cfg->data.proximity_pair.model = pp_models[index].value;
variable_item_set_current_value_text(item, pp_models[index].name); variable_item_set_current_value_text(item, pp_models[index].name);
} else { } else {
cfg->data.proximity_pair.model = 0x0000; _cfg->mode = ProtocolModeRandom;
variable_item_set_current_value_text(item, "Random"); variable_item_set_current_value_text(item, "Random");
} }
} }
static void pp_prefix_changed(VariableItem* item) { static void pp_prefix_changed(VariableItem* item) {
ContinuityCfg* cfg = variable_item_get_context(item); ProtocolCfg* _cfg = variable_item_get_context(item);
ContinuityCfg* cfg = &_cfg->specific.continuity;
uint8_t index = variable_item_get_current_value_index(item); uint8_t index = variable_item_get_current_value_index(item);
if(index) { if(index) {
index--; index--;
@@ -365,33 +377,39 @@ static void pp_prefix_changed(VariableItem* item) {
} }
} }
static void na_action_changed(VariableItem* item) { static void na_action_changed(VariableItem* item) {
ContinuityCfg* cfg = variable_item_get_context(item); ProtocolCfg* _cfg = variable_item_get_context(item);
ContinuityCfg* cfg = &_cfg->specific.continuity;
uint8_t index = variable_item_get_current_value_index(item); uint8_t index = variable_item_get_current_value_index(item);
if(index) { if(index) {
index--; index--;
_cfg->mode = ProtocolModeValue;
cfg->data.nearby_action.action = na_actions[index].value; cfg->data.nearby_action.action = na_actions[index].value;
variable_item_set_current_value_text(item, na_actions[index].name); variable_item_set_current_value_text(item, na_actions[index].name);
} else { } else {
cfg->data.nearby_action.action = 0x00; _cfg->mode = ProtocolModeRandom;
variable_item_set_current_value_text(item, "Random"); variable_item_set_current_value_text(item, "Random");
} }
} }
static void extra_config(Ctx* ctx) { static void extra_config(Ctx* ctx) {
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
VariableItemList* list = ctx->variable_item_list; VariableItemList* list = ctx->variable_item_list;
VariableItem* item; VariableItem* item;
size_t value_index; size_t value_index;
switch(cfg->type) { switch(cfg->type) {
case ContinuityTypeProximityPair: { case ContinuityTypeProximityPair: {
item = item = variable_item_list_add(
variable_item_list_add(list, "Model Code", pp_models_count + 1, pp_model_changed, cfg); list, "Model Code", pp_models_count + 1, pp_model_changed, _cfg);
const char* model_name = NULL; const char* model_name = NULL;
char model_name_buf[5]; char model_name_buf[5];
if(cfg->data.proximity_pair.model == 0x0000) { switch(_cfg->mode) {
case ProtocolModeRandom:
default:
model_name = "Random"; model_name = "Random";
value_index = 0; value_index = 0;
} else { break;
case ProtocolModeValue:
for(uint8_t i = 0; i < pp_models_count; i++) { for(uint8_t i = 0; i < pp_models_count; i++) {
if(cfg->data.proximity_pair.model == pp_models[i].value) { if(cfg->data.proximity_pair.model == pp_models[i].value) {
model_name = pp_models[i].name; model_name = pp_models[i].name;
@@ -405,12 +423,13 @@ static void extra_config(Ctx* ctx) {
model_name = model_name_buf; model_name = model_name_buf;
value_index = pp_models_count + 1; value_index = pp_models_count + 1;
} }
break;
} }
variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, model_name); variable_item_set_current_value_text(item, model_name);
item = item =
variable_item_list_add(list, "Prefix", pp_prefixes_count + 1, pp_prefix_changed, cfg); variable_item_list_add(list, "Prefix", pp_prefixes_count + 1, pp_prefix_changed, _cfg);
const char* prefix_name = NULL; const char* prefix_name = NULL;
char prefix_name_buf[3]; char prefix_name_buf[3];
if(cfg->data.proximity_pair.prefix == 0x00) { if(cfg->data.proximity_pair.prefix == 0x00) {
@@ -440,13 +459,16 @@ static void extra_config(Ctx* ctx) {
} }
case ContinuityTypeNearbyAction: { case ContinuityTypeNearbyAction: {
item = variable_item_list_add( item = variable_item_list_add(
list, "Action Type", na_actions_count + 1, na_action_changed, cfg); list, "Action Type", na_actions_count + 1, na_action_changed, _cfg);
const char* action_name = NULL; const char* action_name = NULL;
char action_name_buf[3]; char action_name_buf[3];
if(cfg->data.nearby_action.action == 0x00) { switch(_cfg->mode) {
case ProtocolModeRandom:
default:
action_name = "Random"; action_name = "Random";
value_index = 0; value_index = 0;
} else { break;
case ProtocolModeValue:
for(uint8_t i = 0; i < na_actions_count; i++) { for(uint8_t i = 0; i < na_actions_count; i++) {
if(cfg->data.nearby_action.action == na_actions[i].value) { if(cfg->data.nearby_action.action == na_actions[i].value) {
action_name = na_actions[i].name; action_name = na_actions[i].name;
@@ -463,6 +485,7 @@ static void extra_config(Ctx* ctx) {
action_name = action_name_buf; action_name = action_name_buf;
value_index = na_actions_count + 1; value_index = na_actions_count + 1;
} }
break;
} }
variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, action_name); variable_item_set_current_value_text(item, action_name);
@@ -503,7 +526,7 @@ static uint8_t config_counts[ContinuityTypeCOUNT] = {
[ContinuityTypeCustomCrash] = ConfigCcCOUNT - ConfigExtraStart - 1, [ContinuityTypeCustomCrash] = ConfigCcCOUNT - ConfigExtraStart - 1,
}; };
static uint8_t config_count(const ProtocolCfg* _cfg) { static uint8_t config_count(const ProtocolCfg* _cfg) {
const ContinuityCfg* cfg = &_cfg->continuity; const ContinuityCfg* cfg = &_cfg->specific.continuity;
return config_counts[cfg->type]; return config_counts[cfg->type];
} }
@@ -517,16 +540,18 @@ const Protocol protocol_continuity = {
static void pp_model_callback(void* _ctx, uint32_t index) { static void pp_model_callback(void* _ctx, uint32_t index) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
switch(index) { switch(index) {
case 0: case 0:
cfg->data.proximity_pair.model = 0x0000; _cfg->mode = ProtocolModeRandom;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
break; break;
case pp_models_count + 1: case pp_models_count + 1:
scene_manager_next_scene(ctx->scene_manager, SceneContinuityPpModelCustom); scene_manager_next_scene(ctx->scene_manager, SceneContinuityPpModelCustom);
break; break;
default: default:
_cfg->mode = ProtocolModeValue;
cfg->data.proximity_pair.model = pp_models[index - 1].value; cfg->data.proximity_pair.model = pp_models[index - 1].value;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
break; break;
@@ -534,27 +559,28 @@ static void pp_model_callback(void* _ctx, uint32_t index) {
} }
void scene_continuity_pp_model_on_enter(void* _ctx) { void scene_continuity_pp_model_on_enter(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
Submenu* submenu = ctx->submenu; Submenu* submenu = ctx->submenu;
uint32_t selected = 0; uint32_t selected = 0;
bool found = false;
submenu_reset(submenu); submenu_reset(submenu);
submenu_add_item(submenu, "Random", 0, pp_model_callback, ctx); submenu_add_item(submenu, "Random", 0, pp_model_callback, ctx);
if(cfg->data.proximity_pair.model == 0x0000) { if(_cfg->mode == ProtocolModeRandom) {
found = true;
selected = 0; selected = 0;
} }
bool found = false;
for(uint8_t i = 0; i < pp_models_count; i++) { for(uint8_t i = 0; i < pp_models_count; i++) {
submenu_add_item(submenu, pp_models[i].name, i + 1, pp_model_callback, ctx); submenu_add_item(submenu, pp_models[i].name, i + 1, pp_model_callback, ctx);
if(!found && cfg->data.proximity_pair.model == pp_models[i].value) { if(!found && _cfg->mode == ProtocolModeValue &&
cfg->data.proximity_pair.model == pp_models[i].value) {
found = true; found = true;
selected = i + 1; selected = i + 1;
} }
} }
submenu_add_item(submenu, "Custom", pp_models_count + 1, pp_model_callback, ctx); submenu_add_item(submenu, "Custom", pp_models_count + 1, pp_model_callback, ctx);
if(!found) { if(!found && _cfg->mode == ProtocolModeValue) {
found = true;
selected = pp_models_count + 1; selected = pp_models_count + 1;
} }
@@ -573,14 +599,17 @@ void scene_continuity_pp_model_on_exit(void* _ctx) {
static void pp_model_custom_callback(void* _ctx) { static void pp_model_custom_callback(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
_cfg->mode = ProtocolModeValue;
cfg->data.proximity_pair.model = (ctx->byte_store[0] << 0x08) + (ctx->byte_store[1] << 0x00); cfg->data.proximity_pair.model = (ctx->byte_store[0] << 0x08) + (ctx->byte_store[1] << 0x00);
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
} }
void scene_continuity_pp_model_custom_on_enter(void* _ctx) { void scene_continuity_pp_model_custom_on_enter(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
ByteInput* byte_input = ctx->byte_input; ByteInput* byte_input = ctx->byte_input;
byte_input_set_header_text(byte_input, "Enter custom Model Code"); byte_input_set_header_text(byte_input, "Enter custom Model Code");
@@ -604,7 +633,8 @@ void scene_continuity_pp_model_custom_on_exit(void* _ctx) {
static void pp_prefix_callback(void* _ctx, uint32_t index) { static void pp_prefix_callback(void* _ctx, uint32_t index) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
switch(index) { switch(index) {
case 0: case 0:
cfg->data.proximity_pair.prefix = 0x00; cfg->data.proximity_pair.prefix = 0x00;
@@ -621,7 +651,8 @@ static void pp_prefix_callback(void* _ctx, uint32_t index) {
} }
void scene_continuity_pp_prefix_on_enter(void* _ctx) { void scene_continuity_pp_prefix_on_enter(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
Submenu* submenu = ctx->submenu; Submenu* submenu = ctx->submenu;
uint32_t selected = 0; uint32_t selected = 0;
bool found = false; bool found = false;
@@ -632,6 +663,7 @@ void scene_continuity_pp_prefix_on_enter(void* _ctx) {
found = true; found = true;
selected = 0; selected = 0;
} }
for(uint8_t i = 0; i < pp_prefixes_count; i++) { for(uint8_t i = 0; i < pp_prefixes_count; i++) {
submenu_add_item(submenu, pp_prefixes[i].name, i + 1, pp_prefix_callback, ctx); submenu_add_item(submenu, pp_prefixes[i].name, i + 1, pp_prefix_callback, ctx);
if(!found && cfg->data.proximity_pair.prefix == pp_prefixes[i].value) { if(!found && cfg->data.proximity_pair.prefix == pp_prefixes[i].value) {
@@ -641,7 +673,6 @@ void scene_continuity_pp_prefix_on_enter(void* _ctx) {
} }
submenu_add_item(submenu, "Custom", pp_prefixes_count + 1, pp_prefix_callback, ctx); submenu_add_item(submenu, "Custom", pp_prefixes_count + 1, pp_prefix_callback, ctx);
if(!found) { if(!found) {
found = true;
selected = pp_prefixes_count + 1; selected = pp_prefixes_count + 1;
} }
@@ -660,14 +691,16 @@ void scene_continuity_pp_prefix_on_exit(void* _ctx) {
static void pp_prefix_custom_callback(void* _ctx) { static void pp_prefix_custom_callback(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
cfg->data.proximity_pair.prefix = (ctx->byte_store[0] << 0x00); cfg->data.proximity_pair.prefix = (ctx->byte_store[0] << 0x00);
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
} }
void scene_continuity_pp_prefix_custom_on_enter(void* _ctx) { void scene_continuity_pp_prefix_custom_on_enter(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
ByteInput* byte_input = ctx->byte_input; ByteInput* byte_input = ctx->byte_input;
byte_input_set_header_text(byte_input, "Enter custom Prefix"); byte_input_set_header_text(byte_input, "Enter custom Prefix");
@@ -690,16 +723,18 @@ void scene_continuity_pp_prefix_custom_on_exit(void* _ctx) {
static void na_action_callback(void* _ctx, uint32_t index) { static void na_action_callback(void* _ctx, uint32_t index) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
switch(index) { switch(index) {
case 0: case 0:
cfg->data.nearby_action.action = 0x00; _cfg->mode = ProtocolModeRandom;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
break; break;
case na_actions_count + 1: case na_actions_count + 1:
scene_manager_next_scene(ctx->scene_manager, SceneContinuityNaActionCustom); scene_manager_next_scene(ctx->scene_manager, SceneContinuityNaActionCustom);
break; break;
default: default:
_cfg->mode = ProtocolModeValue;
cfg->data.nearby_action.action = na_actions[index - 1].value; cfg->data.nearby_action.action = na_actions[index - 1].value;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
break; break;
@@ -707,27 +742,28 @@ static void na_action_callback(void* _ctx, uint32_t index) {
} }
void scene_continuity_na_action_on_enter(void* _ctx) { void scene_continuity_na_action_on_enter(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
Submenu* submenu = ctx->submenu; Submenu* submenu = ctx->submenu;
uint32_t selected = 0; uint32_t selected = 0;
bool found = false;
submenu_reset(submenu); submenu_reset(submenu);
submenu_add_item(submenu, "Random", 0, na_action_callback, ctx); submenu_add_item(submenu, "Random", 0, na_action_callback, ctx);
if(cfg->data.nearby_action.action == 0x00) { if(_cfg->mode == ProtocolModeRandom) {
found = true;
selected = 0; selected = 0;
} }
bool found = false;
for(uint8_t i = 0; i < na_actions_count; i++) { for(uint8_t i = 0; i < na_actions_count; i++) {
submenu_add_item(submenu, na_actions[i].name, i + 1, na_action_callback, ctx); submenu_add_item(submenu, na_actions[i].name, i + 1, na_action_callback, ctx);
if(!found && cfg->data.nearby_action.action == na_actions[i].value) { if(!found && _cfg->mode == ProtocolModeValue &&
cfg->data.nearby_action.action == na_actions[i].value) {
found = true; found = true;
selected = i + 1; selected = i + 1;
} }
} }
submenu_add_item(submenu, "Custom", na_actions_count + 1, na_action_callback, ctx); submenu_add_item(submenu, "Custom", na_actions_count + 1, na_action_callback, ctx);
if(!found) { if(!found && _cfg->mode == ProtocolModeValue) {
found = true;
selected = na_actions_count + 1; selected = na_actions_count + 1;
} }
@@ -746,14 +782,17 @@ void scene_continuity_na_action_on_exit(void* _ctx) {
static void na_action_custom_callback(void* _ctx) { static void na_action_custom_callback(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
_cfg->mode = ProtocolModeValue;
cfg->data.nearby_action.action = (ctx->byte_store[0] << 0x00); cfg->data.nearby_action.action = (ctx->byte_store[0] << 0x00);
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
} }
void scene_continuity_na_action_custom_on_enter(void* _ctx) { void scene_continuity_na_action_custom_on_enter(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
ByteInput* byte_input = ctx->byte_input; ByteInput* byte_input = ctx->byte_input;
byte_input_set_header_text(byte_input, "Enter custom Action Type"); byte_input_set_header_text(byte_input, "Enter custom Action Type");
@@ -780,7 +819,8 @@ static void na_flags_callback(void* _ctx) {
} }
void scene_continuity_na_flags_on_enter(void* _ctx) { void scene_continuity_na_flags_on_enter(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
ByteInput* byte_input = ctx->byte_input; ByteInput* byte_input = ctx->byte_input;
byte_input_set_header_text(byte_input, "Press back for automatic"); byte_input_set_header_text(byte_input, "Press back for automatic");
@@ -801,6 +841,7 @@ bool scene_continuity_na_flags_on_event(void* _ctx, SceneManagerEvent event) {
} }
void scene_continuity_na_flags_on_exit(void* _ctx) { void scene_continuity_na_flags_on_exit(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
cfg->data.nearby_action.flags = (ctx->byte_store[0] << 0x00); cfg->data.nearby_action.flags = (ctx->byte_store[0] << 0x00);
} }

View File

@@ -69,7 +69,7 @@ static const char* type_names[EasysetupTypeCOUNT] = {
[EasysetupTypeWatch] = "EasySetup Watch", [EasysetupTypeWatch] = "EasySetup Watch",
}; };
static const char* get_name(const ProtocolCfg* _cfg) { static const char* get_name(const ProtocolCfg* _cfg) {
const EasysetupCfg* cfg = &_cfg->easysetup; const EasysetupCfg* cfg = &_cfg->specific.easysetup;
return type_names[cfg->type]; return type_names[cfg->type];
} }
@@ -77,8 +77,8 @@ static uint8_t packet_sizes[EasysetupTypeCOUNT] = {
[EasysetupTypeBuds] = 31, [EasysetupTypeBuds] = 31,
[EasysetupTypeWatch] = 15, [EasysetupTypeWatch] = 15,
}; };
void make_packet(uint8_t* out_size, uint8_t** out_packet, const ProtocolCfg* _cfg) { void make_packet(uint8_t* out_size, uint8_t** out_packet, ProtocolCfg* _cfg) {
const EasysetupCfg* cfg = _cfg ? &_cfg->easysetup : NULL; EasysetupCfg* cfg = _cfg ? &_cfg->specific.easysetup : NULL;
EasysetupType type; EasysetupType type;
if(cfg && cfg->type != 0x00) { if(cfg && cfg->type != 0x00) {
@@ -98,10 +98,14 @@ void make_packet(uint8_t* out_size, uint8_t** out_packet, const ProtocolCfg* _cf
switch(type) { switch(type) {
case EasysetupTypeBuds: { case EasysetupTypeBuds: {
uint32_t model; uint32_t model;
if(cfg && cfg->data.buds.model != 0x000000) { switch(cfg ? _cfg->mode : ProtocolModeRandom) {
model = cfg->data.buds.model; case ProtocolModeRandom:
} else { default:
model = buds_models[rand() % buds_models_count].value; model = buds_models[rand() % buds_models_count].value;
break;
case ProtocolModeValue:
model = cfg->data.buds.model;
break;
} }
packet[i++] = 27; // Size packet[i++] = 27; // Size
@@ -141,10 +145,14 @@ void make_packet(uint8_t* out_size, uint8_t** out_packet, const ProtocolCfg* _cf
} }
case EasysetupTypeWatch: { case EasysetupTypeWatch: {
uint8_t model; uint8_t model;
if(cfg && cfg->data.watch.model != 0x00) { switch(cfg ? _cfg->mode : ProtocolModeRandom) {
model = cfg->data.watch.model; case ProtocolModeRandom:
} else { default:
model = watch_models[rand() % watch_models_count].value; model = watch_models[rand() % watch_models_count].value;
break;
case ProtocolModeValue:
model = cfg->data.watch.model;
break;
} }
packet[i++] = 14; // Size packet[i++] = 14; // Size
@@ -185,7 +193,8 @@ enum {
}; };
static void config_callback(void* _ctx, uint32_t index) { static void config_callback(void* _ctx, uint32_t index) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
EasysetupCfg* cfg = &_cfg->specific.easysetup;
scene_manager_set_scene_state(ctx->scene_manager, SceneConfig, index); scene_manager_set_scene_state(ctx->scene_manager, SceneConfig, index);
switch(cfg->type) { switch(cfg->type) {
case EasysetupTypeBuds: { case EasysetupTypeBuds: {
@@ -218,31 +227,36 @@ static void config_callback(void* _ctx, uint32_t index) {
} }
} }
static void buds_model_changed(VariableItem* item) { static void buds_model_changed(VariableItem* item) {
EasysetupCfg* cfg = variable_item_get_context(item); ProtocolCfg* _cfg = variable_item_get_context(item);
EasysetupCfg* cfg = &_cfg->specific.easysetup;
uint8_t index = variable_item_get_current_value_index(item); uint8_t index = variable_item_get_current_value_index(item);
if(index) { if(index) {
index--; index--;
_cfg->mode = ProtocolModeValue;
cfg->data.buds.model = buds_models[index].value; cfg->data.buds.model = buds_models[index].value;
variable_item_set_current_value_text(item, buds_models[index].name); variable_item_set_current_value_text(item, buds_models[index].name);
} else { } else {
cfg->data.buds.model = 0x000000; _cfg->mode = ProtocolModeRandom;
variable_item_set_current_value_text(item, "Random"); variable_item_set_current_value_text(item, "Random");
} }
} }
static void watch_model_changed(VariableItem* item) { static void watch_model_changed(VariableItem* item) {
EasysetupCfg* cfg = variable_item_get_context(item); ProtocolCfg* _cfg = variable_item_get_context(item);
EasysetupCfg* cfg = &_cfg->specific.easysetup;
uint8_t index = variable_item_get_current_value_index(item); uint8_t index = variable_item_get_current_value_index(item);
if(index) { if(index) {
index--; index--;
_cfg->mode = ProtocolModeValue;
cfg->data.watch.model = watch_models[index].value; cfg->data.watch.model = watch_models[index].value;
variable_item_set_current_value_text(item, watch_models[index].name); variable_item_set_current_value_text(item, watch_models[index].name);
} else { } else {
cfg->data.watch.model = 0x00; _cfg->mode = ProtocolModeRandom;
variable_item_set_current_value_text(item, "Random"); variable_item_set_current_value_text(item, "Random");
} }
} }
static void extra_config(Ctx* ctx) { static void extra_config(Ctx* ctx) {
EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
EasysetupCfg* cfg = &_cfg->specific.easysetup;
VariableItemList* list = ctx->variable_item_list; VariableItemList* list = ctx->variable_item_list;
VariableItem* item; VariableItem* item;
size_t value_index; size_t value_index;
@@ -250,13 +264,16 @@ static void extra_config(Ctx* ctx) {
switch(cfg->type) { switch(cfg->type) {
case EasysetupTypeBuds: { case EasysetupTypeBuds: {
item = variable_item_list_add( item = variable_item_list_add(
list, "Model Code", buds_models_count + 1, buds_model_changed, cfg); list, "Model Code", buds_models_count + 1, buds_model_changed, _cfg);
const char* model_name = NULL; const char* model_name = NULL;
char model_name_buf[9]; char model_name_buf[9];
if(cfg->data.buds.model == 0x000000) { switch(_cfg->mode) {
case ProtocolModeRandom:
default:
model_name = "Random"; model_name = "Random";
value_index = 0; value_index = 0;
} else { break;
case ProtocolModeValue:
for(uint8_t i = 0; i < buds_models_count; i++) { for(uint8_t i = 0; i < buds_models_count; i++) {
if(cfg->data.buds.model == buds_models[i].value) { if(cfg->data.buds.model == buds_models[i].value) {
model_name = buds_models[i].name; model_name = buds_models[i].name;
@@ -269,6 +286,7 @@ static void extra_config(Ctx* ctx) {
model_name = model_name_buf; model_name = model_name_buf;
value_index = buds_models_count + 1; value_index = buds_models_count + 1;
} }
break;
} }
variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, model_name); variable_item_set_current_value_text(item, model_name);
@@ -278,13 +296,16 @@ static void extra_config(Ctx* ctx) {
} }
case EasysetupTypeWatch: { case EasysetupTypeWatch: {
item = variable_item_list_add( item = variable_item_list_add(
list, "Model Code", watch_models_count + 1, watch_model_changed, cfg); list, "Model Code", watch_models_count + 1, watch_model_changed, _cfg);
const char* model_name = NULL; const char* model_name = NULL;
char model_name_buf[3]; char model_name_buf[3];
if(cfg->data.watch.model == 0x00) { switch(_cfg->mode) {
case ProtocolModeRandom:
default:
model_name = "Random"; model_name = "Random";
value_index = 0; value_index = 0;
} else { break;
case ProtocolModeValue:
for(uint8_t i = 0; i < watch_models_count; i++) { for(uint8_t i = 0; i < watch_models_count; i++) {
if(cfg->data.watch.model == watch_models[i].value) { if(cfg->data.watch.model == watch_models[i].value) {
model_name = watch_models[i].name; model_name = watch_models[i].name;
@@ -297,6 +318,7 @@ static void extra_config(Ctx* ctx) {
model_name = model_name_buf; model_name = model_name_buf;
value_index = watch_models_count + 1; value_index = watch_models_count + 1;
} }
break;
} }
variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, model_name); variable_item_set_current_value_text(item, model_name);
@@ -314,7 +336,7 @@ static uint8_t config_counts[EasysetupTypeCOUNT] = {
[EasysetupTypeWatch] = ConfigWatchCOUNT - ConfigExtraStart - 1, [EasysetupTypeWatch] = ConfigWatchCOUNT - ConfigExtraStart - 1,
}; };
static uint8_t config_count(const ProtocolCfg* _cfg) { static uint8_t config_count(const ProtocolCfg* _cfg) {
const EasysetupCfg* cfg = &_cfg->easysetup; const EasysetupCfg* cfg = &_cfg->specific.easysetup;
return config_counts[cfg->type]; return config_counts[cfg->type];
} }
@@ -328,16 +350,18 @@ const Protocol protocol_easysetup = {
static void buds_model_callback(void* _ctx, uint32_t index) { static void buds_model_callback(void* _ctx, uint32_t index) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
EasysetupCfg* cfg = &_cfg->specific.easysetup;
switch(index) { switch(index) {
case 0: case 0:
cfg->data.buds.model = 0x000000; _cfg->mode = ProtocolModeRandom;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
break; break;
case buds_models_count + 1: case buds_models_count + 1:
scene_manager_next_scene(ctx->scene_manager, SceneEasysetupBudsModelCustom); scene_manager_next_scene(ctx->scene_manager, SceneEasysetupBudsModelCustom);
break; break;
default: default:
_cfg->mode = ProtocolModeValue;
cfg->data.buds.model = buds_models[index - 1].value; cfg->data.buds.model = buds_models[index - 1].value;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
break; break;
@@ -345,27 +369,28 @@ static void buds_model_callback(void* _ctx, uint32_t index) {
} }
void scene_easysetup_buds_model_on_enter(void* _ctx) { void scene_easysetup_buds_model_on_enter(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
EasysetupCfg* cfg = &_cfg->specific.easysetup;
Submenu* submenu = ctx->submenu; Submenu* submenu = ctx->submenu;
uint32_t selected = 0; uint32_t selected = 0;
bool found = false;
submenu_reset(submenu); submenu_reset(submenu);
submenu_add_item(submenu, "Random", 0, buds_model_callback, ctx); submenu_add_item(submenu, "Random", 0, buds_model_callback, ctx);
if(cfg->data.buds.model == 0x000000) { if(_cfg->mode == ProtocolModeRandom) {
found = true;
selected = 0; selected = 0;
} }
bool found = false;
for(uint8_t i = 0; i < buds_models_count; i++) { for(uint8_t i = 0; i < buds_models_count; i++) {
submenu_add_item(submenu, buds_models[i].name, i + 1, buds_model_callback, ctx); submenu_add_item(submenu, buds_models[i].name, i + 1, buds_model_callback, ctx);
if(!found && cfg->data.buds.model == buds_models[i].value) { if(!found && _cfg->mode == ProtocolModeValue &&
cfg->data.buds.model == buds_models[i].value) {
found = true; found = true;
selected = i + 1; selected = i + 1;
} }
} }
submenu_add_item(submenu, "Custom", buds_models_count + 1, buds_model_callback, ctx); submenu_add_item(submenu, "Custom", buds_models_count + 1, buds_model_callback, ctx);
if(!found) { if(!found && _cfg->mode == ProtocolModeValue) {
found = true;
selected = buds_models_count + 1; selected = buds_models_count + 1;
} }
@@ -384,7 +409,9 @@ void scene_easysetup_buds_model_on_exit(void* _ctx) {
static void buds_model_custom_callback(void* _ctx) { static void buds_model_custom_callback(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
EasysetupCfg* cfg = &_cfg->specific.easysetup;
_cfg->mode = ProtocolModeValue;
cfg->data.buds.model = cfg->data.buds.model =
(ctx->byte_store[0] << 0x10) + (ctx->byte_store[1] << 0x08) + (ctx->byte_store[2] << 0x00); (ctx->byte_store[0] << 0x10) + (ctx->byte_store[1] << 0x08) + (ctx->byte_store[2] << 0x00);
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
@@ -392,7 +419,8 @@ static void buds_model_custom_callback(void* _ctx) {
} }
void scene_easysetup_buds_model_custom_on_enter(void* _ctx) { void scene_easysetup_buds_model_custom_on_enter(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
EasysetupCfg* cfg = &_cfg->specific.easysetup;
ByteInput* byte_input = ctx->byte_input; ByteInput* byte_input = ctx->byte_input;
byte_input_set_header_text(byte_input, "Enter custom Model Code"); byte_input_set_header_text(byte_input, "Enter custom Model Code");
@@ -417,16 +445,18 @@ void scene_easysetup_buds_model_custom_on_exit(void* _ctx) {
static void watch_model_callback(void* _ctx, uint32_t index) { static void watch_model_callback(void* _ctx, uint32_t index) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
EasysetupCfg* cfg = &_cfg->specific.easysetup;
switch(index) { switch(index) {
case 0: case 0:
cfg->data.watch.model = 0x00; _cfg->mode = ProtocolModeRandom;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
break; break;
case watch_models_count + 1: case watch_models_count + 1:
scene_manager_next_scene(ctx->scene_manager, SceneEasysetupWatchModelCustom); scene_manager_next_scene(ctx->scene_manager, SceneEasysetupWatchModelCustom);
break; break;
default: default:
_cfg->mode = ProtocolModeValue;
cfg->data.watch.model = watch_models[index - 1].value; cfg->data.watch.model = watch_models[index - 1].value;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
break; break;
@@ -434,27 +464,28 @@ static void watch_model_callback(void* _ctx, uint32_t index) {
} }
void scene_easysetup_watch_model_on_enter(void* _ctx) { void scene_easysetup_watch_model_on_enter(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
EasysetupCfg* cfg = &_cfg->specific.easysetup;
Submenu* submenu = ctx->submenu; Submenu* submenu = ctx->submenu;
uint32_t selected = 0; uint32_t selected = 0;
bool found = false;
submenu_reset(submenu); submenu_reset(submenu);
submenu_add_item(submenu, "Random", 0, watch_model_callback, ctx); submenu_add_item(submenu, "Random", 0, watch_model_callback, ctx);
if(cfg->data.watch.model == 0x00) { if(_cfg->mode == ProtocolModeRandom) {
found = true;
selected = 0; selected = 0;
} }
bool found = false;
for(uint8_t i = 0; i < watch_models_count; i++) { for(uint8_t i = 0; i < watch_models_count; i++) {
submenu_add_item(submenu, watch_models[i].name, i + 1, watch_model_callback, ctx); submenu_add_item(submenu, watch_models[i].name, i + 1, watch_model_callback, ctx);
if(!found && cfg->data.watch.model == watch_models[i].value) { if(!found && _cfg->mode == ProtocolModeValue &&
cfg->data.watch.model == watch_models[i].value) {
found = true; found = true;
selected = i + 1; selected = i + 1;
} }
} }
submenu_add_item(submenu, "Custom", watch_models_count + 1, watch_model_callback, ctx); submenu_add_item(submenu, "Custom", watch_models_count + 1, watch_model_callback, ctx);
if(!found) { if(!found && _cfg->mode == ProtocolModeValue) {
found = true;
selected = watch_models_count + 1; selected = watch_models_count + 1;
} }
@@ -473,14 +504,17 @@ void scene_easysetup_watch_model_on_exit(void* _ctx) {
static void watch_model_custom_callback(void* _ctx) { static void watch_model_custom_callback(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
EasysetupCfg* cfg = &_cfg->specific.easysetup;
_cfg->mode = ProtocolModeValue;
cfg->data.watch.model = (ctx->byte_store[0] << 0x00); cfg->data.watch.model = (ctx->byte_store[0] << 0x00);
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
} }
void scene_easysetup_watch_model_custom_on_enter(void* _ctx) { void scene_easysetup_watch_model_custom_on_enter(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
EasysetupCfg* cfg = &_cfg->specific.easysetup;
ByteInput* byte_input = ctx->byte_input; ByteInput* byte_input = ctx->byte_input;
byte_input_set_header_text(byte_input, "Enter custom Model Code"); byte_input_set_header_text(byte_input, "Enter custom Model Code");

View File

@@ -51,14 +51,18 @@ static const char* get_name(const ProtocolCfg* _cfg) {
return "FastPair"; return "FastPair";
} }
static void make_packet(uint8_t* _size, uint8_t** _packet, const ProtocolCfg* _cfg) { static void make_packet(uint8_t* _size, uint8_t** _packet, ProtocolCfg* _cfg) {
const FastpairCfg* cfg = _cfg ? &_cfg->fastpair : NULL; FastpairCfg* cfg = _cfg ? &_cfg->specific.fastpair : NULL;
uint32_t model; uint32_t model;
if(cfg && cfg->model != 0x000000) { switch(cfg ? _cfg->mode : ProtocolModeRandom) {
model = cfg->model; case ProtocolModeRandom:
} else { default:
model = models[rand() % models_count].value; model = models[rand() % models_count].value;
break;
case ProtocolModeValue:
model = cfg->model;
break;
} }
uint8_t size = 14; uint8_t size = 14;
@@ -107,30 +111,36 @@ static void config_callback(void* _ctx, uint32_t index) {
} }
} }
static void model_changed(VariableItem* item) { static void model_changed(VariableItem* item) {
FastpairCfg* cfg = variable_item_get_context(item); ProtocolCfg* _cfg = variable_item_get_context(item);
FastpairCfg* cfg = &_cfg->specific.fastpair;
uint8_t index = variable_item_get_current_value_index(item); uint8_t index = variable_item_get_current_value_index(item);
if(index) { if(index) {
index--; index--;
_cfg->mode = ProtocolModeValue;
cfg->model = models[index].value; cfg->model = models[index].value;
variable_item_set_current_value_text(item, models[index].name); variable_item_set_current_value_text(item, models[index].name);
} else { } else {
cfg->model = 0x000000; _cfg->mode = ProtocolModeRandom;
variable_item_set_current_value_text(item, "Random"); variable_item_set_current_value_text(item, "Random");
} }
} }
static void extra_config(Ctx* ctx) { static void extra_config(Ctx* ctx) {
FastpairCfg* cfg = &ctx->attack->payload.cfg.fastpair; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
FastpairCfg* cfg = &_cfg->specific.fastpair;
VariableItemList* list = ctx->variable_item_list; VariableItemList* list = ctx->variable_item_list;
VariableItem* item; VariableItem* item;
size_t value_index; size_t value_index;
item = variable_item_list_add(list, "Model Code", models_count + 1, model_changed, cfg); item = variable_item_list_add(list, "Model Code", models_count + 1, model_changed, _cfg);
const char* model_name = NULL; const char* model_name = NULL;
char model_name_buf[9]; char model_name_buf[9];
if(cfg->model == 0x000000) { switch(_cfg->mode) {
case ProtocolModeRandom:
default:
model_name = "Random"; model_name = "Random";
value_index = 0; value_index = 0;
} else { break;
case ProtocolModeValue:
for(uint8_t i = 0; i < models_count; i++) { for(uint8_t i = 0; i < models_count; i++) {
if(cfg->model == models[i].value) { if(cfg->model == models[i].value) {
model_name = models[i].name; model_name = models[i].name;
@@ -143,6 +153,7 @@ static void extra_config(Ctx* ctx) {
model_name = model_name_buf; model_name = model_name_buf;
value_index = models_count + 1; value_index = models_count + 1;
} }
break;
} }
variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, model_name); variable_item_set_current_value_text(item, model_name);
@@ -167,16 +178,18 @@ const Protocol protocol_fastpair = {
static void model_callback(void* _ctx, uint32_t index) { static void model_callback(void* _ctx, uint32_t index) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
FastpairCfg* cfg = &ctx->attack->payload.cfg.fastpair; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
FastpairCfg* cfg = &_cfg->specific.fastpair;
switch(index) { switch(index) {
case 0: case 0:
cfg->model = 0x000000; _cfg->mode = ProtocolModeRandom;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
break; break;
case models_count + 1: case models_count + 1:
scene_manager_next_scene(ctx->scene_manager, SceneFastpairModelCustom); scene_manager_next_scene(ctx->scene_manager, SceneFastpairModelCustom);
break; break;
default: default:
_cfg->mode = ProtocolModeValue;
cfg->model = models[index - 1].value; cfg->model = models[index - 1].value;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
break; break;
@@ -184,27 +197,27 @@ static void model_callback(void* _ctx, uint32_t index) {
} }
void scene_fastpair_model_on_enter(void* _ctx) { void scene_fastpair_model_on_enter(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
FastpairCfg* cfg = &ctx->attack->payload.cfg.fastpair; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
FastpairCfg* cfg = &_cfg->specific.fastpair;
Submenu* submenu = ctx->submenu; Submenu* submenu = ctx->submenu;
uint32_t selected = 0; uint32_t selected = 0;
bool found = false;
submenu_reset(submenu); submenu_reset(submenu);
submenu_add_item(submenu, "Random", 0, model_callback, ctx); submenu_add_item(submenu, "Random", 0, model_callback, ctx);
if(cfg->model == 0x000000) { if(_cfg->mode == ProtocolModeRandom) {
found = true;
selected = 0; selected = 0;
} }
bool found = false;
for(uint8_t i = 0; i < models_count; i++) { for(uint8_t i = 0; i < models_count; i++) {
submenu_add_item(submenu, models[i].name, i + 1, model_callback, ctx); submenu_add_item(submenu, models[i].name, i + 1, model_callback, ctx);
if(!found && cfg->model == models[i].value) { if(!found && _cfg->mode == ProtocolModeValue && cfg->model == models[i].value) {
found = true; found = true;
selected = i + 1; selected = i + 1;
} }
} }
submenu_add_item(submenu, "Custom", models_count + 1, model_callback, ctx); submenu_add_item(submenu, "Custom", models_count + 1, model_callback, ctx);
if(!found) { if(!found && _cfg->mode == ProtocolModeValue) {
found = true;
selected = models_count + 1; selected = models_count + 1;
} }
@@ -223,7 +236,9 @@ void scene_fastpair_model_on_exit(void* _ctx) {
static void model_custom_callback(void* _ctx) { static void model_custom_callback(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
FastpairCfg* cfg = &ctx->attack->payload.cfg.fastpair; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
FastpairCfg* cfg = &_cfg->specific.fastpair;
_cfg->mode = ProtocolModeValue;
cfg->model = cfg->model =
(ctx->byte_store[0] << 0x10) + (ctx->byte_store[1] << 0x08) + (ctx->byte_store[2] << 0x00); (ctx->byte_store[0] << 0x10) + (ctx->byte_store[1] << 0x08) + (ctx->byte_store[2] << 0x00);
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
@@ -231,7 +246,8 @@ static void model_custom_callback(void* _ctx) {
} }
void scene_fastpair_model_custom_on_enter(void* _ctx) { void scene_fastpair_model_custom_on_enter(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
FastpairCfg* cfg = &ctx->attack->payload.cfg.fastpair; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
FastpairCfg* cfg = &_cfg->specific.fastpair;
ByteInput* byte_input = ctx->byte_input; ByteInput* byte_input = ctx->byte_input;
byte_input_set_header_text(byte_input, "Enter custom Model Code"); byte_input_set_header_text(byte_input, "Enter custom Model Code");

View File

@@ -4,18 +4,6 @@
// Hacked together by @Willy-JL and @Spooks4576 // Hacked together by @Willy-JL and @Spooks4576
// Documentation at https://learn.microsoft.com/en-us/windows-hardware/design/component-guidelines/bluetooth-swift-pair // Documentation at https://learn.microsoft.com/en-us/windows-hardware/design/component-guidelines/bluetooth-swift-pair
static const char* get_name(const ProtocolCfg* _cfg) {
UNUSED(_cfg);
return "SwiftPair";
}
static void make_packet(uint8_t* _size, uint8_t** _packet, const ProtocolCfg* _cfg) {
const SwiftpairCfg* cfg = _cfg ? &_cfg->swiftpair : NULL;
const char* name;
if(cfg && cfg->name[0] != '\0') {
name = cfg->name;
} else {
const char* names[] = { const char* names[] = {
"Assquach💦", "Assquach💦",
"Flipper 🐬", "Flipper 🐬",
@@ -24,7 +12,25 @@ static void make_packet(uint8_t* _size, uint8_t** _packet, const ProtocolCfg* _c
"👉👌", "👉👌",
"🔵🦷", "🔵🦷",
}; };
name = names[rand() % COUNT_OF(names)]; const uint8_t names_count = COUNT_OF(names);
static const char* get_name(const ProtocolCfg* _cfg) {
UNUSED(_cfg);
return "SwiftPair";
}
static void make_packet(uint8_t* _size, uint8_t** _packet, ProtocolCfg* _cfg) {
SwiftpairCfg* cfg = _cfg ? &_cfg->specific.swiftpair : NULL;
const char* name;
switch(cfg ? _cfg->mode : ProtocolModeRandom) {
case ProtocolModeRandom:
default:
name = names[rand() % names_count];
break;
case ProtocolModeValue:
name = cfg->name;
break;
} }
uint8_t name_len = strlen(name); uint8_t name_len = strlen(name);
@@ -67,12 +73,14 @@ static void config_callback(void* _ctx, uint32_t index) {
} }
} }
static void extra_config(Ctx* ctx) { static void extra_config(Ctx* ctx) {
SwiftpairCfg* cfg = &ctx->attack->payload.cfg.swiftpair; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
SwiftpairCfg* cfg = &_cfg->specific.swiftpair;
VariableItemList* list = ctx->variable_item_list; VariableItemList* list = ctx->variable_item_list;
VariableItem* item; VariableItem* item;
item = variable_item_list_add(list, "Display Name", 0, NULL, NULL); item = variable_item_list_add(list, "Display Name", 0, NULL, NULL);
variable_item_set_current_value_text(item, cfg->name[0] != '\0' ? cfg->name : "Random"); variable_item_set_current_value_text(
item, _cfg->mode == ProtocolModeRandom ? "Random" : cfg->name);
variable_item_list_add(list, "Requires enabling SwiftPair", 0, NULL, NULL); variable_item_list_add(list, "Requires enabling SwiftPair", 0, NULL, NULL);
@@ -94,15 +102,18 @@ const Protocol protocol_swiftpair = {
static void name_callback(void* _ctx) { static void name_callback(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
_cfg->mode = ProtocolModeValue;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
} }
void scene_swiftpair_name_on_enter(void* _ctx) { void scene_swiftpair_name_on_enter(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
SwiftpairCfg* cfg = &ctx->attack->payload.cfg.swiftpair; ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
SwiftpairCfg* cfg = &_cfg->specific.swiftpair;
TextInput* text_input = ctx->text_input; TextInput* text_input = ctx->text_input;
text_input_reset(text_input); text_input_reset(text_input);
text_input_set_header_text(text_input, "Leave empty for random"); text_input_set_header_text(text_input, "Press back for random");
text_input_set_result_callback( text_input_set_result_callback(
text_input, name_callback, ctx, cfg->name, sizeof(cfg->name), true); text_input, name_callback, ctx, cfg->name, sizeof(cfg->name), true);
@@ -112,8 +123,11 @@ void scene_swiftpair_name_on_enter(void* _ctx) {
view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewTextInput); view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewTextInput);
} }
bool scene_swiftpair_name_on_event(void* _ctx, SceneManagerEvent event) { bool scene_swiftpair_name_on_event(void* _ctx, SceneManagerEvent event) {
UNUSED(_ctx); Ctx* ctx = _ctx;
UNUSED(event); ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
if(event.type == SceneManagerEventTypeBack) {
_cfg->mode = ProtocolModeRandom;
}
return false; return false;
} }
void scene_swiftpair_name_on_exit(void* _ctx) { void scene_swiftpair_name_on_exit(void* _ctx) {