From ab86f58643be1a9d478c220c95447958cf72c194 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Fri, 2 Jun 2023 16:42:58 +0300 Subject: [PATCH 01/31] Fuzzers App: gui start --- .../external/pacs_fuzzer/application.fam | 19 ++++ applications/external/pacs_fuzzer/fuzzer.c | 78 +++++++++++++++ applications/external/pacs_fuzzer/fuzzer_i.h | 21 ++++ .../pacs_fuzzer/helpers/fuzzer_custom_event.h | 8 ++ .../pacs_fuzzer/helpers/fuzzer_types.h | 8 ++ .../external/pacs_fuzzer/rfid_10px.png | Bin 0 -> 2389 bytes .../pacs_fuzzer/scenes/fuzzer_scene.c | 30 ++++++ .../pacs_fuzzer/scenes/fuzzer_scene.h | 29 ++++++ .../pacs_fuzzer/scenes/fuzzer_scene_config.h | 1 + .../pacs_fuzzer/scenes/fuzzer_scene_main.c | 41 ++++++++ .../external/pacs_fuzzer/views/main_menu.c | 94 ++++++++++++++++++ .../external/pacs_fuzzer/views/main_menu.h | 26 +++++ 12 files changed, 355 insertions(+) create mode 100644 applications/external/pacs_fuzzer/application.fam create mode 100644 applications/external/pacs_fuzzer/fuzzer.c create mode 100644 applications/external/pacs_fuzzer/fuzzer_i.h create mode 100644 applications/external/pacs_fuzzer/helpers/fuzzer_custom_event.h create mode 100644 applications/external/pacs_fuzzer/helpers/fuzzer_types.h create mode 100644 applications/external/pacs_fuzzer/rfid_10px.png create mode 100644 applications/external/pacs_fuzzer/scenes/fuzzer_scene.c create mode 100644 applications/external/pacs_fuzzer/scenes/fuzzer_scene.h create mode 100644 applications/external/pacs_fuzzer/scenes/fuzzer_scene_config.h create mode 100644 applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c create mode 100644 applications/external/pacs_fuzzer/views/main_menu.c create mode 100644 applications/external/pacs_fuzzer/views/main_menu.h diff --git a/applications/external/pacs_fuzzer/application.fam b/applications/external/pacs_fuzzer/application.fam new file mode 100644 index 000000000..5e0aafd99 --- /dev/null +++ b/applications/external/pacs_fuzzer/application.fam @@ -0,0 +1,19 @@ +App( + appid="pacs_fuzzer", + name="Fuzzer Gui", + apptype=FlipperAppType.EXTERNAL, + entry_point="fuzzer_start", + requires=[ + "gui", + "storage", + "dialogs", + "input", + "notification", + ], + stack_size=2 * 1024, + order=15, + fap_icon="rfid_10px.png", + fap_category="Debug", + # fap_icon_assets="images", + # fap_icon_assets_symbol="fuzzer", +) diff --git a/applications/external/pacs_fuzzer/fuzzer.c b/applications/external/pacs_fuzzer/fuzzer.c new file mode 100644 index 000000000..ac0400ae5 --- /dev/null +++ b/applications/external/pacs_fuzzer/fuzzer.c @@ -0,0 +1,78 @@ +#include "fuzzer_i.h" +#include "helpers/fuzzer_types.h" + +static bool fuzzer_app_custom_event_callback(void* context, uint32_t event) { + furi_assert(context); + PacsFuzzerApp* app = context; + return scene_manager_handle_custom_event(app->scene_manager, event); +} + +static bool fuzzer_app_back_event_callback(void* context) { + furi_assert(context); + PacsFuzzerApp* app = context; + return scene_manager_handle_back_event(app->scene_manager); +} + +static void fuzzer_app_tick_event_callback(void* context) { + furi_assert(context); + PacsFuzzerApp* app = context; + scene_manager_handle_tick_event(app->scene_manager); +} + +PacsFuzzerApp* fuzzer_app_alloc() { + PacsFuzzerApp* app = malloc(sizeof(PacsFuzzerApp)); + + // GUI + app->gui = furi_record_open(RECORD_GUI); + + // View Dispatcher + app->view_dispatcher = view_dispatcher_alloc(); + + // Main view + app->main_view = fuzzer_view_main_alloc(); + view_dispatcher_add_view( + app->view_dispatcher, FuzzerViewIDMain, fuzzer_view_main_get_view(app->main_view)); + + app->scene_manager = scene_manager_alloc(&fuzzer_scene_handlers, app); + view_dispatcher_enable_queue(app->view_dispatcher); + + view_dispatcher_set_event_callback_context(app->view_dispatcher, app); + view_dispatcher_set_custom_event_callback( + app->view_dispatcher, fuzzer_app_custom_event_callback); + view_dispatcher_set_navigation_event_callback( + app->view_dispatcher, fuzzer_app_back_event_callback); + view_dispatcher_set_tick_event_callback( + app->view_dispatcher, fuzzer_app_tick_event_callback, 100); + + view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen); + + scene_manager_next_scene(app->scene_manager, FuzzerSceneMain); + + return app; +} + +void fuzzer_app_free(PacsFuzzerApp* app) { + furi_assert(app); + + // Remote view + view_dispatcher_remove_view(app->view_dispatcher, FuzzerViewIDMain); + fuzzer_view_main_free(app->main_view); + + scene_manager_free(app->scene_manager); + view_dispatcher_free(app->view_dispatcher); + + // Close records + furi_record_close(RECORD_GUI); + + free(app); +} + +int32_t fuzzer_start(void* p) { + UNUSED(p); + PacsFuzzerApp* fuzzer_app = fuzzer_app_alloc(); + + view_dispatcher_run(fuzzer_app->view_dispatcher); + + fuzzer_app_free(fuzzer_app); + return 0; +} \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/fuzzer_i.h b/applications/external/pacs_fuzzer/fuzzer_i.h new file mode 100644 index 000000000..f1ed6e738 --- /dev/null +++ b/applications/external/pacs_fuzzer/fuzzer_i.h @@ -0,0 +1,21 @@ +#pragma once + +#include +#include +#include +#include + +#include "scenes/fuzzer_scene.h" +#include "views/main_menu.h" + +#include "helpers/fuzzer_types.h" + +#include + +typedef struct { + Gui* gui; + ViewDispatcher* view_dispatcher; + SceneManager* scene_manager; + FuzzerViewMain* main_view; + +} PacsFuzzerApp; \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/helpers/fuzzer_custom_event.h b/applications/external/pacs_fuzzer/helpers/fuzzer_custom_event.h new file mode 100644 index 000000000..2ef8fce56 --- /dev/null +++ b/applications/external/pacs_fuzzer/helpers/fuzzer_custom_event.h @@ -0,0 +1,8 @@ +#pragma once + +typedef enum { + + // FuzzerCustomEvent + FuzzerCustomEventViewMainOk = 100, + FuzzerCustomEventViewMainBack, +} FuzzerCustomEvent; \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/helpers/fuzzer_types.h b/applications/external/pacs_fuzzer/helpers/fuzzer_types.h new file mode 100644 index 000000000..7b6f5a680 --- /dev/null +++ b/applications/external/pacs_fuzzer/helpers/fuzzer_types.h @@ -0,0 +1,8 @@ +#pragma once + +#include +#include + +typedef enum { + FuzzerViewIDMain, +} FuzzerViewID; \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/rfid_10px.png b/applications/external/pacs_fuzzer/rfid_10px.png new file mode 100644 index 0000000000000000000000000000000000000000..8097f477552333f695733baf98f72e52ae840206 GIT binary patch literal 2389 zcmcIleQXnD7{6^!#>U44<0gnZixCj6_tCqycdm@C?Y2%j%BZlR1g>}Qb?4f<$dYAbBp?=L>s9H44zi+G=z@ z$+GSR2r_^Bu5APL?}u;SJTN7D;oJYQXJbzy83Gd~}8wyVLJ?VRDO5w9Zzw8@g?;6Z|IeLEIrsbQiG#zUHZ2RGh zXD*aUd-8i4_PpADs0}HdxBi3jq2Z#Q^P&Dr^r?|WO%j;%cM#(P)0|Mc8; z{t8g`*A^{V)i?clE}f@2H&CjT}F< z?2jues!qd7PS)z04FoBfX?^mLy)Tp_$Rt&cG?`7IrJSH9?7UT9dorQHXauRON@~2& z3QRN#VzT0~4fhY&P+9cYRxu$Wr1?OLT-T+86?9@-1c8#I)9z+Pr-LUJp%g)pI7#A^ z8>2{$U^#~a&AepaJ-|V!`|Vrt9lHFc42XX!YK-a5tz}b zn0yjbjJa6^KQIJc)=XJdPz#Zds%@sn2DzpWkAYyf`V1Rfhy zjlu{PBk2f5aSnoGTnh;YM-b`I5OjjboBR#IOoSjf8osX&Rz+FroJeRW#03?@@6WtU}<<5`k-GmIOPTuus$(zJDPkQf=2B!Xdi7eP5vyx@MnDzsUZu=b~oE2;v- z$W@bzGC*KNw}3fBr-TVK?Z%=6L1S(pkqisLNim1EOqXHr@bS^87Ap}ViVmI>S)RcJ zh9WV*(*TPy(I`d}G$F90;3Qy6q1W>I)VQjLR1sDe;)?<&sd|Ek{*e=W4B(m)v)l~P z;VJ5514`GK>5mm)eP$Jx(Uj>pUa-9Gu?d#Q0Om>GmdB{x#CWFnceDTqI*$11FhiBh z4qgY|7_9WanhU=fd4q2spSnP~C5On1n8Y&u^S%9C@(-&evej?~Ro2+Su!z(GxDJJ~1-%>yfuE?__2!EG(Q-w?lmFd+!g0U&StM zdu5hu`a91J8fzAOad#fF`0WbM%BH;qRp;*CJ^0}3t1p(6l^kTQe)IdHQfq1l0}cMe I)$5-48`f?Vpa1{> literal 0 HcmV?d00001 diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene.c new file mode 100644 index 000000000..0fe0f558d --- /dev/null +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene.c @@ -0,0 +1,30 @@ +#include "fuzzer_scene.h" + +// Generate scene on_enter handlers array +#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter, +void (*const fuzzer_scene_on_enter_handlers[])(void*) = { +#include "fuzzer_scene_config.h" +}; +#undef ADD_SCENE + +// Generate scene on_event handlers array +#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event, +bool (*const fuzzer_scene_on_event_handlers[])(void* context, SceneManagerEvent event) = { +#include "fuzzer_scene_config.h" +}; +#undef ADD_SCENE + +// Generate scene on_exit handlers array +#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit, +void (*const fuzzer_scene_on_exit_handlers[])(void* context) = { +#include "fuzzer_scene_config.h" +}; +#undef ADD_SCENE + +// Initialize scene handlers configuration structure +const SceneManagerHandlers fuzzer_scene_handlers = { + .on_enter_handlers = fuzzer_scene_on_enter_handlers, + .on_event_handlers = fuzzer_scene_on_event_handlers, + .on_exit_handlers = fuzzer_scene_on_exit_handlers, + .scene_num = FuzzerSceneNum, +}; diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene.h b/applications/external/pacs_fuzzer/scenes/fuzzer_scene.h new file mode 100644 index 000000000..280654510 --- /dev/null +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene.h @@ -0,0 +1,29 @@ +#pragma once + +#include + +// Generate scene id and total number +#define ADD_SCENE(prefix, name, id) FuzzerScene##id, +typedef enum { +#include "fuzzer_scene_config.h" + FuzzerSceneNum, +} FuzzerScene; +#undef ADD_SCENE + +extern const SceneManagerHandlers fuzzer_scene_handlers; + +// Generate scene on_enter handlers declaration +#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*); +#include "fuzzer_scene_config.h" +#undef ADD_SCENE + +// Generate scene on_event handlers declaration +#define ADD_SCENE(prefix, name, id) \ + bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event); +#include "fuzzer_scene_config.h" +#undef ADD_SCENE + +// Generate scene on_exit handlers declaration +#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context); +#include "fuzzer_scene_config.h" +#undef ADD_SCENE diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_config.h b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_config.h new file mode 100644 index 000000000..7923cd83e --- /dev/null +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_config.h @@ -0,0 +1 @@ +ADD_SCENE(fuzzer, main, Main) \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c new file mode 100644 index 000000000..994867ed3 --- /dev/null +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c @@ -0,0 +1,41 @@ +#include "../fuzzer_i.h" +#include "../helpers/fuzzer_custom_event.h" + +void fuzzer_scene_main_callback(FuzzerCustomEvent event, void* context) { + furi_assert(context); + PacsFuzzerApp* app = context; + view_dispatcher_send_custom_event(app->view_dispatcher, event); +} + +void fuzzer_scene_main_on_enter(void* context) { + furi_assert(context); + PacsFuzzerApp* app = context; + + fuzzer_view_main_set_callback(app->main_view, fuzzer_scene_main_callback, app); + + view_dispatcher_switch_to_view(app->view_dispatcher, FuzzerViewIDMain); +} + +bool fuzzer_scene_main_on_event(void* context, SceneManagerEvent event) { + furi_assert(context); + PacsFuzzerApp* app = context; + bool consumed = false; + + if(event.type == SceneManagerEventTypeCustom) { + if(event.event == FuzzerCustomEventViewMainBack) { + if(!scene_manager_previous_scene(app->scene_manager)) { + scene_manager_stop(app->scene_manager); + view_dispatcher_stop(app->view_dispatcher); + } + consumed = true; + } + } + + return consumed; +} + +void fuzzer_scene_main_on_exit(void* context) { + // furi_assert(context); + // PacsFuzzerApp* app = context; + UNUSED(context); +} diff --git a/applications/external/pacs_fuzzer/views/main_menu.c b/applications/external/pacs_fuzzer/views/main_menu.c new file mode 100644 index 000000000..7db7d26f3 --- /dev/null +++ b/applications/external/pacs_fuzzer/views/main_menu.c @@ -0,0 +1,94 @@ +#include "main_menu.h" +#include "../fuzzer_i.h" + +#include +#include + +struct FuzzerViewMain { + View* view; + FuzzerViewMainCallback callback; + void* context; +}; + +typedef struct { + uint8_t proto_index; + uint8_t menu_index; +} FuzzerViewMainModel; + +void fuzzer_view_main_set_callback( + FuzzerViewMain* fuzzer_view_main, + FuzzerViewMainCallback callback, + void* context) { + furi_assert(fuzzer_view_main); + + fuzzer_view_main->callback = callback; + fuzzer_view_main->context = context; +} + +void fuzzer_view_main_draw(Canvas* canvas, FuzzerViewMainModel* model) { + UNUSED(canvas); + UNUSED(model); +} + +bool fuzzer_view_main_input(InputEvent* event, void* context) { + furi_assert(context); + FuzzerViewMain* fuzzer_view_main = context; + + if(event->key == InputKeyBack && + (event->type == InputTypeLong || event->type == InputTypeShort)) { + fuzzer_view_main->callback(FuzzerCustomEventViewMainBack, fuzzer_view_main->context); + return true; + } + + return true; +} + +void fuzzer_view_main_enter(void* context) { + furi_assert(context); +} + +void fuzzer_view_main_exit(void* context) { + furi_assert(context); +} + +FuzzerViewMain* fuzzer_view_main_alloc() { + FuzzerViewMain* fuzzer_view_main = malloc(sizeof(FuzzerViewMain)); + + // View allocation and configuration + fuzzer_view_main->view = view_alloc(); + view_allocate_model(fuzzer_view_main->view, ViewModelTypeLocking, sizeof(FuzzerViewMainModel)); + view_set_context(fuzzer_view_main->view, fuzzer_view_main); + view_set_draw_callback(fuzzer_view_main->view, (ViewDrawCallback)fuzzer_view_main_draw); + view_set_input_callback(fuzzer_view_main->view, fuzzer_view_main_input); + view_set_enter_callback(fuzzer_view_main->view, fuzzer_view_main_enter); + view_set_exit_callback(fuzzer_view_main->view, fuzzer_view_main_exit); + + with_view_model( + fuzzer_view_main->view, + FuzzerViewMainModel * model, + { + model->proto_index = 0; + model->menu_index = 0; + }, + true); + return fuzzer_view_main; +} + +void fuzzer_view_main_free(FuzzerViewMain* fuzzer_view_main) { + furi_assert(fuzzer_view_main); + + // with_view_model( + // fuzzer_view_main->view, + // FuzzerViewMainModel * model, + // { + + // }, + // true); + view_free(fuzzer_view_main->view); + free(fuzzer_view_main); +} + +View* fuzzer_view_main_get_view(FuzzerViewMain* fuzzer_view_main) { + furi_assert(fuzzer_view_main); + return fuzzer_view_main->view; +} \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/views/main_menu.h b/applications/external/pacs_fuzzer/views/main_menu.h new file mode 100644 index 000000000..17631807f --- /dev/null +++ b/applications/external/pacs_fuzzer/views/main_menu.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include "../helpers/fuzzer_custom_event.h" + +typedef enum { + FuzzerViewMainStateIdle, + FuzzerViewMainStateLoading, + FuzzerViewMainStateSending, + FuzzerViewMainStateOFF, +} FuzzerViewMainState; + +typedef struct FuzzerViewMain FuzzerViewMain; + +typedef void (*FuzzerViewMainCallback)(FuzzerCustomEvent event, void* context); + +void fuzzer_view_main_set_callback( + FuzzerViewMain* fuzzer_view_main, + FuzzerViewMainCallback callback, + void* context); + +FuzzerViewMain* fuzzer_view_main_alloc(); + +void fuzzer_view_main_free(FuzzerViewMain* fuzzer_view_main); + +View* fuzzer_view_main_get_view(FuzzerViewMain* fuzzer_view_main); \ No newline at end of file From 321f2d8d504e8362543f36e5c0337bd000b89eac Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Fri, 2 Jun 2023 17:48:21 +0300 Subject: [PATCH 02/31] Fuzzers app: main menu v0 --- .../pacs_fuzzer/helpers/fuzzer_types.h | 9 ++ .../external/pacs_fuzzer/helpers/protocol.c | 92 +++++++++++++++++++ .../external/pacs_fuzzer/helpers/protocol.h | 28 ++++++ .../external/pacs_fuzzer/views/main_menu.c | 83 ++++++++++++++++- 4 files changed, 210 insertions(+), 2 deletions(-) create mode 100644 applications/external/pacs_fuzzer/helpers/protocol.c create mode 100644 applications/external/pacs_fuzzer/helpers/protocol.h diff --git a/applications/external/pacs_fuzzer/helpers/fuzzer_types.h b/applications/external/pacs_fuzzer/helpers/fuzzer_types.h index 7b6f5a680..cfc9274d1 100644 --- a/applications/external/pacs_fuzzer/helpers/fuzzer_types.h +++ b/applications/external/pacs_fuzzer/helpers/fuzzer_types.h @@ -3,6 +3,15 @@ #include #include +// TODO replace it +typedef enum { + FuzzerMainMenuIndexDefaultValues = 0, + FuzzerMainMenuIndexLoadFile, + FuzzerMainMenuIndexLoadFileCustomUids, + + FuzzerMainMenuIndexMax, +} FuzzerMainMenuIndex; + typedef enum { FuzzerViewIDMain, } FuzzerViewID; \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/helpers/protocol.c b/applications/external/pacs_fuzzer/helpers/protocol.c new file mode 100644 index 000000000..072749179 --- /dev/null +++ b/applications/external/pacs_fuzzer/helpers/protocol.c @@ -0,0 +1,92 @@ +#include "protocol.h" + +#define DS1990_DATA_SIZE (8) +#define Metakom_DATA_SIZE (4) +#define Cyfral_DATA_SIZE (2) + +const uint8_t uid_list_ds1990[][DS1990_DATA_SIZE] = { + {0x01, 0xBE, 0x40, 0x11, 0x5A, 0x36, 0x00, 0xE1}, //– код универсального ключа, для Vizit + {0x01, 0xBE, 0x40, 0x11, 0x5A, 0x56, 0x00, 0xBB}, //- проверен работает + {0x01, 0xBE, 0x40, 0x11, 0x00, 0x00, 0x00, 0x77}, //- проверен работает + {0x01, 0xBE, 0x40, 0x11, 0x0A, 0x00, 0x00, 0x1D}, //- проверен работает Визит иногда КЕЙМАНЫ + {0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x2F}, //- проверен(метаком, цифрал, ВИЗИТ). + {0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x9B}, //- проверен Визит, Метакомы, КОНДОР + {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x14}, //???-Открываает 98% Метаком и некоторые Цифрал + {0x01, 0x00, 0x00, 0x00, 0x00, 0x90, 0x19, 0xFF}, //???-Отлично работает на старых домофонах + {0x01, 0x6F, 0x2E, 0x88, 0x8A, 0x00, 0x00, 0x4D}, //???-Открывать что-то должен + {0x01, 0x53, 0xD4, 0xFE, 0x00, 0x00, 0x7E, 0x88}, //???-Cyfral, Metakom + {0x01, 0x53, 0xD4, 0xFE, 0x00, 0x00, 0x00, 0x6F}, //???-домофоны Визит (Vizit) - до 99% + {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3D}, //???-домофоны Cyfral CCD-20 - до 70% + {0x01, 0x00, 0xBE, 0x11, 0xAA, 0x00, 0x00, 0xFB}, //???-домофоны Кейман (KEYMAN) + {0x01, 0x76, 0xB8, 0x2E, 0x0F, 0x00, 0x00, 0x5C}, //???-домофоны Форвард + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Null bytes + {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x14}, // Only FF + {0x01, 0x78, 0x00, 0x48, 0xFD, 0xFF, 0xFF, 0xD1}, // StarNew Uni5 + {0x01, 0xA9, 0xE4, 0x3C, 0x09, 0x00, 0x00, 0xE6}, // Eltis Uni +}; + +const uint8_t uid_list_metakom[][Metakom_DATA_SIZE] = { + {0x00, 0x00, 0x00, 0x00}, // Null bytes + {0xFF, 0xFF, 0xFF, 0xFF}, // Only FF + {0x11, 0x11, 0x11, 0x11}, // Only 11 + {0x22, 0x22, 0x22, 0x22}, // Only 22 + {0x33, 0x33, 0x33, 0x33}, // Only 33 + {0x44, 0x44, 0x44, 0x44}, // Only 44 + {0x55, 0x55, 0x55, 0x55}, // Only 55 + {0x66, 0x66, 0x66, 0x66}, // Only 66 + {0x77, 0x77, 0x77, 0x77}, // Only 77 + {0x88, 0x88, 0x88, 0x88}, // Only 88 + {0x99, 0x99, 0x99, 0x99}, // Only 99 + {0x12, 0x34, 0x56, 0x78}, // Incremental UID + {0x9A, 0x78, 0x56, 0x34}, // Decremental UID + {0x04, 0xd0, 0x9b, 0x0d}, // ?? + {0x34, 0x00, 0x29, 0x3d}, // ?? + {0x04, 0xdf, 0x00, 0x00}, // ?? + {0xCA, 0xCA, 0xCA, 0xCA}, // ?? +}; + +const uint8_t uid_list_cyfral[][Cyfral_DATA_SIZE] = { + {0x00, 0x00}, // Null bytes + {0xFF, 0xFF}, // Only FF + {0x11, 0x11}, // Only 11 + {0x22, 0x22}, // Only 22 + {0x33, 0x33}, // Only 33 + {0x44, 0x44}, // Only 44 + {0x55, 0x55}, // Only 55 + {0x66, 0x66}, // Only 66 + {0x77, 0x77}, // Only 77 + {0x88, 0x88}, // Only 88 + {0x99, 0x99}, // Only 99 + {0x12, 0x34}, // Incremental UID + {0x56, 0x34}, // Decremental UID + {0xCA, 0xCA}, // ?? + {0x8E, 0xC9}, // Elevator code + {0x6A, 0x50}, // VERY fresh code from smartkey +}; + +const FuzzerProtocol fuzzer_proto_items[] = { + [DS1990] = + { + .name = "DS1990", + .data_size = DS1990_DATA_SIZE, + .dict = + {.val = (const uint8_t*)&uid_list_ds1990, + .len = sizeof(uid_list_ds1990) / DS1990_DATA_SIZE}, + }, + [Metakom] = + { + .name = "Metakom", + .data_size = Metakom_DATA_SIZE, + .dict = + {.val = (const uint8_t*)&uid_list_metakom, + .len = sizeof(uid_list_metakom) / Metakom_DATA_SIZE}, + }, + [Cyfral] = + { + .name = "Cyfral", + .data_size = Cyfral_DATA_SIZE, + .dict = + {.val = (const uint8_t*)&uid_list_cyfral, + .len = sizeof(uid_list_cyfral) / Cyfral_DATA_SIZE}, + }, +}; \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/helpers/protocol.h b/applications/external/pacs_fuzzer/helpers/protocol.h new file mode 100644 index 000000000..c43e7f128 --- /dev/null +++ b/applications/external/pacs_fuzzer/helpers/protocol.h @@ -0,0 +1,28 @@ +#pragma once + +#include + +typedef enum { + DS1990, + Metakom, + Cyfral, + // Reserved + FuzzerProtoMax, +} FuzzerProtos; + +struct ProtoDict { + const uint8_t* val; + const uint8_t len; +}; + +typedef struct ProtoDict ProtoDict; + +struct FuzzerProtocol { + const char* name; + const uint8_t data_size; + const ProtoDict dict; +}; + +typedef struct FuzzerProtocol FuzzerProtocol; + +extern const FuzzerProtocol fuzzer_proto_items[]; \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/views/main_menu.c b/applications/external/pacs_fuzzer/views/main_menu.c index 7db7d26f3..2d55cc143 100644 --- a/applications/external/pacs_fuzzer/views/main_menu.c +++ b/applications/external/pacs_fuzzer/views/main_menu.c @@ -4,12 +4,21 @@ #include #include +#include "../helpers/protocol.h" + +const char* main_menu_items[FuzzerMainMenuIndexMax] = { + [FuzzerMainMenuIndexDefaultValues] = "Default Values", + [FuzzerMainMenuIndexLoadFile] = "Load File", + [FuzzerMainMenuIndexLoadFileCustomUids] = "Load UIDs from file", +}; + struct FuzzerViewMain { View* view; FuzzerViewMainCallback callback; void* context; }; +// TODO Furi string for procol name typedef struct { uint8_t proto_index; uint8_t menu_index; @@ -26,8 +35,30 @@ void fuzzer_view_main_set_callback( } void fuzzer_view_main_draw(Canvas* canvas, FuzzerViewMainModel* model) { - UNUSED(canvas); - UNUSED(model); + canvas_clear(canvas); + canvas_set_color(canvas, ColorBlack); + + if(model->menu_index > 0) { + canvas_set_font(canvas, FontSecondary); + canvas_draw_str_aligned( + canvas, 64, 24, AlignCenter, AlignTop, main_menu_items[model->menu_index - 1]); + } + + canvas_set_font(canvas, FontPrimary); + canvas_draw_str_aligned( + canvas, 64, 36, AlignCenter, AlignTop, main_menu_items[model->menu_index]); + + if(model->menu_index < FuzzerMainMenuIndexMax) { + canvas_set_font(canvas, FontSecondary); + canvas_draw_str_aligned( + canvas, 64, 48, AlignCenter, AlignTop, main_menu_items[model->menu_index + 1]); + } + + canvas_set_font(canvas, FontPrimary); + canvas_draw_str_aligned(canvas, 27, 4, AlignCenter, AlignTop, "<"); + canvas_draw_str_aligned( + canvas, 64, 4, AlignCenter, AlignTop, fuzzer_proto_items[model->proto_index].name); + canvas_draw_str_aligned(canvas, 101, 4, AlignCenter, AlignTop, ">"); } bool fuzzer_view_main_input(InputEvent* event, void* context) { @@ -38,6 +69,54 @@ bool fuzzer_view_main_input(InputEvent* event, void* context) { (event->type == InputTypeLong || event->type == InputTypeShort)) { fuzzer_view_main->callback(FuzzerCustomEventViewMainBack, fuzzer_view_main->context); return true; + } else if(event->key == InputKeyDown && event->type == InputTypeShort) { + with_view_model( + fuzzer_view_main->view, + FuzzerViewMainModel * model, + { + if(model->menu_index < (FuzzerMainMenuIndexMax - 1)) { + model->menu_index++; + } + }, + true); + return true; + } else if(event->key == InputKeyUp && event->type == InputTypeShort) { + with_view_model( + fuzzer_view_main->view, + FuzzerViewMainModel * model, + { + if(model->menu_index != 0) { + model->menu_index--; + } + }, + true); + return true; + } else if(event->key == InputKeyLeft && event->type == InputTypeShort) { + with_view_model( + fuzzer_view_main->view, + FuzzerViewMainModel * model, + { + if(model->proto_index != 0) { + model->proto_index--; + } else { + model->proto_index = (FuzzerProtoMax - 1); + } + }, + true); + return true; + } else if(event->key == InputKeyRight && event->type == InputTypeShort) { + with_view_model( + fuzzer_view_main->view, + FuzzerViewMainModel * model, + { + if(model->proto_index == (FuzzerProtoMax - 1)) { + model->proto_index = 0; + } else { + model->proto_index++; + } + }, + true); + return true; } return true; From e31a0c4d6d7d144b67e64e621e5bd5c70e3210e9 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Fri, 2 Jun 2023 20:33:28 +0300 Subject: [PATCH 03/31] Fuzzers App: attack gui --- applications/external/pacs_fuzzer/fuzzer.c | 12 + applications/external/pacs_fuzzer/fuzzer_i.h | 6 +- .../pacs_fuzzer/helpers/fuzzer_custom_event.h | 7 +- .../pacs_fuzzer/helpers/fuzzer_types.h | 13 +- .../external/pacs_fuzzer/helpers/gui_const.c | 7 + .../external/pacs_fuzzer/helpers/gui_const.h | 12 + .../external/pacs_fuzzer/helpers/protocol.h | 4 + .../pacs_fuzzer/scenes/fuzzer_scene_attack.c | 53 +++++ .../pacs_fuzzer/scenes/fuzzer_scene_config.h | 3 +- .../pacs_fuzzer/scenes/fuzzer_scene_main.c | 6 + .../external/pacs_fuzzer/views/attack.c | 212 ++++++++++++++++++ .../external/pacs_fuzzer/views/attack.h | 27 +++ .../external/pacs_fuzzer/views/main_menu.c | 98 ++++---- .../external/pacs_fuzzer/views/main_menu.h | 15 +- 14 files changed, 416 insertions(+), 59 deletions(-) create mode 100644 applications/external/pacs_fuzzer/helpers/gui_const.c create mode 100644 applications/external/pacs_fuzzer/helpers/gui_const.h create mode 100644 applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c create mode 100644 applications/external/pacs_fuzzer/views/attack.c create mode 100644 applications/external/pacs_fuzzer/views/attack.h diff --git a/applications/external/pacs_fuzzer/fuzzer.c b/applications/external/pacs_fuzzer/fuzzer.c index ac0400ae5..42c7d1e47 100644 --- a/applications/external/pacs_fuzzer/fuzzer.c +++ b/applications/external/pacs_fuzzer/fuzzer.c @@ -22,6 +22,9 @@ static void fuzzer_app_tick_event_callback(void* context) { PacsFuzzerApp* fuzzer_app_alloc() { PacsFuzzerApp* app = malloc(sizeof(PacsFuzzerApp)); + app->fuzzer_state.menu_index = 0; + app->fuzzer_state.proto_index = 0; + // GUI app->gui = furi_record_open(RECORD_GUI); @@ -33,6 +36,11 @@ PacsFuzzerApp* fuzzer_app_alloc() { view_dispatcher_add_view( app->view_dispatcher, FuzzerViewIDMain, fuzzer_view_main_get_view(app->main_view)); + // Attack view + app->attack_view = fuzzer_view_attack_alloc(); + view_dispatcher_add_view( + app->view_dispatcher, FuzzerViewIDAttack, fuzzer_view_attack_get_view(app->attack_view)); + app->scene_manager = scene_manager_alloc(&fuzzer_scene_handlers, app); view_dispatcher_enable_queue(app->view_dispatcher); @@ -58,6 +66,10 @@ void fuzzer_app_free(PacsFuzzerApp* app) { view_dispatcher_remove_view(app->view_dispatcher, FuzzerViewIDMain); fuzzer_view_main_free(app->main_view); + // Attack view + view_dispatcher_remove_view(app->view_dispatcher, FuzzerViewIDAttack); + fuzzer_view_attack_free(app->attack_view); + scene_manager_free(app->scene_manager); view_dispatcher_free(app->view_dispatcher); diff --git a/applications/external/pacs_fuzzer/fuzzer_i.h b/applications/external/pacs_fuzzer/fuzzer_i.h index f1ed6e738..8f84a558d 100644 --- a/applications/external/pacs_fuzzer/fuzzer_i.h +++ b/applications/external/pacs_fuzzer/fuzzer_i.h @@ -7,6 +7,7 @@ #include "scenes/fuzzer_scene.h" #include "views/main_menu.h" +#include "views/attack.h" #include "helpers/fuzzer_types.h" @@ -16,6 +17,9 @@ typedef struct { Gui* gui; ViewDispatcher* view_dispatcher; SceneManager* scene_manager; - FuzzerViewMain* main_view; + FuzzerViewMain* main_view; + FuzzerViewAttack* attack_view; + + FuzzerState fuzzer_state; } PacsFuzzerApp; \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/helpers/fuzzer_custom_event.h b/applications/external/pacs_fuzzer/helpers/fuzzer_custom_event.h index 2ef8fce56..189d72ef4 100644 --- a/applications/external/pacs_fuzzer/helpers/fuzzer_custom_event.h +++ b/applications/external/pacs_fuzzer/helpers/fuzzer_custom_event.h @@ -3,6 +3,9 @@ typedef enum { // FuzzerCustomEvent - FuzzerCustomEventViewMainOk = 100, - FuzzerCustomEventViewMainBack, + FuzzerCustomEventViewMainBack = 100, + FuzzerCustomEventViewMainOk, + + FuzzerCustomEventViewAttackBack, + FuzzerCustomEventViewAttackOk, } FuzzerCustomEvent; \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/helpers/fuzzer_types.h b/applications/external/pacs_fuzzer/helpers/fuzzer_types.h index cfc9274d1..55c64954c 100644 --- a/applications/external/pacs_fuzzer/helpers/fuzzer_types.h +++ b/applications/external/pacs_fuzzer/helpers/fuzzer_types.h @@ -3,15 +3,12 @@ #include #include -// TODO replace it -typedef enum { - FuzzerMainMenuIndexDefaultValues = 0, - FuzzerMainMenuIndexLoadFile, - FuzzerMainMenuIndexLoadFileCustomUids, - - FuzzerMainMenuIndexMax, -} FuzzerMainMenuIndex; +typedef struct { + uint8_t menu_index; + uint8_t proto_index; +} FuzzerState; typedef enum { FuzzerViewIDMain, + FuzzerViewIDAttack, } FuzzerViewID; \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/helpers/gui_const.c b/applications/external/pacs_fuzzer/helpers/gui_const.c new file mode 100644 index 000000000..79e31ad1b --- /dev/null +++ b/applications/external/pacs_fuzzer/helpers/gui_const.c @@ -0,0 +1,7 @@ +#include "gui_const.h" + +const char* fuzzer_attack_names[FuzzerMainMenuIndexMax] = { + [FuzzerMainMenuIndexDefaultValues] = "Default Values", + [FuzzerMainMenuIndexLoadFile] = "Load File", + [FuzzerMainMenuIndexLoadFileCustomUids] = "Load UIDs from file", +}; \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/helpers/gui_const.h b/applications/external/pacs_fuzzer/helpers/gui_const.h new file mode 100644 index 000000000..837322c2a --- /dev/null +++ b/applications/external/pacs_fuzzer/helpers/gui_const.h @@ -0,0 +1,12 @@ +#pragma once + +// TODO replace it +typedef enum { + FuzzerMainMenuIndexDefaultValues = 0, + FuzzerMainMenuIndexLoadFile, + FuzzerMainMenuIndexLoadFileCustomUids, + + FuzzerMainMenuIndexMax, +} FuzzerMainMenuIndex; + +extern const char* fuzzer_attack_names[]; \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/helpers/protocol.h b/applications/external/pacs_fuzzer/helpers/protocol.h index c43e7f128..aedeedd8d 100644 --- a/applications/external/pacs_fuzzer/helpers/protocol.h +++ b/applications/external/pacs_fuzzer/helpers/protocol.h @@ -2,6 +2,10 @@ #include +#define FUZZ_TIME_DELAY_MIN (4) +#define FUZZ_TIME_DELAY_DEFAULT (8) +#define FUZZ_TIME_DELAY_MAX (80) + typedef enum { DS1990, Metakom, diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c new file mode 100644 index 000000000..71d38650c --- /dev/null +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c @@ -0,0 +1,53 @@ +#include "../fuzzer_i.h" +#include "../helpers/fuzzer_custom_event.h" + +#include "../helpers/protocol.h" +#include "../helpers/gui_const.h" + +void fuzzer_scene_attack_callback(FuzzerCustomEvent event, void* context) { + furi_assert(context); + PacsFuzzerApp* app = context; + view_dispatcher_send_custom_event(app->view_dispatcher, event); +} + +void fuzzer_scene_attack_on_enter(void* context) { + furi_assert(context); + PacsFuzzerApp* app = context; + + fuzzer_view_attack_set_callback(app->attack_view, fuzzer_scene_attack_callback, app); + + FuzzerProtocol proto = fuzzer_proto_items[app->fuzzer_state.proto_index]; + + fuzzer_view_attack_reset_data( + app->attack_view, + fuzzer_attack_names[app->fuzzer_state.menu_index], + proto.name, + proto.data_size); + fuzzer_view_attack_set_uid(app->attack_view, &proto.dict.val[0], false); + + view_dispatcher_switch_to_view(app->view_dispatcher, FuzzerViewIDAttack); +} + +bool fuzzer_scene_attack_on_event(void* context, SceneManagerEvent event) { + furi_assert(context); + PacsFuzzerApp* app = context; + bool consumed = false; + + if(event.type == SceneManagerEventTypeCustom) { + if(event.event == FuzzerCustomEventViewAttackBack) { + if(!scene_manager_previous_scene(app->scene_manager)) { + scene_manager_stop(app->scene_manager); + view_dispatcher_stop(app->view_dispatcher); + } + consumed = true; + } + } + + return consumed; +} + +void fuzzer_scene_attack_on_exit(void* context) { + // furi_assert(context); + // PacsFuzzerApp* app = context; + UNUSED(context); +} diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_config.h b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_config.h index 7923cd83e..bccdbd9a5 100644 --- a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_config.h +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_config.h @@ -1 +1,2 @@ -ADD_SCENE(fuzzer, main, Main) \ No newline at end of file +ADD_SCENE(fuzzer, main, Main) +ADD_SCENE(fuzzer, attack, Attack) \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c index 994867ed3..812e063ab 100644 --- a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c @@ -13,6 +13,8 @@ void fuzzer_scene_main_on_enter(void* context) { fuzzer_view_main_set_callback(app->main_view, fuzzer_scene_main_callback, app); + fuzzer_view_main_update_data(app->main_view, app->fuzzer_state); + view_dispatcher_switch_to_view(app->view_dispatcher, FuzzerViewIDMain); } @@ -28,6 +30,10 @@ bool fuzzer_scene_main_on_event(void* context, SceneManagerEvent event) { view_dispatcher_stop(app->view_dispatcher); } consumed = true; + } else if(event.event == FuzzerCustomEventViewMainOk) { + fuzzer_view_main_get_state(app->main_view, &app->fuzzer_state); + scene_manager_next_scene(app->scene_manager, FuzzerSceneAttack); + consumed = true; } } diff --git a/applications/external/pacs_fuzzer/views/attack.c b/applications/external/pacs_fuzzer/views/attack.c new file mode 100644 index 000000000..a83740f3d --- /dev/null +++ b/applications/external/pacs_fuzzer/views/attack.c @@ -0,0 +1,212 @@ +#include "attack.h" +#include "../fuzzer_i.h" + +#include +#include + +#include "../helpers/protocol.h" + +#define ATTACK_SCENE_MAX_UID_LENGTH 25 + +struct FuzzerViewAttack { + View* view; + FuzzerViewAttackCallback callback; + void* context; +}; + +typedef struct { + uint8_t time_delay; + const char* attack_name; + const char* protocol_name; + bool attack_enabled; + char* uid; + uint8_t uid_size; +} FuzzerViewAttackModel; + +void fuzzer_view_attack_reset_data( + FuzzerViewAttack* view, + const char* attack_name, + const char* protocol_name, + uint8_t uid_size) { + furi_assert(view); + + with_view_model( + view->view, + FuzzerViewAttackModel * model, + { + model->attack_name = attack_name; + model->protocol_name = protocol_name; + model->attack_enabled = false; + model->uid_size = uid_size; + }, + true); +} + +void fuzzer_view_attack_set_uid(FuzzerViewAttack* view, const uint8_t* uid, bool attack) { + furi_assert(view); + + with_view_model( + view->view, + FuzzerViewAttackModel * model, + { + snprintf( + model->uid, + model->uid_size * 3, + "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X", + uid[0], + uid[1], + uid[2], + uid[3], + uid[4], + uid[5], + uid[6], + uid[7]); + model->attack_enabled = attack; + }, + true); +} + +void fuzzer_view_attack_set_callback( + FuzzerViewAttack* view_attack, + FuzzerViewAttackCallback callback, + void* context) { + furi_assert(view_attack); + + view_attack->callback = callback; + view_attack->context = context; +} + +void fuzzer_view_attack_draw(Canvas* canvas, FuzzerViewAttackModel* model) { + char time_delay[16]; + snprintf(time_delay, sizeof(time_delay), "Time delay: %d", model->time_delay); + + canvas_clear(canvas); + canvas_set_color(canvas, ColorBlack); + + canvas_set_font(canvas, FontPrimary); + canvas_draw_str_aligned(canvas, 64, 2, AlignCenter, AlignTop, model->attack_name); + + canvas_set_font(canvas, FontSecondary); + canvas_draw_str_aligned(canvas, 64, 14, AlignCenter, AlignTop, time_delay); + canvas_draw_str_aligned(canvas, 64, 26, AlignCenter, AlignTop, model->protocol_name); + + canvas_set_font(canvas, FontPrimary); + if(128 < canvas_string_width(canvas, model->uid)) { + canvas_set_font(canvas, FontSecondary); + } + canvas_draw_str_aligned(canvas, 64, 38, AlignCenter, AlignTop, model->uid); + + if(model->attack_enabled) { + elements_button_center(canvas, "Stop"); + } else { + elements_button_center(canvas, "Start"); + elements_button_left(canvas, "TD -"); + elements_button_right(canvas, "+ TD"); + } +} + +bool fuzzer_view_attack_input(InputEvent* event, void* context) { + furi_assert(context); + FuzzerViewAttack* view_attack = context; + + if(event->key == InputKeyBack && event->type == InputTypeShort) { + view_attack->callback(FuzzerCustomEventViewAttackBack, view_attack->context); + return true; + } else if(event->key == InputKeyOk && event->type == InputTypeShort) { + view_attack->callback(FuzzerCustomEventViewAttackOk, view_attack->context); + return true; + } else if(event->key == InputKeyLeft) { + with_view_model( + view_attack->view, + FuzzerViewAttackModel * model, + { + if(!model->attack_enabled) { + if(event->type == InputTypeShort) { + if(model->time_delay > FUZZ_TIME_DELAY_MIN) { + model->time_delay--; + } + } else if(event->type == InputTypeLong) { + if((model->time_delay - 10) >= FUZZ_TIME_DELAY_MIN) { + model->time_delay -= 10; + } else { + model->time_delay = FUZZ_TIME_DELAY_MIN; + } + } + } + }, + true); + return true; + } else if(event->key == InputKeyRight) { + with_view_model( + view_attack->view, + FuzzerViewAttackModel * model, + { + if(!model->attack_enabled) { + if(event->type == InputTypeShort) { + if(model->time_delay < FUZZ_TIME_DELAY_MAX) { + model->time_delay++; + } + } else if(event->type == InputTypeLong) { + model->time_delay += 10; + if(model->time_delay > FUZZ_TIME_DELAY_MAX) { + model->time_delay = FUZZ_TIME_DELAY_MAX; + } + } + } + }, + true); + return true; + } + + return true; +} + +void fuzzer_view_attack_enter(void* context) { + furi_assert(context); +} + +void fuzzer_view_attack_exit(void* context) { + furi_assert(context); +} + +FuzzerViewAttack* fuzzer_view_attack_alloc() { + FuzzerViewAttack* view_attack = malloc(sizeof(FuzzerViewAttack)); + + // View allocation and configuration + view_attack->view = view_alloc(); + view_allocate_model(view_attack->view, ViewModelTypeLocking, sizeof(FuzzerViewAttackModel)); + view_set_context(view_attack->view, view_attack); + view_set_draw_callback(view_attack->view, (ViewDrawCallback)fuzzer_view_attack_draw); + view_set_input_callback(view_attack->view, fuzzer_view_attack_input); + view_set_enter_callback(view_attack->view, fuzzer_view_attack_enter); + view_set_exit_callback(view_attack->view, fuzzer_view_attack_exit); + + with_view_model( + view_attack->view, + FuzzerViewAttackModel * model, + { + model->time_delay = FUZZ_TIME_DELAY_MIN; + model->uid = malloc(ATTACK_SCENE_MAX_UID_LENGTH + 1); + model->attack_enabled = false; + + strcpy(model->uid, "Not_set"); + model->attack_name = "Not_set"; + model->protocol_name = "Not_set"; + }, + true); + return view_attack; +} + +void fuzzer_view_attack_free(FuzzerViewAttack* view_attack) { + furi_assert(view_attack); + + with_view_model( + view_attack->view, FuzzerViewAttackModel * model, { free(model->uid); }, true); + view_free(view_attack->view); + free(view_attack); +} + +View* fuzzer_view_attack_get_view(FuzzerViewAttack* view_attack) { + furi_assert(view_attack); + return view_attack->view; +} \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/views/attack.h b/applications/external/pacs_fuzzer/views/attack.h new file mode 100644 index 000000000..082b7ba36 --- /dev/null +++ b/applications/external/pacs_fuzzer/views/attack.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include "../helpers/fuzzer_custom_event.h" + +typedef struct FuzzerViewAttack FuzzerViewAttack; + +typedef void (*FuzzerViewAttackCallback)(FuzzerCustomEvent event, void* context); + +void fuzzer_view_attack_set_callback( + FuzzerViewAttack* view_attack, + FuzzerViewAttackCallback callback, + void* context); + +FuzzerViewAttack* fuzzer_view_attack_alloc(); + +void fuzzer_view_attack_free(FuzzerViewAttack* view_attack); + +View* fuzzer_view_attack_get_view(FuzzerViewAttack* view_attack); + +void fuzzer_view_attack_reset_data( + FuzzerViewAttack* view, + const char* attack_name, + const char* protocol_name, + uint8_t uid_size); + +void fuzzer_view_attack_set_uid(FuzzerViewAttack* view, const uint8_t* uid, bool attack); \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/views/main_menu.c b/applications/external/pacs_fuzzer/views/main_menu.c index 2d55cc143..c037fdf44 100644 --- a/applications/external/pacs_fuzzer/views/main_menu.c +++ b/applications/external/pacs_fuzzer/views/main_menu.c @@ -2,15 +2,10 @@ #include "../fuzzer_i.h" #include -#include +// #include #include "../helpers/protocol.h" - -const char* main_menu_items[FuzzerMainMenuIndexMax] = { - [FuzzerMainMenuIndexDefaultValues] = "Default Values", - [FuzzerMainMenuIndexLoadFile] = "Load File", - [FuzzerMainMenuIndexLoadFileCustomUids] = "Load UIDs from file", -}; +#include "../helpers/gui_const.h" struct FuzzerViewMain { View* view; @@ -24,14 +19,38 @@ typedef struct { uint8_t menu_index; } FuzzerViewMainModel; +void fuzzer_view_main_update_data(FuzzerViewMain* view, FuzzerState state) { + furi_assert(view); + with_view_model( + view->view, + FuzzerViewMainModel * model, + { + model->proto_index = state.proto_index; + model->menu_index = state.menu_index; + }, + true); +} + +void fuzzer_view_main_get_state(FuzzerViewMain* view, FuzzerState* state) { + furi_assert(view); + with_view_model( + view->view, + FuzzerViewMainModel * model, + { + state->proto_index = model->proto_index; + state->menu_index = model->menu_index; + }, + true); +} + void fuzzer_view_main_set_callback( - FuzzerViewMain* fuzzer_view_main, + FuzzerViewMain* view, FuzzerViewMainCallback callback, void* context) { - furi_assert(fuzzer_view_main); + furi_assert(view); - fuzzer_view_main->callback = callback; - fuzzer_view_main->context = context; + view->callback = callback; + view->context = context; } void fuzzer_view_main_draw(Canvas* canvas, FuzzerViewMainModel* model) { @@ -41,17 +60,17 @@ void fuzzer_view_main_draw(Canvas* canvas, FuzzerViewMainModel* model) { if(model->menu_index > 0) { canvas_set_font(canvas, FontSecondary); canvas_draw_str_aligned( - canvas, 64, 24, AlignCenter, AlignTop, main_menu_items[model->menu_index - 1]); + canvas, 64, 24, AlignCenter, AlignTop, fuzzer_attack_names[model->menu_index - 1]); } canvas_set_font(canvas, FontPrimary); canvas_draw_str_aligned( - canvas, 64, 36, AlignCenter, AlignTop, main_menu_items[model->menu_index]); + canvas, 64, 36, AlignCenter, AlignTop, fuzzer_attack_names[model->menu_index]); if(model->menu_index < FuzzerMainMenuIndexMax) { canvas_set_font(canvas, FontSecondary); canvas_draw_str_aligned( - canvas, 64, 48, AlignCenter, AlignTop, main_menu_items[model->menu_index + 1]); + canvas, 64, 48, AlignCenter, AlignTop, fuzzer_attack_names[model->menu_index + 1]); } canvas_set_font(canvas, FontPrimary); @@ -63,15 +82,18 @@ void fuzzer_view_main_draw(Canvas* canvas, FuzzerViewMainModel* model) { bool fuzzer_view_main_input(InputEvent* event, void* context) { furi_assert(context); - FuzzerViewMain* fuzzer_view_main = context; + FuzzerViewMain* view = context; if(event->key == InputKeyBack && (event->type == InputTypeLong || event->type == InputTypeShort)) { - fuzzer_view_main->callback(FuzzerCustomEventViewMainBack, fuzzer_view_main->context); + view->callback(FuzzerCustomEventViewMainBack, view->context); + return true; + } else if(event->key == InputKeyOk && event->type == InputTypeShort) { + view->callback(FuzzerCustomEventViewMainOk, view->context); return true; } else if(event->key == InputKeyDown && event->type == InputTypeShort) { with_view_model( - fuzzer_view_main->view, + view->view, FuzzerViewMainModel * model, { if(model->menu_index < (FuzzerMainMenuIndexMax - 1)) { @@ -82,7 +104,7 @@ bool fuzzer_view_main_input(InputEvent* event, void* context) { return true; } else if(event->key == InputKeyUp && event->type == InputTypeShort) { with_view_model( - fuzzer_view_main->view, + view->view, FuzzerViewMainModel * model, { if(model->menu_index != 0) { @@ -93,7 +115,7 @@ bool fuzzer_view_main_input(InputEvent* event, void* context) { return true; } else if(event->key == InputKeyLeft && event->type == InputTypeShort) { with_view_model( - fuzzer_view_main->view, + view->view, FuzzerViewMainModel * model, { if(model->proto_index != 0) { @@ -106,7 +128,7 @@ bool fuzzer_view_main_input(InputEvent* event, void* context) { return true; } else if(event->key == InputKeyRight && event->type == InputTypeShort) { with_view_model( - fuzzer_view_main->view, + view->view, FuzzerViewMainModel * model, { if(model->proto_index == (FuzzerProtoMax - 1)) { @@ -131,43 +153,43 @@ void fuzzer_view_main_exit(void* context) { } FuzzerViewMain* fuzzer_view_main_alloc() { - FuzzerViewMain* fuzzer_view_main = malloc(sizeof(FuzzerViewMain)); + FuzzerViewMain* view = malloc(sizeof(FuzzerViewMain)); // View allocation and configuration - fuzzer_view_main->view = view_alloc(); - view_allocate_model(fuzzer_view_main->view, ViewModelTypeLocking, sizeof(FuzzerViewMainModel)); - view_set_context(fuzzer_view_main->view, fuzzer_view_main); - view_set_draw_callback(fuzzer_view_main->view, (ViewDrawCallback)fuzzer_view_main_draw); - view_set_input_callback(fuzzer_view_main->view, fuzzer_view_main_input); - view_set_enter_callback(fuzzer_view_main->view, fuzzer_view_main_enter); - view_set_exit_callback(fuzzer_view_main->view, fuzzer_view_main_exit); + view->view = view_alloc(); + view_allocate_model(view->view, ViewModelTypeLocking, sizeof(FuzzerViewMainModel)); + view_set_context(view->view, view); + view_set_draw_callback(view->view, (ViewDrawCallback)fuzzer_view_main_draw); + view_set_input_callback(view->view, fuzzer_view_main_input); + view_set_enter_callback(view->view, fuzzer_view_main_enter); + view_set_exit_callback(view->view, fuzzer_view_main_exit); with_view_model( - fuzzer_view_main->view, + view->view, FuzzerViewMainModel * model, { model->proto_index = 0; model->menu_index = 0; }, true); - return fuzzer_view_main; + return view; } -void fuzzer_view_main_free(FuzzerViewMain* fuzzer_view_main) { - furi_assert(fuzzer_view_main); +void fuzzer_view_main_free(FuzzerViewMain* view) { + furi_assert(view); // with_view_model( - // fuzzer_view_main->view, + // view->view, // FuzzerViewMainModel * model, // { // }, // true); - view_free(fuzzer_view_main->view); - free(fuzzer_view_main); + view_free(view->view); + free(view); } -View* fuzzer_view_main_get_view(FuzzerViewMain* fuzzer_view_main) { - furi_assert(fuzzer_view_main); - return fuzzer_view_main->view; +View* fuzzer_view_main_get_view(FuzzerViewMain* view) { + furi_assert(view); + return view->view; } \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/views/main_menu.h b/applications/external/pacs_fuzzer/views/main_menu.h index 17631807f..262d54405 100644 --- a/applications/external/pacs_fuzzer/views/main_menu.h +++ b/applications/external/pacs_fuzzer/views/main_menu.h @@ -2,13 +2,7 @@ #include #include "../helpers/fuzzer_custom_event.h" - -typedef enum { - FuzzerViewMainStateIdle, - FuzzerViewMainStateLoading, - FuzzerViewMainStateSending, - FuzzerViewMainStateOFF, -} FuzzerViewMainState; +#include "../helpers/fuzzer_types.h" typedef struct FuzzerViewMain FuzzerViewMain; @@ -21,6 +15,9 @@ void fuzzer_view_main_set_callback( FuzzerViewMain* fuzzer_view_main_alloc(); -void fuzzer_view_main_free(FuzzerViewMain* fuzzer_view_main); +void fuzzer_view_main_free(FuzzerViewMain* view); -View* fuzzer_view_main_get_view(FuzzerViewMain* fuzzer_view_main); \ No newline at end of file +View* fuzzer_view_main_get_view(FuzzerViewMain* view); + +void fuzzer_view_main_update_data(FuzzerViewMain* view, FuzzerState state); +void fuzzer_view_main_get_state(FuzzerViewMain* view, FuzzerState* state); \ No newline at end of file From 70edcf3f6a1797cef169dfe524a3e744be309109 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Sat, 3 Jun 2023 00:32:32 +0300 Subject: [PATCH 04/31] Fuzzer App: worker --- applications/external/pacs_fuzzer/fuzzer.c | 4 + applications/external/pacs_fuzzer/fuzzer_i.h | 3 + .../pacs_fuzzer/helpers/fake_worker.c | 183 ++++++++++++++++++ .../pacs_fuzzer/helpers/fake_worker.h | 40 ++++ .../pacs_fuzzer/helpers/fuzzer_custom_event.h | 2 + .../external/pacs_fuzzer/helpers/protocol.h | 2 + .../pacs_fuzzer/scenes/fuzzer_scene_attack.c | 73 ++++++- .../pacs_fuzzer/scenes/fuzzer_scene_main.c | 13 ++ .../external/pacs_fuzzer/views/attack.c | 21 +- .../external/pacs_fuzzer/views/attack.h | 6 +- 10 files changed, 336 insertions(+), 11 deletions(-) create mode 100644 applications/external/pacs_fuzzer/helpers/fake_worker.c create mode 100644 applications/external/pacs_fuzzer/helpers/fake_worker.h diff --git a/applications/external/pacs_fuzzer/fuzzer.c b/applications/external/pacs_fuzzer/fuzzer.c index 42c7d1e47..5a6a4c9b6 100644 --- a/applications/external/pacs_fuzzer/fuzzer.c +++ b/applications/external/pacs_fuzzer/fuzzer.c @@ -25,6 +25,8 @@ PacsFuzzerApp* fuzzer_app_alloc() { app->fuzzer_state.menu_index = 0; app->fuzzer_state.proto_index = 0; + app->worker = fuzzer_worker_alloc(); + // GUI app->gui = furi_record_open(RECORD_GUI); @@ -76,6 +78,8 @@ void fuzzer_app_free(PacsFuzzerApp* app) { // Close records furi_record_close(RECORD_GUI); + fuzzer_worker_free(app->worker); + free(app); } diff --git a/applications/external/pacs_fuzzer/fuzzer_i.h b/applications/external/pacs_fuzzer/fuzzer_i.h index 8f84a558d..bd4833c5b 100644 --- a/applications/external/pacs_fuzzer/fuzzer_i.h +++ b/applications/external/pacs_fuzzer/fuzzer_i.h @@ -10,6 +10,7 @@ #include "views/attack.h" #include "helpers/fuzzer_types.h" +#include "helpers/fake_worker.h" #include @@ -22,4 +23,6 @@ typedef struct { FuzzerViewAttack* attack_view; FuzzerState fuzzer_state; + + FuzzerWorker* worker; } PacsFuzzerApp; \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/helpers/fake_worker.c b/applications/external/pacs_fuzzer/helpers/fake_worker.c new file mode 100644 index 000000000..15e3e035a --- /dev/null +++ b/applications/external/pacs_fuzzer/helpers/fake_worker.c @@ -0,0 +1,183 @@ +#include "fake_worker.h" + +#include +#include + +#include +#include + +#include + +struct FuzzerWorker { + iButtonWorker* proto_worker; + iButtonProtocolId protocol_id; + iButtonProtocols* protocols_items; + iButtonKey* key; + + const FuzzerProtocol* protocol; + FuzzerWorkerAttackType attack_type; + uint8_t timeer_delay; + + uint8_t payload[MAX_PAYLOAD_SIZE]; + Stream* uids_stream; + uint16_t index; + + bool treead_running; + FuriTimer* timer; + + FuzzerWorkerUidChagedCallback tick_callback; + void* tick_context; + + FuzzerWorkerEndCallback end_callback; + void* end_context; +}; + +static bool fuzzer_worker_load_key(FuzzerWorker* worker, bool next) { + furi_assert(worker); + furi_assert(worker->protocol); + bool res = false; + + const FuzzerProtocol* protocol = worker->protocol; + + if(next) { + worker->index++; + } + + switch(worker->attack_type) { + case FuzzerWorkerAttackTypeDefaultDict: + if(worker->index < protocol->dict.len) { + memcpy( + worker->payload, + &protocol->dict.val[worker->index * protocol->data_size], + protocol->data_size); + res = true; + } + break; + + default: + break; + } + + return res; +} + +static void fuzzer_worker_on_tick_callback(void* context) { + furi_assert(context); + + FuzzerWorker* worker = context; + + if(!fuzzer_worker_load_key(worker, true)) { + fuzzer_worker_stop(worker); + if(worker->end_callback) { + worker->end_callback(worker->end_context); + } + } else { + if(worker->tick_callback) { + worker->tick_callback(worker->tick_context); + } + } + + // TODO load ibutton key +} + +void fuzzer_worker_get_current_key(FuzzerWorker* worker, uint8_t* key) { + furi_assert(worker); + furi_assert(worker->protocol); + + memcpy(key, worker->payload, worker->protocol->data_size); +} + +bool fuzzer_worker_attack_dict(FuzzerWorker* worker, FuzzerProtos protocol_index) { + furi_assert(worker); + + worker->attack_type = FuzzerWorkerAttackTypeDefaultDict; + worker->protocol = &fuzzer_proto_items[protocol_index]; + worker->index = 0; + + return fuzzer_worker_load_key(worker, false); +} + +FuzzerWorker* fuzzer_worker_alloc() { + FuzzerWorker* worker = malloc(sizeof(FuzzerWorker)); + + worker->protocols_items = ibutton_protocols_alloc(); + worker->key = ibutton_key_alloc(ibutton_protocols_get_max_data_size(worker->protocols_items)); + + worker->proto_worker = ibutton_worker_alloc(worker->protocols_items); + + worker->index = 0; + worker->treead_running = false; + + memset(worker->payload, 0x00, sizeof(worker->payload)); + + worker->timeer_delay = FUZZ_TIME_DELAY_DEFAULT; + + worker->timer = + furi_timer_alloc(fuzzer_worker_on_tick_callback, FuriTimerTypePeriodic, worker); + + return worker; +} + +void fuzzer_worker_free(FuzzerWorker* worker) { + furi_assert(worker); + + fuzzer_worker_stop(worker); + + furi_timer_free(worker->timer); + + ibutton_worker_free(worker->proto_worker); + + ibutton_key_free(worker->key); + ibutton_protocols_free(worker->protocols_items); + // TODO delete + UNUSED(fuzzer_worker_on_tick_callback); + free(worker); +} + +void fuzzer_worker_start(FuzzerWorker* worker, uint8_t timer_dellay) { + furi_assert(worker); + + worker->timeer_delay = timer_dellay; + + furi_timer_start(worker->timer, furi_ms_to_ticks(timer_dellay * 100)); + + // TODO start timer + // worker->treead_running = true; + // ibutton_worker_start_thread(worker->proto_worker); + + // TODO load ibutton key + + // ibutton_worker_emulate_start(worker->proto_worker, worker->key); +} + +void fuzzer_worker_stop(FuzzerWorker* worker) { + furi_assert(worker); + + furi_timer_stop(worker->timer); + + if(worker->treead_running) { + ibutton_worker_stop(worker->proto_worker); + ibutton_worker_stop_thread(worker->proto_worker); + worker->treead_running = false; + } + + // TODO stop timer, anything else +} + +void fuzzer_worker_set_uid_chaged_callback( + FuzzerWorker* worker, + FuzzerWorkerUidChagedCallback callback, + void* context) { + furi_assert(worker); + worker->tick_callback = callback; + worker->tick_context = context; +} + +void fuzzer_worker_set_end_callback( + FuzzerWorker* worker, + FuzzerWorkerEndCallback callback, + void* context) { + furi_assert(worker); + worker->end_callback = callback; + worker->end_context = context; +} diff --git a/applications/external/pacs_fuzzer/helpers/fake_worker.h b/applications/external/pacs_fuzzer/helpers/fake_worker.h new file mode 100644 index 000000000..00e3cb23f --- /dev/null +++ b/applications/external/pacs_fuzzer/helpers/fake_worker.h @@ -0,0 +1,40 @@ +#pragma once + +#include + +#include "protocol.h" + +typedef enum { + FuzzerWorkerAttackTypeDefaultDict = 0, + FuzzerWorkerAttackTypeLoadFile, + FuzzerWorkerAttackTypeLoadFileCustomUids, + + FuzzerWorkerAttackTypeMax, +} FuzzerWorkerAttackType; + +typedef void (*FuzzerWorkerUidChagedCallback)(void* context); +typedef void (*FuzzerWorkerEndCallback)(void* context); + +typedef struct FuzzerWorker FuzzerWorker; + +FuzzerWorker* fuzzer_worker_alloc(); + +void fuzzer_worker_free(FuzzerWorker* worker); + +void fuzzer_worker_start(FuzzerWorker* worker, uint8_t timer_dellay); + +void fuzzer_worker_stop(FuzzerWorker* worker); + +bool fuzzer_worker_attack_dict(FuzzerWorker* worker, FuzzerProtos protocol_index); + +void fuzzer_worker_get_current_key(FuzzerWorker* worker, uint8_t* key); + +void fuzzer_worker_set_uid_chaged_callback( + FuzzerWorker* worker, + FuzzerWorkerUidChagedCallback callback, + void* context); + +void fuzzer_worker_set_end_callback( + FuzzerWorker* worker, + FuzzerWorkerEndCallback callback, + void* context); \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/helpers/fuzzer_custom_event.h b/applications/external/pacs_fuzzer/helpers/fuzzer_custom_event.h index 189d72ef4..890d961db 100644 --- a/applications/external/pacs_fuzzer/helpers/fuzzer_custom_event.h +++ b/applications/external/pacs_fuzzer/helpers/fuzzer_custom_event.h @@ -8,4 +8,6 @@ typedef enum { FuzzerCustomEventViewAttackBack, FuzzerCustomEventViewAttackOk, + FuzzerCustomEventViewAttackTick, + FuzzerCustomEventViewAttackEnd, } FuzzerCustomEvent; \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/helpers/protocol.h b/applications/external/pacs_fuzzer/helpers/protocol.h index aedeedd8d..c0dd5dd15 100644 --- a/applications/external/pacs_fuzzer/helpers/protocol.h +++ b/applications/external/pacs_fuzzer/helpers/protocol.h @@ -2,6 +2,8 @@ #include +#define MAX_PAYLOAD_SIZE 8 + #define FUZZ_TIME_DELAY_MIN (4) #define FUZZ_TIME_DELAY_DEFAULT (8) #define FUZZ_TIME_DELAY_MAX (80) diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c index 71d38650c..f80cc9b29 100644 --- a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c @@ -1,9 +1,22 @@ #include "../fuzzer_i.h" #include "../helpers/fuzzer_custom_event.h" -#include "../helpers/protocol.h" #include "../helpers/gui_const.h" +// TODO simlify callbacks and attack state + +void fuzzer_scene_attack_worker_tick_callback(void* context) { + furi_assert(context); + PacsFuzzerApp* app = context; + view_dispatcher_send_custom_event(app->view_dispatcher, FuzzerCustomEventViewAttackTick); +} + +void fuzzer_scene_attack_worker_end_callback(void* context) { + furi_assert(context); + PacsFuzzerApp* app = context; + view_dispatcher_send_custom_event(app->view_dispatcher, FuzzerCustomEventViewAttackEnd); +} + void fuzzer_scene_attack_callback(FuzzerCustomEvent event, void* context) { furi_assert(context); PacsFuzzerApp* app = context; @@ -23,7 +36,20 @@ void fuzzer_scene_attack_on_enter(void* context) { fuzzer_attack_names[app->fuzzer_state.menu_index], proto.name, proto.data_size); - fuzzer_view_attack_set_uid(app->attack_view, &proto.dict.val[0], false); + + fuzzer_worker_set_uid_chaged_callback( + app->worker, fuzzer_scene_attack_worker_tick_callback, app); + + fuzzer_worker_set_end_callback(app->worker, fuzzer_scene_attack_worker_end_callback, app); + + uint8_t temp_uid[MAX_PAYLOAD_SIZE]; + + fuzzer_worker_get_current_key(app->worker, temp_uid); + + fuzzer_view_attack_set_attack(app->attack_view, false); + fuzzer_view_attack_set_uid(app->attack_view, (uint8_t*)&temp_uid); + + scene_manager_set_scene_state(app->scene_manager, FuzzerSceneAttack, false); view_dispatcher_switch_to_view(app->view_dispatcher, FuzzerViewIDAttack); } @@ -35,11 +61,40 @@ bool fuzzer_scene_attack_on_event(void* context, SceneManagerEvent event) { if(event.type == SceneManagerEventTypeCustom) { if(event.event == FuzzerCustomEventViewAttackBack) { - if(!scene_manager_previous_scene(app->scene_manager)) { - scene_manager_stop(app->scene_manager); - view_dispatcher_stop(app->view_dispatcher); + if(!scene_manager_get_scene_state(app->scene_manager, FuzzerSceneAttack)) { + if(!scene_manager_previous_scene(app->scene_manager)) { + scene_manager_stop(app->scene_manager); + view_dispatcher_stop(app->view_dispatcher); + } + } else { + scene_manager_set_scene_state(app->scene_manager, FuzzerSceneAttack, false); + fuzzer_view_attack_set_attack(app->attack_view, false); + fuzzer_worker_stop(app->worker); } consumed = true; + } else if(event.event == FuzzerCustomEventViewAttackOk) { + if(!scene_manager_get_scene_state(app->scene_manager, FuzzerSceneAttack)) { + scene_manager_set_scene_state(app->scene_manager, FuzzerSceneAttack, true); + fuzzer_view_attack_set_attack(app->attack_view, true); + fuzzer_worker_start( + app->worker, fuzzer_view_attack_get_time_delay(app->attack_view)); + } else { + scene_manager_set_scene_state(app->scene_manager, FuzzerSceneAttack, false); + fuzzer_view_attack_set_attack(app->attack_view, false); + fuzzer_worker_stop(app->worker); + } + consumed = true; + } else if(event.event == FuzzerCustomEventViewAttackTick) { + uint8_t temp_uid[MAX_PAYLOAD_SIZE]; + + fuzzer_worker_get_current_key(app->worker, temp_uid); + + fuzzer_view_attack_set_uid(app->attack_view, (uint8_t*)&temp_uid); + consumed = true; + } else if(event.event == FuzzerCustomEventViewAttackEnd) { + scene_manager_set_scene_state(app->scene_manager, FuzzerSceneAttack, false); + fuzzer_view_attack_set_attack(app->attack_view, false); + consumed = true; } } @@ -47,7 +102,9 @@ bool fuzzer_scene_attack_on_event(void* context, SceneManagerEvent event) { } void fuzzer_scene_attack_on_exit(void* context) { - // furi_assert(context); - // PacsFuzzerApp* app = context; - UNUSED(context); + furi_assert(context); + PacsFuzzerApp* app = context; + + fuzzer_worker_set_uid_chaged_callback(app->worker, NULL, NULL); + fuzzer_worker_set_end_callback(app->worker, NULL, NULL); } diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c index 812e063ab..00ecdc543 100644 --- a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c @@ -1,6 +1,9 @@ #include "../fuzzer_i.h" #include "../helpers/fuzzer_custom_event.h" +#include "../helpers/protocol.h" +#include "../helpers/gui_const.h" + void fuzzer_scene_main_callback(FuzzerCustomEvent event, void* context) { furi_assert(context); PacsFuzzerApp* app = context; @@ -32,6 +35,16 @@ bool fuzzer_scene_main_on_event(void* context, SceneManagerEvent event) { consumed = true; } else if(event.event == FuzzerCustomEventViewMainOk) { fuzzer_view_main_get_state(app->main_view, &app->fuzzer_state); + + switch(app->fuzzer_state.menu_index) { + case FuzzerMainMenuIndexDefaultValues: + fuzzer_worker_attack_dict(app->worker, app->fuzzer_state.proto_index); + break; + + default: + break; + } + scene_manager_next_scene(app->scene_manager, FuzzerSceneAttack); consumed = true; } diff --git a/applications/external/pacs_fuzzer/views/attack.c b/applications/external/pacs_fuzzer/views/attack.c index a83740f3d..57dd4dd4b 100644 --- a/applications/external/pacs_fuzzer/views/attack.c +++ b/applications/external/pacs_fuzzer/views/attack.c @@ -42,7 +42,7 @@ void fuzzer_view_attack_reset_data( true); } -void fuzzer_view_attack_set_uid(FuzzerViewAttack* view, const uint8_t* uid, bool attack) { +void fuzzer_view_attack_set_uid(FuzzerViewAttack* view, const uint8_t* uid) { furi_assert(view); with_view_model( @@ -61,11 +61,17 @@ void fuzzer_view_attack_set_uid(FuzzerViewAttack* view, const uint8_t* uid, bool uid[5], uid[6], uid[7]); - model->attack_enabled = attack; }, true); } +void fuzzer_view_attack_set_attack(FuzzerViewAttack* view, bool attack) { + furi_assert(view); + + with_view_model( + view->view, FuzzerViewAttackModel * model, { model->attack_enabled = attack; }, true); +} + void fuzzer_view_attack_set_callback( FuzzerViewAttack* view_attack, FuzzerViewAttackCallback callback, @@ -96,6 +102,7 @@ void fuzzer_view_attack_draw(Canvas* canvas, FuzzerViewAttackModel* model) { } canvas_draw_str_aligned(canvas, 64, 38, AlignCenter, AlignTop, model->uid); + canvas_set_font(canvas, FontSecondary); if(model->attack_enabled) { elements_button_center(canvas, "Stop"); } else { @@ -209,4 +216,14 @@ void fuzzer_view_attack_free(FuzzerViewAttack* view_attack) { View* fuzzer_view_attack_get_view(FuzzerViewAttack* view_attack) { furi_assert(view_attack); return view_attack->view; +} + +uint8_t fuzzer_view_attack_get_time_delay(FuzzerViewAttack* view) { + furi_assert(view); + uint8_t time_delay; + + with_view_model( + view->view, FuzzerViewAttackModel * model, { time_delay = model->time_delay; }, false); + + return time_delay; } \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/views/attack.h b/applications/external/pacs_fuzzer/views/attack.h index 082b7ba36..c8204eb18 100644 --- a/applications/external/pacs_fuzzer/views/attack.h +++ b/applications/external/pacs_fuzzer/views/attack.h @@ -24,4 +24,8 @@ void fuzzer_view_attack_reset_data( const char* protocol_name, uint8_t uid_size); -void fuzzer_view_attack_set_uid(FuzzerViewAttack* view, const uint8_t* uid, bool attack); \ No newline at end of file +void fuzzer_view_attack_set_uid(FuzzerViewAttack* view, const uint8_t* uid); + +void fuzzer_view_attack_set_attack(FuzzerViewAttack* view, bool attack); + +uint8_t fuzzer_view_attack_get_time_delay(FuzzerViewAttack* view); \ No newline at end of file From d3a260e4417d96a77c750f0f815f4255d39ace24 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Sat, 3 Jun 2023 14:24:27 +0300 Subject: [PATCH 05/31] Fuzzer App: worker add RFID --- .../external/pacs_fuzzer/application.fam | 38 +++- applications/external/pacs_fuzzer/fuzzer_i.h | 2 +- .../external/pacs_fuzzer/helpers/protocol.c | 92 -------- .../external/pacs_fuzzer/icons/125_10px.png | Bin 0 -> 308 bytes .../external/pacs_fuzzer/icons/ibutt_10px.png | Bin 0 -> 304 bytes .../pacs_fuzzer/{ => icons}/rfid_10px.png | Bin .../{helpers => lib/worker}/fake_worker.c | 106 +++++++-- .../{helpers => lib/worker}/fake_worker.h | 0 .../pacs_fuzzer/lib/worker/protocol.c | 214 ++++++++++++++++++ .../{helpers => lib/worker}/protocol.h | 23 ++ .../pacs_fuzzer/scenes/fuzzer_scene_main.c | 2 +- .../external/pacs_fuzzer/views/attack.c | 2 +- .../external/pacs_fuzzer/views/main_menu.c | 2 +- 13 files changed, 365 insertions(+), 116 deletions(-) delete mode 100644 applications/external/pacs_fuzzer/helpers/protocol.c create mode 100644 applications/external/pacs_fuzzer/icons/125_10px.png create mode 100644 applications/external/pacs_fuzzer/icons/ibutt_10px.png rename applications/external/pacs_fuzzer/{ => icons}/rfid_10px.png (100%) rename applications/external/pacs_fuzzer/{helpers => lib/worker}/fake_worker.c (59%) rename applications/external/pacs_fuzzer/{helpers => lib/worker}/fake_worker.h (100%) create mode 100644 applications/external/pacs_fuzzer/lib/worker/protocol.c rename applications/external/pacs_fuzzer/{helpers => lib/worker}/protocol.h (65%) diff --git a/applications/external/pacs_fuzzer/application.fam b/applications/external/pacs_fuzzer/application.fam index 5e0aafd99..6b6b2ab36 100644 --- a/applications/external/pacs_fuzzer/application.fam +++ b/applications/external/pacs_fuzzer/application.fam @@ -12,8 +12,40 @@ App( ], stack_size=2 * 1024, order=15, - fap_icon="rfid_10px.png", + fap_icon="icons/rfid_10px.png", fap_category="Debug", - # fap_icon_assets="images", - # fap_icon_assets_symbol="fuzzer", + fap_private_libs=[ + Lib( + name="worker", + cdefines=["IBUTTON_PROTOCOL"], + ), + ], + fap_icon_assets="icons", + fap_icon_assets_symbol="fuzzer", +) + +App( + appid="pacs_rfid_fuzzer", + name="Fuzzer Gui rfid", + apptype=FlipperAppType.EXTERNAL, + entry_point="fuzzer_start", + requires=[ + "gui", + "storage", + "dialogs", + "input", + "notification", + ], + stack_size=2 * 1024, + order=15, + fap_icon="icons/125_10px.png", + fap_category="Debug", + fap_private_libs=[ + Lib( + name="worker", + cdefines=["RFID_125_PROTOCOL"], + ), + ], + fap_icon_assets="icons", + fap_icon_assets_symbol="fuzzer", ) diff --git a/applications/external/pacs_fuzzer/fuzzer_i.h b/applications/external/pacs_fuzzer/fuzzer_i.h index bd4833c5b..bc31a137c 100644 --- a/applications/external/pacs_fuzzer/fuzzer_i.h +++ b/applications/external/pacs_fuzzer/fuzzer_i.h @@ -10,7 +10,7 @@ #include "views/attack.h" #include "helpers/fuzzer_types.h" -#include "helpers/fake_worker.h" +#include "lib/worker/fake_worker.h" #include diff --git a/applications/external/pacs_fuzzer/helpers/protocol.c b/applications/external/pacs_fuzzer/helpers/protocol.c deleted file mode 100644 index 072749179..000000000 --- a/applications/external/pacs_fuzzer/helpers/protocol.c +++ /dev/null @@ -1,92 +0,0 @@ -#include "protocol.h" - -#define DS1990_DATA_SIZE (8) -#define Metakom_DATA_SIZE (4) -#define Cyfral_DATA_SIZE (2) - -const uint8_t uid_list_ds1990[][DS1990_DATA_SIZE] = { - {0x01, 0xBE, 0x40, 0x11, 0x5A, 0x36, 0x00, 0xE1}, //– код универсального ключа, для Vizit - {0x01, 0xBE, 0x40, 0x11, 0x5A, 0x56, 0x00, 0xBB}, //- проверен работает - {0x01, 0xBE, 0x40, 0x11, 0x00, 0x00, 0x00, 0x77}, //- проверен работает - {0x01, 0xBE, 0x40, 0x11, 0x0A, 0x00, 0x00, 0x1D}, //- проверен работает Визит иногда КЕЙМАНЫ - {0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x2F}, //- проверен(метаком, цифрал, ВИЗИТ). - {0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x9B}, //- проверен Визит, Метакомы, КОНДОР - {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x14}, //???-Открываает 98% Метаком и некоторые Цифрал - {0x01, 0x00, 0x00, 0x00, 0x00, 0x90, 0x19, 0xFF}, //???-Отлично работает на старых домофонах - {0x01, 0x6F, 0x2E, 0x88, 0x8A, 0x00, 0x00, 0x4D}, //???-Открывать что-то должен - {0x01, 0x53, 0xD4, 0xFE, 0x00, 0x00, 0x7E, 0x88}, //???-Cyfral, Metakom - {0x01, 0x53, 0xD4, 0xFE, 0x00, 0x00, 0x00, 0x6F}, //???-домофоны Визит (Vizit) - до 99% - {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3D}, //???-домофоны Cyfral CCD-20 - до 70% - {0x01, 0x00, 0xBE, 0x11, 0xAA, 0x00, 0x00, 0xFB}, //???-домофоны Кейман (KEYMAN) - {0x01, 0x76, 0xB8, 0x2E, 0x0F, 0x00, 0x00, 0x5C}, //???-домофоны Форвард - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Null bytes - {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x14}, // Only FF - {0x01, 0x78, 0x00, 0x48, 0xFD, 0xFF, 0xFF, 0xD1}, // StarNew Uni5 - {0x01, 0xA9, 0xE4, 0x3C, 0x09, 0x00, 0x00, 0xE6}, // Eltis Uni -}; - -const uint8_t uid_list_metakom[][Metakom_DATA_SIZE] = { - {0x00, 0x00, 0x00, 0x00}, // Null bytes - {0xFF, 0xFF, 0xFF, 0xFF}, // Only FF - {0x11, 0x11, 0x11, 0x11}, // Only 11 - {0x22, 0x22, 0x22, 0x22}, // Only 22 - {0x33, 0x33, 0x33, 0x33}, // Only 33 - {0x44, 0x44, 0x44, 0x44}, // Only 44 - {0x55, 0x55, 0x55, 0x55}, // Only 55 - {0x66, 0x66, 0x66, 0x66}, // Only 66 - {0x77, 0x77, 0x77, 0x77}, // Only 77 - {0x88, 0x88, 0x88, 0x88}, // Only 88 - {0x99, 0x99, 0x99, 0x99}, // Only 99 - {0x12, 0x34, 0x56, 0x78}, // Incremental UID - {0x9A, 0x78, 0x56, 0x34}, // Decremental UID - {0x04, 0xd0, 0x9b, 0x0d}, // ?? - {0x34, 0x00, 0x29, 0x3d}, // ?? - {0x04, 0xdf, 0x00, 0x00}, // ?? - {0xCA, 0xCA, 0xCA, 0xCA}, // ?? -}; - -const uint8_t uid_list_cyfral[][Cyfral_DATA_SIZE] = { - {0x00, 0x00}, // Null bytes - {0xFF, 0xFF}, // Only FF - {0x11, 0x11}, // Only 11 - {0x22, 0x22}, // Only 22 - {0x33, 0x33}, // Only 33 - {0x44, 0x44}, // Only 44 - {0x55, 0x55}, // Only 55 - {0x66, 0x66}, // Only 66 - {0x77, 0x77}, // Only 77 - {0x88, 0x88}, // Only 88 - {0x99, 0x99}, // Only 99 - {0x12, 0x34}, // Incremental UID - {0x56, 0x34}, // Decremental UID - {0xCA, 0xCA}, // ?? - {0x8E, 0xC9}, // Elevator code - {0x6A, 0x50}, // VERY fresh code from smartkey -}; - -const FuzzerProtocol fuzzer_proto_items[] = { - [DS1990] = - { - .name = "DS1990", - .data_size = DS1990_DATA_SIZE, - .dict = - {.val = (const uint8_t*)&uid_list_ds1990, - .len = sizeof(uid_list_ds1990) / DS1990_DATA_SIZE}, - }, - [Metakom] = - { - .name = "Metakom", - .data_size = Metakom_DATA_SIZE, - .dict = - {.val = (const uint8_t*)&uid_list_metakom, - .len = sizeof(uid_list_metakom) / Metakom_DATA_SIZE}, - }, - [Cyfral] = - { - .name = "Cyfral", - .data_size = Cyfral_DATA_SIZE, - .dict = - {.val = (const uint8_t*)&uid_list_cyfral, - .len = sizeof(uid_list_cyfral) / Cyfral_DATA_SIZE}, - }, -}; \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/icons/125_10px.png b/applications/external/pacs_fuzzer/icons/125_10px.png new file mode 100644 index 0000000000000000000000000000000000000000..ce01284a2c1f3eb413f581b84f1fb3f3a2a7223b GIT binary patch literal 308 zcmeAS@N?(olHy`uVBq!ia0vp^AT}2xkYHHq`AGmsv7|ftIx;Y9?C1WI$O_~uBzpw; zGB8xBF)%c=FfjZA3N^f7U???UV0e|lz+g3lfkC`r&aOZkpafHrx4R1i<>&pI=m5)bWZjP>yH&963)5S4_<9hOs!iI<>&pI=m5)bW_|craZ$KesPZ!4!j_b)kjvx52z42i= z^Wk##wtdVzTiGS{99;2>!TC2M!yZeXz}?LkD}l;YOI#yLQW8s2t&)pUffR$0fsvuE zfvK*cNr<75m9c@9v4ysQft7*5`ikN&C>nC}Q!>*kp&E>VdO{3LtqcsU49p-Jly36? Qy~)7f>FVdQ&MBb@0C$~I0{{R3 literal 0 HcmV?d00001 diff --git a/applications/external/pacs_fuzzer/rfid_10px.png b/applications/external/pacs_fuzzer/icons/rfid_10px.png similarity index 100% rename from applications/external/pacs_fuzzer/rfid_10px.png rename to applications/external/pacs_fuzzer/icons/rfid_10px.png diff --git a/applications/external/pacs_fuzzer/helpers/fake_worker.c b/applications/external/pacs_fuzzer/lib/worker/fake_worker.c similarity index 59% rename from applications/external/pacs_fuzzer/helpers/fake_worker.c rename to applications/external/pacs_fuzzer/lib/worker/fake_worker.c index 15e3e035a..6da2becbc 100644 --- a/applications/external/pacs_fuzzer/helpers/fake_worker.c +++ b/applications/external/pacs_fuzzer/lib/worker/fake_worker.c @@ -3,16 +3,36 @@ #include #include +#if defined(RFID_125_PROTOCOL) + +#else + +#endif + +#if defined(RFID_125_PROTOCOL) + +#include +#include + +#else + #include #include +#endif #include struct FuzzerWorker { +#if defined(RFID_125_PROTOCOL) + LFRFIDWorker* proto_worker; + ProtocolId protocol_id; + ProtocolDict* protocols_items; +#else iButtonWorker* proto_worker; - iButtonProtocolId protocol_id; + iButtonProtocolId protocol_id; // TODO iButtonProtocols* protocols_items; iButtonKey* key; +#endif const FuzzerProtocol* protocol; FuzzerWorkerAttackType attack_type; @@ -57,7 +77,18 @@ static bool fuzzer_worker_load_key(FuzzerWorker* worker, bool next) { default: break; } +#if defined(RFID_125_PROTOCOL) + protocol_dict_set_data( + worker->protocols_items, worker->protocol_id, worker->payload, MAX_PAYLOAD_SIZE); +#else + ibutton_key_set_protocol_id(worker->key, worker->protocol_id); + iButtonEditableData data; + ibutton_protocols_get_editable_data(worker->protocols_items, worker->key, &data); + // TODO check data.size logic + data.size = MAX_PAYLOAD_SIZE; + memcpy(data.ptr, worker->payload, MAX_PAYLOAD_SIZE); // data.size); +#endif return res; } @@ -66,18 +97,31 @@ static void fuzzer_worker_on_tick_callback(void* context) { FuzzerWorker* worker = context; + if(worker->treead_running) { +#if defined(RFID_125_PROTOCOL) + lfrfid_worker_stop(worker->proto_worker); +#else + ibutton_worker_stop(worker->proto_worker); +#endif + } + if(!fuzzer_worker_load_key(worker, true)) { fuzzer_worker_stop(worker); if(worker->end_callback) { worker->end_callback(worker->end_context); } } else { + if(worker->treead_running) { +#if defined(RFID_125_PROTOCOL) + lfrfid_worker_emulate_start(worker->proto_worker, worker->protocol_id); +#else + ibutton_worker_emulate_start(worker->proto_worker, worker->key); +#endif + } if(worker->tick_callback) { worker->tick_callback(worker->tick_context); } } - - // TODO load ibutton key } void fuzzer_worker_get_current_key(FuzzerWorker* worker, uint8_t* key) { @@ -90,8 +134,17 @@ void fuzzer_worker_get_current_key(FuzzerWorker* worker, uint8_t* key) { bool fuzzer_worker_attack_dict(FuzzerWorker* worker, FuzzerProtos protocol_index) { furi_assert(worker); - worker->attack_type = FuzzerWorkerAttackTypeDefaultDict; worker->protocol = &fuzzer_proto_items[protocol_index]; + // TODO iButtonProtocolIdInvalid check + +#if defined(RFID_125_PROTOCOL) + worker->protocol_id = + protocol_dict_get_protocol_by_name(worker->protocols_items, worker->protocol->name); +#else + worker->protocol_id = + ibutton_protocols_get_id_by_name(worker->protocols_items, worker->protocol->name); +#endif + worker->attack_type = FuzzerWorkerAttackTypeDefaultDict; worker->index = 0; return fuzzer_worker_load_key(worker, false); @@ -100,11 +153,17 @@ bool fuzzer_worker_attack_dict(FuzzerWorker* worker, FuzzerProtos protocol_index FuzzerWorker* fuzzer_worker_alloc() { FuzzerWorker* worker = malloc(sizeof(FuzzerWorker)); +#if defined(RFID_125_PROTOCOL) + worker->protocols_items = protocol_dict_alloc(lfrfid_protocols, LFRFIDProtocolMax); + + worker->proto_worker = lfrfid_worker_alloc(worker->protocols_items); +#else worker->protocols_items = ibutton_protocols_alloc(); worker->key = ibutton_key_alloc(ibutton_protocols_get_max_data_size(worker->protocols_items)); worker->proto_worker = ibutton_worker_alloc(worker->protocols_items); - +#endif + worker->attack_type = FuzzerWorkerAttackTypeMax; worker->index = 0; worker->treead_running = false; @@ -125,29 +184,37 @@ void fuzzer_worker_free(FuzzerWorker* worker) { furi_timer_free(worker->timer); +#if defined(RFID_125_PROTOCOL) + lfrfid_worker_free(worker->proto_worker); + + protocol_dict_free(worker->protocols_items); +#else ibutton_worker_free(worker->proto_worker); ibutton_key_free(worker->key); ibutton_protocols_free(worker->protocols_items); - // TODO delete - UNUSED(fuzzer_worker_on_tick_callback); +#endif + free(worker); } void fuzzer_worker_start(FuzzerWorker* worker, uint8_t timer_dellay) { furi_assert(worker); - worker->timeer_delay = timer_dellay; + if(worker->attack_type < FuzzerWorkerAttackTypeMax) { + worker->timeer_delay = timer_dellay; - furi_timer_start(worker->timer, furi_ms_to_ticks(timer_dellay * 100)); + furi_timer_start(worker->timer, furi_ms_to_ticks(timer_dellay * 100)); - // TODO start timer - // worker->treead_running = true; - // ibutton_worker_start_thread(worker->proto_worker); - - // TODO load ibutton key - - // ibutton_worker_emulate_start(worker->proto_worker, worker->key); + worker->treead_running = true; +#if defined(RFID_125_PROTOCOL) + lfrfid_worker_start_thread(worker->proto_worker); + lfrfid_worker_emulate_start(worker->proto_worker, worker->protocol_id); +#else + ibutton_worker_start_thread(worker->proto_worker); + ibutton_worker_emulate_start(worker->proto_worker, worker->key); +#endif + } } void fuzzer_worker_stop(FuzzerWorker* worker) { @@ -156,12 +223,17 @@ void fuzzer_worker_stop(FuzzerWorker* worker) { furi_timer_stop(worker->timer); if(worker->treead_running) { +#if defined(RFID_125_PROTOCOL) + lfrfid_worker_stop(worker->proto_worker); + lfrfid_worker_stop_thread(worker->proto_worker); +#else ibutton_worker_stop(worker->proto_worker); ibutton_worker_stop_thread(worker->proto_worker); +#endif worker->treead_running = false; } - // TODO stop timer, anything else + // TODO anything else } void fuzzer_worker_set_uid_chaged_callback( diff --git a/applications/external/pacs_fuzzer/helpers/fake_worker.h b/applications/external/pacs_fuzzer/lib/worker/fake_worker.h similarity index 100% rename from applications/external/pacs_fuzzer/helpers/fake_worker.h rename to applications/external/pacs_fuzzer/lib/worker/fake_worker.h diff --git a/applications/external/pacs_fuzzer/lib/worker/protocol.c b/applications/external/pacs_fuzzer/lib/worker/protocol.c new file mode 100644 index 000000000..b27524d06 --- /dev/null +++ b/applications/external/pacs_fuzzer/lib/worker/protocol.c @@ -0,0 +1,214 @@ +#include "protocol.h" + +// ####################### +// ## Ibutton Protocols ## +// ####################### +#define DS1990_DATA_SIZE (8) +#define Metakom_DATA_SIZE (4) +#define Cyfral_DATA_SIZE (2) + +const uint8_t uid_list_ds1990[][DS1990_DATA_SIZE] = { + {0x01, 0xBE, 0x40, 0x11, 0x5A, 0x36, 0x00, 0xE1}, //– код универсального ключа, для Vizit + {0x01, 0xBE, 0x40, 0x11, 0x5A, 0x56, 0x00, 0xBB}, //- проверен работает + {0x01, 0xBE, 0x40, 0x11, 0x00, 0x00, 0x00, 0x77}, //- проверен работает + {0x01, 0xBE, 0x40, 0x11, 0x0A, 0x00, 0x00, 0x1D}, //- проверен работает Визит иногда КЕЙМАНЫ + {0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x2F}, //- проверен(метаком, цифрал, ВИЗИТ). + {0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x9B}, //- проверен Визит, Метакомы, КОНДОР + {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x14}, //???-Открываает 98% Метаком и некоторые Цифрал + {0x01, 0x00, 0x00, 0x00, 0x00, 0x90, 0x19, 0xFF}, //???-Отлично работает на старых домофонах + {0x01, 0x6F, 0x2E, 0x88, 0x8A, 0x00, 0x00, 0x4D}, //???-Открывать что-то должен + {0x01, 0x53, 0xD4, 0xFE, 0x00, 0x00, 0x7E, 0x88}, //???-Cyfral, Metakom + {0x01, 0x53, 0xD4, 0xFE, 0x00, 0x00, 0x00, 0x6F}, //???-домофоны Визит (Vizit) - до 99% + {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3D}, //???-домофоны Cyfral CCD-20 - до 70% + {0x01, 0x00, 0xBE, 0x11, 0xAA, 0x00, 0x00, 0xFB}, //???-домофоны Кейман (KEYMAN) + {0x01, 0x76, 0xB8, 0x2E, 0x0F, 0x00, 0x00, 0x5C}, //???-домофоны Форвард + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Null bytes + {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x14}, // Only FF + {0x01, 0x78, 0x00, 0x48, 0xFD, 0xFF, 0xFF, 0xD1}, // StarNew Uni5 + {0x01, 0xA9, 0xE4, 0x3C, 0x09, 0x00, 0x00, 0xE6}, // Eltis Uni +}; + +const uint8_t uid_list_metakom[][Metakom_DATA_SIZE] = { + {0x00, 0x00, 0x00, 0x00}, // Null bytes + {0xFF, 0xFF, 0xFF, 0xFF}, // Only FF + {0x11, 0x11, 0x11, 0x11}, // Only 11 + {0x22, 0x22, 0x22, 0x22}, // Only 22 + {0x33, 0x33, 0x33, 0x33}, // Only 33 + {0x44, 0x44, 0x44, 0x44}, // Only 44 + {0x55, 0x55, 0x55, 0x55}, // Only 55 + {0x66, 0x66, 0x66, 0x66}, // Only 66 + {0x77, 0x77, 0x77, 0x77}, // Only 77 + {0x88, 0x88, 0x88, 0x88}, // Only 88 + {0x99, 0x99, 0x99, 0x99}, // Only 99 + {0x12, 0x34, 0x56, 0x78}, // Incremental UID + {0x9A, 0x78, 0x56, 0x34}, // Decremental UID + {0x04, 0xd0, 0x9b, 0x0d}, // ?? + {0x34, 0x00, 0x29, 0x3d}, // ?? + {0x04, 0xdf, 0x00, 0x00}, // ?? + {0xCA, 0xCA, 0xCA, 0xCA}, // ?? +}; + +const uint8_t uid_list_cyfral[][Cyfral_DATA_SIZE] = { + {0x00, 0x00}, // Null bytes + {0xFF, 0xFF}, // Only FF + {0x11, 0x11}, // Only 11 + {0x22, 0x22}, // Only 22 + {0x33, 0x33}, // Only 33 + {0x44, 0x44}, // Only 44 + {0x55, 0x55}, // Only 55 + {0x66, 0x66}, // Only 66 + {0x77, 0x77}, // Only 77 + {0x88, 0x88}, // Only 88 + {0x99, 0x99}, // Only 99 + {0x12, 0x34}, // Incremental UID + {0x56, 0x34}, // Decremental UID + {0xCA, 0xCA}, // ?? + {0x8E, 0xC9}, // Elevator code + {0x6A, 0x50}, // VERY fresh code from smartkey +}; + +// ########################### +// ## Rfid_125khz Protocols ## +// ########################### +#define EM4100_DATA_SIZE (5) +#define HIDProx_DATA_SIZE (6) +#define PAC_DATA_SIZE (4) +#define H10301_DATA_SIZE (3) + +const uint8_t uid_list_em4100[][EM4100_DATA_SIZE] = { + {0x00, 0x00, 0x00, 0x00, 0x00}, // Null bytes + {0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Only FF + {0x11, 0x11, 0x11, 0x11, 0x11}, // Only 11 + {0x22, 0x22, 0x22, 0x22, 0x22}, // Only 22 + {0x33, 0x33, 0x33, 0x33, 0x33}, // Only 33 + {0x44, 0x44, 0x44, 0x44, 0x44}, // Only 44 + {0x55, 0x55, 0x55, 0x55, 0x55}, // Only 55 + {0x66, 0x66, 0x66, 0x66, 0x66}, // Only 66 + {0x77, 0x77, 0x77, 0x77, 0x77}, // Only 77 + {0x88, 0x88, 0x88, 0x88, 0x88}, // Only 88 + {0x99, 0x99, 0x99, 0x99, 0x99}, // Only 99 + {0x12, 0x34, 0x56, 0x78, 0x9A}, // Incremental UID + {0x9A, 0x78, 0x56, 0x34, 0x12}, // Decremental UID + {0x04, 0xd0, 0x9b, 0x0d, 0x6a}, // From arha + {0x34, 0x00, 0x29, 0x3d, 0x9e}, // From arha + {0x04, 0xdf, 0x00, 0x00, 0x01}, // From arha + {0xCA, 0xCA, 0xCA, 0xCA, 0xCA}, // From arha +}; + +const uint8_t uid_list_hid[][HIDProx_DATA_SIZE] = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Null bytes + {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Only FF + {0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, // Only 11 + {0x22, 0x22, 0x22, 0x22, 0x22, 0x22}, // Only 22 + {0x33, 0x33, 0x33, 0x33, 0x33, 0x33}, // Only 33 + {0x44, 0x44, 0x44, 0x44, 0x44, 0x44}, // Only 44 + {0x55, 0x55, 0x55, 0x55, 0x55, 0x55}, // Only 55 + {0x66, 0x66, 0x66, 0x66, 0x66, 0x66}, // Only 66 + {0x77, 0x77, 0x77, 0x77, 0x77, 0x77}, // Only 77 + {0x88, 0x88, 0x88, 0x88, 0x88, 0x88}, // Only 88 + {0x99, 0x99, 0x99, 0x99, 0x99, 0x99}, // Only 99 + {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC}, // Incremental UID + {0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12}, // Decremental UID + {0xCA, 0xCA, 0xCA, 0xCA, 0xCA, 0xCA}, // From arha +}; + +const uint8_t uid_list_pac[][PAC_DATA_SIZE] = { + {0x00, 0x00, 0x00, 0x00}, // Null bytes + {0xFF, 0xFF, 0xFF, 0xFF}, // Only FF + {0x11, 0x11, 0x11, 0x11}, // Only 11 + {0x22, 0x22, 0x22, 0x22}, // Only 22 + {0x33, 0x33, 0x33, 0x33}, // Only 33 + {0x44, 0x44, 0x44, 0x44}, // Only 44 + {0x55, 0x55, 0x55, 0x55}, // Only 55 + {0x66, 0x66, 0x66, 0x66}, // Only 66 + {0x77, 0x77, 0x77, 0x77}, // Only 77 + {0x88, 0x88, 0x88, 0x88}, // Only 88 + {0x99, 0x99, 0x99, 0x99}, // Only 99 + {0x12, 0x34, 0x56, 0x78}, // Incremental UID + {0x9A, 0x78, 0x56, 0x34}, // Decremental UID + {0x04, 0xd0, 0x9b, 0x0d}, // From arha + {0x34, 0x00, 0x29, 0x3d}, // From arha + {0x04, 0xdf, 0x00, 0x00}, // From arha + {0xCA, 0xCA, 0xCA, 0xCA}, // From arha +}; + +const uint8_t uid_list_h10301[][H10301_DATA_SIZE] = { + {0x00, 0x00, 0x00}, // Null bytes + {0xFF, 0xFF, 0xFF}, // Only FF + {0x11, 0x11, 0x11}, // Only 11 + {0x22, 0x22, 0x22}, // Only 22 + {0x33, 0x33, 0x33}, // Only 33 + {0x44, 0x44, 0x44}, // Only 44 + {0x55, 0x55, 0x55}, // Only 55 + {0x66, 0x66, 0x66}, // Only 66 + {0x77, 0x77, 0x77}, // Only 77 + {0x88, 0x88, 0x88}, // Only 88 + {0x99, 0x99, 0x99}, // Only 99 + {0x12, 0x34, 0x56}, // Incremental UID + {0x56, 0x34, 0x12}, // Decremental UID + {0xCA, 0xCA, 0xCA}, // From arha +}; + +#if defined(RFID_125_PROTOCOL) +const FuzzerProtocol fuzzer_proto_items[] = { + [EM4100] = + { + .name = "EM4100", + .data_size = EM4100_DATA_SIZE, + .dict = + {.val = (const uint8_t*)&uid_list_em4100, + .len = sizeof(uid_list_em4100) / EM4100_DATA_SIZE}, + }, + [HIDProx] = + { + .name = "HIDProx", + .data_size = HIDProx_DATA_SIZE, + .dict = + {.val = (const uint8_t*)&uid_list_hid, + .len = sizeof(uid_list_hid) / HIDProx_DATA_SIZE}, + }, + [PAC] = + { + .name = "PAC/Stanley", + .data_size = PAC_DATA_SIZE, + .dict = + {.val = (const uint8_t*)&uid_list_pac, + .len = sizeof(uid_list_pac) / PAC_DATA_SIZE}, + }, + [H10301] = + { + .name = "H10301", + .data_size = H10301_DATA_SIZE, + .dict = + {.val = (const uint8_t*)&uid_list_h10301, + .len = sizeof(uid_list_h10301) / H10301_DATA_SIZE}, + }, +}; +#else +const FuzzerProtocol fuzzer_proto_items[] = { + [DS1990] = + { + .name = "DS1990", + .data_size = DS1990_DATA_SIZE, + .dict = + {.val = (const uint8_t*)&uid_list_ds1990, + .len = sizeof(uid_list_ds1990) / DS1990_DATA_SIZE}, + }, + [Metakom] = + { + .name = "Metakom", + .data_size = Metakom_DATA_SIZE, + .dict = + {.val = (const uint8_t*)&uid_list_metakom, + .len = sizeof(uid_list_metakom) / Metakom_DATA_SIZE}, + }, + [Cyfral] = + { + .name = "Cyfral", + .data_size = Cyfral_DATA_SIZE, + .dict = + {.val = (const uint8_t*)&uid_list_cyfral, + .len = sizeof(uid_list_cyfral) / Cyfral_DATA_SIZE}, + }, +}; +#endif \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/helpers/protocol.h b/applications/external/pacs_fuzzer/lib/worker/protocol.h similarity index 65% rename from applications/external/pacs_fuzzer/helpers/protocol.h rename to applications/external/pacs_fuzzer/lib/worker/protocol.h index c0dd5dd15..c6d7c88ba 100644 --- a/applications/external/pacs_fuzzer/helpers/protocol.h +++ b/applications/external/pacs_fuzzer/lib/worker/protocol.h @@ -2,16 +2,39 @@ #include +// #define RFID_125_PROTOCOL + +#if defined(RFID_125_PROTOCOL) + +#define MAX_PAYLOAD_SIZE 6 + +#define FUZZ_TIME_DELAY_MIN (5) +#define FUZZ_TIME_DELAY_DEFAULT (10) +#define FUZZ_TIME_DELAY_MAX (70) + +#else + #define MAX_PAYLOAD_SIZE 8 #define FUZZ_TIME_DELAY_MIN (4) #define FUZZ_TIME_DELAY_DEFAULT (8) #define FUZZ_TIME_DELAY_MAX (80) +#endif + typedef enum { + +#if defined(RFID_125_PROTOCOL) + EM4100, + HIDProx, + PAC, + H10301, +#else DS1990, Metakom, Cyfral, +#endif + // Reserved FuzzerProtoMax, } FuzzerProtos; diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c index 00ecdc543..1caf0b0ed 100644 --- a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c @@ -1,7 +1,7 @@ #include "../fuzzer_i.h" #include "../helpers/fuzzer_custom_event.h" -#include "../helpers/protocol.h" +#include "../lib/worker/protocol.h" #include "../helpers/gui_const.h" void fuzzer_scene_main_callback(FuzzerCustomEvent event, void* context) { diff --git a/applications/external/pacs_fuzzer/views/attack.c b/applications/external/pacs_fuzzer/views/attack.c index 57dd4dd4b..9e589985d 100644 --- a/applications/external/pacs_fuzzer/views/attack.c +++ b/applications/external/pacs_fuzzer/views/attack.c @@ -4,7 +4,7 @@ #include #include -#include "../helpers/protocol.h" +#include "../lib/worker/protocol.h" #define ATTACK_SCENE_MAX_UID_LENGTH 25 diff --git a/applications/external/pacs_fuzzer/views/main_menu.c b/applications/external/pacs_fuzzer/views/main_menu.c index c037fdf44..13ed005f1 100644 --- a/applications/external/pacs_fuzzer/views/main_menu.c +++ b/applications/external/pacs_fuzzer/views/main_menu.c @@ -4,7 +4,7 @@ #include // #include -#include "../helpers/protocol.h" +#include "../lib/worker/protocol.h" #include "../helpers/gui_const.h" struct FuzzerViewMain { From 2b677c83e3832e3bfb7d9c9df2bf0fa178f82406 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Sat, 3 Jun 2023 18:47:53 +0300 Subject: [PATCH 06/31] Fuzzers App: load custom dict --- .../external/pacs_fuzzer/application.fam | 4 +- applications/external/pacs_fuzzer/fuzzer.c | 38 +++++- applications/external/pacs_fuzzer/fuzzer_i.h | 19 +++ .../pacs_fuzzer/lib/worker/fake_worker.c | 114 ++++++++++++++++-- .../pacs_fuzzer/lib/worker/fake_worker.h | 9 +- .../pacs_fuzzer/lib/worker/protocol.h | 18 --- .../pacs_fuzzer/lib/worker/protocol_i.h | 31 +++++ .../pacs_fuzzer/scenes/fuzzer_scene_attack.c | 21 ++-- .../pacs_fuzzer/scenes/fuzzer_scene_main.c | 43 ++++++- 9 files changed, 253 insertions(+), 44 deletions(-) create mode 100644 applications/external/pacs_fuzzer/lib/worker/protocol_i.h diff --git a/applications/external/pacs_fuzzer/application.fam b/applications/external/pacs_fuzzer/application.fam index 6b6b2ab36..8e67af6d4 100644 --- a/applications/external/pacs_fuzzer/application.fam +++ b/applications/external/pacs_fuzzer/application.fam @@ -2,7 +2,7 @@ App( appid="pacs_fuzzer", name="Fuzzer Gui", apptype=FlipperAppType.EXTERNAL, - entry_point="fuzzer_start", + entry_point="fuzzer_start_ibtn", requires=[ "gui", "storage", @@ -28,7 +28,7 @@ App( appid="pacs_rfid_fuzzer", name="Fuzzer Gui rfid", apptype=FlipperAppType.EXTERNAL, - entry_point="fuzzer_start", + entry_point="fuzzer_start_rfid", requires=[ "gui", "storage", diff --git a/applications/external/pacs_fuzzer/fuzzer.c b/applications/external/pacs_fuzzer/fuzzer.c index 5a6a4c9b6..b6b66fb18 100644 --- a/applications/external/pacs_fuzzer/fuzzer.c +++ b/applications/external/pacs_fuzzer/fuzzer.c @@ -27,9 +27,14 @@ PacsFuzzerApp* fuzzer_app_alloc() { app->worker = fuzzer_worker_alloc(); + app->file_path = furi_string_alloc(); + // GUI app->gui = furi_record_open(RECORD_GUI); + // Dialog + app->dialogs = furi_record_open(RECORD_DIALOGS); + // View Dispatcher app->view_dispatcher = view_dispatcher_alloc(); @@ -75,18 +80,49 @@ void fuzzer_app_free(PacsFuzzerApp* app) { scene_manager_free(app->scene_manager); view_dispatcher_free(app->view_dispatcher); + // Dialog + furi_record_close(RECORD_DIALOGS); + // Close records furi_record_close(RECORD_GUI); + furi_string_free(app->file_path); + fuzzer_worker_free(app->worker); free(app); } -int32_t fuzzer_start(void* p) { +int32_t fuzzer_start_ibtn(void* p) { UNUSED(p); PacsFuzzerApp* fuzzer_app = fuzzer_app_alloc(); + FuzzerConsts app_const = { + .custom_dict_folder = "/ext/ibtnfuzzer", + .custom_dict_extension = ".txt", + .key_extension = ".ibtn", + .path_key_folder = "/ext/ibutton", + }; + fuzzer_app->fuzzer_const = &app_const; + + view_dispatcher_run(fuzzer_app->view_dispatcher); + + fuzzer_app_free(fuzzer_app); + return 0; +} + +int32_t fuzzer_start_rfid(void* p) { + UNUSED(p); + PacsFuzzerApp* fuzzer_app = fuzzer_app_alloc(); + + FuzzerConsts app_const = { + .custom_dict_folder = "/ext/rfidfuzzer", + .custom_dict_extension = ".txt", + .key_extension = ".rfid", + .path_key_folder = "/ext/lfrfid", + }; + fuzzer_app->fuzzer_const = &app_const; + view_dispatcher_run(fuzzer_app->view_dispatcher); fuzzer_app_free(fuzzer_app); diff --git a/applications/external/pacs_fuzzer/fuzzer_i.h b/applications/external/pacs_fuzzer/fuzzer_i.h index bc31a137c..b56becd8f 100644 --- a/applications/external/pacs_fuzzer/fuzzer_i.h +++ b/applications/external/pacs_fuzzer/fuzzer_i.h @@ -1,9 +1,13 @@ #pragma once +#include +#include + #include #include #include #include +#include #include "scenes/fuzzer_scene.h" #include "views/main_menu.h" @@ -13,16 +17,31 @@ #include "lib/worker/fake_worker.h" #include +#include "fuzzer_icons.h" + +#define FUZZ_TIME_DELAY_MIN (5) +#define FUZZ_TIME_DELAY_MAX (80) + +typedef struct { + const char* custom_dict_extension; + const char* custom_dict_folder; + const char* key_extension; + const char* path_key_folder; +} FuzzerConsts; typedef struct { Gui* gui; ViewDispatcher* view_dispatcher; SceneManager* scene_manager; + DialogsApp* dialogs; FuzzerViewMain* main_view; FuzzerViewAttack* attack_view; + FuriString* file_path; + FuzzerState fuzzer_state; + FuzzerConsts* fuzzer_const; FuzzerWorker* worker; } PacsFuzzerApp; \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/lib/worker/fake_worker.c b/applications/external/pacs_fuzzer/lib/worker/fake_worker.c index 6da2becbc..ff74f29e1 100644 --- a/applications/external/pacs_fuzzer/lib/worker/fake_worker.c +++ b/applications/external/pacs_fuzzer/lib/worker/fake_worker.c @@ -1,25 +1,28 @@ #include "fake_worker.h" -#include #include -#if defined(RFID_125_PROTOCOL) +#include +#include +#include -#else - -#endif +#define TAG "Fuzzer worker" +#define FUZZ_TIME_DELAY_DEFAULT (10) #if defined(RFID_125_PROTOCOL) +#define MAX_PAYLOAD_SIZE 6 #include #include #else +#define MAX_PAYLOAD_SIZE 8 #include #include #endif + #include struct FuzzerWorker { @@ -74,6 +77,42 @@ static bool fuzzer_worker_load_key(FuzzerWorker* worker, bool next) { } break; + case FuzzerWorkerAttackTypeLoadFileCustomUids: { + uint8_t str_len = protocol->data_size * 2 + 1; + FuriString* data_str = furi_string_alloc(); + while(true) { + furi_string_reset(data_str); + if(!stream_read_line(worker->uids_stream, data_str)) { + stream_rewind(worker->uids_stream); + // TODO Check empty file & close stream and storage + break; + } else if(furi_string_get_char(data_str, 0) == '#') { + // Skip comment string + continue; + } else if(furi_string_size(data_str) != str_len) { + // Ignore strin with bad length + FURI_LOG_W(TAG, "Bad string length"); + continue; + } else { + FURI_LOG_D(TAG, "Uid candidate: \"%s\"", furi_string_get_cstr(data_str)); + bool parse_ok = true; + for(uint8_t i = 0; i < protocol->data_size; i++) { + if(!hex_char_to_uint8( + furi_string_get_cstr(data_str)[i * 2], + furi_string_get_cstr(data_str)[i * 2 + 1], + &worker->payload[i])) { + parse_ok = false; + break; + } + } + res = parse_ok; + } + break; + } + } + + break; + default: break; } @@ -134,20 +173,71 @@ void fuzzer_worker_get_current_key(FuzzerWorker* worker, uint8_t* key) { bool fuzzer_worker_attack_dict(FuzzerWorker* worker, FuzzerProtos protocol_index) { furi_assert(worker); + bool res = false; + worker->protocol = &fuzzer_proto_items[protocol_index]; - // TODO iButtonProtocolIdInvalid check #if defined(RFID_125_PROTOCOL) worker->protocol_id = protocol_dict_get_protocol_by_name(worker->protocols_items, worker->protocol->name); #else + // TODO iButtonProtocolIdInvalid check worker->protocol_id = ibutton_protocols_get_id_by_name(worker->protocols_items, worker->protocol->name); #endif worker->attack_type = FuzzerWorkerAttackTypeDefaultDict; worker->index = 0; - return fuzzer_worker_load_key(worker, false); + if(!fuzzer_worker_load_key(worker, false)) { + worker->attack_type = FuzzerWorkerAttackTypeMax; + } else { + res = true; + } + + return res; +} + +bool fuzzer_worker_attack_file_dict( + FuzzerWorker* worker, + FuzzerProtos protocol_index, + FuriString* file_path) { + furi_assert(worker); + furi_assert(file_path); + + bool res = false; + + worker->protocol = &fuzzer_proto_items[protocol_index]; + +#if defined(RFID_125_PROTOCOL) + worker->protocol_id = + protocol_dict_get_protocol_by_name(worker->protocols_items, worker->protocol->name); +#else + // TODO iButtonProtocolIdInvalid check + worker->protocol_id = + ibutton_protocols_get_id_by_name(worker->protocols_items, worker->protocol->name); +#endif + + Storage* storage = furi_record_open(RECORD_STORAGE); + worker->uids_stream = buffered_file_stream_alloc(storage); + + if(!buffered_file_stream_open( + worker->uids_stream, furi_string_get_cstr(file_path), FSAM_READ, FSOM_OPEN_EXISTING)) { + buffered_file_stream_close(worker->uids_stream); + return res; + } + + worker->attack_type = FuzzerWorkerAttackTypeLoadFileCustomUids; + worker->index = 0; + + if(!fuzzer_worker_load_key(worker, false)) { + worker->attack_type = FuzzerWorkerAttackTypeMax; + buffered_file_stream_close(worker->uids_stream); + furi_record_close(RECORD_STORAGE); + } else { + res = true; + } + + return res; } FuzzerWorker* fuzzer_worker_alloc() { @@ -198,7 +288,7 @@ void fuzzer_worker_free(FuzzerWorker* worker) { free(worker); } -void fuzzer_worker_start(FuzzerWorker* worker, uint8_t timer_dellay) { +bool fuzzer_worker_start(FuzzerWorker* worker, uint8_t timer_dellay) { furi_assert(worker); if(worker->attack_type < FuzzerWorkerAttackTypeMax) { @@ -214,7 +304,9 @@ void fuzzer_worker_start(FuzzerWorker* worker, uint8_t timer_dellay) { ibutton_worker_start_thread(worker->proto_worker); ibutton_worker_emulate_start(worker->proto_worker, worker->key); #endif + return true; } + return false; } void fuzzer_worker_stop(FuzzerWorker* worker) { @@ -233,6 +325,12 @@ void fuzzer_worker_stop(FuzzerWorker* worker) { worker->treead_running = false; } + if(worker->attack_type == FuzzerWorkerAttackTypeLoadFileCustomUids) { + buffered_file_stream_close(worker->uids_stream); + furi_record_close(RECORD_STORAGE); + worker->attack_type = FuzzerWorkerAttackTypeMax; + } + // TODO anything else } diff --git a/applications/external/pacs_fuzzer/lib/worker/fake_worker.h b/applications/external/pacs_fuzzer/lib/worker/fake_worker.h index 00e3cb23f..2628ac649 100644 --- a/applications/external/pacs_fuzzer/lib/worker/fake_worker.h +++ b/applications/external/pacs_fuzzer/lib/worker/fake_worker.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "protocol.h" @@ -21,12 +21,17 @@ FuzzerWorker* fuzzer_worker_alloc(); void fuzzer_worker_free(FuzzerWorker* worker); -void fuzzer_worker_start(FuzzerWorker* worker, uint8_t timer_dellay); +bool fuzzer_worker_start(FuzzerWorker* worker, uint8_t timer_dellay); void fuzzer_worker_stop(FuzzerWorker* worker); bool fuzzer_worker_attack_dict(FuzzerWorker* worker, FuzzerProtos protocol_index); +bool fuzzer_worker_attack_file_dict( + FuzzerWorker* worker, + FuzzerProtos protocol_index, + FuriString* file_path); + void fuzzer_worker_get_current_key(FuzzerWorker* worker, uint8_t* key); void fuzzer_worker_set_uid_chaged_callback( diff --git a/applications/external/pacs_fuzzer/lib/worker/protocol.h b/applications/external/pacs_fuzzer/lib/worker/protocol.h index c6d7c88ba..a69d3db04 100644 --- a/applications/external/pacs_fuzzer/lib/worker/protocol.h +++ b/applications/external/pacs_fuzzer/lib/worker/protocol.h @@ -4,24 +4,6 @@ // #define RFID_125_PROTOCOL -#if defined(RFID_125_PROTOCOL) - -#define MAX_PAYLOAD_SIZE 6 - -#define FUZZ_TIME_DELAY_MIN (5) -#define FUZZ_TIME_DELAY_DEFAULT (10) -#define FUZZ_TIME_DELAY_MAX (70) - -#else - -#define MAX_PAYLOAD_SIZE 8 - -#define FUZZ_TIME_DELAY_MIN (4) -#define FUZZ_TIME_DELAY_DEFAULT (8) -#define FUZZ_TIME_DELAY_MAX (80) - -#endif - typedef enum { #if defined(RFID_125_PROTOCOL) diff --git a/applications/external/pacs_fuzzer/lib/worker/protocol_i.h b/applications/external/pacs_fuzzer/lib/worker/protocol_i.h new file mode 100644 index 000000000..e0ab76cb3 --- /dev/null +++ b/applications/external/pacs_fuzzer/lib/worker/protocol_i.h @@ -0,0 +1,31 @@ +#pragma once + +#include "protocol.h" + +#if defined(RFID_125_PROTOCOL) + +#define MAX_PAYLOAD_SIZE 6 + +#define FUZZ_TIME_DELAY_MIN (5) +#define FUZZ_TIME_DELAY_DEFAULT (10) +#define FUZZ_TIME_DELAY_MAX (70) + +#define FUZZER_APP_CUSTOM_DICT_EXTENSION ".txt" +#define FUZZER_APP_CUSTOM_DICT_FOLDER "/ext/rfidfuzzer" +#define FUZZER_APP_KEY_EXTENSION ".rfid" +#define FUZZER_APP_PATH_KEY_FOLDER "/ext/lfrfid" + +#else + +#define MAX_PAYLOAD_SIZE 8 + +#define FUZZ_TIME_DELAY_MIN (4) +#define FUZZ_TIME_DELAY_DEFAULT (8) +#define FUZZ_TIME_DELAY_MAX (80) + +#define FUZZER_APP_CUSTOM_DICT_EXTENSION ".txt" +#define FUZZER_APP_CUSTOM_DICT_FOLDER "/ext/ibtnfuzzer" +#define FUZZER_APP_KEY_EXTENSION ".ibtn" +#define FUZZER_APP_PATH_KEY_FOLDER "/ext/ibutton" + +#endif diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c index f80cc9b29..c18e2cec9 100644 --- a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c @@ -31,21 +31,20 @@ void fuzzer_scene_attack_on_enter(void* context) { FuzzerProtocol proto = fuzzer_proto_items[app->fuzzer_state.proto_index]; - fuzzer_view_attack_reset_data( - app->attack_view, - fuzzer_attack_names[app->fuzzer_state.menu_index], - proto.name, - proto.data_size); - fuzzer_worker_set_uid_chaged_callback( app->worker, fuzzer_scene_attack_worker_tick_callback, app); fuzzer_worker_set_end_callback(app->worker, fuzzer_scene_attack_worker_end_callback, app); - uint8_t temp_uid[MAX_PAYLOAD_SIZE]; + uint8_t temp_uid[proto.data_size]; fuzzer_worker_get_current_key(app->worker, temp_uid); + fuzzer_view_attack_reset_data( + app->attack_view, + fuzzer_attack_names[app->fuzzer_state.menu_index], + proto.name, + proto.data_size); fuzzer_view_attack_set_attack(app->attack_view, false); fuzzer_view_attack_set_uid(app->attack_view, (uint8_t*)&temp_uid); @@ -73,11 +72,11 @@ bool fuzzer_scene_attack_on_event(void* context, SceneManagerEvent event) { } consumed = true; } else if(event.event == FuzzerCustomEventViewAttackOk) { - if(!scene_manager_get_scene_state(app->scene_manager, FuzzerSceneAttack)) { + if(!scene_manager_get_scene_state(app->scene_manager, FuzzerSceneAttack) && + fuzzer_worker_start( + app->worker, fuzzer_view_attack_get_time_delay(app->attack_view))) { scene_manager_set_scene_state(app->scene_manager, FuzzerSceneAttack, true); fuzzer_view_attack_set_attack(app->attack_view, true); - fuzzer_worker_start( - app->worker, fuzzer_view_attack_get_time_delay(app->attack_view)); } else { scene_manager_set_scene_state(app->scene_manager, FuzzerSceneAttack, false); fuzzer_view_attack_set_attack(app->attack_view, false); @@ -85,7 +84,7 @@ bool fuzzer_scene_attack_on_event(void* context, SceneManagerEvent event) { } consumed = true; } else if(event.event == FuzzerCustomEventViewAttackTick) { - uint8_t temp_uid[MAX_PAYLOAD_SIZE]; + uint8_t temp_uid[fuzzer_proto_items[app->fuzzer_state.proto_index].data_size]; fuzzer_worker_get_current_key(app->worker, temp_uid); diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c index 1caf0b0ed..a42701adf 100644 --- a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c @@ -10,6 +10,26 @@ void fuzzer_scene_main_callback(FuzzerCustomEvent event, void* context) { view_dispatcher_send_custom_event(app->view_dispatcher, event); } +static bool fuzzer_scene_main_load_custom_dict(void* context) { + furi_assert(context); + PacsFuzzerApp* app = context; + + FuzzerConsts* consts = app->fuzzer_const; + + furi_string_set_str(app->file_path, consts->custom_dict_folder); + + DialogsFileBrowserOptions browser_options; + dialog_file_browser_set_basic_options( + &browser_options, consts->custom_dict_extension, &I_rfid_10px); + browser_options.base_path = consts->custom_dict_folder; + browser_options.hide_ext = false; + + bool res = + dialog_file_browser_show(app->dialogs, app->file_path, app->file_path, &browser_options); + + return res; +} + void fuzzer_scene_main_on_enter(void* context) { furi_assert(context); PacsFuzzerApp* app = context; @@ -36,16 +56,35 @@ bool fuzzer_scene_main_on_event(void* context, SceneManagerEvent event) { } else if(event.event == FuzzerCustomEventViewMainOk) { fuzzer_view_main_get_state(app->main_view, &app->fuzzer_state); + // TODO error logic + bool loading_ok = false; + switch(app->fuzzer_state.menu_index) { case FuzzerMainMenuIndexDefaultValues: - fuzzer_worker_attack_dict(app->worker, app->fuzzer_state.proto_index); + + loading_ok = fuzzer_worker_attack_dict(app->worker, app->fuzzer_state.proto_index); + + if(!loading_ok) { + // error + } + break; + + case FuzzerMainMenuIndexLoadFileCustomUids: + if(!fuzzer_scene_main_load_custom_dict(app)) { + break; + } else { + loading_ok = fuzzer_worker_attack_file_dict( + app->worker, app->fuzzer_state.proto_index, app->file_path); + } break; default: break; } - scene_manager_next_scene(app->scene_manager, FuzzerSceneAttack); + if(loading_ok) { + scene_manager_next_scene(app->scene_manager, FuzzerSceneAttack); + } consumed = true; } } From 5b4bb66848e28a325b97872339beb986d80c4d39 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Sat, 3 Jun 2023 22:03:20 +0300 Subject: [PATCH 07/31] Fuzzer App: Field editor view --- applications/external/pacs_fuzzer/fuzzer.c | 11 + applications/external/pacs_fuzzer/fuzzer_i.h | 2 + .../pacs_fuzzer/helpers/fuzzer_custom_event.h | 3 + .../pacs_fuzzer/helpers/fuzzer_types.h | 1 + .../pacs_fuzzer/scenes/fuzzer_scene_config.h | 3 +- .../scenes/fuzzer_scene_field_editor.c | 42 +++ .../pacs_fuzzer/scenes/fuzzer_scene_main.c | 6 + .../external/pacs_fuzzer/views/attack.c | 2 - .../external/pacs_fuzzer/views/field_editor.c | 251 ++++++++++++++++++ .../external/pacs_fuzzer/views/field_editor.h | 19 ++ .../external/pacs_fuzzer/views/main_menu.c | 2 - 11 files changed, 337 insertions(+), 5 deletions(-) create mode 100644 applications/external/pacs_fuzzer/scenes/fuzzer_scene_field_editor.c create mode 100644 applications/external/pacs_fuzzer/views/field_editor.c create mode 100644 applications/external/pacs_fuzzer/views/field_editor.h diff --git a/applications/external/pacs_fuzzer/fuzzer.c b/applications/external/pacs_fuzzer/fuzzer.c index b6b66fb18..6b609040c 100644 --- a/applications/external/pacs_fuzzer/fuzzer.c +++ b/applications/external/pacs_fuzzer/fuzzer.c @@ -48,6 +48,13 @@ PacsFuzzerApp* fuzzer_app_alloc() { view_dispatcher_add_view( app->view_dispatcher, FuzzerViewIDAttack, fuzzer_view_attack_get_view(app->attack_view)); + // FieldEditor view + app->field_editor_view = fuzzer_view_field_editor_alloc(); + view_dispatcher_add_view( + app->view_dispatcher, + FuzzerViewIDFieldEditor, + fuzzer_view_field_editor_get_view(app->field_editor_view)); + app->scene_manager = scene_manager_alloc(&fuzzer_scene_handlers, app); view_dispatcher_enable_queue(app->view_dispatcher); @@ -77,6 +84,10 @@ void fuzzer_app_free(PacsFuzzerApp* app) { view_dispatcher_remove_view(app->view_dispatcher, FuzzerViewIDAttack); fuzzer_view_attack_free(app->attack_view); + // FieldEditor view + view_dispatcher_remove_view(app->view_dispatcher, FuzzerViewIDFieldEditor); + fuzzer_view_field_editor_free(app->field_editor_view); + scene_manager_free(app->scene_manager); view_dispatcher_free(app->view_dispatcher); diff --git a/applications/external/pacs_fuzzer/fuzzer_i.h b/applications/external/pacs_fuzzer/fuzzer_i.h index b56becd8f..59ec2df33 100644 --- a/applications/external/pacs_fuzzer/fuzzer_i.h +++ b/applications/external/pacs_fuzzer/fuzzer_i.h @@ -12,6 +12,7 @@ #include "scenes/fuzzer_scene.h" #include "views/main_menu.h" #include "views/attack.h" +#include "views/field_editor.h" #include "helpers/fuzzer_types.h" #include "lib/worker/fake_worker.h" @@ -37,6 +38,7 @@ typedef struct { DialogsApp* dialogs; FuzzerViewMain* main_view; FuzzerViewAttack* attack_view; + FuzzerViewFieldEditor* field_editor_view; FuriString* file_path; diff --git a/applications/external/pacs_fuzzer/helpers/fuzzer_custom_event.h b/applications/external/pacs_fuzzer/helpers/fuzzer_custom_event.h index 890d961db..930029d3c 100644 --- a/applications/external/pacs_fuzzer/helpers/fuzzer_custom_event.h +++ b/applications/external/pacs_fuzzer/helpers/fuzzer_custom_event.h @@ -10,4 +10,7 @@ typedef enum { FuzzerCustomEventViewAttackOk, FuzzerCustomEventViewAttackTick, FuzzerCustomEventViewAttackEnd, + + FuzzerCustomEventViewFieldEditorBack, + FuzzerCustomEventViewFieldEditorOk, } FuzzerCustomEvent; \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/helpers/fuzzer_types.h b/applications/external/pacs_fuzzer/helpers/fuzzer_types.h index 55c64954c..7e390f875 100644 --- a/applications/external/pacs_fuzzer/helpers/fuzzer_types.h +++ b/applications/external/pacs_fuzzer/helpers/fuzzer_types.h @@ -11,4 +11,5 @@ typedef struct { typedef enum { FuzzerViewIDMain, FuzzerViewIDAttack, + FuzzerViewIDFieldEditor, } FuzzerViewID; \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_config.h b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_config.h index bccdbd9a5..711ebe1c4 100644 --- a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_config.h +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_config.h @@ -1,2 +1,3 @@ ADD_SCENE(fuzzer, main, Main) -ADD_SCENE(fuzzer, attack, Attack) \ No newline at end of file +ADD_SCENE(fuzzer, attack, Attack) +ADD_SCENE(fuzzer, field_editor, FieldEditor) \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_field_editor.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_field_editor.c new file mode 100644 index 000000000..197bd82c4 --- /dev/null +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_field_editor.c @@ -0,0 +1,42 @@ +#include "../fuzzer_i.h" +#include "../helpers/fuzzer_custom_event.h" + +void fuzzer_scene_field_editor_callback(FuzzerCustomEvent event, void* context) { + furi_assert(context); + PacsFuzzerApp* app = context; + view_dispatcher_send_custom_event(app->view_dispatcher, event); +} + +void fuzzer_scene_field_editor_on_enter(void* context) { + furi_assert(context); + PacsFuzzerApp* app = context; + + fuzzer_view_field_editor_set_callback( + app->field_editor_view, fuzzer_scene_field_editor_callback, app); + + view_dispatcher_switch_to_view(app->view_dispatcher, FuzzerViewIDFieldEditor); +} + +bool fuzzer_scene_field_editor_on_event(void* context, SceneManagerEvent event) { + furi_assert(context); + PacsFuzzerApp* app = context; + bool consumed = false; + + if(event.type == SceneManagerEventTypeCustom) { + if(event.event == FuzzerCustomEventViewFieldEditorBack) { + if(!scene_manager_previous_scene(app->scene_manager)) { + scene_manager_stop(app->scene_manager); + view_dispatcher_stop(app->view_dispatcher); + } + consumed = true; + } + } + + return consumed; +} + +void fuzzer_scene_field_editor_on_exit(void* context) { + // furi_assert(context); + // PacsFuzzerApp* app = context; + UNUSED(context); +} diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c index a42701adf..cb5e97c52 100644 --- a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c @@ -69,6 +69,12 @@ bool fuzzer_scene_main_on_event(void* context, SceneManagerEvent event) { } break; + case FuzzerMainMenuIndexLoadFile: + // TODO Delete + scene_manager_next_scene(app->scene_manager, FuzzerSceneFieldEditor); + + break; + case FuzzerMainMenuIndexLoadFileCustomUids: if(!fuzzer_scene_main_load_custom_dict(app)) { break; diff --git a/applications/external/pacs_fuzzer/views/attack.c b/applications/external/pacs_fuzzer/views/attack.c index 9e589985d..910d69c0c 100644 --- a/applications/external/pacs_fuzzer/views/attack.c +++ b/applications/external/pacs_fuzzer/views/attack.c @@ -4,8 +4,6 @@ #include #include -#include "../lib/worker/protocol.h" - #define ATTACK_SCENE_MAX_UID_LENGTH 25 struct FuzzerViewAttack { diff --git a/applications/external/pacs_fuzzer/views/field_editor.c b/applications/external/pacs_fuzzer/views/field_editor.c new file mode 100644 index 000000000..daf8e9d24 --- /dev/null +++ b/applications/external/pacs_fuzzer/views/field_editor.c @@ -0,0 +1,251 @@ +#include "field_editor.h" +#include "../fuzzer_i.h" + +#include +#include +#include + +#define UID_STR_LENGTH 25 +#define EDITOR_STRING_Y 50 + +struct FuzzerViewFieldEditor { + View* view; + FuzzerViewFieldEditorCallback callback; + void* context; +}; + +// TODO model +typedef struct { + uint8_t* uid; + uint8_t uid_size; + uint8_t index; + FuriString* uid_str; + bool lo; +} FuzzerViewFieldEditorModel; + +void fuzzer_view_field_editor_set_callback( + FuzzerViewFieldEditor* view_edit, + FuzzerViewFieldEditorCallback callback, + void* context) { + furi_assert(view_edit); + + view_edit->callback = callback; + view_edit->context = context; +} + +void fuzzer_view_field_editor_draw(Canvas* canvas, FuzzerViewFieldEditorModel* model) { + canvas_clear(canvas); + canvas_set_color(canvas, ColorBlack); + + canvas_set_font(canvas, FontSecondary); + canvas_draw_str_aligned(canvas, 64, 5, AlignCenter, AlignTop, "Left and right: select byte"); + canvas_draw_str_aligned(canvas, 64, 15, AlignCenter, AlignTop, "Up and down: adjust byte"); + + char msg_index[18]; + canvas_set_font(canvas, FontPrimary); + snprintf(msg_index, sizeof(msg_index), "Field index : %d", model->index); + canvas_draw_str_aligned(canvas, 64, 30, AlignCenter, AlignTop, msg_index); + + // ####### Editor ####### + FuriString* temp_s = model->uid_str; + canvas_set_font(canvas, FontSecondary); + + furi_string_reset(temp_s); + for(int i = -3; i != 0; i++) { + if(0 <= (model->index + i)) { + furi_string_cat_printf(temp_s, "%2X ", model->uid[model->index + i]); + } + } + canvas_draw_str_aligned( + canvas, 52, EDITOR_STRING_Y, AlignRight, AlignBottom, furi_string_get_cstr(temp_s)); + + furi_string_reset(temp_s); + for(int i = 1; i != 4; i++) { + if((model->index + i) < model->uid_size) { + furi_string_cat_printf(temp_s, " %2X", model->uid[model->index + i]); + } + } + canvas_draw_str_aligned( + canvas, 77, EDITOR_STRING_Y, AlignLeft, AlignBottom, furi_string_get_cstr(temp_s)); + + canvas_set_font(canvas, FontPrimary); + + furi_string_reset(temp_s); + furi_string_cat_printf(temp_s, "<%02X>", model->uid[model->index]); + canvas_draw_str_aligned( + canvas, 64, EDITOR_STRING_Y, AlignCenter, AlignBottom, furi_string_get_cstr(temp_s)); + + uint16_t w = canvas_string_width(canvas, furi_string_get_cstr(temp_s)); + w -= 11; // '<' & '>' + w /= 2; + + if(model->lo) { + canvas_draw_line(canvas, 64 + 1, EDITOR_STRING_Y + 2, 64 + w, EDITOR_STRING_Y + 2); + } else { + canvas_draw_line(canvas, 64 - w, EDITOR_STRING_Y + 2, 64 - 1, EDITOR_STRING_Y + 2); + } + // ####### Editor ####### +} + +bool fuzzer_view_field_editor_input(InputEvent* event, void* context) { + furi_assert(context); + FuzzerViewFieldEditor* view_edit = context; + + if(event->key == InputKeyBack && event->type == InputTypeShort) { + view_edit->callback(FuzzerCustomEventViewFieldEditorBack, view_edit->context); + return true; + } else if(event->key == InputKeyOk && event->type == InputTypeShort) { + view_edit->callback(FuzzerCustomEventViewFieldEditorOk, view_edit->context); + return true; + } else if(event->key == InputKeyLeft) { + with_view_model( + view_edit->view, + FuzzerViewFieldEditorModel * model, + { + if(event->type == InputTypeShort) { + if(model->index > 0 || model->lo) { + if(!model->lo) { + model->index--; + } + model->lo = !model->lo; + } + } else if(event->type == InputTypeLong) { + model->index = 0; + model->lo = false; + } + }, + true); + return true; + } else if(event->key == InputKeyRight) { + with_view_model( + view_edit->view, + FuzzerViewFieldEditorModel * model, + { + if(event->type == InputTypeShort) { + if(model->index < (model->uid_size - 1) || !model->lo) { + if(model->lo) { + model->index++; + } + model->lo = !model->lo; + } + } else if(event->type == InputTypeLong) { + model->index = model->uid_size - 1; + model->lo = true; + } + }, + true); + return true; + } else if(event->key == InputKeyUp) { + with_view_model( + view_edit->view, + FuzzerViewFieldEditorModel * model, + { + if(event->type == InputTypeShort) { + if(model->lo) { + model->uid[model->index] = (model->uid[model->index] & 0xF0) | + ((model->uid[model->index] + 1) & 0x0F); + } else { + model->uid[model->index] = ((model->uid[model->index] + 0x10) & 0xF0) | + (model->uid[model->index] & 0x0F); + } + } + }, + true); + return true; + } else if(event->key == InputKeyDown) { + with_view_model( + view_edit->view, + FuzzerViewFieldEditorModel * model, + { + if(event->type == InputTypeShort) { + if(model->lo) { + model->uid[model->index] = (model->uid[model->index] & 0xF0) | + ((model->uid[model->index] - 1) & 0x0F); + } else { + model->uid[model->index] = ((model->uid[model->index] - 0x10) & 0xF0) | + (model->uid[model->index] & 0x0F); + } + } + }, + true); + return true; + } + + return true; +} + +void fuzzer_view_field_editor_enter(void* context) { + furi_assert(context); + // TODO delete only for debug + // FuzzerViewFieldEditor* view_edit = context; + // uint8_t temp[8] = { + // 0x12, + // 0x34, + // 0x56, + // 0x78, + // 0x90, + // 0xAB, + // 0xCD, + // 0xEF, + // }; + // with_view_model( + // view_edit->view, + // FuzzerViewFieldEditorModel * model, + // { + // memcpy(model->uid, &temp, 8); + + // // memset(model->uid, 0xCC, 8); + // model->index = 0; + // model->uid_size = 8; + // }, + // true); +} + +void fuzzer_view_field_editor_exit(void* context) { + furi_assert(context); +} + +FuzzerViewFieldEditor* fuzzer_view_field_editor_alloc() { + FuzzerViewFieldEditor* view_edit = malloc(sizeof(FuzzerViewFieldEditor)); + + // View allocation and configuration + view_edit->view = view_alloc(); + view_allocate_model(view_edit->view, ViewModelTypeLocking, sizeof(FuzzerViewFieldEditorModel)); + view_set_context(view_edit->view, view_edit); + view_set_draw_callback(view_edit->view, (ViewDrawCallback)fuzzer_view_field_editor_draw); + view_set_input_callback(view_edit->view, fuzzer_view_field_editor_input); + view_set_enter_callback(view_edit->view, fuzzer_view_field_editor_enter); + view_set_exit_callback(view_edit->view, fuzzer_view_field_editor_exit); + + with_view_model( + view_edit->view, + FuzzerViewFieldEditorModel * model, + { + model->uid_str = furi_string_alloc(); + + model->uid = malloc(8); + }, + true); + + return view_edit; +} + +void fuzzer_view_field_editor_free(FuzzerViewFieldEditor* view_edit) { + furi_assert(view_edit); + + with_view_model( + view_edit->view, + FuzzerViewFieldEditorModel * model, + { + furi_string_free(model->uid_str); + free(model->uid); + }, + true); + view_free(view_edit->view); + free(view_edit); +} + +View* fuzzer_view_field_editor_get_view(FuzzerViewFieldEditor* view_edit) { + furi_assert(view_edit); + return view_edit->view; +} \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/views/field_editor.h b/applications/external/pacs_fuzzer/views/field_editor.h new file mode 100644 index 000000000..df3aba724 --- /dev/null +++ b/applications/external/pacs_fuzzer/views/field_editor.h @@ -0,0 +1,19 @@ +#pragma once + +#include +#include "../helpers/fuzzer_custom_event.h" + +typedef struct FuzzerViewFieldEditor FuzzerViewFieldEditor; + +typedef void (*FuzzerViewFieldEditorCallback)(FuzzerCustomEvent event, void* context); + +void fuzzer_view_field_editor_set_callback( + FuzzerViewFieldEditor* view_attack, + FuzzerViewFieldEditorCallback callback, + void* context); + +FuzzerViewFieldEditor* fuzzer_view_field_editor_alloc(); + +void fuzzer_view_field_editor_free(FuzzerViewFieldEditor* view_attack); + +View* fuzzer_view_field_editor_get_view(FuzzerViewFieldEditor* view_attack); \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/views/main_menu.c b/applications/external/pacs_fuzzer/views/main_menu.c index 13ed005f1..d12c3e380 100644 --- a/applications/external/pacs_fuzzer/views/main_menu.c +++ b/applications/external/pacs_fuzzer/views/main_menu.c @@ -2,9 +2,7 @@ #include "../fuzzer_i.h" #include -// #include -#include "../lib/worker/protocol.h" #include "../helpers/gui_const.h" struct FuzzerViewMain { From 3bd08ab31cb56ce30aaf6d6953dc3c6a12419072 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Sun, 4 Jun 2023 20:21:51 +0300 Subject: [PATCH 08/31] Fuzzer App: Load key file --- .../pacs_fuzzer/lib/worker/fake_worker.c | 119 +++++++++++++++--- .../pacs_fuzzer/lib/worker/fake_worker.h | 11 ++ .../scenes/fuzzer_scene_field_editor.c | 22 ++++ .../pacs_fuzzer/scenes/fuzzer_scene_main.c | 36 +++++- applications/external/pacs_fuzzer/todo.md | 32 +++++ .../external/pacs_fuzzer/views/field_editor.c | 42 ++++++- .../external/pacs_fuzzer/views/field_editor.h | 11 +- 7 files changed, 247 insertions(+), 26 deletions(-) create mode 100644 applications/external/pacs_fuzzer/todo.md diff --git a/applications/external/pacs_fuzzer/lib/worker/fake_worker.c b/applications/external/pacs_fuzzer/lib/worker/fake_worker.c index ff74f29e1..b44790ebc 100644 --- a/applications/external/pacs_fuzzer/lib/worker/fake_worker.c +++ b/applications/external/pacs_fuzzer/lib/worker/fake_worker.c @@ -12,6 +12,7 @@ #if defined(RFID_125_PROTOCOL) #define MAX_PAYLOAD_SIZE 6 +#include #include #include @@ -44,6 +45,7 @@ struct FuzzerWorker { uint8_t payload[MAX_PAYLOAD_SIZE]; Stream* uids_stream; uint16_t index; + uint8_t chusen_byte; bool treead_running; FuriTimer* timer; @@ -62,12 +64,11 @@ static bool fuzzer_worker_load_key(FuzzerWorker* worker, bool next) { const FuzzerProtocol* protocol = worker->protocol; - if(next) { - worker->index++; - } - switch(worker->attack_type) { case FuzzerWorkerAttackTypeDefaultDict: + if(next) { + worker->index++; + } if(worker->index < protocol->dict.len) { memcpy( worker->payload, @@ -78,6 +79,9 @@ static bool fuzzer_worker_load_key(FuzzerWorker* worker, bool next) { break; case FuzzerWorkerAttackTypeLoadFileCustomUids: { + if(next) { + worker->index++; + } uint8_t str_len = protocol->data_size * 2 + 1; FuriString* data_str = furi_string_alloc(); while(true) { @@ -113,6 +117,14 @@ static bool fuzzer_worker_load_key(FuzzerWorker* worker, bool next) { break; + case FuzzerWorkerAttackTypeLoadFile: + if(worker->payload[worker->index] != 0xFF) { + worker->payload[worker->index]++; + res = true; + } + + break; + default: break; } @@ -170,11 +182,7 @@ void fuzzer_worker_get_current_key(FuzzerWorker* worker, uint8_t* key) { memcpy(key, worker->payload, worker->protocol->data_size); } -bool fuzzer_worker_attack_dict(FuzzerWorker* worker, FuzzerProtos protocol_index) { - furi_assert(worker); - - bool res = false; - +static void fuzzer_worker_set_protocol(FuzzerWorker* worker, FuzzerProtos protocol_index) { worker->protocol = &fuzzer_proto_items[protocol_index]; #if defined(RFID_125_PROTOCOL) @@ -185,6 +193,14 @@ bool fuzzer_worker_attack_dict(FuzzerWorker* worker, FuzzerProtos protocol_index worker->protocol_id = ibutton_protocols_get_id_by_name(worker->protocols_items, worker->protocol->name); #endif +} + +bool fuzzer_worker_attack_dict(FuzzerWorker* worker, FuzzerProtos protocol_index) { + furi_assert(worker); + + bool res = false; + fuzzer_worker_set_protocol(worker, protocol_index); + worker->attack_type = FuzzerWorkerAttackTypeDefaultDict; worker->index = 0; @@ -205,17 +221,7 @@ bool fuzzer_worker_attack_file_dict( furi_assert(file_path); bool res = false; - - worker->protocol = &fuzzer_proto_items[protocol_index]; - -#if defined(RFID_125_PROTOCOL) - worker->protocol_id = - protocol_dict_get_protocol_by_name(worker->protocols_items, worker->protocol->name); -#else - // TODO iButtonProtocolIdInvalid check - worker->protocol_id = - ibutton_protocols_get_id_by_name(worker->protocols_items, worker->protocol->name); -#endif + fuzzer_worker_set_protocol(worker, protocol_index); Storage* storage = furi_record_open(RECORD_STORAGE); worker->uids_stream = buffered_file_stream_alloc(storage); @@ -240,6 +246,79 @@ bool fuzzer_worker_attack_file_dict( return res; } +bool fuzzer_worker_attack_bf_byte( + FuzzerWorker* worker, + FuzzerProtos protocol_index, + const uint8_t* uid, + uint8_t chusen) { + furi_assert(worker); + + bool res = false; + fuzzer_worker_set_protocol(worker, protocol_index); + + worker->attack_type = FuzzerWorkerAttackTypeLoadFile; + worker->index = chusen; + + memcpy(worker->payload, uid, worker->protocol->data_size); + + res = true; + + return res; +} + +// TODO make it protocol independent +bool fuzzer_worker_load_key_from_file( + FuzzerWorker* worker, + FuzzerProtos protocol_index, + const char* filename) { + furi_assert(worker); + + bool res = false; + fuzzer_worker_set_protocol(worker, protocol_index); + +#if defined(RFID_125_PROTOCOL) + ProtocolId loaded_proto_id = lfrfid_dict_file_load(worker->protocols_items, filename); + if(loaded_proto_id == PROTOCOL_NO) { + // Err Cant load file + FURI_LOG_W(TAG, "Cant load file"); + } else if(worker->protocol_id != loaded_proto_id) { // Err wrong protocol + FURI_LOG_W(TAG, "Wrong protocol"); + FURI_LOG_W( + TAG, + "Selected: %s Loaded: %s", + worker->protocol->name, + protocol_dict_get_name(worker->protocols_items, loaded_proto_id)); + } else { + protocol_dict_get_data( + worker->protocols_items, worker->protocol_id, worker->payload, MAX_PAYLOAD_SIZE); + res = true; + } +#else + if(!ibutton_protocols_load(worker->protocols_items, worker->key, filename)) { + // Err Cant load file + FURI_LOG_W(TAG, "Cant load file"); + } else { + if(worker->protocol_id != ibutton_key_get_protocol_id(worker->key)) { + // Err wrong protocol + FURI_LOG_W(TAG, "Wrong protocol"); + FURI_LOG_W( + TAG, + "Selected: %s Loaded: %s", + worker->protocol->name, + ibutton_protocols_get_name( + worker->protocols_items, ibutton_key_get_protocol_id(worker->key))); + } else { + iButtonEditableData data; + ibutton_protocols_get_editable_data(worker->protocols_items, worker->key, &data); + memcpy(worker->payload, data.ptr, data.size); + res = true; + } + } +#endif + + return res; +} + FuzzerWorker* fuzzer_worker_alloc() { FuzzerWorker* worker = malloc(sizeof(FuzzerWorker)); diff --git a/applications/external/pacs_fuzzer/lib/worker/fake_worker.h b/applications/external/pacs_fuzzer/lib/worker/fake_worker.h index 2628ac649..b1eea19fb 100644 --- a/applications/external/pacs_fuzzer/lib/worker/fake_worker.h +++ b/applications/external/pacs_fuzzer/lib/worker/fake_worker.h @@ -27,6 +27,12 @@ void fuzzer_worker_stop(FuzzerWorker* worker); bool fuzzer_worker_attack_dict(FuzzerWorker* worker, FuzzerProtos protocol_index); +bool fuzzer_worker_attack_bf_byte( + FuzzerWorker* worker, + FuzzerProtos protocol_index, + const uint8_t* uid, + uint8_t chusen); + bool fuzzer_worker_attack_file_dict( FuzzerWorker* worker, FuzzerProtos protocol_index, @@ -34,6 +40,11 @@ bool fuzzer_worker_attack_file_dict( void fuzzer_worker_get_current_key(FuzzerWorker* worker, uint8_t* key); +bool fuzzer_worker_load_key_from_file( + FuzzerWorker* worker, + FuzzerProtos protocol_index, + const char* filename); + void fuzzer_worker_set_uid_chaged_callback( FuzzerWorker* worker, FuzzerWorkerUidChagedCallback callback, diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_field_editor.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_field_editor.c index 197bd82c4..52e19e9e0 100644 --- a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_field_editor.c +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_field_editor.c @@ -1,6 +1,8 @@ #include "../fuzzer_i.h" #include "../helpers/fuzzer_custom_event.h" +#define UID_MAX_SIZE 8 // TODO + void fuzzer_scene_field_editor_callback(FuzzerCustomEvent event, void* context) { furi_assert(context); PacsFuzzerApp* app = context; @@ -14,6 +16,17 @@ void fuzzer_scene_field_editor_on_enter(void* context) { fuzzer_view_field_editor_set_callback( app->field_editor_view, fuzzer_scene_field_editor_callback, app); + uint8_t uid[UID_MAX_SIZE]; + + uint8_t* uid_p = &uid[0]; + + fuzzer_worker_get_current_key(app->worker, uid_p); + + fuzzer_view_field_editor_reset_data( + app->field_editor_view, + uid_p, + fuzzer_proto_items[app->fuzzer_state.proto_index].data_size); // TODO + view_dispatcher_switch_to_view(app->view_dispatcher, FuzzerViewIDFieldEditor); } @@ -29,6 +42,15 @@ bool fuzzer_scene_field_editor_on_event(void* context, SceneManagerEvent event) view_dispatcher_stop(app->view_dispatcher); } consumed = true; + } else if(event.event == FuzzerCustomEventViewFieldEditorOk) { + // TODO + if(fuzzer_worker_attack_bf_byte( + app->worker, + app->fuzzer_state.proto_index, + fuzzer_view_field_editor_get_uid(app->field_editor_view), + fuzzer_view_field_editor_get_index(app->field_editor_view))) { + scene_manager_next_scene(app->scene_manager, FuzzerSceneAttack); + } } } diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c index cb5e97c52..3f03835fa 100644 --- a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c @@ -30,6 +30,26 @@ static bool fuzzer_scene_main_load_custom_dict(void* context) { return res; } +static bool fuzzer_scene_main_load_key(void* context) { + furi_assert(context); + PacsFuzzerApp* app = context; + + FuzzerConsts* consts = app->fuzzer_const; + + furi_string_set_str(app->file_path, consts->path_key_folder); + + DialogsFileBrowserOptions browser_options; + dialog_file_browser_set_basic_options( + &browser_options, consts->key_extension, &I_rfid_10px); // TODO icon + browser_options.base_path = consts->path_key_folder; + browser_options.hide_ext = true; + + bool res = + dialog_file_browser_show(app->dialogs, app->file_path, app->file_path, &browser_options); + + return res; +} + void fuzzer_scene_main_on_enter(void* context) { furi_assert(context); PacsFuzzerApp* app = context; @@ -70,9 +90,19 @@ bool fuzzer_scene_main_on_event(void* context, SceneManagerEvent event) { break; case FuzzerMainMenuIndexLoadFile: - // TODO Delete - scene_manager_next_scene(app->scene_manager, FuzzerSceneFieldEditor); - + if(!fuzzer_scene_main_load_key(app)) { + break; + } else { + if(fuzzer_worker_load_key_from_file( + app->worker, + app->fuzzer_state.proto_index, + furi_string_get_cstr(app->file_path))) { + scene_manager_next_scene(app->scene_manager, FuzzerSceneFieldEditor); + FURI_LOG_I("Scene", "Load ok"); + } else { + FURI_LOG_W("Scene", "Load err"); + } + } break; case FuzzerMainMenuIndexLoadFileCustomUids: diff --git a/applications/external/pacs_fuzzer/todo.md b/applications/external/pacs_fuzzer/todo.md new file mode 100644 index 000000000..c96e897e9 --- /dev/null +++ b/applications/external/pacs_fuzzer/todo.md @@ -0,0 +1,32 @@ +## Working Improvement + +#### Quality of life + +- [ ] Make the "Load File" independent of the current protocol +- [ ] Add pause + - [ ] Switching UIDs if possible +- [ ] Led and sound Notification +- [ ] Error Notification + - [ ] Custom UIDs dict loading + - [ ] Key file loading + - [ ] Anything else + +#### App functionality + +- [ ] Add `BFCustomerID` attack +- [ ] Save key logic + +## Code Improvement + +- [ ] GUI + - [ ] Rewrite `gui_const` logic + - [ ] Separate protocol name from `fuzzer_proto_items` + - [ ] Icon in dialog + - [ ] Description and buttons in `field_editor` view + - [ ] Protocol carousel in `main_menu` +- [ ] UID + - [ ] Simplify the storage and exchange of `uids.data` `uid.data_size` in `views` + - [ ] `UID_MAX_SIZE` +- [ ] Add pause + - [ ] Fix `Custom dict` attack when ended +- [ ] this can be simplified `fuzzer_proto_items` diff --git a/applications/external/pacs_fuzzer/views/field_editor.c b/applications/external/pacs_fuzzer/views/field_editor.c index daf8e9d24..f073baf99 100644 --- a/applications/external/pacs_fuzzer/views/field_editor.c +++ b/applications/external/pacs_fuzzer/views/field_editor.c @@ -8,6 +8,8 @@ #define UID_STR_LENGTH 25 #define EDITOR_STRING_Y 50 +#define UID_MAX_SIZE 8 // TODO + struct FuzzerViewFieldEditor { View* view; FuzzerViewFieldEditorCallback callback; @@ -18,8 +20,10 @@ struct FuzzerViewFieldEditor { typedef struct { uint8_t* uid; uint8_t uid_size; - uint8_t index; + FuriString* uid_str; + + uint8_t index; bool lo; } FuzzerViewFieldEditorModel; @@ -33,6 +37,40 @@ void fuzzer_view_field_editor_set_callback( view_edit->context = context; } +void fuzzer_view_field_editor_reset_data( + FuzzerViewFieldEditor* view_edit, + uint8_t* uid, + uint8_t uid_size) { + furi_assert(view_edit); + + with_view_model( + view_edit->view, + FuzzerViewFieldEditorModel * model, + { + memcpy(model->uid, uid, uid_size); + model->index = 0; + model->lo = false; + model->uid_size = uid_size; + }, + true); +} + +const uint8_t* fuzzer_view_field_editor_get_uid(FuzzerViewFieldEditor* view_edit) { + furi_assert(view_edit); + uint8_t* uid; + with_view_model( + view_edit->view, FuzzerViewFieldEditorModel * model, { uid = model->uid; }, true); + return uid; +} + +uint8_t fuzzer_view_field_editor_get_index(FuzzerViewFieldEditor* view_edit) { + furi_assert(view_edit); + uint8_t index; + with_view_model( + view_edit->view, FuzzerViewFieldEditorModel * model, { index = model->index; }, true); + return index; +} + void fuzzer_view_field_editor_draw(Canvas* canvas, FuzzerViewFieldEditorModel* model) { canvas_clear(canvas); canvas_set_color(canvas, ColorBlack); @@ -223,7 +261,7 @@ FuzzerViewFieldEditor* fuzzer_view_field_editor_alloc() { { model->uid_str = furi_string_alloc(); - model->uid = malloc(8); + model->uid = malloc(UID_MAX_SIZE); }, true); diff --git a/applications/external/pacs_fuzzer/views/field_editor.h b/applications/external/pacs_fuzzer/views/field_editor.h index df3aba724..26a8a8ac9 100644 --- a/applications/external/pacs_fuzzer/views/field_editor.h +++ b/applications/external/pacs_fuzzer/views/field_editor.h @@ -16,4 +16,13 @@ FuzzerViewFieldEditor* fuzzer_view_field_editor_alloc(); void fuzzer_view_field_editor_free(FuzzerViewFieldEditor* view_attack); -View* fuzzer_view_field_editor_get_view(FuzzerViewFieldEditor* view_attack); \ No newline at end of file +View* fuzzer_view_field_editor_get_view(FuzzerViewFieldEditor* view_attack); + +void fuzzer_view_field_editor_reset_data( + FuzzerViewFieldEditor* view_edit, + uint8_t* uid, + uint8_t uid_size); + +const uint8_t* fuzzer_view_field_editor_get_uid(FuzzerViewFieldEditor* view_edit); + +uint8_t fuzzer_view_field_editor_get_index(FuzzerViewFieldEditor* view_edit); \ No newline at end of file From b95620cdd0fe8332e9f499551fdd9c6eceef4975 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Mon, 5 Jun 2023 14:10:51 +0300 Subject: [PATCH 09/31] Fuzzer App: Some Improvement --- applications/external/pacs_fuzzer/fuzzer.c | 2 + applications/external/pacs_fuzzer/fuzzer_i.h | 1 + .../external/pacs_fuzzer/helpers/gui_const.c | 7 -- .../external/pacs_fuzzer/helpers/gui_const.h | 12 --- .../pacs_fuzzer/lib/worker/fake_worker.c | 20 ++--- .../pacs_fuzzer/lib/worker/fake_worker.h | 10 +-- .../pacs_fuzzer/lib/worker/protocol.c | 73 +++++++++++++++---- .../pacs_fuzzer/lib/worker/protocol.h | 32 ++++---- .../pacs_fuzzer/lib/worker/protocol_i.h | 64 ++++++++++------ .../pacs_fuzzer/scenes/fuzzer_scene_attack.c | 35 ++++----- .../scenes/fuzzer_scene_field_editor.c | 14 +--- .../pacs_fuzzer/scenes/fuzzer_scene_main.c | 3 +- applications/external/pacs_fuzzer/todo.md | 12 +-- .../external/pacs_fuzzer/views/attack.c | 37 ++++++---- .../external/pacs_fuzzer/views/attack.h | 6 +- .../external/pacs_fuzzer/views/field_editor.c | 12 +-- .../external/pacs_fuzzer/views/field_editor.h | 5 +- .../external/pacs_fuzzer/views/main_menu.c | 32 +++++--- 18 files changed, 218 insertions(+), 159 deletions(-) delete mode 100644 applications/external/pacs_fuzzer/helpers/gui_const.c delete mode 100644 applications/external/pacs_fuzzer/helpers/gui_const.h diff --git a/applications/external/pacs_fuzzer/fuzzer.c b/applications/external/pacs_fuzzer/fuzzer.c index 6b609040c..0a9aa3f7d 100644 --- a/applications/external/pacs_fuzzer/fuzzer.c +++ b/applications/external/pacs_fuzzer/fuzzer.c @@ -113,6 +113,7 @@ int32_t fuzzer_start_ibtn(void* p) { .custom_dict_extension = ".txt", .key_extension = ".ibtn", .path_key_folder = "/ext/ibutton", + .key_icon = &I_ibutt_10px, }; fuzzer_app->fuzzer_const = &app_const; @@ -131,6 +132,7 @@ int32_t fuzzer_start_rfid(void* p) { .custom_dict_extension = ".txt", .key_extension = ".rfid", .path_key_folder = "/ext/lfrfid", + .key_icon = &I_125_10px, }; fuzzer_app->fuzzer_const = &app_const; diff --git a/applications/external/pacs_fuzzer/fuzzer_i.h b/applications/external/pacs_fuzzer/fuzzer_i.h index 59ec2df33..2f24ec431 100644 --- a/applications/external/pacs_fuzzer/fuzzer_i.h +++ b/applications/external/pacs_fuzzer/fuzzer_i.h @@ -28,6 +28,7 @@ typedef struct { const char* custom_dict_folder; const char* key_extension; const char* path_key_folder; + const Icon* key_icon; } FuzzerConsts; typedef struct { diff --git a/applications/external/pacs_fuzzer/helpers/gui_const.c b/applications/external/pacs_fuzzer/helpers/gui_const.c deleted file mode 100644 index 79e31ad1b..000000000 --- a/applications/external/pacs_fuzzer/helpers/gui_const.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "gui_const.h" - -const char* fuzzer_attack_names[FuzzerMainMenuIndexMax] = { - [FuzzerMainMenuIndexDefaultValues] = "Default Values", - [FuzzerMainMenuIndexLoadFile] = "Load File", - [FuzzerMainMenuIndexLoadFileCustomUids] = "Load UIDs from file", -}; \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/helpers/gui_const.h b/applications/external/pacs_fuzzer/helpers/gui_const.h deleted file mode 100644 index 837322c2a..000000000 --- a/applications/external/pacs_fuzzer/helpers/gui_const.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -// TODO replace it -typedef enum { - FuzzerMainMenuIndexDefaultValues = 0, - FuzzerMainMenuIndexLoadFile, - FuzzerMainMenuIndexLoadFileCustomUids, - - FuzzerMainMenuIndexMax, -} FuzzerMainMenuIndex; - -extern const char* fuzzer_attack_names[]; \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/lib/worker/fake_worker.c b/applications/external/pacs_fuzzer/lib/worker/fake_worker.c index b44790ebc..f4a442bc0 100644 --- a/applications/external/pacs_fuzzer/lib/worker/fake_worker.c +++ b/applications/external/pacs_fuzzer/lib/worker/fake_worker.c @@ -1,4 +1,5 @@ #include "fake_worker.h" +#include "protocol_i.h" #include @@ -11,14 +12,12 @@ #if defined(RFID_125_PROTOCOL) -#define MAX_PAYLOAD_SIZE 6 #include #include #include #else -#define MAX_PAYLOAD_SIZE 8 #include #include @@ -175,14 +174,17 @@ static void fuzzer_worker_on_tick_callback(void* context) { } } -void fuzzer_worker_get_current_key(FuzzerWorker* worker, uint8_t* key) { +void fuzzer_worker_get_current_key(FuzzerWorker* worker, FuzzerPayload* output_key) { furi_assert(worker); + furi_assert(output_key); furi_assert(worker->protocol); - memcpy(key, worker->payload, worker->protocol->data_size); + output_key->data_size = worker->protocol->data_size; + output_key->data = malloc(sizeof(output_key->data_size)); + memcpy(output_key->data, worker->payload, worker->protocol->data_size); } -static void fuzzer_worker_set_protocol(FuzzerWorker* worker, FuzzerProtos protocol_index) { +static void fuzzer_worker_set_protocol(FuzzerWorker* worker, FuzzerProtocolsID protocol_index) { worker->protocol = &fuzzer_proto_items[protocol_index]; #if defined(RFID_125_PROTOCOL) @@ -195,7 +197,7 @@ static void fuzzer_worker_set_protocol(FuzzerWorker* worker, FuzzerProtos protoc #endif } -bool fuzzer_worker_attack_dict(FuzzerWorker* worker, FuzzerProtos protocol_index) { +bool fuzzer_worker_attack_dict(FuzzerWorker* worker, FuzzerProtocolsID protocol_index) { furi_assert(worker); bool res = false; @@ -215,7 +217,7 @@ bool fuzzer_worker_attack_dict(FuzzerWorker* worker, FuzzerProtos protocol_index bool fuzzer_worker_attack_file_dict( FuzzerWorker* worker, - FuzzerProtos protocol_index, + FuzzerProtocolsID protocol_index, FuriString* file_path) { furi_assert(worker); furi_assert(file_path); @@ -248,7 +250,7 @@ bool fuzzer_worker_attack_file_dict( bool fuzzer_worker_attack_bf_byte( FuzzerWorker* worker, - FuzzerProtos protocol_index, + FuzzerProtocolsID protocol_index, const uint8_t* uid, uint8_t chusen) { furi_assert(worker); @@ -269,7 +271,7 @@ bool fuzzer_worker_attack_bf_byte( // TODO make it protocol independent bool fuzzer_worker_load_key_from_file( FuzzerWorker* worker, - FuzzerProtos protocol_index, + FuzzerProtocolsID protocol_index, const char* filename) { furi_assert(worker); diff --git a/applications/external/pacs_fuzzer/lib/worker/fake_worker.h b/applications/external/pacs_fuzzer/lib/worker/fake_worker.h index b1eea19fb..fe680f36b 100644 --- a/applications/external/pacs_fuzzer/lib/worker/fake_worker.h +++ b/applications/external/pacs_fuzzer/lib/worker/fake_worker.h @@ -25,24 +25,24 @@ bool fuzzer_worker_start(FuzzerWorker* worker, uint8_t timer_dellay); void fuzzer_worker_stop(FuzzerWorker* worker); -bool fuzzer_worker_attack_dict(FuzzerWorker* worker, FuzzerProtos protocol_index); +bool fuzzer_worker_attack_dict(FuzzerWorker* worker, FuzzerProtocolsID protocol_index); bool fuzzer_worker_attack_bf_byte( FuzzerWorker* worker, - FuzzerProtos protocol_index, + FuzzerProtocolsID protocol_index, const uint8_t* uid, uint8_t chusen); bool fuzzer_worker_attack_file_dict( FuzzerWorker* worker, - FuzzerProtos protocol_index, + FuzzerProtocolsID protocol_index, FuriString* file_path); -void fuzzer_worker_get_current_key(FuzzerWorker* worker, uint8_t* key); +void fuzzer_worker_get_current_key(FuzzerWorker* worker, FuzzerPayload* output_key); bool fuzzer_worker_load_key_from_file( FuzzerWorker* worker, - FuzzerProtos protocol_index, + FuzzerProtocolsID protocol_index, const char* filename); void fuzzer_worker_set_uid_chaged_callback( diff --git a/applications/external/pacs_fuzzer/lib/worker/protocol.c b/applications/external/pacs_fuzzer/lib/worker/protocol.c index b27524d06..b9f9e6bf6 100644 --- a/applications/external/pacs_fuzzer/lib/worker/protocol.c +++ b/applications/external/pacs_fuzzer/lib/worker/protocol.c @@ -1,4 +1,5 @@ -#include "protocol.h" +#include "protocol_i.h" +#include "furi.h" // ####################### // ## Ibutton Protocols ## @@ -156,32 +157,40 @@ const FuzzerProtocol fuzzer_proto_items[] = { .name = "EM4100", .data_size = EM4100_DATA_SIZE, .dict = - {.val = (const uint8_t*)&uid_list_em4100, - .len = sizeof(uid_list_em4100) / EM4100_DATA_SIZE}, + { + .val = (const uint8_t*)&uid_list_em4100, + .len = COUNT_OF(uid_list_em4100), + }, }, [HIDProx] = { .name = "HIDProx", .data_size = HIDProx_DATA_SIZE, .dict = - {.val = (const uint8_t*)&uid_list_hid, - .len = sizeof(uid_list_hid) / HIDProx_DATA_SIZE}, + { + .val = (const uint8_t*)&uid_list_hid, + .len = COUNT_OF(uid_list_hid), + }, }, [PAC] = { .name = "PAC/Stanley", .data_size = PAC_DATA_SIZE, .dict = - {.val = (const uint8_t*)&uid_list_pac, - .len = sizeof(uid_list_pac) / PAC_DATA_SIZE}, + { + .val = (const uint8_t*)&uid_list_pac, + .len = COUNT_OF(uid_list_pac), + }, }, [H10301] = { .name = "H10301", .data_size = H10301_DATA_SIZE, .dict = - {.val = (const uint8_t*)&uid_list_h10301, - .len = sizeof(uid_list_h10301) / H10301_DATA_SIZE}, + { + .val = (const uint8_t*)&uid_list_h10301, + .len = COUNT_OF(uid_list_h10301), + }, }, }; #else @@ -191,24 +200,56 @@ const FuzzerProtocol fuzzer_proto_items[] = { .name = "DS1990", .data_size = DS1990_DATA_SIZE, .dict = - {.val = (const uint8_t*)&uid_list_ds1990, - .len = sizeof(uid_list_ds1990) / DS1990_DATA_SIZE}, + { + .val = (const uint8_t*)&uid_list_ds1990, + .len = COUNT_OF(uid_list_ds1990), + }, }, [Metakom] = { .name = "Metakom", .data_size = Metakom_DATA_SIZE, .dict = - {.val = (const uint8_t*)&uid_list_metakom, - .len = sizeof(uid_list_metakom) / Metakom_DATA_SIZE}, + { + .val = (const uint8_t*)&uid_list_metakom, + .len = COUNT_OF(uid_list_metakom), + }, }, [Cyfral] = { .name = "Cyfral", .data_size = Cyfral_DATA_SIZE, .dict = - {.val = (const uint8_t*)&uid_list_cyfral, - .len = sizeof(uid_list_cyfral) / Cyfral_DATA_SIZE}, + { + .val = (const uint8_t*)&uid_list_cyfral, + .len = COUNT_OF(uid_list_cyfral), + }, }, }; -#endif \ No newline at end of file +#endif + +const char* fuzzer_attack_names[] = { + [FuzzerMainMenuIndexDefaultValues] = "Default Values", + [FuzzerMainMenuIndexLoadFile] = "Load File", + [FuzzerMainMenuIndexLoadFileCustomUids] = "Load UIDs from file", +}; + +const char* fuzzer_proto_get_name(FuzzerProtocolsID index) { + return fuzzer_proto_items[index].name; +} + +uint8_t fuzzer_proto_get_count_of_protocols() { + return COUNT_OF(fuzzer_proto_items); +} + +uint8_t fuzzer_proto_get_max_data_size() { + return MAX_PAYLOAD_SIZE; +} + +const char* fuzzer_proto_get_menu_label(FuzzerMainMenuIndex index) { + return fuzzer_attack_names[index]; +} + +uint8_t fuzzer_proto_get_count_of_menu_items() { + return COUNT_OF(fuzzer_attack_names); +} \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/lib/worker/protocol.h b/applications/external/pacs_fuzzer/lib/worker/protocol.h index a69d3db04..0de1223ff 100644 --- a/applications/external/pacs_fuzzer/lib/worker/protocol.h +++ b/applications/external/pacs_fuzzer/lib/worker/protocol.h @@ -4,8 +4,9 @@ // #define RFID_125_PROTOCOL -typedef enum { +typedef struct FuzzerPayload FuzzerPayload; +typedef enum { #if defined(RFID_125_PROTOCOL) EM4100, HIDProx, @@ -16,24 +17,25 @@ typedef enum { Metakom, Cyfral, #endif +} FuzzerProtocolsID; - // Reserved - FuzzerProtoMax, -} FuzzerProtos; +typedef enum { + FuzzerMainMenuIndexDefaultValues = 0, + FuzzerMainMenuIndexLoadFile, + FuzzerMainMenuIndexLoadFileCustomUids, +} FuzzerMainMenuIndex; -struct ProtoDict { - const uint8_t* val; - const uint8_t len; +struct FuzzerPayload { + uint8_t* data; + uint8_t data_size; }; -typedef struct ProtoDict ProtoDict; +uint8_t fuzzer_proto_get_max_data_size(); -struct FuzzerProtocol { - const char* name; - const uint8_t data_size; - const ProtoDict dict; -}; +const char* fuzzer_proto_get_name(FuzzerProtocolsID index); -typedef struct FuzzerProtocol FuzzerProtocol; +uint8_t fuzzer_proto_get_count_of_protocols(); -extern const FuzzerProtocol fuzzer_proto_items[]; \ No newline at end of file +const char* fuzzer_proto_get_menu_label(FuzzerMainMenuIndex index); + +uint8_t fuzzer_proto_get_count_of_menu_items(); \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/lib/worker/protocol_i.h b/applications/external/pacs_fuzzer/lib/worker/protocol_i.h index e0ab76cb3..841784f16 100644 --- a/applications/external/pacs_fuzzer/lib/worker/protocol_i.h +++ b/applications/external/pacs_fuzzer/lib/worker/protocol_i.h @@ -3,29 +3,45 @@ #include "protocol.h" #if defined(RFID_125_PROTOCOL) - -#define MAX_PAYLOAD_SIZE 6 - -#define FUZZ_TIME_DELAY_MIN (5) -#define FUZZ_TIME_DELAY_DEFAULT (10) -#define FUZZ_TIME_DELAY_MAX (70) - -#define FUZZER_APP_CUSTOM_DICT_EXTENSION ".txt" -#define FUZZER_APP_CUSTOM_DICT_FOLDER "/ext/rfidfuzzer" -#define FUZZER_APP_KEY_EXTENSION ".rfid" -#define FUZZER_APP_PATH_KEY_FOLDER "/ext/lfrfid" - +#define MAX_PAYLOAD_SIZE (6) #else - -#define MAX_PAYLOAD_SIZE 8 - -#define FUZZ_TIME_DELAY_MIN (4) -#define FUZZ_TIME_DELAY_DEFAULT (8) -#define FUZZ_TIME_DELAY_MAX (80) - -#define FUZZER_APP_CUSTOM_DICT_EXTENSION ".txt" -#define FUZZER_APP_CUSTOM_DICT_FOLDER "/ext/ibtnfuzzer" -#define FUZZER_APP_KEY_EXTENSION ".ibtn" -#define FUZZER_APP_PATH_KEY_FOLDER "/ext/ibutton" - +#define MAX_PAYLOAD_SIZE (8) #endif + +typedef struct ProtoDict ProtoDict; +typedef struct FuzzerProtocol FuzzerProtocol; + +struct ProtoDict { + const uint8_t* val; + const uint8_t len; // TODO +}; + +struct FuzzerProtocol { + const char* name; + const uint8_t data_size; + const ProtoDict dict; +}; + +// #define MAX_PAYLOAD_SIZE 6 + +// #define FUZZ_TIME_DELAY_MIN (5) +// #define FUZZ_TIME_DELAY_DEFAULT (10) +// #define FUZZ_TIME_DELAY_MAX (70) + +// #define FUZZER_APP_CUSTOM_DICT_EXTENSION ".txt" +// #define FUZZER_APP_CUSTOM_DICT_FOLDER "/ext/rfidfuzzer" +// #define FUZZER_APP_KEY_EXTENSION ".rfid" +// #define FUZZER_APP_PATH_KEY_FOLDER "/ext/lfrfid" + +// #define MAX_PAYLOAD_SIZE 8 + +// #define FUZZ_TIME_DELAY_MIN (4) +// #define FUZZ_TIME_DELAY_DEFAULT (8) +// #define FUZZ_TIME_DELAY_MAX (80) + +// #define FUZZER_APP_CUSTOM_DICT_EXTENSION ".txt" +// #define FUZZER_APP_CUSTOM_DICT_FOLDER "/ext/ibtnfuzzer" +// #define FUZZER_APP_KEY_EXTENSION ".ibtn" +// #define FUZZER_APP_PATH_KEY_FOLDER "/ext/ibutton" + +extern const FuzzerProtocol fuzzer_proto_items[]; \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c index c18e2cec9..ac3962f32 100644 --- a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c @@ -1,8 +1,6 @@ #include "../fuzzer_i.h" #include "../helpers/fuzzer_custom_event.h" -#include "../helpers/gui_const.h" - // TODO simlify callbacks and attack state void fuzzer_scene_attack_worker_tick_callback(void* context) { @@ -23,30 +21,37 @@ void fuzzer_scene_attack_callback(FuzzerCustomEvent event, void* context) { view_dispatcher_send_custom_event(app->view_dispatcher, event); } +static void fuzzer_scene_attack_update_uid(PacsFuzzerApp* app) { + furi_assert(app); + furi_assert(app->worker); + furi_assert(app->attack_view); + + FuzzerPayload uid; + fuzzer_worker_get_current_key(app->worker, &uid); + + fuzzer_view_attack_set_uid(app->attack_view, uid); + + free(uid.data); +} + void fuzzer_scene_attack_on_enter(void* context) { furi_assert(context); PacsFuzzerApp* app = context; fuzzer_view_attack_set_callback(app->attack_view, fuzzer_scene_attack_callback, app); - FuzzerProtocol proto = fuzzer_proto_items[app->fuzzer_state.proto_index]; - fuzzer_worker_set_uid_chaged_callback( app->worker, fuzzer_scene_attack_worker_tick_callback, app); fuzzer_worker_set_end_callback(app->worker, fuzzer_scene_attack_worker_end_callback, app); - uint8_t temp_uid[proto.data_size]; - - fuzzer_worker_get_current_key(app->worker, temp_uid); - fuzzer_view_attack_reset_data( app->attack_view, - fuzzer_attack_names[app->fuzzer_state.menu_index], - proto.name, - proto.data_size); + fuzzer_proto_get_menu_label(app->fuzzer_state.menu_index), + fuzzer_proto_get_name(app->fuzzer_state.proto_index)); fuzzer_view_attack_set_attack(app->attack_view, false); - fuzzer_view_attack_set_uid(app->attack_view, (uint8_t*)&temp_uid); + + fuzzer_scene_attack_update_uid(app); scene_manager_set_scene_state(app->scene_manager, FuzzerSceneAttack, false); @@ -84,11 +89,7 @@ bool fuzzer_scene_attack_on_event(void* context, SceneManagerEvent event) { } consumed = true; } else if(event.event == FuzzerCustomEventViewAttackTick) { - uint8_t temp_uid[fuzzer_proto_items[app->fuzzer_state.proto_index].data_size]; - - fuzzer_worker_get_current_key(app->worker, temp_uid); - - fuzzer_view_attack_set_uid(app->attack_view, (uint8_t*)&temp_uid); + fuzzer_scene_attack_update_uid(app); consumed = true; } else if(event.event == FuzzerCustomEventViewAttackEnd) { scene_manager_set_scene_state(app->scene_manager, FuzzerSceneAttack, false); diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_field_editor.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_field_editor.c index 52e19e9e0..f8adae0df 100644 --- a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_field_editor.c +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_field_editor.c @@ -1,8 +1,6 @@ #include "../fuzzer_i.h" #include "../helpers/fuzzer_custom_event.h" -#define UID_MAX_SIZE 8 // TODO - void fuzzer_scene_field_editor_callback(FuzzerCustomEvent event, void* context) { furi_assert(context); PacsFuzzerApp* app = context; @@ -16,16 +14,12 @@ void fuzzer_scene_field_editor_on_enter(void* context) { fuzzer_view_field_editor_set_callback( app->field_editor_view, fuzzer_scene_field_editor_callback, app); - uint8_t uid[UID_MAX_SIZE]; + FuzzerPayload uid; + fuzzer_worker_get_current_key(app->worker, &uid); - uint8_t* uid_p = &uid[0]; + fuzzer_view_field_editor_reset_data(app->field_editor_view, uid); - fuzzer_worker_get_current_key(app->worker, uid_p); - - fuzzer_view_field_editor_reset_data( - app->field_editor_view, - uid_p, - fuzzer_proto_items[app->fuzzer_state.proto_index].data_size); // TODO + free(uid.data); view_dispatcher_switch_to_view(app->view_dispatcher, FuzzerViewIDFieldEditor); } diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c index 3f03835fa..e27bc0776 100644 --- a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c @@ -2,7 +2,6 @@ #include "../helpers/fuzzer_custom_event.h" #include "../lib/worker/protocol.h" -#include "../helpers/gui_const.h" void fuzzer_scene_main_callback(FuzzerCustomEvent event, void* context) { furi_assert(context); @@ -40,7 +39,7 @@ static bool fuzzer_scene_main_load_key(void* context) { DialogsFileBrowserOptions browser_options; dialog_file_browser_set_basic_options( - &browser_options, consts->key_extension, &I_rfid_10px); // TODO icon + &browser_options, consts->key_extension, consts->key_icon); browser_options.base_path = consts->path_key_folder; browser_options.hide_ext = true; diff --git a/applications/external/pacs_fuzzer/todo.md b/applications/external/pacs_fuzzer/todo.md index c96e897e9..75e708c06 100644 --- a/applications/external/pacs_fuzzer/todo.md +++ b/applications/external/pacs_fuzzer/todo.md @@ -19,14 +19,14 @@ ## Code Improvement - [ ] GUI - - [ ] Rewrite `gui_const` logic + - [x] Rewrite `gui_const` logic - [ ] Separate protocol name from `fuzzer_proto_items` - - [ ] Icon in dialog + - [x] Icon in dialog - [ ] Description and buttons in `field_editor` view - [ ] Protocol carousel in `main_menu` -- [ ] UID - - [ ] Simplify the storage and exchange of `uids.data` `uid.data_size` in `views` - - [ ] `UID_MAX_SIZE` +- [x] UID + - [x] Simplify the storage and exchange of `uids.data` `uid.data_size` in `views` + - [x] `UID_MAX_SIZE` - [ ] Add pause - [ ] Fix `Custom dict` attack when ended -- [ ] this can be simplified `fuzzer_proto_items` +- [x] this can be simplified `fuzzer_proto_items` diff --git a/applications/external/pacs_fuzzer/views/attack.c b/applications/external/pacs_fuzzer/views/attack.c index 910d69c0c..6ef306f07 100644 --- a/applications/external/pacs_fuzzer/views/attack.c +++ b/applications/external/pacs_fuzzer/views/attack.c @@ -5,6 +5,7 @@ #include #define ATTACK_SCENE_MAX_UID_LENGTH 25 +#define UID_MAX_DISPLAYED_LEN (8U) struct FuzzerViewAttack { View* view; @@ -18,14 +19,12 @@ typedef struct { const char* protocol_name; bool attack_enabled; char* uid; - uint8_t uid_size; } FuzzerViewAttackModel; void fuzzer_view_attack_reset_data( FuzzerViewAttack* view, const char* attack_name, - const char* protocol_name, - uint8_t uid_size) { + const char* protocol_name) { furi_assert(view); with_view_model( @@ -35,32 +34,38 @@ void fuzzer_view_attack_reset_data( model->attack_name = attack_name; model->protocol_name = protocol_name; model->attack_enabled = false; - model->uid_size = uid_size; + strcpy(model->uid, "Not_set"); }, true); } -void fuzzer_view_attack_set_uid(FuzzerViewAttack* view, const uint8_t* uid) { +void fuzzer_view_attack_set_uid(FuzzerViewAttack* view, const FuzzerPayload uid) { furi_assert(view); + // TODO fix it + uint8_t* data = malloc(uid.data_size); + memcpy(data, uid.data, uid.data_size); + with_view_model( view->view, FuzzerViewAttackModel * model, { snprintf( model->uid, - model->uid_size * 3, + uid.data_size * 3, "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X", - uid[0], - uid[1], - uid[2], - uid[3], - uid[4], - uid[5], - uid[6], - uid[7]); + data[0], + data[1], + data[2], + data[3], + data[4], + data[5], + data[6], + data[7]); }, true); + + free(data); } void fuzzer_view_attack_set_attack(FuzzerViewAttack* view, bool attack) { @@ -175,6 +180,10 @@ void fuzzer_view_attack_exit(void* context) { } FuzzerViewAttack* fuzzer_view_attack_alloc() { + if(fuzzer_proto_get_max_data_size() > UID_MAX_DISPLAYED_LEN) { + furi_crash("Maximum of displayed bytes exceeded"); + } + FuzzerViewAttack* view_attack = malloc(sizeof(FuzzerViewAttack)); // View allocation and configuration diff --git a/applications/external/pacs_fuzzer/views/attack.h b/applications/external/pacs_fuzzer/views/attack.h index c8204eb18..e1aa4edae 100644 --- a/applications/external/pacs_fuzzer/views/attack.h +++ b/applications/external/pacs_fuzzer/views/attack.h @@ -2,6 +2,7 @@ #include #include "../helpers/fuzzer_custom_event.h" +#include "../lib/worker/protocol.h" typedef struct FuzzerViewAttack FuzzerViewAttack; @@ -21,10 +22,9 @@ View* fuzzer_view_attack_get_view(FuzzerViewAttack* view_attack); void fuzzer_view_attack_reset_data( FuzzerViewAttack* view, const char* attack_name, - const char* protocol_name, - uint8_t uid_size); + const char* protocol_name); -void fuzzer_view_attack_set_uid(FuzzerViewAttack* view, const uint8_t* uid); +void fuzzer_view_attack_set_uid(FuzzerViewAttack* view, const FuzzerPayload uid); void fuzzer_view_attack_set_attack(FuzzerViewAttack* view, bool attack); diff --git a/applications/external/pacs_fuzzer/views/field_editor.c b/applications/external/pacs_fuzzer/views/field_editor.c index f073baf99..53e15e152 100644 --- a/applications/external/pacs_fuzzer/views/field_editor.c +++ b/applications/external/pacs_fuzzer/views/field_editor.c @@ -8,8 +8,6 @@ #define UID_STR_LENGTH 25 #define EDITOR_STRING_Y 50 -#define UID_MAX_SIZE 8 // TODO - struct FuzzerViewFieldEditor { View* view; FuzzerViewFieldEditorCallback callback; @@ -39,18 +37,17 @@ void fuzzer_view_field_editor_set_callback( void fuzzer_view_field_editor_reset_data( FuzzerViewFieldEditor* view_edit, - uint8_t* uid, - uint8_t uid_size) { + const FuzzerPayload new_uid) { furi_assert(view_edit); with_view_model( view_edit->view, FuzzerViewFieldEditorModel * model, { - memcpy(model->uid, uid, uid_size); + memcpy(model->uid, new_uid.data, new_uid.data_size); model->index = 0; model->lo = false; - model->uid_size = uid_size; + model->uid_size = new_uid.data_size; }, true); } @@ -260,8 +257,7 @@ FuzzerViewFieldEditor* fuzzer_view_field_editor_alloc() { FuzzerViewFieldEditorModel * model, { model->uid_str = furi_string_alloc(); - - model->uid = malloc(UID_MAX_SIZE); + model->uid = malloc(fuzzer_proto_get_max_data_size()); }, true); diff --git a/applications/external/pacs_fuzzer/views/field_editor.h b/applications/external/pacs_fuzzer/views/field_editor.h index 26a8a8ac9..f76b5d336 100644 --- a/applications/external/pacs_fuzzer/views/field_editor.h +++ b/applications/external/pacs_fuzzer/views/field_editor.h @@ -2,6 +2,7 @@ #include #include "../helpers/fuzzer_custom_event.h" +#include "../lib/worker/protocol.h" typedef struct FuzzerViewFieldEditor FuzzerViewFieldEditor; @@ -20,9 +21,9 @@ View* fuzzer_view_field_editor_get_view(FuzzerViewFieldEditor* view_attack); void fuzzer_view_field_editor_reset_data( FuzzerViewFieldEditor* view_edit, - uint8_t* uid, - uint8_t uid_size); + const FuzzerPayload new_uid); +// TODO const uint8_t* fuzzer_view_field_editor_get_uid(FuzzerViewFieldEditor* view_edit); uint8_t fuzzer_view_field_editor_get_index(FuzzerViewFieldEditor* view_edit); \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/views/main_menu.c b/applications/external/pacs_fuzzer/views/main_menu.c index d12c3e380..8194275ec 100644 --- a/applications/external/pacs_fuzzer/views/main_menu.c +++ b/applications/external/pacs_fuzzer/views/main_menu.c @@ -3,7 +3,7 @@ #include -#include "../helpers/gui_const.h" +#include "../lib/worker/protocol.h" struct FuzzerViewMain { View* view; @@ -15,6 +15,8 @@ struct FuzzerViewMain { typedef struct { uint8_t proto_index; uint8_t menu_index; + uint8_t proto_max; + uint8_t menu_max; } FuzzerViewMainModel; void fuzzer_view_main_update_data(FuzzerViewMain* view, FuzzerState state) { @@ -58,23 +60,33 @@ void fuzzer_view_main_draw(Canvas* canvas, FuzzerViewMainModel* model) { if(model->menu_index > 0) { canvas_set_font(canvas, FontSecondary); canvas_draw_str_aligned( - canvas, 64, 24, AlignCenter, AlignTop, fuzzer_attack_names[model->menu_index - 1]); + canvas, + 64, + 24, + AlignCenter, + AlignTop, + fuzzer_proto_get_menu_label(model->menu_index - 1)); } canvas_set_font(canvas, FontPrimary); canvas_draw_str_aligned( - canvas, 64, 36, AlignCenter, AlignTop, fuzzer_attack_names[model->menu_index]); + canvas, 64, 36, AlignCenter, AlignTop, fuzzer_proto_get_menu_label(model->menu_index)); - if(model->menu_index < FuzzerMainMenuIndexMax) { + if(model->menu_index < model->menu_max) { canvas_set_font(canvas, FontSecondary); canvas_draw_str_aligned( - canvas, 64, 48, AlignCenter, AlignTop, fuzzer_attack_names[model->menu_index + 1]); + canvas, + 64, + 48, + AlignCenter, + AlignTop, + fuzzer_proto_get_menu_label(model->menu_index + 1)); } canvas_set_font(canvas, FontPrimary); canvas_draw_str_aligned(canvas, 27, 4, AlignCenter, AlignTop, "<"); canvas_draw_str_aligned( - canvas, 64, 4, AlignCenter, AlignTop, fuzzer_proto_items[model->proto_index].name); + canvas, 64, 4, AlignCenter, AlignTop, fuzzer_proto_get_name(model->proto_index)); canvas_draw_str_aligned(canvas, 101, 4, AlignCenter, AlignTop, ">"); } @@ -94,7 +106,7 @@ bool fuzzer_view_main_input(InputEvent* event, void* context) { view->view, FuzzerViewMainModel * model, { - if(model->menu_index < (FuzzerMainMenuIndexMax - 1)) { + if(model->menu_index < (model->menu_max - 1)) { model->menu_index++; } }, @@ -119,7 +131,7 @@ bool fuzzer_view_main_input(InputEvent* event, void* context) { if(model->proto_index != 0) { model->proto_index--; } else { - model->proto_index = (FuzzerProtoMax - 1); + model->proto_index = (model->proto_max - 1); } }, true); @@ -129,7 +141,7 @@ bool fuzzer_view_main_input(InputEvent* event, void* context) { view->view, FuzzerViewMainModel * model, { - if(model->proto_index == (FuzzerProtoMax - 1)) { + if(model->proto_index == (model->proto_max - 1)) { model->proto_index = 0; } else { model->proto_index++; @@ -167,7 +179,9 @@ FuzzerViewMain* fuzzer_view_main_alloc() { FuzzerViewMainModel * model, { model->proto_index = 0; + model->proto_max = fuzzer_proto_get_count_of_protocols(); model->menu_index = 0; + model->menu_max = fuzzer_proto_get_count_of_menu_items(); }, true); return view; From 6eed74c71628f4a1e98fda43f58b3d4bb1077293 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Mon, 5 Jun 2023 14:35:15 +0300 Subject: [PATCH 10/31] Fuzzer App: prtocol carusel prototype --- .../pacs_fuzzer/helpers/fuzzer_types.h | 1 - applications/external/pacs_fuzzer/todo.md | 1 + .../external/pacs_fuzzer/views/main_menu.c | 35 +++++++++++++++++-- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/applications/external/pacs_fuzzer/helpers/fuzzer_types.h b/applications/external/pacs_fuzzer/helpers/fuzzer_types.h index 7e390f875..a50b89c61 100644 --- a/applications/external/pacs_fuzzer/helpers/fuzzer_types.h +++ b/applications/external/pacs_fuzzer/helpers/fuzzer_types.h @@ -1,7 +1,6 @@ #pragma once #include -#include typedef struct { uint8_t menu_index; diff --git a/applications/external/pacs_fuzzer/todo.md b/applications/external/pacs_fuzzer/todo.md index 75e708c06..1b56ec189 100644 --- a/applications/external/pacs_fuzzer/todo.md +++ b/applications/external/pacs_fuzzer/todo.md @@ -24,6 +24,7 @@ - [x] Icon in dialog - [ ] Description and buttons in `field_editor` view - [ ] Protocol carousel in `main_menu` + - [x] prototype - [x] UID - [x] Simplify the storage and exchange of `uids.data` `uid.data_size` in `views` - [x] `UID_MAX_SIZE` diff --git a/applications/external/pacs_fuzzer/views/main_menu.c b/applications/external/pacs_fuzzer/views/main_menu.c index 8194275ec..8c4c23603 100644 --- a/applications/external/pacs_fuzzer/views/main_menu.c +++ b/applications/external/pacs_fuzzer/views/main_menu.c @@ -5,6 +5,9 @@ #include "../lib/worker/protocol.h" +#define PROTOCOL_NAME_Y 12 +// #define PROTOCOL_CAROUSEL + struct FuzzerViewMain { View* view; FuzzerViewMainCallback callback; @@ -84,10 +87,36 @@ void fuzzer_view_main_draw(Canvas* canvas, FuzzerViewMainModel* model) { } canvas_set_font(canvas, FontPrimary); - canvas_draw_str_aligned(canvas, 27, 4, AlignCenter, AlignTop, "<"); + canvas_draw_str_aligned(canvas, 27, PROTOCOL_NAME_Y, AlignCenter, AlignBottom, "<"); canvas_draw_str_aligned( - canvas, 64, 4, AlignCenter, AlignTop, fuzzer_proto_get_name(model->proto_index)); - canvas_draw_str_aligned(canvas, 101, 4, AlignCenter, AlignTop, ">"); + canvas, + 64, + PROTOCOL_NAME_Y, + AlignCenter, + AlignBottom, + fuzzer_proto_get_name(model->proto_index)); + canvas_draw_str_aligned(canvas, 101, PROTOCOL_NAME_Y, AlignCenter, AlignBottom, ">"); + +#ifdef PROTOCOL_CAROUSEL + canvas_set_font(canvas, FontSecondary); + canvas_draw_str_aligned( + canvas, + 20, + PROTOCOL_NAME_Y, + AlignRight, + AlignBottom, + (model->proto_index > 0) ? fuzzer_proto_get_name(model->proto_index - 1) : + fuzzer_proto_get_name((model->proto_max - 1))); + canvas_draw_str_aligned( + canvas, + 108, + PROTOCOL_NAME_Y, + AlignLeft, + AlignBottom, + (model->proto_index < (model->proto_max - 1)) ? + fuzzer_proto_get_name(model->proto_index + 1) : + fuzzer_proto_get_name(0)); +#endif } bool fuzzer_view_main_input(InputEvent* event, void* context) { From d3eb43ce3537643f78840b248e4f186d0cd160bb Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Mon, 5 Jun 2023 17:49:30 +0300 Subject: [PATCH 11/31] Fuzzer App: Attack state --- .../pacs_fuzzer/helpers/fuzzer_types.h | 8 +++ .../pacs_fuzzer/lib/worker/fake_worker.c | 35 +++++++++-- .../pacs_fuzzer/lib/worker/fake_worker.h | 2 + .../pacs_fuzzer/scenes/fuzzer_scene_attack.c | 53 ++++++++++------ applications/external/pacs_fuzzer/todo.md | 6 +- .../external/pacs_fuzzer/views/attack.c | 63 ++++++++++++++++--- .../external/pacs_fuzzer/views/attack.h | 11 +++- 7 files changed, 143 insertions(+), 35 deletions(-) diff --git a/applications/external/pacs_fuzzer/helpers/fuzzer_types.h b/applications/external/pacs_fuzzer/helpers/fuzzer_types.h index a50b89c61..259fc2b52 100644 --- a/applications/external/pacs_fuzzer/helpers/fuzzer_types.h +++ b/applications/external/pacs_fuzzer/helpers/fuzzer_types.h @@ -7,6 +7,14 @@ typedef struct { uint8_t proto_index; } FuzzerState; +typedef enum { + FuzzerAttackStateOff = 0, + FuzzerAttackStateIdle, + FuzzerAttackStateRunning, + FuzzerAttackStateEnd, + +} FuzzerAttackState; + typedef enum { FuzzerViewIDMain, FuzzerViewIDAttack, diff --git a/applications/external/pacs_fuzzer/lib/worker/fake_worker.c b/applications/external/pacs_fuzzer/lib/worker/fake_worker.c index f4a442bc0..97f632085 100644 --- a/applications/external/pacs_fuzzer/lib/worker/fake_worker.c +++ b/applications/external/pacs_fuzzer/lib/worker/fake_worker.c @@ -156,7 +156,7 @@ static void fuzzer_worker_on_tick_callback(void* context) { } if(!fuzzer_worker_load_key(worker, true)) { - fuzzer_worker_stop(worker); + fuzzer_worker_pause(worker); // XXX if(worker->end_callback) { worker->end_callback(worker->end_context); } @@ -377,12 +377,23 @@ bool fuzzer_worker_start(FuzzerWorker* worker, uint8_t timer_dellay) { furi_timer_start(worker->timer, furi_ms_to_ticks(timer_dellay * 100)); - worker->treead_running = true; + if(!worker->treead_running) { #if defined(RFID_125_PROTOCOL) - lfrfid_worker_start_thread(worker->proto_worker); + lfrfid_worker_start_thread(worker->proto_worker); +#else + ibutton_worker_start_thread(worker->proto_worker); +#endif + FURI_LOG_D(TAG, "Worker Starting"); + worker->treead_running = true; + } else { + FURI_LOG_D(TAG, "Worker UnPaused"); + } + +#if defined(RFID_125_PROTOCOL) + // lfrfid_worker_start_thread(worker->proto_worker); lfrfid_worker_emulate_start(worker->proto_worker, worker->protocol_id); #else - ibutton_worker_start_thread(worker->proto_worker); + // ibutton_worker_start_thread(worker->proto_worker); ibutton_worker_emulate_start(worker->proto_worker, worker->key); #endif return true; @@ -390,6 +401,21 @@ bool fuzzer_worker_start(FuzzerWorker* worker, uint8_t timer_dellay) { return false; } +void fuzzer_worker_pause(FuzzerWorker* worker) { + furi_assert(worker); + + furi_timer_stop(worker->timer); + + if(worker->treead_running) { +#if defined(RFID_125_PROTOCOL) + lfrfid_worker_stop(worker->proto_worker); +#else + ibutton_worker_stop(worker->proto_worker); +#endif + FURI_LOG_D(TAG, "Worker Paused"); + } +} + void fuzzer_worker_stop(FuzzerWorker* worker) { furi_assert(worker); @@ -403,6 +429,7 @@ void fuzzer_worker_stop(FuzzerWorker* worker) { ibutton_worker_stop(worker->proto_worker); ibutton_worker_stop_thread(worker->proto_worker); #endif + FURI_LOG_D(TAG, "Worker Stopping"); worker->treead_running = false; } diff --git a/applications/external/pacs_fuzzer/lib/worker/fake_worker.h b/applications/external/pacs_fuzzer/lib/worker/fake_worker.h index fe680f36b..2f8733393 100644 --- a/applications/external/pacs_fuzzer/lib/worker/fake_worker.h +++ b/applications/external/pacs_fuzzer/lib/worker/fake_worker.h @@ -25,6 +25,8 @@ bool fuzzer_worker_start(FuzzerWorker* worker, uint8_t timer_dellay); void fuzzer_worker_stop(FuzzerWorker* worker); +void fuzzer_worker_pause(FuzzerWorker* worker); + bool fuzzer_worker_attack_dict(FuzzerWorker* worker, FuzzerProtocolsID protocol_index); bool fuzzer_worker_attack_bf_byte( diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c index ac3962f32..61fa84261 100644 --- a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c @@ -49,11 +49,10 @@ void fuzzer_scene_attack_on_enter(void* context) { app->attack_view, fuzzer_proto_get_menu_label(app->fuzzer_state.menu_index), fuzzer_proto_get_name(app->fuzzer_state.proto_index)); - fuzzer_view_attack_set_attack(app->attack_view, false); fuzzer_scene_attack_update_uid(app); - scene_manager_set_scene_state(app->scene_manager, FuzzerSceneAttack, false); + scene_manager_set_scene_state(app->scene_manager, FuzzerSceneAttack, FuzzerAttackStateIdle); view_dispatcher_switch_to_view(app->view_dispatcher, FuzzerViewIDAttack); } @@ -65,35 +64,53 @@ bool fuzzer_scene_attack_on_event(void* context, SceneManagerEvent event) { if(event.type == SceneManagerEventTypeCustom) { if(event.event == FuzzerCustomEventViewAttackBack) { - if(!scene_manager_get_scene_state(app->scene_manager, FuzzerSceneAttack)) { + if(scene_manager_get_scene_state(app->scene_manager, FuzzerSceneAttack) == + FuzzerAttackStateRunning) { + // Pause if attack running + fuzzer_worker_pause(app->worker); + scene_manager_set_scene_state( + app->scene_manager, FuzzerSceneAttack, FuzzerAttackStateIdle); + fuzzer_view_attack_pause(app->attack_view); + } else { + // Exit + fuzzer_worker_stop(app->worker); + scene_manager_set_scene_state( + app->scene_manager, FuzzerSceneAttack, FuzzerAttackStateOff); + fuzzer_view_attack_stop(app->attack_view); if(!scene_manager_previous_scene(app->scene_manager)) { scene_manager_stop(app->scene_manager); view_dispatcher_stop(app->view_dispatcher); } - } else { - scene_manager_set_scene_state(app->scene_manager, FuzzerSceneAttack, false); - fuzzer_view_attack_set_attack(app->attack_view, false); - fuzzer_worker_stop(app->worker); } consumed = true; } else if(event.event == FuzzerCustomEventViewAttackOk) { - if(!scene_manager_get_scene_state(app->scene_manager, FuzzerSceneAttack) && - fuzzer_worker_start( - app->worker, fuzzer_view_attack_get_time_delay(app->attack_view))) { - scene_manager_set_scene_state(app->scene_manager, FuzzerSceneAttack, true); - fuzzer_view_attack_set_attack(app->attack_view, true); - } else { - scene_manager_set_scene_state(app->scene_manager, FuzzerSceneAttack, false); - fuzzer_view_attack_set_attack(app->attack_view, false); - fuzzer_worker_stop(app->worker); + if(scene_manager_get_scene_state(app->scene_manager, FuzzerSceneAttack) == + FuzzerAttackStateIdle) { + // Start or Continue Attack + if(fuzzer_worker_start( + app->worker, fuzzer_view_attack_get_time_delay(app->attack_view))) { + scene_manager_set_scene_state( + app->scene_manager, FuzzerSceneAttack, FuzzerAttackStateRunning); + fuzzer_view_attack_start(app->attack_view); + } else { + // Error? + } + } else if( + scene_manager_get_scene_state(app->scene_manager, FuzzerSceneAttack) == + FuzzerAttackStateRunning) { + scene_manager_set_scene_state( + app->scene_manager, FuzzerSceneAttack, FuzzerAttackStateIdle); + fuzzer_view_attack_pause(app->attack_view); + fuzzer_worker_pause(app->worker); // XXX } consumed = true; } else if(event.event == FuzzerCustomEventViewAttackTick) { fuzzer_scene_attack_update_uid(app); consumed = true; } else if(event.event == FuzzerCustomEventViewAttackEnd) { - scene_manager_set_scene_state(app->scene_manager, FuzzerSceneAttack, false); - fuzzer_view_attack_set_attack(app->attack_view, false); + scene_manager_set_scene_state( + app->scene_manager, FuzzerSceneAttack, FuzzerAttackStateEnd); + fuzzer_view_attack_end(app->attack_view); consumed = true; } } diff --git a/applications/external/pacs_fuzzer/todo.md b/applications/external/pacs_fuzzer/todo.md index 1b56ec189..dd6f4fc69 100644 --- a/applications/external/pacs_fuzzer/todo.md +++ b/applications/external/pacs_fuzzer/todo.md @@ -3,7 +3,7 @@ #### Quality of life - [ ] Make the "Load File" independent of the current protocol -- [ ] Add pause +- [x] Add pause - [ ] Switching UIDs if possible - [ ] Led and sound Notification - [ ] Error Notification @@ -28,6 +28,6 @@ - [x] UID - [x] Simplify the storage and exchange of `uids.data` `uid.data_size` in `views` - [x] `UID_MAX_SIZE` -- [ ] Add pause - - [ ] Fix `Custom dict` attack when ended +- [x] Add pause + - [x] Fix `Custom dict` attack when ended - [x] this can be simplified `fuzzer_proto_items` diff --git a/applications/external/pacs_fuzzer/views/attack.c b/applications/external/pacs_fuzzer/views/attack.c index 6ef306f07..ad99f0132 100644 --- a/applications/external/pacs_fuzzer/views/attack.c +++ b/applications/external/pacs_fuzzer/views/attack.c @@ -17,7 +17,7 @@ typedef struct { uint8_t time_delay; const char* attack_name; const char* protocol_name; - bool attack_enabled; + FuzzerAttackState attack_state; char* uid; } FuzzerViewAttackModel; @@ -33,7 +33,7 @@ void fuzzer_view_attack_reset_data( { model->attack_name = attack_name; model->protocol_name = protocol_name; - model->attack_enabled = false; + model->attack_state = FuzzerAttackStateIdle; strcpy(model->uid, "Not_set"); }, true); @@ -68,11 +68,44 @@ void fuzzer_view_attack_set_uid(FuzzerViewAttack* view, const FuzzerPayload uid) free(data); } -void fuzzer_view_attack_set_attack(FuzzerViewAttack* view, bool attack) { +void fuzzer_view_attack_start(FuzzerViewAttack* view) { furi_assert(view); with_view_model( - view->view, FuzzerViewAttackModel * model, { model->attack_enabled = attack; }, true); + view->view, + FuzzerViewAttackModel * model, + { model->attack_state = FuzzerAttackStateRunning; }, + true); +} + +void fuzzer_view_attack_stop(FuzzerViewAttack* view) { + furi_assert(view); + + with_view_model( + view->view, + FuzzerViewAttackModel * model, + { model->attack_state = FuzzerAttackStateOff; }, + true); +} + +void fuzzer_view_attack_pause(FuzzerViewAttack* view) { + furi_assert(view); + + with_view_model( + view->view, + FuzzerViewAttackModel * model, + { model->attack_state = FuzzerAttackStateIdle; }, + true); +} + +void fuzzer_view_attack_end(FuzzerViewAttack* view) { + furi_assert(view); + + with_view_model( + view->view, + FuzzerViewAttackModel * model, + { model->attack_state = FuzzerAttackStateEnd; }, + true); } void fuzzer_view_attack_set_callback( @@ -106,12 +139,15 @@ void fuzzer_view_attack_draw(Canvas* canvas, FuzzerViewAttackModel* model) { canvas_draw_str_aligned(canvas, 64, 38, AlignCenter, AlignTop, model->uid); canvas_set_font(canvas, FontSecondary); - if(model->attack_enabled) { + if(model->attack_state == FuzzerAttackStateRunning) { elements_button_center(canvas, "Stop"); - } else { + } else if(model->attack_state == FuzzerAttackStateIdle) { elements_button_center(canvas, "Start"); elements_button_left(canvas, "TD -"); elements_button_right(canvas, "+ TD"); + } else if(model->attack_state == FuzzerAttackStateEnd) { + // elements_button_center(canvas, "Restart"); // Reset + elements_button_left(canvas, "Exit"); } } @@ -130,7 +166,8 @@ bool fuzzer_view_attack_input(InputEvent* event, void* context) { view_attack->view, FuzzerViewAttackModel * model, { - if(!model->attack_enabled) { + if(model->attack_state == FuzzerAttackStateIdle) { + // TimeDelay if(event->type == InputTypeShort) { if(model->time_delay > FUZZ_TIME_DELAY_MIN) { model->time_delay--; @@ -142,6 +179,11 @@ bool fuzzer_view_attack_input(InputEvent* event, void* context) { model->time_delay = FUZZ_TIME_DELAY_MIN; } } + } else if( + (model->attack_state == FuzzerAttackStateEnd) && + (event->type == InputTypeShort)) { + // Exit if Ended + view_attack->callback(FuzzerCustomEventViewAttackBack, view_attack->context); } }, true); @@ -151,7 +193,8 @@ bool fuzzer_view_attack_input(InputEvent* event, void* context) { view_attack->view, FuzzerViewAttackModel * model, { - if(!model->attack_enabled) { + if(model->attack_state == FuzzerAttackStateIdle) { + // TimeDelay if(event->type == InputTypeShort) { if(model->time_delay < FUZZ_TIME_DELAY_MAX) { model->time_delay++; @@ -162,6 +205,8 @@ bool fuzzer_view_attack_input(InputEvent* event, void* context) { model->time_delay = FUZZ_TIME_DELAY_MAX; } } + } else { + // Nothing } }, true); @@ -201,7 +246,7 @@ FuzzerViewAttack* fuzzer_view_attack_alloc() { { model->time_delay = FUZZ_TIME_DELAY_MIN; model->uid = malloc(ATTACK_SCENE_MAX_UID_LENGTH + 1); - model->attack_enabled = false; + model->attack_state = FuzzerAttackStateOff; strcpy(model->uid, "Not_set"); model->attack_name = "Not_set"; diff --git a/applications/external/pacs_fuzzer/views/attack.h b/applications/external/pacs_fuzzer/views/attack.h index e1aa4edae..41fd857bf 100644 --- a/applications/external/pacs_fuzzer/views/attack.h +++ b/applications/external/pacs_fuzzer/views/attack.h @@ -1,7 +1,10 @@ #pragma once #include + #include "../helpers/fuzzer_custom_event.h" +#include "../helpers/fuzzer_types.h" + #include "../lib/worker/protocol.h" typedef struct FuzzerViewAttack FuzzerViewAttack; @@ -26,6 +29,12 @@ void fuzzer_view_attack_reset_data( void fuzzer_view_attack_set_uid(FuzzerViewAttack* view, const FuzzerPayload uid); -void fuzzer_view_attack_set_attack(FuzzerViewAttack* view, bool attack); +void fuzzer_view_attack_start(FuzzerViewAttack* view); + +void fuzzer_view_attack_stop(FuzzerViewAttack* view); + +void fuzzer_view_attack_pause(FuzzerViewAttack* view); + +void fuzzer_view_attack_end(FuzzerViewAttack* view); uint8_t fuzzer_view_attack_get_time_delay(FuzzerViewAttack* view); \ No newline at end of file From 6a9f396663092a90241399148a102bdaef57739f Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Mon, 5 Jun 2023 20:24:38 +0300 Subject: [PATCH 12/31] Fuzzer App: Some description --- .../pacs_fuzzer/lib/worker/fake_worker.c | 293 +++++++++--------- .../pacs_fuzzer/lib/worker/fake_worker.h | 111 ++++++- .../pacs_fuzzer/lib/worker/protocol.h | 22 ++ .../scenes/fuzzer_scene_field_editor.c | 2 +- .../pacs_fuzzer/scenes/fuzzer_scene_main.c | 5 +- 5 files changed, 268 insertions(+), 165 deletions(-) diff --git a/applications/external/pacs_fuzzer/lib/worker/fake_worker.c b/applications/external/pacs_fuzzer/lib/worker/fake_worker.c index 97f632085..9d3d89cdf 100644 --- a/applications/external/pacs_fuzzer/lib/worker/fake_worker.c +++ b/applications/external/pacs_fuzzer/lib/worker/fake_worker.c @@ -56,22 +56,22 @@ struct FuzzerWorker { void* end_context; }; -static bool fuzzer_worker_load_key(FuzzerWorker* worker, bool next) { - furi_assert(worker); - furi_assert(worker->protocol); +static bool fuzzer_worker_load_key(FuzzerWorker* instance, bool next) { + furi_assert(instance); + furi_assert(instance->protocol); bool res = false; - const FuzzerProtocol* protocol = worker->protocol; + const FuzzerProtocol* protocol = instance->protocol; - switch(worker->attack_type) { + switch(instance->attack_type) { case FuzzerWorkerAttackTypeDefaultDict: if(next) { - worker->index++; + instance->index++; } - if(worker->index < protocol->dict.len) { + if(instance->index < protocol->dict.len) { memcpy( - worker->payload, - &protocol->dict.val[worker->index * protocol->data_size], + instance->payload, + &protocol->dict.val[instance->index * protocol->data_size], protocol->data_size); res = true; } @@ -79,14 +79,14 @@ static bool fuzzer_worker_load_key(FuzzerWorker* worker, bool next) { case FuzzerWorkerAttackTypeLoadFileCustomUids: { if(next) { - worker->index++; + instance->index++; } uint8_t str_len = protocol->data_size * 2 + 1; FuriString* data_str = furi_string_alloc(); while(true) { furi_string_reset(data_str); - if(!stream_read_line(worker->uids_stream, data_str)) { - stream_rewind(worker->uids_stream); + if(!stream_read_line(instance->uids_stream, data_str)) { + stream_rewind(instance->uids_stream); // TODO Check empty file & close stream and storage break; } else if(furi_string_get_char(data_str, 0) == '#') { @@ -103,7 +103,7 @@ static bool fuzzer_worker_load_key(FuzzerWorker* worker, bool next) { if(!hex_char_to_uint8( furi_string_get_cstr(data_str)[i * 2], furi_string_get_cstr(data_str)[i * 2 + 1], - &worker->payload[i])) { + &instance->payload[i])) { parse_ok = false; break; } @@ -117,8 +117,8 @@ static bool fuzzer_worker_load_key(FuzzerWorker* worker, bool next) { break; case FuzzerWorkerAttackTypeLoadFile: - if(worker->payload[worker->index] != 0xFF) { - worker->payload[worker->index]++; + if(instance->payload[instance->index] != 0xFF) { + instance->payload[instance->index]++; res = true; } @@ -129,15 +129,15 @@ static bool fuzzer_worker_load_key(FuzzerWorker* worker, bool next) { } #if defined(RFID_125_PROTOCOL) protocol_dict_set_data( - worker->protocols_items, worker->protocol_id, worker->payload, MAX_PAYLOAD_SIZE); + instance->protocols_items, instance->protocol_id, instance->payload, MAX_PAYLOAD_SIZE); #else - ibutton_key_set_protocol_id(worker->key, worker->protocol_id); + ibutton_key_set_protocol_id(instance->key, instance->protocol_id); iButtonEditableData data; - ibutton_protocols_get_editable_data(worker->protocols_items, worker->key, &data); + ibutton_protocols_get_editable_data(instance->protocols_items, instance->key, &data); // TODO check data.size logic data.size = MAX_PAYLOAD_SIZE; - memcpy(data.ptr, worker->payload, MAX_PAYLOAD_SIZE); // data.size); + memcpy(data.ptr, instance->payload, MAX_PAYLOAD_SIZE); // data.size); #endif return res; } @@ -145,69 +145,69 @@ static bool fuzzer_worker_load_key(FuzzerWorker* worker, bool next) { static void fuzzer_worker_on_tick_callback(void* context) { furi_assert(context); - FuzzerWorker* worker = context; + FuzzerWorker* instance = context; - if(worker->treead_running) { + if(instance->treead_running) { #if defined(RFID_125_PROTOCOL) - lfrfid_worker_stop(worker->proto_worker); + lfrfid_worker_stop(instance->proto_worker); #else - ibutton_worker_stop(worker->proto_worker); + ibutton_worker_stop(instance->proto_worker); #endif } - if(!fuzzer_worker_load_key(worker, true)) { - fuzzer_worker_pause(worker); // XXX - if(worker->end_callback) { - worker->end_callback(worker->end_context); + if(!fuzzer_worker_load_key(instance, true)) { + fuzzer_worker_pause(instance); // XXX + if(instance->end_callback) { + instance->end_callback(instance->end_context); } } else { - if(worker->treead_running) { + if(instance->treead_running) { #if defined(RFID_125_PROTOCOL) - lfrfid_worker_emulate_start(worker->proto_worker, worker->protocol_id); + lfrfid_worker_emulate_start(instance->proto_worker, instance->protocol_id); #else - ibutton_worker_emulate_start(worker->proto_worker, worker->key); + ibutton_worker_emulate_start(instance->proto_worker, instance->key); #endif } - if(worker->tick_callback) { - worker->tick_callback(worker->tick_context); + if(instance->tick_callback) { + instance->tick_callback(instance->tick_context); } } } -void fuzzer_worker_get_current_key(FuzzerWorker* worker, FuzzerPayload* output_key) { - furi_assert(worker); +void fuzzer_worker_get_current_key(FuzzerWorker* instance, FuzzerPayload* output_key) { + furi_assert(instance); furi_assert(output_key); - furi_assert(worker->protocol); + furi_assert(instance->protocol); - output_key->data_size = worker->protocol->data_size; + output_key->data_size = instance->protocol->data_size; output_key->data = malloc(sizeof(output_key->data_size)); - memcpy(output_key->data, worker->payload, worker->protocol->data_size); + memcpy(output_key->data, instance->payload, instance->protocol->data_size); } -static void fuzzer_worker_set_protocol(FuzzerWorker* worker, FuzzerProtocolsID protocol_index) { - worker->protocol = &fuzzer_proto_items[protocol_index]; +static void fuzzer_worker_set_protocol(FuzzerWorker* instance, FuzzerProtocolsID protocol_index) { + instance->protocol = &fuzzer_proto_items[protocol_index]; #if defined(RFID_125_PROTOCOL) - worker->protocol_id = - protocol_dict_get_protocol_by_name(worker->protocols_items, worker->protocol->name); + instance->protocol_id = + protocol_dict_get_protocol_by_name(instance->protocols_items, instance->protocol->name); #else // TODO iButtonProtocolIdInvalid check - worker->protocol_id = - ibutton_protocols_get_id_by_name(worker->protocols_items, worker->protocol->name); + instance->protocol_id = + ibutton_protocols_get_id_by_name(instance->protocols_items, instance->protocol->name); #endif } -bool fuzzer_worker_attack_dict(FuzzerWorker* worker, FuzzerProtocolsID protocol_index) { - furi_assert(worker); +bool fuzzer_worker_init_attack_dict(FuzzerWorker* instance, FuzzerProtocolsID protocol_index) { + furi_assert(instance); bool res = false; - fuzzer_worker_set_protocol(worker, protocol_index); + fuzzer_worker_set_protocol(instance, protocol_index); - worker->attack_type = FuzzerWorkerAttackTypeDefaultDict; - worker->index = 0; + instance->attack_type = FuzzerWorkerAttackTypeDefaultDict; + instance->index = 0; - if(!fuzzer_worker_load_key(worker, false)) { - worker->attack_type = FuzzerWorkerAttackTypeMax; + if(!fuzzer_worker_load_key(instance, false)) { + instance->attack_type = FuzzerWorkerAttackTypeMax; } else { res = true; } @@ -215,31 +215,31 @@ bool fuzzer_worker_attack_dict(FuzzerWorker* worker, FuzzerProtocolsID protocol_ return res; } -bool fuzzer_worker_attack_file_dict( - FuzzerWorker* worker, +bool fuzzer_worker_init_attack_file_dict( + FuzzerWorker* instance, FuzzerProtocolsID protocol_index, FuriString* file_path) { - furi_assert(worker); + furi_assert(instance); furi_assert(file_path); bool res = false; - fuzzer_worker_set_protocol(worker, protocol_index); + fuzzer_worker_set_protocol(instance, protocol_index); Storage* storage = furi_record_open(RECORD_STORAGE); - worker->uids_stream = buffered_file_stream_alloc(storage); + instance->uids_stream = buffered_file_stream_alloc(storage); if(!buffered_file_stream_open( - worker->uids_stream, furi_string_get_cstr(file_path), FSAM_READ, FSOM_OPEN_EXISTING)) { - buffered_file_stream_close(worker->uids_stream); + instance->uids_stream, furi_string_get_cstr(file_path), FSAM_READ, FSOM_OPEN_EXISTING)) { + buffered_file_stream_close(instance->uids_stream); return res; } - worker->attack_type = FuzzerWorkerAttackTypeLoadFileCustomUids; - worker->index = 0; + instance->attack_type = FuzzerWorkerAttackTypeLoadFileCustomUids; + instance->index = 0; - if(!fuzzer_worker_load_key(worker, false)) { - worker->attack_type = FuzzerWorkerAttackTypeMax; - buffered_file_stream_close(worker->uids_stream); + if(!fuzzer_worker_load_key(instance, false)) { + instance->attack_type = FuzzerWorkerAttackTypeMax; + buffered_file_stream_close(instance->uids_stream); furi_record_close(RECORD_STORAGE); } else { res = true; @@ -248,20 +248,20 @@ bool fuzzer_worker_attack_file_dict( return res; } -bool fuzzer_worker_attack_bf_byte( - FuzzerWorker* worker, +bool fuzzer_worker_init_attack_bf_byte( + FuzzerWorker* instance, FuzzerProtocolsID protocol_index, const uint8_t* uid, uint8_t chusen) { - furi_assert(worker); + furi_assert(instance); bool res = false; - fuzzer_worker_set_protocol(worker, protocol_index); + fuzzer_worker_set_protocol(instance, protocol_index); - worker->attack_type = FuzzerWorkerAttackTypeLoadFile; - worker->index = chusen; + instance->attack_type = FuzzerWorkerAttackTypeLoadFile; + instance->index = chusen; - memcpy(worker->payload, uid, worker->protocol->data_size); + memcpy(instance->payload, uid, instance->protocol->data_size); res = true; @@ -270,49 +270,49 @@ bool fuzzer_worker_attack_bf_byte( // TODO make it protocol independent bool fuzzer_worker_load_key_from_file( - FuzzerWorker* worker, + FuzzerWorker* instance, FuzzerProtocolsID protocol_index, const char* filename) { - furi_assert(worker); + furi_assert(instance); bool res = false; - fuzzer_worker_set_protocol(worker, protocol_index); + fuzzer_worker_set_protocol(instance, protocol_index); #if defined(RFID_125_PROTOCOL) - ProtocolId loaded_proto_id = lfrfid_dict_file_load(worker->protocols_items, filename); + ProtocolId loaded_proto_id = lfrfid_dict_file_load(instance->protocols_items, filename); if(loaded_proto_id == PROTOCOL_NO) { // Err Cant load file FURI_LOG_W(TAG, "Cant load file"); - } else if(worker->protocol_id != loaded_proto_id) { // Err wrong protocol + } else if(instance->protocol_id != loaded_proto_id) { // Err wrong protocol FURI_LOG_W(TAG, "Wrong protocol"); FURI_LOG_W( TAG, "Selected: %s Loaded: %s", - worker->protocol->name, - protocol_dict_get_name(worker->protocols_items, loaded_proto_id)); + instance->protocol->name, + protocol_dict_get_name(instance->protocols_items, loaded_proto_id)); } else { protocol_dict_get_data( - worker->protocols_items, worker->protocol_id, worker->payload, MAX_PAYLOAD_SIZE); + instance->protocols_items, instance->protocol_id, instance->payload, MAX_PAYLOAD_SIZE); res = true; } #else - if(!ibutton_protocols_load(worker->protocols_items, worker->key, filename)) { + if(!ibutton_protocols_load(instance->protocols_items, instance->key, filename)) { // Err Cant load file FURI_LOG_W(TAG, "Cant load file"); } else { - if(worker->protocol_id != ibutton_key_get_protocol_id(worker->key)) { + if(instance->protocol_id != ibutton_key_get_protocol_id(instance->key)) { // Err wrong protocol FURI_LOG_W(TAG, "Wrong protocol"); FURI_LOG_W( TAG, "Selected: %s Loaded: %s", - worker->protocol->name, + instance->protocol->name, ibutton_protocols_get_name( - worker->protocols_items, ibutton_key_get_protocol_id(worker->key))); + instance->protocols_items, ibutton_key_get_protocol_id(instance->key))); } else { iButtonEditableData data; - ibutton_protocols_get_editable_data(worker->protocols_items, worker->key, &data); - memcpy(worker->payload, data.ptr, data.size); + ibutton_protocols_get_editable_data(instance->protocols_items, instance->key, &data); + memcpy(instance->payload, data.ptr, data.size); res = true; } } @@ -322,140 +322,141 @@ bool fuzzer_worker_load_key_from_file( } FuzzerWorker* fuzzer_worker_alloc() { - FuzzerWorker* worker = malloc(sizeof(FuzzerWorker)); + FuzzerWorker* instance = malloc(sizeof(FuzzerWorker)); #if defined(RFID_125_PROTOCOL) - worker->protocols_items = protocol_dict_alloc(lfrfid_protocols, LFRFIDProtocolMax); + instance->protocols_items = protocol_dict_alloc(lfrfid_protocols, LFRFIDProtocolMax); - worker->proto_worker = lfrfid_worker_alloc(worker->protocols_items); + instance->proto_worker = lfrfid_worker_alloc(instance->protocols_items); #else - worker->protocols_items = ibutton_protocols_alloc(); - worker->key = ibutton_key_alloc(ibutton_protocols_get_max_data_size(worker->protocols_items)); + instance->protocols_items = ibutton_protocols_alloc(); + instance->key = + ibutton_key_alloc(ibutton_protocols_get_max_data_size(instance->protocols_items)); - worker->proto_worker = ibutton_worker_alloc(worker->protocols_items); + instance->proto_worker = ibutton_worker_alloc(instance->protocols_items); #endif - worker->attack_type = FuzzerWorkerAttackTypeMax; - worker->index = 0; - worker->treead_running = false; + instance->attack_type = FuzzerWorkerAttackTypeMax; + instance->index = 0; + instance->treead_running = false; - memset(worker->payload, 0x00, sizeof(worker->payload)); + memset(instance->payload, 0x00, sizeof(instance->payload)); - worker->timeer_delay = FUZZ_TIME_DELAY_DEFAULT; + instance->timeer_delay = FUZZ_TIME_DELAY_DEFAULT; - worker->timer = - furi_timer_alloc(fuzzer_worker_on_tick_callback, FuriTimerTypePeriodic, worker); + instance->timer = + furi_timer_alloc(fuzzer_worker_on_tick_callback, FuriTimerTypePeriodic, instance); - return worker; + return instance; } -void fuzzer_worker_free(FuzzerWorker* worker) { - furi_assert(worker); +void fuzzer_worker_free(FuzzerWorker* instance) { + furi_assert(instance); - fuzzer_worker_stop(worker); + fuzzer_worker_stop(instance); - furi_timer_free(worker->timer); + furi_timer_free(instance->timer); #if defined(RFID_125_PROTOCOL) - lfrfid_worker_free(worker->proto_worker); + lfrfid_worker_free(instance->proto_worker); - protocol_dict_free(worker->protocols_items); + protocol_dict_free(instance->protocols_items); #else - ibutton_worker_free(worker->proto_worker); + ibutton_worker_free(instance->proto_worker); - ibutton_key_free(worker->key); - ibutton_protocols_free(worker->protocols_items); + ibutton_key_free(instance->key); + ibutton_protocols_free(instance->protocols_items); #endif - free(worker); + free(instance); } -bool fuzzer_worker_start(FuzzerWorker* worker, uint8_t timer_dellay) { - furi_assert(worker); +bool fuzzer_worker_start(FuzzerWorker* instance, uint8_t timer_dellay) { + furi_assert(instance); - if(worker->attack_type < FuzzerWorkerAttackTypeMax) { - worker->timeer_delay = timer_dellay; + if(instance->attack_type < FuzzerWorkerAttackTypeMax) { + instance->timeer_delay = timer_dellay; - furi_timer_start(worker->timer, furi_ms_to_ticks(timer_dellay * 100)); + furi_timer_start(instance->timer, furi_ms_to_ticks(timer_dellay * 100)); - if(!worker->treead_running) { + if(!instance->treead_running) { #if defined(RFID_125_PROTOCOL) - lfrfid_worker_start_thread(worker->proto_worker); + lfrfid_worker_start_thread(instance->proto_worker); #else - ibutton_worker_start_thread(worker->proto_worker); + ibutton_worker_start_thread(instance->proto_worker); #endif FURI_LOG_D(TAG, "Worker Starting"); - worker->treead_running = true; + instance->treead_running = true; } else { FURI_LOG_D(TAG, "Worker UnPaused"); } #if defined(RFID_125_PROTOCOL) - // lfrfid_worker_start_thread(worker->proto_worker); - lfrfid_worker_emulate_start(worker->proto_worker, worker->protocol_id); + // lfrfid_worker_start_thread(instance->proto_worker); + lfrfid_worker_emulate_start(instance->proto_worker, instance->protocol_id); #else - // ibutton_worker_start_thread(worker->proto_worker); - ibutton_worker_emulate_start(worker->proto_worker, worker->key); + // ibutton_worker_start_thread(instance->proto_worker); + ibutton_worker_emulate_start(instance->proto_worker, instance->key); #endif return true; } return false; } -void fuzzer_worker_pause(FuzzerWorker* worker) { - furi_assert(worker); +void fuzzer_worker_pause(FuzzerWorker* instance) { + furi_assert(instance); - furi_timer_stop(worker->timer); + furi_timer_stop(instance->timer); - if(worker->treead_running) { + if(instance->treead_running) { #if defined(RFID_125_PROTOCOL) - lfrfid_worker_stop(worker->proto_worker); + lfrfid_worker_stop(instance->proto_worker); #else - ibutton_worker_stop(worker->proto_worker); + ibutton_worker_stop(instance->proto_worker); #endif FURI_LOG_D(TAG, "Worker Paused"); } } -void fuzzer_worker_stop(FuzzerWorker* worker) { - furi_assert(worker); +void fuzzer_worker_stop(FuzzerWorker* instance) { + furi_assert(instance); - furi_timer_stop(worker->timer); + furi_timer_stop(instance->timer); - if(worker->treead_running) { + if(instance->treead_running) { #if defined(RFID_125_PROTOCOL) - lfrfid_worker_stop(worker->proto_worker); - lfrfid_worker_stop_thread(worker->proto_worker); + lfrfid_worker_stop(instance->proto_worker); + lfrfid_worker_stop_thread(instance->proto_worker); #else - ibutton_worker_stop(worker->proto_worker); - ibutton_worker_stop_thread(worker->proto_worker); + ibutton_worker_stop(instance->proto_worker); + ibutton_worker_stop_thread(instance->proto_worker); #endif FURI_LOG_D(TAG, "Worker Stopping"); - worker->treead_running = false; + instance->treead_running = false; } - if(worker->attack_type == FuzzerWorkerAttackTypeLoadFileCustomUids) { - buffered_file_stream_close(worker->uids_stream); + if(instance->attack_type == FuzzerWorkerAttackTypeLoadFileCustomUids) { + buffered_file_stream_close(instance->uids_stream); furi_record_close(RECORD_STORAGE); - worker->attack_type = FuzzerWorkerAttackTypeMax; + instance->attack_type = FuzzerWorkerAttackTypeMax; } // TODO anything else } void fuzzer_worker_set_uid_chaged_callback( - FuzzerWorker* worker, + FuzzerWorker* instance, FuzzerWorkerUidChagedCallback callback, void* context) { - furi_assert(worker); - worker->tick_callback = callback; - worker->tick_context = context; + furi_assert(instance); + instance->tick_callback = callback; + instance->tick_context = context; } void fuzzer_worker_set_end_callback( - FuzzerWorker* worker, + FuzzerWorker* instance, FuzzerWorkerEndCallback callback, void* context) { - furi_assert(worker); - worker->end_callback = callback; - worker->end_context = context; + furi_assert(instance); + instance->end_callback = callback; + instance->end_context = context; } diff --git a/applications/external/pacs_fuzzer/lib/worker/fake_worker.h b/applications/external/pacs_fuzzer/lib/worker/fake_worker.h index 2f8733393..04635169b 100644 --- a/applications/external/pacs_fuzzer/lib/worker/fake_worker.h +++ b/applications/external/pacs_fuzzer/lib/worker/fake_worker.h @@ -17,42 +17,121 @@ typedef void (*FuzzerWorkerEndCallback)(void* context); typedef struct FuzzerWorker FuzzerWorker; +/** + * Allocate FuzzerWorker + * + * @return FuzzerWorker* pointer to FuzzerWorker + */ FuzzerWorker* fuzzer_worker_alloc(); -void fuzzer_worker_free(FuzzerWorker* worker); +/** + * Free FuzzerWorker + * + * @param instance Pointer to a FuzzerWorker + */ +void fuzzer_worker_free(FuzzerWorker* instance); -bool fuzzer_worker_start(FuzzerWorker* worker, uint8_t timer_dellay); +/** + * Start or continue emulation + * + * @param instance Pointer to a FuzzerWorker + * @param timer_dellay Emulation time of one UID in tenths of a second + * @return bool True if emulation has started + */ +bool fuzzer_worker_start(FuzzerWorker* instance, uint8_t timer_dellay); -void fuzzer_worker_stop(FuzzerWorker* worker); +/** + * Stop emulation and deinit worker + * + * @param instance Pointer to a FuzzerWorker + */ +void fuzzer_worker_stop(FuzzerWorker* instance); -void fuzzer_worker_pause(FuzzerWorker* worker); +/** + * Suspend emulation + * + * @param instance Pointer to a FuzzerWorker + */ +void fuzzer_worker_pause(FuzzerWorker* instance); -bool fuzzer_worker_attack_dict(FuzzerWorker* worker, FuzzerProtocolsID protocol_index); +/** + * Init attack by default dictionary + * + * @param instance Pointer to a FuzzerWorker + * @param protocol_index index of the selected protocol + * @return bool True if initialization is successful + */ +bool fuzzer_worker_init_attack_dict(FuzzerWorker* instance, FuzzerProtocolsID protocol_index); -bool fuzzer_worker_attack_bf_byte( - FuzzerWorker* worker, +/** + * Init attack by custom dictionary + * + * @param instance Pointer to a FuzzerWorker + * @param protocol_index index of the selected protocol + * @param file_path file path to the dictionary + * @return bool True if initialization is successful + */ +bool fuzzer_worker_init_attack_file_dict( + FuzzerWorker* instance, + FuzzerProtocolsID protocol_index, + FuriString* file_path); + +/** + * Init attack brute force one of byte + * + * @param instance Pointer to a FuzzerWorker + * @param protocol_index index of the selected protocol + * @param uid UID for brute force + * @param chosen index of chusen byte + * @return bool True if initialization is successful + */ +bool fuzzer_worker_init_attack_bf_byte( + FuzzerWorker* instance, FuzzerProtocolsID protocol_index, const uint8_t* uid, uint8_t chusen); -bool fuzzer_worker_attack_file_dict( - FuzzerWorker* worker, - FuzzerProtocolsID protocol_index, - FuriString* file_path); - -void fuzzer_worker_get_current_key(FuzzerWorker* worker, FuzzerPayload* output_key); +/** + * Get current UID + * + * @param instance Pointer to a FuzzerWorker + * @param output_key Pointer to a FuzzerWorker, memory for data will be allocated + */ +void fuzzer_worker_get_current_key(FuzzerWorker* instance, FuzzerPayload* output_key); +/** + * Load UID from Flipper Format Key file + * + * @param instance Pointer to a FuzzerWorker + * @param protocol_index index of the selected protocol + * @param filename file path to the key file + * @return bool True if loading is successful + */ bool fuzzer_worker_load_key_from_file( - FuzzerWorker* worker, + FuzzerWorker* instance, FuzzerProtocolsID protocol_index, const char* filename); +/** + * Set callback for uid changed + * + * @param instance Pointer to a FuzzerWorker + * @param callback Callback for uid changed + * @param context Context for callback + */ void fuzzer_worker_set_uid_chaged_callback( - FuzzerWorker* worker, + FuzzerWorker* instance, FuzzerWorkerUidChagedCallback callback, void* context); +/** + * Set callback for end of emulation + * + * @param instance Pointer to a FuzzerWorker + * @param callback Callback for end of emulation + * @param context Context for callback + */ void fuzzer_worker_set_end_callback( - FuzzerWorker* worker, + FuzzerWorker* instance, FuzzerWorkerEndCallback callback, void* context); \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/lib/worker/protocol.h b/applications/external/pacs_fuzzer/lib/worker/protocol.h index 0de1223ff..a2893123e 100644 --- a/applications/external/pacs_fuzzer/lib/worker/protocol.h +++ b/applications/external/pacs_fuzzer/lib/worker/protocol.h @@ -30,12 +30,34 @@ struct FuzzerPayload { uint8_t data_size; }; +/** + * Get maximum length of UID among all supported protocols + * @return Maximum length of UID + */ uint8_t fuzzer_proto_get_max_data_size(); +/** + * Get protocol name based on its index + * @param index protocol index + * @return pointer to a string containing the name + */ const char* fuzzer_proto_get_name(FuzzerProtocolsID index); +/** + * Get number of protocols + * @return number of protocols + */ uint8_t fuzzer_proto_get_count_of_protocols(); +/** + * Get menu label based on its index + * @param index menu index + * @return pointer to a string containing the menu label + */ const char* fuzzer_proto_get_menu_label(FuzzerMainMenuIndex index); +/** + * Get number of menu items + * @return number of menu items + */ uint8_t fuzzer_proto_get_count_of_menu_items(); \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_field_editor.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_field_editor.c index f8adae0df..637eff2d7 100644 --- a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_field_editor.c +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_field_editor.c @@ -38,7 +38,7 @@ bool fuzzer_scene_field_editor_on_event(void* context, SceneManagerEvent event) consumed = true; } else if(event.event == FuzzerCustomEventViewFieldEditorOk) { // TODO - if(fuzzer_worker_attack_bf_byte( + if(fuzzer_worker_init_attack_bf_byte( app->worker, app->fuzzer_state.proto_index, fuzzer_view_field_editor_get_uid(app->field_editor_view), diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c index e27bc0776..5ad37654a 100644 --- a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c @@ -81,7 +81,8 @@ bool fuzzer_scene_main_on_event(void* context, SceneManagerEvent event) { switch(app->fuzzer_state.menu_index) { case FuzzerMainMenuIndexDefaultValues: - loading_ok = fuzzer_worker_attack_dict(app->worker, app->fuzzer_state.proto_index); + loading_ok = + fuzzer_worker_init_attack_dict(app->worker, app->fuzzer_state.proto_index); if(!loading_ok) { // error @@ -108,7 +109,7 @@ bool fuzzer_scene_main_on_event(void* context, SceneManagerEvent event) { if(!fuzzer_scene_main_load_custom_dict(app)) { break; } else { - loading_ok = fuzzer_worker_attack_file_dict( + loading_ok = fuzzer_worker_init_attack_file_dict( app->worker, app->fuzzer_state.proto_index, app->file_path); } break; From b346487e760e8d55505a91e117e801344237fd39 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Mon, 5 Jun 2023 21:19:32 +0300 Subject: [PATCH 13/31] Fuzzer App: BFCustomerID attack, some fix --- .../pacs_fuzzer/lib/worker/protocol.c | 28 +++++++++++++------ .../pacs_fuzzer/lib/worker/protocol.h | 18 ++++++++---- .../pacs_fuzzer/scenes/fuzzer_scene_main.c | 22 ++++++++++++--- applications/external/pacs_fuzzer/todo.md | 2 +- .../external/pacs_fuzzer/views/main_menu.c | 2 +- 5 files changed, 53 insertions(+), 19 deletions(-) diff --git a/applications/external/pacs_fuzzer/lib/worker/protocol.c b/applications/external/pacs_fuzzer/lib/worker/protocol.c index b9f9e6bf6..c295289ae 100644 --- a/applications/external/pacs_fuzzer/lib/worker/protocol.c +++ b/applications/external/pacs_fuzzer/lib/worker/protocol.c @@ -228,10 +228,18 @@ const FuzzerProtocol fuzzer_proto_items[] = { }; #endif -const char* fuzzer_attack_names[] = { - [FuzzerMainMenuIndexDefaultValues] = "Default Values", - [FuzzerMainMenuIndexLoadFile] = "Load File", - [FuzzerMainMenuIndexLoadFileCustomUids] = "Load UIDs from file", +typedef struct { + const char* menu_label; + FuzzerAttackId attack_id; +} FuzzerMenuItems; + +const FuzzerMenuItems fuzzer_menu_items[] = { + {"Default Values", FuzzerAttackIdDefaultValues}, +#ifdef RFID_125_PROTOCOL + {"BF Customer ID", FuzzerAttackIdBFCustomerID}, +#endif + {"Load File", FuzzerAttackIdLoadFile}, + {"Load UIDs from file", FuzzerAttackIdLoadFileCustomUids}, }; const char* fuzzer_proto_get_name(FuzzerProtocolsID index) { @@ -246,10 +254,14 @@ uint8_t fuzzer_proto_get_max_data_size() { return MAX_PAYLOAD_SIZE; } -const char* fuzzer_proto_get_menu_label(FuzzerMainMenuIndex index) { - return fuzzer_attack_names[index]; +const char* fuzzer_proto_get_menu_label(uint8_t index) { + return fuzzer_menu_items[index].menu_label; +} + +FuzzerAttackId fuzzer_proto_get_attack_id_by_index(uint8_t index) { + return fuzzer_menu_items[index].attack_id; } uint8_t fuzzer_proto_get_count_of_menu_items() { - return COUNT_OF(fuzzer_attack_names); -} \ No newline at end of file + return COUNT_OF(fuzzer_menu_items); +} diff --git a/applications/external/pacs_fuzzer/lib/worker/protocol.h b/applications/external/pacs_fuzzer/lib/worker/protocol.h index a2893123e..4c2c70e0c 100644 --- a/applications/external/pacs_fuzzer/lib/worker/protocol.h +++ b/applications/external/pacs_fuzzer/lib/worker/protocol.h @@ -20,10 +20,11 @@ typedef enum { } FuzzerProtocolsID; typedef enum { - FuzzerMainMenuIndexDefaultValues = 0, - FuzzerMainMenuIndexLoadFile, - FuzzerMainMenuIndexLoadFileCustomUids, -} FuzzerMainMenuIndex; + FuzzerAttackIdDefaultValues = 0, + FuzzerAttackIdLoadFile, + FuzzerAttackIdLoadFileCustomUids, + FuzzerAttackIdBFCustomerID, +} FuzzerAttackId; struct FuzzerPayload { uint8_t* data; @@ -54,7 +55,14 @@ uint8_t fuzzer_proto_get_count_of_protocols(); * @param index menu index * @return pointer to a string containing the menu label */ -const char* fuzzer_proto_get_menu_label(FuzzerMainMenuIndex index); +const char* fuzzer_proto_get_menu_label(uint8_t index); + +/** + * Get FuzzerAttackId based on its index + * @param index menu index + * @return FuzzerAttackId + */ +FuzzerAttackId fuzzer_proto_get_attack_id_by_index(uint8_t index); /** * Get number of menu items diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c index 5ad37654a..699037430 100644 --- a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c @@ -77,9 +77,11 @@ bool fuzzer_scene_main_on_event(void* context, SceneManagerEvent event) { // TODO error logic bool loading_ok = false; + uint8_t d_size = fuzzer_proto_get_max_data_size(); + uint8_t* uid; - switch(app->fuzzer_state.menu_index) { - case FuzzerMainMenuIndexDefaultValues: + switch(fuzzer_proto_get_attack_id_by_index(app->fuzzer_state.menu_index)) { + case FuzzerAttackIdDefaultValues: loading_ok = fuzzer_worker_init_attack_dict(app->worker, app->fuzzer_state.proto_index); @@ -88,8 +90,20 @@ bool fuzzer_scene_main_on_event(void* context, SceneManagerEvent event) { // error } break; + case FuzzerAttackIdBFCustomerID: + uid = malloc(d_size); + memset(uid, 0x00, d_size); - case FuzzerMainMenuIndexLoadFile: + loading_ok = fuzzer_worker_init_attack_bf_byte( + app->worker, app->fuzzer_state.proto_index, uid, 0); + + free(uid); + if(!loading_ok) { + // error + } + break; + + case FuzzerAttackIdLoadFile: if(!fuzzer_scene_main_load_key(app)) { break; } else { @@ -105,7 +119,7 @@ bool fuzzer_scene_main_on_event(void* context, SceneManagerEvent event) { } break; - case FuzzerMainMenuIndexLoadFileCustomUids: + case FuzzerAttackIdLoadFileCustomUids: if(!fuzzer_scene_main_load_custom_dict(app)) { break; } else { diff --git a/applications/external/pacs_fuzzer/todo.md b/applications/external/pacs_fuzzer/todo.md index dd6f4fc69..7afd3fad8 100644 --- a/applications/external/pacs_fuzzer/todo.md +++ b/applications/external/pacs_fuzzer/todo.md @@ -13,7 +13,7 @@ #### App functionality -- [ ] Add `BFCustomerID` attack +- [x] Add `BFCustomerID` attack - [ ] Save key logic ## Code Improvement diff --git a/applications/external/pacs_fuzzer/views/main_menu.c b/applications/external/pacs_fuzzer/views/main_menu.c index 8c4c23603..49b0a0d9c 100644 --- a/applications/external/pacs_fuzzer/views/main_menu.c +++ b/applications/external/pacs_fuzzer/views/main_menu.c @@ -75,7 +75,7 @@ void fuzzer_view_main_draw(Canvas* canvas, FuzzerViewMainModel* model) { canvas_draw_str_aligned( canvas, 64, 36, AlignCenter, AlignTop, fuzzer_proto_get_menu_label(model->menu_index)); - if(model->menu_index < model->menu_max) { + if(model->menu_index < (model->menu_max - 1)) { canvas_set_font(canvas, FontSecondary); canvas_draw_str_aligned( canvas, From 237d2ba1a01ff1ea371d92bdaf0df7527c1ac845 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 6 Jun 2023 11:14:23 +0300 Subject: [PATCH 14/31] Fuzzer App: field_editor view V2 --- .../pacs_fuzzer/icons/ButtonLeft_4x7.png | Bin 0 -> 1415 bytes .../pacs_fuzzer/icons/ButtonRight_4x7.png | Bin 0 -> 1839 bytes .../external/pacs_fuzzer/icons/Ok_btn_9x9.png | Bin 0 -> 3605 bytes .../pacs_fuzzer/icons/Pin_arrow_up_7x9.png | Bin 0 -> 3603 bytes .../pacs_fuzzer/icons/Pin_back_arrow_10x8.png | Bin 0 -> 3606 bytes applications/external/pacs_fuzzer/todo.md | 2 +- .../external/pacs_fuzzer/views/attack.c | 42 +++---- .../external/pacs_fuzzer/views/field_editor.c | 108 ++++++++++++------ .../external/pacs_fuzzer/views/main_menu.c | 1 - 9 files changed, 94 insertions(+), 59 deletions(-) create mode 100644 applications/external/pacs_fuzzer/icons/ButtonLeft_4x7.png create mode 100644 applications/external/pacs_fuzzer/icons/ButtonRight_4x7.png create mode 100644 applications/external/pacs_fuzzer/icons/Ok_btn_9x9.png create mode 100644 applications/external/pacs_fuzzer/icons/Pin_arrow_up_7x9.png create mode 100644 applications/external/pacs_fuzzer/icons/Pin_back_arrow_10x8.png diff --git a/applications/external/pacs_fuzzer/icons/ButtonLeft_4x7.png b/applications/external/pacs_fuzzer/icons/ButtonLeft_4x7.png new file mode 100644 index 0000000000000000000000000000000000000000..0b4655d43247083aa705620e9836ac415b42ca46 GIT binary patch literal 1415 zcmbVM+iKK67*5rq)>aU2M7$VM1Vxif;vTv~W2u`S7ED{V3s&&L*<`XiG|9wd+THd> z5CnY!sdyuJtrvQyAo>KpiLcV|{Tkc)riAbluXfwSZCApL`ztB&p zx6LGKvks4K_4~)qD&oGa-YdJlW)hAKMNJd7<=t?6c^RI1>c$ifyjaM>^|&8!ey zB4!nh9u>5uen6Ve@<H5rru6h<2Ef#GQdQ*CmZOlQi~N!?9H`Rp;C% zU}CB21#?;r`&0|6C0}b-=jODa5|nEJ#ntxQ&{~jpgtwDta4hftr~G=#p@V36e4Zjh zq%J~{y26Jjn=1Nw-l*3%QW5YFE*v4z3gt0$&(*xf2en34c?JpH8+FYldo+Alvg8af-pG4(=!fyUi-Wsg z`g#n9VUcf(DFr{poMSNzw-lz>w+HV+n1ELr&SLA#LHUb0p(xWQ(1*vJ-i+1!`swxZ Z!O7;c$;lT_->m1Ovaz)0yuI`A$q$F8u*d)a literal 0 HcmV?d00001 diff --git a/applications/external/pacs_fuzzer/icons/ButtonRight_4x7.png b/applications/external/pacs_fuzzer/icons/ButtonRight_4x7.png new file mode 100644 index 0000000000000000000000000000000000000000..8e1c74c1c0038ea55172f19ac875003fc80c2d06 GIT binary patch literal 1839 zcmcIlO>f*p7#Yw)M6zw!O+@VZ{?d|D~WYi~8rHRY?X-&T}Yen`g$^+EJ;z+|RV zE@PoDvZ9%#+_}3bC_5Cj8jDGq541mi{7F+&KF}W65sr$Xn5H|YrMQ2(J7%Yc%;(zO z57ax000=TsQ+1Ke@+w#iw3au3cGGQWY740k2ijH>P(6tD)S)be>gX6Tj7`<`b>di- zgWp$8Y+?i31~CzF0&E4uRlA=C(Mp~K`{74jEchB|)4DDK!ZVhSwdFyw0YIZ1cDh0S{OvfO-U_~ zvmRF*m9sWDXNH)GOyqS1Skhxbr6}s*7t&@~kFM(NW5}qh?Lu@lJ}HE;FDiLdGO>LO z5pS*%E2grR)l^;|?O5b_?u0me&c1U}%jrk8*%=Wk%i)8yp2P|kuxmKg<=(u_`oQRI_0 zS`-DNysBx=#3&qSkgA@hJP>~D+ZM(s5jI6Owp`?yE=3e`YGUqkVOp#Cp=3wR3O4hX zX6BLsN3UBzV(vI5;|SZHgOb=HD0VFjpTyfFW}GnQuh>2*Q`k>*cAmA#iUT7EXSpo# zkPm5~#I-o^cpgfe#P$=4-Pi*SpT!-@nJgp8L347xe>5EKl`=_ZFc8XGy+_j=_R_7! z@vZZMowS1GJ?Zw)eetks%~G{BTR>T}9|jt0j3Btyb*C3-`C?fwY3EY`q*oYZ39DpM z&uJ;PCZPLs4QO1Jd_|A1PF)azZJ)RZ`^-VMWr6e#XUOA%3eLG_Ch@BDOHzMk*MF0G zCo7xMd?Mg*HMIXw%nNz?%60fZiZPlqb?GqUpXO`F&Yi!okZl(n>P@r1P2i)yk3DgRwbHeNn6e|;J^SK4TM LH~i+q&mR8;k>NTA literal 0 HcmV?d00001 diff --git a/applications/external/pacs_fuzzer/icons/Ok_btn_9x9.png b/applications/external/pacs_fuzzer/icons/Ok_btn_9x9.png new file mode 100644 index 0000000000000000000000000000000000000000..9a1539da2049f12f7b25f96b11a9c40cd8227302 GIT binary patch literal 3605 zcmaJ@c{r5q+kR|?vSeS9G2*Q(Gqz$f_GQ#q8r!JE7=ytqjlqnNNGaK}Wlbolp-q`& zs|bxHiiEP0&{#s&zVZIv-rx7f*Y_O9^W67+-RF5;*L_{ra~$^-2RmyaK{-JH0EBE1 z7AVdru>JD$aK0bym%#uaXpT2Gcd#)x2azcxAABGV0BC)Aj-lw(6)B^^6`Y8RS?}DV z%)ko(See1!Eb3M$dL6)A6csaRjExg?k&xVzi*Rm;?iNJk#f=mkVEUR~jXN3dd|Lmz z;y}sMh%ol-?E1&`>dD;6jdps6NYoxN)s%@sf4~40YY6LAOtMEbwA4g#OCpANL823^ zSH66W05Hcxr$tg98gFntAOYL}xm$C;Skv&Ym?{TVR{)d(41vWacX1`7fM!jnW(lBK z26*WB#9I(Z1Ast!xEUC@Cj`v=urcBTdP`FWq=DYTy`}s>0vC{VzHdNRvxNFy}ir1|g=xDsrFP&l1P<-Sv zXLqYVYz{b^ZIV@1Ulg->7DEgvM*Min&Y8{8QW! z$_pA434?^wCTq$4%^>Zo8&|8XwbCv;KEd;WJJ{s;T}8R8Zwi7ssk$QWQ5l5+opKfX z;8D*COFEB#4W^*FIrRU%PDSc?B(}+9ZV?N9(yH>0uSnM?xg!>+>;e z{{7tXQQ|ZFXD*7q3XD!pwnih-=66+Qlqtl9;N-D|PHoI&B5d8>^V#i{mE>V0gQgu3+(DG%B z|8W!pl$lbQERt-0eZA%NSfvE4F>VAYP`DpeoF;Zm4`)2id;6xgSysWl6K$pWANcRZ z!ETRXKIU9G=@9lEB?<{ivj7!8FE9WN;qoo2Lr0#c@DmcF=JzU<73PmM3 zbe!-gs`c26Uc(AKz7%U!a0yZ5gsprdo1i51MjJPeHtV6d@Jy=*+_3dJ^>}p#8N#kPK_4t?hltq>u=?m+t z?em(Y%u3Bp_pyV?c_w-4c}p+?Y$aHr>TuPGs@SUj;Er!b@3GVLDS@T8OTts1JFS-p zKZ=&5zp;DRor*`Gy8MTeWdpVJv2(4-*slRM@XXG+i^F&Ku>7i08vKenZHoS4s(!!h zJE}*MHu7PR_IfdNzu*P}3^87K?f&A1;>NMsgKcR6**;aB74NC7tR(NB?{dHT-9QhXa*KoG!kGU1}$l2D>ypo)fSBuG$ zkTW4?+|I1m?6ZH8tD4^fB{cUpoEoZOo%4hl!EtNtQ#?j*jJR)x-Mn0TrxrX2uT_rh ziOh=Jxsktqbd9x{^s{c5z92Pk$LGoQl53o+=7QXXCp-Z>io998w|DCCCGfr20oiRN zX|`KH$W4)wN~)J$kYB~>4EU;NcS^qH&yzeUzXokpMegg_lX$6ve^4}%bY~Sg)%uJ- zZpb$p4x^GS5d{XJP=STbfpHV`58UBH& zKFg&BgS6bV+#-|^KBGeIBee2B zrM-`uTB^_(eS+{-KK1h3l`-Yjpv8X4z*uBwQ3a~pL0Ae2xvNGyC3A|#MARToe$W~8 z+4{DsyenENye9df1M}gNUM9_Leh6G=`9exL-cdSKQ_CGyEdZ3W5uoR!Lb^D)9!bd=7h@R=M%=|JqX9XP;Z6# zFD15Bw7qTP(ZlG?o@#x@=wG;XxM(>n@4P$9WwY#lW$h=`zMi_zq30HbV-zHheqpE0 zR6kXtxdzl&Ml2D#zDIvflJkb*e zIAI?GMjp?JBK76WW`{l{pFAY|%5?nYUxRnT&y6~Kz19AD;C0(z*7?dM{%HhVtqWEc z%+M$z6u@uQu)kg_%2PO_U|n1JE0V1>iVbekOLEOG$U6X^Umc519WC)L$t%`#Di0$ zY1|5H*440_`onhmXeayq`8EIg?x2r9KWe()q}QayqCMEC?c4meb4}#i`HHPaxO&3SPtSVKj@ND?Y+-@R`CDnf-d`T>vTn8RR<=@3 zNXk=Gloyh#S@3R89WHrXBHr;f(&ZO@I_Uo7;O5Bs@ecGx@7%7{_>Q`Adg&sCeZTYp ztVy{^vAUfOpTDzF*4`h%X0odWn`#uZ4s4igIV^UrVVg?c*{>K)hHq^^RxU2CM;WN> z;oK@^sg`J}BguyvilN{DQ*V+N4rD{X_~KAFj5qyk3(gP#cvSIDXe!zk3B!^InwV{j zCXGPmumQl(m`28618`K37tR+?goD{H>cAkpHyrG$XA89@o8$cOh%gGyG0e^h8y0{y z@CF+jfedLdjsO8i#eispKw=P#1_%GG3**eU%@8o?ZwNI24*pM2Xj=!6If;S;9nsX% zz(S!=&=CVoZ;TfP>*b{m(uQhlL7=)2EnN*L6sBVU)71t2^ME<-DBeCWl!etl&NwSL z*pEsj!yu5*&``}#9ZeF&7oufgU;u$?L$tLuI0%g(I+2Q@X%K^ye=Atvg0K`knTjV7 zLEDNLFH$fS4(5dVpED51|H=}B{>c+3V-OmK4AIhrZlCEl(AM_T0=zuK- zizjYd4*pHCwT0ObgQyrH7H4At2XjO;@px~TsgAA%R9|05PuEIcOUu&SOwUTs^00xK zshI`T;)sF%Z>|Li8%)3vslU12|K;lbk-Oav1Tx371&)Fb!FgLzNCeQ|r-tGG9E;W; z_5R^{|2Y=zKXM_QU?AJI{a>~IZQ?Z0_VnM@jcrt7jKN@*#$ZMzB}>VcEo(xFhBigA zRfKF&B$OpfLSqS8d&l#8dVcR8Z}0is_kGT}&h`CX>-l`{D|W}MM1o0W+qqCz&a@8xmO|M3uh;cln|6OUI z@X7fQ&dki(hqbDStcmq@R)<*FE(x{7@jPF^02^V5=v9ihMb|f1hw)0IhxkF_<1H_} z1sVWgmXE~@Wjrum=ebV>cmZ0s_CATm;a}mEc52Q5C=nO}OHAzGNx%Y4+73-pK+|sE zf&F7oVIUa*{8{JBz(BDGF#W^YNC4<9N*a&_dh_-a2?DV^K)SlsK3W zOCXnR0@miQE9D7uc?!4U4XYLag5q!qVkYiDSh|^JD*)2x1yFk>+xS2jzFcTm?NE^$ zEusR=1Jt#ow51*G(vhl2c`F}0KRYy{Jo3{2p&4FwzqpssC^#!EQ$-Rz!G~$z2>|jd zoi8@^jT0uuM~BC~Cj2=+8uB*%W~pE!<+;Jls%yObfcUWvPM_P@SPvhqk>^2RtzXee zpw9{L8C-GI=@-g9A^bLEC5ENHZn8J$mR*yf;vV50J7!cpZdF6S#2Ee38Kw@!gf4MU zH~T|ofioE<=_Pgf;Tvc0l%P^<+(Zk%8H}<#p|aT+abY8Ff9Htq!&92lSLbk7D(t{E zjjU(bM04fllo5%^3-CFm)D5AeU=e^FXGmfr{&k_>d3a+)aa}=xN$7&sHTfNh zfVj6VoV5%9Nwq8SCK^0ITUx;v0I2%9`_$cJSLF_4$)r9^g5d7-;)ha7k^2JBT`QGyenmoI!B!BgFZa^nPSIjjmHP5e8zHBct z>}g(M=h3f$4B-6LI6_z_Ow{YzNBpU4Q5No3aPn%6GK4Xlo>ROYK@oQ-NLryT2hS1Q z#~TwSIW2hlviM8?O9=^9I1CPTS9MyYOrlcISt$H6?B!qJq`S6dsv#09^-K@M!vvfq zTkX5@UgaFs(|?Idx+S6ai8fy!JtnNIngF-nVeN7Z`Pkld>>sQwike&!d8m z!q}j+#PS5O1l#Lt&96qwr4S9#BN(B)eb|Czi6eSM<1zl*H{oXKxy8rZigMly7Dpp) zp0Fn82H8REqlzST12a_HGG$OL1zP#tZ!<{Vq-7t-B%@O3Q}|wsw6|$peqXmwPE3aX z2;M0YDH7g@_E4AelRGO{xVu~ql8(6}@GdRA$pQKSu8{71L+l3C5qDtez&Yu}Hxem` z6sMHXl!;;o#{fs;ZdUOQhkK4<_f9*Vzhmk6*zQY_(0iGC-9?Iy&x;P0wqt{_@pc`@ z-STVPHZH9aL>@&(Sms8e^BoA~ujOKuWnROHb2zgex)a}&rr!-4kCTs9rZGVRYYIV- zvlx3+K(QCwE72=^{7f5<=%`? zl>Nr(;dCk;g6aw$Opx=3=@VvK69`}ZZjdTEXD<)m-PPh#nON_W-)WuySB2X5DDN+N zOj#o@Hg%5&TlX_@z|RoxL4x-e)E6|2*6eRf_RH|9>@0i7Xl-rM9ANjdo2TOpy0iRp z@HHQ+`qyJ4Zd+tE9Emv?)0oNb81R+irnMuZ>Qj# zxib@y+4A&mNoGlXP$qd$YD6l2f7kv+drBW{dVN}WI%9gX}>;*m9J4X{*B+`P?WbMg?R|_dOLt0YC zJHiM_Ty3A^GkR^rdo$!_RLz|l@F22ACA23r zJ#_ne&f4MCmW}wIwZp7=nYm*E?mRDe#(1hP%3plU=f|hSpU!`KyPiO-!1Ha8okr4T zJB37Cl;}y+I@x)J6@t!yw`NAC^c%r!=@Sa8&{j3f-kx1?ksX4A;-S<#E11dFr-IQ# zR{qfyN+h{-*_HEB`wzg2wZ9!NvuB)PENk|#M_tyutK;V4i>^I8-0%C89^}pT^~d@X zrZX$TDvB#EGNXQ4%%w>%B=-r;Tp6wJtw&z@62Lp*pP`dAn&FVjAe4>`?UC_VILOQnvfFm7kYb}KIe$4b!q%cDFE;P^!}5wFhS$flol=(c zKOH`gTJ?#vwG4c%BV>!!U?s|3f2Oiv<7D3Rncea6%ttMQ=SEEn7*BSKM z{I;U9VyY&6%QWwRxn-WhQPHJ&t+6%>}7+sVXoLpPbO)$>wJq(%cIl{yAd4L zao(3TFdv5v@49^(rE$qwH>D`KxrI{ti`zebVW|0ofEcHjRC^^ydT1 zit!QWV{YB&7Fp!JzRyR>-^@&*rwXPh>}8kQ`$wvMO}pPl&We;M%*Bo=xRH;1X50$# zU5slhYkSkir-#>@IobM@-9LZpVE$4__664#r;U<(Fif+aek4~_5ISPczF+n%G&YJPZd_dwhcM)XK$a~zGT6f@?}u{2kzI_J`y5h z5613ABWPopVbs3NnT+5kv=awJUz(1+_-pXaxwBvFzTRqoHSnr!F#SULqTm#orO}0` z4PcuJ1W{iBF zKEPVWtf%|A9(S$wMs?&E%QC)W%H5Wm7d}tKyUte8et?%f`c=!1mLN-!R-v?wVf6iz z)G6X}%Z#&ODdUID)ZtFfy9=wnb=?6Uetyt)y~(QPyq;Dlr>K3}Q=wY9_%mo}MmAXZ zJ7&N&B%XPHy{2#D+xAtlZx_lo9}?@xLqFZ?+&f;mh;c-PqH;Eqf4z$u?y_pN>Q=E- ziH*-zQc@6+ub%g8PZ}Rf89BiysN>^Vu*|b~eTqQIXzO`L8nmD()4q3juuoh;Z zx{Lc)DaWwDG3=>cj9@&S2$*_OJ%}J{GTxhrCE`61Z>_G%gwd42_vIJi(910C^C-NfacQ^Sl-eB6%Xg&U!Xb8ybq}LqdnpiS{AK90(zP z1Ord7u@T6SiQp2Di3~i5N%p4%Aecz--@FL!dP@uegZ@@w_#wgnaSCT+2SQQlM9?8^ zm=*yFg@O(lXcIm0a1R|XJV6r#hr(eH8234(1v`X*>mXnTpnnFKYmn~gg}|Cy{$q~2 zLxO!63>pFg2@Vd{4%X48(!C)t0|NsH6b^yIwYVBu0W1mw&(xv>sQhLyCk7DcBpQQ6 zrGT~=@gCGb1`^D5_CHaOY5&qv0{+PqH)jwgo(6$wL${*(t!QKO|ErS8|7r&?u*CoR z`+pJ#IIw6$2$mQ?4WtvewewQhGDSn6=tMk&N_U`A{eLIY&WFmN2KZ2EAh?b;45V&@ zCy*#xlKp=}Y-|wLlmG^vLLge3Bf(q}Z4${7VPJ`Z>caJO59#RW!C)3BeO)*VWoc## zg<9yK4D<|sW6i0AKr)fS_>J}aFIMl5*sX>j)3}z+iF8sB(bJMnC4>Hs8bSKAFYrI| z{e$)VvoAV-#6q~vK(=c8ziRzk#BHFh<-g6#-Td4BL<+a(>D=bN76lY@FUB@IjDy9m z(5*YN-4s*8oj}&+rVh+L4|neH1o$j1E!71)pl~xe=$Un0lQ15DzW@MOBBhHB}+m>LbCLY=Y4wK?~kwVKJMeb&hxs?-|t+n40QpA+b4G8*k_>A)gsvzul2%)`{+ zGXO-B3u=_{$d$PU5YEZSn%Bo%6nB$X*pi8HtvlN(j>)<>oU^ms-{SJc!?CVM_kGpq zD|mb=fG|Jac@dmEE>EYKyFP!dPw~V2q0~L3V4zJ7VgZs-lDyFoU9CnK9lA z{|)s3FeAcdMKT|ltq9$x0m1;iQ-6nS!_cqj3MXxM0Gt2}LS)A!gg7{$QQxIe9%xhs z9ymYp6$g?4Aeep95(3@bioPky5s{%vM(c>C~+;D?q3rCl<9Vk3~u)C^5I%(w`)RT2PH zm)f7N?K9(ykBtnC`Hctjzt`uk1dC{xK3DmG+T--QM)Dliz9M@cHh&jC)x2t{F@ZnKih0C+}OXW@w z`v&$?T!Pj1rsQGSiPMN#jg(cf#BeEqd)~3u;mM}Qyx`i%uR_AH()f-rz&vtJ?~1BK z0wCjWh+r=QKw`~Oyt$4L(2|<}2>>cTD<8d+q=bD10syO=GrJ#HY?6E~&#jfte6C(u zt0YX=Xk{+Bqt-;ma^pzUR`Hw4DHbX&wa9MK#}7nQbGD=p$&@~a?~@uIls$T8lCHGT zTRHoMa^-n3QHw^99AP{1;ufE{Zb&OgDJ@PELckbai^>O2T$Dcqsc&TD3l~}jCU{~r zzv(gLjjtXx|H*H&$^=ebjw433!=?SMd>|aXa>3gB5?)oiL6JC$H*$+NBC6x}hAF7kW)t|J z9m26ua#NsV=VV?4pXG3D@mM_ij@FcBscZ$vT`c+>{Ka38#5<0qS`o5Kbu1s`Lk`}C ztNnHRw(Z$k$NrL*^Gd|*kZ!s*;vl|Vi-WL}unWTUV)XKz^G!Qs$eCE}Ne-py;|QoE ziVIFnDC2DAI9^+BdO1=ikF38qj1|k>fy+;lJzzvK8x_5E17Vq#bN5h7VfH)F-HXT@ zhwUgiVNOuz3x#rqq3K#J8H#9LzFuDEn{={2c`*Pw!K@JLkKSgT`X;p_=<}wD@rmf~ z;gVA4rJ@@!K08%{R8FWAD3_@~)3CQUyiHAObb-A`sHOQ|-+Z0sir>Ak`=mm`YuRLE zvRiUw^7vgB*AQ2;PWD|1mwT?8?;UeHb=$`Ek<+I_v3H91It$fZpB3&YZpDS;;+@(K zdF54mt)Bf!lqxwNW0P|pljlM#d!=%9yW%SZX%=tU#c&gu)D60B?{lPNX$l**VOcE< zdIIZ=4!P^c^-J)}8av)1B>n2);EeHy%mc04Tcui0=!xi=={@WUEb=RgEZW->(No>y zGtHP*oSy9AhtjjmvvjlOkrd=&s943GibEAK6}_QtUrgT;C)pEX^RMTnC;HoM=PBRw z=9RwiyZG%Idtrv4Jsg!__&(xHGl%#&=sLN)edgTIoh`h8iiEm=ymq_1zsj}0Uhw~9 z#8NW#s4ujm8iU4JvG{?xr?d;JWxCeN2BzQy;MMf~vb=1*A#83ixqIOEV` zVaGg#~3WwEx!kV?Q+q$;Ioo@pT$VAd^FJUK|pMWk7 z+6G@N*C4B;DJ`9n-?bZYSO3eQQfKCI=Av#Fcf@1azbbAvzVOP^{k?%t7-9b0z+hZ3 zaVn!cs{C&G8PM z+2JN0Mjo7#`(m!krk0qEMuRP#pvsP;1yp-=xo_t(VjQijbFbzedRSI|z~tIkmRs_| zzW)8E&_4stJKBW4G7xjb>97-2u07S9vv;%V`p9kjaQuUwaZ+YdW*$z8oKmXu9#*!q z%+XIrCsAsIJw|!0mU!Xy;)v!_$Xu^Na16FRuM}78B&~>r-qB$lQ9i;d$5deszcU!{ zTl=!4DREZuWEJOuQ~85O-Q_Hg*+EE+^)p4ySZAeheYhvC!k0y!={Us;;FYATIt}A- zuHORLec$46(H*yLp>@u>8zvVfHSws$-w!_}DiD%=UHO5jok!eG?^a6o;?lWyihn$? zDIXhlckt>wInSo_^n5%}_Ii2}Gnqe0E+&@qiXwmuR{ESqQ+U(U)H80A6kIb79 zf%9=Kr7f>pM2rYV(?^=0aC^Vq+>^Huk#*XW=eAmOudMomc28GLfB11cI@{U7;B zQ-8QzAye z?YX)QgQSmUMA3ROrqjb8(+}^Keqk~C{I7xACr^BG`h2tXW#7w|fwa?Q^Pou#Tc-nA z6Ux=gqvW7&R`EYy$;(ndrfyqZ_A8PP|3nOJFp782&dJ(|nq3+>oA{}~w;(&q!3^~- zt&hEkT}cb_JmgvBk8aC0Q(}I_mU%5U&3zn?_nfJue}^pk^lFtIEJ78dY$NHbLzw$V zXp^Kx-n6?(G4s3qJ66M%C`$TCPDSu}Lmjrwww;{p%X+9*d9fjae!jTBR?Bh)&695p|Np`_A@%C6Gkw(!c ztlQ|bD0BfD08GqSbOJGm#02}0{K-@lg#WAt0w(*SAnr!?Fncs1cZ-)AAzU~M!*noC|vOF)r0RvA`FmlWAHx@MBtF&>xaZy+5F>9 zprIfEOeP%(g@%WR>xUcY(-{6xxUsP@6o!Bz5PAX&y%08)Nnq(wLo|OgSdl`A3^JWb zrcuG`j07KAC=&${1pA*XDD;16sUiPVN>DQ>i$I6M^|Nl)Xlz**5m^jjZ zpQ#thS=L9?WiG40+mRzvqC`xB>H5sFVffs4KqX-!S)&$7{TGz=zWF=INHY2 z0tT}-KpPtw|HfL;h@lh`mH8X%`(G^lkJ$BrpwI=Ltw;=V7|GX$L8E~G&KgPnV=RW& zf8_fI>-)!83~m01g$ja!uJ`tT_4@agV1U-ee}`9~{5$?6s$k|Bg5ln!QST+V7#p3i zF4n&y*YC(C3v7{K(X_L&aAEcMczb*MMhV&2h)M`^tW<_XOB8+kL0OWLfY3%j)E-d2 TFC+3}9cE|kU{!4CefEC<&8td2 literal 0 HcmV?d00001 diff --git a/applications/external/pacs_fuzzer/todo.md b/applications/external/pacs_fuzzer/todo.md index 7afd3fad8..9070e6363 100644 --- a/applications/external/pacs_fuzzer/todo.md +++ b/applications/external/pacs_fuzzer/todo.md @@ -22,7 +22,7 @@ - [x] Rewrite `gui_const` logic - [ ] Separate protocol name from `fuzzer_proto_items` - [x] Icon in dialog - - [ ] Description and buttons in `field_editor` view + - [x] Description and buttons in `field_editor` view - [ ] Protocol carousel in `main_menu` - [x] prototype - [x] UID diff --git a/applications/external/pacs_fuzzer/views/attack.c b/applications/external/pacs_fuzzer/views/attack.c index ad99f0132..13e2325fd 100644 --- a/applications/external/pacs_fuzzer/views/attack.c +++ b/applications/external/pacs_fuzzer/views/attack.c @@ -18,7 +18,7 @@ typedef struct { const char* attack_name; const char* protocol_name; FuzzerAttackState attack_state; - char* uid; + FuriString* uid_str; } FuzzerViewAttackModel; void fuzzer_view_attack_reset_data( @@ -34,38 +34,25 @@ void fuzzer_view_attack_reset_data( model->attack_name = attack_name; model->protocol_name = protocol_name; model->attack_state = FuzzerAttackStateIdle; - strcpy(model->uid, "Not_set"); + furi_string_set_str(model->uid_str, "Not_set"); }, true); } void fuzzer_view_attack_set_uid(FuzzerViewAttack* view, const FuzzerPayload uid) { furi_assert(view); - - // TODO fix it - uint8_t* data = malloc(uid.data_size); - memcpy(data, uid.data, uid.data_size); + furi_assert(uid.data); with_view_model( view->view, FuzzerViewAttackModel * model, { - snprintf( - model->uid, - uid.data_size * 3, - "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X", - data[0], - data[1], - data[2], - data[3], - data[4], - data[5], - data[6], - data[7]); + furi_string_printf(model->uid_str, "%02X", uid.data[0]); + for(uint8_t i = 1; i < uid.data_size; i++) { + furi_string_cat_printf(model->uid_str, ":%02X", uid.data[i]); + } }, true); - - free(data); } void fuzzer_view_attack_start(FuzzerViewAttack* view) { @@ -133,10 +120,11 @@ void fuzzer_view_attack_draw(Canvas* canvas, FuzzerViewAttackModel* model) { canvas_draw_str_aligned(canvas, 64, 26, AlignCenter, AlignTop, model->protocol_name); canvas_set_font(canvas, FontPrimary); - if(128 < canvas_string_width(canvas, model->uid)) { + if(128 < canvas_string_width(canvas, furi_string_get_cstr(model->uid_str))) { canvas_set_font(canvas, FontSecondary); } - canvas_draw_str_aligned(canvas, 64, 38, AlignCenter, AlignTop, model->uid); + canvas_draw_str_aligned( + canvas, 64, 38, AlignCenter, AlignTop, furi_string_get_cstr(model->uid_str)); canvas_set_font(canvas, FontSecondary); if(model->attack_state == FuzzerAttackStateRunning) { @@ -245,10 +233,11 @@ FuzzerViewAttack* fuzzer_view_attack_alloc() { FuzzerViewAttackModel * model, { model->time_delay = FUZZ_TIME_DELAY_MIN; - model->uid = malloc(ATTACK_SCENE_MAX_UID_LENGTH + 1); + model->uid_str = furi_string_alloc_set_str("Not_set"); + // malloc(ATTACK_SCENE_MAX_UID_LENGTH + 1); model->attack_state = FuzzerAttackStateOff; - strcpy(model->uid, "Not_set"); + // strcpy(model->uid_str, "Not_set"); model->attack_name = "Not_set"; model->protocol_name = "Not_set"; }, @@ -260,7 +249,10 @@ void fuzzer_view_attack_free(FuzzerViewAttack* view_attack) { furi_assert(view_attack); with_view_model( - view_attack->view, FuzzerViewAttackModel * model, { free(model->uid); }, true); + view_attack->view, + FuzzerViewAttackModel * model, + { furi_string_free(model->uid_str); }, + true); view_free(view_attack->view); free(view_attack); } diff --git a/applications/external/pacs_fuzzer/views/field_editor.c b/applications/external/pacs_fuzzer/views/field_editor.c index 53e15e152..07a19ae0e 100644 --- a/applications/external/pacs_fuzzer/views/field_editor.c +++ b/applications/external/pacs_fuzzer/views/field_editor.c @@ -5,8 +5,21 @@ #include #include +#define FIELD_EDITOR_V2 + +#define GUI_DISPLAY_WIDTH 128 +#define GUI_DISPLAY_HEIGHT 64 + +#define GUI_DISPLAY_HORIZONTAL_CENTER 64 +#define GUI_DISPLAY_VERTICAL_CENTER 32 + #define UID_STR_LENGTH 25 + +#ifdef FIELD_EDITOR_V2 +#define EDITOR_STRING_Y 38 +#else #define EDITOR_STRING_Y 50 +#endif struct FuzzerViewFieldEditor { View* view; @@ -14,7 +27,6 @@ struct FuzzerViewFieldEditor { void* context; }; -// TODO model typedef struct { uint8_t* uid; uint8_t uid_size; @@ -72,15 +84,55 @@ void fuzzer_view_field_editor_draw(Canvas* canvas, FuzzerViewFieldEditorModel* m canvas_clear(canvas); canvas_set_color(canvas, ColorBlack); +#ifdef FIELD_EDITOR_V2 + canvas_set_font(canvas, FontSecondary); - canvas_draw_str_aligned(canvas, 64, 5, AlignCenter, AlignTop, "Left and right: select byte"); - canvas_draw_str_aligned(canvas, 64, 15, AlignCenter, AlignTop, "Up and down: adjust byte"); + + canvas_draw_icon(canvas, 2, 4, &I_ButtonLeft_4x7); + canvas_draw_icon(canvas, 8, 4, &I_ButtonRight_4x7); + + canvas_draw_icon_ex(canvas, 62, 3, &I_Pin_arrow_up_7x9, IconRotation180); + canvas_draw_icon(canvas, 69, 3, &I_Pin_arrow_up_7x9); + + canvas_draw_str(canvas, 14, 10, "select byte"); + canvas_draw_str(canvas, 79, 10, "adjust byte"); char msg_index[18]; canvas_set_font(canvas, FontPrimary); snprintf(msg_index, sizeof(msg_index), "Field index : %d", model->index); - canvas_draw_str_aligned(canvas, 64, 30, AlignCenter, AlignTop, msg_index); + canvas_draw_str_aligned( + canvas, GUI_DISPLAY_HORIZONTAL_CENTER, 24, AlignCenter, AlignBottom, msg_index); + + canvas_set_font(canvas, FontSecondary); + canvas_draw_icon(canvas, 4, 52, &I_Pin_back_arrow_10x8); + canvas_draw_icon(canvas, 85, 52, &I_Ok_btn_9x9); + + canvas_draw_str(canvas, 16, 60, "Back"); + canvas_draw_str(canvas, 96, 60, "Attack"); +#else + canvas_set_font(canvas, FontSecondary); + canvas_draw_str_aligned( + canvas, + GUI_DISPLAY_HORIZONTAL_CENTER, + 5, + AlignCenter, + AlignTop, + "Left and right: select byte"); + canvas_draw_str_aligned( + canvas, + GUI_DISPLAY_HORIZONTAL_CENTER, + 15, + AlignCenter, + AlignTop, + "Up and down: adjust byte"); + + char msg_index[18]; + canvas_set_font(canvas, FontPrimary); + snprintf(msg_index, sizeof(msg_index), "Field index : %d", model->index); + canvas_draw_str_aligned( + canvas, GUI_DISPLAY_HORIZONTAL_CENTER, 28, AlignCenter, AlignTop, msg_index); +#endif // ####### Editor ####### FuriString* temp_s = model->uid_str; canvas_set_font(canvas, FontSecondary); @@ -88,7 +140,7 @@ void fuzzer_view_field_editor_draw(Canvas* canvas, FuzzerViewFieldEditorModel* m furi_string_reset(temp_s); for(int i = -3; i != 0; i++) { if(0 <= (model->index + i)) { - furi_string_cat_printf(temp_s, "%2X ", model->uid[model->index + i]); + furi_string_cat_printf(temp_s, "%02X ", model->uid[model->index + i]); } } canvas_draw_str_aligned( @@ -97,7 +149,7 @@ void fuzzer_view_field_editor_draw(Canvas* canvas, FuzzerViewFieldEditorModel* m furi_string_reset(temp_s); for(int i = 1; i != 4; i++) { if((model->index + i) < model->uid_size) { - furi_string_cat_printf(temp_s, " %2X", model->uid[model->index + i]); + furi_string_cat_printf(temp_s, " %02X", model->uid[model->index + i]); } } canvas_draw_str_aligned( @@ -108,16 +160,31 @@ void fuzzer_view_field_editor_draw(Canvas* canvas, FuzzerViewFieldEditorModel* m furi_string_reset(temp_s); furi_string_cat_printf(temp_s, "<%02X>", model->uid[model->index]); canvas_draw_str_aligned( - canvas, 64, EDITOR_STRING_Y, AlignCenter, AlignBottom, furi_string_get_cstr(temp_s)); + canvas, + GUI_DISPLAY_HORIZONTAL_CENTER, + EDITOR_STRING_Y, + AlignCenter, + AlignBottom, + furi_string_get_cstr(temp_s)); uint16_t w = canvas_string_width(canvas, furi_string_get_cstr(temp_s)); w -= 11; // '<' & '>' w /= 2; if(model->lo) { - canvas_draw_line(canvas, 64 + 1, EDITOR_STRING_Y + 2, 64 + w, EDITOR_STRING_Y + 2); + canvas_draw_line( + canvas, + GUI_DISPLAY_HORIZONTAL_CENTER + 1, + EDITOR_STRING_Y + 2, + GUI_DISPLAY_HORIZONTAL_CENTER + w, + EDITOR_STRING_Y + 2); } else { - canvas_draw_line(canvas, 64 - w, EDITOR_STRING_Y + 2, 64 - 1, EDITOR_STRING_Y + 2); + canvas_draw_line( + canvas, + GUI_DISPLAY_HORIZONTAL_CENTER - w, + EDITOR_STRING_Y + 2, + GUI_DISPLAY_HORIZONTAL_CENTER - 1, + EDITOR_STRING_Y + 2); } // ####### Editor ####### } @@ -211,29 +278,6 @@ bool fuzzer_view_field_editor_input(InputEvent* event, void* context) { void fuzzer_view_field_editor_enter(void* context) { furi_assert(context); - // TODO delete only for debug - // FuzzerViewFieldEditor* view_edit = context; - // uint8_t temp[8] = { - // 0x12, - // 0x34, - // 0x56, - // 0x78, - // 0x90, - // 0xAB, - // 0xCD, - // 0xEF, - // }; - // with_view_model( - // view_edit->view, - // FuzzerViewFieldEditorModel * model, - // { - // memcpy(model->uid, &temp, 8); - - // // memset(model->uid, 0xCC, 8); - // model->index = 0; - // model->uid_size = 8; - // }, - // true); } void fuzzer_view_field_editor_exit(void* context) { diff --git a/applications/external/pacs_fuzzer/views/main_menu.c b/applications/external/pacs_fuzzer/views/main_menu.c index 49b0a0d9c..14422145b 100644 --- a/applications/external/pacs_fuzzer/views/main_menu.c +++ b/applications/external/pacs_fuzzer/views/main_menu.c @@ -14,7 +14,6 @@ struct FuzzerViewMain { void* context; }; -// TODO Furi string for procol name typedef struct { uint8_t proto_index; uint8_t menu_index; From a0638588428301fb6e6f4b07b942210d35750cb0 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 6 Jun 2023 13:03:36 +0300 Subject: [PATCH 15/31] Fuzzer App: notifications --- applications/external/pacs_fuzzer/fuzzer.c | 15 +++ applications/external/pacs_fuzzer/fuzzer_i.h | 7 +- .../pacs_fuzzer/helpers/fuzzer_custom_event.h | 3 +- .../pacs_fuzzer/helpers/fuzzer_types.h | 2 + .../pacs_fuzzer/scenes/fuzzer_scene_attack.c | 107 ++++++++++++------ .../pacs_fuzzer/scenes/fuzzer_scene_main.c | 33 ++++++ applications/external/pacs_fuzzer/todo.md | 16 ++- 7 files changed, 140 insertions(+), 43 deletions(-) diff --git a/applications/external/pacs_fuzzer/fuzzer.c b/applications/external/pacs_fuzzer/fuzzer.c index 0a9aa3f7d..c80c18130 100644 --- a/applications/external/pacs_fuzzer/fuzzer.c +++ b/applications/external/pacs_fuzzer/fuzzer.c @@ -35,9 +35,16 @@ PacsFuzzerApp* fuzzer_app_alloc() { // Dialog app->dialogs = furi_record_open(RECORD_DIALOGS); + // Open Notification record + app->notifications = furi_record_open(RECORD_NOTIFICATION); + // View Dispatcher app->view_dispatcher = view_dispatcher_alloc(); + // Popup + app->popup = popup_alloc(); + view_dispatcher_add_view(app->view_dispatcher, FuzzerViewIDPopup, popup_get_view(app->popup)); + // Main view app->main_view = fuzzer_view_main_alloc(); view_dispatcher_add_view( @@ -88,6 +95,10 @@ void fuzzer_app_free(PacsFuzzerApp* app) { view_dispatcher_remove_view(app->view_dispatcher, FuzzerViewIDFieldEditor); fuzzer_view_field_editor_free(app->field_editor_view); + // Popup + view_dispatcher_remove_view(app->view_dispatcher, FuzzerViewIDPopup); + popup_free(app->popup); + scene_manager_free(app->scene_manager); view_dispatcher_free(app->view_dispatcher); @@ -97,6 +108,10 @@ void fuzzer_app_free(PacsFuzzerApp* app) { // Close records furi_record_close(RECORD_GUI); + // Notifications + furi_record_close(RECORD_NOTIFICATION); + app->notifications = NULL; + furi_string_free(app->file_path); fuzzer_worker_free(app->worker); diff --git a/applications/external/pacs_fuzzer/fuzzer_i.h b/applications/external/pacs_fuzzer/fuzzer_i.h index 2f24ec431..1dad1608a 100644 --- a/applications/external/pacs_fuzzer/fuzzer_i.h +++ b/applications/external/pacs_fuzzer/fuzzer_i.h @@ -3,11 +3,13 @@ #include #include -#include #include #include #include +#include + #include +#include #include "scenes/fuzzer_scene.h" #include "views/main_menu.h" @@ -33,9 +35,12 @@ typedef struct { typedef struct { Gui* gui; + NotificationApp* notifications; + ViewDispatcher* view_dispatcher; SceneManager* scene_manager; + Popup* popup; DialogsApp* dialogs; FuzzerViewMain* main_view; FuzzerViewAttack* attack_view; diff --git a/applications/external/pacs_fuzzer/helpers/fuzzer_custom_event.h b/applications/external/pacs_fuzzer/helpers/fuzzer_custom_event.h index 930029d3c..321187722 100644 --- a/applications/external/pacs_fuzzer/helpers/fuzzer_custom_event.h +++ b/applications/external/pacs_fuzzer/helpers/fuzzer_custom_event.h @@ -5,10 +5,11 @@ typedef enum { // FuzzerCustomEvent FuzzerCustomEventViewMainBack = 100, FuzzerCustomEventViewMainOk, + FuzzerCustomEventViewMainPopupErr, FuzzerCustomEventViewAttackBack, FuzzerCustomEventViewAttackOk, - FuzzerCustomEventViewAttackTick, + // FuzzerCustomEventViewAttackTick, // now not use FuzzerCustomEventViewAttackEnd, FuzzerCustomEventViewFieldEditorBack, diff --git a/applications/external/pacs_fuzzer/helpers/fuzzer_types.h b/applications/external/pacs_fuzzer/helpers/fuzzer_types.h index 259fc2b52..e4661ed7b 100644 --- a/applications/external/pacs_fuzzer/helpers/fuzzer_types.h +++ b/applications/external/pacs_fuzzer/helpers/fuzzer_types.h @@ -16,6 +16,8 @@ typedef enum { } FuzzerAttackState; typedef enum { + FuzzerViewIDPopup, + FuzzerViewIDMain, FuzzerViewIDAttack, FuzzerViewIDFieldEditor, diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c index 61fa84261..a0bd0e2d3 100644 --- a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c @@ -3,23 +3,15 @@ // TODO simlify callbacks and attack state -void fuzzer_scene_attack_worker_tick_callback(void* context) { - furi_assert(context); - PacsFuzzerApp* app = context; - view_dispatcher_send_custom_event(app->view_dispatcher, FuzzerCustomEventViewAttackTick); -} - -void fuzzer_scene_attack_worker_end_callback(void* context) { - furi_assert(context); - PacsFuzzerApp* app = context; - view_dispatcher_send_custom_event(app->view_dispatcher, FuzzerCustomEventViewAttackEnd); -} - -void fuzzer_scene_attack_callback(FuzzerCustomEvent event, void* context) { - furi_assert(context); - PacsFuzzerApp* app = context; - view_dispatcher_send_custom_event(app->view_dispatcher, event); -} +const NotificationSequence sequence_one_green_50_on_blink_blue = { + &message_red_255, + &message_delay_50, + &message_red_0, + &message_blink_start_10, + &message_blink_set_color_blue, + &message_do_not_reset, + NULL, +}; static void fuzzer_scene_attack_update_uid(PacsFuzzerApp* app) { furi_assert(app); @@ -34,6 +26,56 @@ static void fuzzer_scene_attack_update_uid(PacsFuzzerApp* app) { free(uid.data); } +static void fuzzer_scene_attack_set_state(PacsFuzzerApp* app, FuzzerAttackState state) { + furi_assert(app); + + scene_manager_set_scene_state(app->scene_manager, FuzzerSceneAttack, state); + switch(state) { + case FuzzerAttackStateIdle: + notification_message(app->notifications, &sequence_blink_stop); + fuzzer_view_attack_pause(app->attack_view); + break; + + case FuzzerAttackStateRunning: + notification_message(app->notifications, &sequence_blink_start_blue); + fuzzer_view_attack_start(app->attack_view); + break; + + case FuzzerAttackStateEnd: + notification_message(app->notifications, &sequence_blink_stop); + notification_message(app->notifications, &sequence_single_vibro); + fuzzer_view_attack_end(app->attack_view); + break; + + case FuzzerAttackStateOff: + notification_message(app->notifications, &sequence_blink_stop); + fuzzer_view_attack_stop(app->attack_view); + break; + } +} + +void fuzzer_scene_attack_worker_tick_callback(void* context) { + furi_assert(context); + PacsFuzzerApp* app = context; + + notification_message(app->notifications, &sequence_one_green_50_on_blink_blue); + fuzzer_scene_attack_update_uid(app); + + // view_dispatcher_send_custom_event(app->view_dispatcher, FuzzerCustomEventViewAttackTick); +} + +void fuzzer_scene_attack_worker_end_callback(void* context) { + furi_assert(context); + PacsFuzzerApp* app = context; + view_dispatcher_send_custom_event(app->view_dispatcher, FuzzerCustomEventViewAttackEnd); +} + +void fuzzer_scene_attack_callback(FuzzerCustomEvent event, void* context) { + furi_assert(context); + PacsFuzzerApp* app = context; + view_dispatcher_send_custom_event(app->view_dispatcher, event); +} + void fuzzer_scene_attack_on_enter(void* context) { furi_assert(context); PacsFuzzerApp* app = context; @@ -68,15 +110,13 @@ bool fuzzer_scene_attack_on_event(void* context, SceneManagerEvent event) { FuzzerAttackStateRunning) { // Pause if attack running fuzzer_worker_pause(app->worker); - scene_manager_set_scene_state( - app->scene_manager, FuzzerSceneAttack, FuzzerAttackStateIdle); - fuzzer_view_attack_pause(app->attack_view); + + fuzzer_scene_attack_set_state(app, FuzzerAttackStateIdle); } else { // Exit fuzzer_worker_stop(app->worker); - scene_manager_set_scene_state( - app->scene_manager, FuzzerSceneAttack, FuzzerAttackStateOff); - fuzzer_view_attack_stop(app->attack_view); + + fuzzer_scene_attack_set_state(app, FuzzerAttackStateOff); if(!scene_manager_previous_scene(app->scene_manager)) { scene_manager_stop(app->scene_manager); view_dispatcher_stop(app->view_dispatcher); @@ -89,28 +129,23 @@ bool fuzzer_scene_attack_on_event(void* context, SceneManagerEvent event) { // Start or Continue Attack if(fuzzer_worker_start( app->worker, fuzzer_view_attack_get_time_delay(app->attack_view))) { - scene_manager_set_scene_state( - app->scene_manager, FuzzerSceneAttack, FuzzerAttackStateRunning); - fuzzer_view_attack_start(app->attack_view); + fuzzer_scene_attack_set_state(app, FuzzerAttackStateRunning); } else { // Error? } } else if( scene_manager_get_scene_state(app->scene_manager, FuzzerSceneAttack) == FuzzerAttackStateRunning) { - scene_manager_set_scene_state( - app->scene_manager, FuzzerSceneAttack, FuzzerAttackStateIdle); - fuzzer_view_attack_pause(app->attack_view); + // Pause if attack running fuzzer_worker_pause(app->worker); // XXX + + fuzzer_scene_attack_set_state(app, FuzzerAttackStateIdle); } consumed = true; - } else if(event.event == FuzzerCustomEventViewAttackTick) { - fuzzer_scene_attack_update_uid(app); - consumed = true; + // } else if(event.event == FuzzerCustomEventViewAttackTick) { + // consumed = true; } else if(event.event == FuzzerCustomEventViewAttackEnd) { - scene_manager_set_scene_state( - app->scene_manager, FuzzerSceneAttack, FuzzerAttackStateEnd); - fuzzer_view_attack_end(app->attack_view); + fuzzer_scene_attack_set_state(app, FuzzerAttackStateEnd); consumed = true; } } @@ -122,6 +157,8 @@ void fuzzer_scene_attack_on_exit(void* context) { furi_assert(context); PacsFuzzerApp* app = context; + // fuzzer_worker_stop(); // XXX + fuzzer_worker_set_uid_chaged_callback(app->worker, NULL, NULL); fuzzer_worker_set_end_callback(app->worker, NULL, NULL); } diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c index 699037430..cfa43ad87 100644 --- a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c @@ -9,6 +9,12 @@ void fuzzer_scene_main_callback(FuzzerCustomEvent event, void* context) { view_dispatcher_send_custom_event(app->view_dispatcher, event); } +void fuzzer_scene_main_error_popup_callback(void* context) { + PacsFuzzerApp* app = context; + notification_message(app->notifications, &sequence_reset_rgb); + view_dispatcher_send_custom_event(app->view_dispatcher, FuzzerCustomEventViewMainPopupErr); +} + static bool fuzzer_scene_main_load_custom_dict(void* context) { furi_assert(context); PacsFuzzerApp* app = context; @@ -49,6 +55,15 @@ static bool fuzzer_scene_main_load_key(void* context) { return res; } +static void fuzzer_scene_main_show_error(void* context, const char* erre_str) { + furi_assert(context); + PacsFuzzerApp* app = context; + popup_set_header(app->popup, erre_str, 64, 20, AlignCenter, AlignTop); + notification_message(app->notifications, &sequence_set_red_255); + notification_message(app->notifications, &sequence_double_vibro); + view_dispatcher_switch_to_view(app->view_dispatcher, FuzzerViewIDPopup); +} + void fuzzer_scene_main_on_enter(void* context) { furi_assert(context); PacsFuzzerApp* app = context; @@ -57,6 +72,14 @@ void fuzzer_scene_main_on_enter(void* context) { fuzzer_view_main_update_data(app->main_view, app->fuzzer_state); + // Setup view + Popup* popup = app->popup; + // popup_set_icon(popup, 72, 17, &I_DolphinCommon_56x48); + popup_set_timeout(popup, 2500); + popup_set_context(popup, app); + popup_set_callback(popup, fuzzer_scene_main_error_popup_callback); + popup_enable_timeout(popup); + view_dispatcher_switch_to_view(app->view_dispatcher, FuzzerViewIDMain); } @@ -72,6 +95,9 @@ bool fuzzer_scene_main_on_event(void* context, SceneManagerEvent event) { view_dispatcher_stop(app->view_dispatcher); } consumed = true; + } else if(event.event == FuzzerCustomEventViewMainPopupErr) { + view_dispatcher_switch_to_view(app->view_dispatcher, FuzzerViewIDMain); + consumed = true; } else if(event.event == FuzzerCustomEventViewMainOk) { fuzzer_view_main_get_state(app->main_view, &app->fuzzer_state); @@ -88,9 +114,11 @@ bool fuzzer_scene_main_on_event(void* context, SceneManagerEvent event) { if(!loading_ok) { // error + fuzzer_scene_main_show_error(app, "Default dictionary\nis empty"); } break; case FuzzerAttackIdBFCustomerID: + // TODO uid = malloc(d_size); memset(uid, 0x00, d_size); @@ -114,6 +142,7 @@ bool fuzzer_scene_main_on_event(void* context, SceneManagerEvent event) { scene_manager_next_scene(app->scene_manager, FuzzerSceneFieldEditor); FURI_LOG_I("Scene", "Load ok"); } else { + fuzzer_scene_main_show_error(app, "Unsupported protocol\nor broken file"); FURI_LOG_W("Scene", "Load err"); } } @@ -125,6 +154,10 @@ bool fuzzer_scene_main_on_event(void* context, SceneManagerEvent event) { } else { loading_ok = fuzzer_worker_init_attack_file_dict( app->worker, app->fuzzer_state.proto_index, app->file_path); + if(!loading_ok) { + fuzzer_scene_main_show_error(app, "Incorrect key format\nor length"); + // error + } } break; diff --git a/applications/external/pacs_fuzzer/todo.md b/applications/external/pacs_fuzzer/todo.md index 9070e6363..98450035c 100644 --- a/applications/external/pacs_fuzzer/todo.md +++ b/applications/external/pacs_fuzzer/todo.md @@ -5,10 +5,13 @@ - [ ] Make the "Load File" independent of the current protocol - [x] Add pause - [ ] Switching UIDs if possible -- [ ] Led and sound Notification -- [ ] Error Notification - - [ ] Custom UIDs dict loading - - [ ] Key file loading +- [x] Led and sound Notification + - [x] Led + - [x] Vibro + - [ ] Sound? +- [x] Error Notification + - [x] Custom UIDs dict loading + - [x] Key file loading - [ ] Anything else #### App functionality @@ -20,7 +23,6 @@ - [ ] GUI - [x] Rewrite `gui_const` logic - - [ ] Separate protocol name from `fuzzer_proto_items` - [x] Icon in dialog - [x] Description and buttons in `field_editor` view - [ ] Protocol carousel in `main_menu` @@ -30,4 +32,6 @@ - [x] `UID_MAX_SIZE` - [x] Add pause - [x] Fix `Custom dict` attack when ended -- [x] this can be simplified `fuzzer_proto_items` +- [ ] Worker + - [ ] Use `prtocol_id` instead of protocol name + - [x] this can be simplified `fuzzer_proto_items` \ No newline at end of file From d2b0aa8513e9df980d6d1d94261663e5838605c9 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 6 Jun 2023 15:13:50 +0300 Subject: [PATCH 16/31] Fuzzer App: fix time_delay --- applications/external/pacs_fuzzer/fuzzer_i.h | 1 - .../pacs_fuzzer/lib/worker/fake_worker.c | 65 ++++++++++++------- .../pacs_fuzzer/lib/worker/protocol.c | 4 ++ .../pacs_fuzzer/lib/worker/protocol.h | 6 ++ .../pacs_fuzzer/lib/worker/protocol_i.h | 4 ++ .../external/pacs_fuzzer/views/attack.c | 10 +-- 6 files changed, 61 insertions(+), 29 deletions(-) diff --git a/applications/external/pacs_fuzzer/fuzzer_i.h b/applications/external/pacs_fuzzer/fuzzer_i.h index 1dad1608a..63bf85d24 100644 --- a/applications/external/pacs_fuzzer/fuzzer_i.h +++ b/applications/external/pacs_fuzzer/fuzzer_i.h @@ -22,7 +22,6 @@ #include #include "fuzzer_icons.h" -#define FUZZ_TIME_DELAY_MIN (5) #define FUZZ_TIME_DELAY_MAX (80) typedef struct { diff --git a/applications/external/pacs_fuzzer/lib/worker/fake_worker.c b/applications/external/pacs_fuzzer/lib/worker/fake_worker.c index 9d3d89cdf..896088308 100644 --- a/applications/external/pacs_fuzzer/lib/worker/fake_worker.c +++ b/applications/external/pacs_fuzzer/lib/worker/fake_worker.c @@ -8,7 +8,6 @@ #include #define TAG "Fuzzer worker" -#define FUZZ_TIME_DELAY_DEFAULT (10) #if defined(RFID_125_PROTOCOL) @@ -39,7 +38,8 @@ struct FuzzerWorker { const FuzzerProtocol* protocol; FuzzerWorkerAttackType attack_type; - uint8_t timeer_delay; + uint8_t timer_idle_delay; + uint8_t timer_emu_delay; uint8_t payload[MAX_PAYLOAD_SIZE]; Stream* uids_stream; @@ -47,6 +47,7 @@ struct FuzzerWorker { uint8_t chusen_byte; bool treead_running; + bool in_emu_phase; FuriTimer* timer; FuzzerWorkerUidChagedCallback tick_callback; @@ -147,29 +148,35 @@ static void fuzzer_worker_on_tick_callback(void* context) { FuzzerWorker* instance = context; - if(instance->treead_running) { -#if defined(RFID_125_PROTOCOL) - lfrfid_worker_stop(instance->proto_worker); -#else - ibutton_worker_stop(instance->proto_worker); -#endif - } - - if(!fuzzer_worker_load_key(instance, true)) { - fuzzer_worker_pause(instance); // XXX - if(instance->end_callback) { - instance->end_callback(instance->end_context); - } - } else { + if(instance->in_emu_phase) { if(instance->treead_running) { #if defined(RFID_125_PROTOCOL) - lfrfid_worker_emulate_start(instance->proto_worker, instance->protocol_id); + lfrfid_worker_stop(instance->proto_worker); #else - ibutton_worker_emulate_start(instance->proto_worker, instance->key); + ibutton_worker_stop(instance->proto_worker); #endif } - if(instance->tick_callback) { - instance->tick_callback(instance->tick_context); + instance->in_emu_phase = false; + furi_timer_start(instance->timer, furi_ms_to_ticks(instance->timer_idle_delay * 100)); + } else { + if(!fuzzer_worker_load_key(instance, true)) { + fuzzer_worker_pause(instance); // XXX + if(instance->end_callback) { + instance->end_callback(instance->end_context); + } + } else { + if(instance->treead_running) { +#if defined(RFID_125_PROTOCOL) + lfrfid_worker_emulate_start(instance->proto_worker, instance->protocol_id); +#else + ibutton_worker_emulate_start(instance->proto_worker, instance->key); +#endif + } + instance->in_emu_phase = true; + furi_timer_start(instance->timer, furi_ms_to_ticks(instance->timer_emu_delay * 100)); + if(instance->tick_callback) { + instance->tick_callback(instance->tick_context); + } } } } @@ -338,13 +345,15 @@ FuzzerWorker* fuzzer_worker_alloc() { instance->attack_type = FuzzerWorkerAttackTypeMax; instance->index = 0; instance->treead_running = false; + instance->in_emu_phase = false; memset(instance->payload, 0x00, sizeof(instance->payload)); - instance->timeer_delay = FUZZ_TIME_DELAY_DEFAULT; + instance->timer_idle_delay = PROTOCOL_MIN_IDLE_DELAY; + instance->timer_emu_delay = PROTOCOL_MIN_IDLE_DELAY; instance->timer = - furi_timer_alloc(fuzzer_worker_on_tick_callback, FuriTimerTypePeriodic, instance); + furi_timer_alloc(fuzzer_worker_on_tick_callback, FuriTimerTypeOnce, instance); return instance; } @@ -374,9 +383,15 @@ bool fuzzer_worker_start(FuzzerWorker* instance, uint8_t timer_dellay) { furi_assert(instance); if(instance->attack_type < FuzzerWorkerAttackTypeMax) { - instance->timeer_delay = timer_dellay; + uint8_t temp = timer_dellay / 2; + instance->timer_emu_delay = temp; + instance->timer_idle_delay = temp + timer_dellay % 2; - furi_timer_start(instance->timer, furi_ms_to_ticks(timer_dellay * 100)); + FURI_LOG_D( + TAG, + "Emu_delay %u Idle_delay %u", + instance->timer_emu_delay, + instance->timer_idle_delay); if(!instance->treead_running) { #if defined(RFID_125_PROTOCOL) @@ -397,6 +412,8 @@ bool fuzzer_worker_start(FuzzerWorker* instance, uint8_t timer_dellay) { // ibutton_worker_start_thread(instance->proto_worker); ibutton_worker_emulate_start(instance->proto_worker, instance->key); #endif + instance->in_emu_phase = true; + furi_timer_start(instance->timer, furi_ms_to_ticks(instance->timer_emu_delay * 100)); return true; } return false; diff --git a/applications/external/pacs_fuzzer/lib/worker/protocol.c b/applications/external/pacs_fuzzer/lib/worker/protocol.c index c295289ae..fb7651901 100644 --- a/applications/external/pacs_fuzzer/lib/worker/protocol.c +++ b/applications/external/pacs_fuzzer/lib/worker/protocol.c @@ -254,6 +254,10 @@ uint8_t fuzzer_proto_get_max_data_size() { return MAX_PAYLOAD_SIZE; } +uint8_t fuzzer_proto_get_min_delay() { + return PROTOCOL_TIME_DELAY_MIN; +} + const char* fuzzer_proto_get_menu_label(uint8_t index) { return fuzzer_menu_items[index].menu_label; } diff --git a/applications/external/pacs_fuzzer/lib/worker/protocol.h b/applications/external/pacs_fuzzer/lib/worker/protocol.h index 4c2c70e0c..62ce88d5c 100644 --- a/applications/external/pacs_fuzzer/lib/worker/protocol.h +++ b/applications/external/pacs_fuzzer/lib/worker/protocol.h @@ -37,6 +37,12 @@ struct FuzzerPayload { */ uint8_t fuzzer_proto_get_max_data_size(); +/** + * Get minimum time delay for protocols + * @return Minimum time delay + */ +uint8_t fuzzer_proto_get_min_delay(); + /** * Get protocol name based on its index * @param index protocol index diff --git a/applications/external/pacs_fuzzer/lib/worker/protocol_i.h b/applications/external/pacs_fuzzer/lib/worker/protocol_i.h index 841784f16..793b3e043 100644 --- a/applications/external/pacs_fuzzer/lib/worker/protocol_i.h +++ b/applications/external/pacs_fuzzer/lib/worker/protocol_i.h @@ -4,8 +4,12 @@ #if defined(RFID_125_PROTOCOL) #define MAX_PAYLOAD_SIZE (6) +#define PROTOCOL_MIN_IDLE_DELAY (5) +#define PROTOCOL_TIME_DELAY_MIN PROTOCOL_MIN_IDLE_DELAY + 4 #else #define MAX_PAYLOAD_SIZE (8) +#define PROTOCOL_MIN_IDLE_DELAY (2) +#define PROTOCOL_TIME_DELAY_MIN PROTOCOL_MIN_IDLE_DELAY + 2 #endif typedef struct ProtoDict ProtoDict; diff --git a/applications/external/pacs_fuzzer/views/attack.c b/applications/external/pacs_fuzzer/views/attack.c index 13e2325fd..1df6d5eb3 100644 --- a/applications/external/pacs_fuzzer/views/attack.c +++ b/applications/external/pacs_fuzzer/views/attack.c @@ -15,6 +15,7 @@ struct FuzzerViewAttack { typedef struct { uint8_t time_delay; + uint8_t time_delay_min; const char* attack_name; const char* protocol_name; FuzzerAttackState attack_state; @@ -157,14 +158,14 @@ bool fuzzer_view_attack_input(InputEvent* event, void* context) { if(model->attack_state == FuzzerAttackStateIdle) { // TimeDelay if(event->type == InputTypeShort) { - if(model->time_delay > FUZZ_TIME_DELAY_MIN) { + if(model->time_delay > model->time_delay_min) { model->time_delay--; } } else if(event->type == InputTypeLong) { - if((model->time_delay - 10) >= FUZZ_TIME_DELAY_MIN) { + if((model->time_delay - 10) >= model->time_delay_min) { model->time_delay -= 10; } else { - model->time_delay = FUZZ_TIME_DELAY_MIN; + model->time_delay = model->time_delay_min; } } } else if( @@ -232,7 +233,8 @@ FuzzerViewAttack* fuzzer_view_attack_alloc() { view_attack->view, FuzzerViewAttackModel * model, { - model->time_delay = FUZZ_TIME_DELAY_MIN; + model->time_delay_min = fuzzer_proto_get_min_delay(); + model->time_delay = model->time_delay_min; model->uid_str = furi_string_alloc_set_str("Not_set"); // malloc(ATTACK_SCENE_MAX_UID_LENGTH + 1); model->attack_state = FuzzerAttackStateOff; From caab7c8e1092ca7f090ec828ce9857b8197c1950 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 6 Jun 2023 16:55:29 +0300 Subject: [PATCH 17/31] Fuzzer App: Edit Manifests --- applications/external/pacs_fuzzer/application.fam | 14 ++++++-------- .../pacs_fuzzer/scenes/fuzzer_scene_attack.c | 2 +- applications/external/pacs_fuzzer/todo.md | 1 + 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/applications/external/pacs_fuzzer/application.fam b/applications/external/pacs_fuzzer/application.fam index 8e67af6d4..4d14e55fd 100644 --- a/applications/external/pacs_fuzzer/application.fam +++ b/applications/external/pacs_fuzzer/application.fam @@ -1,6 +1,6 @@ App( - appid="pacs_fuzzer", - name="Fuzzer Gui", + appid="pacs_fuzzer_ibtn", + name="iButton Fuzzer [B]", apptype=FlipperAppType.EXTERNAL, entry_point="fuzzer_start_ibtn", requires=[ @@ -10,8 +10,7 @@ App( "input", "notification", ], - stack_size=2 * 1024, - order=15, + stack_size=1 * 1024, fap_icon="icons/rfid_10px.png", fap_category="Debug", fap_private_libs=[ @@ -25,8 +24,8 @@ App( ) App( - appid="pacs_rfid_fuzzer", - name="Fuzzer Gui rfid", + appid="pacs_fuzzer_rfid", + name="RFID Fuzzer [B]", apptype=FlipperAppType.EXTERNAL, entry_point="fuzzer_start_rfid", requires=[ @@ -36,8 +35,7 @@ App( "input", "notification", ], - stack_size=2 * 1024, - order=15, + stack_size=1 * 1024, fap_icon="icons/125_10px.png", fap_category="Debug", fap_private_libs=[ diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c index a0bd0e2d3..36734495b 100644 --- a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c @@ -137,7 +137,7 @@ bool fuzzer_scene_attack_on_event(void* context, SceneManagerEvent event) { scene_manager_get_scene_state(app->scene_manager, FuzzerSceneAttack) == FuzzerAttackStateRunning) { // Pause if attack running - fuzzer_worker_pause(app->worker); // XXX + fuzzer_worker_pause(app->worker); fuzzer_scene_attack_set_state(app, FuzzerAttackStateIdle); } diff --git a/applications/external/pacs_fuzzer/todo.md b/applications/external/pacs_fuzzer/todo.md index 98450035c..823e2f05a 100644 --- a/applications/external/pacs_fuzzer/todo.md +++ b/applications/external/pacs_fuzzer/todo.md @@ -27,6 +27,7 @@ - [x] Description and buttons in `field_editor` view - [ ] Protocol carousel in `main_menu` - [x] prototype + - [ ] Add the ability to edit emulation time and downtime separately - [x] UID - [x] Simplify the storage and exchange of `uids.data` `uid.data_size` in `views` - [x] `UID_MAX_SIZE` From 7c172c7c064a6afe36d71ae571df4d6e6fa4744d Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 6 Jun 2023 19:23:39 +0300 Subject: [PATCH 18/31] Fuzzer App: revert stack_size --- applications/external/pacs_fuzzer/application.fam | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/applications/external/pacs_fuzzer/application.fam b/applications/external/pacs_fuzzer/application.fam index 4d14e55fd..6098322ac 100644 --- a/applications/external/pacs_fuzzer/application.fam +++ b/applications/external/pacs_fuzzer/application.fam @@ -10,7 +10,7 @@ App( "input", "notification", ], - stack_size=1 * 1024, + stack_size=2 * 1024, fap_icon="icons/rfid_10px.png", fap_category="Debug", fap_private_libs=[ @@ -35,7 +35,7 @@ App( "input", "notification", ], - stack_size=1 * 1024, + stack_size=2 * 1024, fap_icon="icons/125_10px.png", fap_category="Debug", fap_private_libs=[ From 28f4cd3d3ce172f9c60283120294de1a606d7165 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 6 Jun 2023 22:43:44 +0300 Subject: [PATCH 19/31] Fuzzer App: Zero idle time --- .../pacs_fuzzer/lib/worker/fake_worker.c | 32 +-- .../pacs_fuzzer/lib/worker/fake_worker.h | 5 +- .../pacs_fuzzer/lib/worker/protocol.c | 8 +- .../pacs_fuzzer/lib/worker/protocol.h | 8 +- .../pacs_fuzzer/lib/worker/protocol_i.h | 10 +- .../pacs_fuzzer/scenes/fuzzer_scene_attack.c | 5 +- applications/external/pacs_fuzzer/todo.md | 3 +- .../external/pacs_fuzzer/views/attack.c | 217 ++++++++++++++++-- .../external/pacs_fuzzer/views/attack.h | 4 +- 9 files changed, 237 insertions(+), 55 deletions(-) diff --git a/applications/external/pacs_fuzzer/lib/worker/fake_worker.c b/applications/external/pacs_fuzzer/lib/worker/fake_worker.c index 896088308..e48b1dd32 100644 --- a/applications/external/pacs_fuzzer/lib/worker/fake_worker.c +++ b/applications/external/pacs_fuzzer/lib/worker/fake_worker.c @@ -38,8 +38,8 @@ struct FuzzerWorker { const FuzzerProtocol* protocol; FuzzerWorkerAttackType attack_type; - uint8_t timer_idle_delay; - uint8_t timer_emu_delay; + uint8_t timer_idle_time; + uint8_t timer_emu_time; uint8_t payload[MAX_PAYLOAD_SIZE]; Stream* uids_stream; @@ -157,7 +157,7 @@ static void fuzzer_worker_on_tick_callback(void* context) { #endif } instance->in_emu_phase = false; - furi_timer_start(instance->timer, furi_ms_to_ticks(instance->timer_idle_delay * 100)); + furi_timer_start(instance->timer, furi_ms_to_ticks(instance->timer_idle_time * 100)); } else { if(!fuzzer_worker_load_key(instance, true)) { fuzzer_worker_pause(instance); // XXX @@ -173,7 +173,7 @@ static void fuzzer_worker_on_tick_callback(void* context) { #endif } instance->in_emu_phase = true; - furi_timer_start(instance->timer, furi_ms_to_ticks(instance->timer_emu_delay * 100)); + furi_timer_start(instance->timer, furi_ms_to_ticks(instance->timer_emu_time * 100)); if(instance->tick_callback) { instance->tick_callback(instance->tick_context); } @@ -349,8 +349,8 @@ FuzzerWorker* fuzzer_worker_alloc() { memset(instance->payload, 0x00, sizeof(instance->payload)); - instance->timer_idle_delay = PROTOCOL_MIN_IDLE_DELAY; - instance->timer_emu_delay = PROTOCOL_MIN_IDLE_DELAY; + instance->timer_idle_time = PROTOCOL_DEF_IDLE_TIME; + instance->timer_emu_time = PROTOCOL_DEF_EMU_TIME; instance->timer = furi_timer_alloc(fuzzer_worker_on_tick_callback, FuriTimerTypeOnce, instance); @@ -379,19 +379,21 @@ void fuzzer_worker_free(FuzzerWorker* instance) { free(instance); } -bool fuzzer_worker_start(FuzzerWorker* instance, uint8_t timer_dellay) { +bool fuzzer_worker_start(FuzzerWorker* instance, uint8_t idle_time, uint8_t emu_time) { furi_assert(instance); if(instance->attack_type < FuzzerWorkerAttackTypeMax) { - uint8_t temp = timer_dellay / 2; - instance->timer_emu_delay = temp; - instance->timer_idle_delay = temp + timer_dellay % 2; + // if(emu_time == 0) { + // uint8_t temp = idle_time / 2; + // instance->timer_emu_time = temp; + // instance->timer_idle_time = temp + idle_time % 2; + // } else { + instance->timer_idle_time = idle_time; + instance->timer_emu_time = emu_time; + // } FURI_LOG_D( - TAG, - "Emu_delay %u Idle_delay %u", - instance->timer_emu_delay, - instance->timer_idle_delay); + TAG, "Emu_time %u Idle_time %u", instance->timer_emu_time, instance->timer_idle_time); if(!instance->treead_running) { #if defined(RFID_125_PROTOCOL) @@ -413,7 +415,7 @@ bool fuzzer_worker_start(FuzzerWorker* instance, uint8_t timer_dellay) { ibutton_worker_emulate_start(instance->proto_worker, instance->key); #endif instance->in_emu_phase = true; - furi_timer_start(instance->timer, furi_ms_to_ticks(instance->timer_emu_delay * 100)); + furi_timer_start(instance->timer, furi_ms_to_ticks(instance->timer_emu_time * 100)); return true; } return false; diff --git a/applications/external/pacs_fuzzer/lib/worker/fake_worker.h b/applications/external/pacs_fuzzer/lib/worker/fake_worker.h index 04635169b..6396525be 100644 --- a/applications/external/pacs_fuzzer/lib/worker/fake_worker.h +++ b/applications/external/pacs_fuzzer/lib/worker/fake_worker.h @@ -35,10 +35,11 @@ void fuzzer_worker_free(FuzzerWorker* instance); * Start or continue emulation * * @param instance Pointer to a FuzzerWorker - * @param timer_dellay Emulation time of one UID in tenths of a second + * @param idle_time Delay between emulations in tenths of a second + * @param emu_time Emulation time of one UID in tenths of a second * @return bool True if emulation has started */ -bool fuzzer_worker_start(FuzzerWorker* instance, uint8_t timer_dellay); +bool fuzzer_worker_start(FuzzerWorker* instance, uint8_t idle_time, uint8_t emu_time); /** * Stop emulation and deinit worker diff --git a/applications/external/pacs_fuzzer/lib/worker/protocol.c b/applications/external/pacs_fuzzer/lib/worker/protocol.c index fb7651901..f520037ac 100644 --- a/applications/external/pacs_fuzzer/lib/worker/protocol.c +++ b/applications/external/pacs_fuzzer/lib/worker/protocol.c @@ -254,8 +254,12 @@ uint8_t fuzzer_proto_get_max_data_size() { return MAX_PAYLOAD_SIZE; } -uint8_t fuzzer_proto_get_min_delay() { - return PROTOCOL_TIME_DELAY_MIN; +uint8_t fuzzer_proto_get_def_emu_time() { + return PROTOCOL_DEF_EMU_TIME; +} + +uint8_t fuzzer_proto_get_def_idle_time() { + return PROTOCOL_DEF_IDLE_TIME; } const char* fuzzer_proto_get_menu_label(uint8_t index) { diff --git a/applications/external/pacs_fuzzer/lib/worker/protocol.h b/applications/external/pacs_fuzzer/lib/worker/protocol.h index 62ce88d5c..68632b029 100644 --- a/applications/external/pacs_fuzzer/lib/worker/protocol.h +++ b/applications/external/pacs_fuzzer/lib/worker/protocol.h @@ -37,11 +37,9 @@ struct FuzzerPayload { */ uint8_t fuzzer_proto_get_max_data_size(); -/** - * Get minimum time delay for protocols - * @return Minimum time delay - */ -uint8_t fuzzer_proto_get_min_delay(); +// TODO add description +uint8_t fuzzer_proto_get_def_emu_time(); +uint8_t fuzzer_proto_get_def_idle_time(); /** * Get protocol name based on its index diff --git a/applications/external/pacs_fuzzer/lib/worker/protocol_i.h b/applications/external/pacs_fuzzer/lib/worker/protocol_i.h index 793b3e043..074c50d9d 100644 --- a/applications/external/pacs_fuzzer/lib/worker/protocol_i.h +++ b/applications/external/pacs_fuzzer/lib/worker/protocol_i.h @@ -4,12 +4,14 @@ #if defined(RFID_125_PROTOCOL) #define MAX_PAYLOAD_SIZE (6) -#define PROTOCOL_MIN_IDLE_DELAY (5) -#define PROTOCOL_TIME_DELAY_MIN PROTOCOL_MIN_IDLE_DELAY + 4 +#define PROTOCOL_DEF_IDLE_TIME (4) +#define PROTOCOL_DEF_EMU_TIME (5) +#define PROTOCOL_TIME_DELAY_MIN PROTOCOL_DEF_IDLE_TIME + PROTOCOL_DEF_EMU_TIME #else #define MAX_PAYLOAD_SIZE (8) -#define PROTOCOL_MIN_IDLE_DELAY (2) -#define PROTOCOL_TIME_DELAY_MIN PROTOCOL_MIN_IDLE_DELAY + 2 +#define PROTOCOL_DEF_IDLE_TIME (2) +#define PROTOCOL_DEF_EMU_TIME (2) +#define PROTOCOL_TIME_DELAY_MIN PROTOCOL_DEF_IDLE_TIME + PROTOCOL_DEF_EMU_TIME #endif typedef struct ProtoDict ProtoDict; diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c index 36734495b..836bbdef5 100644 --- a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c @@ -127,8 +127,11 @@ bool fuzzer_scene_attack_on_event(void* context, SceneManagerEvent event) { if(scene_manager_get_scene_state(app->scene_manager, FuzzerSceneAttack) == FuzzerAttackStateIdle) { // Start or Continue Attack + // TODO emu_time if(fuzzer_worker_start( - app->worker, fuzzer_view_attack_get_time_delay(app->attack_view))) { + app->worker, + fuzzer_view_attack_get_time_delay(app->attack_view), + fuzzer_view_attack_get_emu_time(app->attack_view))) { fuzzer_scene_attack_set_state(app, FuzzerAttackStateRunning); } else { // Error? diff --git a/applications/external/pacs_fuzzer/todo.md b/applications/external/pacs_fuzzer/todo.md index 823e2f05a..d0bab30d6 100644 --- a/applications/external/pacs_fuzzer/todo.md +++ b/applications/external/pacs_fuzzer/todo.md @@ -27,7 +27,8 @@ - [x] Description and buttons in `field_editor` view - [ ] Protocol carousel in `main_menu` - [x] prototype - - [ ] Add the ability to edit emulation time and downtime separately + - [x] Add the ability to edit emulation time and downtime separately + - [ ] Decide on the display - [x] UID - [x] Simplify the storage and exchange of `uids.data` `uid.data_size` in `views` - [x] `UID_MAX_SIZE` diff --git a/applications/external/pacs_fuzzer/views/attack.c b/applications/external/pacs_fuzzer/views/attack.c index 1df6d5eb3..a29e2d966 100644 --- a/applications/external/pacs_fuzzer/views/attack.c +++ b/applications/external/pacs_fuzzer/views/attack.c @@ -4,8 +4,13 @@ #include #include +#define ATACK_VIEW_V2 +// #define ATACK_VIEW_V2_1 +#define ATACK_VIEW_V2_2 + #define ATTACK_SCENE_MAX_UID_LENGTH 25 #define UID_MAX_DISPLAYED_LEN (8U) +#define LIFT_RIGHT_OFFSET (3) struct FuzzerViewAttack { View* view; @@ -14,8 +19,11 @@ struct FuzzerViewAttack { }; typedef struct { - uint8_t time_delay; - uint8_t time_delay_min; + uint8_t time_delay; // 1 = 100ms + uint8_t time_delay_min; // 1 = 100ms + uint8_t emu_time; // 1 = 100ms + uint8_t emu_time_min; // 1 = 100ms + bool td_emt_cursor; // false - time_delay, true - emu_time const char* attack_name; const char* protocol_name; FuzzerAttackState attack_state; @@ -107,8 +115,7 @@ void fuzzer_view_attack_set_callback( } void fuzzer_view_attack_draw(Canvas* canvas, FuzzerViewAttackModel* model) { - char time_delay[16]; - snprintf(time_delay, sizeof(time_delay), "Time delay: %d", model->time_delay); + char temp_str[50]; canvas_clear(canvas); canvas_set_color(canvas, ColorBlack); @@ -116,8 +123,101 @@ void fuzzer_view_attack_draw(Canvas* canvas, FuzzerViewAttackModel* model) { canvas_set_font(canvas, FontPrimary); canvas_draw_str_aligned(canvas, 64, 2, AlignCenter, AlignTop, model->attack_name); +#ifndef ATACK_VIEW_V2 + canvas_set_font(canvas, FontSecondary); + snprintf( + temp_str, + sizeof(temp_str), + "Time delay: %d.%d", + model->time_delay / 10, + model->time_delay % 10); + canvas_draw_str_aligned(canvas, 64, 14, AlignCenter, AlignTop, temp_str); +#elif defined(ATACK_VIEW_V2_1) + + canvas_set_font(canvas, FontSecondary); + if(!model->td_emt_cursor) { + snprintf( + temp_str, + sizeof(temp_str), + "Time delay: %d.%d EmT: %d.%d", + model->time_delay / 10, + model->time_delay % 10, + model->emu_time / 10, + model->emu_time % 10); + } else { + snprintf( + temp_str, + sizeof(temp_str), + "TD: %d.%d Emulation time: %d.%d", + model->time_delay / 10, + model->time_delay % 10, + model->emu_time / 10, + model->emu_time % 10); + } + canvas_draw_str_aligned(canvas, 64, 21, AlignCenter, AlignBottom, temp_str); + +#elif defined(ATACK_VIEW_V2_2) + + uint16_t crt; + canvas_set_font(canvas, FontPrimary); + + if(!model->td_emt_cursor) { + canvas_set_font(canvas, FontSecondary); + snprintf(temp_str, sizeof(temp_str), "Time delay:"); + canvas_draw_str_aligned(canvas, LIFT_RIGHT_OFFSET, 21, AlignLeft, AlignBottom, temp_str); + crt = canvas_string_width(canvas, temp_str); + + canvas_set_font(canvas, FontPrimary); + snprintf( + temp_str, sizeof(temp_str), "%d.%d", model->time_delay / 10, model->time_delay % 10); + canvas_draw_str_aligned( + canvas, crt + LIFT_RIGHT_OFFSET + 3, 21, AlignLeft, AlignBottom, temp_str); + + canvas_set_font(canvas, FontSecondary); + snprintf( + temp_str, sizeof(temp_str), "EmT: %d.%d", model->emu_time / 10, model->emu_time % 10); + canvas_draw_str_aligned( + canvas, 128 - LIFT_RIGHT_OFFSET, 21, AlignRight, AlignBottom, temp_str); + + } else { + canvas_set_font(canvas, FontSecondary); + snprintf( + temp_str, + sizeof(temp_str), + "TD: %d.%d", + model->time_delay / 10, + model->time_delay % 10); + + canvas_draw_str_aligned(canvas, LIFT_RIGHT_OFFSET, 21, AlignLeft, AlignBottom, temp_str); + + canvas_set_font(canvas, FontPrimary); + snprintf(temp_str, sizeof(temp_str), "%d.%d", model->emu_time / 10, model->emu_time % 10); + canvas_draw_str_aligned( + canvas, 128 - LIFT_RIGHT_OFFSET, 21, AlignRight, AlignBottom, temp_str); + crt = canvas_string_width(canvas, temp_str); + + canvas_set_font(canvas, FontSecondary); + snprintf(temp_str, sizeof(temp_str), "Emulation time:"); + canvas_draw_str_aligned( + canvas, 128 - LIFT_RIGHT_OFFSET - crt - 3, 21, AlignRight, AlignBottom, temp_str); + } + +#else + + canvas_set_font(canvas, FontSecondary); + snprintf( + temp_str, + sizeof(temp_str), + "Time delay: %d.%d Emu time: %d.%d", + model->time_delay / 10, + model->time_delay % 10, + model->emu_time / 10, + model->emu_time % 10); + canvas_draw_str_aligned(canvas, 64, 14, AlignCenter, AlignTop, temp_str); + +#endif + canvas_set_font(canvas, FontSecondary); - canvas_draw_str_aligned(canvas, 64, 14, AlignCenter, AlignTop, time_delay); canvas_draw_str_aligned(canvas, 64, 26, AlignCenter, AlignTop, model->protocol_name); canvas_set_font(canvas, FontPrimary); @@ -131,9 +231,21 @@ void fuzzer_view_attack_draw(Canvas* canvas, FuzzerViewAttackModel* model) { if(model->attack_state == FuzzerAttackStateRunning) { elements_button_center(canvas, "Stop"); } else if(model->attack_state == FuzzerAttackStateIdle) { +#ifndef ATACK_VIEW_V2 elements_button_center(canvas, "Start"); elements_button_left(canvas, "TD -"); elements_button_right(canvas, "+ TD"); +#else + if(model->td_emt_cursor) { + elements_button_center(canvas, "Start"); + elements_button_left(canvas, "EmT -"); + elements_button_right(canvas, "+ EmT"); + } else { + elements_button_center(canvas, "Start"); + elements_button_left(canvas, "TD -"); + elements_button_right(canvas, "+ TD"); + } +#endif } else if(model->attack_state == FuzzerAttackStateEnd) { // elements_button_center(canvas, "Restart"); // Reset elements_button_left(canvas, "Exit"); @@ -156,16 +268,31 @@ bool fuzzer_view_attack_input(InputEvent* event, void* context) { FuzzerViewAttackModel * model, { if(model->attack_state == FuzzerAttackStateIdle) { - // TimeDelay - if(event->type == InputTypeShort) { - if(model->time_delay > model->time_delay_min) { - model->time_delay--; + if(!model->td_emt_cursor) { + // TimeDelay -- + if(event->type == InputTypeShort) { + if(model->time_delay > model->time_delay_min) { + model->time_delay--; + } + } else if(event->type == InputTypeLong) { + if((model->time_delay - 10) >= model->time_delay_min) { + model->time_delay -= 10; + } else { + model->time_delay = model->time_delay_min; + } } - } else if(event->type == InputTypeLong) { - if((model->time_delay - 10) >= model->time_delay_min) { - model->time_delay -= 10; - } else { - model->time_delay = model->time_delay_min; + } else { + // EmuTime -- + if(event->type == InputTypeShort) { + if(model->emu_time > model->emu_time_min) { + model->emu_time--; + } + } else if(event->type == InputTypeLong) { + if((model->emu_time - 10) >= model->emu_time_min) { + model->emu_time -= 10; + } else { + model->emu_time = model->emu_time_min; + } } } } else if( @@ -183,15 +310,29 @@ bool fuzzer_view_attack_input(InputEvent* event, void* context) { FuzzerViewAttackModel * model, { if(model->attack_state == FuzzerAttackStateIdle) { - // TimeDelay - if(event->type == InputTypeShort) { - if(model->time_delay < FUZZ_TIME_DELAY_MAX) { - model->time_delay++; + if(!model->td_emt_cursor) { + // TimeDelay ++ + if(event->type == InputTypeShort) { + if(model->time_delay < FUZZ_TIME_DELAY_MAX) { + model->time_delay++; + } + } else if(event->type == InputTypeLong) { + model->time_delay += 10; + if(model->time_delay > FUZZ_TIME_DELAY_MAX) { + model->time_delay = FUZZ_TIME_DELAY_MAX; + } } - } else if(event->type == InputTypeLong) { - model->time_delay += 10; - if(model->time_delay > FUZZ_TIME_DELAY_MAX) { - model->time_delay = FUZZ_TIME_DELAY_MAX; + } else { + // EmuTime ++ + if(event->type == InputTypeShort) { + if(model->emu_time < FUZZ_TIME_DELAY_MAX) { + model->emu_time++; + } + } else if(event->type == InputTypeLong) { + model->emu_time += 10; + if(model->emu_time > FUZZ_TIME_DELAY_MAX) { + model->emu_time = FUZZ_TIME_DELAY_MAX; + } } } } else { @@ -200,6 +341,15 @@ bool fuzzer_view_attack_input(InputEvent* event, void* context) { }, true); return true; + } else if( + (event->key == InputKeyUp || event->key == InputKeyDown) && + event->type == InputTypeShort) { + with_view_model( + view_attack->view, + FuzzerViewAttackModel * model, + { model->td_emt_cursor = !model->td_emt_cursor; }, + true); + return true; } return true; @@ -211,6 +361,9 @@ void fuzzer_view_attack_enter(void* context) { void fuzzer_view_attack_exit(void* context) { furi_assert(context); + FuzzerViewAttack* view_attack = context; + with_view_model( + view_attack->view, FuzzerViewAttackModel * model, { model->td_emt_cursor = false; }, true); } FuzzerViewAttack* fuzzer_view_attack_alloc() { @@ -233,11 +386,17 @@ FuzzerViewAttack* fuzzer_view_attack_alloc() { view_attack->view, FuzzerViewAttackModel * model, { - model->time_delay_min = fuzzer_proto_get_min_delay(); - model->time_delay = model->time_delay_min; + model->time_delay = fuzzer_proto_get_def_idle_time(); + model->time_delay_min = 0; // model->time_delay; + + model->emu_time = fuzzer_proto_get_def_emu_time(); + + model->emu_time_min = 2; // model->emu_time; + model->uid_str = furi_string_alloc_set_str("Not_set"); // malloc(ATTACK_SCENE_MAX_UID_LENGTH + 1); model->attack_state = FuzzerAttackStateOff; + model->td_emt_cursor = false; // strcpy(model->uid_str, "Not_set"); model->attack_name = "Not_set"; @@ -272,4 +431,14 @@ uint8_t fuzzer_view_attack_get_time_delay(FuzzerViewAttack* view) { view->view, FuzzerViewAttackModel * model, { time_delay = model->time_delay; }, false); return time_delay; +} + +uint8_t fuzzer_view_attack_get_emu_time(FuzzerViewAttack* view) { + furi_assert(view); + uint8_t emu_time; + + with_view_model( + view->view, FuzzerViewAttackModel * model, { emu_time = model->emu_time; }, false); + + return emu_time; } \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/views/attack.h b/applications/external/pacs_fuzzer/views/attack.h index 41fd857bf..9341ae7e2 100644 --- a/applications/external/pacs_fuzzer/views/attack.h +++ b/applications/external/pacs_fuzzer/views/attack.h @@ -37,4 +37,6 @@ void fuzzer_view_attack_pause(FuzzerViewAttack* view); void fuzzer_view_attack_end(FuzzerViewAttack* view); -uint8_t fuzzer_view_attack_get_time_delay(FuzzerViewAttack* view); \ No newline at end of file +uint8_t fuzzer_view_attack_get_time_delay(FuzzerViewAttack* view); + +uint8_t fuzzer_view_attack_get_emu_time(FuzzerViewAttack* view); \ No newline at end of file From 6ce098064aed2282437a5df8208f63ec2e263da5 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Wed, 7 Jun 2023 11:51:15 +0300 Subject: [PATCH 20/31] Fuzzer App: use FuzzerPayload & smal fixes --- applications/external/pacs_fuzzer/fuzzer.c | 2 + applications/external/pacs_fuzzer/fuzzer_i.h | 1 + .../pacs_fuzzer/lib/worker/fake_worker.c | 42 ++++++++++--------- .../pacs_fuzzer/lib/worker/fake_worker.h | 6 +-- .../pacs_fuzzer/lib/worker/protocol.c | 16 +++++++ .../pacs_fuzzer/lib/worker/protocol.h | 14 +++++++ .../pacs_fuzzer/lib/worker/protocol_i.h | 12 +----- .../pacs_fuzzer/scenes/fuzzer_scene_attack.c | 13 ++---- .../scenes/fuzzer_scene_field_editor.c | 11 ++--- .../pacs_fuzzer/scenes/fuzzer_scene_main.c | 9 ++-- applications/external/pacs_fuzzer/todo.md | 4 ++ .../external/pacs_fuzzer/views/attack.c | 10 ++--- .../external/pacs_fuzzer/views/attack.h | 2 +- .../external/pacs_fuzzer/views/field_editor.c | 20 +++++---- .../external/pacs_fuzzer/views/field_editor.h | 5 +-- 15 files changed, 96 insertions(+), 71 deletions(-) diff --git a/applications/external/pacs_fuzzer/fuzzer.c b/applications/external/pacs_fuzzer/fuzzer.c index c80c18130..113291d0c 100644 --- a/applications/external/pacs_fuzzer/fuzzer.c +++ b/applications/external/pacs_fuzzer/fuzzer.c @@ -26,6 +26,7 @@ PacsFuzzerApp* fuzzer_app_alloc() { app->fuzzer_state.proto_index = 0; app->worker = fuzzer_worker_alloc(); + app->payload = fuzzer_payload_alloc(); app->file_path = furi_string_alloc(); @@ -114,6 +115,7 @@ void fuzzer_app_free(PacsFuzzerApp* app) { furi_string_free(app->file_path); + fuzzer_payload_free(app->payload); fuzzer_worker_free(app->worker); free(app); diff --git a/applications/external/pacs_fuzzer/fuzzer_i.h b/applications/external/pacs_fuzzer/fuzzer_i.h index 63bf85d24..5b58e59d8 100644 --- a/applications/external/pacs_fuzzer/fuzzer_i.h +++ b/applications/external/pacs_fuzzer/fuzzer_i.h @@ -51,4 +51,5 @@ typedef struct { FuzzerConsts* fuzzer_const; FuzzerWorker* worker; + FuzzerPayload* payload; } PacsFuzzerApp; \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/lib/worker/fake_worker.c b/applications/external/pacs_fuzzer/lib/worker/fake_worker.c index e48b1dd32..07b0479b4 100644 --- a/applications/external/pacs_fuzzer/lib/worker/fake_worker.c +++ b/applications/external/pacs_fuzzer/lib/worker/fake_worker.c @@ -38,8 +38,8 @@ struct FuzzerWorker { const FuzzerProtocol* protocol; FuzzerWorkerAttackType attack_type; - uint8_t timer_idle_time; - uint8_t timer_emu_time; + uint16_t timer_idle_time_ms; + uint16_t timer_emu_time_ms; uint8_t payload[MAX_PAYLOAD_SIZE]; Stream* uids_stream; @@ -157,7 +157,7 @@ static void fuzzer_worker_on_tick_callback(void* context) { #endif } instance->in_emu_phase = false; - furi_timer_start(instance->timer, furi_ms_to_ticks(instance->timer_idle_time * 100)); + furi_timer_start(instance->timer, furi_ms_to_ticks(instance->timer_idle_time_ms)); } else { if(!fuzzer_worker_load_key(instance, true)) { fuzzer_worker_pause(instance); // XXX @@ -173,7 +173,7 @@ static void fuzzer_worker_on_tick_callback(void* context) { #endif } instance->in_emu_phase = true; - furi_timer_start(instance->timer, furi_ms_to_ticks(instance->timer_emu_time * 100)); + furi_timer_start(instance->timer, furi_ms_to_ticks(instance->timer_emu_time_ms)); if(instance->tick_callback) { instance->tick_callback(instance->tick_context); } @@ -187,7 +187,6 @@ void fuzzer_worker_get_current_key(FuzzerWorker* instance, FuzzerPayload* output furi_assert(instance->protocol); output_key->data_size = instance->protocol->data_size; - output_key->data = malloc(sizeof(output_key->data_size)); memcpy(output_key->data, instance->payload, instance->protocol->data_size); } @@ -258,7 +257,7 @@ bool fuzzer_worker_init_attack_file_dict( bool fuzzer_worker_init_attack_bf_byte( FuzzerWorker* instance, FuzzerProtocolsID protocol_index, - const uint8_t* uid, + const FuzzerPayload* new_uid, uint8_t chusen) { furi_assert(instance); @@ -268,7 +267,7 @@ bool fuzzer_worker_init_attack_bf_byte( instance->attack_type = FuzzerWorkerAttackTypeLoadFile; instance->index = chusen; - memcpy(instance->payload, uid, instance->protocol->data_size); + memcpy(instance->payload, new_uid->data, instance->protocol->data_size); res = true; @@ -349,8 +348,8 @@ FuzzerWorker* fuzzer_worker_alloc() { memset(instance->payload, 0x00, sizeof(instance->payload)); - instance->timer_idle_time = PROTOCOL_DEF_IDLE_TIME; - instance->timer_emu_time = PROTOCOL_DEF_EMU_TIME; + instance->timer_idle_time_ms = PROTOCOL_DEF_IDLE_TIME * 100; + instance->timer_emu_time_ms = PROTOCOL_DEF_EMU_TIME * 100; instance->timer = furi_timer_alloc(fuzzer_worker_on_tick_callback, FuriTimerTypeOnce, instance); @@ -383,17 +382,22 @@ bool fuzzer_worker_start(FuzzerWorker* instance, uint8_t idle_time, uint8_t emu_ furi_assert(instance); if(instance->attack_type < FuzzerWorkerAttackTypeMax) { - // if(emu_time == 0) { - // uint8_t temp = idle_time / 2; - // instance->timer_emu_time = temp; - // instance->timer_idle_time = temp + idle_time % 2; - // } else { - instance->timer_idle_time = idle_time; - instance->timer_emu_time = emu_time; - // } + if(idle_time == 0) { + instance->timer_idle_time_ms = 10; + } else { + instance->timer_idle_time_ms = idle_time * 100; + } + if(emu_time == 0) { + instance->timer_emu_time_ms = 10; + } else { + instance->timer_emu_time_ms = emu_time * 100; + } FURI_LOG_D( - TAG, "Emu_time %u Idle_time %u", instance->timer_emu_time, instance->timer_idle_time); + TAG, + "Emu_time %u ms Idle_time %u ms", + instance->timer_emu_time_ms, + instance->timer_idle_time_ms); if(!instance->treead_running) { #if defined(RFID_125_PROTOCOL) @@ -415,7 +419,7 @@ bool fuzzer_worker_start(FuzzerWorker* instance, uint8_t idle_time, uint8_t emu_ ibutton_worker_emulate_start(instance->proto_worker, instance->key); #endif instance->in_emu_phase = true; - furi_timer_start(instance->timer, furi_ms_to_ticks(instance->timer_emu_time * 100)); + furi_timer_start(instance->timer, furi_ms_to_ticks(instance->timer_emu_time_ms)); return true; } return false; diff --git a/applications/external/pacs_fuzzer/lib/worker/fake_worker.h b/applications/external/pacs_fuzzer/lib/worker/fake_worker.h index 6396525be..8b934f300 100644 --- a/applications/external/pacs_fuzzer/lib/worker/fake_worker.h +++ b/applications/external/pacs_fuzzer/lib/worker/fake_worker.h @@ -82,21 +82,21 @@ bool fuzzer_worker_init_attack_file_dict( * * @param instance Pointer to a FuzzerWorker * @param protocol_index index of the selected protocol - * @param uid UID for brute force + * @param new_uid Pointer to a FuzzerPayload with UID for brute force * @param chosen index of chusen byte * @return bool True if initialization is successful */ bool fuzzer_worker_init_attack_bf_byte( FuzzerWorker* instance, FuzzerProtocolsID protocol_index, - const uint8_t* uid, + const FuzzerPayload* new_uid, uint8_t chusen); /** * Get current UID * * @param instance Pointer to a FuzzerWorker - * @param output_key Pointer to a FuzzerWorker, memory for data will be allocated + * @param output_key Pointer to a FuzzerPayload */ void fuzzer_worker_get_current_key(FuzzerWorker* instance, FuzzerPayload* output_key); diff --git a/applications/external/pacs_fuzzer/lib/worker/protocol.c b/applications/external/pacs_fuzzer/lib/worker/protocol.c index f520037ac..a64fe8767 100644 --- a/applications/external/pacs_fuzzer/lib/worker/protocol.c +++ b/applications/external/pacs_fuzzer/lib/worker/protocol.c @@ -242,6 +242,22 @@ const FuzzerMenuItems fuzzer_menu_items[] = { {"Load UIDs from file", FuzzerAttackIdLoadFileCustomUids}, }; +FuzzerPayload* fuzzer_payload_alloc() { + FuzzerPayload* payload = malloc(sizeof(FuzzerPayload)); + payload->data = malloc(sizeof(payload->data[0]) * MAX_PAYLOAD_SIZE); + + return payload; +} + +void fuzzer_payload_free(FuzzerPayload* payload) { + furi_assert(payload); + + if(payload->data) { + free(payload->data); + } + free(payload); +} + const char* fuzzer_proto_get_name(FuzzerProtocolsID index) { return fuzzer_proto_items[index].name; } diff --git a/applications/external/pacs_fuzzer/lib/worker/protocol.h b/applications/external/pacs_fuzzer/lib/worker/protocol.h index 68632b029..9c5315d00 100644 --- a/applications/external/pacs_fuzzer/lib/worker/protocol.h +++ b/applications/external/pacs_fuzzer/lib/worker/protocol.h @@ -31,6 +31,20 @@ struct FuzzerPayload { uint8_t data_size; }; +/** + * Allocate FuzzerPayload + * + * @return FuzzerPayload* pointer to FuzzerPayload + */ +FuzzerPayload* fuzzer_payload_alloc(); + +/** + * Free FuzzerPayload + * + * @param instance Pointer to a FuzzerPayload + */ +void fuzzer_payload_free(FuzzerPayload*); + /** * Get maximum length of UID among all supported protocols * @return Maximum length of UID diff --git a/applications/external/pacs_fuzzer/lib/worker/protocol_i.h b/applications/external/pacs_fuzzer/lib/worker/protocol_i.h index 074c50d9d..2f1c65fd7 100644 --- a/applications/external/pacs_fuzzer/lib/worker/protocol_i.h +++ b/applications/external/pacs_fuzzer/lib/worker/protocol_i.h @@ -19,7 +19,7 @@ typedef struct FuzzerProtocol FuzzerProtocol; struct ProtoDict { const uint8_t* val; - const uint8_t len; // TODO + const uint8_t len; }; struct FuzzerProtocol { @@ -34,20 +34,10 @@ struct FuzzerProtocol { // #define FUZZ_TIME_DELAY_DEFAULT (10) // #define FUZZ_TIME_DELAY_MAX (70) -// #define FUZZER_APP_CUSTOM_DICT_EXTENSION ".txt" -// #define FUZZER_APP_CUSTOM_DICT_FOLDER "/ext/rfidfuzzer" -// #define FUZZER_APP_KEY_EXTENSION ".rfid" -// #define FUZZER_APP_PATH_KEY_FOLDER "/ext/lfrfid" - // #define MAX_PAYLOAD_SIZE 8 // #define FUZZ_TIME_DELAY_MIN (4) // #define FUZZ_TIME_DELAY_DEFAULT (8) // #define FUZZ_TIME_DELAY_MAX (80) -// #define FUZZER_APP_CUSTOM_DICT_EXTENSION ".txt" -// #define FUZZER_APP_CUSTOM_DICT_FOLDER "/ext/ibtnfuzzer" -// #define FUZZER_APP_KEY_EXTENSION ".ibtn" -// #define FUZZER_APP_PATH_KEY_FOLDER "/ext/ibutton" - extern const FuzzerProtocol fuzzer_proto_items[]; \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c index 836bbdef5..6424e62b5 100644 --- a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c @@ -1,8 +1,6 @@ #include "../fuzzer_i.h" #include "../helpers/fuzzer_custom_event.h" -// TODO simlify callbacks and attack state - const NotificationSequence sequence_one_green_50_on_blink_blue = { &message_red_255, &message_delay_50, @@ -18,12 +16,9 @@ static void fuzzer_scene_attack_update_uid(PacsFuzzerApp* app) { furi_assert(app->worker); furi_assert(app->attack_view); - FuzzerPayload uid; - fuzzer_worker_get_current_key(app->worker, &uid); + fuzzer_worker_get_current_key(app->worker, app->payload); - fuzzer_view_attack_set_uid(app->attack_view, uid); - - free(uid.data); + fuzzer_view_attack_set_uid(app->attack_view, app->payload); } static void fuzzer_scene_attack_set_state(PacsFuzzerApp* app, FuzzerAttackState state) { @@ -127,7 +122,6 @@ bool fuzzer_scene_attack_on_event(void* context, SceneManagerEvent event) { if(scene_manager_get_scene_state(app->scene_manager, FuzzerSceneAttack) == FuzzerAttackStateIdle) { // Start or Continue Attack - // TODO emu_time if(fuzzer_worker_start( app->worker, fuzzer_view_attack_get_time_delay(app->attack_view), @@ -160,7 +154,8 @@ void fuzzer_scene_attack_on_exit(void* context) { furi_assert(context); PacsFuzzerApp* app = context; - // fuzzer_worker_stop(); // XXX + // XXX the scene has no descendants, and the return will be processed in on_event + // fuzzer_worker_stop(); fuzzer_worker_set_uid_chaged_callback(app->worker, NULL, NULL); fuzzer_worker_set_end_callback(app->worker, NULL, NULL); diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_field_editor.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_field_editor.c index 637eff2d7..4c45bd154 100644 --- a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_field_editor.c +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_field_editor.c @@ -14,12 +14,9 @@ void fuzzer_scene_field_editor_on_enter(void* context) { fuzzer_view_field_editor_set_callback( app->field_editor_view, fuzzer_scene_field_editor_callback, app); - FuzzerPayload uid; - fuzzer_worker_get_current_key(app->worker, &uid); + fuzzer_worker_get_current_key(app->worker, app->payload); - fuzzer_view_field_editor_reset_data(app->field_editor_view, uid); - - free(uid.data); + fuzzer_view_field_editor_reset_data(app->field_editor_view, app->payload); view_dispatcher_switch_to_view(app->view_dispatcher, FuzzerViewIDFieldEditor); } @@ -37,11 +34,11 @@ bool fuzzer_scene_field_editor_on_event(void* context, SceneManagerEvent event) } consumed = true; } else if(event.event == FuzzerCustomEventViewFieldEditorOk) { - // TODO + fuzzer_view_field_editor_get_uid(app->field_editor_view, app->payload); if(fuzzer_worker_init_attack_bf_byte( app->worker, app->fuzzer_state.proto_index, - fuzzer_view_field_editor_get_uid(app->field_editor_view), + app->payload, fuzzer_view_field_editor_get_index(app->field_editor_view))) { scene_manager_next_scene(app->scene_manager, FuzzerSceneAttack); } diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c index cfa43ad87..8ed7e09d4 100644 --- a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c @@ -103,8 +103,6 @@ bool fuzzer_scene_main_on_event(void* context, SceneManagerEvent event) { // TODO error logic bool loading_ok = false; - uint8_t d_size = fuzzer_proto_get_max_data_size(); - uint8_t* uid; switch(fuzzer_proto_get_attack_id_by_index(app->fuzzer_state.menu_index)) { case FuzzerAttackIdDefaultValues: @@ -119,13 +117,12 @@ bool fuzzer_scene_main_on_event(void* context, SceneManagerEvent event) { break; case FuzzerAttackIdBFCustomerID: // TODO - uid = malloc(d_size); - memset(uid, 0x00, d_size); + app->payload->data_size = fuzzer_proto_get_max_data_size(); + memset(app->payload->data, 0x00, app->payload->data_size); loading_ok = fuzzer_worker_init_attack_bf_byte( - app->worker, app->fuzzer_state.proto_index, uid, 0); + app->worker, app->fuzzer_state.proto_index, app->payload, 0); - free(uid); if(!loading_ok) { // error } diff --git a/applications/external/pacs_fuzzer/todo.md b/applications/external/pacs_fuzzer/todo.md index d0bab30d6..1cbd53c46 100644 --- a/applications/external/pacs_fuzzer/todo.md +++ b/applications/external/pacs_fuzzer/todo.md @@ -31,9 +31,13 @@ - [ ] Decide on the display - [x] UID - [x] Simplify the storage and exchange of `uids.data` `uid.data_size` in `views` + - [x] Using `FuzzerPayload` to store the uid - [x] `UID_MAX_SIZE` - [x] Add pause - [x] Fix `Custom dict` attack when ended +- [ ] Pause V2 + - [ ] Save logic + - [ ] Switching UIDs if possible - [ ] Worker - [ ] Use `prtocol_id` instead of protocol name - [x] this can be simplified `fuzzer_proto_items` \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/views/attack.c b/applications/external/pacs_fuzzer/views/attack.c index a29e2d966..9787278a6 100644 --- a/applications/external/pacs_fuzzer/views/attack.c +++ b/applications/external/pacs_fuzzer/views/attack.c @@ -48,17 +48,17 @@ void fuzzer_view_attack_reset_data( true); } -void fuzzer_view_attack_set_uid(FuzzerViewAttack* view, const FuzzerPayload uid) { +void fuzzer_view_attack_set_uid(FuzzerViewAttack* view, const FuzzerPayload* uid) { furi_assert(view); - furi_assert(uid.data); + furi_assert(uid->data); with_view_model( view->view, FuzzerViewAttackModel * model, { - furi_string_printf(model->uid_str, "%02X", uid.data[0]); - for(uint8_t i = 1; i < uid.data_size; i++) { - furi_string_cat_printf(model->uid_str, ":%02X", uid.data[i]); + furi_string_printf(model->uid_str, "%02X", uid->data[0]); + for(uint8_t i = 1; i < uid->data_size; i++) { + furi_string_cat_printf(model->uid_str, ":%02X", uid->data[i]); } }, true); diff --git a/applications/external/pacs_fuzzer/views/attack.h b/applications/external/pacs_fuzzer/views/attack.h index 9341ae7e2..66e96d7d6 100644 --- a/applications/external/pacs_fuzzer/views/attack.h +++ b/applications/external/pacs_fuzzer/views/attack.h @@ -27,7 +27,7 @@ void fuzzer_view_attack_reset_data( const char* attack_name, const char* protocol_name); -void fuzzer_view_attack_set_uid(FuzzerViewAttack* view, const FuzzerPayload uid); +void fuzzer_view_attack_set_uid(FuzzerViewAttack* view, const FuzzerPayload* uid); void fuzzer_view_attack_start(FuzzerViewAttack* view); diff --git a/applications/external/pacs_fuzzer/views/field_editor.c b/applications/external/pacs_fuzzer/views/field_editor.c index 07a19ae0e..45b5f70a1 100644 --- a/applications/external/pacs_fuzzer/views/field_editor.c +++ b/applications/external/pacs_fuzzer/views/field_editor.c @@ -49,27 +49,33 @@ void fuzzer_view_field_editor_set_callback( void fuzzer_view_field_editor_reset_data( FuzzerViewFieldEditor* view_edit, - const FuzzerPayload new_uid) { + const FuzzerPayload* new_uid) { furi_assert(view_edit); + furi_assert(new_uid->data); with_view_model( view_edit->view, FuzzerViewFieldEditorModel * model, { - memcpy(model->uid, new_uid.data, new_uid.data_size); + memcpy(model->uid, new_uid->data, new_uid->data_size); model->index = 0; model->lo = false; - model->uid_size = new_uid.data_size; + model->uid_size = new_uid->data_size; }, true); } -const uint8_t* fuzzer_view_field_editor_get_uid(FuzzerViewFieldEditor* view_edit) { +void fuzzer_view_field_editor_get_uid(FuzzerViewFieldEditor* view_edit, FuzzerPayload* output_uid) { furi_assert(view_edit); - uint8_t* uid; + furi_assert(output_uid); with_view_model( - view_edit->view, FuzzerViewFieldEditorModel * model, { uid = model->uid; }, true); - return uid; + view_edit->view, + FuzzerViewFieldEditorModel * model, + { + output_uid->data_size = model->uid_size; + memcpy(output_uid->data, model->uid, model->uid_size); + }, + true); } uint8_t fuzzer_view_field_editor_get_index(FuzzerViewFieldEditor* view_edit) { diff --git a/applications/external/pacs_fuzzer/views/field_editor.h b/applications/external/pacs_fuzzer/views/field_editor.h index f76b5d336..72c5de5e5 100644 --- a/applications/external/pacs_fuzzer/views/field_editor.h +++ b/applications/external/pacs_fuzzer/views/field_editor.h @@ -21,9 +21,8 @@ View* fuzzer_view_field_editor_get_view(FuzzerViewFieldEditor* view_attack); void fuzzer_view_field_editor_reset_data( FuzzerViewFieldEditor* view_edit, - const FuzzerPayload new_uid); + const FuzzerPayload* new_uid); -// TODO -const uint8_t* fuzzer_view_field_editor_get_uid(FuzzerViewFieldEditor* view_edit); +void fuzzer_view_field_editor_get_uid(FuzzerViewFieldEditor* view_edit, FuzzerPayload* output_uid); uint8_t fuzzer_view_field_editor_get_index(FuzzerViewFieldEditor* view_edit); \ No newline at end of file From c763ae6d5cefcc332487478405ad64c8e8fcece0 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Wed, 7 Jun 2023 11:54:20 +0300 Subject: [PATCH 21/31] Fuzzer App: cleanup attack view --- applications/external/pacs_fuzzer/todo.md | 2 +- .../external/pacs_fuzzer/views/attack.c | 62 +------------------ 2 files changed, 2 insertions(+), 62 deletions(-) diff --git a/applications/external/pacs_fuzzer/todo.md b/applications/external/pacs_fuzzer/todo.md index 1cbd53c46..136ec5e99 100644 --- a/applications/external/pacs_fuzzer/todo.md +++ b/applications/external/pacs_fuzzer/todo.md @@ -28,7 +28,7 @@ - [ ] Protocol carousel in `main_menu` - [x] prototype - [x] Add the ability to edit emulation time and downtime separately - - [ ] Decide on the display + - [x] Decide on the display - [x] UID - [x] Simplify the storage and exchange of `uids.data` `uid.data_size` in `views` - [x] Using `FuzzerPayload` to store the uid diff --git a/applications/external/pacs_fuzzer/views/attack.c b/applications/external/pacs_fuzzer/views/attack.c index 9787278a6..87aa9f659 100644 --- a/applications/external/pacs_fuzzer/views/attack.c +++ b/applications/external/pacs_fuzzer/views/attack.c @@ -4,10 +4,6 @@ #include #include -#define ATACK_VIEW_V2 -// #define ATACK_VIEW_V2_1 -#define ATACK_VIEW_V2_2 - #define ATTACK_SCENE_MAX_UID_LENGTH 25 #define UID_MAX_DISPLAYED_LEN (8U) #define LIFT_RIGHT_OFFSET (3) @@ -123,41 +119,6 @@ void fuzzer_view_attack_draw(Canvas* canvas, FuzzerViewAttackModel* model) { canvas_set_font(canvas, FontPrimary); canvas_draw_str_aligned(canvas, 64, 2, AlignCenter, AlignTop, model->attack_name); -#ifndef ATACK_VIEW_V2 - canvas_set_font(canvas, FontSecondary); - snprintf( - temp_str, - sizeof(temp_str), - "Time delay: %d.%d", - model->time_delay / 10, - model->time_delay % 10); - canvas_draw_str_aligned(canvas, 64, 14, AlignCenter, AlignTop, temp_str); -#elif defined(ATACK_VIEW_V2_1) - - canvas_set_font(canvas, FontSecondary); - if(!model->td_emt_cursor) { - snprintf( - temp_str, - sizeof(temp_str), - "Time delay: %d.%d EmT: %d.%d", - model->time_delay / 10, - model->time_delay % 10, - model->emu_time / 10, - model->emu_time % 10); - } else { - snprintf( - temp_str, - sizeof(temp_str), - "TD: %d.%d Emulation time: %d.%d", - model->time_delay / 10, - model->time_delay % 10, - model->emu_time / 10, - model->emu_time % 10); - } - canvas_draw_str_aligned(canvas, 64, 21, AlignCenter, AlignBottom, temp_str); - -#elif defined(ATACK_VIEW_V2_2) - uint16_t crt; canvas_set_font(canvas, FontPrimary); @@ -178,7 +139,6 @@ void fuzzer_view_attack_draw(Canvas* canvas, FuzzerViewAttackModel* model) { temp_str, sizeof(temp_str), "EmT: %d.%d", model->emu_time / 10, model->emu_time % 10); canvas_draw_str_aligned( canvas, 128 - LIFT_RIGHT_OFFSET, 21, AlignRight, AlignBottom, temp_str); - } else { canvas_set_font(canvas, FontSecondary); snprintf( @@ -202,21 +162,6 @@ void fuzzer_view_attack_draw(Canvas* canvas, FuzzerViewAttackModel* model) { canvas, 128 - LIFT_RIGHT_OFFSET - crt - 3, 21, AlignRight, AlignBottom, temp_str); } -#else - - canvas_set_font(canvas, FontSecondary); - snprintf( - temp_str, - sizeof(temp_str), - "Time delay: %d.%d Emu time: %d.%d", - model->time_delay / 10, - model->time_delay % 10, - model->emu_time / 10, - model->emu_time % 10); - canvas_draw_str_aligned(canvas, 64, 14, AlignCenter, AlignTop, temp_str); - -#endif - canvas_set_font(canvas, FontSecondary); canvas_draw_str_aligned(canvas, 64, 26, AlignCenter, AlignTop, model->protocol_name); @@ -231,11 +176,6 @@ void fuzzer_view_attack_draw(Canvas* canvas, FuzzerViewAttackModel* model) { if(model->attack_state == FuzzerAttackStateRunning) { elements_button_center(canvas, "Stop"); } else if(model->attack_state == FuzzerAttackStateIdle) { -#ifndef ATACK_VIEW_V2 - elements_button_center(canvas, "Start"); - elements_button_left(canvas, "TD -"); - elements_button_right(canvas, "+ TD"); -#else if(model->td_emt_cursor) { elements_button_center(canvas, "Start"); elements_button_left(canvas, "EmT -"); @@ -245,7 +185,7 @@ void fuzzer_view_attack_draw(Canvas* canvas, FuzzerViewAttackModel* model) { elements_button_left(canvas, "TD -"); elements_button_right(canvas, "+ TD"); } -#endif + } else if(model->attack_state == FuzzerAttackStateEnd) { // elements_button_center(canvas, "Restart"); // Reset elements_button_left(canvas, "Exit"); From 82de8145b0b123954183e18b688b18b51744c485 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Wed, 7 Jun 2023 12:44:33 +0300 Subject: [PATCH 22/31] Fuzzer App: improved BFCustomerID attack --- .../pacs_fuzzer/helpers/fuzzer_types.h | 6 ++ .../scenes/fuzzer_scene_field_editor.c | 13 +++- .../pacs_fuzzer/scenes/fuzzer_scene_main.c | 18 +++-- applications/external/pacs_fuzzer/todo.md | 1 + .../external/pacs_fuzzer/views/field_editor.c | 69 ++++++++++++------- .../external/pacs_fuzzer/views/field_editor.h | 3 +- 6 files changed, 81 insertions(+), 29 deletions(-) diff --git a/applications/external/pacs_fuzzer/helpers/fuzzer_types.h b/applications/external/pacs_fuzzer/helpers/fuzzer_types.h index e4661ed7b..bb608a5f1 100644 --- a/applications/external/pacs_fuzzer/helpers/fuzzer_types.h +++ b/applications/external/pacs_fuzzer/helpers/fuzzer_types.h @@ -15,6 +15,12 @@ typedef enum { } FuzzerAttackState; +typedef enum { + FuzzerFieldEditorStateEditingOn = 0, + FuzzerFieldEditorStateEditingOff, + +} FuzzerFieldEditorState; + typedef enum { FuzzerViewIDPopup, diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_field_editor.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_field_editor.c index 4c45bd154..ccea123dc 100644 --- a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_field_editor.c +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_field_editor.c @@ -16,7 +16,18 @@ void fuzzer_scene_field_editor_on_enter(void* context) { fuzzer_worker_get_current_key(app->worker, app->payload); - fuzzer_view_field_editor_reset_data(app->field_editor_view, app->payload); + switch(scene_manager_get_scene_state(app->scene_manager, FuzzerSceneFieldEditor)) { + case FuzzerFieldEditorStateEditingOn: + fuzzer_view_field_editor_reset_data(app->field_editor_view, app->payload, true); + break; + + case FuzzerFieldEditorStateEditingOff: + fuzzer_view_field_editor_reset_data(app->field_editor_view, app->payload, false); + break; + + default: + break; + } view_dispatcher_switch_to_view(app->view_dispatcher, FuzzerViewIDFieldEditor); } diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c index 8ed7e09d4..0d074a121 100644 --- a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c +++ b/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c @@ -106,7 +106,6 @@ bool fuzzer_scene_main_on_event(void* context, SceneManagerEvent event) { switch(fuzzer_proto_get_attack_id_by_index(app->fuzzer_state.menu_index)) { case FuzzerAttackIdDefaultValues: - loading_ok = fuzzer_worker_init_attack_dict(app->worker, app->fuzzer_state.proto_index); @@ -115,15 +114,21 @@ bool fuzzer_scene_main_on_event(void* context, SceneManagerEvent event) { fuzzer_scene_main_show_error(app, "Default dictionary\nis empty"); } break; + case FuzzerAttackIdBFCustomerID: // TODO app->payload->data_size = fuzzer_proto_get_max_data_size(); memset(app->payload->data, 0x00, app->payload->data_size); - loading_ok = fuzzer_worker_init_attack_bf_byte( - app->worker, app->fuzzer_state.proto_index, app->payload, 0); + if(fuzzer_worker_init_attack_bf_byte( + app->worker, app->fuzzer_state.proto_index, app->payload, 0)) { + scene_manager_set_scene_state( + app->scene_manager, + FuzzerSceneFieldEditor, + FuzzerFieldEditorStateEditingOff); + scene_manager_next_scene(app->scene_manager, FuzzerSceneFieldEditor); - if(!loading_ok) { + } else { // error } break; @@ -136,6 +141,10 @@ bool fuzzer_scene_main_on_event(void* context, SceneManagerEvent event) { app->worker, app->fuzzer_state.proto_index, furi_string_get_cstr(app->file_path))) { + scene_manager_set_scene_state( + app->scene_manager, + FuzzerSceneFieldEditor, + FuzzerFieldEditorStateEditingOn); scene_manager_next_scene(app->scene_manager, FuzzerSceneFieldEditor); FURI_LOG_I("Scene", "Load ok"); } else { @@ -159,6 +168,7 @@ bool fuzzer_scene_main_on_event(void* context, SceneManagerEvent event) { break; default: + fuzzer_scene_main_show_error(app, "Unsuported attack"); break; } diff --git a/applications/external/pacs_fuzzer/todo.md b/applications/external/pacs_fuzzer/todo.md index 136ec5e99..4e3b0e17d 100644 --- a/applications/external/pacs_fuzzer/todo.md +++ b/applications/external/pacs_fuzzer/todo.md @@ -17,6 +17,7 @@ #### App functionality - [x] Add `BFCustomerID` attack + - [x] Add the ability to select index - [ ] Save key logic ## Code Improvement diff --git a/applications/external/pacs_fuzzer/views/field_editor.c b/applications/external/pacs_fuzzer/views/field_editor.c index 45b5f70a1..bdce0a516 100644 --- a/applications/external/pacs_fuzzer/views/field_editor.c +++ b/applications/external/pacs_fuzzer/views/field_editor.c @@ -35,6 +35,7 @@ typedef struct { uint8_t index; bool lo; + bool allow_edit; } FuzzerViewFieldEditorModel; void fuzzer_view_field_editor_set_callback( @@ -49,7 +50,8 @@ void fuzzer_view_field_editor_set_callback( void fuzzer_view_field_editor_reset_data( FuzzerViewFieldEditor* view_edit, - const FuzzerPayload* new_uid) { + const FuzzerPayload* new_uid, + bool allow_edit) { furi_assert(view_edit); furi_assert(new_uid->data); @@ -61,6 +63,7 @@ void fuzzer_view_field_editor_reset_data( model->index = 0; model->lo = false; model->uid_size = new_uid->data_size; + model->allow_edit = allow_edit; }, true); } @@ -93,15 +96,20 @@ void fuzzer_view_field_editor_draw(Canvas* canvas, FuzzerViewFieldEditorModel* m #ifdef FIELD_EDITOR_V2 canvas_set_font(canvas, FontSecondary); + if(model->allow_edit) { + canvas_draw_icon(canvas, 2, 4, &I_ButtonLeft_4x7); + canvas_draw_icon(canvas, 8, 4, &I_ButtonRight_4x7); - canvas_draw_icon(canvas, 2, 4, &I_ButtonLeft_4x7); - canvas_draw_icon(canvas, 8, 4, &I_ButtonRight_4x7); + canvas_draw_icon_ex(canvas, 62, 3, &I_Pin_arrow_up_7x9, IconRotation180); + canvas_draw_icon(canvas, 69, 3, &I_Pin_arrow_up_7x9); - canvas_draw_icon_ex(canvas, 62, 3, &I_Pin_arrow_up_7x9, IconRotation180); - canvas_draw_icon(canvas, 69, 3, &I_Pin_arrow_up_7x9); - - canvas_draw_str(canvas, 14, 10, "select byte"); - canvas_draw_str(canvas, 79, 10, "adjust byte"); + canvas_draw_str(canvas, 14, 10, "select byte"); + canvas_draw_str(canvas, 79, 10, "adjust byte"); + } else { + canvas_draw_icon(canvas, 35, 4, &I_ButtonLeft_4x7); + canvas_draw_icon(canvas, 41, 4, &I_ButtonRight_4x7); + canvas_draw_str(canvas, 49, 10, "select byte"); + } char msg_index[18]; canvas_set_font(canvas, FontPrimary); @@ -177,20 +185,29 @@ void fuzzer_view_field_editor_draw(Canvas* canvas, FuzzerViewFieldEditorModel* m w -= 11; // '<' & '>' w /= 2; - if(model->lo) { - canvas_draw_line( - canvas, - GUI_DISPLAY_HORIZONTAL_CENTER + 1, - EDITOR_STRING_Y + 2, - GUI_DISPLAY_HORIZONTAL_CENTER + w, - EDITOR_STRING_Y + 2); + if(model->allow_edit) { + if(model->lo) { + canvas_draw_line( + canvas, + GUI_DISPLAY_HORIZONTAL_CENTER + 1, + EDITOR_STRING_Y + 2, + GUI_DISPLAY_HORIZONTAL_CENTER + w, + EDITOR_STRING_Y + 2); + } else { + canvas_draw_line( + canvas, + GUI_DISPLAY_HORIZONTAL_CENTER - w, + EDITOR_STRING_Y + 2, + GUI_DISPLAY_HORIZONTAL_CENTER - 1, + EDITOR_STRING_Y + 2); + } } else { - canvas_draw_line( - canvas, - GUI_DISPLAY_HORIZONTAL_CENTER - w, - EDITOR_STRING_Y + 2, - GUI_DISPLAY_HORIZONTAL_CENTER - 1, - EDITOR_STRING_Y + 2); + // canvas_draw_line( + // canvas, + // GUI_DISPLAY_HORIZONTAL_CENTER - w, + // EDITOR_STRING_Y + 2, + // GUI_DISPLAY_HORIZONTAL_CENTER + w, + // EDITOR_STRING_Y + 2); } // ####### Editor ####### } @@ -211,6 +228,9 @@ bool fuzzer_view_field_editor_input(InputEvent* event, void* context) { FuzzerViewFieldEditorModel * model, { if(event->type == InputTypeShort) { + if(!model->allow_edit) { + model->lo = false; + } if(model->index > 0 || model->lo) { if(!model->lo) { model->index--; @@ -230,6 +250,9 @@ bool fuzzer_view_field_editor_input(InputEvent* event, void* context) { FuzzerViewFieldEditorModel * model, { if(event->type == InputTypeShort) { + if(!model->allow_edit) { + model->lo = true; + } if(model->index < (model->uid_size - 1) || !model->lo) { if(model->lo) { model->index++; @@ -248,7 +271,7 @@ bool fuzzer_view_field_editor_input(InputEvent* event, void* context) { view_edit->view, FuzzerViewFieldEditorModel * model, { - if(event->type == InputTypeShort) { + if(event->type == InputTypeShort && model->allow_edit) { if(model->lo) { model->uid[model->index] = (model->uid[model->index] & 0xF0) | ((model->uid[model->index] + 1) & 0x0F); @@ -265,7 +288,7 @@ bool fuzzer_view_field_editor_input(InputEvent* event, void* context) { view_edit->view, FuzzerViewFieldEditorModel * model, { - if(event->type == InputTypeShort) { + if(event->type == InputTypeShort && model->allow_edit) { if(model->lo) { model->uid[model->index] = (model->uid[model->index] & 0xF0) | ((model->uid[model->index] - 1) & 0x0F); diff --git a/applications/external/pacs_fuzzer/views/field_editor.h b/applications/external/pacs_fuzzer/views/field_editor.h index 72c5de5e5..d81538bf8 100644 --- a/applications/external/pacs_fuzzer/views/field_editor.h +++ b/applications/external/pacs_fuzzer/views/field_editor.h @@ -21,7 +21,8 @@ View* fuzzer_view_field_editor_get_view(FuzzerViewFieldEditor* view_attack); void fuzzer_view_field_editor_reset_data( FuzzerViewFieldEditor* view_edit, - const FuzzerPayload* new_uid); + const FuzzerPayload* new_uid, + bool allow_edit); void fuzzer_view_field_editor_get_uid(FuzzerViewFieldEditor* view_edit, FuzzerPayload* output_uid); From 9af3c22a6a3acef2652ced06b3646a928cad9f9e Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Wed, 7 Jun 2023 23:39:52 +0300 Subject: [PATCH 23/31] Fix ProtoView issue #503 --- applications/external/protoview/signal_file.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/applications/external/protoview/signal_file.c b/applications/external/protoview/signal_file.c index c60a6a181..886573a06 100644 --- a/applications/external/protoview/signal_file.c +++ b/applications/external/protoview/signal_file.c @@ -48,8 +48,9 @@ bool save_signal(ProtoViewApp* app, const char* filename) { for(int j = 0; regs[j]; j += 2) { furi_string_cat_printf(custom, "%02X %02X ", (int)regs[j], (int)regs[j + 1]); } - size_t len = furi_string_size(file_content); - furi_string_set_char(custom, len - 1, '\n'); + //size_t len = furi_string_size(file_content); + //furi_string_set_char(custom, len - 1, '\n'); + furi_string_cat(custom, "\n"); furi_string_cat(file_content, custom); furi_string_free(custom); } From 87f70655a2817acc99552d01915827aaa0f8931b Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Wed, 7 Jun 2023 23:54:01 +0300 Subject: [PATCH 24/31] Remove broken modulation that was causing buffer Overrun Fixes issue #506 --- applications/main/subghz/subghz.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index d30bd79f2..97e2e8c34 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -211,7 +211,7 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { flipper_format_free(temp_fm_preset3); - // # HND - FM presets + // # HND - FM preset FlipperFormat* temp_fm_preset4 = flipper_format_string_alloc(); flipper_format_write_string_cstr( temp_fm_preset4, @@ -221,16 +221,6 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { subghz_setting_load_custom_preset(setting, (const char*)"HND_1", temp_fm_preset4); flipper_format_free(temp_fm_preset4); - - FlipperFormat* temp_fm_preset5 = flipper_format_string_alloc(); - flipper_format_write_string_cstr( - temp_fm_preset5, - (const char*)"Custom_preset_data", - (const char*)"02 0D 0B 06 08 32 07 04 14 00 13 02 12 07 11 36 10 E9 15 32 18 18 19 16 1D 92 1C 40 1B 03 20 FB 22 10 21 56 00 00 C0 00 00 00 00 00 00 00"); - flipper_format_rewind(temp_fm_preset5); - subghz_setting_load_custom_preset(setting, (const char*)"HND_2", temp_fm_preset5); - - flipper_format_free(temp_fm_preset5); } // custom presets loading - end From af2ecbc3ed35a1e6b52af7a5b07decd03a2a5186 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Thu, 8 Jun 2023 00:26:10 +0300 Subject: [PATCH 25/31] SCD30 Unitemp --- applications/external/unitemp/Sensors.c | 3 +- applications/external/unitemp/Sensors.h | 5 + .../external/unitemp/assets/co2_11x14.png | Bin 0 -> 176 bytes applications/external/unitemp/sensors/SCD30.c | 438 ++++++++++++++++++ applications/external/unitemp/sensors/SCD30.h | 59 +++ .../external/unitemp/views/General_view.c | 38 ++ 6 files changed, 542 insertions(+), 1 deletion(-) create mode 100644 applications/external/unitemp/assets/co2_11x14.png create mode 100644 applications/external/unitemp/sensors/SCD30.c create mode 100644 applications/external/unitemp/sensors/SCD30.h diff --git a/applications/external/unitemp/Sensors.c b/applications/external/unitemp/Sensors.c index 666438bfa..ae90ce4d5 100644 --- a/applications/external/unitemp/Sensors.c +++ b/applications/external/unitemp/Sensors.c @@ -78,7 +78,8 @@ const Interface SPI = { static const SensorType* sensorTypes[] = {&DHT11, &DHT12_SW, &DHT20, &DHT21, &DHT22, &Dallas, &AM2320_SW, &AM2320_I2C, &HTU21x, &AHT10, &SHT30, &GXHT30, &LM75, &HDC1080, &BMP180, - &BMP280, &BME280, &BME680, &MAX31855, &MAX6675}; + &BMP280, &BME280, &BME680, &MAX31855, &MAX6675, + &SCD30}; const SensorType* unitemp_sensors_getTypeFromInt(uint8_t index) { if(index > SENSOR_TYPES_COUNT) return NULL; diff --git a/applications/external/unitemp/Sensors.h b/applications/external/unitemp/Sensors.h index d2b7c07af..25b9cb49e 100644 --- a/applications/external/unitemp/Sensors.h +++ b/applications/external/unitemp/Sensors.h @@ -24,6 +24,7 @@ #define UT_TEMPERATURE 0b00000001 #define UT_HUMIDITY 0b00000010 #define UT_PRESSURE 0b00000100 +#define UT_CO2 0b00001000 //Статусы опроса датчика typedef enum { @@ -31,6 +32,7 @@ typedef enum { UT_DATA_TYPE_TEMP_HUM = UT_TEMPERATURE | UT_HUMIDITY, UT_DATA_TYPE_TEMP_PRESS = UT_TEMPERATURE | UT_PRESSURE, UT_DATA_TYPE_TEMP_HUM_PRESS = UT_TEMPERATURE | UT_HUMIDITY | UT_PRESSURE, + UT_DATA_TYPE_TEMP_HUM_CO2 = UT_TEMPERATURE | UT_HUMIDITY | UT_CO2, } SensorDataType; //Типы возвращаемых данных @@ -121,6 +123,8 @@ typedef struct Sensor { float hum; //Атмосферное давление float pressure; + // Концентрация CO2 + float co2; //Тип датчика const SensorType* type; //Статус последнего опроса датчика @@ -329,4 +333,5 @@ const GPIO* #include "./sensors/HDC1080.h" #include "./sensors/MAX31855.h" #include "./sensors/MAX6675.h" +#include "./sensors/SCD30.h" #endif diff --git a/applications/external/unitemp/assets/co2_11x14.png b/applications/external/unitemp/assets/co2_11x14.png new file mode 100644 index 0000000000000000000000000000000000000000..2a2b5e068d6153d1f30dfc93acd3b0279ee8d551 GIT binary patch literal 176 zcmeAS@N?(olHy`uVBq!ia0vp@Ak4uAB#T}@sR2?f#ZI0f96(URk}M!fC3NGbie=qQ>#|?bzTh2Q%vH}y3IC$ZRvemx8YG!hReRKhg7T% zs+8bg=d#Wzp$PyIY(cC5 literal 0 HcmV?d00001 diff --git a/applications/external/unitemp/sensors/SCD30.c b/applications/external/unitemp/sensors/SCD30.c new file mode 100644 index 000000000..b5f15b50d --- /dev/null +++ b/applications/external/unitemp/sensors/SCD30.c @@ -0,0 +1,438 @@ +/* + Unitemp - Universal temperature reader + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) + Contributed by divinebird (https://github.com/divinebird) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +// Some information may be seen on https://github.com/sparkfun/SparkFun_SCD30_Arduino_Library + +#include "SCD30.h" +#include "../interfaces/I2CSensor.h" +//#include <3rdparty/everest/include/everest/kremlin/c_endianness.h> + +inline static uint16_t load16(uint8_t* b) { + uint16_t x; + memcpy(&x, b, 2); + return x; +} + +inline static uint32_t load32(uint8_t* b) { + uint32_t x; + memcpy(&x, b, 4); + return x; +} + +inline static void store16(uint8_t* b, uint16_t i) { + memcpy(b, &i, 2); +} + +inline static void store32(uint8_t* b, uint32_t i) { + memcpy(b, &i, 4); +} + +#if BYTE_ORDER == BIG_ENDIAN +#define htobe16(x) (x) +#define htobe32(x) (x) +#define htole16(x) __builtin_bswap16(x) +#define htole32(x) __builtin_bswap32(x) +#define be16toh(x) (x) +#define be32toh(x) (x) +#define le16toh(x) __builtin_bswap16(x) +#define le32toh(x) __builtin_bswap32(x) +#elif BYTE_ORDER == LITTLE_ENDIAN +#define htobe16(x) __builtin_bswap16(x) +#define htobe32(x) __builtin_bswap32(x) +#define htole16(x) (x) +#define htole32(x) (x) +#define be16toh(x) __builtin_bswap16(x) +#define be32toh(x) __builtin_bswap32(x) +#define le16toh(x) (x) +#define le32toh(x) (x) +#else +#error "What kind of system is this?" +#endif + +#define load16_le(b) (le16toh(load16(b))) +#define load32_le(b) (le32toh(load32(b))) +#define store16_le(b, i) (store16(b, htole16(i))) +#define store32_le(b, i) (store32(b, htole32(i))) + +#define load16_be(b) (be16toh(load16(b))) +#define load32_be(b) (be32toh(load32(b))) +#define store16_be(b, i) (store16(b, htobe16(i))) +#define store32_be(b, i) (store32(b, htobe32(i))) + +typedef union { + uint16_t array16[2]; + uint8_t array8[4]; + float value; +} ByteToFl; + +bool unitemp_SCD30_alloc(Sensor* sensor, char* args); +bool unitemp_SCD30_init(Sensor* sensor); +bool unitemp_SCD30_deinit(Sensor* sensor); +UnitempStatus unitemp_SCD30_update(Sensor* sensor); +bool unitemp_SCD30_free(Sensor* sensor); + +const SensorType SCD30 = { + .typename = "SCD30", + .interface = &I2C, + .datatype = UT_DATA_TYPE_TEMP_HUM_CO2, + .pollingInterval = 2000, + .allocator = unitemp_SCD30_alloc, + .mem_releaser = unitemp_SCD30_free, + .initializer = unitemp_SCD30_init, + .deinitializer = unitemp_SCD30_deinit, + .updater = unitemp_SCD30_update}; + +#define SCD30_ID 0x61 + +#define COMMAND_CONTINUOUS_MEASUREMENT 0x0010 +#define COMMAND_SET_MEASUREMENT_INTERVAL 0x4600 +#define COMMAND_GET_DATA_READY 0x0202 +#define COMMAND_READ_MEASUREMENT 0x0300 +#define COMMAND_AUTOMATIC_SELF_CALIBRATION 0x5306 +#define COMMAND_SET_FORCED_RECALIBRATION_FACTOR 0x5204 +#define COMMAND_SET_TEMPERATURE_OFFSET 0x5403 +#define COMMAND_SET_ALTITUDE_COMPENSATION 0x5102 +#define COMMAND_RESET 0xD304 // Soft reset +#define COMMAND_STOP_MEAS 0x0104 +#define COMMAND_READ_FW_VER 0xD100 + +static bool dataAvailable(Sensor* sensor) __attribute__((unused)); +static bool readMeasurement(Sensor* sensor) __attribute__((unused)); +static void reset(Sensor* sensor) __attribute__((unused)); + +static bool setAutoSelfCalibration(Sensor* sensor, bool enable) __attribute__((unused)); +static bool getAutoSelfCalibration(Sensor* sensor) __attribute__((unused)); + +static bool getFirmwareVersion(Sensor* sensor, uint16_t* val) __attribute__((unused)); + +static bool setForcedRecalibrationFactor(Sensor* sensor, uint16_t concentration) + __attribute__((unused)); +static uint16_t getAltitudeCompensation(Sensor* sensor) __attribute__((unused)); +static bool setAltitudeCompensation(Sensor* sensor, uint16_t altitude) __attribute__((unused)); +static bool setAmbientPressure(Sensor* sensor, uint16_t pressure_mbar) __attribute__((unused)); + +static float getTemperatureOffset(Sensor* sensor) __attribute__((unused)); +static bool setTemperatureOffset(Sensor* sensor, float tempOffset) __attribute__((unused)); + +static bool beginMeasuringWithSettings(Sensor* sensor, uint16_t pressureOffset) + __attribute__((unused)); +static bool beginMeasuring(Sensor* sensor) __attribute__((unused)); +static bool stopMeasurement(Sensor* sensor) __attribute__((unused)); + +static bool setMeasurementInterval(Sensor* sensor, uint16_t interval) __attribute__((unused)); +static uint16_t getMeasurementInterval(Sensor* sensor) __attribute__((unused)); + +bool unitemp_SCD30_alloc(Sensor* sensor, char* args) { + UNUSED(args); + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + + i2c_sensor->minI2CAdr = SCD30_ID << 1; + i2c_sensor->maxI2CAdr = SCD30_ID << 1; + return true; +} + +bool unitemp_SCD30_free(Sensor* sensor) { + //Нечего высвобождать, так как ничего не было выделено + UNUSED(sensor); + return true; +} + +bool unitemp_SCD30_init(Sensor* sensor) { + if(beginMeasuring(sensor) == true) { // Start continuous measurements + setMeasurementInterval(sensor, SCD30.pollingInterval / 1000); + setAutoSelfCalibration(sensor, true); + setAmbientPressure(sensor, 0); + } else + return false; + + return true; +} + +bool unitemp_SCD30_deinit(Sensor* sensor) { + return stopMeasurement(sensor); +} + +UnitempStatus unitemp_SCD30_update(Sensor* sensor) { + readMeasurement(sensor); + return UT_SENSORSTATUS_OK; +} + +static uint8_t computeCRC8(uint8_t* message, uint8_t len) { + uint8_t crc = 0xFF; // Init with 0xFF + for(uint8_t x = 0; x < len; x++) { + crc ^= message[x]; // XOR-in the next input byte + for(uint8_t i = 0; i < 8; i++) { + if((crc & 0x80) != 0) + crc = (uint8_t)((crc << 1) ^ 0x31); + else + crc <<= 1; + } + } + return crc; // No output reflection +} + +// Sends a command along with arguments and CRC +static bool sendCommandWithCRC(Sensor* sensor, uint16_t command, uint16_t arguments) { + static const uint8_t cmdSize = 5; + + uint8_t bytes[cmdSize]; + uint8_t* pointer = bytes; + store16_be(pointer, command); + pointer += 2; + uint8_t* argPos = pointer; + store16_be(pointer, arguments); + pointer += 2; + *pointer = computeCRC8(argPos, pointer - argPos); + + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + return unitemp_i2c_writeArray(i2c_sensor, cmdSize, bytes); +} + +// Sends just a command, no arguments, no CRC +static bool sendCommand(Sensor* sensor, uint16_t command) { + static const uint8_t cmdSize = 2; + + uint8_t bytes[cmdSize]; + store16_be(bytes, command); + + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + return unitemp_i2c_writeArray(i2c_sensor, cmdSize, bytes); +} + +static uint16_t readRegister(Sensor* sensor, uint16_t registerAddress) { + static const uint8_t regSize = 2; + + if(!sendCommand(sensor, registerAddress)) return 0; // Sensor did not ACK + + furi_delay_ms(3); + + uint8_t bytes[regSize]; + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + if(!unitemp_i2c_readArray(i2c_sensor, regSize, bytes)) return 0; + + return load16_be(bytes); +} + +static bool loadWord(uint8_t* buff, uint16_t* val) { + uint16_t tmp = load16_be(buff); + uint8_t expectedCRC = computeCRC8(buff, 2); + if(buff[2] != expectedCRC) return false; + *val = tmp; + return true; +} + +static bool getSettingValue(Sensor* sensor, uint16_t registerAddress, uint16_t* val) { + static const uint8_t respSize = 3; + + if(!sendCommand(sensor, registerAddress)) return false; // Sensor did not ACK + + furi_delay_ms(3); + + uint8_t bytes[respSize]; + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + if(!unitemp_i2c_readArray(i2c_sensor, respSize, bytes)) return false; + + return loadWord(bytes, val); +} + +static bool loadFloat(uint8_t* buff, float* val) { + // ByteToFl tmp; + size_t cntr = 0; + uint8_t floatBuff[4]; + for(size_t i = 0; i < 2; i++) { + floatBuff[cntr++] = buff[0]; + floatBuff[cntr++] = buff[1]; + uint8_t expectedCRC = computeCRC8(buff, 2); + if(buff[2] != expectedCRC) return false; + buff += 3; + } + uint32_t tmpVal = load32_be(floatBuff); + *val = *(float*)&tmpVal; + return true; +} + +// Get 18 bytes from SCD30 +// Updates global variables with floats +// Returns true if success +static bool readMeasurement(Sensor* sensor) { + // Verify we have data from the sensor + if(!dataAvailable(sensor)) { + return false; + } + + if(!sendCommand(sensor, COMMAND_READ_MEASUREMENT)) { + FURI_LOG_E(APP_NAME, "Sensor did not ACK"); + return false; // Sensor did not ACK + } + + float tempCO2 = 0; + float tempHumidity = 0; + float tempTemperature = 0; + + furi_delay_ms(3); + + static const uint8_t respSize = 18; + uint8_t buff[respSize]; + uint8_t* bytes = buff; + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + if(!unitemp_i2c_readArray(i2c_sensor, respSize, bytes)) { + FURI_LOG_E(APP_NAME, "Error while read measures"); + return false; + } + + bool error = false; + if(loadFloat(bytes, &tempCO2)) { + sensor->co2 = tempCO2; + } else { + FURI_LOG_E(APP_NAME, "Error while parsing CO2"); + error = true; + } + + bytes += 6; + if(loadFloat(bytes, &tempTemperature)) { + sensor->temp = tempTemperature; + } else { + FURI_LOG_E(APP_NAME, "Error while parsing temp"); + error = true; + } + + bytes += 6; + if(loadFloat(bytes, &tempHumidity)) { + sensor->hum = tempHumidity; + } else { + FURI_LOG_E(APP_NAME, "Error while parsing humidity"); + error = true; + } + + return !error; +} + +static void reset(Sensor* sensor) { + sendCommand(sensor, COMMAND_RESET); +} + +static bool setAutoSelfCalibration(Sensor* sensor, bool enable) { + return sendCommandWithCRC( + sensor, COMMAND_AUTOMATIC_SELF_CALIBRATION, enable); // Activate continuous ASC +} + +// Get the current ASC setting +static bool getAutoSelfCalibration(Sensor* sensor) { + return 1 == readRegister(sensor, COMMAND_AUTOMATIC_SELF_CALIBRATION); +} + +static bool getFirmwareVersion(Sensor* sensor, uint16_t* val) { + return getSettingValue(sensor, COMMAND_READ_FW_VER, val); +} + +// Set the forced recalibration factor. See 1.3.7. +// The reference CO2 concentration has to be within the range 400 ppm ≤ cref(CO2) ≤ 2000 ppm. +static bool setForcedRecalibrationFactor(Sensor* sensor, uint16_t concentration) { + if(concentration < 400 || concentration > 2000) { + return false; // Error check. + } + return sendCommandWithCRC(sensor, COMMAND_SET_FORCED_RECALIBRATION_FACTOR, concentration); +} + +// Get the temperature offset. See 1.3.8. +static float getTemperatureOffset(Sensor* sensor) { + union { + int16_t signed16; + uint16_t unsigned16; + } signedUnsigned; // Avoid any ambiguity casting int16_t to uint16_t + signedUnsigned.unsigned16 = readRegister(sensor, COMMAND_SET_TEMPERATURE_OFFSET); + + return ((float)signedUnsigned.signed16) / 100.0; +} + +static bool setTemperatureOffset(Sensor* sensor, float tempOffset) { + // Temp offset is only positive. See: https://github.com/sparkfun/SparkFun_SCD30_Arduino_Library/issues/27#issuecomment-971986826 + //"The SCD30 offset temperature is obtained by subtracting the reference temperature from the SCD30 output temperature" + // https://www.sensirion.com/fileadmin/user_upload/customers/sensirion/Dokumente/9.5_CO2/Sensirion_CO2_Sensors_SCD30_Low_Power_Mode.pdf + + if(tempOffset < 0.0) return false; + + uint16_t value = tempOffset * 100; + + return sendCommandWithCRC(sensor, COMMAND_SET_TEMPERATURE_OFFSET, value); +} + +// Get the altitude compenstation. See 1.3.9. +static uint16_t getAltitudeCompensation(Sensor* sensor) { + return readRegister(sensor, COMMAND_SET_ALTITUDE_COMPENSATION); +} + +// Set the altitude compenstation. See 1.3.9. +static bool setAltitudeCompensation(Sensor* sensor, uint16_t altitude) { + return sendCommandWithCRC(sensor, COMMAND_SET_ALTITUDE_COMPENSATION, altitude); +} + +// Set the pressure compenstation. This is passed during measurement startup. +// mbar can be 700 to 1200 +static bool setAmbientPressure(Sensor* sensor, uint16_t pressure_mbar) { + if(pressure_mbar != 0 || pressure_mbar < 700 || pressure_mbar > 1200) { + return false; + } + return sendCommandWithCRC(sensor, COMMAND_CONTINUOUS_MEASUREMENT, pressure_mbar); +} + +// Begins continuous measurements +// Continuous measurement status is saved in non-volatile memory. When the sensor +// is powered down while continuous measurement mode is active SCD30 will measure +// continuously after repowering without sending the measurement command. +// Returns true if successful +static bool beginMeasuringWithSettings(Sensor* sensor, uint16_t pressureOffset) { + return sendCommandWithCRC(sensor, COMMAND_CONTINUOUS_MEASUREMENT, pressureOffset); +} + +// Overload - no pressureOffset +static bool beginMeasuring(Sensor* sensor) { + return beginMeasuringWithSettings(sensor, 0); +} + +// Stop continuous measurement +static bool stopMeasurement(Sensor* sensor) { + return sendCommand(sensor, COMMAND_STOP_MEAS); +} + +// Sets interval between measurements +// 2 seconds to 1800 seconds (30 minutes) +static bool setMeasurementInterval(Sensor* sensor, uint16_t interval) { + if(interval < 2 || interval > 1800) return false; + if(!sendCommandWithCRC(sensor, COMMAND_SET_MEASUREMENT_INTERVAL, interval)) return false; + uint16_t verInterval = readRegister(sensor, COMMAND_SET_MEASUREMENT_INTERVAL); + if(verInterval != interval) { + FURI_LOG_E(APP_NAME, "Measure interval wrong! Val: %02x", verInterval); + return false; + } + return true; +} + +// Gets interval between measurements +// 2 seconds to 1800 seconds (30 minutes) +static uint16_t getMeasurementInterval(Sensor* sensor) { + uint16_t interval = 0; + getSettingValue(sensor, COMMAND_SET_MEASUREMENT_INTERVAL, &interval); + return interval; +} + +// Returns true when data is available +static bool dataAvailable(Sensor* sensor) { + return 1 == readRegister(sensor, COMMAND_GET_DATA_READY); +} \ No newline at end of file diff --git a/applications/external/unitemp/sensors/SCD30.h b/applications/external/unitemp/sensors/SCD30.h new file mode 100644 index 000000000..1ebfbb411 --- /dev/null +++ b/applications/external/unitemp/sensors/SCD30.h @@ -0,0 +1,59 @@ +/* + Unitemp - Universal temperature reader + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) + Contributed by divinebird (https://github.com/divinebird) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#ifndef UNITEMP_SCD30 +#define UNITEMP_SCD30 + +#include "../unitemp.h" +#include "../Sensors.h" + +extern const SensorType SCD30; +/** + * @brief Выделение памяти и установка начальных значений датчика SCD30 + * @param sensor Указатель на создаваемый датчик + * @return Истина при успехе + */ +bool unitemp_SCD30_alloc(Sensor* sensor, char* args); + +/** + * @brief Инициализации датчика SCD30 + * @param sensor Указатель на датчик + * @return Истина если инициализация упспешная + */ +bool unitemp_SCD30_init(Sensor* sensor); + +/** + * @brief Деинициализация датчика + * @param sensor Указатель на датчик + */ +bool unitemp_SCD30_deinit(Sensor* sensor); + +/** + * @brief Обновление значений из датчика + * @param sensor Указатель на датчик + * @return Статус опроса датчика + */ +UnitempStatus unitemp_SCD30_update(Sensor* sensor); + +/** + * @brief Высвободить память датчика + * @param sensor Указатель на датчик + */ +bool unitemp_SCD30_free(Sensor* sensor); + +#endif \ No newline at end of file diff --git a/applications/external/unitemp/views/General_view.c b/applications/external/unitemp/views/General_view.c index 2c8d389bf..dd045d336 100644 --- a/applications/external/unitemp/views/General_view.c +++ b/applications/external/unitemp/views/General_view.c @@ -159,7 +159,34 @@ static void _draw_pressure(Canvas* canvas, Sensor* sensor) { canvas_draw_str(canvas, x + 52, y + 13, "kPa"); } else if(app->settings.pressure_unit == UT_PRESSURE_HPA) { canvas_draw_str(canvas, x + 67, y + 13, "hPa"); + +static void _draw_co2(Canvas* canvas, Sensor* sensor, Color color) { + const uint8_t x = 29, y = 39; + //Рисование рамки + canvas_draw_rframe(canvas, x, y, 75, 20, 3); + if(color == ColorBlack) { + canvas_draw_rbox(canvas, x, y, 75, 19, 3); + canvas_invert_color(canvas); + } else { + canvas_draw_rframe(canvas, x, y, 75, 19, 3); } + + //Рисование иконки + canvas_draw_icon(canvas, x + 3, y + 3, &I_co2_11x14); + + int16_t concentration_int = sensor->co2; + // int8_t concentration_dec = (int16_t)(sensor->co2 * 10) % 10; + + //Целая часть + if(concentration_int > 9999) { + snprintf(app->buff, BUFF_SIZE, "MAX "); + canvas_set_font(canvas, FontPrimary); + } else { + snprintf(app->buff, BUFF_SIZE, "%d", concentration_int); + canvas_set_font(canvas, FontBigNumbers); + } + + canvas_draw_str_aligned(canvas, x + 70, y + 10, AlignRight, AlignCenter, app->buff); } static void _draw_singleSensor(Canvas* canvas, Sensor* sensor, const uint8_t pos[2], Color color) { @@ -320,6 +347,17 @@ static void _draw_carousel_values(Canvas* canvas) { canvas, unitemp_sensor_getActive(generalview_sensor_index), hum_positions[1]); _draw_pressure(canvas, unitemp_sensor_getActive(generalview_sensor_index)); break; + case UT_DATA_TYPE_TEMP_HUM_CO2: + _draw_temperature( + canvas, + unitemp_sensor_getActive(generalview_sensor_index), + temp_positions[2][0], + temp_positions[2][1], + ColorWhite); + _draw_humidity( + canvas, unitemp_sensor_getActive(generalview_sensor_index), hum_positions[1]); + _draw_co2(canvas, unitemp_sensor_getActive(generalview_sensor_index), ColorWhite); + break; } } From 47734f24599edb39c9bd4ceec9196d00802bbcc2 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Thu, 8 Jun 2023 00:26:50 +0300 Subject: [PATCH 26/31] Fix --- applications/external/unitemp/views/General_view.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/applications/external/unitemp/views/General_view.c b/applications/external/unitemp/views/General_view.c index dd045d336..22d724935 100644 --- a/applications/external/unitemp/views/General_view.c +++ b/applications/external/unitemp/views/General_view.c @@ -159,6 +159,8 @@ static void _draw_pressure(Canvas* canvas, Sensor* sensor) { canvas_draw_str(canvas, x + 52, y + 13, "kPa"); } else if(app->settings.pressure_unit == UT_PRESSURE_HPA) { canvas_draw_str(canvas, x + 67, y + 13, "hPa"); + } +} static void _draw_co2(Canvas* canvas, Sensor* sensor, Color color) { const uint8_t x = 29, y = 39; From ffda6ad32102b27e493cf0d49e434997f11938a7 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Thu, 8 Jun 2023 01:03:07 +0300 Subject: [PATCH 27/31] Fix? I have no way to check if sensor still works --- applications/external/unitemp/sensors/SCD30.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/external/unitemp/sensors/SCD30.c b/applications/external/unitemp/sensors/SCD30.c index b5f15b50d..627130da7 100644 --- a/applications/external/unitemp/sensors/SCD30.c +++ b/applications/external/unitemp/sensors/SCD30.c @@ -263,7 +263,7 @@ static bool loadFloat(uint8_t* buff, float* val) { buff += 3; } uint32_t tmpVal = load32_be(floatBuff); - *val = *(float*)&tmpVal; + memcpy(val, &tmpVal, sizeof(float)); return true; } From 016249c982ac4d8ac68427e607eab68f232a246a Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Thu, 8 Jun 2023 01:05:38 +0300 Subject: [PATCH 28/31] bump ver --- applications/external/unitemp/unitemp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/external/unitemp/unitemp.h b/applications/external/unitemp/unitemp.h index 4d184b2c3..69cd8cf4f 100644 --- a/applications/external/unitemp/unitemp.h +++ b/applications/external/unitemp/unitemp.h @@ -40,7 +40,7 @@ //Имя приложения #define APP_NAME "Unitemp" //Версия приложения -#define UNITEMP_APP_VER "1.2" +#define UNITEMP_APP_VER "1.3" //Путь хранения файлов плагина #define APP_PATH_FOLDER "/ext/unitemp" //Имя файла с настройками From c5f062be9a0715ef34016e4fabf186df681e681c Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Thu, 8 Jun 2023 01:30:29 +0300 Subject: [PATCH 29/31] Rename and remove old apps --- ReadMe.md | 4 +- applications/external/flipfrid/LICENSE.md | 8 - applications/external/flipfrid/README.md | 36 - .../external/flipfrid/application.fam | 12 - applications/external/flipfrid/flipfrid.c | 276 -------- applications/external/flipfrid/flipfrid.h | 94 --- .../scene/flipfrid_scene_entrypoint.c | 201 ------ .../scene/flipfrid_scene_entrypoint.h | 8 - .../scene/flipfrid_scene_load_custom_uids.c | 85 --- .../scene/flipfrid_scene_load_custom_uids.h | 9 - .../flipfrid/scene/flipfrid_scene_load_file.c | 193 ----- .../flipfrid/scene/flipfrid_scene_load_file.h | 9 - .../scene/flipfrid_scene_run_attack.c | 666 ------------------ .../scene/flipfrid_scene_run_attack.h | 8 - .../scene/flipfrid_scene_select_field.c | 160 ----- .../scene/flipfrid_scene_select_field.h | 9 - applications/external/ibtn_fuzzer/LICENSE.md | 8 - .../external/ibtn_fuzzer/application.fam | 12 - .../external/ibtn_fuzzer/ibtnfuzzer.c | 280 -------- .../external/ibtn_fuzzer/ibtnfuzzer.h | 94 --- .../ibtn_fuzzer/images/ibutt_10px.png | Bin 304 -> 0 bytes .../scene/ibtnfuzzer_scene_entrypoint.c | 201 ------ .../scene/ibtnfuzzer_scene_entrypoint.h | 8 - .../scene/ibtnfuzzer_scene_load_custom_uids.c | 86 --- .../scene/ibtnfuzzer_scene_load_custom_uids.h | 9 - .../scene/ibtnfuzzer_scene_load_file.c | 293 -------- .../scene/ibtnfuzzer_scene_load_file.h | 9 - .../scene/ibtnfuzzer_scene_run_attack.c | 501 ------------- .../scene/ibtnfuzzer_scene_run_attack.h | 8 - .../scene/ibtnfuzzer_scene_select_field.c | 160 ----- .../scene/ibtnfuzzer_scene_select_field.h | 9 - .../application.fam | 16 +- .../{pacs_fuzzer => multi_fuzzer}/fuzzer.c | 0 .../{pacs_fuzzer => multi_fuzzer}/fuzzer_i.h | 0 .../helpers/fuzzer_custom_event.h | 0 .../helpers/fuzzer_types.h | 0 .../icons}/125_10px.png | Bin .../icons/ButtonLeft_4x7.png | Bin .../icons/ButtonRight_4x7.png | Bin .../icons/Ok_btn_9x9.png | Bin .../icons/Pin_arrow_up_7x9.png | Bin .../icons/Pin_back_arrow_10x8.png | Bin .../icons}/ibutt_10px.png | Bin .../icons}/rfid_10px.png | Bin .../lib/worker/fake_worker.c | 0 .../lib/worker/fake_worker.h | 0 .../lib/worker/protocol.c | 0 .../lib/worker/protocol.h | 0 .../lib/worker/protocol_i.h | 0 .../scenes/fuzzer_scene.c | 0 .../scenes/fuzzer_scene.h | 0 .../scenes/fuzzer_scene_attack.c | 0 .../scenes/fuzzer_scene_config.h | 0 .../scenes/fuzzer_scene_field_editor.c | 0 .../scenes/fuzzer_scene_main.c | 0 .../{pacs_fuzzer => multi_fuzzer}/todo.md | 0 .../views/attack.c | 0 .../views/attack.h | 0 .../views/field_editor.c | 0 .../views/field_editor.h | 0 .../views/main_menu.c | 0 .../views/main_menu.h | 0 .../external/pacs_fuzzer/icons/125_10px.png | Bin 308 -> 0 bytes .../external/pacs_fuzzer/icons/ibutt_10px.png | Bin 304 -> 0 bytes .../external/pacs_fuzzer/icons/rfid_10px.png | Bin 2389 -> 0 bytes 65 files changed, 10 insertions(+), 3462 deletions(-) delete mode 100644 applications/external/flipfrid/LICENSE.md delete mode 100644 applications/external/flipfrid/README.md delete mode 100644 applications/external/flipfrid/application.fam delete mode 100644 applications/external/flipfrid/flipfrid.c delete mode 100644 applications/external/flipfrid/flipfrid.h delete mode 100644 applications/external/flipfrid/scene/flipfrid_scene_entrypoint.c delete mode 100644 applications/external/flipfrid/scene/flipfrid_scene_entrypoint.h delete mode 100644 applications/external/flipfrid/scene/flipfrid_scene_load_custom_uids.c delete mode 100644 applications/external/flipfrid/scene/flipfrid_scene_load_custom_uids.h delete mode 100644 applications/external/flipfrid/scene/flipfrid_scene_load_file.c delete mode 100644 applications/external/flipfrid/scene/flipfrid_scene_load_file.h delete mode 100644 applications/external/flipfrid/scene/flipfrid_scene_run_attack.c delete mode 100644 applications/external/flipfrid/scene/flipfrid_scene_run_attack.h delete mode 100644 applications/external/flipfrid/scene/flipfrid_scene_select_field.c delete mode 100644 applications/external/flipfrid/scene/flipfrid_scene_select_field.h delete mode 100644 applications/external/ibtn_fuzzer/LICENSE.md delete mode 100644 applications/external/ibtn_fuzzer/application.fam delete mode 100644 applications/external/ibtn_fuzzer/ibtnfuzzer.c delete mode 100644 applications/external/ibtn_fuzzer/ibtnfuzzer.h delete mode 100644 applications/external/ibtn_fuzzer/images/ibutt_10px.png delete mode 100644 applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_entrypoint.c delete mode 100644 applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_entrypoint.h delete mode 100644 applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_load_custom_uids.c delete mode 100644 applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_load_custom_uids.h delete mode 100644 applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_load_file.c delete mode 100644 applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_load_file.h delete mode 100644 applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_run_attack.c delete mode 100644 applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_run_attack.h delete mode 100644 applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_select_field.c delete mode 100644 applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_select_field.h rename applications/external/{pacs_fuzzer => multi_fuzzer}/application.fam (81%) rename applications/external/{pacs_fuzzer => multi_fuzzer}/fuzzer.c (100%) rename applications/external/{pacs_fuzzer => multi_fuzzer}/fuzzer_i.h (100%) rename applications/external/{pacs_fuzzer => multi_fuzzer}/helpers/fuzzer_custom_event.h (100%) rename applications/external/{pacs_fuzzer => multi_fuzzer}/helpers/fuzzer_types.h (100%) rename applications/external/{flipfrid/images => multi_fuzzer/icons}/125_10px.png (100%) rename applications/external/{pacs_fuzzer => multi_fuzzer}/icons/ButtonLeft_4x7.png (100%) rename applications/external/{pacs_fuzzer => multi_fuzzer}/icons/ButtonRight_4x7.png (100%) rename applications/external/{pacs_fuzzer => multi_fuzzer}/icons/Ok_btn_9x9.png (100%) rename applications/external/{pacs_fuzzer => multi_fuzzer}/icons/Pin_arrow_up_7x9.png (100%) rename applications/external/{pacs_fuzzer => multi_fuzzer}/icons/Pin_back_arrow_10x8.png (100%) rename applications/external/{ibtn_fuzzer => multi_fuzzer/icons}/ibutt_10px.png (100%) rename applications/external/{flipfrid => multi_fuzzer/icons}/rfid_10px.png (100%) rename applications/external/{pacs_fuzzer => multi_fuzzer}/lib/worker/fake_worker.c (100%) rename applications/external/{pacs_fuzzer => multi_fuzzer}/lib/worker/fake_worker.h (100%) rename applications/external/{pacs_fuzzer => multi_fuzzer}/lib/worker/protocol.c (100%) rename applications/external/{pacs_fuzzer => multi_fuzzer}/lib/worker/protocol.h (100%) rename applications/external/{pacs_fuzzer => multi_fuzzer}/lib/worker/protocol_i.h (100%) rename applications/external/{pacs_fuzzer => multi_fuzzer}/scenes/fuzzer_scene.c (100%) rename applications/external/{pacs_fuzzer => multi_fuzzer}/scenes/fuzzer_scene.h (100%) rename applications/external/{pacs_fuzzer => multi_fuzzer}/scenes/fuzzer_scene_attack.c (100%) rename applications/external/{pacs_fuzzer => multi_fuzzer}/scenes/fuzzer_scene_config.h (100%) rename applications/external/{pacs_fuzzer => multi_fuzzer}/scenes/fuzzer_scene_field_editor.c (100%) rename applications/external/{pacs_fuzzer => multi_fuzzer}/scenes/fuzzer_scene_main.c (100%) rename applications/external/{pacs_fuzzer => multi_fuzzer}/todo.md (100%) rename applications/external/{pacs_fuzzer => multi_fuzzer}/views/attack.c (100%) rename applications/external/{pacs_fuzzer => multi_fuzzer}/views/attack.h (100%) rename applications/external/{pacs_fuzzer => multi_fuzzer}/views/field_editor.c (100%) rename applications/external/{pacs_fuzzer => multi_fuzzer}/views/field_editor.h (100%) rename applications/external/{pacs_fuzzer => multi_fuzzer}/views/main_menu.c (100%) rename applications/external/{pacs_fuzzer => multi_fuzzer}/views/main_menu.h (100%) delete mode 100644 applications/external/pacs_fuzzer/icons/125_10px.png delete mode 100644 applications/external/pacs_fuzzer/icons/ibutt_10px.png delete mode 100644 applications/external/pacs_fuzzer/icons/rfid_10px.png diff --git a/ReadMe.md b/ReadMe.md index 23128cac0..f9e759e0b 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -134,7 +134,8 @@ You can support us by using links or addresses below: ### Community apps included: -- **RFID Fuzzer** [(by Ganapati & @xMasterX)](https://github.com/DarkFlippers/unleashed-firmware/pull/54) & New protocols by @mvanzanten +- **RFID Fuzzer** [(by @gid9798)](https://github.com/DarkFlippers/unleashed-firmware/pull/507) (original by Ganapati & xMasterX) +- **iButton Fuzzer** [(by @gid9798)](https://github.com/DarkFlippers/unleashed-firmware/pull/507) (original by xMasterX) - **Sub-GHz bruteforcer** [(by @derskythe & xMasterX)](https://github.com/derskythe/flipperzero-subbrute) [(original by Ganapati & xMasterX)](https://github.com/DarkFlippers/unleashed-firmware/pull/57) - **Sub-GHz playlist** [(by darmiel)](https://github.com/DarkFlippers/unleashed-firmware/pull/62) - ESP8266 Deauther plugin [(by SequoiaSan)](https://github.com/SequoiaSan/FlipperZero-Wifi-ESP8266-Deauther-Module) @@ -157,7 +158,6 @@ You can support us by using links or addresses below: - Morse Code [(by wh00hw)](https://github.com/wh00hw/MorseCodeFAP) - **Unitemp - Temperature sensors reader** (DHT11/22, DS18B20, BMP280, HTU21x and more) [(by quen0n)](https://github.com/quen0n/unitemp-flipperzero) - BH1750 - Lightmeter [(by oleksiikutuzov)](https://github.com/oleksiikutuzov/flipperzero-lightmeter) -- **iButton Fuzzer** [(by xMasterX)](https://github.com/xMasterX/ibutton-fuzzer) - HEX Viewer [(by QtRoS)](https://github.com/QtRoS/flipper-zero-hex-viewer) - POCSAG Pager [(by xMasterX & Shmuma)](https://github.com/xMasterX/flipper-pager) - Text Viewer [(by kowalski7cc & kyhwana)](https://github.com/kowalski7cc/flipper-zero-text-viewer/tree/refactor-text-app) diff --git a/applications/external/flipfrid/LICENSE.md b/applications/external/flipfrid/LICENSE.md deleted file mode 100644 index a856581c9..000000000 --- a/applications/external/flipfrid/LICENSE.md +++ /dev/null @@ -1,8 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * @G4N4P4T1 wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. - * ---------------------------------------------------------------------------- - */ \ No newline at end of file diff --git a/applications/external/flipfrid/README.md b/applications/external/flipfrid/README.md deleted file mode 100644 index 83d849454..000000000 --- a/applications/external/flipfrid/README.md +++ /dev/null @@ -1,36 +0,0 @@ -# Flipfrid - -Basic LFRFID Fuzzer. - -## Why - -Flipfrid is a simple Rfid fuzzer using lfrfid protocols (125khz). -Objective is to provide a simple to use fuzzer to test readers by emulating various cards. - -- EM4100 cards use a 1 byte customer id and 4 bytes card id. -- HIDProx cards use a 2 byte customer id and 3 byte card id. - -## How - -1) Select the Protocol with the left and right arrows -2) Select the Mode with the up and down arrows -3) Set TD (Time delay) between ID switch if you need, or left it as is -4) Click Start - -### Info - -There are 4 Protocols: -- EM4100 -- HIDProx -- PAC/Stanley -- H10301 - -There are 4 modes: -- Default Values: Try factory/default keys and emulate one after the other. -- BF customer id: An iteration from 0X00 to 0XFF on the first byte. -- Load Dump file: Load an existing dump (.rfid) generated by Flipperzero, select an index and bruteforce from 0X00 to 0XFF; -- Uids list: Iterate over an input text file (one uid per line) and emulate one after the other. - - -TODO : -- Add second byte test to `BF customer id` diff --git a/applications/external/flipfrid/application.fam b/applications/external/flipfrid/application.fam deleted file mode 100644 index 1ddd6ba50..000000000 --- a/applications/external/flipfrid/application.fam +++ /dev/null @@ -1,12 +0,0 @@ -App( - appid="rfid_fuzzer", - name="RFID Fuzzer", - apptype=FlipperAppType.EXTERNAL, - entry_point="flipfrid_start", - requires=["gui", "storage", "dialogs", "input", "notification"], - stack_size=2 * 1024, - order=15, - fap_icon="rfid_10px.png", - fap_category="Tools", - fap_icon_assets="images", -) diff --git a/applications/external/flipfrid/flipfrid.c b/applications/external/flipfrid/flipfrid.c deleted file mode 100644 index 1cf7be865..000000000 --- a/applications/external/flipfrid/flipfrid.c +++ /dev/null @@ -1,276 +0,0 @@ -#include "flipfrid.h" - -#include "scene/flipfrid_scene_entrypoint.h" -#include "scene/flipfrid_scene_load_file.h" -#include "scene/flipfrid_scene_select_field.h" -#include "scene/flipfrid_scene_run_attack.h" -#include "scene/flipfrid_scene_load_custom_uids.h" - -#define RFIDFUZZER_APP_FOLDER "/ext/rfidfuzzer" - -static void flipfrid_draw_callback(Canvas* const canvas, void* ctx) { - furi_assert(ctx); - FlipFridState* flipfrid_state = ctx; - furi_mutex_acquire(flipfrid_state->mutex, FuriWaitForever); - - // Draw correct Canvas - switch(flipfrid_state->current_scene) { - case NoneScene: - case SceneEntryPoint: - flipfrid_scene_entrypoint_on_draw(canvas, flipfrid_state); - break; - case SceneSelectFile: - flipfrid_scene_load_file_on_draw(canvas, flipfrid_state); - break; - case SceneSelectField: - flipfrid_scene_select_field_on_draw(canvas, flipfrid_state); - break; - case SceneAttack: - flipfrid_scene_run_attack_on_draw(canvas, flipfrid_state); - break; - case SceneLoadCustomUids: - flipfrid_scene_load_custom_uids_on_draw(canvas, flipfrid_state); - break; - } - - furi_mutex_release(flipfrid_state->mutex); -} - -void flipfrid_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { - furi_assert(event_queue); - - FlipFridEvent event = { - .evt_type = EventTypeKey, .key = input_event->key, .input_type = input_event->type}; - furi_message_queue_put(event_queue, &event, 25); -} - -static void flipfrid_timer_callback(FuriMessageQueue* event_queue) { - furi_assert(event_queue); - FlipFridEvent event = { - .evt_type = EventTypeTick, .key = InputKeyUp, .input_type = InputTypeRelease}; - furi_message_queue_put(event_queue, &event, 25); -} - -FlipFridState* flipfrid_alloc() { - FlipFridState* flipfrid = malloc(sizeof(FlipFridState)); - flipfrid->notification_msg = furi_string_alloc(); - flipfrid->attack_name = furi_string_alloc(); - flipfrid->proto_name = furi_string_alloc(); - flipfrid->data_str = furi_string_alloc(); - - flipfrid->main_menu_items[0] = furi_string_alloc_set("Default Values"); - flipfrid->main_menu_items[1] = furi_string_alloc_set("BF Customer ID"); - flipfrid->main_menu_items[2] = furi_string_alloc_set("Load File"); - flipfrid->main_menu_items[3] = furi_string_alloc_set("Load UIDs from file"); - - flipfrid->main_menu_proto_items[0] = furi_string_alloc_set("EM4100"); - flipfrid->main_menu_proto_items[1] = furi_string_alloc_set("HIDProx"); - flipfrid->main_menu_proto_items[2] = furi_string_alloc_set("PAC/Stanley"); - flipfrid->main_menu_proto_items[3] = furi_string_alloc_set("H10301"); - - flipfrid->previous_scene = NoneScene; - flipfrid->current_scene = SceneEntryPoint; - flipfrid->is_running = true; - flipfrid->is_attacking = false; - flipfrid->key_index = 0; - flipfrid->menu_index = 0; - flipfrid->menu_proto_index = 0; - - flipfrid->attack = FlipFridAttackDefaultValues; - flipfrid->notify = furi_record_open(RECORD_NOTIFICATION); - - flipfrid->data[0] = 0x00; - flipfrid->data[1] = 0x00; - flipfrid->data[2] = 0x00; - flipfrid->data[3] = 0x00; - flipfrid->data[4] = 0x00; - flipfrid->data[5] = 0x00; - - flipfrid->payload[0] = 0x00; - flipfrid->payload[1] = 0x00; - flipfrid->payload[2] = 0x00; - flipfrid->payload[3] = 0x00; - flipfrid->payload[4] = 0x00; - flipfrid->payload[5] = 0x00; - - //Dialog - flipfrid->dialogs = furi_record_open(RECORD_DIALOGS); - - return flipfrid; -} - -void flipfrid_free(FlipFridState* flipfrid) { - //Dialog - furi_record_close(RECORD_DIALOGS); - notification_message(flipfrid->notify, &sequence_blink_stop); - - // Strings - furi_string_free(flipfrid->notification_msg); - furi_string_free(flipfrid->attack_name); - furi_string_free(flipfrid->proto_name); - furi_string_free(flipfrid->data_str); - - for(uint32_t i = 0; i < 4; i++) { - furi_string_free(flipfrid->main_menu_items[i]); - } - - for(uint32_t i = 0; i < 4; i++) { - furi_string_free(flipfrid->main_menu_proto_items[i]); - } - - // The rest - free(flipfrid); -} - -// ENTRYPOINT -int32_t flipfrid_start(void* p) { - UNUSED(p); - // Input - FURI_LOG_I(TAG, "Initializing input"); - FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(FlipFridEvent)); - FlipFridState* flipfrid_state = flipfrid_alloc(); - - flipfrid_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal); - if(!flipfrid_state->mutex) { - FURI_LOG_E(TAG, "cannot create mutex\r\n"); - furi_message_queue_free(event_queue); - furi_record_close(RECORD_NOTIFICATION); - flipfrid_free(flipfrid_state); - return 255; - } - - Storage* storage = furi_record_open(RECORD_STORAGE); - if(!storage_simply_mkdir(storage, RFIDFUZZER_APP_FOLDER)) { - FURI_LOG_E(TAG, "Could not create folder %s", RFIDFUZZER_APP_FOLDER); - } - furi_record_close(RECORD_STORAGE); - - // Configure view port - FURI_LOG_I(TAG, "Initializing viewport"); - ViewPort* view_port = view_port_alloc(); - view_port_draw_callback_set(view_port, flipfrid_draw_callback, flipfrid_state); - view_port_input_callback_set(view_port, flipfrid_input_callback, event_queue); - - // Configure timer - FURI_LOG_I(TAG, "Initializing timer"); - FuriTimer* timer = - furi_timer_alloc(flipfrid_timer_callback, FuriTimerTypePeriodic, event_queue); - furi_timer_start(timer, furi_kernel_get_tick_frequency() / 10); // 10 times per second - - // Register view port in GUI - FURI_LOG_I(TAG, "Initializing gui"); - Gui* gui = (Gui*)furi_record_open(RECORD_GUI); - gui_add_view_port(gui, view_port, GuiLayerFullscreen); - - // Init values - FlipFridEvent event; - while(flipfrid_state->is_running) { - // Get next event - FuriStatus event_status = furi_message_queue_get(event_queue, &event, 25); - if(event_status == FuriStatusOk) { - if(event.evt_type == EventTypeKey) { - //Handle event key - switch(flipfrid_state->current_scene) { - case NoneScene: - case SceneEntryPoint: - flipfrid_scene_entrypoint_on_event(event, flipfrid_state); - break; - case SceneSelectFile: - flipfrid_scene_load_file_on_event(event, flipfrid_state); - break; - case SceneSelectField: - flipfrid_scene_select_field_on_event(event, flipfrid_state); - break; - case SceneAttack: - flipfrid_scene_run_attack_on_event(event, flipfrid_state); - break; - case SceneLoadCustomUids: - flipfrid_scene_load_custom_uids_on_event(event, flipfrid_state); - break; - } - - } else if(event.evt_type == EventTypeTick) { - //Handle event tick - if(flipfrid_state->current_scene != flipfrid_state->previous_scene) { - // Trigger Exit Scene - switch(flipfrid_state->previous_scene) { - case SceneEntryPoint: - flipfrid_scene_entrypoint_on_exit(flipfrid_state); - break; - case SceneSelectFile: - flipfrid_scene_load_file_on_exit(flipfrid_state); - break; - case SceneSelectField: - flipfrid_scene_select_field_on_exit(flipfrid_state); - break; - case SceneAttack: - flipfrid_scene_run_attack_on_exit(flipfrid_state); - break; - case SceneLoadCustomUids: - flipfrid_scene_load_custom_uids_on_exit(flipfrid_state); - break; - case NoneScene: - break; - } - - // Trigger Entry Scene - switch(flipfrid_state->current_scene) { - case NoneScene: - case SceneEntryPoint: - flipfrid_scene_entrypoint_on_enter(flipfrid_state); - break; - case SceneSelectFile: - flipfrid_scene_load_file_on_enter(flipfrid_state); - break; - case SceneSelectField: - flipfrid_scene_select_field_on_enter(flipfrid_state); - break; - case SceneAttack: - flipfrid_scene_run_attack_on_enter(flipfrid_state); - break; - case SceneLoadCustomUids: - flipfrid_scene_load_custom_uids_on_enter(flipfrid_state); - break; - } - flipfrid_state->previous_scene = flipfrid_state->current_scene; - } - - // Trigger Tick Scene - switch(flipfrid_state->current_scene) { - case NoneScene: - case SceneEntryPoint: - flipfrid_scene_entrypoint_on_tick(flipfrid_state); - break; - case SceneSelectFile: - flipfrid_scene_load_file_on_tick(flipfrid_state); - break; - case SceneSelectField: - flipfrid_scene_select_field_on_tick(flipfrid_state); - break; - case SceneAttack: - flipfrid_scene_run_attack_on_tick(flipfrid_state); - break; - case SceneLoadCustomUids: - flipfrid_scene_load_custom_uids_on_tick(flipfrid_state); - break; - } - view_port_update(view_port); - } - } - } - - // Cleanup - furi_timer_stop(timer); - furi_timer_free(timer); - - FURI_LOG_I(TAG, "Cleaning up"); - gui_remove_view_port(gui, view_port); - view_port_free(view_port); - furi_message_queue_free(event_queue); - furi_record_close(RECORD_GUI); - furi_record_close(RECORD_NOTIFICATION); - furi_mutex_free(flipfrid_state->mutex); - flipfrid_free(flipfrid_state); - - return 0; -} \ No newline at end of file diff --git a/applications/external/flipfrid/flipfrid.h b/applications/external/flipfrid/flipfrid.h deleted file mode 100644 index b95f9f75f..000000000 --- a/applications/external/flipfrid/flipfrid.h +++ /dev/null @@ -1,94 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include - -#include -#include - -#define TAG "FlipFrid" - -typedef enum { - FlipFridAttackDefaultValues, - FlipFridAttackBfCustomerId, - FlipFridAttackLoadFile, - FlipFridAttackLoadFileCustomUids, -} FlipFridAttacks; - -typedef enum { - EM4100, - HIDProx, - PAC, - H10301, -} FlipFridProtos; - -typedef enum { - NoneScene, - SceneEntryPoint, - SceneSelectFile, - SceneSelectField, - SceneAttack, - SceneLoadCustomUids, -} FlipFridScene; - -typedef enum { - EventTypeTick, - EventTypeKey, -} EventType; - -typedef struct { - EventType evt_type; - InputKey key; - InputType input_type; -} FlipFridEvent; - -// STRUCTS -typedef struct { - FuriMutex* mutex; - bool is_running; - bool is_attacking; - FlipFridScene current_scene; - FlipFridScene previous_scene; - NotificationApp* notify; - u_int8_t menu_index; - u_int8_t menu_proto_index; - - FuriString* data_str; - uint8_t data[6]; - uint8_t payload[6]; - uint8_t attack_step; - FlipFridAttacks attack; - FlipFridProtos proto; - FuriString* attack_name; - FuriString* proto_name; - FuriString* main_menu_items[4]; - FuriString* main_menu_proto_items[4]; - - DialogsApp* dialogs; - FuriString* notification_msg; - uint8_t key_index; - LFRFIDWorker* worker; - ProtocolDict* dict; - ProtocolId protocol; - bool workr_rund; - bool attack_stop_called; - - uint8_t time_between_cards; - - // Used for custom dictionnary - Stream* uids_stream; -} FlipFridState; \ No newline at end of file diff --git a/applications/external/flipfrid/scene/flipfrid_scene_entrypoint.c b/applications/external/flipfrid/scene/flipfrid_scene_entrypoint.c deleted file mode 100644 index f4b39aa66..000000000 --- a/applications/external/flipfrid/scene/flipfrid_scene_entrypoint.c +++ /dev/null @@ -1,201 +0,0 @@ -#include "flipfrid_scene_entrypoint.h" - -void flipfrid_scene_entrypoint_menu_callback( - FlipFridState* context, - uint32_t index, - uint32_t proto_index) { - switch(index) { - case FlipFridAttackDefaultValues: - context->attack = FlipFridAttackDefaultValues; - context->current_scene = SceneAttack; - furi_string_set(context->attack_name, "Default Values"); - break; - case FlipFridAttackBfCustomerId: - context->attack = FlipFridAttackBfCustomerId; - context->current_scene = SceneAttack; - furi_string_set(context->attack_name, "Bad Customer ID"); - break; - case FlipFridAttackLoadFile: - context->attack = FlipFridAttackLoadFile; - context->current_scene = SceneSelectFile; - furi_string_set(context->attack_name, "Load File"); - break; - case FlipFridAttackLoadFileCustomUids: - context->attack = FlipFridAttackLoadFileCustomUids; - context->current_scene = SceneLoadCustomUids; - furi_string_set(context->attack_name, "Load Custom UIDs"); - break; - default: - break; - } - - switch(proto_index) { - case EM4100: - context->proto = EM4100; - furi_string_set(context->proto_name, "EM4100"); - break; - case HIDProx: - context->proto = HIDProx; - furi_string_set(context->proto_name, "HIDProx"); - break; - case PAC: - context->proto = PAC; - furi_string_set(context->proto_name, "PAC/Stanley"); - break; - case H10301: - context->proto = H10301; - furi_string_set(context->proto_name, "H10301"); - break; - default: - break; - } -} - -void flipfrid_scene_entrypoint_on_enter(FlipFridState* context) { - // Clear the previous payload - context->payload[0] = 0x00; - context->payload[1] = 0x00; - context->payload[2] = 0x00; - context->payload[3] = 0x00; - context->payload[4] = 0x00; - context->payload[5] = 0x00; - - context->menu_index = 0; - /*for(uint32_t i = 0; i < 4; i++) { - menu_items[i] = furi_string_alloc(); - }*/ - - context->menu_proto_index = 0; - /*for(uint32_t i = 0; i < 4; i++) { - menu_proto_items[i] = furi_string_alloc(); - }*/ -} - -void flipfrid_scene_entrypoint_on_exit(FlipFridState* context) { - UNUSED(context); -} - -void flipfrid_scene_entrypoint_on_tick(FlipFridState* context) { - UNUSED(context); -} - -void flipfrid_scene_entrypoint_on_event(FlipFridEvent event, FlipFridState* context) { - if(event.evt_type == EventTypeKey) { - if(event.input_type == InputTypeShort) { - switch(event.key) { - case InputKeyDown: - if(context->menu_index < FlipFridAttackLoadFileCustomUids) { - context->menu_index++; - } - break; - case InputKeyUp: - if(context->menu_index > FlipFridAttackDefaultValues) { - context->menu_index--; - } - break; - case InputKeyLeft: - if(context->menu_proto_index > EM4100) { - context->menu_proto_index--; - } else if(context->menu_proto_index == EM4100) { - context->menu_proto_index = H10301; - } - break; - case InputKeyRight: - if(context->menu_proto_index < H10301) { - context->menu_proto_index++; - } else if(context->menu_proto_index == H10301) { - context->menu_proto_index = EM4100; - } - break; - case InputKeyOk: - flipfrid_scene_entrypoint_menu_callback( - context, context->menu_index, context->menu_proto_index); - break; - case InputKeyBack: - context->is_running = false; - break; - default: - break; - } - } - } -} - -void flipfrid_scene_entrypoint_on_draw(Canvas* canvas, FlipFridState* context) { - canvas_clear(canvas); - canvas_set_color(canvas, ColorBlack); - - if(context->main_menu_items != NULL) { - if(context->main_menu_items[context->menu_index] != NULL) { - if(context->menu_index > FlipFridAttackDefaultValues) { - canvas_set_font(canvas, FontSecondary); - canvas_draw_str_aligned( - canvas, - 64, - 24, - AlignCenter, - AlignTop, - furi_string_get_cstr(context->main_menu_items[context->menu_index - 1])); - } - - canvas_set_font(canvas, FontPrimary); - canvas_draw_str_aligned( - canvas, - 64, - 36, - AlignCenter, - AlignTop, - furi_string_get_cstr(context->main_menu_items[context->menu_index])); - - if(context->menu_index < FlipFridAttackLoadFileCustomUids) { - canvas_set_font(canvas, FontSecondary); - canvas_draw_str_aligned( - canvas, - 64, - 48, - AlignCenter, - AlignTop, - furi_string_get_cstr(context->main_menu_items[context->menu_index + 1])); - } - - if(context->menu_proto_index > EM4100) { - canvas_set_font(canvas, FontSecondary); - canvas_draw_str_aligned( - canvas, - 64, - -12, - AlignCenter, - AlignTop, - furi_string_get_cstr( - context->main_menu_proto_items[context->menu_proto_index - 1])); - } - - canvas_set_font(canvas, FontPrimary); - canvas_draw_str_aligned(canvas, 27, 4, AlignCenter, AlignTop, "<"); - - canvas_set_font(canvas, FontPrimary); - canvas_draw_str_aligned( - canvas, - 64, - 4, - AlignCenter, - AlignTop, - furi_string_get_cstr(context->main_menu_proto_items[context->menu_proto_index])); - - canvas_set_font(canvas, FontPrimary); - canvas_draw_str_aligned(canvas, 101, 4, AlignCenter, AlignTop, ">"); - - if(context->menu_proto_index < H10301) { - canvas_set_font(canvas, FontSecondary); - canvas_draw_str_aligned( - canvas, - 64, - -12, - AlignCenter, - AlignTop, - furi_string_get_cstr( - context->main_menu_proto_items[context->menu_proto_index + 1])); - } - } - } -} \ No newline at end of file diff --git a/applications/external/flipfrid/scene/flipfrid_scene_entrypoint.h b/applications/external/flipfrid/scene/flipfrid_scene_entrypoint.h deleted file mode 100644 index 29ca5bdfa..000000000 --- a/applications/external/flipfrid/scene/flipfrid_scene_entrypoint.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once -#include "../flipfrid.h" - -void flipfrid_scene_entrypoint_on_enter(FlipFridState* context); -void flipfrid_scene_entrypoint_on_exit(FlipFridState* context); -void flipfrid_scene_entrypoint_on_tick(FlipFridState* context); -void flipfrid_scene_entrypoint_on_event(FlipFridEvent event, FlipFridState* context); -void flipfrid_scene_entrypoint_on_draw(Canvas* canvas, FlipFridState* context); \ No newline at end of file diff --git a/applications/external/flipfrid/scene/flipfrid_scene_load_custom_uids.c b/applications/external/flipfrid/scene/flipfrid_scene_load_custom_uids.c deleted file mode 100644 index 32157556b..000000000 --- a/applications/external/flipfrid/scene/flipfrid_scene_load_custom_uids.c +++ /dev/null @@ -1,85 +0,0 @@ -#include "flipfrid_scene_load_custom_uids.h" -#include "flipfrid_scene_run_attack.h" -#include "flipfrid_scene_entrypoint.h" - -#define LFRFID_UIDS_EXTENSION ".txt" -#define RFIDFUZZER_APP_PATH_FOLDER "/ext/rfidfuzzer" - -bool flipfrid_load_uids(FlipFridState* context, const char* file_path) { - bool result = false; - Storage* storage = furi_record_open(RECORD_STORAGE); - context->uids_stream = buffered_file_stream_alloc(storage); - result = - buffered_file_stream_open(context->uids_stream, file_path, FSAM_READ, FSOM_OPEN_EXISTING); - // Close if loading fails - if(!result) { - buffered_file_stream_close(context->uids_stream); - return false; - } - return result; -} - -bool flipfrid_load_custom_uids_from_file(FlipFridState* context) { - // Input events and views are managed by file_select - FuriString* uid_path; - uid_path = furi_string_alloc(); - furi_string_set(uid_path, RFIDFUZZER_APP_PATH_FOLDER); - - DialogsFileBrowserOptions browser_options; - dialog_file_browser_set_basic_options(&browser_options, LFRFID_UIDS_EXTENSION, &I_125_10px); - browser_options.base_path = RFIDFUZZER_APP_PATH_FOLDER; - browser_options.hide_ext = false; - - bool res = dialog_file_browser_show(context->dialogs, uid_path, uid_path, &browser_options); - - if(res) { - res = flipfrid_load_uids(context, furi_string_get_cstr(uid_path)); - } - - furi_string_free(uid_path); - - return res; -} - -void flipfrid_scene_load_custom_uids_on_enter(FlipFridState* context) { - if(flipfrid_load_custom_uids_from_file(context)) { - // Force context loading - flipfrid_scene_run_attack_on_enter(context); - context->current_scene = SceneAttack; - } else { - flipfrid_scene_entrypoint_on_enter(context); - context->current_scene = SceneEntryPoint; - } -} - -void flipfrid_scene_load_custom_uids_on_exit(FlipFridState* context) { - UNUSED(context); -} - -void flipfrid_scene_load_custom_uids_on_tick(FlipFridState* context) { - UNUSED(context); -} - -void flipfrid_scene_load_custom_uids_on_event(FlipFridEvent event, FlipFridState* context) { - if(event.evt_type == EventTypeKey) { - if(event.input_type == InputTypeShort) { - switch(event.key) { - case InputKeyDown: - case InputKeyUp: - case InputKeyLeft: - case InputKeyRight: - case InputKeyOk: - case InputKeyBack: - context->current_scene = SceneEntryPoint; - break; - default: - break; - } - } - } -} - -void flipfrid_scene_load_custom_uids_on_draw(Canvas* canvas, FlipFridState* context) { - UNUSED(context); - UNUSED(canvas); -} diff --git a/applications/external/flipfrid/scene/flipfrid_scene_load_custom_uids.h b/applications/external/flipfrid/scene/flipfrid_scene_load_custom_uids.h deleted file mode 100644 index a8ed982b6..000000000 --- a/applications/external/flipfrid/scene/flipfrid_scene_load_custom_uids.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include "../flipfrid.h" - -void flipfrid_scene_load_custom_uids_on_enter(FlipFridState* context); -void flipfrid_scene_load_custom_uids_on_exit(FlipFridState* context); -void flipfrid_scene_load_custom_uids_on_tick(FlipFridState* context); -void flipfrid_scene_load_custom_uids_on_event(FlipFridEvent event, FlipFridState* context); -void flipfrid_scene_load_custom_uids_on_draw(Canvas* canvas, FlipFridState* context); -bool flipfrid_load_custom_uids_from_file(FlipFridState* context); \ No newline at end of file diff --git a/applications/external/flipfrid/scene/flipfrid_scene_load_file.c b/applications/external/flipfrid/scene/flipfrid_scene_load_file.c deleted file mode 100644 index 5f3f1a31b..000000000 --- a/applications/external/flipfrid/scene/flipfrid_scene_load_file.c +++ /dev/null @@ -1,193 +0,0 @@ -#include "flipfrid_scene_load_file.h" -#include "flipfrid_scene_entrypoint.h" - -#define LFRFID_APP_EXTENSION ".rfid" -#define LFRFID_APP_PATH_FOLDER "/ext/lfrfid" - -bool flipfrid_load(FlipFridState* context, const char* file_path) { - bool result = false; - Storage* storage = furi_record_open(RECORD_STORAGE); - FlipperFormat* fff_data_file = flipper_format_file_alloc(storage); - FuriString* temp_str; - temp_str = furi_string_alloc(); - do { - if(!flipper_format_file_open_existing(fff_data_file, file_path)) { - FURI_LOG_E(TAG, "Error open file %s", file_path); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Error open file"); - break; - } - - // FileType - if(!flipper_format_read_string(fff_data_file, "Filetype", temp_str)) { - FURI_LOG_E(TAG, "Missing or incorrect Filetype"); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Missing or incorrect Filetypes"); - break; - } else { - FURI_LOG_I(TAG, "Filetype: %s", furi_string_get_cstr(temp_str)); - } - - // Key type - if(!flipper_format_read_string(fff_data_file, "Key type", temp_str)) { - FURI_LOG_E(TAG, "Missing or incorrect Key type"); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Missing or incorrect Key type"); - break; - } else { - FURI_LOG_I(TAG, "Key type: %s", furi_string_get_cstr(temp_str)); - - if(context->proto == EM4100) { - if(strcmp(furi_string_get_cstr(temp_str), "EM4100") != 0) { - FURI_LOG_E(TAG, "Unsupported Key type"); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Unsupported Key type"); - break; - } - } else if(context->proto == PAC) { - if(strcmp(furi_string_get_cstr(temp_str), "PAC/Stanley") != 0) { - FURI_LOG_E(TAG, "Unsupported Key type"); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Unsupported Key type"); - break; - } - } else if(context->proto == H10301) { - if(strcmp(furi_string_get_cstr(temp_str), "H10301") != 0) { - FURI_LOG_E(TAG, "Unsupported Key type"); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Unsupported Key type"); - break; - } - } else { - if(strcmp(furi_string_get_cstr(temp_str), "HIDProx") != 0) { - FURI_LOG_E(TAG, "Unsupported Key type"); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Unsupported Key type"); - break; - } - } - } - - // Data - if(!flipper_format_read_string(fff_data_file, "Data", context->data_str)) { - FURI_LOG_E(TAG, "Missing or incorrect Data"); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Missing or incorrect Key"); - break; - } else { - FURI_LOG_I(TAG, "Key: %s", furi_string_get_cstr(context->data_str)); - - if(context->proto == EM4100) { - if(furi_string_size(context->data_str) != 14) { - FURI_LOG_E(TAG, "Incorrect Key length"); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Incorrect Key length"); - break; - } - } else if(context->proto == PAC) { - if(furi_string_size(context->data_str) != 11) { - FURI_LOG_E(TAG, "Incorrect Key length"); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Incorrect Key length"); - break; - } - } else if(context->proto == H10301) { - if(furi_string_size(context->data_str) != 8) { - FURI_LOG_E(TAG, "Incorrect Key length"); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Incorrect Key length"); - break; - } - } else { - if(furi_string_size(context->data_str) != 17) { - FURI_LOG_E(TAG, "Incorrect Key length"); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Incorrect Key length"); - break; - } - } - - // String to uint8_t - for(uint8_t i = 0; i < 6; i++) { - char temp_str2[3]; - temp_str2[0] = furi_string_get_cstr(context->data_str)[i * 3]; - temp_str2[1] = furi_string_get_cstr(context->data_str)[i * 3 + 1]; - temp_str2[2] = '\0'; - context->data[i] = (uint8_t)strtol(temp_str2, NULL, 16); - } - } - - result = true; - } while(0); - furi_string_free(temp_str); - flipper_format_free(fff_data_file); - if(result) { - FURI_LOG_I(TAG, "Loaded successfully"); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Source loaded."); - } - return result; -} - -void flipfrid_scene_load_file_on_enter(FlipFridState* context) { - if(flipfrid_load_protocol_from_file(context)) { - context->current_scene = SceneSelectField; - } else { - flipfrid_scene_entrypoint_on_enter(context); - context->current_scene = SceneEntryPoint; - } -} - -void flipfrid_scene_load_file_on_exit(FlipFridState* context) { - UNUSED(context); -} - -void flipfrid_scene_load_file_on_tick(FlipFridState* context) { - UNUSED(context); -} - -void flipfrid_scene_load_file_on_event(FlipFridEvent event, FlipFridState* context) { - if(event.evt_type == EventTypeKey) { - if(event.input_type == InputTypeShort) { - switch(event.key) { - case InputKeyDown: - case InputKeyUp: - case InputKeyLeft: - case InputKeyRight: - case InputKeyOk: - case InputKeyBack: - context->current_scene = SceneEntryPoint; - break; - default: - break; - } - } - } -} - -void flipfrid_scene_load_file_on_draw(Canvas* canvas, FlipFridState* context) { - UNUSED(context); - UNUSED(canvas); -} - -bool flipfrid_load_protocol_from_file(FlipFridState* context) { - FuriString* user_file_path; - user_file_path = furi_string_alloc(); - furi_string_set(user_file_path, LFRFID_APP_PATH_FOLDER); - - DialogsFileBrowserOptions browser_options; - dialog_file_browser_set_basic_options(&browser_options, LFRFID_APP_EXTENSION, &I_125_10px); - browser_options.base_path = LFRFID_APP_PATH_FOLDER; - - // Input events and views are managed by file_select - bool res = dialog_file_browser_show( - context->dialogs, user_file_path, user_file_path, &browser_options); - - if(res) { - res = flipfrid_load(context, furi_string_get_cstr(user_file_path)); - } - - furi_string_free(user_file_path); - - return res; -} \ No newline at end of file diff --git a/applications/external/flipfrid/scene/flipfrid_scene_load_file.h b/applications/external/flipfrid/scene/flipfrid_scene_load_file.h deleted file mode 100644 index ca82daab4..000000000 --- a/applications/external/flipfrid/scene/flipfrid_scene_load_file.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include "../flipfrid.h" - -void flipfrid_scene_load_file_on_enter(FlipFridState* context); -void flipfrid_scene_load_file_on_exit(FlipFridState* context); -void flipfrid_scene_load_file_on_tick(FlipFridState* context); -void flipfrid_scene_load_file_on_event(FlipFridEvent event, FlipFridState* context); -void flipfrid_scene_load_file_on_draw(Canvas* canvas, FlipFridState* context); -bool flipfrid_load_protocol_from_file(FlipFridState* context); \ No newline at end of file diff --git a/applications/external/flipfrid/scene/flipfrid_scene_run_attack.c b/applications/external/flipfrid/scene/flipfrid_scene_run_attack.c deleted file mode 100644 index 5f40313ba..000000000 --- a/applications/external/flipfrid/scene/flipfrid_scene_run_attack.c +++ /dev/null @@ -1,666 +0,0 @@ -#include "flipfrid_scene_run_attack.h" -#include - -uint8_t counter = 0; - -uint8_t id_list[17][5] = { - {0x00, 0x00, 0x00, 0x00, 0x00}, // Null bytes - {0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Only FF - {0x11, 0x11, 0x11, 0x11, 0x11}, // Only 11 - {0x22, 0x22, 0x22, 0x22, 0x22}, // Only 22 - {0x33, 0x33, 0x33, 0x33, 0x33}, // Only 33 - {0x44, 0x44, 0x44, 0x44, 0x44}, // Only 44 - {0x55, 0x55, 0x55, 0x55, 0x55}, // Only 55 - {0x66, 0x66, 0x66, 0x66, 0x66}, // Only 66 - {0x77, 0x77, 0x77, 0x77, 0x77}, // Only 77 - {0x88, 0x88, 0x88, 0x88, 0x88}, // Only 88 - {0x99, 0x99, 0x99, 0x99, 0x99}, // Only 99 - {0x12, 0x34, 0x56, 0x78, 0x9A}, // Incremental UID - {0x9A, 0x78, 0x56, 0x34, 0x12}, // Decremental UID - {0x04, 0xd0, 0x9b, 0x0d, 0x6a}, // From arha - {0x34, 0x00, 0x29, 0x3d, 0x9e}, // From arha - {0x04, 0xdf, 0x00, 0x00, 0x01}, // From arha - {0xCA, 0xCA, 0xCA, 0xCA, 0xCA}, // From arha -}; - -uint8_t id_list_hid[14][6] = { - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Null bytes - {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // Only FF - {0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, // Only 11 - {0x22, 0x22, 0x22, 0x22, 0x22, 0x22}, // Only 22 - {0x33, 0x33, 0x33, 0x33, 0x33, 0x33}, // Only 33 - {0x44, 0x44, 0x44, 0x44, 0x44, 0x44}, // Only 44 - {0x55, 0x55, 0x55, 0x55, 0x55, 0x55}, // Only 55 - {0x66, 0x66, 0x66, 0x66, 0x66, 0x66}, // Only 66 - {0x77, 0x77, 0x77, 0x77, 0x77, 0x77}, // Only 77 - {0x88, 0x88, 0x88, 0x88, 0x88, 0x88}, // Only 88 - {0x99, 0x99, 0x99, 0x99, 0x99, 0x99}, // Only 99 - {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC}, // Incremental UID - {0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12}, // Decremental UID - {0xCA, 0xCA, 0xCA, 0xCA, 0xCA, 0xCA}, // From arha -}; - -uint8_t id_list_pac[17][4] = { - {0x00, 0x00, 0x00, 0x00}, // Null bytes - {0xFF, 0xFF, 0xFF, 0xFF}, // Only FF - {0x11, 0x11, 0x11, 0x11}, // Only 11 - {0x22, 0x22, 0x22, 0x22}, // Only 22 - {0x33, 0x33, 0x33, 0x33}, // Only 33 - {0x44, 0x44, 0x44, 0x44}, // Only 44 - {0x55, 0x55, 0x55, 0x55}, // Only 55 - {0x66, 0x66, 0x66, 0x66}, // Only 66 - {0x77, 0x77, 0x77, 0x77}, // Only 77 - {0x88, 0x88, 0x88, 0x88}, // Only 88 - {0x99, 0x99, 0x99, 0x99}, // Only 99 - {0x12, 0x34, 0x56, 0x78}, // Incremental UID - {0x9A, 0x78, 0x56, 0x34}, // Decremental UID - {0x04, 0xd0, 0x9b, 0x0d}, // From arha - {0x34, 0x00, 0x29, 0x3d}, // From arha - {0x04, 0xdf, 0x00, 0x00}, // From arha - {0xCA, 0xCA, 0xCA, 0xCA}, // From arha -}; - -uint8_t id_list_h[14][3] = { - {0x00, 0x00, 0x00}, // Null bytes - {0xFF, 0xFF, 0xFF}, // Only FF - {0x11, 0x11, 0x11}, // Only 11 - {0x22, 0x22, 0x22}, // Only 22 - {0x33, 0x33, 0x33}, // Only 33 - {0x44, 0x44, 0x44}, // Only 44 - {0x55, 0x55, 0x55}, // Only 55 - {0x66, 0x66, 0x66}, // Only 66 - {0x77, 0x77, 0x77}, // Only 77 - {0x88, 0x88, 0x88}, // Only 88 - {0x99, 0x99, 0x99}, // Only 99 - {0x12, 0x34, 0x56}, // Incremental UID - {0x56, 0x34, 0x12}, // Decremental UID - {0xCA, 0xCA, 0xCA}, // From arha -}; - -void flipfrid_scene_run_attack_on_enter(FlipFridState* context) { - context->time_between_cards = 10; - context->attack_step = 0; - context->attack_stop_called = false; - context->dict = protocol_dict_alloc(lfrfid_protocols, LFRFIDProtocolMax); - context->worker = lfrfid_worker_alloc(context->dict); - if(context->proto == HIDProx) { - context->protocol = protocol_dict_get_protocol_by_name(context->dict, "HIDProx"); - } else if(context->proto == PAC) { - context->protocol = protocol_dict_get_protocol_by_name(context->dict, "PAC/Stanley"); - } else if(context->proto == H10301) { - context->protocol = protocol_dict_get_protocol_by_name(context->dict, "H10301"); - } else { - context->protocol = protocol_dict_get_protocol_by_name(context->dict, "EM4100"); - } -} - -void flipfrid_scene_run_attack_on_exit(FlipFridState* context) { - if(context->workr_rund) { - lfrfid_worker_stop(context->worker); - lfrfid_worker_stop_thread(context->worker); - context->workr_rund = false; - } - lfrfid_worker_free(context->worker); - protocol_dict_free(context->dict); - notification_message(context->notify, &sequence_blink_stop); -} - -void flipfrid_scene_run_attack_on_tick(FlipFridState* context) { - if(context->is_attacking) { - if(1 == counter) { - protocol_dict_set_data(context->dict, context->protocol, context->payload, 6); - lfrfid_worker_free(context->worker); - context->worker = lfrfid_worker_alloc(context->dict); - lfrfid_worker_start_thread(context->worker); - lfrfid_worker_emulate_start(context->worker, context->protocol); - context->workr_rund = true; - } else if(0 == counter) { - if(context->workr_rund) { - lfrfid_worker_stop(context->worker); - lfrfid_worker_stop_thread(context->worker); - context->workr_rund = false; - furi_delay_ms(200); - } - switch(context->attack) { - case FlipFridAttackDefaultValues: - if(context->proto == EM4100) { - context->payload[0] = id_list[context->attack_step][0]; - context->payload[1] = id_list[context->attack_step][1]; - context->payload[2] = id_list[context->attack_step][2]; - context->payload[3] = id_list[context->attack_step][3]; - context->payload[4] = id_list[context->attack_step][4]; - - if(context->attack_step == 16) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_single_vibro); - } else { - context->attack_step++; - } - break; - } else if(context->proto == PAC) { - context->payload[0] = id_list_pac[context->attack_step][0]; - context->payload[1] = id_list_pac[context->attack_step][1]; - context->payload[2] = id_list_pac[context->attack_step][2]; - context->payload[3] = id_list_pac[context->attack_step][3]; - - if(context->attack_step == 16) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_single_vibro); - } else { - context->attack_step++; - } - break; - } else if(context->proto == H10301) { - context->payload[0] = id_list_h[context->attack_step][0]; - context->payload[1] = id_list_h[context->attack_step][1]; - context->payload[2] = id_list_h[context->attack_step][2]; - - if(context->attack_step == 13) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_single_vibro); - } else { - context->attack_step++; - } - break; - } else { - context->payload[0] = id_list_hid[context->attack_step][0]; - context->payload[1] = id_list_hid[context->attack_step][1]; - context->payload[2] = id_list_hid[context->attack_step][2]; - context->payload[3] = id_list_hid[context->attack_step][3]; - context->payload[4] = id_list_hid[context->attack_step][4]; - context->payload[5] = id_list_hid[context->attack_step][5]; - - if(context->attack_step == 13) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_single_vibro); - - } else { - context->attack_step++; - } - break; - } - - case FlipFridAttackBfCustomerId: - if(context->proto == EM4100) { - context->payload[0] = context->attack_step; - context->payload[1] = 0x00; - context->payload[2] = 0x00; - context->payload[3] = 0x00; - context->payload[4] = 0x00; - - if(context->attack_step == 255) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_single_vibro); - } else { - context->attack_step++; - } - break; - } else if(context->proto == PAC) { - context->payload[0] = context->attack_step; - context->payload[1] = 0x00; - context->payload[2] = 0x00; - context->payload[3] = 0x00; - - if(context->attack_step == 255) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_single_vibro); - } else { - context->attack_step++; - } - break; - } else if(context->proto == H10301) { - context->payload[0] = context->attack_step; - context->payload[1] = 0x00; - context->payload[2] = 0x00; - - if(context->attack_step == 255) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_single_vibro); - } else { - context->attack_step++; - } - break; - } else { - context->payload[0] = context->attack_step; - context->payload[1] = 0x00; - context->payload[2] = 0x00; - context->payload[3] = 0x00; - context->payload[4] = 0x00; - context->payload[5] = 0x00; - - if(context->attack_step == 255) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_single_vibro); - } else { - context->attack_step++; - } - break; - } - - case FlipFridAttackLoadFile: - if(context->proto == EM4100) { - context->payload[0] = context->data[0]; - context->payload[1] = context->data[1]; - context->payload[2] = context->data[2]; - context->payload[3] = context->data[3]; - context->payload[4] = context->data[4]; - - context->payload[context->key_index] = context->attack_step; - - if(context->attack_step == 255) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_single_vibro); - break; - } else { - context->attack_step++; - } - break; - } else if(context->proto == PAC) { - context->payload[0] = context->data[0]; - context->payload[1] = context->data[1]; - context->payload[2] = context->data[2]; - context->payload[3] = context->data[3]; - - context->payload[context->key_index] = context->attack_step; - - if(context->attack_step == 255) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_single_vibro); - break; - } else { - context->attack_step++; - } - break; - } else if(context->proto == H10301) { - context->payload[0] = context->data[0]; - context->payload[1] = context->data[1]; - context->payload[2] = context->data[2]; - - context->payload[context->key_index] = context->attack_step; - - if(context->attack_step == 255) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_single_vibro); - break; - } else { - context->attack_step++; - } - break; - } else { - context->payload[0] = context->data[0]; - context->payload[1] = context->data[1]; - context->payload[2] = context->data[2]; - context->payload[3] = context->data[3]; - context->payload[4] = context->data[4]; - context->payload[5] = context->data[5]; - - context->payload[context->key_index] = context->attack_step; - - if(context->attack_step == 255) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_single_vibro); - break; - } else { - context->attack_step++; - } - break; - } - - case FlipFridAttackLoadFileCustomUids: - if(context->proto == EM4100) { - bool end_of_list = false; - while(true) { - furi_string_reset(context->data_str); - if(!stream_read_line(context->uids_stream, context->data_str)) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_single_vibro); - stream_rewind(context->uids_stream); - end_of_list = true; - break; - }; - if(furi_string_get_char(context->data_str, 0) == '#') continue; - if(furi_string_size(context->data_str) != 11) break; - break; - } - if(end_of_list) break; - FURI_LOG_D(TAG, furi_string_get_cstr(context->data_str)); - if(furi_string_size(context->data_str) != 11) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_error); - break; - }; - - // string is valid, parse it in context->payload - for(uint8_t i = 0; i < 5; i++) { - char temp_str[3]; - temp_str[0] = furi_string_get_cstr(context->data_str)[i * 2]; - temp_str[1] = furi_string_get_cstr(context->data_str)[i * 2 + 1]; - temp_str[2] = '\0'; - context->payload[i] = (uint8_t)strtol(temp_str, NULL, 16); - } - break; - } else if(context->proto == PAC) { - bool end_of_list = false; - while(true) { - furi_string_reset(context->data_str); - if(!stream_read_line(context->uids_stream, context->data_str)) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_single_vibro); - stream_rewind(context->uids_stream); - end_of_list = true; - break; - }; - if(furi_string_get_char(context->data_str, 0) == '#') continue; - if(furi_string_size(context->data_str) != 9) break; - break; - } - if(end_of_list) break; - FURI_LOG_D(TAG, furi_string_get_cstr(context->data_str)); - if(furi_string_size(context->data_str) != 9) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_error); - break; - }; - - // string is valid, parse it in context->payload - for(uint8_t i = 0; i < 4; i++) { - char temp_str[3]; - temp_str[0] = furi_string_get_cstr(context->data_str)[i * 2]; - temp_str[1] = furi_string_get_cstr(context->data_str)[i * 2 + 1]; - temp_str[2] = '\0'; - context->payload[i] = (uint8_t)strtol(temp_str, NULL, 16); - } - break; - } else if(context->proto == H10301) { - bool end_of_list = false; - while(true) { - furi_string_reset(context->data_str); - if(!stream_read_line(context->uids_stream, context->data_str)) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_single_vibro); - stream_rewind(context->uids_stream); - end_of_list = true; - break; - }; - if(furi_string_get_char(context->data_str, 0) == '#') continue; - if(furi_string_size(context->data_str) != 7) break; - break; - } - if(end_of_list) break; - FURI_LOG_D(TAG, furi_string_get_cstr(context->data_str)); - if(furi_string_size(context->data_str) != 7) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_error); - break; - }; - - // string is valid, parse it in context->payload - for(uint8_t i = 0; i < 3; i++) { - char temp_str[3]; - temp_str[0] = furi_string_get_cstr(context->data_str)[i * 2]; - temp_str[1] = furi_string_get_cstr(context->data_str)[i * 2 + 1]; - temp_str[2] = '\0'; - context->payload[i] = (uint8_t)strtol(temp_str, NULL, 16); - } - break; - } else { - bool end_of_list = false; - while(true) { - furi_string_reset(context->data_str); - if(!stream_read_line(context->uids_stream, context->data_str)) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_single_vibro); - stream_rewind(context->uids_stream); - end_of_list = true; - break; - }; - if(furi_string_get_char(context->data_str, 0) == '#') continue; - if(furi_string_size(context->data_str) != 13) break; - break; - } - FURI_LOG_D(TAG, furi_string_get_cstr(context->data_str)); - if(end_of_list) break; - if(furi_string_size(context->data_str) != 13) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_error); - break; - }; - - // string is valid, parse it in context->payload - for(uint8_t i = 0; i < 6; i++) { - char temp_str[3]; - temp_str[0] = furi_string_get_cstr(context->data_str)[i * 2]; - temp_str[1] = furi_string_get_cstr(context->data_str)[i * 2 + 1]; - temp_str[2] = '\0'; - context->payload[i] = (uint8_t)strtol(temp_str, NULL, 16); - } - break; - } - } - } - if(counter > context->time_between_cards) { - counter = 0; - } else { - counter++; - } - } -} - -void flipfrid_scene_run_attack_on_event(FlipFridEvent event, FlipFridState* context) { - if(event.evt_type == EventTypeKey) { - if(event.input_type == InputTypeShort) { - switch(event.key) { - case InputKeyDown: - break; - case InputKeyUp: - break; - case InputKeyLeft: - if(!context->is_attacking) { - if(context->time_between_cards > 5) { - context->time_between_cards--; - } - } - break; - case InputKeyRight: - if(!context->is_attacking) { - if(context->time_between_cards < 70) { - context->time_between_cards++; - } - } - break; - case InputKeyOk: - counter = 0; - if(!context->is_attacking) { - notification_message(context->notify, &sequence_blink_start_blue); - context->is_attacking = true; - } else { - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_single_vibro); - } - break; - case InputKeyBack: - context->is_attacking = false; - counter = 0; - - notification_message(context->notify, &sequence_blink_stop); - if(context->attack_stop_called) { - context->attack_stop_called = false; - context->attack_step = 0; - if(context->attack == FlipFridAttackLoadFileCustomUids) { - furi_string_reset(context->data_str); - stream_rewind(context->uids_stream); - buffered_file_stream_close(context->uids_stream); - } - - furi_string_reset(context->notification_msg); - context->current_scene = SceneEntryPoint; - } - - context->attack_stop_called = true; - break; - default: - break; - } - } - if(event.input_type == InputTypeLong) { - switch(event.key) { - case InputKeyLeft: - if(!context->is_attacking) { - if(context->time_between_cards > 0) { - if((context->time_between_cards - 10) > 5) { - context->time_between_cards -= 10; - } - } - } - break; - case InputKeyRight: - if(!context->is_attacking) { - if(context->time_between_cards < 70) { - context->time_between_cards += 10; - } - } - break; - default: - break; - } - } - } -} - -void flipfrid_scene_run_attack_on_draw(Canvas* canvas, FlipFridState* context) { - canvas_clear(canvas); - canvas_set_color(canvas, ColorBlack); - - // Frame - //canvas_draw_frame(canvas, 0, 0, 128, 64); - - // Title - canvas_set_font(canvas, FontPrimary); - canvas_draw_str_aligned( - canvas, 64, 2, AlignCenter, AlignTop, furi_string_get_cstr(context->attack_name)); - - char uid[18]; - char speed[16]; - if(context->proto == HIDProx) { - snprintf( - uid, - sizeof(uid), - "%02X:%02X:%02X:%02X:%02X:%02X", - context->payload[0], - context->payload[1], - context->payload[2], - context->payload[3], - context->payload[4], - context->payload[5]); - } else if(context->proto == PAC) { - snprintf( - uid, - sizeof(uid), - "%02X:%02X:%02X:%02X", - context->payload[0], - context->payload[1], - context->payload[2], - context->payload[3]); - } else if(context->proto == H10301) { - snprintf( - uid, - sizeof(uid), - "%02X:%02X:%02X", - context->payload[0], - context->payload[1], - context->payload[2]); - } else { - snprintf( - uid, - sizeof(uid), - "%02X:%02X:%02X:%02X:%02X", - context->payload[0], - context->payload[1], - context->payload[2], - context->payload[3], - context->payload[4]); - } - - canvas_draw_str_aligned(canvas, 64, 38, AlignCenter, AlignTop, uid); - - canvas_set_font(canvas, FontSecondary); - - canvas_draw_str_aligned( - canvas, 64, 26, AlignCenter, AlignTop, furi_string_get_cstr(context->proto_name)); - - snprintf(speed, sizeof(speed), "Time delay: %d", context->time_between_cards); - - //canvas_draw_str_aligned(canvas, 0, 22, AlignLeft, AlignTop, "Speed:"); - canvas_draw_str_aligned(canvas, 64, 14, AlignCenter, AlignTop, speed); - //char start_stop_msg[20]; - if(context->is_attacking) { - elements_button_center(canvas, "Stop"); - //snprintf(start_stop_msg, sizeof(start_stop_msg), " Press OK to stop "); - } else { - elements_button_center(canvas, "Start"); - elements_button_left(canvas, "TD -"); - elements_button_right(canvas, "+ TD"); - } - //canvas_draw_str_aligned(canvas, 64, 44, AlignCenter, AlignTop, start_stop_msg); -} diff --git a/applications/external/flipfrid/scene/flipfrid_scene_run_attack.h b/applications/external/flipfrid/scene/flipfrid_scene_run_attack.h deleted file mode 100644 index ae56d35e7..000000000 --- a/applications/external/flipfrid/scene/flipfrid_scene_run_attack.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once -#include "../flipfrid.h" - -void flipfrid_scene_run_attack_on_enter(FlipFridState* context); -void flipfrid_scene_run_attack_on_exit(FlipFridState* context); -void flipfrid_scene_run_attack_on_tick(FlipFridState* context); -void flipfrid_scene_run_attack_on_event(FlipFridEvent event, FlipFridState* context); -void flipfrid_scene_run_attack_on_draw(Canvas* canvas, FlipFridState* context); diff --git a/applications/external/flipfrid/scene/flipfrid_scene_select_field.c b/applications/external/flipfrid/scene/flipfrid_scene_select_field.c deleted file mode 100644 index ccb49e910..000000000 --- a/applications/external/flipfrid/scene/flipfrid_scene_select_field.c +++ /dev/null @@ -1,160 +0,0 @@ -#include "flipfrid_scene_select_field.h" - -void flipfrid_center_displayed_key(FlipFridState* context, uint8_t index) { - char key_cstr[18]; - uint8_t key_len = 18; - uint8_t str_index = (index * 3); - int data_len = sizeof(context->data) / sizeof(context->data[0]); - int key_index = 0; - - if(context->proto == EM4100) { - key_len = 16; - } - if(context->proto == PAC) { - key_len = 13; - } - if(context->proto == H10301) { - key_len = 10; - } - - for(uint8_t i = 0; i < data_len; i++) { - if(context->data[i] < 9) { - key_index += - snprintf(&key_cstr[key_index], key_len - key_index, "0%X ", context->data[i]); - } else { - key_index += - snprintf(&key_cstr[key_index], key_len - key_index, "%X ", context->data[i]); - } - } - - char display_menu[17] = { - 'X', 'X', ' ', 'X', 'X', ' ', '<', 'X', 'X', '>', ' ', 'X', 'X', ' ', 'X', 'X', '\0'}; - - if(index > 1) { - display_menu[0] = key_cstr[str_index - 6]; - display_menu[1] = key_cstr[str_index - 5]; - } else { - display_menu[0] = ' '; - display_menu[1] = ' '; - } - - if(index > 0) { - display_menu[3] = key_cstr[str_index - 3]; - display_menu[4] = key_cstr[str_index - 2]; - } else { - display_menu[3] = ' '; - display_menu[4] = ' '; - } - - display_menu[7] = key_cstr[str_index]; - display_menu[8] = key_cstr[str_index + 1]; - - if((str_index + 4) <= (uint8_t)strlen(key_cstr)) { - display_menu[11] = key_cstr[str_index + 3]; - display_menu[12] = key_cstr[str_index + 4]; - } else { - display_menu[11] = ' '; - display_menu[12] = ' '; - } - - if((str_index + 8) <= (uint8_t)strlen(key_cstr)) { - display_menu[14] = key_cstr[str_index + 6]; - display_menu[15] = key_cstr[str_index + 7]; - } else { - display_menu[14] = ' '; - display_menu[15] = ' '; - } - - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, display_menu); -} - -void flipfrid_scene_select_field_on_enter(FlipFridState* context) { - furi_string_reset(context->notification_msg); -} - -void flipfrid_scene_select_field_on_exit(FlipFridState* context) { - UNUSED(context); -} - -void flipfrid_scene_select_field_on_tick(FlipFridState* context) { - UNUSED(context); -} - -void flipfrid_scene_select_field_on_event(FlipFridEvent event, FlipFridState* context) { - if(event.evt_type == EventTypeKey) { - if(event.input_type == InputTypeShort) { - const char* key_cstr = furi_string_get_cstr(context->data_str); - int data_len = sizeof(context->data) / sizeof(context->data[0]); - - // don't look, it's ugly but I'm a python dev so... - uint8_t nb_bytes = 0; - for(uint8_t i = 0; i < strlen(key_cstr); i++) { - if(' ' == key_cstr[i]) { - nb_bytes++; - } - } - - switch(event.key) { - case InputKeyDown: - for(uint8_t i = 0; i < data_len; i++) { - if(context->key_index == i) { - context->data[i] = (context->data[i] - 1); - } - } - break; - case InputKeyUp: - for(uint8_t i = 0; i < data_len; i++) { - if(context->key_index == i) { - context->data[i] = (context->data[i] + 1); - } - } - break; - case InputKeyLeft: - if(context->key_index > 0) { - context->key_index = context->key_index - 1; - } - break; - case InputKeyRight: - if(context->key_index < nb_bytes) { - context->key_index = context->key_index + 1; - } - break; - case InputKeyOk: - furi_string_reset(context->notification_msg); - context->current_scene = SceneAttack; - break; - case InputKeyBack: - context->key_index = 0; - furi_string_reset(context->notification_msg); - context->current_scene = SceneSelectFile; - break; - default: - break; - } - FURI_LOG_D(TAG, "Position: %d/%d", context->key_index, nb_bytes); - } - } -} - -void flipfrid_scene_select_field_on_draw(Canvas* canvas, FlipFridState* context) { - canvas_clear(canvas); - canvas_set_color(canvas, ColorBlack); - - // Frame - //canvas_draw_frame(canvas, 0, 0, 128, 64); - - canvas_set_font(canvas, FontSecondary); - canvas_draw_str_aligned(canvas, 12, 5, AlignLeft, AlignTop, "Left and right: select byte"); - canvas_draw_str_aligned(canvas, 12, 15, AlignLeft, AlignTop, "Up and down: adjust byte"); - - char msg_index[18]; - canvas_set_font(canvas, FontPrimary); - snprintf(msg_index, sizeof(msg_index), "Field index : %d", context->key_index); - canvas_draw_str_aligned(canvas, 64, 30, AlignCenter, AlignTop, msg_index); - - flipfrid_center_displayed_key(context, context->key_index); - canvas_set_font(canvas, FontSecondary); - canvas_draw_str_aligned( - canvas, 64, 45, AlignCenter, AlignTop, furi_string_get_cstr(context->notification_msg)); -} diff --git a/applications/external/flipfrid/scene/flipfrid_scene_select_field.h b/applications/external/flipfrid/scene/flipfrid_scene_select_field.h deleted file mode 100644 index 5533e321c..000000000 --- a/applications/external/flipfrid/scene/flipfrid_scene_select_field.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include "../flipfrid.h" - -void flipfrid_scene_select_field_on_enter(FlipFridState* context); -void flipfrid_scene_select_field_on_exit(FlipFridState* context); -void flipfrid_scene_select_field_on_tick(FlipFridState* context); -void flipfrid_scene_select_field_on_event(FlipFridEvent event, FlipFridState* context); -void flipfrid_scene_select_field_on_draw(Canvas* canvas, FlipFridState* context); -void center_displayed_key(FlipFridState* context, uint8_t index); \ No newline at end of file diff --git a/applications/external/ibtn_fuzzer/LICENSE.md b/applications/external/ibtn_fuzzer/LICENSE.md deleted file mode 100644 index ba3b84456..000000000 --- a/applications/external/ibtn_fuzzer/LICENSE.md +++ /dev/null @@ -1,8 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * @xMasterX and @G4N4P4T1(made original version) wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. - * ---------------------------------------------------------------------------- - */ \ No newline at end of file diff --git a/applications/external/ibtn_fuzzer/application.fam b/applications/external/ibtn_fuzzer/application.fam deleted file mode 100644 index 87c02a913..000000000 --- a/applications/external/ibtn_fuzzer/application.fam +++ /dev/null @@ -1,12 +0,0 @@ -App( - appid="ibtn_fuzzer", - name="iButton Fuzzer", - apptype=FlipperAppType.EXTERNAL, - entry_point="ibtnfuzzer_start", - requires=["gui", "storage", "dialogs", "input", "notification"], - stack_size=1 * 1024, - order=15, - fap_icon="ibutt_10px.png", - fap_category="Tools", - fap_icon_assets="images", -) diff --git a/applications/external/ibtn_fuzzer/ibtnfuzzer.c b/applications/external/ibtn_fuzzer/ibtnfuzzer.c deleted file mode 100644 index 825a55560..000000000 --- a/applications/external/ibtn_fuzzer/ibtnfuzzer.c +++ /dev/null @@ -1,280 +0,0 @@ -#include "ibtnfuzzer.h" - -#include "scene/ibtnfuzzer_scene_entrypoint.h" -#include "scene/ibtnfuzzer_scene_load_file.h" -#include "scene/ibtnfuzzer_scene_select_field.h" -#include "scene/ibtnfuzzer_scene_run_attack.h" -#include "scene/ibtnfuzzer_scene_load_custom_uids.h" - -#define IBTNFUZZER_APP_FOLDER "/ext/ibtnfuzzer" - -static void ibtnfuzzer_draw_callback(Canvas* const canvas, void* ctx) { - furi_assert(ctx); - iBtnFuzzerState* ibtnfuzzer_state = ctx; - furi_mutex_acquire(ibtnfuzzer_state->mutex, FuriWaitForever); - - // Draw correct Canvas - switch(ibtnfuzzer_state->current_scene) { - case NoneScene: - case SceneEntryPoint: - ibtnfuzzer_scene_entrypoint_on_draw(canvas, ibtnfuzzer_state); - break; - case SceneSelectFile: - ibtnfuzzer_scene_load_file_on_draw(canvas, ibtnfuzzer_state); - break; - case SceneSelectField: - ibtnfuzzer_scene_select_field_on_draw(canvas, ibtnfuzzer_state); - break; - case SceneAttack: - ibtnfuzzer_scene_run_attack_on_draw(canvas, ibtnfuzzer_state); - break; - case SceneLoadCustomUids: - ibtnfuzzer_scene_load_custom_uids_on_draw(canvas, ibtnfuzzer_state); - break; - } - - furi_mutex_release(ibtnfuzzer_state->mutex); -} - -void ibtnfuzzer_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { - furi_assert(event_queue); - - iBtnFuzzerEvent event = { - .evt_type = EventTypeKey, .key = input_event->key, .input_type = input_event->type}; - furi_message_queue_put(event_queue, &event, 25); -} - -static void ibtnfuzzer_timer_callback(FuriMessageQueue* event_queue) { - furi_assert(event_queue); - iBtnFuzzerEvent event = { - .evt_type = EventTypeTick, .key = InputKeyUp, .input_type = InputTypeRelease}; - furi_message_queue_put(event_queue, &event, 25); -} - -iBtnFuzzerState* ibtnfuzzer_alloc() { - iBtnFuzzerState* ibtnfuzzer = malloc(sizeof(iBtnFuzzerState)); - ibtnfuzzer->notification_msg = furi_string_alloc(); - ibtnfuzzer->attack_name = furi_string_alloc(); - ibtnfuzzer->proto_name = furi_string_alloc(); - ibtnfuzzer->data_str = furi_string_alloc(); - - ibtnfuzzer->main_menu_items[0] = furi_string_alloc_set("Default Values"); - ibtnfuzzer->main_menu_items[1] = furi_string_alloc_set("Load File"); - ibtnfuzzer->main_menu_items[2] = furi_string_alloc_set("Load UIDs from file"); - - ibtnfuzzer->main_menu_proto_items[0] = furi_string_alloc_set("DS1990"); - ibtnfuzzer->main_menu_proto_items[1] = furi_string_alloc_set("Metakom"); - ibtnfuzzer->main_menu_proto_items[2] = furi_string_alloc_set("Cyfral"); - - ibtnfuzzer->previous_scene = NoneScene; - ibtnfuzzer->current_scene = SceneEntryPoint; - ibtnfuzzer->is_running = true; - ibtnfuzzer->is_attacking = false; - ibtnfuzzer->key_index = 0; - ibtnfuzzer->menu_index = 0; - ibtnfuzzer->menu_proto_index = 0; - - ibtnfuzzer->attack = iBtnFuzzerAttackDefaultValues; - ibtnfuzzer->notify = furi_record_open(RECORD_NOTIFICATION); - - ibtnfuzzer->data[0] = 0x00; - ibtnfuzzer->data[1] = 0x00; - ibtnfuzzer->data[2] = 0x00; - ibtnfuzzer->data[3] = 0x00; - ibtnfuzzer->data[4] = 0x00; - ibtnfuzzer->data[5] = 0x00; - ibtnfuzzer->data[6] = 0x00; - ibtnfuzzer->data[7] = 0x00; - - ibtnfuzzer->payload[0] = 0x00; - ibtnfuzzer->payload[1] = 0x00; - ibtnfuzzer->payload[2] = 0x00; - ibtnfuzzer->payload[3] = 0x00; - ibtnfuzzer->payload[4] = 0x00; - ibtnfuzzer->payload[5] = 0x00; - ibtnfuzzer->payload[6] = 0x00; - ibtnfuzzer->payload[7] = 0x00; - - //Dialog - ibtnfuzzer->dialogs = furi_record_open(RECORD_DIALOGS); - - return ibtnfuzzer; -} - -void ibtnfuzzer_free(iBtnFuzzerState* ibtnfuzzer) { - //Dialog - furi_record_close(RECORD_DIALOGS); - notification_message(ibtnfuzzer->notify, &sequence_blink_stop); - - // Strings - furi_string_free(ibtnfuzzer->notification_msg); - furi_string_free(ibtnfuzzer->attack_name); - furi_string_free(ibtnfuzzer->proto_name); - furi_string_free(ibtnfuzzer->data_str); - - for(uint32_t i = 0; i < 3; i++) { - furi_string_free(ibtnfuzzer->main_menu_items[i]); - } - - for(uint32_t i = 0; i < 3; i++) { - furi_string_free(ibtnfuzzer->main_menu_proto_items[i]); - } - - // The rest - free(ibtnfuzzer); -} - -// ENTRYPOINT -int32_t ibtnfuzzer_start(void* p) { - UNUSED(p); - // Input - FURI_LOG_I(TAG, "Initializing input"); - FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(iBtnFuzzerEvent)); - iBtnFuzzerState* ibtnfuzzer_state = ibtnfuzzer_alloc(); - - ibtnfuzzer_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal); - if(!ibtnfuzzer_state->mutex) { - FURI_LOG_E(TAG, "cannot create mutex\r\n"); - furi_message_queue_free(event_queue); - furi_record_close(RECORD_NOTIFICATION); - ibtnfuzzer_free(ibtnfuzzer_state); - return 255; - } - - Storage* storage = furi_record_open(RECORD_STORAGE); - if(!storage_simply_mkdir(storage, IBTNFUZZER_APP_FOLDER)) { - FURI_LOG_E(TAG, "Could not create folder %s", IBTNFUZZER_APP_FOLDER); - } - furi_record_close(RECORD_STORAGE); - - // Configure view port - FURI_LOG_I(TAG, "Initializing viewport"); - ViewPort* view_port = view_port_alloc(); - view_port_draw_callback_set(view_port, ibtnfuzzer_draw_callback, ibtnfuzzer_state); - view_port_input_callback_set(view_port, ibtnfuzzer_input_callback, event_queue); - - // Configure timer - FURI_LOG_I(TAG, "Initializing timer"); - FuriTimer* timer = - furi_timer_alloc(ibtnfuzzer_timer_callback, FuriTimerTypePeriodic, event_queue); - furi_timer_start(timer, furi_kernel_get_tick_frequency() / 10); // 10 times per second - - // Register view port in GUI - FURI_LOG_I(TAG, "Initializing gui"); - Gui* gui = (Gui*)furi_record_open(RECORD_GUI); - gui_add_view_port(gui, view_port, GuiLayerFullscreen); - - // Init values - iBtnFuzzerEvent event; - while(ibtnfuzzer_state->is_running) { - // Get next event - FuriStatus event_status = furi_message_queue_get(event_queue, &event, 25); - //furi_mutex_acquire(ibtnfuzzer_state->mutex, FuriWaitForever); - if(event_status == FuriStatusOk) { - if(event.evt_type == EventTypeKey) { - //Handle event key - switch(ibtnfuzzer_state->current_scene) { - case NoneScene: - case SceneEntryPoint: - ibtnfuzzer_scene_entrypoint_on_event(event, ibtnfuzzer_state); - break; - case SceneSelectFile: - ibtnfuzzer_scene_load_file_on_event(event, ibtnfuzzer_state); - break; - case SceneSelectField: - ibtnfuzzer_scene_select_field_on_event(event, ibtnfuzzer_state); - break; - case SceneAttack: - ibtnfuzzer_scene_run_attack_on_event(event, ibtnfuzzer_state); - break; - case SceneLoadCustomUids: - ibtnfuzzer_scene_load_custom_uids_on_event(event, ibtnfuzzer_state); - break; - } - - } else if(event.evt_type == EventTypeTick) { - //Handle event tick - if(ibtnfuzzer_state->current_scene != ibtnfuzzer_state->previous_scene) { - // Trigger Exit Scene - switch(ibtnfuzzer_state->previous_scene) { - case SceneEntryPoint: - ibtnfuzzer_scene_entrypoint_on_exit(ibtnfuzzer_state); - break; - case SceneSelectFile: - ibtnfuzzer_scene_load_file_on_exit(ibtnfuzzer_state); - break; - case SceneSelectField: - ibtnfuzzer_scene_select_field_on_exit(ibtnfuzzer_state); - break; - case SceneAttack: - ibtnfuzzer_scene_run_attack_on_exit(ibtnfuzzer_state); - break; - case SceneLoadCustomUids: - ibtnfuzzer_scene_load_custom_uids_on_exit(ibtnfuzzer_state); - break; - case NoneScene: - break; - } - - // Trigger Entry Scene - switch(ibtnfuzzer_state->current_scene) { - case NoneScene: - case SceneEntryPoint: - ibtnfuzzer_scene_entrypoint_on_enter(ibtnfuzzer_state); - break; - case SceneSelectFile: - ibtnfuzzer_scene_load_file_on_enter(ibtnfuzzer_state); - break; - case SceneSelectField: - ibtnfuzzer_scene_select_field_on_enter(ibtnfuzzer_state); - break; - case SceneAttack: - ibtnfuzzer_scene_run_attack_on_enter(ibtnfuzzer_state); - break; - case SceneLoadCustomUids: - ibtnfuzzer_scene_load_custom_uids_on_enter(ibtnfuzzer_state); - break; - } - ibtnfuzzer_state->previous_scene = ibtnfuzzer_state->current_scene; - } - - // Trigger Tick Scene - switch(ibtnfuzzer_state->current_scene) { - case NoneScene: - case SceneEntryPoint: - ibtnfuzzer_scene_entrypoint_on_tick(ibtnfuzzer_state); - break; - case SceneSelectFile: - ibtnfuzzer_scene_load_file_on_tick(ibtnfuzzer_state); - break; - case SceneSelectField: - ibtnfuzzer_scene_select_field_on_tick(ibtnfuzzer_state); - break; - case SceneAttack: - ibtnfuzzer_scene_run_attack_on_tick(ibtnfuzzer_state); - break; - case SceneLoadCustomUids: - ibtnfuzzer_scene_load_custom_uids_on_tick(ibtnfuzzer_state); - break; - } - view_port_update(view_port); - } - } - //furi_mutex_release(ibtnfuzzer_state->mutex); - } - - // Cleanup - furi_timer_stop(timer); - furi_timer_free(timer); - - FURI_LOG_I(TAG, "Cleaning up"); - gui_remove_view_port(gui, view_port); - view_port_free(view_port); - furi_message_queue_free(event_queue); - furi_record_close(RECORD_GUI); - furi_record_close(RECORD_NOTIFICATION); - furi_mutex_free(ibtnfuzzer_state->mutex); - ibtnfuzzer_free(ibtnfuzzer_state); - - return 0; -} \ No newline at end of file diff --git a/applications/external/ibtn_fuzzer/ibtnfuzzer.h b/applications/external/ibtn_fuzzer/ibtnfuzzer.h deleted file mode 100644 index 7a9e2b537..000000000 --- a/applications/external/ibtn_fuzzer/ibtnfuzzer.h +++ /dev/null @@ -1,94 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include - -#include -#include - -#define TAG "iBtnFuzzer" - -typedef enum { - iBtnFuzzerAttackDefaultValues, - iBtnFuzzerAttackLoadFile, - iBtnFuzzerAttackLoadFileCustomUids, -} iBtnFuzzerAttacks; - -typedef enum { - DS1990, - Metakom, - Cyfral, -} iBtnFuzzerProtos; - -typedef enum { - NoneScene, - SceneEntryPoint, - SceneSelectFile, - SceneSelectField, - SceneAttack, - SceneLoadCustomUids, -} iBtnFuzzerScene; - -typedef enum { - EventTypeTick, - EventTypeKey, -} EventType; - -typedef struct { - EventType evt_type; - InputKey key; - InputType input_type; -} iBtnFuzzerEvent; - -// STRUCTS -typedef struct { - FuriMutex* mutex; - bool is_running; - bool is_attacking; - iBtnFuzzerScene current_scene; - iBtnFuzzerScene previous_scene; - NotificationApp* notify; - u_int8_t menu_index; - u_int8_t menu_proto_index; - - FuriString* data_str; - uint8_t data[8]; - uint8_t payload[8]; - uint8_t attack_step; - iBtnFuzzerAttacks attack; - iBtnFuzzerProtos proto; - FuriString* attack_name; - FuriString* proto_name; - FuriString* main_menu_items[3]; - FuriString* main_menu_proto_items[3]; - - DialogsApp* dialogs; - FuriString* notification_msg; - uint8_t key_index; - iButtonWorker* worker; - iButtonKey* key; - iButtonProtocolId keytype; - iButtonProtocols* protocols; - bool workr_rund; - bool enter_rerun; - bool attack_stop_called; - - uint8_t time_between_cards; - - // Used for custom dictionnary - Stream* uids_stream; -} iBtnFuzzerState; \ No newline at end of file diff --git a/applications/external/ibtn_fuzzer/images/ibutt_10px.png b/applications/external/ibtn_fuzzer/images/ibutt_10px.png deleted file mode 100644 index 2fdaf123a657c00c9c84632ca3c151674e451ae1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 304 zcmeAS@N?(olHy`uVBq!ia0vp^AT}2xkYHHq`AGmsv7|ftIx;Y9?C1WI$O_~uBzpw; zGB8xBF)%c=FfjZA3N^f7U???UV0e|lz+g3lfkC`r&aOZkpafHrx4R1i<>&pI=m5)bW_|craZ$KesPZ!4!j_b)kjvx52z42i= z^Wk##wtdVzTiGS{99;2>!TC2M!yZeXz}?LkD}l;YOI#yLQW8s2t&)pUffR$0fsvuE zfvK*cNr<75m9c@9v4ysQft7*5`ikN&C>nC}Q!>*kp&E>VdO{3LtqcsU49p-Jly36? Qy~)7f>FVdQ&MBb@0C$~I0{{R3 diff --git a/applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_entrypoint.c b/applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_entrypoint.c deleted file mode 100644 index 1dd239c3b..000000000 --- a/applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_entrypoint.c +++ /dev/null @@ -1,201 +0,0 @@ -#include "ibtnfuzzer_scene_entrypoint.h" - -void ibtnfuzzer_scene_entrypoint_menu_callback( - iBtnFuzzerState* context, - uint32_t index, - uint32_t proto_index) { - switch(index) { - case iBtnFuzzerAttackDefaultValues: - context->attack = iBtnFuzzerAttackDefaultValues; - context->current_scene = SceneAttack; - furi_string_set(context->attack_name, "Default Values"); - break; - case iBtnFuzzerAttackLoadFile: - context->attack = iBtnFuzzerAttackLoadFile; - context->current_scene = SceneSelectFile; - furi_string_set(context->attack_name, "Load File"); - break; - case iBtnFuzzerAttackLoadFileCustomUids: - context->attack = iBtnFuzzerAttackLoadFileCustomUids; - context->current_scene = SceneLoadCustomUids; - furi_string_set(context->attack_name, "Load Custom UIDs"); - break; - default: - break; - } - - switch(proto_index) { - case DS1990: - context->proto = DS1990; - furi_string_set(context->proto_name, "DS1990"); - break; - case Metakom: - context->proto = Metakom; - furi_string_set(context->proto_name, "Metakom"); - break; - case Cyfral: - context->proto = Cyfral; - furi_string_set(context->proto_name, "Cyfral"); - break; - default: - break; - } -} - -void ibtnfuzzer_scene_entrypoint_on_enter(iBtnFuzzerState* context) { - // Clear the previous payload - context->payload[0] = 0x00; - context->payload[1] = 0x00; - context->payload[2] = 0x00; - context->payload[3] = 0x00; - context->payload[4] = 0x00; - context->payload[5] = 0x00; - context->payload[6] = 0x00; - context->payload[7] = 0x00; - - context->menu_index = 0; - /*for(uint32_t i = 0; i < 4; i++) { - menu_items[i] = furi_string_alloc(); - }*/ - - context->menu_proto_index = 0; - /*for(uint32_t i = 0; i < 4; i++) { - menu_proto_items[i] = furi_string_alloc(); - }*/ -} - -void ibtnfuzzer_scene_entrypoint_on_exit(iBtnFuzzerState* context) { - context->enter_rerun = false; -} - -void ibtnfuzzer_scene_entrypoint_on_tick(iBtnFuzzerState* context) { - UNUSED(context); -} - -void ibtnfuzzer_scene_entrypoint_on_event(iBtnFuzzerEvent event, iBtnFuzzerState* context) { - if(event.evt_type == EventTypeKey) { - if(event.input_type == InputTypeShort) { - switch(event.key) { - case InputKeyDown: - if(context->menu_index < iBtnFuzzerAttackLoadFileCustomUids) { - context->menu_index++; - } - break; - case InputKeyUp: - if(context->menu_index > iBtnFuzzerAttackDefaultValues) { - context->menu_index--; - } - break; - case InputKeyLeft: - if(context->menu_proto_index > DS1990) { - context->menu_proto_index--; - } else if(context->menu_proto_index == DS1990) { - context->menu_proto_index = Cyfral; - } - break; - case InputKeyRight: - if(context->menu_proto_index < Cyfral) { - context->menu_proto_index++; - } else if(context->menu_proto_index == Cyfral) { - context->menu_proto_index = DS1990; - } - break; - case InputKeyOk: - ibtnfuzzer_scene_entrypoint_menu_callback( - context, context->menu_index, context->menu_proto_index); - break; - case InputKeyBack: - context->is_running = false; - break; - default: - break; - } - } - } -} - -void ibtnfuzzer_scene_entrypoint_on_draw(Canvas* canvas, iBtnFuzzerState* context) { - if(!context->enter_rerun) { - ibtnfuzzer_scene_entrypoint_on_enter(context); - context->enter_rerun = true; - } - - canvas_clear(canvas); - canvas_set_color(canvas, ColorBlack); - - if(context->main_menu_items != NULL) { - if(context->main_menu_items[context->menu_index] != NULL) { - if(context->menu_index > iBtnFuzzerAttackDefaultValues) { - canvas_set_font(canvas, FontSecondary); - canvas_draw_str_aligned( - canvas, - 64, - 24, - AlignCenter, - AlignTop, - furi_string_get_cstr(context->main_menu_items[context->menu_index - 1])); - } - - canvas_set_font(canvas, FontPrimary); - canvas_draw_str_aligned( - canvas, - 64, - 36, - AlignCenter, - AlignTop, - furi_string_get_cstr(context->main_menu_items[context->menu_index])); - - if(context->menu_index < iBtnFuzzerAttackLoadFileCustomUids) { - canvas_set_font(canvas, FontSecondary); - canvas_draw_str_aligned( - canvas, - 64, - 48, - AlignCenter, - AlignTop, - furi_string_get_cstr(context->main_menu_items[context->menu_index + 1])); - } - - if(context->menu_proto_index > DS1990) { - canvas_set_font(canvas, FontSecondary); - canvas_draw_str_aligned( - canvas, - 64, - -12, - AlignCenter, - AlignTop, - furi_string_get_cstr( - context->main_menu_proto_items[context->menu_proto_index - 1])); - } - - canvas_set_font(canvas, FontPrimary); - canvas_draw_str_aligned(canvas, 27, 4, AlignCenter, AlignTop, "<"); - - canvas_set_font(canvas, FontPrimary); - if(context->main_menu_proto_items[context->menu_proto_index] != NULL) { - canvas_draw_str_aligned( - canvas, - 64, - 4, - AlignCenter, - AlignTop, - furi_string_get_cstr( - context->main_menu_proto_items[context->menu_proto_index])); - } - canvas_set_font(canvas, FontPrimary); - canvas_draw_str_aligned(canvas, 101, 4, AlignCenter, AlignTop, ">"); - - if(context->menu_proto_index < Cyfral) { - canvas_set_font(canvas, FontSecondary); - canvas_draw_str_aligned( - canvas, - 64, - -12, - AlignCenter, - AlignTop, - furi_string_get_cstr( - context->main_menu_proto_items[context->menu_proto_index + 1])); - } - } - } -} \ No newline at end of file diff --git a/applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_entrypoint.h b/applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_entrypoint.h deleted file mode 100644 index b77aec369..000000000 --- a/applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_entrypoint.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once -#include "../ibtnfuzzer.h" - -void ibtnfuzzer_scene_entrypoint_on_enter(iBtnFuzzerState* context); -void ibtnfuzzer_scene_entrypoint_on_exit(iBtnFuzzerState* context); -void ibtnfuzzer_scene_entrypoint_on_tick(iBtnFuzzerState* context); -void ibtnfuzzer_scene_entrypoint_on_event(iBtnFuzzerEvent event, iBtnFuzzerState* context); -void ibtnfuzzer_scene_entrypoint_on_draw(Canvas* canvas, iBtnFuzzerState* context); \ No newline at end of file diff --git a/applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_load_custom_uids.c b/applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_load_custom_uids.c deleted file mode 100644 index 07199ab46..000000000 --- a/applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_load_custom_uids.c +++ /dev/null @@ -1,86 +0,0 @@ -#include "ibtnfuzzer_scene_load_custom_uids.h" -#include "ibtnfuzzer_scene_run_attack.h" -#include "ibtnfuzzer_scene_entrypoint.h" - -#define IBTNFUZZER_UIDS_EXTENSION ".txt" -#define IBTNFUZZER_APP_PATH_FOLDER "/ext/ibtnfuzzer" - -bool ibtnfuzzer_load_uids(iBtnFuzzerState* context, const char* file_path) { - bool result = false; - Storage* storage = furi_record_open(RECORD_STORAGE); - context->uids_stream = buffered_file_stream_alloc(storage); - result = - buffered_file_stream_open(context->uids_stream, file_path, FSAM_READ, FSOM_OPEN_EXISTING); - // Close if loading fails - if(!result) { - buffered_file_stream_close(context->uids_stream); - return false; - } - return result; -} - -bool ibtnfuzzer_load_custom_uids_from_file(iBtnFuzzerState* context) { - // Input events and views are managed by file_select - FuriString* uid_path; - uid_path = furi_string_alloc(); - furi_string_set(uid_path, IBTNFUZZER_APP_PATH_FOLDER); - - DialogsFileBrowserOptions browser_options; - dialog_file_browser_set_basic_options( - &browser_options, IBTNFUZZER_UIDS_EXTENSION, &I_ibutt_10px); - browser_options.base_path = IBTNFUZZER_APP_PATH_FOLDER; - browser_options.hide_ext = false; - - bool res = dialog_file_browser_show(context->dialogs, uid_path, uid_path, &browser_options); - - if(res) { - res = ibtnfuzzer_load_uids(context, furi_string_get_cstr(uid_path)); - } - - furi_string_free(uid_path); - - return res; -} - -void ibtnfuzzer_scene_load_custom_uids_on_enter(iBtnFuzzerState* context) { - if(ibtnfuzzer_load_custom_uids_from_file(context)) { - // Force context loading - ibtnfuzzer_scene_run_attack_on_enter(context); - context->current_scene = SceneAttack; - } else { - ibtnfuzzer_scene_entrypoint_on_enter(context); - context->current_scene = SceneEntryPoint; - } -} - -void ibtnfuzzer_scene_load_custom_uids_on_exit(iBtnFuzzerState* context) { - UNUSED(context); -} - -void ibtnfuzzer_scene_load_custom_uids_on_tick(iBtnFuzzerState* context) { - UNUSED(context); -} - -void ibtnfuzzer_scene_load_custom_uids_on_event(iBtnFuzzerEvent event, iBtnFuzzerState* context) { - if(event.evt_type == EventTypeKey) { - if(event.input_type == InputTypeShort) { - switch(event.key) { - case InputKeyDown: - case InputKeyUp: - case InputKeyLeft: - case InputKeyRight: - case InputKeyOk: - case InputKeyBack: - context->current_scene = SceneEntryPoint; - break; - default: - break; - } - } - } -} - -void ibtnfuzzer_scene_load_custom_uids_on_draw(Canvas* canvas, iBtnFuzzerState* context) { - UNUSED(context); - UNUSED(canvas); -} diff --git a/applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_load_custom_uids.h b/applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_load_custom_uids.h deleted file mode 100644 index bb51c7079..000000000 --- a/applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_load_custom_uids.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include "../ibtnfuzzer.h" - -void ibtnfuzzer_scene_load_custom_uids_on_enter(iBtnFuzzerState* context); -void ibtnfuzzer_scene_load_custom_uids_on_exit(iBtnFuzzerState* context); -void ibtnfuzzer_scene_load_custom_uids_on_tick(iBtnFuzzerState* context); -void ibtnfuzzer_scene_load_custom_uids_on_event(iBtnFuzzerEvent event, iBtnFuzzerState* context); -void ibtnfuzzer_scene_load_custom_uids_on_draw(Canvas* canvas, iBtnFuzzerState* context); -bool ibtnfuzzer_load_custom_uids_from_file(iBtnFuzzerState* context); \ No newline at end of file diff --git a/applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_load_file.c b/applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_load_file.c deleted file mode 100644 index 92f79a424..000000000 --- a/applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_load_file.c +++ /dev/null @@ -1,293 +0,0 @@ -#include "ibtnfuzzer_scene_load_file.h" -#include "ibtnfuzzer_scene_entrypoint.h" - -#define IBUTTON_FUZZER_APP_EXTENSION ".ibtn" -#define IBUTTON_FUZZER_APP_PATH_FOLDER "/ext/ibutton" - -bool ibtnfuzzer_load(iBtnFuzzerState* context, const char* file_path) { - bool result = false; - Storage* storage = furi_record_open(RECORD_STORAGE); - FlipperFormat* fff_data_file = flipper_format_file_alloc(storage); - FuriString* temp_str; - temp_str = furi_string_alloc(); - bool key_v2 = false; - do { - if(!flipper_format_file_open_existing(fff_data_file, file_path)) { - FURI_LOG_E(TAG, "Error open file %s", file_path); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Error open file"); - break; - } - - // FileType - if(!flipper_format_read_string(fff_data_file, "Filetype", temp_str)) { - FURI_LOG_E(TAG, "Missing or incorrect Filetype"); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Missing or incorrect Filetypes"); - break; - } else { - FURI_LOG_I(TAG, "Filetype: %s", furi_string_get_cstr(temp_str)); - } - - // Key type - if(!flipper_format_read_string(fff_data_file, "Key type", temp_str)) { - FURI_LOG_E(TAG, "Missing or incorrect Key type, checking for typ2.."); - - if(!flipper_format_rewind(fff_data_file)) { - FURI_LOG_E(TAG, "Failed to rewind file"); - break; - } - if(!flipper_format_read_string(fff_data_file, "Protocol", temp_str)) { - furi_string_reset(context->notification_msg); - furi_string_set( - context->notification_msg, "Missing or incorrect Protocol or Key type"); - break; - } - FURI_LOG_I(TAG, "Key type V2: %s", furi_string_get_cstr(temp_str)); - key_v2 = true; - - if(context->proto == DS1990) { - if(strcmp(furi_string_get_cstr(temp_str), "DS1990") != 0) { - FURI_LOG_E(TAG, "Unsupported Key type"); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Unsupported Key type"); - break; - } - } else if(context->proto == Cyfral) { - if(strcmp(furi_string_get_cstr(temp_str), "Cyfral") != 0) { - FURI_LOG_E(TAG, "Unsupported Key type"); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Unsupported Key type"); - break; - } - } else { - if(strcmp(furi_string_get_cstr(temp_str), "Metakom") != 0) { - FURI_LOG_E(TAG, "Unsupported Key type"); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Unsupported Key type"); - break; - } - } - } else { - FURI_LOG_I(TAG, "Key type: %s", furi_string_get_cstr(temp_str)); - - if(context->proto == DS1990) { - if(strcmp(furi_string_get_cstr(temp_str), "Dallas") != 0) { - FURI_LOG_E(TAG, "Unsupported Key type"); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Unsupported Key type"); - break; - } - } else if(context->proto == Cyfral) { - if(strcmp(furi_string_get_cstr(temp_str), "Cyfral") != 0) { - FURI_LOG_E(TAG, "Unsupported Key type"); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Unsupported Key type"); - break; - } - } else { - if(strcmp(furi_string_get_cstr(temp_str), "Metakom") != 0) { - FURI_LOG_E(TAG, "Unsupported Key type"); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Unsupported Key type"); - break; - } - } - } - if(!key_v2) { - // Data - if(!flipper_format_read_string(fff_data_file, "Data", context->data_str)) { - FURI_LOG_E(TAG, "Missing or incorrect Data"); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Missing or incorrect Key"); - break; - } else { - FURI_LOG_I(TAG, "Key: %s", furi_string_get_cstr(context->data_str)); - - if(context->proto == DS1990) { - if(furi_string_size(context->data_str) != 23) { - FURI_LOG_E(TAG, "Incorrect Key length"); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Incorrect Key length"); - break; - } - } else if(context->proto == Cyfral) { - if(furi_string_size(context->data_str) != 5) { - FURI_LOG_E(TAG, "Incorrect Key length"); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Incorrect Key length"); - break; - } - } else { - if(furi_string_size(context->data_str) != 11) { - FURI_LOG_E(TAG, "Incorrect Key length"); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Incorrect Key length"); - break; - } - } - - // String to uint8_t - for(uint8_t i = 0; i < 8; i++) { - char temp_str2[3]; - temp_str2[0] = furi_string_get_cstr(context->data_str)[i * 3]; - temp_str2[1] = furi_string_get_cstr(context->data_str)[i * 3 + 1]; - temp_str2[2] = '\0'; - context->data[i] = (uint8_t)strtol(temp_str2, NULL, 16); - } - } - } else { - // Data - if(context->proto == DS1990) { - if(!flipper_format_read_string(fff_data_file, "Rom Data", context->data_str)) { - FURI_LOG_E(TAG, "Missing or incorrect Rom Data"); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Missing or incorrect Rom Data"); - break; - } else { - FURI_LOG_I(TAG, "Key: %s", furi_string_get_cstr(context->data_str)); - - if(furi_string_size(context->data_str) != 23) { - FURI_LOG_E(TAG, "Incorrect Key length"); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Incorrect Key length"); - break; - } - - // String to uint8_t - for(uint8_t i = 0; i < 8; i++) { - char temp_str2[3]; - temp_str2[0] = furi_string_get_cstr(context->data_str)[i * 3]; - temp_str2[1] = furi_string_get_cstr(context->data_str)[i * 3 + 1]; - temp_str2[2] = '\0'; - context->data[i] = (uint8_t)strtol(temp_str2, NULL, 16); - } - } - } else if(context->proto == Cyfral) { - if(!flipper_format_read_string(fff_data_file, "Data", context->data_str)) { - FURI_LOG_E(TAG, "Missing or incorrect Data"); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Missing or incorrect Data"); - break; - } else { - FURI_LOG_I(TAG, "Key: %s", furi_string_get_cstr(context->data_str)); - - if(furi_string_size(context->data_str) != 5) { - FURI_LOG_E(TAG, "Incorrect Key length"); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Incorrect Key length"); - break; - } - - // String to uint8_t - for(uint8_t i = 0; i < 8; i++) { - char temp_str2[3]; - temp_str2[0] = furi_string_get_cstr(context->data_str)[i * 3]; - temp_str2[1] = furi_string_get_cstr(context->data_str)[i * 3 + 1]; - temp_str2[2] = '\0'; - context->data[i] = (uint8_t)strtol(temp_str2, NULL, 16); - } - } - } else { - if(!flipper_format_read_string(fff_data_file, "Data", context->data_str)) { - FURI_LOG_E(TAG, "Missing or incorrect Data"); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Missing or incorrect Data"); - break; - } else { - FURI_LOG_I(TAG, "Key: %s", furi_string_get_cstr(context->data_str)); - - if(furi_string_size(context->data_str) != 11) { - FURI_LOG_E(TAG, "Incorrect Key length"); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Incorrect Key length"); - break; - } - - // String to uint8_t - for(uint8_t i = 0; i < 8; i++) { - char temp_str2[3]; - temp_str2[0] = furi_string_get_cstr(context->data_str)[i * 3]; - temp_str2[1] = furi_string_get_cstr(context->data_str)[i * 3 + 1]; - temp_str2[2] = '\0'; - context->data[i] = (uint8_t)strtol(temp_str2, NULL, 16); - } - } - } - } - - result = true; - } while(0); - furi_string_free(temp_str); - flipper_format_free(fff_data_file); - if(result) { - FURI_LOG_I(TAG, "Loaded successfully"); - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, "Source loaded."); - } - return result; -} - -void ibtnfuzzer_scene_load_file_on_enter(iBtnFuzzerState* context) { - if(ibtnfuzzer_load_protocol_from_file(context)) { - context->current_scene = SceneSelectField; - } else { - ibtnfuzzer_scene_entrypoint_on_enter(context); - context->current_scene = SceneEntryPoint; - } -} - -void ibtnfuzzer_scene_load_file_on_exit(iBtnFuzzerState* context) { - UNUSED(context); -} - -void ibtnfuzzer_scene_load_file_on_tick(iBtnFuzzerState* context) { - UNUSED(context); -} - -void ibtnfuzzer_scene_load_file_on_event(iBtnFuzzerEvent event, iBtnFuzzerState* context) { - if(event.evt_type == EventTypeKey) { - if(event.input_type == InputTypeShort) { - switch(event.key) { - case InputKeyDown: - case InputKeyUp: - case InputKeyLeft: - case InputKeyRight: - case InputKeyOk: - case InputKeyBack: - context->current_scene = SceneEntryPoint; - break; - default: - break; - } - } - } -} - -void ibtnfuzzer_scene_load_file_on_draw(Canvas* canvas, iBtnFuzzerState* context) { - UNUSED(context); - UNUSED(canvas); -} - -bool ibtnfuzzer_load_protocol_from_file(iBtnFuzzerState* context) { - FuriString* user_file_path; - user_file_path = furi_string_alloc(); - furi_string_set(user_file_path, IBUTTON_FUZZER_APP_PATH_FOLDER); - - DialogsFileBrowserOptions browser_options; - dialog_file_browser_set_basic_options( - &browser_options, IBUTTON_FUZZER_APP_EXTENSION, &I_ibutt_10px); - browser_options.base_path = IBUTTON_FUZZER_APP_PATH_FOLDER; - - // Input events and views are managed by file_select - bool res = dialog_file_browser_show( - context->dialogs, user_file_path, user_file_path, &browser_options); - - if(res) { - res = ibtnfuzzer_load(context, furi_string_get_cstr(user_file_path)); - } - - furi_string_free(user_file_path); - - return res; -} \ No newline at end of file diff --git a/applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_load_file.h b/applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_load_file.h deleted file mode 100644 index 34031d08c..000000000 --- a/applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_load_file.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include "../ibtnfuzzer.h" - -void ibtnfuzzer_scene_load_file_on_enter(iBtnFuzzerState* context); -void ibtnfuzzer_scene_load_file_on_exit(iBtnFuzzerState* context); -void ibtnfuzzer_scene_load_file_on_tick(iBtnFuzzerState* context); -void ibtnfuzzer_scene_load_file_on_event(iBtnFuzzerEvent event, iBtnFuzzerState* context); -void ibtnfuzzer_scene_load_file_on_draw(Canvas* canvas, iBtnFuzzerState* context); -bool ibtnfuzzer_load_protocol_from_file(iBtnFuzzerState* context); \ No newline at end of file diff --git a/applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_run_attack.c b/applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_run_attack.c deleted file mode 100644 index 13ec6e6be..000000000 --- a/applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_run_attack.c +++ /dev/null @@ -1,501 +0,0 @@ -#include "ibtnfuzzer_scene_run_attack.h" -#include - -uint8_t counter = 0; - -uint8_t id_list_ds1990[18][8] = { - {0x01, 0xBE, 0x40, 0x11, 0x5A, 0x36, 0x00, 0xE1}, //– код универсального ключа, для Vizit - {0x01, 0xBE, 0x40, 0x11, 0x5A, 0x56, 0x00, 0xBB}, //- проверен работает - {0x01, 0xBE, 0x40, 0x11, 0x00, 0x00, 0x00, 0x77}, //- проверен работает - {0x01, 0xBE, 0x40, 0x11, 0x0A, 0x00, 0x00, 0x1D}, //- проверен работает Визит иногда КЕЙМАНЫ - {0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x2F}, //- проверен(метаком, цифрал, ВИЗИТ). - {0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x9B}, //- проверен Визит, Метакомы, КОНДОР - {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x14}, //???-Открываает 98% Метаком и некоторые Цифрал - {0x01, 0x00, 0x00, 0x00, 0x00, 0x90, 0x19, 0xFF}, //???-Отлично работает на старых домофонах - {0x01, 0x6F, 0x2E, 0x88, 0x8A, 0x00, 0x00, 0x4D}, //???-Открывать что-то должен - {0x01, 0x53, 0xD4, 0xFE, 0x00, 0x00, 0x7E, 0x88}, //???-Cyfral, Metakom - {0x01, 0x53, 0xD4, 0xFE, 0x00, 0x00, 0x00, 0x6F}, //???-домофоны Визит (Vizit) - до 99% - {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3D}, //???-домофоны Cyfral CCD-20 - до 70% - {0x01, 0x00, 0xBE, 0x11, 0xAA, 0x00, 0x00, 0xFB}, //???-домофоны Кейман (KEYMAN) - {0x01, 0x76, 0xB8, 0x2E, 0x0F, 0x00, 0x00, 0x5C}, //???-домофоны Форвард - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Null bytes - {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x14}, // Only FF - {0x01, 0x78, 0x00, 0x48, 0xFD, 0xFF, 0xFF, 0xD1}, // StarNew Uni5 - {0x01, 0xA9, 0xE4, 0x3C, 0x09, 0x00, 0x00, 0xE6}, // Eltis Uni -}; - -uint8_t id_list_metakom[17][4] = { - {0x00, 0x00, 0x00, 0x00}, // Null bytes - {0xFF, 0xFF, 0xFF, 0xFF}, // Only FF - {0x11, 0x11, 0x11, 0x11}, // Only 11 - {0x22, 0x22, 0x22, 0x22}, // Only 22 - {0x33, 0x33, 0x33, 0x33}, // Only 33 - {0x44, 0x44, 0x44, 0x44}, // Only 44 - {0x55, 0x55, 0x55, 0x55}, // Only 55 - {0x66, 0x66, 0x66, 0x66}, // Only 66 - {0x77, 0x77, 0x77, 0x77}, // Only 77 - {0x88, 0x88, 0x88, 0x88}, // Only 88 - {0x99, 0x99, 0x99, 0x99}, // Only 99 - {0x12, 0x34, 0x56, 0x78}, // Incremental UID - {0x9A, 0x78, 0x56, 0x34}, // Decremental UID - {0x04, 0xd0, 0x9b, 0x0d}, // ?? - {0x34, 0x00, 0x29, 0x3d}, // ?? - {0x04, 0xdf, 0x00, 0x00}, // ?? - {0xCA, 0xCA, 0xCA, 0xCA}, // ?? -}; - -uint8_t id_list_cyfral[16][2] = { - {0x00, 0x00}, // Null bytes - {0xFF, 0xFF}, // Only FF - {0x11, 0x11}, // Only 11 - {0x22, 0x22}, // Only 22 - {0x33, 0x33}, // Only 33 - {0x44, 0x44}, // Only 44 - {0x55, 0x55}, // Only 55 - {0x66, 0x66}, // Only 66 - {0x77, 0x77}, // Only 77 - {0x88, 0x88}, // Only 88 - {0x99, 0x99}, // Only 99 - {0x12, 0x34}, // Incremental UID - {0x56, 0x34}, // Decremental UID - {0xCA, 0xCA}, // ?? - {0x8E, 0xC9}, // Elevator code - {0x6A, 0x50}, // VERY fresh code from smartkey -}; - -void ibtnfuzzer_scene_run_attack_on_enter(iBtnFuzzerState* context) { - context->time_between_cards = 8; - context->attack_step = 0; - context->attack_stop_called = false; - context->protocols = ibutton_protocols_alloc(); - context->key = ibutton_key_alloc(ibutton_protocols_get_max_data_size(context->protocols)); - context->worker = ibutton_worker_alloc(context->protocols); - if(context->proto == Metakom) { - context->keytype = ibutton_protocols_get_id_by_name(context->protocols, "Metakom"); - } else if(context->proto == Cyfral) { - context->keytype = ibutton_protocols_get_id_by_name(context->protocols, "Cyfral"); - } else { - context->keytype = ibutton_protocols_get_id_by_name(context->protocols, "DS1990"); - } - context->workr_rund = false; -} - -void ibtnfuzzer_scene_run_attack_on_exit(iBtnFuzzerState* context) { - if(context->workr_rund) { - ibutton_worker_stop(context->worker); - ibutton_worker_stop_thread(context->worker); - context->workr_rund = false; - } - ibutton_key_free(context->key); - ibutton_worker_free(context->worker); - ibutton_protocols_free(context->protocols); - notification_message(context->notify, &sequence_blink_stop); -} - -void ibtnfuzzer_scene_run_attack_on_tick(iBtnFuzzerState* context) { - if(context->is_attacking) { - if(1 == counter) { - ibutton_worker_start_thread(context->worker); - ibutton_key_set_protocol_id(context->key, context->keytype); - iButtonEditableData data; - ibutton_protocols_get_editable_data(context->protocols, context->key, &data); - data.size = sizeof(context->payload); - for(size_t i = 0; i < data.size; i++) { - data.ptr[i] = context->payload[i]; - } - - ibutton_worker_emulate_start(context->worker, context->key); - context->workr_rund = true; - } else if(0 == counter) { - if(context->workr_rund) { - ibutton_worker_stop(context->worker); - ibutton_worker_stop_thread(context->worker); - context->workr_rund = false; - furi_delay_ms(500); - } - switch(context->attack) { - case iBtnFuzzerAttackDefaultValues: - if(context->proto == DS1990) { - context->payload[0] = id_list_ds1990[context->attack_step][0]; - context->payload[1] = id_list_ds1990[context->attack_step][1]; - context->payload[2] = id_list_ds1990[context->attack_step][2]; - context->payload[3] = id_list_ds1990[context->attack_step][3]; - context->payload[4] = id_list_ds1990[context->attack_step][4]; - context->payload[5] = id_list_ds1990[context->attack_step][5]; - context->payload[6] = id_list_ds1990[context->attack_step][6]; - context->payload[7] = id_list_ds1990[context->attack_step][7]; - - if(context->attack_step == 17) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_single_vibro); - } else { - context->attack_step++; - } - break; - } else if(context->proto == Metakom) { - context->payload[0] = id_list_metakom[context->attack_step][0]; - context->payload[1] = id_list_metakom[context->attack_step][1]; - context->payload[2] = id_list_metakom[context->attack_step][2]; - context->payload[3] = id_list_metakom[context->attack_step][3]; - - if(context->attack_step == 16) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_single_vibro); - } else { - context->attack_step++; - } - break; - } else { - context->payload[0] = id_list_cyfral[context->attack_step][0]; - context->payload[1] = id_list_cyfral[context->attack_step][1]; - - if(context->attack_step == 15) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_single_vibro); - } else { - context->attack_step++; - } - break; - } - case iBtnFuzzerAttackLoadFile: - if(context->proto == DS1990) { - context->payload[0] = context->data[0]; - context->payload[1] = context->data[1]; - context->payload[2] = context->data[2]; - context->payload[3] = context->data[3]; - context->payload[4] = context->data[4]; - context->payload[5] = context->data[5]; - context->payload[6] = context->data[6]; - context->payload[7] = context->data[7]; - - context->payload[context->key_index] = context->attack_step; - - if(context->attack_step == 255) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_single_vibro); - break; - } else { - context->attack_step++; - } - break; - } else if(context->proto == Cyfral) { - context->payload[0] = context->data[0]; - context->payload[1] = context->data[1]; - - context->payload[context->key_index] = context->attack_step; - - if(context->attack_step == 255) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_single_vibro); - break; - } else { - context->attack_step++; - } - break; - } else { - context->payload[0] = context->data[0]; - context->payload[1] = context->data[1]; - context->payload[2] = context->data[2]; - context->payload[3] = context->data[3]; - - context->payload[context->key_index] = context->attack_step; - - if(context->attack_step == 255) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_single_vibro); - break; - } else { - context->attack_step++; - } - break; - } - - case iBtnFuzzerAttackLoadFileCustomUids: - if(context->proto == DS1990) { - bool end_of_list = false; - while(true) { - furi_string_reset(context->data_str); - if(!stream_read_line(context->uids_stream, context->data_str)) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_single_vibro); - stream_rewind(context->uids_stream); - end_of_list = true; - break; - }; - if(furi_string_get_char(context->data_str, 0) == '#') continue; - if(furi_string_size(context->data_str) != 17) break; - break; - } - if(end_of_list) break; - FURI_LOG_D(TAG, furi_string_get_cstr(context->data_str)); - if(furi_string_size(context->data_str) != 17) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_error); - break; - }; - - // string is valid, parse it in context->payload - for(uint8_t i = 0; i < 8; i++) { - char temp_str[3]; - temp_str[0] = furi_string_get_cstr(context->data_str)[i * 2]; - temp_str[1] = furi_string_get_cstr(context->data_str)[i * 2 + 1]; - temp_str[2] = '\0'; - context->payload[i] = (uint8_t)strtol(temp_str, NULL, 16); - } - break; - } else if(context->proto == Cyfral) { - bool end_of_list = false; - while(true) { - furi_string_reset(context->data_str); - if(!stream_read_line(context->uids_stream, context->data_str)) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_single_vibro); - stream_rewind(context->uids_stream); - end_of_list = true; - break; - }; - if(furi_string_get_char(context->data_str, 0) == '#') continue; - if(furi_string_size(context->data_str) != 5) break; - break; - } - if(end_of_list) break; - FURI_LOG_D(TAG, furi_string_get_cstr(context->data_str)); - if(furi_string_size(context->data_str) != 5) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_error); - break; - }; - - // string is valid, parse it in context->payload - for(uint8_t i = 0; i < 2; i++) { - char temp_str[3]; - temp_str[0] = furi_string_get_cstr(context->data_str)[i * 2]; - temp_str[1] = furi_string_get_cstr(context->data_str)[i * 2 + 1]; - temp_str[2] = '\0'; - context->payload[i] = (uint8_t)strtol(temp_str, NULL, 16); - } - break; - } else { - bool end_of_list = false; - while(true) { - furi_string_reset(context->data_str); - if(!stream_read_line(context->uids_stream, context->data_str)) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_single_vibro); - stream_rewind(context->uids_stream); - end_of_list = true; - break; - }; - if(furi_string_get_char(context->data_str, 0) == '#') continue; - if(furi_string_size(context->data_str) != 9) break; - break; - } - FURI_LOG_D(TAG, furi_string_get_cstr(context->data_str)); - if(end_of_list) break; - if(furi_string_size(context->data_str) != 9) { - context->attack_step = 0; - counter = 0; - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_error); - break; - }; - - // string is valid, parse it in context->payload - for(uint8_t i = 0; i < 4; i++) { - char temp_str[3]; - temp_str[0] = furi_string_get_cstr(context->data_str)[i * 2]; - temp_str[1] = furi_string_get_cstr(context->data_str)[i * 2 + 1]; - temp_str[2] = '\0'; - context->payload[i] = (uint8_t)strtol(temp_str, NULL, 16); - } - break; - } - } - } - - if(counter > context->time_between_cards) { - counter = 0; - } else { - counter++; - } - } -} - -void ibtnfuzzer_scene_run_attack_on_event(iBtnFuzzerEvent event, iBtnFuzzerState* context) { - if(event.evt_type == EventTypeKey) { - if(event.input_type == InputTypeShort) { - switch(event.key) { - case InputKeyDown: - break; - case InputKeyUp: - break; - case InputKeyLeft: - if(!context->is_attacking) { - if(context->time_between_cards > 4) { - context->time_between_cards--; - } - } - break; - case InputKeyRight: - if(!context->is_attacking) { - if(context->time_between_cards < 80) { - context->time_between_cards++; - } - } - break; - case InputKeyOk: - counter = 0; - if(!context->is_attacking) { - notification_message(context->notify, &sequence_blink_start_blue); - context->is_attacking = true; - } else { - context->is_attacking = false; - notification_message(context->notify, &sequence_blink_stop); - notification_message(context->notify, &sequence_single_vibro); - } - break; - case InputKeyBack: - context->is_attacking = false; - counter = 0; - - notification_message(context->notify, &sequence_blink_stop); - if(context->attack_stop_called) { - context->attack_stop_called = false; - context->attack_step = 0; - if(context->attack == iBtnFuzzerAttackLoadFileCustomUids) { - furi_string_reset(context->data_str); - stream_rewind(context->uids_stream); - buffered_file_stream_close(context->uids_stream); - } - - furi_string_reset(context->notification_msg); - context->current_scene = SceneEntryPoint; - } - - context->attack_stop_called = true; - break; - default: - break; - } - } - if(event.input_type == InputTypeLong) { - switch(event.key) { - case InputKeyLeft: - if(!context->is_attacking) { - if(context->time_between_cards > 4) { - if((context->time_between_cards - 10) > 4) { - context->time_between_cards -= 10; - } - } - } - break; - case InputKeyRight: - if(!context->is_attacking) { - if(context->time_between_cards < 80) { - context->time_between_cards += 10; - } - } - break; - default: - break; - } - } - } -} - -void ibtnfuzzer_scene_run_attack_on_draw(Canvas* canvas, iBtnFuzzerState* context) { - canvas_clear(canvas); - canvas_set_color(canvas, ColorBlack); - - // Frame - //canvas_draw_frame(canvas, 0, 0, 128, 64); - - // Title - canvas_set_font(canvas, FontPrimary); - canvas_draw_str_aligned( - canvas, 64, 2, AlignCenter, AlignTop, furi_string_get_cstr(context->attack_name)); - - char uid[25]; - char speed[16]; - if(context->proto == Metakom) { - snprintf( - uid, - sizeof(uid), - "%02X:%02X:%02X:%02X", - context->payload[0], - context->payload[1], - context->payload[2], - context->payload[3]); - } else if(context->proto == Cyfral) { - snprintf(uid, sizeof(uid), "%02X:%02X", context->payload[0], context->payload[1]); - } else { - snprintf( - uid, - sizeof(uid), - "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X", - context->payload[0], - context->payload[1], - context->payload[2], - context->payload[3], - context->payload[4], - context->payload[5], - context->payload[6], - context->payload[7]); - } - - canvas_draw_str_aligned(canvas, 64, 38, AlignCenter, AlignTop, uid); - - canvas_set_font(canvas, FontSecondary); - - canvas_draw_str_aligned( - canvas, 64, 26, AlignCenter, AlignTop, furi_string_get_cstr(context->proto_name)); - - snprintf(speed, sizeof(speed), "Time delay: %d", context->time_between_cards); - - //canvas_draw_str_aligned(canvas, 0, 22, AlignLeft, AlignTop, "Speed:"); - canvas_draw_str_aligned(canvas, 64, 14, AlignCenter, AlignTop, speed); - //char start_stop_msg[20]; - if(context->is_attacking) { - elements_button_center(canvas, "Stop"); - //snprintf(start_stop_msg, sizeof(start_stop_msg), " Press OK to stop "); - } else { - elements_button_center(canvas, "Start"); - elements_button_left(canvas, "TD -"); - elements_button_right(canvas, "+ TD"); - } - //canvas_draw_str_aligned(canvas, 64, 44, AlignCenter, AlignTop, start_stop_msg); -} diff --git a/applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_run_attack.h b/applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_run_attack.h deleted file mode 100644 index 9e44478f7..000000000 --- a/applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_run_attack.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once -#include "../ibtnfuzzer.h" - -void ibtnfuzzer_scene_run_attack_on_enter(iBtnFuzzerState* context); -void ibtnfuzzer_scene_run_attack_on_exit(iBtnFuzzerState* context); -void ibtnfuzzer_scene_run_attack_on_tick(iBtnFuzzerState* context); -void ibtnfuzzer_scene_run_attack_on_event(iBtnFuzzerEvent event, iBtnFuzzerState* context); -void ibtnfuzzer_scene_run_attack_on_draw(Canvas* canvas, iBtnFuzzerState* context); diff --git a/applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_select_field.c b/applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_select_field.c deleted file mode 100644 index f3217f65e..000000000 --- a/applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_select_field.c +++ /dev/null @@ -1,160 +0,0 @@ -#include "ibtnfuzzer_scene_select_field.h" - -void ibtnfuzzer_center_displayed_key(iBtnFuzzerState* context, uint8_t index) { - char key_cstr[25]; - uint8_t key_len = 25; - uint8_t str_index = (index * 3); - int data_len = sizeof(context->data) / sizeof(context->data[0]); - int key_index = 0; - - if(context->proto == DS1990) { - key_len = 25; - } - if(context->proto == Metakom) { - key_len = 13; - } - if(context->proto == Cyfral) { - key_len = 7; - } - - for(uint8_t i = 0; i < data_len; i++) { - if(context->data[i] < 9) { - key_index += - snprintf(&key_cstr[key_index], key_len - key_index, "0%X ", context->data[i]); - } else { - key_index += - snprintf(&key_cstr[key_index], key_len - key_index, "%X ", context->data[i]); - } - } - - char display_menu[17] = { - 'X', 'X', ' ', 'X', 'X', ' ', '<', 'X', 'X', '>', ' ', 'X', 'X', ' ', 'X', 'X', '\0'}; - - if(index > 1) { - display_menu[0] = key_cstr[str_index - 6]; - display_menu[1] = key_cstr[str_index - 5]; - } else { - display_menu[0] = ' '; - display_menu[1] = ' '; - } - - if(index > 0) { - display_menu[3] = key_cstr[str_index - 3]; - display_menu[4] = key_cstr[str_index - 2]; - } else { - display_menu[3] = ' '; - display_menu[4] = ' '; - } - - display_menu[7] = key_cstr[str_index]; - display_menu[8] = key_cstr[str_index + 1]; - - if((str_index + 4) <= (uint8_t)strlen(key_cstr)) { - display_menu[11] = key_cstr[str_index + 3]; - display_menu[12] = key_cstr[str_index + 4]; - } else { - display_menu[11] = ' '; - display_menu[12] = ' '; - } - - if((str_index + 8) <= (uint8_t)strlen(key_cstr)) { - display_menu[14] = key_cstr[str_index + 6]; - display_menu[15] = key_cstr[str_index + 7]; - } else { - display_menu[14] = ' '; - display_menu[15] = ' '; - } - - furi_string_reset(context->notification_msg); - furi_string_set(context->notification_msg, display_menu); -} - -void ibtnfuzzer_scene_select_field_on_enter(iBtnFuzzerState* context) { - furi_string_reset(context->notification_msg); -} - -void ibtnfuzzer_scene_select_field_on_exit(iBtnFuzzerState* context) { - UNUSED(context); -} - -void ibtnfuzzer_scene_select_field_on_tick(iBtnFuzzerState* context) { - UNUSED(context); -} - -void ibtnfuzzer_scene_select_field_on_event(iBtnFuzzerEvent event, iBtnFuzzerState* context) { - if(event.evt_type == EventTypeKey) { - if(event.input_type == InputTypeShort) { - const char* key_cstr = furi_string_get_cstr(context->data_str); - int data_len = sizeof(context->data) / sizeof(context->data[0]); - - // don't look, it's ugly but I'm a python dev so... - uint8_t nb_bytes = 0; - for(uint8_t i = 0; i < strlen(key_cstr); i++) { - if(' ' == key_cstr[i]) { - nb_bytes++; - } - } - - switch(event.key) { - case InputKeyDown: - for(uint8_t i = 0; i < data_len; i++) { - if(context->key_index == i) { - context->data[i] = (context->data[i] - 1); - } - } - break; - case InputKeyUp: - for(uint8_t i = 0; i < data_len; i++) { - if(context->key_index == i) { - context->data[i] = (context->data[i] + 1); - } - } - break; - case InputKeyLeft: - if(context->key_index > 0) { - context->key_index = context->key_index - 1; - } - break; - case InputKeyRight: - if(context->key_index < nb_bytes) { - context->key_index = context->key_index + 1; - } - break; - case InputKeyOk: - furi_string_reset(context->notification_msg); - context->current_scene = SceneAttack; - break; - case InputKeyBack: - context->key_index = 0; - furi_string_reset(context->notification_msg); - context->current_scene = SceneSelectFile; - break; - default: - break; - } - FURI_LOG_D(TAG, "Position: %d/%d", context->key_index, nb_bytes); - } - } -} - -void ibtnfuzzer_scene_select_field_on_draw(Canvas* canvas, iBtnFuzzerState* context) { - canvas_clear(canvas); - canvas_set_color(canvas, ColorBlack); - - // Frame - //canvas_draw_frame(canvas, 0, 0, 128, 64); - - canvas_set_font(canvas, FontSecondary); - canvas_draw_str_aligned(canvas, 12, 5, AlignLeft, AlignTop, "Left and right: select byte"); - canvas_draw_str_aligned(canvas, 12, 15, AlignLeft, AlignTop, "Up and down: adjust byte"); - - char msg_index[18]; - canvas_set_font(canvas, FontPrimary); - snprintf(msg_index, sizeof(msg_index), "Field index : %d", context->key_index); - canvas_draw_str_aligned(canvas, 64, 30, AlignCenter, AlignTop, msg_index); - - ibtnfuzzer_center_displayed_key(context, context->key_index); - canvas_set_font(canvas, FontSecondary); - canvas_draw_str_aligned( - canvas, 64, 45, AlignCenter, AlignTop, furi_string_get_cstr(context->notification_msg)); -} diff --git a/applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_select_field.h b/applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_select_field.h deleted file mode 100644 index b6c684c3b..000000000 --- a/applications/external/ibtn_fuzzer/scene/ibtnfuzzer_scene_select_field.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include "../ibtnfuzzer.h" - -void ibtnfuzzer_scene_select_field_on_enter(iBtnFuzzerState* context); -void ibtnfuzzer_scene_select_field_on_exit(iBtnFuzzerState* context); -void ibtnfuzzer_scene_select_field_on_tick(iBtnFuzzerState* context); -void ibtnfuzzer_scene_select_field_on_event(iBtnFuzzerEvent event, iBtnFuzzerState* context); -void ibtnfuzzer_scene_select_field_on_draw(Canvas* canvas, iBtnFuzzerState* context); -void center_displayed_key(iBtnFuzzerState* context, uint8_t index); \ No newline at end of file diff --git a/applications/external/pacs_fuzzer/application.fam b/applications/external/multi_fuzzer/application.fam similarity index 81% rename from applications/external/pacs_fuzzer/application.fam rename to applications/external/multi_fuzzer/application.fam index 6098322ac..a0ce1be0a 100644 --- a/applications/external/pacs_fuzzer/application.fam +++ b/applications/external/multi_fuzzer/application.fam @@ -1,6 +1,6 @@ App( - appid="pacs_fuzzer_ibtn", - name="iButton Fuzzer [B]", + appid="fuzzer_ibtn", + name="iButton Fuzzer", apptype=FlipperAppType.EXTERNAL, entry_point="fuzzer_start_ibtn", requires=[ @@ -11,8 +11,8 @@ App( "notification", ], stack_size=2 * 1024, - fap_icon="icons/rfid_10px.png", - fap_category="Debug", + fap_icon="icons/ibutt_10px.png", + fap_category="Tools", fap_private_libs=[ Lib( name="worker", @@ -24,8 +24,8 @@ App( ) App( - appid="pacs_fuzzer_rfid", - name="RFID Fuzzer [B]", + appid="fuzzer_rfid", + name="RFID Fuzzer", apptype=FlipperAppType.EXTERNAL, entry_point="fuzzer_start_rfid", requires=[ @@ -36,8 +36,8 @@ App( "notification", ], stack_size=2 * 1024, - fap_icon="icons/125_10px.png", - fap_category="Debug", + fap_icon="icons/rfid_10px.png", + fap_category="Tools", fap_private_libs=[ Lib( name="worker", diff --git a/applications/external/pacs_fuzzer/fuzzer.c b/applications/external/multi_fuzzer/fuzzer.c similarity index 100% rename from applications/external/pacs_fuzzer/fuzzer.c rename to applications/external/multi_fuzzer/fuzzer.c diff --git a/applications/external/pacs_fuzzer/fuzzer_i.h b/applications/external/multi_fuzzer/fuzzer_i.h similarity index 100% rename from applications/external/pacs_fuzzer/fuzzer_i.h rename to applications/external/multi_fuzzer/fuzzer_i.h diff --git a/applications/external/pacs_fuzzer/helpers/fuzzer_custom_event.h b/applications/external/multi_fuzzer/helpers/fuzzer_custom_event.h similarity index 100% rename from applications/external/pacs_fuzzer/helpers/fuzzer_custom_event.h rename to applications/external/multi_fuzzer/helpers/fuzzer_custom_event.h diff --git a/applications/external/pacs_fuzzer/helpers/fuzzer_types.h b/applications/external/multi_fuzzer/helpers/fuzzer_types.h similarity index 100% rename from applications/external/pacs_fuzzer/helpers/fuzzer_types.h rename to applications/external/multi_fuzzer/helpers/fuzzer_types.h diff --git a/applications/external/flipfrid/images/125_10px.png b/applications/external/multi_fuzzer/icons/125_10px.png similarity index 100% rename from applications/external/flipfrid/images/125_10px.png rename to applications/external/multi_fuzzer/icons/125_10px.png diff --git a/applications/external/pacs_fuzzer/icons/ButtonLeft_4x7.png b/applications/external/multi_fuzzer/icons/ButtonLeft_4x7.png similarity index 100% rename from applications/external/pacs_fuzzer/icons/ButtonLeft_4x7.png rename to applications/external/multi_fuzzer/icons/ButtonLeft_4x7.png diff --git a/applications/external/pacs_fuzzer/icons/ButtonRight_4x7.png b/applications/external/multi_fuzzer/icons/ButtonRight_4x7.png similarity index 100% rename from applications/external/pacs_fuzzer/icons/ButtonRight_4x7.png rename to applications/external/multi_fuzzer/icons/ButtonRight_4x7.png diff --git a/applications/external/pacs_fuzzer/icons/Ok_btn_9x9.png b/applications/external/multi_fuzzer/icons/Ok_btn_9x9.png similarity index 100% rename from applications/external/pacs_fuzzer/icons/Ok_btn_9x9.png rename to applications/external/multi_fuzzer/icons/Ok_btn_9x9.png diff --git a/applications/external/pacs_fuzzer/icons/Pin_arrow_up_7x9.png b/applications/external/multi_fuzzer/icons/Pin_arrow_up_7x9.png similarity index 100% rename from applications/external/pacs_fuzzer/icons/Pin_arrow_up_7x9.png rename to applications/external/multi_fuzzer/icons/Pin_arrow_up_7x9.png diff --git a/applications/external/pacs_fuzzer/icons/Pin_back_arrow_10x8.png b/applications/external/multi_fuzzer/icons/Pin_back_arrow_10x8.png similarity index 100% rename from applications/external/pacs_fuzzer/icons/Pin_back_arrow_10x8.png rename to applications/external/multi_fuzzer/icons/Pin_back_arrow_10x8.png diff --git a/applications/external/ibtn_fuzzer/ibutt_10px.png b/applications/external/multi_fuzzer/icons/ibutt_10px.png similarity index 100% rename from applications/external/ibtn_fuzzer/ibutt_10px.png rename to applications/external/multi_fuzzer/icons/ibutt_10px.png diff --git a/applications/external/flipfrid/rfid_10px.png b/applications/external/multi_fuzzer/icons/rfid_10px.png similarity index 100% rename from applications/external/flipfrid/rfid_10px.png rename to applications/external/multi_fuzzer/icons/rfid_10px.png diff --git a/applications/external/pacs_fuzzer/lib/worker/fake_worker.c b/applications/external/multi_fuzzer/lib/worker/fake_worker.c similarity index 100% rename from applications/external/pacs_fuzzer/lib/worker/fake_worker.c rename to applications/external/multi_fuzzer/lib/worker/fake_worker.c diff --git a/applications/external/pacs_fuzzer/lib/worker/fake_worker.h b/applications/external/multi_fuzzer/lib/worker/fake_worker.h similarity index 100% rename from applications/external/pacs_fuzzer/lib/worker/fake_worker.h rename to applications/external/multi_fuzzer/lib/worker/fake_worker.h diff --git a/applications/external/pacs_fuzzer/lib/worker/protocol.c b/applications/external/multi_fuzzer/lib/worker/protocol.c similarity index 100% rename from applications/external/pacs_fuzzer/lib/worker/protocol.c rename to applications/external/multi_fuzzer/lib/worker/protocol.c diff --git a/applications/external/pacs_fuzzer/lib/worker/protocol.h b/applications/external/multi_fuzzer/lib/worker/protocol.h similarity index 100% rename from applications/external/pacs_fuzzer/lib/worker/protocol.h rename to applications/external/multi_fuzzer/lib/worker/protocol.h diff --git a/applications/external/pacs_fuzzer/lib/worker/protocol_i.h b/applications/external/multi_fuzzer/lib/worker/protocol_i.h similarity index 100% rename from applications/external/pacs_fuzzer/lib/worker/protocol_i.h rename to applications/external/multi_fuzzer/lib/worker/protocol_i.h diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene.c b/applications/external/multi_fuzzer/scenes/fuzzer_scene.c similarity index 100% rename from applications/external/pacs_fuzzer/scenes/fuzzer_scene.c rename to applications/external/multi_fuzzer/scenes/fuzzer_scene.c diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene.h b/applications/external/multi_fuzzer/scenes/fuzzer_scene.h similarity index 100% rename from applications/external/pacs_fuzzer/scenes/fuzzer_scene.h rename to applications/external/multi_fuzzer/scenes/fuzzer_scene.h diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c b/applications/external/multi_fuzzer/scenes/fuzzer_scene_attack.c similarity index 100% rename from applications/external/pacs_fuzzer/scenes/fuzzer_scene_attack.c rename to applications/external/multi_fuzzer/scenes/fuzzer_scene_attack.c diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_config.h b/applications/external/multi_fuzzer/scenes/fuzzer_scene_config.h similarity index 100% rename from applications/external/pacs_fuzzer/scenes/fuzzer_scene_config.h rename to applications/external/multi_fuzzer/scenes/fuzzer_scene_config.h diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_field_editor.c b/applications/external/multi_fuzzer/scenes/fuzzer_scene_field_editor.c similarity index 100% rename from applications/external/pacs_fuzzer/scenes/fuzzer_scene_field_editor.c rename to applications/external/multi_fuzzer/scenes/fuzzer_scene_field_editor.c diff --git a/applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c b/applications/external/multi_fuzzer/scenes/fuzzer_scene_main.c similarity index 100% rename from applications/external/pacs_fuzzer/scenes/fuzzer_scene_main.c rename to applications/external/multi_fuzzer/scenes/fuzzer_scene_main.c diff --git a/applications/external/pacs_fuzzer/todo.md b/applications/external/multi_fuzzer/todo.md similarity index 100% rename from applications/external/pacs_fuzzer/todo.md rename to applications/external/multi_fuzzer/todo.md diff --git a/applications/external/pacs_fuzzer/views/attack.c b/applications/external/multi_fuzzer/views/attack.c similarity index 100% rename from applications/external/pacs_fuzzer/views/attack.c rename to applications/external/multi_fuzzer/views/attack.c diff --git a/applications/external/pacs_fuzzer/views/attack.h b/applications/external/multi_fuzzer/views/attack.h similarity index 100% rename from applications/external/pacs_fuzzer/views/attack.h rename to applications/external/multi_fuzzer/views/attack.h diff --git a/applications/external/pacs_fuzzer/views/field_editor.c b/applications/external/multi_fuzzer/views/field_editor.c similarity index 100% rename from applications/external/pacs_fuzzer/views/field_editor.c rename to applications/external/multi_fuzzer/views/field_editor.c diff --git a/applications/external/pacs_fuzzer/views/field_editor.h b/applications/external/multi_fuzzer/views/field_editor.h similarity index 100% rename from applications/external/pacs_fuzzer/views/field_editor.h rename to applications/external/multi_fuzzer/views/field_editor.h diff --git a/applications/external/pacs_fuzzer/views/main_menu.c b/applications/external/multi_fuzzer/views/main_menu.c similarity index 100% rename from applications/external/pacs_fuzzer/views/main_menu.c rename to applications/external/multi_fuzzer/views/main_menu.c diff --git a/applications/external/pacs_fuzzer/views/main_menu.h b/applications/external/multi_fuzzer/views/main_menu.h similarity index 100% rename from applications/external/pacs_fuzzer/views/main_menu.h rename to applications/external/multi_fuzzer/views/main_menu.h diff --git a/applications/external/pacs_fuzzer/icons/125_10px.png b/applications/external/pacs_fuzzer/icons/125_10px.png deleted file mode 100644 index ce01284a2c1f3eb413f581b84f1fb3f3a2a7223b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 308 zcmeAS@N?(olHy`uVBq!ia0vp^AT}2xkYHHq`AGmsv7|ftIx;Y9?C1WI$O_~uBzpw; zGB8xBF)%c=FfjZA3N^f7U???UV0e|lz+g3lfkC`r&aOZkpafHrx4R1i<>&pI=m5)bWZjP>yH&963)5S4_<9hOs!iI<>&pI=m5)bW_|craZ$KesPZ!4!j_b)kjvx52z42i= z^Wk##wtdVzTiGS{99;2>!TC2M!yZeXz}?LkD}l;YOI#yLQW8s2t&)pUffR$0fsvuE zfvK*cNr<75m9c@9v4ysQft7*5`ikN&C>nC}Q!>*kp&E>VdO{3LtqcsU49p-Jly36? Qy~)7f>FVdQ&MBb@0C$~I0{{R3 diff --git a/applications/external/pacs_fuzzer/icons/rfid_10px.png b/applications/external/pacs_fuzzer/icons/rfid_10px.png deleted file mode 100644 index 8097f477552333f695733baf98f72e52ae840206..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2389 zcmcIleQXnD7{6^!#>U44<0gnZixCj6_tCqycdm@C?Y2%j%BZlR1g>}Qb?4f<$dYAbBp?=L>s9H44zi+G=z@ z$+GSR2r_^Bu5APL?}u;SJTN7D;oJYQXJbzy83Gd~}8wyVLJ?VRDO5w9Zzw8@g?;6Z|IeLEIrsbQiG#zUHZ2RGh zXD*aUd-8i4_PpADs0}HdxBi3jq2Z#Q^P&Dr^r?|WO%j;%cM#(P)0|Mc8; z{t8g`*A^{V)i?clE}f@2H&CjT}F< z?2jues!qd7PS)z04FoBfX?^mLy)Tp_$Rt&cG?`7IrJSH9?7UT9dorQHXauRON@~2& z3QRN#VzT0~4fhY&P+9cYRxu$Wr1?OLT-T+86?9@-1c8#I)9z+Pr-LUJp%g)pI7#A^ z8>2{$U^#~a&AepaJ-|V!`|Vrt9lHFc42XX!YK-a5tz}b zn0yjbjJa6^KQIJc)=XJdPz#Zds%@sn2DzpWkAYyf`V1Rfhy zjlu{PBk2f5aSnoGTnh;YM-b`I5OjjboBR#IOoSjf8osX&Rz+FroJeRW#03?@@6WtU}<<5`k-GmIOPTuus$(zJDPkQf=2B!Xdi7eP5vyx@MnDzsUZu=b~oE2;v- z$W@bzGC*KNw}3fBr-TVK?Z%=6L1S(pkqisLNim1EOqXHr@bS^87Ap}ViVmI>S)RcJ zh9WV*(*TPy(I`d}G$F90;3Qy6q1W>I)VQjLR1sDe;)?<&sd|Ek{*e=W4B(m)v)l~P z;VJ5514`GK>5mm)eP$Jx(Uj>pUa-9Gu?d#Q0Om>GmdB{x#CWFnceDTqI*$11FhiBh z4qgY|7_9WanhU=fd4q2spSnP~C5On1n8Y&u^S%9C@(-&evej?~Ro2+Su!z(GxDJJ~1-%>yfuE?__2!EG(Q-w?lmFd+!g0U&StM zdu5hu`a91J8fzAOad#fF`0WbM%BH;qRp;*CJ^0}3t1p(6l^kTQe)IdHQfq1l0}cMe I)$5-48`f?Vpa1{> From 98e0f5a8f6552c02dae3e4964cd721f17be0aa9d Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Thu, 8 Jun 2023 02:59:59 +0300 Subject: [PATCH 30/31] Update docs --- ReadMe.md | 2 +- documentation/SubGHzRemoteProg.md | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/ReadMe.md b/ReadMe.md index f9e759e0b..0c545682c 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -96,7 +96,7 @@ Encoders or sending made by @Eng1n33r(first implementation in Q2 2022) & @xMaste - CAME Atomo -> Update! check out new [instructions](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/SubGHzRemoteProg.md) - Nice Flor S -> How to create new remote - [instructions](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/SubGHzRemoteProg.md) - FAAC SLH (Spa) [External seed calculation required (For info contact me in Discord: Nano#8998)] -- Keeloq: BFT Mitto [External seed calculation required (For info contact me in Discord: Nano#8998)] -> Update! check out new [instructions](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/SubGHzRemoteProg.md) +- Keeloq: BFT Mitto -> Update! check out new [instructions](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/SubGHzRemoteProg.md) - Star Line - Security+ v1 & v2 (encoders was made in OFW) diff --git a/documentation/SubGHzRemoteProg.md b/documentation/SubGHzRemoteProg.md index 7cd8ea68a..e53319b2f 100644 --- a/documentation/SubGHzRemoteProg.md +++ b/documentation/SubGHzRemoteProg.md @@ -60,6 +60,8 @@ Watch this videos to learn more (videos in Russian language): https://www.youtub ## BFT Mitto +How to create new remote and bind it to receiver (will not conflict with original remotes): + 1. Create new remote with randomly generated serial: Go to SubGHz -> Add Manually -> BFT Mitto 433Mhz 2. Open your new remote file 3. You need to be in minimum 3 meters to receiver @@ -68,6 +70,32 @@ Watch this videos to learn more (videos in Russian language): https://www.youtub 6. Long press (Right Arrow) - (0xF button - Btn:F) on Flipper for like 3-5 sec 7. Done? +OR + +1. Create new remote with randomly generated serial: Go to SubGHz -> Add Manually -> BFT Mitto 433Mhz +2. Open your new remote file +3. Open your receiver board box +4. **Watch this video**: https://www.youtube.com/watch?v=5QXMBKI_-Ls +5. Long press (Right Arrow) - (0xF button - Btn:F) on Flipper for like 3-5 sec -> Will act like holding Button 1 & 2 on original remote as shown on video +6. Done? + +-- + +How to get seed to make full clone of your remote (**will conflict with original remote!!!!!**): + +**WARNING!!!! This method can desync your original remote, please avoid using it! It can be used in rare cases like when your remote works poorly or has broken buttons and you want to replace it with flipper** + +1. Open `Read` in SubGHz on your flipper +2. (ONLY FOR ORIGINAL REMOTES) Hold all buttons on your remote at same time, example -> for 2 button remote - press them both at same time and hold OR press hidden button on back of remote with a pin or paper clip +3. You will receive signal on your flipper, open that signal and see `Fix:` value, it should start from `F` like `F00F1C9B` +4. If `Fix:` is showing first `F` see `Hop:` value -> This is your remote Seed +5. Write down Hop value +6. Press button on your remote that you want to clone and receive its signal on your flipper +7. Open and write down `Fix:` value where first digit will be same as your button ID `Btn:` +8. Create new remote using BFT Mitto [Manual] - Enter FIX from step 7, enter counter `FF F9`, enter seed from step 5 +9. Using counter values like `FF F9` can help bypassing current original remote counter value, and in result it also can fully desync original remote, only one remote can work at same time using this method +10. Throw away your original remote since now it needs to be re-added into receiver board :C + ## CAME Atomo 1. Use google to find instructions - `how to program new CAME Atomo remote into receiver` From 5496fa29584e1882c4563966698e01c5a1b9a680 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Thu, 8 Jun 2023 03:00:53 +0300 Subject: [PATCH 31/31] upd anims --- .ci_files/anims_ofw.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.ci_files/anims_ofw.txt b/.ci_files/anims_ofw.txt index 4fa369f82..e3d3314c0 100644 --- a/.ci_files/anims_ofw.txt +++ b/.ci_files/anims_ofw.txt @@ -120,6 +120,13 @@ Min level: 2 Max level: 2 Weight: 3 +Name: L2_Dj_128x64 +Min butthurt: 0 +Max butthurt: 8 +Min level: 2 +Max level: 3 +Weight: 4 + Name: L3_Furippa3_128x64 Min butthurt: 0 Max butthurt: 6