Преглед изворни кода

Merge magspoof from https://github.com/zacharyweiss/magspoof_flipper

# Conflicts:
#	magspoof/helpers/mag_text_input.c
Willy-JL пре 1 година
родитељ
комит
6bf23e509d

+ 2 - 2
magspoof/application.fam

@@ -10,10 +10,9 @@ App(
         "notification",
         "notification",
         "dialogs",
         "dialogs",
     ],
     ],
-    resources="resources",
     provides=[],
     provides=[],
     stack_size=6 * 1024,
     stack_size=6 * 1024,
-    order=64,  # keep it at the bottom of the list while still WIP
+    order=64,
     fap_icon="icons/mag_10px.png",
     fap_icon="icons/mag_10px.png",
     fap_category="GPIO",
     fap_category="GPIO",
     fap_icon_assets="icons",
     fap_icon_assets="icons",
@@ -22,4 +21,5 @@ App(
     fap_description="Enables wireless transmission of magstripe data",
     fap_description="Enables wireless transmission of magstripe data",
     fap_author="Zachary Weiss",
     fap_author="Zachary Weiss",
     fap_weburl="https://github.com/zacharyweiss/magspoof_flipper",
     fap_weburl="https://github.com/zacharyweiss/magspoof_flipper",
+    fap_file_assets="resources",
 )
 )

BIN
magspoof/assets/emulate.png


BIN
magspoof/assets/emulate_config.png


BIN
magspoof/assets/settings.png


BIN
magspoof/assets/start.png


BIN
magspoof/icons/mag_10px.png


+ 24 - 0
magspoof/mag.c

@@ -149,6 +149,7 @@ int32_t mag_app(void* p) {
     }
     }
 
 
     mag_make_app_folder(mag);
     mag_make_app_folder(mag);
+    mag_migrate_and_copy_files(mag);
 
 
     // Enable 5v power, multiple attempts to avoid issues with power chip protection false triggering
     // Enable 5v power, multiple attempts to avoid issues with power chip protection false triggering
     uint8_t attempts = 0;
     uint8_t attempts = 0;
@@ -191,6 +192,29 @@ void mag_make_app_folder(Mag* mag) {
     }
     }
 }
 }
 
 
+void mag_migrate_and_copy_files(Mag* mag) {
+    furi_assert(mag);
+    Storage* storage = mag->storage;
+
+    storage_common_migrate(storage, EXT_PATH("magspoof"), STORAGE_APP_DATA_PATH_PREFIX);
+    storage_common_migrate(storage, EXT_PATH("mag"), STORAGE_APP_DATA_PATH_PREFIX);
+
+    if(!storage_common_exists(storage, APP_DATA_PATH(MAG_EXAMPLE_FILE_1))) {
+        storage_common_copy(
+            storage, APP_ASSETS_PATH(MAG_EXAMPLE_FILE_1), APP_DATA_PATH(MAG_EXAMPLE_FILE_1));
+    }
+
+    if(!storage_common_exists(storage, APP_DATA_PATH(MAG_EXAMPLE_FILE_2))) {
+        storage_common_copy(
+            storage, APP_ASSETS_PATH(MAG_EXAMPLE_FILE_2), APP_DATA_PATH(MAG_EXAMPLE_FILE_2));
+    }
+
+    if(!storage_common_exists(storage, APP_DATA_PATH(MAG_EXAMPLE_FILE_3))) {
+        storage_common_copy(
+            storage, APP_ASSETS_PATH(MAG_EXAMPLE_FILE_3), APP_DATA_PATH(MAG_EXAMPLE_FILE_3));
+    }
+}
+
 void mag_text_store_set(Mag* mag, const char* text, ...) {
 void mag_text_store_set(Mag* mag, const char* text, ...) {
     furi_assert(mag);
     furi_assert(mag);
     va_list args;
     va_list args;

+ 4 - 2
magspoof/mag_device.h

@@ -8,14 +8,16 @@
 #include "mag_icons.h"
 #include "mag_icons.h"
 #include "helpers/mag_types.h"
 #include "helpers/mag_types.h"
 
 
-#include <assets_icons.h>
-
 #define MAG_DEV_NAME_MAX_LEN 22
 #define MAG_DEV_NAME_MAX_LEN 22
 #define MAG_DEV_TRACKS 3
 #define MAG_DEV_TRACKS 3
 
 
 #define MAG_APP_FOLDER STORAGE_APP_DATA_PATH_PREFIX
 #define MAG_APP_FOLDER STORAGE_APP_DATA_PATH_PREFIX
 #define MAG_APP_EXTENSION ".mag"
 #define MAG_APP_EXTENSION ".mag"
 
 
+#define MAG_EXAMPLE_FILE_1 "TestMagstripe.mag"
+#define MAG_EXAMPLE_FILE_2 "SamyExpiredCard.mag"
+#define MAG_EXAMPLE_FILE_3 "SamyExampleImage.mag"
+
 typedef void (*MagLoadingCallback)(void* context, bool state);
 typedef void (*MagLoadingCallback)(void* context, bool state);
 
 
 typedef struct {
 typedef struct {

+ 3 - 1
magspoof/mag_i.h

@@ -44,7 +44,7 @@
 #define submenu_add_lockable_item(                                             \
 #define submenu_add_lockable_item(                                             \
     submenu, label, index, callback, callback_context, locked, locked_message) \
     submenu, label, index, callback, callback_context, locked, locked_message) \
     if(!locked) {                                                              \
     if(!locked) {                                                              \
-        submenu_add_item(submenu, label, index, callback, callback_context)    \
+        submenu_add_item(submenu, label, index, callback, callback_context);   \
     }
     }
 #endif
 #endif
 
 
@@ -99,6 +99,8 @@ void mag_show_loading_popup(void* context, bool show);
 
 
 void mag_make_app_folder(Mag* mag);
 void mag_make_app_folder(Mag* mag);
 
 
+void mag_migrate_and_copy_files(Mag* mag);
+
 void mag_popup_timeout_callback(void* context);
 void mag_popup_timeout_callback(void* context);
 
 
 void mag_widget_callback(GuiButtonType result, InputType type, void* context);
 void mag_widget_callback(GuiButtonType result, InputType type, void* context);

+ 0 - 0
magspoof/resources/apps_data/magspoof/SamyExampleImage.mag → magspoof/resources/SamyExampleImage.mag


+ 0 - 0
magspoof/resources/apps_data/magspoof/SamyExpiredCard.mag → magspoof/resources/SamyExpiredCard.mag


+ 0 - 0
magspoof/resources/apps_data/magspoof/TestMagstripe.mag → magspoof/resources/TestMagstripe.mag


+ 0 - 2
magspoof/scenes/mag_scene_emulate_config.c

@@ -182,8 +182,6 @@ static void mag_scene_emulate_config_set_interpacket(VariableItem* item) {
 };
 };
 
 
 void mag_scene_emulate_config_on_enter(void* context) {
 void mag_scene_emulate_config_on_enter(void* context) {
-    // TODO: retrieve current values from struct, rather than setting to default on setup
-
     Mag* mag = context;
     Mag* mag = context;
     VariableItem* item;
     VariableItem* item;
     uint8_t value_index;
     uint8_t value_index;

+ 9 - 2
magspoof/scenes/mag_scene_settings.c

@@ -8,7 +8,9 @@ enum VarItemListIndex {
     VarItemListIndexPinInput,
     VarItemListIndexPinInput,
     VarItemListIndexPinOutput,
     VarItemListIndexPinOutput,
     VarItemListIndexPinEnable,
     VarItemListIndexPinEnable,
+#ifndef FW_ORIGIN_Official
     VarItemListIndexAllowUART,
     VarItemListIndexAllowUART,
+#endif
 };
 };
 
 
 static const char* gpio[] = {
 static const char* gpio[] = {
@@ -64,7 +66,6 @@ static void mag_pin_variable_item_list_add(
 
 
 void mag_scene_settings_on_enter(void* context) {
 void mag_scene_settings_on_enter(void* context) {
     Mag* mag = context;
     Mag* mag = context;
-    VariableItem* item;
     VariableItemList* var_item_list = mag->variable_item_list;
     VariableItemList* var_item_list = mag->variable_item_list;
 
 
     mag_pin_variable_item_list_add(
     mag_pin_variable_item_list_add(
@@ -74,8 +75,10 @@ void mag_scene_settings_on_enter(void* context) {
     mag_pin_variable_item_list_add(
     mag_pin_variable_item_list_add(
         mag, "Enable pin:", mag->state.pin_enable, mag_scene_settings_set_gpio_enable);
         mag, "Enable pin:", mag->state.pin_enable, mag_scene_settings_set_gpio_enable);
 
 
-    item = variable_item_list_add(var_item_list, "UART MSR: ", 1, NULL, mag);
+#ifndef FW_ORIGIN_Official
+    VariableItem* item = variable_item_list_add(var_item_list, "UART MSR: ", 1, NULL, mag);
     variable_item_set_current_value_text(item, mag->state.allow_uart ? "ON" : "OFF");
     variable_item_set_current_value_text(item, mag->state.allow_uart ? "ON" : "OFF");
+#endif
 
 
     variable_item_list_set_enter_callback(
     variable_item_list_set_enter_callback(
         var_item_list, mag_scene_settings_var_item_list_callback, mag);
         var_item_list, mag_scene_settings_var_item_list_callback, mag);
@@ -109,6 +112,7 @@ void mag_scene_settings_dialog_invalid_pins(Mag* mag) {
     }
     }
 }
 }
 
 
+#ifndef FW_ORIGIN_Official
 void mag_scene_settings_dialog_allow_uart(Mag* mag) {
 void mag_scene_settings_dialog_allow_uart(Mag* mag) {
     bool change = mag->state.allow_uart;
     bool change = mag->state.allow_uart;
     if(!change) {
     if(!change) {
@@ -136,6 +140,7 @@ void mag_scene_settings_dialog_allow_uart(Mag* mag) {
             mag->state.allow_uart ? "ON" : "OFF");
             mag->state.allow_uart ? "ON" : "OFF");
     }
     }
 }
 }
+#endif
 
 
 bool mag_scene_settings_on_event(void* context, SceneManagerEvent event) {
 bool mag_scene_settings_on_event(void* context, SceneManagerEvent event) {
     Mag* mag = context;
     Mag* mag = context;
@@ -154,6 +159,7 @@ bool mag_scene_settings_on_event(void* context, SceneManagerEvent event) {
             scene_manager_previous_scene(scene_manager);
             scene_manager_previous_scene(scene_manager);
         }
         }
         break;
         break;
+#ifndef FW_ORIGIN_Official
     case SceneManagerEventTypeCustom:
     case SceneManagerEventTypeCustom:
         scene_manager_set_scene_state(mag->scene_manager, MagSceneSettings, event.event);
         scene_manager_set_scene_state(mag->scene_manager, MagSceneSettings, event.event);
         consumed = true;
         consumed = true;
@@ -161,6 +167,7 @@ bool mag_scene_settings_on_event(void* context, SceneManagerEvent event) {
             mag_scene_settings_dialog_allow_uart(mag);
             mag_scene_settings_dialog_allow_uart(mag);
         }
         }
         break;
         break;
+#endif
     default:
     default:
         break;
         break;
     }
     }