Kaynağa Gözat

added sectorDbo

develop
Robin Thoni 7 yıl önce
ebeveyn
işleme
32df322407

+ 13
- 9
cli/Interface/MainClass.cpp Dosyayı Görüntüle

@@ -64,16 +64,20 @@ int MainClass::main()
64 64
         auto tag = tags.getData()[i];
65 65
         std::cout << "UID: " << tag->getUid() << std::endl;
66 66
         std::cout << "Type: " << tag->getType() << std::endl;
67
-        for(int i = 0; i < 16; ++i) {
68
-            std::cout << "+Sector: " << i << std::endl;
69
-            for (int j = 0; j < 4; ++j) {
70
-                auto sector = tag->readBlock(i, j, StringUtils::humanToRaw("8829da9daf76").getData(), MFC_KEY_A);
71
-                if (!sector) {
72
-                    sector.print();
73
-                }
74
-                else {
75
-                    std::cout << StringUtils::rawToHuman(sector.getData()) << 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;
76 77
                 }
78
+                std::cout << StringUtils::rawToHuman(sector.getKeyA()) << " "
79
+                << StringUtils::rawToHuman(sector.getAccessBits()) << " "
80
+                << StringUtils::rawToHuman(sector.getKeyB()) << std::endl;
77 81
             }
78 82
         }
79 83
     }

+ 3
- 3
src/Business/FreeFareTagBusiness.cpp Dosyayı Görüntüle

@@ -19,7 +19,7 @@ ResultString FreeFareTagBusiness::readBlock(int sector, int block, std::string k
19 19
     return _tag->readBlock(sector, block, key, keyType);
20 20
 }
21 21
 
22
-ResultString FreeFareTagBusiness::readSector(int sector, std::string key, int keyType)
22
+Result<SectorDbo> FreeFareTagBusiness::readSector(int sector, std::string key, int keyType)
23 23
 {
24 24
     std::string res;
25 25
     int lastBlock = _tag->getSectorBlockCount(sector);
@@ -29,10 +29,10 @@ ResultString FreeFareTagBusiness::readSector(int sector, std::string key, int ke
29 29
             res += data.getData();
30 30
         }
31 31
         else {
32
-            return data;
32
+            return Result<SectorDbo>::error(data);
33 33
         }
34 34
     }
35
-    return ResultString::ok(res);
35
+    return SectorDbo::parse(res);
36 36
 }
37 37
 
38 38
 const std::string &FreeFareTagBusiness::getUid() const

+ 2
- 1
src/Business/FreeFareTagBusiness.h Dosyayı Görüntüle

@@ -8,6 +8,7 @@
8 8
 
9 9
 #include <boost/shared_ptr.hpp>
10 10
 #include <DataAccess/FreeFareTag.h>
11
+#include <DataAccess/SectorDbo.h>
11 12
 
12 13
 class FreeFareTagBusiness
13 14
 {
@@ -18,7 +19,7 @@ public:
18 19
 
19 20
     ResultString readBlock(int sector, int block, std::string key, int keyType);
20 21
 
21
-    ResultString readSector(int sector, std::string key, int keyType);
22
+    Result<SectorDbo> readSector(int sector, std::string key, int keyType);
22 23
 
23 24
     const std::string & getUid() const;
24 25
 

+ 1
- 1
src/CMakeLists.txt Dosyayı Görüntüle

@@ -11,7 +11,7 @@ set(SOURCE_FILES
11 11
         DataAccess/FreeFareDevice.h
12 12
         DataAccess/FreeFareTag.cpp
13 13
         DataAccess/FreeFareTag.h
14
-        DBO/StringUtils.cpp DBO/StringUtils.h DBO/AccessBitsDbo.cpp DBO/AccessBitsDbo.h Business/LibNfcBusiness.cpp Business/LibNfcBusiness.h Business/NfcDeviceBusiness.cpp Business/NfcDeviceBusiness.h Business/FreeFareDeviceBusiness.cpp Business/FreeFareDeviceBusiness.h Business/FreeFareTagBusiness.cpp Business/FreeFareTagBusiness.h)
14
+        DBO/StringUtils.cpp DBO/StringUtils.h DBO/AccessBitsDbo.cpp DBO/AccessBitsDbo.h Business/LibNfcBusiness.cpp Business/LibNfcBusiness.h Business/NfcDeviceBusiness.cpp Business/NfcDeviceBusiness.h Business/FreeFareDeviceBusiness.cpp Business/FreeFareDeviceBusiness.h Business/FreeFareTagBusiness.cpp Business/FreeFareTagBusiness.h DataAccess/SectorDbo.cpp DataAccess/SectorDbo.h)
15 15
 
16 16
 add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES})
17 17
 target_link_libraries(${PROJECT_NAME} ${LIBS})

+ 37
- 0
src/DataAccess/SectorDbo.cpp Dosyayı Görüntüle

@@ -0,0 +1,37 @@
1
+//
2
+// Created by robin on 7/22/16.
3
+//
4
+
5
+#include "SectorDbo.h"
6
+
7
+Result<SectorDbo> SectorDbo::parse(std::string data)
8
+{
9
+    if (data.length() != 64) {
10
+        return Result<SectorDbo>::error("Data length must be 64");
11
+    }
12
+    SectorDbo dbo;
13
+    for (int i = 0; i < 4; ++i) {
14
+        dbo._blocks[i] = data.substr(16 * i, 16);
15
+    }
16
+    return Result<SectorDbo>::ok(dbo);
17
+}
18
+
19
+const std::string &SectorDbo::getBlock(int block) const
20
+{
21
+    return _blocks[block];
22
+}
23
+
24
+std::string SectorDbo::getKeyA() const
25
+{
26
+    return _blocks[3].substr(0, 6);
27
+}
28
+
29
+std::string SectorDbo::getKeyB() const
30
+{
31
+    return _blocks[3].substr(10, 6);
32
+}
33
+
34
+std::string SectorDbo::getAccessBits() const
35
+{
36
+    return _blocks[3].substr(6, 4);
37
+}

+ 31
- 0
src/DataAccess/SectorDbo.h Dosyayı Görüntüle

@@ -0,0 +1,31 @@
1
+//
2
+// Created by robin on 7/22/16.
3
+//
4
+
5
+#ifndef MIFARE_TOOLS_SECTORDBO_H
6
+#define MIFARE_TOOLS_SECTORDBO_H
7
+
8
+
9
+#include <string>
10
+#include <DBO/Result.h>
11
+
12
+class SectorDbo
13
+{
14
+public:
15
+
16
+    const std::string& getBlock(int block) const;
17
+
18
+    std::string getKeyA() const;
19
+
20
+    std::string getKeyB() const;
21
+
22
+    std::string getAccessBits() const;
23
+
24
+    static Result<SectorDbo> parse(std::string data);
25
+
26
+protected:
27
+    std::string _blocks[4];
28
+};
29
+
30
+
31
+#endif //MIFARE_TOOLS_SECTORDBO_H

Loading…
İptal
Kaydet