Refactor payload config, dont need 2 structs

This commit is contained in:
Willy-JL
2023-10-25 21:43:26 +01:00
parent e4309dcb8a
commit f474e8c7ca
8 changed files with 273 additions and 276 deletions

View File

@@ -30,7 +30,7 @@ static Attack attacks[] = {
.payload =
{
.random_mac = false,
.cfg.specific.continuity =
.cfg.continuity =
{
.type = ContinuityTypeCustomCrash,
.data = {},
@@ -44,7 +44,7 @@ static Attack attacks[] = {
.payload =
{
.random_mac = false,
.cfg.specific.continuity =
.cfg.continuity =
{
.type = ContinuityTypeNearbyAction,
.data = {},
@@ -58,7 +58,7 @@ static Attack attacks[] = {
.payload =
{
.random_mac = false,
.cfg.specific.continuity =
.cfg.continuity =
{
.type = ContinuityTypeProximityPair,
.data = {},
@@ -72,7 +72,7 @@ static Attack attacks[] = {
.payload =
{
.random_mac = true,
.cfg.specific.fastpair = {},
.cfg.fastpair = {},
},
},
{
@@ -82,7 +82,7 @@ static Attack attacks[] = {
.payload =
{
.random_mac = true,
.cfg.specific.easysetup =
.cfg.easysetup =
{
.type = EasysetupTypeBuds,
.data = {},
@@ -96,7 +96,7 @@ static Attack attacks[] = {
.payload =
{
.random_mac = true,
.cfg.specific.easysetup =
.cfg.easysetup =
{
.type = EasysetupTypeWatch,
.data = {},
@@ -110,7 +110,7 @@ static Attack attacks[] = {
.payload =
{
.random_mac = true,
.cfg.specific.swiftpair = {},
.cfg.swiftpair = {},
},
},
};
@@ -171,18 +171,17 @@ static int32_t adv_thread(void* _ctx) {
uint8_t mac[GAP_MAC_ADDR_SIZE];
Payload* payload = &attacks[state->index].payload;
const Protocol* protocol = attacks[state->index].protocol;
ProtocolCfg* _cfg = &payload->cfg;
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) {
if(_cfg->mode == ProtocolModeBruteforce && _cfg->bruteforce.counter++ >= 10) {
_cfg->bruteforce.counter = 0;
_cfg->bruteforce.value =
(_cfg->bruteforce.value + 1) % (1 << (_cfg->bruteforce.size * 8));
if(payload->mode == PayloadModeBruteforce && payload->bruteforce.counter++ >= 10) {
payload->bruteforce.counter = 0;
payload->bruteforce.value =
(payload->bruteforce.value + 1) % (1 << (payload->bruteforce.size * 8));
}
protocol->make_packet(&size, &packet, &payload->cfg);
protocol->make_packet(&size, &packet, payload);
} else {
protocols[rand() % protocols_count]->make_packet(&size, &packet, NULL);
}
@@ -367,13 +366,13 @@ static void draw_callback(Canvas* canvas, void* _ctx) {
char str[32];
canvas_set_font(canvas, FontBatteryPercent);
if(payload->cfg.mode == ProtocolModeBruteforce) {
if(payload->mode == PayloadModeBruteforce) {
snprintf(
str,
sizeof(str),
"0x%0*lX",
payload->cfg.bruteforce.size * 2,
payload->cfg.bruteforce.value);
payload->bruteforce.size * 2,
payload->bruteforce.value);
} else {
snprintf(str, sizeof(str), "%ims", delays[state->delay]);
}
@@ -382,7 +381,7 @@ static void draw_callback(Canvas* canvas, void* _ctx) {
canvas_draw_icon(canvas, 119, 10, &I_SmallArrowDown_3x5);
canvas_set_font(canvas, FontBatteryPercent);
if(payload->cfg.mode == ProtocolModeBruteforce) {
if(payload->mode == PayloadModeBruteforce) {
canvas_draw_str_aligned(canvas, 64, 22, AlignCenter, AlignBottom, "Bruteforce");
if(delays[state->delay] < 100) {
snprintf(str, sizeof(str), "%ims>", delays[state->delay]);
@@ -403,7 +402,7 @@ static void draw_callback(Canvas* canvas, void* _ctx) {
"%02i/%02i: %s",
state->index + 1,
ATTACKS_COUNT,
protocol ? protocol->get_name(&payload->cfg) : "Everything AND");
protocol ? protocol->get_name(payload) : "Everything AND");
canvas_draw_str(canvas, 4 - (state->index < 19 ? 1 : 0), 22, str);
}
@@ -461,7 +460,7 @@ static bool input_callback(InputEvent* input, void* _ctx) {
consumed = true;
bool is_attack = state->index >= 0 && state->index <= ATTACKS_COUNT - 1;
ProtocolCfg* _cfg = is_attack ? &attacks[state->index].payload.cfg : NULL;
Payload* payload = is_attack ? &attacks[state->index].payload : NULL;
bool advertising = state->advertising;
switch(input->key) {
@@ -479,10 +478,10 @@ static bool input_callback(InputEvent* input, void* _ctx) {
break;
case InputKeyUp:
if(is_attack) {
if(_cfg->mode == ProtocolModeBruteforce) {
_cfg->bruteforce.counter = 0;
_cfg->bruteforce.value =
(_cfg->bruteforce.value + 1) % (1 << (_cfg->bruteforce.size * 8));
if(payload->mode == PayloadModeBruteforce) {
payload->bruteforce.counter = 0;
payload->bruteforce.value =
(payload->bruteforce.value + 1) % (1 << (payload->bruteforce.size * 8));
} else if(state->delay < COUNT_OF(delays) - 1) {
state->delay++;
if(advertising) start_blink(state);
@@ -491,10 +490,10 @@ static bool input_callback(InputEvent* input, void* _ctx) {
break;
case InputKeyDown:
if(is_attack) {
if(_cfg->mode == ProtocolModeBruteforce) {
_cfg->bruteforce.counter = 0;
_cfg->bruteforce.value =
(_cfg->bruteforce.value - 1) % (1 << (_cfg->bruteforce.size * 8));
if(payload->mode == PayloadModeBruteforce) {
payload->bruteforce.counter = 0;
payload->bruteforce.value =
(payload->bruteforce.value - 1) % (1 << (payload->bruteforce.size * 8));
} else if(state->delay > 0) {
state->delay--;
if(advertising) start_blink(state);
@@ -503,10 +502,11 @@ static bool input_callback(InputEvent* input, void* _ctx) {
break;
case InputKeyLeft:
if(input->type == InputTypeLong) {
state->ignore_bruteforce = _cfg ? (_cfg->mode != ProtocolModeBruteforce) : true;
state->ignore_bruteforce = payload ? (payload->mode != PayloadModeBruteforce) :
true;
}
if(input->type == InputTypeShort || !is_attack || state->ignore_bruteforce ||
_cfg->mode != ProtocolModeBruteforce) {
payload->mode != PayloadModeBruteforce) {
if(state->index > PAGE_MIN) {
if(advertising) toggle_adv(state);
state->index--;
@@ -520,7 +520,7 @@ static bool input_callback(InputEvent* input, void* _ctx) {
uint8_t size;
uint8_t* packet;
protocol->make_packet(&size, &packet, &payload->cfg);
protocol->make_packet(&size, &packet, payload);
furi_hal_bt_custom_adv_set(packet, size);
free(packet);
@@ -541,10 +541,11 @@ static bool input_callback(InputEvent* input, void* _ctx) {
break;
case InputKeyRight:
if(input->type == InputTypeLong) {
state->ignore_bruteforce = _cfg ? (_cfg->mode != ProtocolModeBruteforce) : true;
state->ignore_bruteforce = payload ? (payload->mode != PayloadModeBruteforce) :
true;
}
if(input->type == InputTypeShort || !is_attack || state->ignore_bruteforce ||
_cfg->mode != ProtocolModeBruteforce) {
payload->mode != PayloadModeBruteforce) {
if(state->index < PAGE_MAX) {
if(advertising) toggle_adv(state);
state->index++;

View File

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

View File

@@ -6,13 +6,14 @@
#include "swiftpair.h"
typedef enum {
ProtocolModeRandom,
ProtocolModeValue,
ProtocolModeBruteforce,
} ProtocolMode;
PayloadModeRandom,
PayloadModeValue,
PayloadModeBruteforce,
} PayloadMode;
struct ProtocolCfg {
ProtocolMode mode;
struct Payload {
bool random_mac;
PayloadMode mode;
struct {
uint8_t counter;
uint32_t value;
@@ -23,18 +24,13 @@ struct ProtocolCfg {
FastpairCfg fastpair;
EasysetupCfg easysetup;
SwiftpairCfg swiftpair;
} specific;
} cfg;
};
extern const Protocol* protocols[];
extern const size_t protocols_count;
typedef struct {
bool random_mac;
ProtocolCfg cfg;
} Payload;
struct Attack {
const char* title;
const char* text;

View File

@@ -71,8 +71,8 @@ static const char* type_names[ContinuityTypeCOUNT] = {
[ContinuityTypeNearbyInfo] = "Nearby Info",
[ContinuityTypeCustomCrash] = "Continuity Custom",
};
static const char* get_name(const ProtocolCfg* _cfg) {
const ContinuityCfg* cfg = &_cfg->specific.continuity;
static const char* get_name(const Payload* payload) {
const ContinuityCfg* cfg = &payload->cfg.continuity;
return type_names[cfg->type];
}
@@ -87,8 +87,8 @@ static uint8_t packet_sizes[ContinuityTypeCOUNT] = {
[ContinuityTypeNearbyInfo] = HEADER_LEN + 5,
[ContinuityTypeCustomCrash] = HEADER_LEN + 11,
};
static void make_packet(uint8_t* _size, uint8_t** _packet, ProtocolCfg* _cfg) {
ContinuityCfg* cfg = _cfg ? &_cfg->specific.continuity : NULL;
static void make_packet(uint8_t* _size, uint8_t** _packet, Payload* payload) {
ContinuityCfg* cfg = payload ? &payload->cfg.continuity : NULL;
ContinuityType type;
if(cfg && cfg->type != 0x00) {
@@ -139,16 +139,16 @@ static void make_packet(uint8_t* _size, uint8_t** _packet, ProtocolCfg* _cfg) {
case ContinuityTypeProximityPair: {
uint16_t model;
switch(cfg ? _cfg->mode : ProtocolModeRandom) {
case ProtocolModeRandom:
switch(payload ? payload->mode : PayloadModeRandom) {
case PayloadModeRandom:
default:
model = pp_models[rand() % pp_models_count].value;
break;
case ProtocolModeValue:
case PayloadModeValue:
model = cfg->data.proximity_pair.model;
break;
case ProtocolModeBruteforce:
model = cfg->data.proximity_pair.model = _cfg->bruteforce.value;
case PayloadModeBruteforce:
model = cfg->data.proximity_pair.model = payload->bruteforce.value;
break;
}
@@ -216,16 +216,16 @@ static void make_packet(uint8_t* _size, uint8_t** _packet, ProtocolCfg* _cfg) {
case ContinuityTypeNearbyAction: {
uint8_t action;
switch(cfg ? _cfg->mode : ProtocolModeRandom) {
case ProtocolModeRandom:
switch(payload ? payload->mode : PayloadModeRandom) {
case PayloadModeRandom:
default:
action = na_actions[rand() % na_actions_count].value;
break;
case ProtocolModeValue:
case PayloadModeValue:
action = cfg->data.nearby_action.action;
break;
case ProtocolModeBruteforce:
action = cfg->data.nearby_action.action = _cfg->bruteforce.value;
case PayloadModeBruteforce:
action = cfg->data.nearby_action.action = payload->bruteforce.value;
break;
}
@@ -307,8 +307,8 @@ enum {
};
static void config_callback(void* _ctx, uint32_t index) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &payload->cfg.continuity;
scene_manager_set_scene_state(ctx->scene_manager, SceneConfig, index);
switch(cfg->type) {
case ContinuityTypeProximityPair: {
@@ -356,22 +356,22 @@ static void config_callback(void* _ctx, uint32_t index) {
}
}
static void pp_model_changed(VariableItem* item) {
ProtocolCfg* _cfg = variable_item_get_context(item);
ContinuityCfg* cfg = &_cfg->specific.continuity;
Payload* payload = variable_item_get_context(item);
ContinuityCfg* cfg = &payload->cfg.continuity;
uint8_t index = variable_item_get_current_value_index(item);
if(index) {
index--;
_cfg->mode = ProtocolModeValue;
payload->mode = PayloadModeValue;
cfg->data.proximity_pair.model = pp_models[index].value;
variable_item_set_current_value_text(item, pp_models[index].name);
} else {
_cfg->mode = ProtocolModeRandom;
payload->mode = PayloadModeRandom;
variable_item_set_current_value_text(item, "Random");
}
}
static void pp_prefix_changed(VariableItem* item) {
ProtocolCfg* _cfg = variable_item_get_context(item);
ContinuityCfg* cfg = &_cfg->specific.continuity;
Payload* payload = variable_item_get_context(item);
ContinuityCfg* cfg = &payload->cfg.continuity;
uint8_t index = variable_item_get_current_value_index(item);
if(index) {
index--;
@@ -383,22 +383,22 @@ static void pp_prefix_changed(VariableItem* item) {
}
}
static void na_action_changed(VariableItem* item) {
ProtocolCfg* _cfg = variable_item_get_context(item);
ContinuityCfg* cfg = &_cfg->specific.continuity;
Payload* payload = variable_item_get_context(item);
ContinuityCfg* cfg = &payload->cfg.continuity;
uint8_t index = variable_item_get_current_value_index(item);
if(index) {
index--;
_cfg->mode = ProtocolModeValue;
payload->mode = PayloadModeValue;
cfg->data.nearby_action.action = na_actions[index].value;
variable_item_set_current_value_text(item, na_actions[index].name);
} else {
_cfg->mode = ProtocolModeRandom;
payload->mode = PayloadModeRandom;
variable_item_set_current_value_text(item, "Random");
}
}
static void extra_config(Ctx* ctx) {
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &payload->cfg.continuity;
VariableItemList* list = ctx->variable_item_list;
VariableItem* item;
size_t value_index;
@@ -406,16 +406,16 @@ static void extra_config(Ctx* ctx) {
switch(cfg->type) {
case ContinuityTypeProximityPair: {
item = 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, payload);
const char* model_name = NULL;
char model_name_buf[5];
switch(_cfg->mode) {
case ProtocolModeRandom:
switch(payload->mode) {
case PayloadModeRandom:
default:
model_name = "Random";
value_index = 0;
break;
case ProtocolModeValue:
case PayloadModeValue:
for(uint8_t i = 0; i < pp_models_count; i++) {
if(cfg->data.proximity_pair.model == pp_models[i].value) {
model_name = pp_models[i].name;
@@ -430,7 +430,7 @@ static void extra_config(Ctx* ctx) {
value_index = pp_models_count + 1;
}
break;
case ProtocolModeBruteforce:
case PayloadModeBruteforce:
model_name = "Bruteforce";
value_index = pp_models_count + 1;
break;
@@ -438,8 +438,8 @@ static void extra_config(Ctx* ctx) {
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, model_name);
item =
variable_item_list_add(list, "Prefix", pp_prefixes_count + 1, pp_prefix_changed, _cfg);
item = variable_item_list_add(
list, "Prefix", pp_prefixes_count + 1, pp_prefix_changed, payload);
const char* prefix_name = NULL;
char prefix_name_buf[3];
if(cfg->data.proximity_pair.prefix == 0x00) {
@@ -469,16 +469,16 @@ static void extra_config(Ctx* ctx) {
}
case ContinuityTypeNearbyAction: {
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, payload);
const char* action_name = NULL;
char action_name_buf[3];
switch(_cfg->mode) {
case ProtocolModeRandom:
switch(payload->mode) {
case PayloadModeRandom:
default:
action_name = "Random";
value_index = 0;
break;
case ProtocolModeValue:
case PayloadModeValue:
for(uint8_t i = 0; i < na_actions_count; i++) {
if(cfg->data.nearby_action.action == na_actions[i].value) {
action_name = na_actions[i].name;
@@ -496,7 +496,7 @@ static void extra_config(Ctx* ctx) {
value_index = na_actions_count + 1;
}
break;
case ProtocolModeBruteforce:
case PayloadModeBruteforce:
action_name = "Bruteforce";
value_index = na_actions_count + 1;
break;
@@ -539,8 +539,8 @@ static uint8_t config_counts[ContinuityTypeCOUNT] = {
[ContinuityTypeNearbyInfo] = 0,
[ContinuityTypeCustomCrash] = ConfigCcCOUNT - ConfigExtraStart - 1,
};
static uint8_t config_count(const ProtocolCfg* _cfg) {
const ContinuityCfg* cfg = &_cfg->specific.continuity;
static uint8_t config_count(const Payload* payload) {
const ContinuityCfg* cfg = &payload->cfg.continuity;
return config_counts[cfg->type];
}
@@ -554,25 +554,25 @@ const Protocol protocol_continuity = {
static void pp_model_callback(void* _ctx, uint32_t index) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &payload->cfg.continuity;
switch(index) {
case 0:
_cfg->mode = ProtocolModeRandom;
payload->mode = PayloadModeRandom;
scene_manager_previous_scene(ctx->scene_manager);
break;
case pp_models_count + 1:
scene_manager_next_scene(ctx->scene_manager, SceneContinuityPpModelCustom);
break;
case pp_models_count + 2:
_cfg->mode = ProtocolModeBruteforce;
_cfg->bruteforce.counter = 0;
_cfg->bruteforce.value = cfg->data.proximity_pair.model;
_cfg->bruteforce.size = 2;
payload->mode = PayloadModeBruteforce;
payload->bruteforce.counter = 0;
payload->bruteforce.value = cfg->data.proximity_pair.model;
payload->bruteforce.size = 2;
scene_manager_previous_scene(ctx->scene_manager);
break;
default:
_cfg->mode = ProtocolModeValue;
payload->mode = PayloadModeValue;
cfg->data.proximity_pair.model = pp_models[index - 1].value;
scene_manager_previous_scene(ctx->scene_manager);
break;
@@ -580,33 +580,33 @@ static void pp_model_callback(void* _ctx, uint32_t index) {
}
void scene_continuity_pp_model_on_enter(void* _ctx) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &payload->cfg.continuity;
Submenu* submenu = ctx->submenu;
uint32_t selected = 0;
submenu_reset(submenu);
submenu_add_item(submenu, "Random", 0, pp_model_callback, ctx);
if(_cfg->mode == ProtocolModeRandom) {
if(payload->mode == PayloadModeRandom) {
selected = 0;
}
bool found = false;
for(uint8_t i = 0; i < pp_models_count; i++) {
submenu_add_item(submenu, pp_models[i].name, i + 1, pp_model_callback, ctx);
if(!found && _cfg->mode == ProtocolModeValue &&
if(!found && payload->mode == PayloadModeValue &&
cfg->data.proximity_pair.model == pp_models[i].value) {
found = true;
selected = i + 1;
}
}
submenu_add_item(submenu, "Custom", pp_models_count + 1, pp_model_callback, ctx);
if(!found && _cfg->mode == ProtocolModeValue) {
if(!found && payload->mode == PayloadModeValue) {
selected = pp_models_count + 1;
}
submenu_add_item(submenu, "Bruteforce", pp_models_count + 2, pp_model_callback, ctx);
if(_cfg->mode == ProtocolModeBruteforce) {
if(payload->mode == PayloadModeBruteforce) {
selected = pp_models_count + 2;
}
@@ -625,17 +625,17 @@ void scene_continuity_pp_model_on_exit(void* _ctx) {
static void pp_model_custom_callback(void* _ctx) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
_cfg->mode = ProtocolModeValue;
Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &payload->cfg.continuity;
payload->mode = PayloadModeValue;
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);
}
void scene_continuity_pp_model_custom_on_enter(void* _ctx) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &payload->cfg.continuity;
ByteInput* byte_input = ctx->byte_input;
byte_input_set_header_text(byte_input, "Enter custom Model Code");
@@ -659,8 +659,8 @@ void scene_continuity_pp_model_custom_on_exit(void* _ctx) {
static void pp_prefix_callback(void* _ctx, uint32_t index) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &payload->cfg.continuity;
switch(index) {
case 0:
cfg->data.proximity_pair.prefix = 0x00;
@@ -677,8 +677,8 @@ static void pp_prefix_callback(void* _ctx, uint32_t index) {
}
void scene_continuity_pp_prefix_on_enter(void* _ctx) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &payload->cfg.continuity;
Submenu* submenu = ctx->submenu;
uint32_t selected = 0;
bool found = false;
@@ -717,16 +717,16 @@ void scene_continuity_pp_prefix_on_exit(void* _ctx) {
static void pp_prefix_custom_callback(void* _ctx) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &payload->cfg.continuity;
cfg->data.proximity_pair.prefix = (ctx->byte_store[0] << 0x00);
scene_manager_previous_scene(ctx->scene_manager);
scene_manager_previous_scene(ctx->scene_manager);
}
void scene_continuity_pp_prefix_custom_on_enter(void* _ctx) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &payload->cfg.continuity;
ByteInput* byte_input = ctx->byte_input;
byte_input_set_header_text(byte_input, "Enter custom Prefix");
@@ -749,25 +749,25 @@ void scene_continuity_pp_prefix_custom_on_exit(void* _ctx) {
static void na_action_callback(void* _ctx, uint32_t index) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &payload->cfg.continuity;
switch(index) {
case 0:
_cfg->mode = ProtocolModeRandom;
payload->mode = PayloadModeRandom;
scene_manager_previous_scene(ctx->scene_manager);
break;
case na_actions_count + 1:
scene_manager_next_scene(ctx->scene_manager, SceneContinuityNaActionCustom);
break;
case na_actions_count + 2:
_cfg->mode = ProtocolModeBruteforce;
_cfg->bruteforce.counter = 0;
_cfg->bruteforce.value = cfg->data.nearby_action.action;
_cfg->bruteforce.size = 1;
payload->mode = PayloadModeBruteforce;
payload->bruteforce.counter = 0;
payload->bruteforce.value = cfg->data.nearby_action.action;
payload->bruteforce.size = 1;
scene_manager_previous_scene(ctx->scene_manager);
break;
default:
_cfg->mode = ProtocolModeValue;
payload->mode = PayloadModeValue;
cfg->data.nearby_action.action = na_actions[index - 1].value;
scene_manager_previous_scene(ctx->scene_manager);
break;
@@ -775,33 +775,33 @@ static void na_action_callback(void* _ctx, uint32_t index) {
}
void scene_continuity_na_action_on_enter(void* _ctx) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &payload->cfg.continuity;
Submenu* submenu = ctx->submenu;
uint32_t selected = 0;
submenu_reset(submenu);
submenu_add_item(submenu, "Random", 0, na_action_callback, ctx);
if(_cfg->mode == ProtocolModeRandom) {
if(payload->mode == PayloadModeRandom) {
selected = 0;
}
bool found = false;
for(uint8_t i = 0; i < na_actions_count; i++) {
submenu_add_item(submenu, na_actions[i].name, i + 1, na_action_callback, ctx);
if(!found && _cfg->mode == ProtocolModeValue &&
if(!found && payload->mode == PayloadModeValue &&
cfg->data.nearby_action.action == na_actions[i].value) {
found = true;
selected = i + 1;
}
}
submenu_add_item(submenu, "Custom", na_actions_count + 1, na_action_callback, ctx);
if(!found && _cfg->mode == ProtocolModeValue) {
if(!found && payload->mode == PayloadModeValue) {
selected = na_actions_count + 1;
}
submenu_add_item(submenu, "Bruteforce", na_actions_count + 2, na_action_callback, ctx);
if(_cfg->mode == ProtocolModeBruteforce) {
if(payload->mode == PayloadModeBruteforce) {
selected = na_actions_count + 2;
}
@@ -820,17 +820,17 @@ void scene_continuity_na_action_on_exit(void* _ctx) {
static void na_action_custom_callback(void* _ctx) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
_cfg->mode = ProtocolModeValue;
Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &payload->cfg.continuity;
payload->mode = PayloadModeValue;
cfg->data.nearby_action.action = (ctx->byte_store[0] << 0x00);
scene_manager_previous_scene(ctx->scene_manager);
scene_manager_previous_scene(ctx->scene_manager);
}
void scene_continuity_na_action_custom_on_enter(void* _ctx) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &payload->cfg.continuity;
ByteInput* byte_input = ctx->byte_input;
byte_input_set_header_text(byte_input, "Enter custom Action Type");
@@ -857,8 +857,8 @@ static void na_flags_callback(void* _ctx) {
}
void scene_continuity_na_flags_on_enter(void* _ctx) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &payload->cfg.continuity;
ByteInput* byte_input = ctx->byte_input;
byte_input_set_header_text(byte_input, "Press back for automatic");
@@ -879,7 +879,7 @@ bool scene_continuity_na_flags_on_event(void* _ctx, SceneManagerEvent event) {
}
void scene_continuity_na_flags_on_exit(void* _ctx) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
ContinuityCfg* cfg = &_cfg->specific.continuity;
Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &payload->cfg.continuity;
cfg->data.nearby_action.flags = (ctx->byte_store[0] << 0x00);
}

View File

@@ -68,8 +68,8 @@ static const char* type_names[EasysetupTypeCOUNT] = {
[EasysetupTypeBuds] = "EasySetup Buds",
[EasysetupTypeWatch] = "EasySetup Watch",
};
static const char* get_name(const ProtocolCfg* _cfg) {
const EasysetupCfg* cfg = &_cfg->specific.easysetup;
static const char* get_name(const Payload* payload) {
const EasysetupCfg* cfg = &payload->cfg.easysetup;
return type_names[cfg->type];
}
@@ -77,8 +77,8 @@ static uint8_t packet_sizes[EasysetupTypeCOUNT] = {
[EasysetupTypeBuds] = 31,
[EasysetupTypeWatch] = 15,
};
void make_packet(uint8_t* out_size, uint8_t** out_packet, ProtocolCfg* _cfg) {
EasysetupCfg* cfg = _cfg ? &_cfg->specific.easysetup : NULL;
void make_packet(uint8_t* out_size, uint8_t** out_packet, Payload* payload) {
EasysetupCfg* cfg = payload ? &payload->cfg.easysetup : NULL;
EasysetupType type;
if(cfg && cfg->type != 0x00) {
@@ -98,16 +98,16 @@ void make_packet(uint8_t* out_size, uint8_t** out_packet, ProtocolCfg* _cfg) {
switch(type) {
case EasysetupTypeBuds: {
uint32_t model;
switch(cfg ? _cfg->mode : ProtocolModeRandom) {
case ProtocolModeRandom:
switch(cfg ? payload->mode : PayloadModeRandom) {
case PayloadModeRandom:
default:
model = buds_models[rand() % buds_models_count].value;
break;
case ProtocolModeValue:
case PayloadModeValue:
model = cfg->data.buds.model;
break;
case ProtocolModeBruteforce:
model = cfg->data.buds.model = _cfg->bruteforce.value;
case PayloadModeBruteforce:
model = cfg->data.buds.model = payload->bruteforce.value;
break;
}
@@ -148,16 +148,16 @@ void make_packet(uint8_t* out_size, uint8_t** out_packet, ProtocolCfg* _cfg) {
}
case EasysetupTypeWatch: {
uint8_t model;
switch(cfg ? _cfg->mode : ProtocolModeRandom) {
case ProtocolModeRandom:
switch(cfg ? payload->mode : PayloadModeRandom) {
case PayloadModeRandom:
default:
model = watch_models[rand() % watch_models_count].value;
break;
case ProtocolModeValue:
case PayloadModeValue:
model = cfg->data.watch.model;
break;
case ProtocolModeBruteforce:
model = cfg->data.watch.model = _cfg->bruteforce.value;
case PayloadModeBruteforce:
model = cfg->data.watch.model = payload->bruteforce.value;
break;
}
@@ -199,8 +199,8 @@ enum {
};
static void config_callback(void* _ctx, uint32_t index) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
EasysetupCfg* cfg = &_cfg->specific.easysetup;
Payload* payload = &ctx->attack->payload;
EasysetupCfg* cfg = &payload->cfg.easysetup;
scene_manager_set_scene_state(ctx->scene_manager, SceneConfig, index);
switch(cfg->type) {
case EasysetupTypeBuds: {
@@ -233,36 +233,36 @@ static void config_callback(void* _ctx, uint32_t index) {
}
}
static void buds_model_changed(VariableItem* item) {
ProtocolCfg* _cfg = variable_item_get_context(item);
EasysetupCfg* cfg = &_cfg->specific.easysetup;
Payload* payload = variable_item_get_context(item);
EasysetupCfg* cfg = &payload->cfg.easysetup;
uint8_t index = variable_item_get_current_value_index(item);
if(index) {
index--;
_cfg->mode = ProtocolModeValue;
payload->mode = PayloadModeValue;
cfg->data.buds.model = buds_models[index].value;
variable_item_set_current_value_text(item, buds_models[index].name);
} else {
_cfg->mode = ProtocolModeRandom;
payload->mode = PayloadModeRandom;
variable_item_set_current_value_text(item, "Random");
}
}
static void watch_model_changed(VariableItem* item) {
ProtocolCfg* _cfg = variable_item_get_context(item);
EasysetupCfg* cfg = &_cfg->specific.easysetup;
Payload* payload = variable_item_get_context(item);
EasysetupCfg* cfg = &payload->cfg.easysetup;
uint8_t index = variable_item_get_current_value_index(item);
if(index) {
index--;
_cfg->mode = ProtocolModeValue;
payload->mode = PayloadModeValue;
cfg->data.watch.model = watch_models[index].value;
variable_item_set_current_value_text(item, watch_models[index].name);
} else {
_cfg->mode = ProtocolModeRandom;
payload->mode = PayloadModeRandom;
variable_item_set_current_value_text(item, "Random");
}
}
static void extra_config(Ctx* ctx) {
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
EasysetupCfg* cfg = &_cfg->specific.easysetup;
Payload* payload = &ctx->attack->payload;
EasysetupCfg* cfg = &payload->cfg.easysetup;
VariableItemList* list = ctx->variable_item_list;
VariableItem* item;
size_t value_index;
@@ -270,16 +270,16 @@ static void extra_config(Ctx* ctx) {
switch(cfg->type) {
case EasysetupTypeBuds: {
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, payload);
const char* model_name = NULL;
char model_name_buf[9];
switch(_cfg->mode) {
case ProtocolModeRandom:
switch(payload->mode) {
case PayloadModeRandom:
default:
model_name = "Random";
value_index = 0;
break;
case ProtocolModeValue:
case PayloadModeValue:
for(uint8_t i = 0; i < buds_models_count; i++) {
if(cfg->data.buds.model == buds_models[i].value) {
model_name = buds_models[i].name;
@@ -293,7 +293,7 @@ static void extra_config(Ctx* ctx) {
value_index = buds_models_count + 1;
}
break;
case ProtocolModeBruteforce:
case PayloadModeBruteforce:
model_name = "Bruteforce";
value_index = buds_models_count + 1;
break;
@@ -306,16 +306,16 @@ static void extra_config(Ctx* ctx) {
}
case EasysetupTypeWatch: {
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, payload);
const char* model_name = NULL;
char model_name_buf[3];
switch(_cfg->mode) {
case ProtocolModeRandom:
switch(payload->mode) {
case PayloadModeRandom:
default:
model_name = "Random";
value_index = 0;
break;
case ProtocolModeValue:
case PayloadModeValue:
for(uint8_t i = 0; i < watch_models_count; i++) {
if(cfg->data.watch.model == watch_models[i].value) {
model_name = watch_models[i].name;
@@ -329,7 +329,7 @@ static void extra_config(Ctx* ctx) {
value_index = watch_models_count + 1;
}
break;
case ProtocolModeBruteforce:
case PayloadModeBruteforce:
model_name = "Bruteforce";
value_index = watch_models_count + 1;
break;
@@ -349,8 +349,8 @@ static uint8_t config_counts[EasysetupTypeCOUNT] = {
[EasysetupTypeBuds] = ConfigBudsCOUNT - ConfigExtraStart - 1,
[EasysetupTypeWatch] = ConfigWatchCOUNT - ConfigExtraStart - 1,
};
static uint8_t config_count(const ProtocolCfg* _cfg) {
const EasysetupCfg* cfg = &_cfg->specific.easysetup;
static uint8_t config_count(const Payload* payload) {
const EasysetupCfg* cfg = &payload->cfg.easysetup;
return config_counts[cfg->type];
}
@@ -364,25 +364,25 @@ const Protocol protocol_easysetup = {
static void buds_model_callback(void* _ctx, uint32_t index) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
EasysetupCfg* cfg = &_cfg->specific.easysetup;
Payload* payload = &ctx->attack->payload;
EasysetupCfg* cfg = &payload->cfg.easysetup;
switch(index) {
case 0:
_cfg->mode = ProtocolModeRandom;
payload->mode = PayloadModeRandom;
scene_manager_previous_scene(ctx->scene_manager);
break;
case buds_models_count + 1:
scene_manager_next_scene(ctx->scene_manager, SceneEasysetupBudsModelCustom);
break;
case buds_models_count + 2:
_cfg->mode = ProtocolModeBruteforce;
_cfg->bruteforce.counter = 0;
_cfg->bruteforce.value = cfg->data.buds.model;
_cfg->bruteforce.size = 3;
payload->mode = PayloadModeBruteforce;
payload->bruteforce.counter = 0;
payload->bruteforce.value = cfg->data.buds.model;
payload->bruteforce.size = 3;
scene_manager_previous_scene(ctx->scene_manager);
break;
default:
_cfg->mode = ProtocolModeValue;
payload->mode = PayloadModeValue;
cfg->data.buds.model = buds_models[index - 1].value;
scene_manager_previous_scene(ctx->scene_manager);
break;
@@ -390,33 +390,33 @@ static void buds_model_callback(void* _ctx, uint32_t index) {
}
void scene_easysetup_buds_model_on_enter(void* _ctx) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
EasysetupCfg* cfg = &_cfg->specific.easysetup;
Payload* payload = &ctx->attack->payload;
EasysetupCfg* cfg = &payload->cfg.easysetup;
Submenu* submenu = ctx->submenu;
uint32_t selected = 0;
submenu_reset(submenu);
submenu_add_item(submenu, "Random", 0, buds_model_callback, ctx);
if(_cfg->mode == ProtocolModeRandom) {
if(payload->mode == PayloadModeRandom) {
selected = 0;
}
bool found = false;
for(uint8_t i = 0; i < buds_models_count; i++) {
submenu_add_item(submenu, buds_models[i].name, i + 1, buds_model_callback, ctx);
if(!found && _cfg->mode == ProtocolModeValue &&
if(!found && payload->mode == PayloadModeValue &&
cfg->data.buds.model == buds_models[i].value) {
found = true;
selected = i + 1;
}
}
submenu_add_item(submenu, "Custom", buds_models_count + 1, buds_model_callback, ctx);
if(!found && _cfg->mode == ProtocolModeValue) {
if(!found && payload->mode == PayloadModeValue) {
selected = buds_models_count + 1;
}
submenu_add_item(submenu, "Bruteforce", buds_models_count + 2, buds_model_callback, ctx);
if(_cfg->mode == ProtocolModeBruteforce) {
if(payload->mode == PayloadModeBruteforce) {
selected = buds_models_count + 2;
}
@@ -435,9 +435,9 @@ void scene_easysetup_buds_model_on_exit(void* _ctx) {
static void buds_model_custom_callback(void* _ctx) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
EasysetupCfg* cfg = &_cfg->specific.easysetup;
_cfg->mode = ProtocolModeValue;
Payload* payload = &ctx->attack->payload;
EasysetupCfg* cfg = &payload->cfg.easysetup;
payload->mode = PayloadModeValue;
cfg->data.buds.model =
(ctx->byte_store[0] << 0x10) + (ctx->byte_store[1] << 0x08) + (ctx->byte_store[2] << 0x00);
scene_manager_previous_scene(ctx->scene_manager);
@@ -445,8 +445,8 @@ static void buds_model_custom_callback(void* _ctx) {
}
void scene_easysetup_buds_model_custom_on_enter(void* _ctx) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
EasysetupCfg* cfg = &_cfg->specific.easysetup;
Payload* payload = &ctx->attack->payload;
EasysetupCfg* cfg = &payload->cfg.easysetup;
ByteInput* byte_input = ctx->byte_input;
byte_input_set_header_text(byte_input, "Enter custom Model Code");
@@ -471,25 +471,25 @@ void scene_easysetup_buds_model_custom_on_exit(void* _ctx) {
static void watch_model_callback(void* _ctx, uint32_t index) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
EasysetupCfg* cfg = &_cfg->specific.easysetup;
Payload* payload = &ctx->attack->payload;
EasysetupCfg* cfg = &payload->cfg.easysetup;
switch(index) {
case 0:
_cfg->mode = ProtocolModeRandom;
payload->mode = PayloadModeRandom;
scene_manager_previous_scene(ctx->scene_manager);
break;
case watch_models_count + 1:
scene_manager_next_scene(ctx->scene_manager, SceneEasysetupWatchModelCustom);
break;
case watch_models_count + 2:
_cfg->mode = ProtocolModeBruteforce;
_cfg->bruteforce.counter = 0;
_cfg->bruteforce.value = cfg->data.watch.model;
_cfg->bruteforce.size = 1;
payload->mode = PayloadModeBruteforce;
payload->bruteforce.counter = 0;
payload->bruteforce.value = cfg->data.watch.model;
payload->bruteforce.size = 1;
scene_manager_previous_scene(ctx->scene_manager);
break;
default:
_cfg->mode = ProtocolModeValue;
payload->mode = PayloadModeValue;
cfg->data.watch.model = watch_models[index - 1].value;
scene_manager_previous_scene(ctx->scene_manager);
break;
@@ -497,33 +497,33 @@ static void watch_model_callback(void* _ctx, uint32_t index) {
}
void scene_easysetup_watch_model_on_enter(void* _ctx) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
EasysetupCfg* cfg = &_cfg->specific.easysetup;
Payload* payload = &ctx->attack->payload;
EasysetupCfg* cfg = &payload->cfg.easysetup;
Submenu* submenu = ctx->submenu;
uint32_t selected = 0;
submenu_reset(submenu);
submenu_add_item(submenu, "Random", 0, watch_model_callback, ctx);
if(_cfg->mode == ProtocolModeRandom) {
if(payload->mode == PayloadModeRandom) {
selected = 0;
}
bool found = false;
for(uint8_t i = 0; i < watch_models_count; i++) {
submenu_add_item(submenu, watch_models[i].name, i + 1, watch_model_callback, ctx);
if(!found && _cfg->mode == ProtocolModeValue &&
if(!found && payload->mode == PayloadModeValue &&
cfg->data.watch.model == watch_models[i].value) {
found = true;
selected = i + 1;
}
}
submenu_add_item(submenu, "Custom", watch_models_count + 1, watch_model_callback, ctx);
if(!found && _cfg->mode == ProtocolModeValue) {
if(!found && payload->mode == PayloadModeValue) {
selected = watch_models_count + 1;
}
submenu_add_item(submenu, "Bruteforce", watch_models_count + 2, watch_model_callback, ctx);
if(_cfg->mode == ProtocolModeBruteforce) {
if(payload->mode == PayloadModeBruteforce) {
selected = watch_models_count + 2;
}
@@ -542,17 +542,17 @@ void scene_easysetup_watch_model_on_exit(void* _ctx) {
static void watch_model_custom_callback(void* _ctx) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
EasysetupCfg* cfg = &_cfg->specific.easysetup;
_cfg->mode = ProtocolModeValue;
Payload* payload = &ctx->attack->payload;
EasysetupCfg* cfg = &payload->cfg.easysetup;
payload->mode = PayloadModeValue;
cfg->data.watch.model = (ctx->byte_store[0] << 0x00);
scene_manager_previous_scene(ctx->scene_manager);
scene_manager_previous_scene(ctx->scene_manager);
}
void scene_easysetup_watch_model_custom_on_enter(void* _ctx) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
EasysetupCfg* cfg = &_cfg->specific.easysetup;
Payload* payload = &ctx->attack->payload;
EasysetupCfg* cfg = &payload->cfg.easysetup;
ByteInput* byte_input = ctx->byte_input;
byte_input_set_header_text(byte_input, "Enter custom Model Code");

View File

@@ -65,25 +65,25 @@ const struct {
};
const uint8_t models_count = COUNT_OF(models);
static const char* get_name(const ProtocolCfg* _cfg) {
UNUSED(_cfg);
static const char* get_name(const Payload* payload) {
UNUSED(payload);
return "FastPair";
}
static void make_packet(uint8_t* _size, uint8_t** _packet, ProtocolCfg* _cfg) {
FastpairCfg* cfg = _cfg ? &_cfg->specific.fastpair : NULL;
static void make_packet(uint8_t* _size, uint8_t** _packet, Payload* payload) {
FastpairCfg* cfg = payload ? &payload->cfg.fastpair : NULL;
uint32_t model;
switch(cfg ? _cfg->mode : ProtocolModeRandom) {
case ProtocolModeRandom:
switch(cfg ? payload->mode : PayloadModeRandom) {
case PayloadModeRandom:
default:
model = models[rand() % models_count].value;
break;
case ProtocolModeValue:
case PayloadModeValue:
model = cfg->model;
break;
case ProtocolModeBruteforce:
model = cfg->model = _cfg->bruteforce.value;
case PayloadModeBruteforce:
model = cfg->model = payload->bruteforce.value;
break;
}
@@ -133,36 +133,36 @@ static void config_callback(void* _ctx, uint32_t index) {
}
}
static void model_changed(VariableItem* item) {
ProtocolCfg* _cfg = variable_item_get_context(item);
FastpairCfg* cfg = &_cfg->specific.fastpair;
Payload* payload = variable_item_get_context(item);
FastpairCfg* cfg = &payload->cfg.fastpair;
uint8_t index = variable_item_get_current_value_index(item);
if(index) {
index--;
_cfg->mode = ProtocolModeValue;
payload->mode = PayloadModeValue;
cfg->model = models[index].value;
variable_item_set_current_value_text(item, models[index].name);
} else {
_cfg->mode = ProtocolModeRandom;
payload->mode = PayloadModeRandom;
variable_item_set_current_value_text(item, "Random");
}
}
static void extra_config(Ctx* ctx) {
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
FastpairCfg* cfg = &_cfg->specific.fastpair;
Payload* payload = &ctx->attack->payload;
FastpairCfg* cfg = &payload->cfg.fastpair;
VariableItemList* list = ctx->variable_item_list;
VariableItem* item;
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, payload);
const char* model_name = NULL;
char model_name_buf[9];
switch(_cfg->mode) {
case ProtocolModeRandom:
switch(payload->mode) {
case PayloadModeRandom:
default:
model_name = "Random";
value_index = 0;
break;
case ProtocolModeValue:
case PayloadModeValue:
for(uint8_t i = 0; i < models_count; i++) {
if(cfg->model == models[i].value) {
model_name = models[i].name;
@@ -176,7 +176,7 @@ static void extra_config(Ctx* ctx) {
value_index = models_count + 1;
}
break;
case ProtocolModeBruteforce:
case PayloadModeBruteforce:
model_name = "Bruteforce";
value_index = models_count + 1;
break;
@@ -189,8 +189,8 @@ static void extra_config(Ctx* ctx) {
variable_item_list_set_enter_callback(list, config_callback, ctx);
}
static uint8_t config_count(const ProtocolCfg* _cfg) {
UNUSED(_cfg);
static uint8_t config_count(const Payload* payload) {
UNUSED(payload);
return ConfigCOUNT - ConfigExtraStart - 1;
}
@@ -204,25 +204,25 @@ const Protocol protocol_fastpair = {
static void model_callback(void* _ctx, uint32_t index) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
FastpairCfg* cfg = &_cfg->specific.fastpair;
Payload* payload = &ctx->attack->payload;
FastpairCfg* cfg = &payload->cfg.fastpair;
switch(index) {
case 0:
_cfg->mode = ProtocolModeRandom;
payload->mode = PayloadModeRandom;
scene_manager_previous_scene(ctx->scene_manager);
break;
case models_count + 1:
scene_manager_next_scene(ctx->scene_manager, SceneFastpairModelCustom);
break;
case models_count + 2:
_cfg->mode = ProtocolModeBruteforce;
_cfg->bruteforce.counter = 0;
_cfg->bruteforce.value = cfg->model;
_cfg->bruteforce.size = 3;
payload->mode = PayloadModeBruteforce;
payload->bruteforce.counter = 0;
payload->bruteforce.value = cfg->model;
payload->bruteforce.size = 3;
scene_manager_previous_scene(ctx->scene_manager);
break;
default:
_cfg->mode = ProtocolModeValue;
payload->mode = PayloadModeValue;
cfg->model = models[index - 1].value;
scene_manager_previous_scene(ctx->scene_manager);
break;
@@ -230,32 +230,32 @@ static void model_callback(void* _ctx, uint32_t index) {
}
void scene_fastpair_model_on_enter(void* _ctx) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
FastpairCfg* cfg = &_cfg->specific.fastpair;
Payload* payload = &ctx->attack->payload;
FastpairCfg* cfg = &payload->cfg.fastpair;
Submenu* submenu = ctx->submenu;
uint32_t selected = 0;
submenu_reset(submenu);
submenu_add_item(submenu, "Random", 0, model_callback, ctx);
if(_cfg->mode == ProtocolModeRandom) {
if(payload->mode == PayloadModeRandom) {
selected = 0;
}
bool found = false;
for(uint8_t i = 0; i < models_count; i++) {
submenu_add_item(submenu, models[i].name, i + 1, model_callback, ctx);
if(!found && _cfg->mode == ProtocolModeValue && cfg->model == models[i].value) {
if(!found && payload->mode == PayloadModeValue && cfg->model == models[i].value) {
found = true;
selected = i + 1;
}
}
submenu_add_item(submenu, "Custom", models_count + 1, model_callback, ctx);
if(!found && _cfg->mode == ProtocolModeValue) {
if(!found && payload->mode == PayloadModeValue) {
selected = models_count + 1;
}
submenu_add_item(submenu, "Bruteforce", models_count + 2, model_callback, ctx);
if(_cfg->mode == ProtocolModeBruteforce) {
if(payload->mode == PayloadModeBruteforce) {
selected = models_count + 2;
}
@@ -274,9 +274,9 @@ void scene_fastpair_model_on_exit(void* _ctx) {
static void model_custom_callback(void* _ctx) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
FastpairCfg* cfg = &_cfg->specific.fastpair;
_cfg->mode = ProtocolModeValue;
Payload* payload = &ctx->attack->payload;
FastpairCfg* cfg = &payload->cfg.fastpair;
payload->mode = PayloadModeValue;
cfg->model =
(ctx->byte_store[0] << 0x10) + (ctx->byte_store[1] << 0x08) + (ctx->byte_store[2] << 0x00);
scene_manager_previous_scene(ctx->scene_manager);
@@ -284,8 +284,8 @@ static void model_custom_callback(void* _ctx) {
}
void scene_fastpair_model_custom_on_enter(void* _ctx) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
FastpairCfg* cfg = &_cfg->specific.fastpair;
Payload* payload = &ctx->attack->payload;
FastpairCfg* cfg = &payload->cfg.fastpair;
ByteInput* byte_input = ctx->byte_input;
byte_input_set_header_text(byte_input, "Enter custom Model Code");

View File

@@ -14,21 +14,21 @@ const char* names[] = {
};
const uint8_t names_count = COUNT_OF(names);
static const char* get_name(const ProtocolCfg* _cfg) {
UNUSED(_cfg);
static const char* get_name(const Payload* payload) {
UNUSED(payload);
return "SwiftPair";
}
static void make_packet(uint8_t* _size, uint8_t** _packet, ProtocolCfg* _cfg) {
SwiftpairCfg* cfg = _cfg ? &_cfg->specific.swiftpair : NULL;
static void make_packet(uint8_t* _size, uint8_t** _packet, Payload* payload) {
SwiftpairCfg* cfg = payload ? &payload->cfg.swiftpair : NULL;
const char* name;
switch(cfg ? _cfg->mode : ProtocolModeRandom) {
case ProtocolModeRandom:
switch(cfg ? payload->mode : PayloadModeRandom) {
case PayloadModeRandom:
default:
name = names[rand() % names_count];
break;
case ProtocolModeValue:
case PayloadModeValue:
name = cfg->name;
break;
}
@@ -73,22 +73,22 @@ static void config_callback(void* _ctx, uint32_t index) {
}
}
static void extra_config(Ctx* ctx) {
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
SwiftpairCfg* cfg = &_cfg->specific.swiftpair;
Payload* payload = &ctx->attack->payload;
SwiftpairCfg* cfg = &payload->cfg.swiftpair;
VariableItemList* list = ctx->variable_item_list;
VariableItem* item;
item = variable_item_list_add(list, "Display Name", 0, NULL, NULL);
variable_item_set_current_value_text(
item, _cfg->mode == ProtocolModeRandom ? "Random" : cfg->name);
item, payload->mode == PayloadModeRandom ? "Random" : cfg->name);
variable_item_list_add(list, "Requires enabling SwiftPair", 0, NULL, NULL);
variable_item_list_set_enter_callback(list, config_callback, ctx);
}
static uint8_t config_count(const ProtocolCfg* _cfg) {
UNUSED(_cfg);
static uint8_t config_count(const Payload* payload) {
UNUSED(payload);
return ConfigCOUNT - ConfigExtraStart - 1;
}
@@ -102,14 +102,14 @@ const Protocol protocol_swiftpair = {
static void name_callback(void* _ctx) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
_cfg->mode = ProtocolModeValue;
Payload* payload = &ctx->attack->payload;
payload->mode = PayloadModeValue;
scene_manager_previous_scene(ctx->scene_manager);
}
void scene_swiftpair_name_on_enter(void* _ctx) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
SwiftpairCfg* cfg = &_cfg->specific.swiftpair;
Payload* payload = &ctx->attack->payload;
SwiftpairCfg* cfg = &payload->cfg.swiftpair;
TextInput* text_input = ctx->text_input;
text_input_reset(text_input);
@@ -124,9 +124,9 @@ void scene_swiftpair_name_on_enter(void* _ctx) {
}
bool scene_swiftpair_name_on_event(void* _ctx, SceneManagerEvent event) {
Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
Payload* payload = &ctx->attack->payload;
if(event.type == SceneManagerEventTypeBack) {
_cfg->mode = ProtocolModeRandom;
payload->mode = PayloadModeRandom;
}
return false;
}

View File

@@ -19,7 +19,7 @@ static void config_callback(void* _ctx, uint32_t index) {
if(!ctx->attack->protocol) {
index--;
} else if(ctx->attack->protocol->config_count) {
uint8_t extra = ctx->attack->protocol->config_count(&ctx->attack->payload.cfg);
uint8_t extra = ctx->attack->protocol->config_count(&ctx->attack->payload);
if(index > extra) index -= extra;
}