Simplify bruteforce code --nobuild

This commit is contained in:
Willy-JL
2023-10-25 01:38:22 +01:00
parent ed364cbffd
commit 8eaff22935
5 changed files with 22 additions and 36 deletions

View File

@@ -162,11 +162,17 @@ static int32_t adv_thread(void* _ctx) {
uint8_t mac[GAP_MAC_ADDR_SIZE]; uint8_t mac[GAP_MAC_ADDR_SIZE];
Payload* payload = &attacks[state->index].payload; Payload* payload = &attacks[state->index].payload;
const Protocol* protocol = attacks[state->index].protocol; const Protocol* protocol = attacks[state->index].protocol;
ProtocolCfg* _cfg = &payload->cfg;
if(!payload->random_mac) furi_hal_random_fill_buf(mac, sizeof(mac)); if(!payload->random_mac) furi_hal_random_fill_buf(mac, sizeof(mac));
if(state->ctx.led_indicator) start_blink(state); if(state->ctx.led_indicator) start_blink(state);
while(state->advertising) { while(state->advertising) {
if(protocol) { 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));
}
protocol->make_packet(&size, &packet, &payload->cfg); protocol->make_packet(&size, &packet, &payload->cfg);
} else { } else {
protocols[rand() % protocols_count]->make_packet(&size, &packet, NULL); protocols[rand() % protocols_count]->make_packet(&size, &packet, NULL);
@@ -340,7 +346,7 @@ static void draw_callback(Canvas* canvas, void* _ctx) {
sizeof(str), sizeof(str),
"0x%0*lX", "0x%0*lX",
payload->cfg.bruteforce.size * 2, payload->cfg.bruteforce.size * 2,
payload->cfg.bruteforce.current); payload->cfg.bruteforce.value);
} else { } else {
snprintf(str, sizeof(str), "%ims", delays[state->delay]); snprintf(str, sizeof(str), "%ims", delays[state->delay]);
} }
@@ -431,9 +437,9 @@ static bool input_callback(InputEvent* input, void* _ctx) {
if(is_attack) { if(is_attack) {
ProtocolCfg* _cfg = &attacks[state->index].payload.cfg; ProtocolCfg* _cfg = &attacks[state->index].payload.cfg;
if(_cfg->mode == ProtocolModeBruteforce) { if(_cfg->mode == ProtocolModeBruteforce) {
_cfg->bruteforce.current =
(_cfg->bruteforce.current + 1) % (1 << (_cfg->bruteforce.size * 8));
_cfg->bruteforce.counter = 0; _cfg->bruteforce.counter = 0;
_cfg->bruteforce.value =
(_cfg->bruteforce.value + 1) % (1 << (_cfg->bruteforce.size * 8));
} else if(state->delay < COUNT_OF(delays) - 1) { } else if(state->delay < COUNT_OF(delays) - 1) {
state->delay++; state->delay++;
if(advertising) start_blink(state); if(advertising) start_blink(state);
@@ -444,9 +450,9 @@ static bool input_callback(InputEvent* input, void* _ctx) {
if(is_attack) { if(is_attack) {
ProtocolCfg* _cfg = &attacks[state->index].payload.cfg; ProtocolCfg* _cfg = &attacks[state->index].payload.cfg;
if(_cfg->mode == ProtocolModeBruteforce) { if(_cfg->mode == ProtocolModeBruteforce) {
_cfg->bruteforce.current =
(_cfg->bruteforce.current - 1) % (1 << (_cfg->bruteforce.size * 8));
_cfg->bruteforce.counter = 0; _cfg->bruteforce.counter = 0;
_cfg->bruteforce.value =
(_cfg->bruteforce.value - 1) % (1 << (_cfg->bruteforce.size * 8));
} else if(state->delay > 0) { } else if(state->delay > 0) {
state->delay--; state->delay--;
if(advertising) start_blink(state); if(advertising) start_blink(state);

View File

@@ -15,7 +15,7 @@ struct ProtocolCfg {
ProtocolMode mode; ProtocolMode mode;
struct { struct {
uint8_t counter; uint8_t counter;
uint32_t current; uint32_t value;
uint8_t size; uint8_t size;
} bruteforce; } bruteforce;
union { union {

View File

@@ -148,11 +148,7 @@ static void make_packet(uint8_t* _size, uint8_t** _packet, ProtocolCfg* _cfg) {
model = cfg->data.proximity_pair.model; model = cfg->data.proximity_pair.model;
break; break;
case ProtocolModeBruteforce: case ProtocolModeBruteforce:
if(_cfg->bruteforce.counter++ >= 10) { model = cfg->data.proximity_pair.model = _cfg->bruteforce.value;
_cfg->bruteforce.counter = 0;
if(_cfg->bruteforce.current++ >= 0xFFFF) _cfg->bruteforce.current = 0x0000;
}
model = cfg->data.proximity_pair.model = _cfg->bruteforce.current;
break; break;
} }
@@ -229,11 +225,7 @@ static void make_packet(uint8_t* _size, uint8_t** _packet, ProtocolCfg* _cfg) {
action = cfg->data.nearby_action.action; action = cfg->data.nearby_action.action;
break; break;
case ProtocolModeBruteforce: case ProtocolModeBruteforce:
if(_cfg->bruteforce.counter++ >= 10) { action = cfg->data.nearby_action.action = _cfg->bruteforce.value;
_cfg->bruteforce.counter = 0;
if(_cfg->bruteforce.current++ >= 0xFF) _cfg->bruteforce.current = 0x00;
}
action = cfg->data.nearby_action.action = _cfg->bruteforce.current;
break; break;
} }
@@ -575,7 +567,7 @@ static void pp_model_callback(void* _ctx, uint32_t index) {
case pp_models_count + 2: case pp_models_count + 2:
_cfg->mode = ProtocolModeBruteforce; _cfg->mode = ProtocolModeBruteforce;
_cfg->bruteforce.counter = 0; _cfg->bruteforce.counter = 0;
_cfg->bruteforce.current = cfg->data.proximity_pair.model; _cfg->bruteforce.value = cfg->data.proximity_pair.model;
_cfg->bruteforce.size = 2; _cfg->bruteforce.size = 2;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
break; break;
@@ -770,7 +762,7 @@ static void na_action_callback(void* _ctx, uint32_t index) {
case na_actions_count + 2: case na_actions_count + 2:
_cfg->mode = ProtocolModeBruteforce; _cfg->mode = ProtocolModeBruteforce;
_cfg->bruteforce.counter = 0; _cfg->bruteforce.counter = 0;
_cfg->bruteforce.current = cfg->data.nearby_action.action; _cfg->bruteforce.value = cfg->data.nearby_action.action;
_cfg->bruteforce.size = 1; _cfg->bruteforce.size = 1;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
break; break;

View File

@@ -107,11 +107,7 @@ void make_packet(uint8_t* out_size, uint8_t** out_packet, ProtocolCfg* _cfg) {
model = cfg->data.buds.model; model = cfg->data.buds.model;
break; break;
case ProtocolModeBruteforce: case ProtocolModeBruteforce:
if(_cfg->bruteforce.counter++ >= 10) { model = cfg->data.buds.model = _cfg->bruteforce.value;
_cfg->bruteforce.counter = 0;
if(_cfg->bruteforce.current++ >= 0xFFFFFF) _cfg->bruteforce.current = 0x000000;
}
model = cfg->data.buds.model = _cfg->bruteforce.current;
break; break;
} }
@@ -161,11 +157,7 @@ void make_packet(uint8_t* out_size, uint8_t** out_packet, ProtocolCfg* _cfg) {
model = cfg->data.watch.model; model = cfg->data.watch.model;
break; break;
case ProtocolModeBruteforce: case ProtocolModeBruteforce:
if(_cfg->bruteforce.counter++ >= 10) { model = cfg->data.watch.model = _cfg->bruteforce.value;
_cfg->bruteforce.counter = 0;
if(_cfg->bruteforce.current++ >= 0xFF) _cfg->bruteforce.current = 0x00;
}
model = cfg->data.watch.model = _cfg->bruteforce.current;
break; break;
} }
@@ -385,7 +377,7 @@ static void buds_model_callback(void* _ctx, uint32_t index) {
case buds_models_count + 2: case buds_models_count + 2:
_cfg->mode = ProtocolModeBruteforce; _cfg->mode = ProtocolModeBruteforce;
_cfg->bruteforce.counter = 0; _cfg->bruteforce.counter = 0;
_cfg->bruteforce.current = cfg->data.buds.model; _cfg->bruteforce.value = cfg->data.buds.model;
_cfg->bruteforce.size = 3; _cfg->bruteforce.size = 3;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
break; break;
@@ -492,7 +484,7 @@ static void watch_model_callback(void* _ctx, uint32_t index) {
case watch_models_count + 2: case watch_models_count + 2:
_cfg->mode = ProtocolModeBruteforce; _cfg->mode = ProtocolModeBruteforce;
_cfg->bruteforce.counter = 0; _cfg->bruteforce.counter = 0;
_cfg->bruteforce.current = cfg->data.watch.model; _cfg->bruteforce.value = cfg->data.watch.model;
_cfg->bruteforce.size = 1; _cfg->bruteforce.size = 1;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
break; break;

View File

@@ -83,11 +83,7 @@ static void make_packet(uint8_t* _size, uint8_t** _packet, ProtocolCfg* _cfg) {
model = cfg->model; model = cfg->model;
break; break;
case ProtocolModeBruteforce: case ProtocolModeBruteforce:
if(_cfg->bruteforce.counter++ >= 10) { model = cfg->model = _cfg->bruteforce.value;
_cfg->bruteforce.counter = 0;
if(_cfg->bruteforce.current++ >= 0xFFFFFF) _cfg->bruteforce.current = 0x000000;
}
model = cfg->model = _cfg->bruteforce.current;
break; break;
} }
@@ -221,7 +217,7 @@ static void model_callback(void* _ctx, uint32_t index) {
case models_count + 2: case models_count + 2:
_cfg->mode = ProtocolModeBruteforce; _cfg->mode = ProtocolModeBruteforce;
_cfg->bruteforce.counter = 0; _cfg->bruteforce.counter = 0;
_cfg->bruteforce.current = cfg->model; _cfg->bruteforce.value = cfg->model;
_cfg->bruteforce.size = 3; _cfg->bruteforce.size = 3;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
break; break;