Parcourir la source

map keys

develop
Robin Thoni il y a 7 ans
Parent
révision
58026ddb3b

+ 1
- 1
cli/CMakeLists.txt Voir le fichier

@@ -1,5 +1,5 @@
1 1
 include_directories(.)
2
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
2
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -ggdb -g3")
3 3
 include_directories(. ../src)
4 4
 set(SOURCE_FILES
5 5
         main.cpp

+ 52
- 18
cli/Interface/MainClass.cpp Voir le fichier

@@ -8,7 +8,6 @@
8 8
 #include <Business/FreeFareDeviceBusiness.h>
9 9
 #include "DBO/Result.h"
10 10
 #include "Business/LibNfcBusiness.h"
11
-#include "Business/FreeFareDeviceBusiness.h"
12 11
 #include "CommandLineParser.h"
13 12
 #include "MainClass.h"
14 13
 
@@ -64,27 +63,62 @@ int MainClass::main()
64 63
         auto tag = tags.getData()[i];
65 64
         std::cout << "UID: " << tag->getUid() << std::endl;
66 65
         std::cout << "Type: " << tag->getType() << std::endl;
67
-        for(int s = 0; s < 16; ++s) {
68
-            std::cout << "+Sector: " << s << std::endl;
69
-            auto sectorResult = tag->readSector(s,  StringUtils::humanToRaw("8829da9daf76").getData(), MFC_KEY_A);
70
-            if (!sectorResult) {
71
-                sectorResult.print();
72
-            }
73
-            else {
74
-                auto sector = sectorResult.getData();
75
-                for (int b = 0; b < 3; ++b) {
76
-                    std::cout << StringUtils::rawToHuman(sector.getBlock(b)) << std::endl;
77
-                }
78
-                std::cout << StringUtils::rawToHuman(sector.getKeyA()) << " "
79
-                << StringUtils::rawToHuman(sector.getAccessBits()) << " "
80
-                << StringUtils::rawToHuman(sector.getKeyB()) << std::endl;
81
-            }
82
-        }
66
+        mapKeys(tag);
83 67
     }
84 68
 
85 69
     device->close();
86
-
87 70
     libNfc.clean();
88 71
 
89 72
     return 0;
90 73
 }
74
+
75
+int MainClass::mapKeys(std::shared_ptr<FreeFareTagBusiness> tag)
76
+{
77
+    std::vector<std::string> keys;
78
+    keys.push_back(StringUtils::humanToRaw("8829da9daf76").getData());
79
+    auto mappedKeysResult = tag->mapKeys(keys);
80
+    if (!mappedKeysResult) {
81
+        mappedKeysResult.print();
82
+    }
83
+    else {
84
+        auto mappedKeys = mappedKeysResult.getData();
85
+        for (int s = 0; s < mappedKeys.size(); ++s) {
86
+            auto sectorKeys = mappedKeys[s];
87
+            std::cout << "+Sector: " << s << std::endl;
88
+            for (int b = 0; b < sectorKeys.size(); ++b) {
89
+                auto blockKeys = sectorKeys[b];
90
+                std::cout << "+Block: " << b << std::endl;
91
+                std::cout << "Key A: " << StringUtils::rawToHuman(blockKeys.first) << std::endl;
92
+                std::cout << "Key B: " << StringUtils::rawToHuman(blockKeys.second) << std::endl;
93
+            }
94
+        }
95
+    }
96
+    return 0;
97
+}
98
+
99
+int MainClass::dump(std::shared_ptr<FreeFareTagBusiness> tag)
100
+{
101
+    for(int s = 0; s < 16; ++s)
102
+    {
103
+        std::cout << "+Sector: " << s << std::endl;
104
+        auto sectorResult = tag->readSector(s, StringUtils::humanToRaw("8829da9daf76").getData(), MFC_KEY_A);
105
+        if (!sectorResult)
106
+        {
107
+            sectorResult.print();
108
+        }
109
+        else
110
+        {
111
+            auto sector = sectorResult.getData();
112
+            for (int b = 0; b < 3; ++b)
113
+            {
114
+                std::cout << StringUtils::rawToHuman(sector.getBlock(b)) << std::endl;
115
+            }
116
+            std::cout << StringUtils::rawToHuman(sector.getKeyA()) << " "
117
+            << StringUtils::rawToHuman(sector.getAccessBits()) << " "
118
+            << StringUtils::rawToHuman(sector.getKeyB()) << std::endl;
119
+        }
120
+    }
121
+    return 0;
122
+}
123
+
124
+

+ 6
- 0
cli/Interface/MainClass.h Voir le fichier

@@ -5,6 +5,8 @@
5 5
 #ifndef PDNS_SLAVE_MAINCLASS_H
6 6
 #define PDNS_SLAVE_MAINCLASS_H
7 7
 
8
+#include <memory>
9
+#include <Business/FreeFareTagBusiness.h>
8 10
 
9 11
 class MainClass {
10 12
 public:
@@ -12,6 +14,10 @@ public:
12 14
 
13 15
     int main();
14 16
 
17
+    int mapKeys(std::shared_ptr<FreeFareTagBusiness> tag);
18
+
19
+    int dump(std::shared_ptr<FreeFareTagBusiness> tag);
20
+
15 21
 private:
16 22
     int _argc;
17 23
 

+ 26
- 0
src/Business/FreeFareTagBusiness.cpp Voir le fichier

@@ -48,4 +48,30 @@ freefare_tag_type FreeFareTagBusiness::getType() const
48 48
 std::shared_ptr<FreeFareTag> FreeFareTagBusiness::getTag() const
49 49
 {
50 50
     return _tag;
51
+}
52
+
53
+Result<std::vector<std::vector<std::pair<std::string, std::string>>>> FreeFareTagBusiness::mapKeys(std::vector<std::string> keys)
54
+{
55
+    std::vector<std::vector<std::pair<std::string, std::string>>> mappedKeys;
56
+
57
+    for (int i = 0; i < 16; ++i) {
58
+        std::vector<std::pair<std::string, std::string>> sectorKeys;
59
+        for (int j = 0; j < 4; ++j) {
60
+            std::pair<std::string, std::string> blockKeys;
61
+            for (auto key : keys) {
62
+                auto res = authenticate(i, j, key, MFC_KEY_A);
63
+                if (res) {
64
+                    blockKeys.first = key;
65
+                }
66
+                res = authenticate(i, j, key, MFC_KEY_B);
67
+                if (res) {
68
+                    blockKeys.second = key;
69
+                }
70
+            }
71
+            sectorKeys.push_back(blockKeys);
72
+        }
73
+        mappedKeys.push_back(sectorKeys);
74
+    }
75
+
76
+    return Result<std::vector<std::vector<std::pair<std::string, std::string>>>>::ok(mappedKeys);
51 77
 }

+ 3
- 1
src/Business/FreeFareTagBusiness.h Voir le fichier

@@ -21,7 +21,9 @@ public:
21 21
 
22 22
     Result<SectorDbo> readSector(int sector, std::string key, int keyType);
23 23
 
24
-    const std::string & getUid() const;
24
+    Result<std::vector<std::vector<std::pair<std::string, std::string>>>> mapKeys(std::vector<std::string> keys);
25
+
26
+    const std::string& getUid() const;
25 27
 
26 28
     freefare_tag_type getType() const;
27 29
 

+ 1
- 1
src/CMakeLists.txt Voir le fichier

@@ -1,5 +1,5 @@
1 1
 include_directories(.)
2
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
2
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11  -ggdb -g3")
3 3
 set(SOURCE_FILES
4 4
         DBO/Result.hxx
5 5
         DBO/Result.h

+ 1
- 1
src/DataAccess/LibNfc.cpp Voir le fichier

@@ -38,7 +38,7 @@ void LibNfc::clean()
38 38
 Result<std::vector<std::shared_ptr<NfcDevice>>> LibNfc::getDevices() const
39 39
 {
40 40
     nfc_connstring devices[16];
41
-    size_t count = nfc_list_devices(_context, devices, sizeof(devices));
41
+    size_t count = nfc_list_devices(_context, devices, 16);
42 42
     if (count < 0) {
43 43
         return Result<std::vector<std::shared_ptr<NfcDevice>>>::error("Failed to list NFC devices: " + count);
44 44
     }

Chargement…
Annuler
Enregistrer