Bläddra i källkod

Add em4100_generator from https://github.com/Milk-Cool/fz-em4100-generator

git-subtree-dir: em4100_generator
git-subtree-mainline: 33e6799f3022324d1f651797e91e0c3f3f7afcab
git-subtree-split: d8b67d779fa834cc28ca2f0d0ca7607ff8a96f65
Willy-JL 1 år sedan
förälder
incheckning
70324366c3

+ 191 - 0
em4100_generator/.clang-format

@@ -0,0 +1,191 @@
+---
+Language:        Cpp
+AccessModifierOffset: -4
+AlignAfterOpenBracket: AlwaysBreak
+AlignArrayOfStructures: None
+AlignConsecutiveMacros: None
+AlignConsecutiveAssignments: None
+AlignConsecutiveBitFields: None
+AlignConsecutiveDeclarations: None
+AlignEscapedNewlines: Left
+AlignOperands:   Align
+AlignTrailingComments: false
+AllowAllArgumentsOnNextLine: true
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortEnumsOnASingleLine: true
+AllowShortBlocksOnASingleLine: Never
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortLambdasOnASingleLine: All
+AllowShortIfStatementsOnASingleLine: WithoutElse
+AllowShortLoopsOnASingleLine: true
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: Yes
+AttributeMacros:
+  - __capability
+BinPackArguments: false
+BinPackParameters: false
+BraceWrapping:
+  AfterCaseLabel:  false
+  AfterClass:      false
+  AfterControlStatement: Never
+  AfterEnum:       false
+  AfterFunction:   false
+  AfterNamespace:  false
+  AfterObjCDeclaration: false
+  AfterStruct:     false
+  AfterUnion:      false
+  AfterExternBlock: false
+  BeforeCatch:     false
+  BeforeElse:      false
+  BeforeLambdaBody: false
+  BeforeWhile:     false
+  IndentBraces:    false
+  SplitEmptyFunction: true
+  SplitEmptyRecord: true
+  SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: None
+BreakBeforeConceptDeclarations: true
+BreakBeforeBraces: Attach
+BreakBeforeInheritanceComma: false
+BreakInheritanceList: BeforeColon
+BreakBeforeTernaryOperators: false
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeComma
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: false
+ColumnLimit:     99
+CommentPragmas:  '^ IWYU pragma:'
+QualifierAlignment: Leave
+CompactNamespaces: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DeriveLineEnding: true
+DerivePointerAlignment: false
+DisableFormat:   false
+EmptyLineAfterAccessModifier: Never
+EmptyLineBeforeAccessModifier: LogicalBlock
+ExperimentalAutoDetectBinPacking: false
+PackConstructorInitializers: BinPack
+BasedOnStyle:    ''
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+AllowAllConstructorInitializersOnNextLine: true
+FixNamespaceComments: false
+ForEachMacros:
+  - foreach
+  - Q_FOREACH
+  - BOOST_FOREACH
+IfMacros:
+  - KJ_IF_MAYBE
+IncludeBlocks:   Preserve
+IncludeCategories:
+  - Regex:           '.*'
+    Priority:        1
+    SortPriority:    0
+    CaseSensitive:   false
+  - Regex:           '^(<|"(gtest|gmock|isl|json)/)'
+    Priority:        3
+    SortPriority:    0
+    CaseSensitive:   false
+  - Regex:           '.*'
+    Priority:        1
+    SortPriority:    0
+    CaseSensitive:   false
+IncludeIsMainRegex: '(Test)?$'
+IncludeIsMainSourceRegex: ''
+IndentAccessModifiers: false
+IndentCaseLabels: false
+IndentCaseBlocks: false
+IndentGotoLabels: true
+IndentPPDirectives: None
+IndentExternBlock: AfterExternBlock
+IndentRequires:  false
+IndentWidth:     4
+IndentWrappedFunctionNames: true
+InsertTrailingCommas: None
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+LambdaBodyIndentation: Signature
+MacroBlockBegin: ''
+MacroBlockEnd:   ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBinPackProtocolList: Auto
+ObjCBlockIndentWidth: 4
+ObjCBreakBeforeNestedBlockParam: true
+ObjCSpaceAfterProperty: true
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakAssignment: 10
+PenaltyBreakBeforeFirstCallParameter: 30
+PenaltyBreakComment: 10
+PenaltyBreakFirstLessLess: 0
+PenaltyBreakOpenParenthesis: 0
+PenaltyBreakString: 10
+PenaltyBreakTemplateDeclaration: 10
+PenaltyExcessCharacter: 100
+PenaltyReturnTypeOnItsOwnLine: 60
+PenaltyIndentedWhitespace: 0
+PointerAlignment: Left
+PPIndentWidth:   -1
+ReferenceAlignment: Pointer
+ReflowComments:  false
+RemoveBracesLLVM: false
+SeparateDefinitionBlocks: Leave
+ShortNamespaceLines: 1
+SortIncludes:    Never
+SortJavaStaticImport: Before
+SortUsingDeclarations: false
+SpaceAfterCStyleCast: false
+SpaceAfterLogicalNot: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCaseColon: false
+SpaceBeforeCpp11BracedList: false
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: Never
+SpaceBeforeParensOptions:
+  AfterControlStatements: false
+  AfterForeachMacros: false
+  AfterFunctionDefinitionName: false
+  AfterFunctionDeclarationName: false
+  AfterIfMacros:   false
+  AfterOverloadedOperator: false
+  BeforeNonEmptyParentheses: false
+SpaceAroundPointerQualifiers: Default
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyBlock: false
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles:  Never
+SpacesInConditionalStatement: false
+SpacesInContainerLiterals: false
+SpacesInCStyleCastParentheses: false
+SpacesInLineCommentPrefix:
+  Minimum:         1
+  Maximum:         -1
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+SpaceBeforeSquareBrackets: false
+BitFieldColonSpacing: Both
+Standard:        c++03
+StatementAttributeLikeMacros:
+  - Q_EMIT
+StatementMacros:
+  - Q_UNUSED
+  - QT_REQUIRE_VERSION
+TabWidth:        4
+UseCRLF:         false
+UseTab:          Never
+WhitespaceSensitiveMacros:
+  - STRINGIZE
+  - PP_STRINGIZE
+  - BOOST_PP_STRINGIZE
+  - NS_SWIFT_NAME
+  - CF_SWIFT_NAME
+...
+

BIN
em4100_generator/.flipcorg/gallery/Screenshot-20230223-203332.png


+ 1 - 0
em4100_generator/.gitsubtree

@@ -0,0 +1 @@
+https://github.com/Milk-Cool/fz-em4100-generator main /

+ 21 - 0
em4100_generator/LICENSE

@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2023 Milk-Cool
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

+ 5 - 0
em4100_generator/README.md

@@ -0,0 +1,5 @@
+# fz-em4100-generator
+A program that generates universal keys from a EM4100 key
+
+## Installing
+Click the FAP badge, connect your flipper and click "Install".

+ 12 - 0
em4100_generator/application.fam

@@ -0,0 +1,12 @@
+App(
+    appid="key_generator",
+    name="EM4100 Key generator",
+    apptype=FlipperAppType.EXTERNAL,
+    entry_point="key_generator_main",
+    requires=["gui"],
+    stack_size=1 * 1024,
+    fap_category="RFID",
+    fap_icon_assets="images",
+    fap_icon="icon.png",
+    fap_version="1.1"
+)

BIN
em4100_generator/icon.png


BIN
em4100_generator/images/icon_10x10.png


BIN
em4100_generator/images/ok_64x64.png


+ 188 - 0
em4100_generator/key_generator.c

@@ -0,0 +1,188 @@
+#include <furi.h>
+#include <furi_hal.h>
+
+#include <gui/gui.h>
+#include <input/input.h>
+#include <dialogs/dialogs.h>
+#include <storage/storage.h>
+#include <flipper_format/flipper_format.h>
+
+#include <notification/notification.h>
+#include <notification/notification_messages.h>
+
+#include "key_generator_icons.h"
+
+#define DIR_PATH "/ext/rfidfuzzer"
+#define FILE_PATH "/ext/rfidfuzzer/generated.txt"
+
+FuriString* file_path;
+FuriString* key;
+
+// Screen is 128x64 px
+static void app_draw_callback(Canvas* canvas, void* ctx) {
+    UNUSED(ctx);
+
+    canvas_clear(canvas);
+    canvas_draw_icon(canvas, 0, 0, &I_ok_64x64);
+    canvas_draw_str(canvas, 80, 24, "Saved as");
+    canvas_draw_str(canvas, 75, 36, "rfidfuzzer/");
+    canvas_draw_str(canvas, 70, 48, "generated.txt");
+}
+
+static void app_input_callback(InputEvent* input_event, void* ctx) {
+    furi_assert(ctx);
+
+    FuriMessageQueue* event_queue = ctx;
+    furi_message_queue_put(event_queue, input_event, FuriWaitForever);
+}
+
+static void beep() {
+    NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
+    notification_message(notification, &sequence_success);
+    furi_record_close(RECORD_NOTIFICATION);
+}
+
+int32_t key_generator_main(void* p) {
+    UNUSED(p);
+    FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
+
+    // Configure view port
+    ViewPort* view_port = view_port_alloc();
+    view_port_draw_callback_set(view_port, app_draw_callback, view_port);
+    view_port_input_callback_set(view_port, app_input_callback, event_queue);
+
+    // Register view port in GUI
+    Gui* gui = furi_record_open(RECORD_GUI);
+    gui_add_view_port(gui, view_port, GuiLayerFullscreen);
+
+    // Selecting file
+    file_path = furi_string_alloc_set_str("/ext/lfrfid");
+    key = furi_string_alloc_set_str("");
+    DialogsFileBrowserOptions browser_options;
+    dialog_file_browser_set_basic_options(&browser_options, ".rfid", &I_icon_10x10);
+    browser_options.base_path = "/ext/lfrfid";
+    DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS);
+    bool running = dialog_file_browser_show(dialogs, file_path, file_path, &browser_options);
+    furi_record_close(RECORD_DIALOGS);
+
+    if(running) {
+        Storage* storage = furi_record_open(RECORD_STORAGE);
+        FlipperFormat* format = flipper_format_file_alloc(storage);
+
+        // Parsing file
+        flipper_format_file_open_existing(format, furi_string_get_cstr(file_path));
+        flipper_format_read_string(format, "Data", key);
+        furi_string_replace_str(key, " ", "", 0);
+
+        flipper_format_file_close(format);
+        flipper_format_free(format);
+
+        if(!storage_dir_exists(storage, DIR_PATH)) storage_simply_mkdir(storage, DIR_PATH);
+
+        File* file = storage_file_alloc(storage);
+        bool ok = storage_file_open(file, FILE_PATH, FSAM_WRITE, FSOM_OPEN_ALWAYS);
+        if(ok) {
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 2);
+            storage_file_write(file, (uint8_t*)"11111111\r\n", 10);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 2);
+            storage_file_write(file, (uint8_t*)"22222222\r\n", 10);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 2);
+            storage_file_write(file, (uint8_t*)"33333333\r\n", 10);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 2);
+            storage_file_write(file, (uint8_t*)"44444444\r\n", 10);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 2);
+            storage_file_write(file, (uint8_t*)"55555555\r\n", 10);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 2);
+            storage_file_write(file, (uint8_t*)"66666666\r\n", 10);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 2);
+            storage_file_write(file, (uint8_t*)"77777777\r\n", 10);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 2);
+            storage_file_write(file, (uint8_t*)"88888888\r\n", 10);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 2);
+            storage_file_write(file, (uint8_t*)"99999999\r\n", 10);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 2);
+            storage_file_write(file, (uint8_t*)"AAAAAAAA\r\n", 10);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 2);
+            storage_file_write(file, (uint8_t*)"BBBBBBBB\r\n", 10);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 2);
+            storage_file_write(file, (uint8_t*)"CCCCCCCC\r\n", 10);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 2);
+            storage_file_write(file, (uint8_t*)"DDDDDDDD\r\n", 10);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 2);
+            storage_file_write(file, (uint8_t*)"EEEEEEEE\r\n", 10);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 2);
+            storage_file_write(file, (uint8_t*)"FFFFFFFF\r\n", 10);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 2);
+            storage_file_write(file, (uint8_t*)"12345678\r\n", 10);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 2);
+            storage_file_write(file, (uint8_t*)"01234567\r\n", 10);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 2);
+            storage_file_write(file, (uint8_t*)"98765432\r\n", 10);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 2);
+            storage_file_write(file, (uint8_t*)"FEDCBA98\r\n", 10);
+
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 4);
+            storage_file_write(file, (uint8_t*)"111111\r\n", 8);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 4);
+            storage_file_write(file, (uint8_t*)"222222\r\n", 8);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 4);
+            storage_file_write(file, (uint8_t*)"333333\r\n", 8);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 4);
+            storage_file_write(file, (uint8_t*)"444444\r\n", 8);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 4);
+            storage_file_write(file, (uint8_t*)"555555\r\n", 8);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 4);
+            storage_file_write(file, (uint8_t*)"666666\r\n", 8);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 4);
+            storage_file_write(file, (uint8_t*)"777777\r\n", 8);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 4);
+            storage_file_write(file, (uint8_t*)"888888\r\n", 8);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 4);
+            storage_file_write(file, (uint8_t*)"999999\r\n", 8);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 4);
+            storage_file_write(file, (uint8_t*)"AAAAAA\r\n", 8);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 4);
+            storage_file_write(file, (uint8_t*)"BBBBBB\r\n", 8);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 4);
+            storage_file_write(file, (uint8_t*)"CCCCCC\r\n", 8);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 4);
+            storage_file_write(file, (uint8_t*)"DDDDDD\r\n", 8);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 4);
+            storage_file_write(file, (uint8_t*)"EEEEEE\r\n", 8);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 4);
+            storage_file_write(file, (uint8_t*)"FFFFFF\r\n", 8);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 4);
+            storage_file_write(file, (uint8_t*)"123456\r\n", 8);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 4);
+            storage_file_write(file, (uint8_t*)"012345\r\n", 8);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 4);
+            storage_file_write(file, (uint8_t*)"987654\r\n", 8);
+            storage_file_write(file, (uint8_t*)furi_string_get_cstr(key), 4);
+            storage_file_write(file, (uint8_t*)"FEDCBA\r\n", 8);
+        }
+        storage_file_close(file);
+        storage_file_free(file);
+
+        furi_record_close(RECORD_STORAGE);
+
+        beep();
+    }
+
+    InputEvent event;
+
+    while(running) {
+        if(furi_message_queue_get(event_queue, &event, 100) == FuriStatusOk) {
+            if(event.type == InputTypePress && event.key == InputKeyBack) running = false;
+        }
+        view_port_update(view_port);
+    }
+
+    view_port_enabled_set(view_port, false);
+    gui_remove_view_port(gui, view_port);
+    view_port_free(view_port);
+    furi_message_queue_free(event_queue);
+
+    furi_record_close(RECORD_GUI);
+
+    return 0;
+}