MX 7 mēneši atpakaļ
vecāks
revīzija
d3cedfec64

+ 12 - 17
picopass.c

@@ -96,28 +96,23 @@ Picopass* picopass_alloc() {
     view_dispatcher_add_view(
         picopass->view_dispatcher, PicopassViewLoclass, loclass_get_view(picopass->loclass));
 
-    picopass->plugin_manager =
+    picopass->plugin_wiegand_manager =
         plugin_manager_alloc(PLUGIN_APP_ID, PLUGIN_API_VERSION, firmware_api_interface);
-
     picopass->plugin_wiegand = NULL;
-    if(plugin_manager_load_all(picopass->plugin_manager, APP_ASSETS_PATH("plugins")) !=
+    if(plugin_manager_load_single(picopass->plugin_wiegand_manager, APP_ASSETS_PATH("plugins/plugin_wiegand.fal")) !=
        PluginManagerErrorNone) {
-        FURI_LOG_E(TAG, "Failed to load all libs");
-    } else {
-        uint32_t plugin_count = plugin_manager_get_count(picopass->plugin_manager);
-        FURI_LOG_I(TAG, "Loaded %lu plugin(s)", plugin_count);
-
-        for(uint32_t i = 0; i < plugin_count; i++) {
-            const PluginWiegand* plugin = plugin_manager_get_ep(picopass->plugin_manager, i);
-            FURI_LOG_I(TAG, "plugin name: %s", plugin->name);
-            if(strcmp(plugin->name, "Plugin Wiegand") == 0) {
-                // Have to cast to drop "const" qualifier
-                picopass->plugin_wiegand = (PluginWiegand*)plugin;
-            }
+        FURI_LOG_E(TAG, "Failed to load Wiegand plugin");
+    } else if (plugin_manager_get_count(picopass->plugin_wiegand_manager)) {
+        picopass->plugin_wiegand = (PluginWiegand*)plugin_manager_get_ep(picopass->plugin_wiegand_manager, 0);
+        if(strcmp(picopass->plugin_wiegand->name, "Plugin Wiegand") != 0) {
+            FURI_LOG_E(TAG, "Tried to load invalid Wiegand plugin");
+            picopass->plugin_wiegand = NULL;
+        } else {
+            FURI_LOG_I(TAG, "Loaded Wiegand plugin");
         }
     }
 
-    picopass->auto_nr_mac = false;
+    picopass->nr_mac_type = ManualNRMAC;
 
     return picopass;
 }
@@ -180,7 +175,7 @@ void picopass_free(Picopass* picopass) {
     furi_record_close(RECORD_NOTIFICATION);
     picopass->notifications = NULL;
 
-    plugin_manager_free(picopass->plugin_manager);
+    plugin_manager_free(picopass->plugin_wiegand_manager);
 
     free(picopass);
 }

+ 7 - 2
picopass_i.h

@@ -84,6 +84,11 @@ typedef struct {
     size_t macs_collected;
 } PicopassLoclassContext;
 
+typedef enum {
+    ManualNRMAC,
+    AutoNRMAC
+} NRMACType;
+
 struct Picopass {
     ViewDispatcher* view_dispatcher;
     Gui* gui;
@@ -112,14 +117,14 @@ struct Picopass {
     DictAttack* dict_attack;
     Loclass* loclass;
 
-    PluginManager* plugin_manager;
+    PluginManager* plugin_wiegand_manager;
     PluginWiegand* plugin_wiegand;
 
     PicopassDictAttackContext dict_attack_ctx;
     PicopassWriteKeyContext write_key_context;
     PicopassLoclassContext loclass_context;
 
-    bool auto_nr_mac;
+    NRMACType nr_mac_type;
 };
 
 typedef enum {

+ 1 - 1
scenes/picopass_scene_elite_dict_attack.c

@@ -187,7 +187,7 @@ bool picopass_scene_elite_dict_attack_on_event(void* context, SceneManagerEvent
                    PICOPASS_BLOCK_LEN) == 0) {
                 scene_manager_next_scene(picopass->scene_manager, PicopassSceneReadFactorySuccess);
             } else {
-                if(auth == PicopassDeviceAuthMethodFailed && picopass->auto_nr_mac) {
+                if(auth == PicopassDeviceAuthMethodFailed && picopass->nr_mac_type == AutoNRMAC) {
                     // save partial as <CSN>-partial
                     picopass->dev->format = PicopassDeviceSaveFormatPartial;
                     uint8_t* csn =

+ 2 - 2
scenes/picopass_scene_nr_mac_saved.c

@@ -27,10 +27,10 @@ bool picopass_scene_nr_mac_saved_on_event(void* context, SceneManagerEvent event
 
     if(event.type == SceneManagerEventTypeCustom) {
         if(event.event == PicopassCustomEventViewExit) {
-            if(picopass->auto_nr_mac) {
+            if(picopass->nr_mac_type == AutoNRMAC) {
                 consumed = scene_manager_search_and_switch_to_previous_scene(
                     picopass->scene_manager, PicopassSceneEliteDictAttack);
-                picopass->auto_nr_mac = false;
+                picopass->nr_mac_type = ManualNRMAC;
             } else {
                 scene_manager_set_scene_state(
                     picopass->scene_manager, PicopassSceneStart, 0); // Set back to "read card"

+ 2 - 2
scenes/picopass_scene_start.c

@@ -17,7 +17,7 @@ void picopass_scene_start_submenu_callback(void* context, uint32_t index) {
 void picopass_scene_start_on_enter(void* context) {
     Picopass* picopass = context;
     // Reset on enter
-    picopass->auto_nr_mac = false;
+    picopass->nr_mac_type = ManualNRMAC;
 
     Submenu* submenu = picopass->submenu;
     submenu_add_item(
@@ -72,7 +72,7 @@ bool picopass_scene_start_on_event(void* context, SceneManagerEvent event) {
             scene_manager_next_scene(picopass->scene_manager, PicopassSceneLoclass);
             consumed = true;
         } else if(event.event == SubmenuIndexNRMAC) {
-            picopass->auto_nr_mac = true;
+            picopass->nr_mac_type = AutoNRMAC;
             scene_manager_set_scene_state(
                 picopass->scene_manager, PicopassSceneStart, SubmenuIndexNRMAC);
             scene_manager_next_scene(picopass->scene_manager, PicopassSceneEliteDictAttack);