Skip to content

Commit

Permalink
merging
Browse files Browse the repository at this point in the history
  • Loading branch information
derskythe committed Nov 23, 2022
1 parent 7b65217 commit ae27cfd
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 3 deletions.
2 changes: 1 addition & 1 deletion application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ App(
requires=["gui","dialogs"],
stack_size=2 * 1024,
order=11,
fap_icon="subbrute_10px.png",
fap_icon="images/subbrute_10px.png",
fap_category="Tools",
fap_icon_assets="images",
)
File renamed without changes
6 changes: 6 additions & 0 deletions scenes/subbrute_scene_load_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ void subbrute_scene_load_file_on_enter(void* context) {
dialog_file_browser_set_basic_options(&browser_options, SUBBRUTE_FILE_EXT, &I_sub1_10px);

SubBruteFileResult load_result = SubBruteFileResultUnknown;
// TODO: DELETE IT
#ifdef FURI_DEBUG
bool res = true;
furi_string_printf(load_path, "%s", "/ext/subghz/princeton.sub");
#else
bool res =
dialog_file_browser_show(instance->dialogs, load_path, app_folder, &browser_options);
#endif
#ifdef FURI_DEBUG
FURI_LOG_D(
TAG,
Expand Down
5 changes: 5 additions & 0 deletions scenes/subbrute_scene_load_select.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ bool subbrute_scene_load_select_on_event(void* context, SceneManagerEvent event)

if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubBruteCustomEventTypeIndexSelected) {
#ifdef FURI_DEBUG
view_dispatcher_stop(instance->view_dispatcher);
consumed = true;
#else
instance->device->load_index = subbrute_main_view_get_index(instance->view_main);
uint8_t extra_repeats = subbrute_main_view_get_extra_repeats(instance->view_main);

Expand All @@ -51,6 +55,7 @@ bool subbrute_scene_load_select_on_event(void* context, SceneManagerEvent event)
furi_crash("Invalid attack set!");
}
scene_manager_next_scene(instance->scene_manager, SubBruteSceneSetupAttack);
#endif
consumed = true;
}
} else if(event.type == SceneManagerEventTypeBack) {
Expand Down
5 changes: 5 additions & 0 deletions scenes/subbrute_scene_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ void subbrute_scene_start_on_enter(void* context) {
subbrute_main_view_set_index(view, instance->device->attack, false, NULL);

view_dispatcher_switch_to_view(instance->view_dispatcher, instance->current_view);

// TODO: DELETE IT
#ifdef FURI_DEBUG
scene_manager_next_scene(instance->scene_manager, SubBruteSceneLoadFile);
#endif
}

void subbrute_scene_start_on_exit(void* context) {
Expand Down
48 changes: 47 additions & 1 deletion subbrute_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ SubBruteDevice* subbrute_device_alloc() {
#ifdef FURI_DEBUG
subbrute_device_attack_set_default_values(instance, SubBruteAttackCAME12bit433);
#else
subbrute_device_attack_set_default_values(instance, SubBruteAttackCAME12bit433);
subbrute_device_attack_set_default_values(instance, SubBruteAttackLoadFile);
#endif
return instance;
}
Expand Down Expand Up @@ -340,6 +340,52 @@ uint8_t subbrute_device_load_from_file(SubBruteDevice* instance, const char* fil
#endif
}

flipper_format_rewind(fff_data_file);

uint8_t key_data[sizeof(uint64_t)] = {0};
if(!flipper_format_read_hex(fff_data_file, "Key", key_data, sizeof(uint64_t))) {
FURI_LOG_E(TAG, "Missing Key");
result = SubBruteFileResultMissingOrIncorrectKey;
break;
}
uint64_t data = 0;
for(uint8_t i = 0; i < sizeof(uint64_t); i++) {
data = (data << 8) | key_data[i];
}
instance->key_from_file = data;

uint16_t add_value = 0x0001;
uint8_t bit_index = 7;
bool two_bytes = true;

uint8_t p[8];
for(int i = 0; i < 8; i++) {
p[i] = (uint8_t)(instance->key_from_file >> 8 * (7 - i)) & 0xFF;
}
uint16_t num = two_bytes ? (p[bit_index - 1] << 8) | p[bit_index] : p[bit_index];
FURI_LOG_D(TAG, "num: 0x%04X", num);
num += add_value;
FURI_LOG_D(TAG, "num added: 0x%04X", num);
uint8_t low_byte = num & (0xff);
uint8_t high_byte = (num >> 8) & 0xff;

data = 0;
for(uint8_t i = 0; i < sizeof(uint64_t); i++) {
if(i == bit_index - 1 && two_bytes) {
data = (data << 8) | high_byte;
data = (data << 8) | low_byte;
i++;
} else if(i == bit_index) {
data = (data << 8) | low_byte;
} else {
data = (data << 8) | p[i];
}
}

furi_string_printf(temp_str, "Key: %lX", (uint32_t)(data & 0xFFFFFFFF));
FURI_LOG_D(
TAG, "H: 0x%02X, L: 0x%02X, %s", high_byte, low_byte, furi_string_get_cstr(temp_str));

// TE
if(!flipper_format_read_uint32(fff_data_file, "TE", &temp_data32, 1)) {
FURI_LOG_E(TAG, "Missing or incorrect TE");
Expand Down
2 changes: 2 additions & 0 deletions subbrute_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ typedef struct {
// Loaded info for attack type
char current_key[SUBBRUTE_PAYLOAD_SIZE];
char file_key[SUBBRUTE_MAX_LEN_NAME];
uint64_t key_from_file;
uint64_t current_key_from_file;
} SubBruteDevice;

SubBruteDevice* subbrute_device_alloc();
Expand Down
3 changes: 2 additions & 1 deletion subbrute_protocols.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,8 @@ void subbrute_protocol_file_generate_file(
uint8_t te,
uint8_t repeat,
uint8_t load_index,
const char* file_key) {
bool two_bytes,
uint64_t file_key) {
FuriString* candidate = furi_string_alloc();
char subbrute_payload_byte[8];
furi_string_set_str(candidate, file_key);
Expand Down

0 comments on commit ae27cfd

Please sign in to comment.