Преглед на файлове

AccessBits decode; tests

develop
Robin Thoni преди 7 години
родител
ревизия
a18384c40e
променени са 6 файла, в които са добавени 528 реда и са изтрити 3 реда
  1. 7
    1
      cli/Interface/MainClass.cpp
  2. 3
    1
      src/Business/FreeFareTag.cpp
  3. 1
    1
      src/CMakeLists.txt
  4. 235
    0
      src/DBO/AccessBitsDbo.cpp
  5. 71
    0
      src/DBO/AccessBitsDbo.h
  6. 211
    0
      tests/test-main.cpp

+ 7
- 1
cli/Interface/MainClass.cpp Целия файл

@@ -4,6 +4,7 @@
4 4
 
5 5
 #include <iostream>
6 6
 #include <sysexits.h>
7
+#include <Business/StringUtils.h>
7 8
 #include "DBO/Result.h"
8 9
 #include "Business/LibNfc.h"
9 10
 #include "Business/FreeFareDevice.h"
@@ -60,7 +61,12 @@ int MainClass::main()
60 61
     for (size_t i = 0; i < tags.getData().size(); ++i) {
61 62
         auto tag = tags.getData()[i];
62 63
         std::cout << "UID: " << tag->getUid() << std::endl;
63
-
64
+        auto sector = tag->readSector(1, StringUtils::humanToRaw("8829da9daf76").getData(), MFC_KEY_A);
65
+        if (!sector) {
66
+            sector.print();
67
+            return 6;
68
+        }
69
+        std::cout << "Sector 1: " << StringUtils::rawToHuman(sector.getData()) << std::endl;
64 70
     }
65 71
 
66 72
     device->close();

+ 3
- 1
src/Business/FreeFareTag.cpp Целия файл

@@ -2,6 +2,8 @@
2 2
 // Created by robin on 6/19/16.
3 3
 //
4 4
 
5
+#include <sstream>
6
+#include <map>
5 7
 #include "FreeFareTag.h"
6 8
 
7 9
 FreeFareTag::FreeFareTag(FreefareTag tag)
@@ -91,4 +93,4 @@ ResultString FreeFareTag::readBlock(int sector, int block, std::string key, int
91 93
 
92 94
     mifare_classic_disconnect(_tag);
93 95
     return ResultString::ok(std::string((const char*)data, sizeof(data)));
94
-}
96
+}

+ 1
- 1
src/CMakeLists.txt Целия файл

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

+ 235
- 0
src/DBO/AccessBitsDbo.cpp Целия файл

@@ -0,0 +1,235 @@
1
+//
2
+// Created by robin on 7/21/16.
3
+//
4
+
5
+#include <cstring>
6
+#include <iostream>
7
+#include "AccessBitsDbo.h"
8
+
9
+const char AccessBitsDbo::nonInvertedBitPosition[4][4] = {
10
+        {0,  0,  0,  0 },
11
+        {11, 10, 9,  8 },
12
+        {23, 22, 21, 20},
13
+        {19, 18, 17, 16}};
14
+
15
+const char AccessBitsDbo::invertedBitPosition[4][4] = {
16
+        {0,  0,  0,  0 },
17
+        {7,  6,  5,  4 },
18
+        {3,  2,  1,  0},
19
+        {15, 14, 13, 12}};
20
+
21
+AccessBitsDbo::AccessBitsDbo()
22
+    : _bits("\xff\x0f\00\x00", 4)
23
+{
24
+}
25
+
26
+AccessBitsDbo::AccessBitsDbo(const std::string &bits)
27
+    : _bits(bits.substr(0, 4))
28
+{
29
+}
30
+
31
+const char AccessBitsDbo::getUserData() const
32
+{
33
+    return _bits[_bits.length() - 1];
34
+}
35
+
36
+void AccessBitsDbo::setUserData(const char &data)
37
+{
38
+    _bits[_bits.length() - 1] = data;
39
+}
40
+
41
+void AccessBitsDbo::setBit(const char& i, const char& j, const bool& value)
42
+{
43
+    char buf[_bits.length()];
44
+    memcpy(buf, _bits.c_str(), _bits.length());
45
+
46
+    setArrayBit(buf, nonInvertedBitPosition[i][j], value);
47
+    setArrayBit(buf, invertedBitPosition[i][j], !value);
48
+
49
+    _bits = std::string(buf, _bits.length());
50
+}
51
+
52
+void AccessBitsDbo::setArrayBit(char *buf, const char &bitPosition, const bool &value)
53
+{
54
+    char byteOffset = (char)(bitPosition / 8);
55
+    char bitOffset = (char)(7 - (bitPosition % 8));
56
+    if(value)
57
+    {
58
+        buf[byteOffset] |=  (1 << bitOffset);
59
+    }
60
+    else
61
+    {
62
+        buf[byteOffset] &= ~(1 << bitOffset);
63
+    }
64
+}
65
+
66
+void AccessBitsDbo::setArrayBit(unsigned char *buf, const char &bitPosition, const bool &value)
67
+{
68
+    setArrayBit((char*)buf, bitPosition, value);
69
+}
70
+
71
+const bool AccessBitsDbo::getBit(const char &i, const char &j) const
72
+{
73
+    const char* buf = _bits.c_str();
74
+    return getArrayBit(buf, nonInvertedBitPosition[i][j]) && !getArrayBit(buf, invertedBitPosition[i][j]);
75
+}
76
+
77
+const bool AccessBitsDbo::getArrayBit(const char *buf, const char &bitPosition)
78
+{
79
+    char byteOffset = (char)(bitPosition / 8);
80
+    char bitOffset = (char)(7 - (bitPosition % 8));
81
+    return (buf[byteOffset] >> bitOffset) & 1 == 1;
82
+}
83
+
84
+const bool AccessBitsDbo::getArrayBit(const unsigned char *buf, const char &bitPosition)
85
+{
86
+    return getArrayBit((const char *)buf, bitPosition);
87
+}
88
+
89
+const bool AccessBitsDbo::canKeyAReadBlock(const char &block) const
90
+{
91
+    bool c1 = getBit(1, block);
92
+    bool c2 = getBit(2, block);
93
+    bool c3 = getBit(3, block);
94
+    return !c3 || (!c1 && !c2 && c3);
95
+}
96
+
97
+const bool AccessBitsDbo::canKeyBReadBlock(const char &block) const
98
+{
99
+    bool c1 = getBit(1, block);
100
+    bool c2 = getBit(2, block);
101
+    bool c3 = getBit(3, block);
102
+    return !c1 || !c2 || !c3;
103
+}
104
+
105
+const bool AccessBitsDbo::canKeyAWriteBlock(const char &block) const
106
+{
107
+    bool c1 = getBit(1, block);
108
+    bool c2 = getBit(2, block);
109
+    bool c3 = getBit(3, block);
110
+    return !c1 && !c2 && !c3;
111
+}
112
+
113
+const bool AccessBitsDbo::canKeyBWriteBlock(const char &block) const
114
+{
115
+    bool c1 = getBit(1, block);
116
+    bool c2 = getBit(2, block);
117
+    bool c3 = getBit(3, block);
118
+    return (!c2 && !c3) || (c1 && !c3) || (!c1 && c2 && c3);
119
+}
120
+
121
+const bool AccessBitsDbo::canKeyAIncrementBlock(const char &block) const
122
+{
123
+    bool c1 = getBit(1, block);
124
+    bool c2 = getBit(2, block);
125
+    bool c3 = getBit(3, block);
126
+    return !c1 && !c2 && !c3;
127
+}
128
+
129
+const bool AccessBitsDbo::canKeyBIncrementBlock(const char &block) const
130
+{
131
+    bool c1 = getBit(1, block);
132
+    bool c2 = getBit(2, block);
133
+    bool c3 = getBit(3, block);
134
+    return (!c1 && !c2 && !c3) || (c1 && c2 && !c3);
135
+}
136
+
137
+const bool AccessBitsDbo::canKeyADecrementBlock(const char &block) const
138
+{
139
+    bool c1 = getBit(1, block);
140
+    bool c2 = getBit(2, block);
141
+    bool c3 = getBit(3, block);
142
+    return (!c1 && !c2) || (c1 && c2 && !c3);
143
+}
144
+
145
+const bool AccessBitsDbo::canKeyBDecrementBlock(const char &block) const
146
+{
147
+    bool c1 = getBit(1, block);
148
+    bool c2 = getBit(2, block);
149
+    bool c3 = getBit(3, block);
150
+    return (!c1 && !c2) || (c1 && c2 && !c3);
151
+}
152
+
153
+const bool AccessBitsDbo::canKeyAReadKeyATrailer() const
154
+{
155
+    return false;
156
+}
157
+
158
+const bool AccessBitsDbo::canKeyBReadKeyATrailer() const
159
+{
160
+    return false;
161
+}
162
+
163
+const bool AccessBitsDbo::canKeyAWriteKeyATrailer() const
164
+{
165
+    bool c1 = getBit(1, 3);
166
+    bool c2 = getBit(2, 3);
167
+    bool c3 = getBit(3, 3);
168
+    return !c1 && !c2;
169
+}
170
+
171
+const bool AccessBitsDbo::canKeyBWriteKeyATrailer() const
172
+{
173
+    bool c1 = getBit(1, 3);
174
+    bool c2 = getBit(2, 3);
175
+    bool c3 = getBit(3, 3);
176
+    return (!c1 && c2 && c3) || (c1 && !c2 && !c3);
177
+}
178
+
179
+const bool AccessBitsDbo::canKeyAReadAccessBitsTrailer() const
180
+{
181
+    return true;
182
+}
183
+
184
+const bool AccessBitsDbo::canKeyBReadAccessBitsTrailer() const
185
+{
186
+    bool c1 = getBit(1, 3);
187
+    bool c2 = getBit(2, 3);
188
+    bool c3 = getBit(3, 3);
189
+    return c1 || (c2 && c3);
190
+}
191
+
192
+const bool AccessBitsDbo::canKeyAWriteAccessBitsTrailer() const
193
+{
194
+    bool c1 = getBit(1, 3);
195
+    bool c2 = getBit(2, 3);
196
+    bool c3 = getBit(3, 3);
197
+    return !c1 && !c2 && c3;
198
+}
199
+
200
+const bool AccessBitsDbo::canKeyBWriteAccessBitsTrailer() const
201
+{
202
+    bool c1 = getBit(1, 3);
203
+    bool c2 = getBit(2, 3);
204
+    bool c3 = getBit(3, 3);
205
+    return (!c1 && c2 && c3) || (c1 && !c2 && c3);
206
+}
207
+
208
+const bool AccessBitsDbo::canKeyAReadKeyBTrailer() const
209
+{
210
+    bool c1 = getBit(1, 3);
211
+    bool c2 = getBit(2, 3);
212
+    bool c3 = getBit(3, 3);
213
+    return (!c1 && !c2) || (!c1 && !c3);
214
+}
215
+
216
+const bool AccessBitsDbo::canKeyBReadKeyBTrailer() const
217
+{
218
+    return false;
219
+}
220
+
221
+const bool AccessBitsDbo::canKeyAWriteKeyBTrailer() const
222
+{
223
+    bool c1 = getBit(1, 3);
224
+    bool c2 = getBit(2, 3);
225
+    bool c3 = getBit(3, 3);
226
+    return !c1 && !c2;
227
+}
228
+
229
+const bool AccessBitsDbo::canKeyBWriteKeyBTrailer() const
230
+{
231
+    bool c1 = getBit(1, 3);
232
+    bool c2 = getBit(2, 3);
233
+    bool c3 = getBit(3, 3);
234
+    return (!c1 && c2 && c3) || (c1 && !c2 && !c3);
235
+}

+ 71
- 0
src/DBO/AccessBitsDbo.h Целия файл

@@ -0,0 +1,71 @@
1
+//
2
+// Created by robin on 7/21/16.
3
+//
4
+
5
+#ifndef MIFARE_TOOLS_ACCESSBITSDBO_H
6
+#define MIFARE_TOOLS_ACCESSBITSDBO_H
7
+
8
+
9
+#include <string>
10
+
11
+#ifndef FRIEND_TEST
12
+#define FRIEND_TEST(C, T)
13
+#endif
14
+
15
+class AccessBitsDbo
16
+{
17
+public:
18
+
19
+    static const char nonInvertedBitPosition[4][4];
20
+    static const char invertedBitPosition[4][4];
21
+
22
+    AccessBitsDbo();
23
+    AccessBitsDbo(const std::string& bits);
24
+
25
+    const char getUserData() const;
26
+    void setUserData(const char& data);
27
+
28
+    void setBit(const char& i, const char& j, const bool& value);
29
+    const bool getBit(const char& i, const char& j) const;
30
+
31
+    const bool canKeyAReadBlock(const char& block) const;
32
+    const bool canKeyBReadBlock(const char& block) const;
33
+
34
+    const bool canKeyAWriteBlock(const char& block) const;
35
+    const bool canKeyBWriteBlock(const char& block) const;
36
+
37
+    const bool canKeyAIncrementBlock(const char& block) const;
38
+    const bool canKeyBIncrementBlock(const char& block) const;
39
+
40
+    const bool canKeyADecrementBlock(const char& block) const;
41
+    const bool canKeyBDecrementBlock(const char& block) const;
42
+
43
+    const bool canKeyAReadKeyATrailer() const;
44
+    const bool canKeyBReadKeyATrailer() const;
45
+
46
+    const bool canKeyAWriteKeyATrailer() const;
47
+    const bool canKeyBWriteKeyATrailer() const;
48
+
49
+    const bool canKeyAReadAccessBitsTrailer() const;
50
+    const bool canKeyBReadAccessBitsTrailer() const;
51
+
52
+    const bool canKeyAWriteAccessBitsTrailer() const;
53
+    const bool canKeyBWriteAccessBitsTrailer() const;
54
+
55
+    const bool canKeyAReadKeyBTrailer() const;
56
+    const bool canKeyBReadKeyBTrailer() const;
57
+
58
+    const bool canKeyAWriteKeyBTrailer() const;
59
+    const bool canKeyBWriteKeyBTrailer() const;
60
+
61
+    static void setArrayBit(char *buf, const char &bitPosition, const bool &value);
62
+    static void setArrayBit(unsigned char *buf, const char &bitPosition, const bool &value);
63
+    static const bool getArrayBit(const char *buf, const char &bitPosition);
64
+    static const bool getArrayBit(const unsigned char *buf, const char &bitPosition);
65
+
66
+private:
67
+    std::string _bits;
68
+};
69
+
70
+
71
+#endif //MIFARE_TOOLS_ACCESSBITSDBO_H

+ 211
- 0
tests/test-main.cpp Целия файл

@@ -3,6 +3,7 @@
3 3
 #include <gtest/gtest.h>
4 4
 #include <Business/LibNfc.h>
5 5
 #include <Business/StringUtils.h>
6
+#include <DBO/AccessBitsDbo.h>
6 7
 
7 8
 TEST(StringUtils, rawToHumanChar)
8 9
 {
@@ -91,6 +92,216 @@ TEST(StringUtils, humanToRaw)
91 92
   ASSERT_EQ(StringUtils::humanToRaw("1a\n00f").getError(), "Malformed hex data at char 2");
92 93
 }
93 94
 
95
+TEST(AccessBitsDbo, getArrayBitimple)
96
+{
97
+  const unsigned char buf[] = {0x04};
98
+  ASSERT_FALSE(AccessBitsDbo::getArrayBit(buf, 0));
99
+  ASSERT_FALSE(AccessBitsDbo::getArrayBit(buf, 1));
100
+  ASSERT_FALSE(AccessBitsDbo::getArrayBit(buf, 2));
101
+  ASSERT_FALSE(AccessBitsDbo::getArrayBit(buf, 3));
102
+  ASSERT_FALSE(AccessBitsDbo::getArrayBit(buf, 4));
103
+  ASSERT_TRUE(AccessBitsDbo::getArrayBit(buf, 5));
104
+  ASSERT_FALSE(AccessBitsDbo::getArrayBit(buf, 6));
105
+  ASSERT_FALSE(AccessBitsDbo::getArrayBit(buf, 7));
106
+}
107
+
108
+TEST(AccessBitsDbo, getArrayBitMultiple)
109
+{
110
+  const unsigned char buf[] = {0x80, 0x14, 0x01};
111
+  ASSERT_TRUE(AccessBitsDbo::getArrayBit(buf, 0));
112
+  ASSERT_FALSE(AccessBitsDbo::getArrayBit(buf, 1));
113
+  ASSERT_FALSE(AccessBitsDbo::getArrayBit(buf, 2));
114
+  ASSERT_FALSE(AccessBitsDbo::getArrayBit(buf, 3));
115
+  ASSERT_FALSE(AccessBitsDbo::getArrayBit(buf, 4));
116
+  ASSERT_FALSE(AccessBitsDbo::getArrayBit(buf, 5));
117
+  ASSERT_FALSE(AccessBitsDbo::getArrayBit(buf, 6));
118
+  ASSERT_FALSE(AccessBitsDbo::getArrayBit(buf, 7));
119
+
120
+  ASSERT_FALSE(AccessBitsDbo::getArrayBit(buf, 8));
121
+  ASSERT_FALSE(AccessBitsDbo::getArrayBit(buf, 9));
122
+  ASSERT_FALSE(AccessBitsDbo::getArrayBit(buf, 10));
123
+  ASSERT_TRUE(AccessBitsDbo::getArrayBit(buf, 11));
124
+  ASSERT_FALSE(AccessBitsDbo::getArrayBit(buf, 12));
125
+  ASSERT_TRUE(AccessBitsDbo::getArrayBit(buf, 13));
126
+  ASSERT_FALSE(AccessBitsDbo::getArrayBit(buf, 14));
127
+  ASSERT_FALSE(AccessBitsDbo::getArrayBit(buf, 15));
128
+
129
+  ASSERT_FALSE(AccessBitsDbo::getArrayBit(buf, 16));
130
+  ASSERT_FALSE(AccessBitsDbo::getArrayBit(buf, 17));
131
+  ASSERT_FALSE(AccessBitsDbo::getArrayBit(buf, 18));
132
+  ASSERT_FALSE(AccessBitsDbo::getArrayBit(buf, 19));
133
+  ASSERT_FALSE(AccessBitsDbo::getArrayBit(buf, 20));
134
+  ASSERT_FALSE(AccessBitsDbo::getArrayBit(buf, 21));
135
+  ASSERT_FALSE(AccessBitsDbo::getArrayBit(buf, 22));
136
+  ASSERT_TRUE(AccessBitsDbo::getArrayBit(buf, 23));
137
+}
138
+
139
+TEST(AccessBitsDbo, getBit)
140
+{
141
+  const unsigned char buf[4] = {0x05, 0xa3, 0xcf, 0x00};
142
+  AccessBitsDbo dbo((const char*)buf);
143
+
144
+  ASSERT_FALSE(dbo.getBit(1, 0));
145
+  ASSERT_TRUE(dbo.getBit(2, 0));
146
+  ASSERT_FALSE(dbo.getBit(3, 0));
147
+
148
+  ASSERT_TRUE(dbo.getBit(1, 1));
149
+  ASSERT_TRUE(dbo.getBit(2, 1));
150
+  ASSERT_FALSE(dbo.getBit(3, 1));
151
+
152
+  ASSERT_FALSE(dbo.getBit(1, 2));
153
+  ASSERT_TRUE(dbo.getBit(2, 2));
154
+  ASSERT_TRUE(dbo.getBit(3, 2));
155
+
156
+  ASSERT_TRUE(dbo.getBit(1, 3));
157
+  ASSERT_TRUE(dbo.getBit(2, 3));
158
+  ASSERT_TRUE(dbo.getBit(3, 3));
159
+}
160
+
161
+TEST(AccessBitsDbo, canKeyDoThisOnThisBlock1)
162
+{
163
+  const unsigned char buf[4] = {0xff, 0x0f, 0x00, 0x00};
164
+  AccessBitsDbo dbo((const char*)buf);
165
+
166
+  ASSERT_TRUE(dbo.canKeyAReadBlock(0));
167
+  ASSERT_TRUE(dbo.canKeyBReadBlock(0));
168
+
169
+  ASSERT_TRUE(dbo.canKeyAWriteBlock(0));
170
+  ASSERT_TRUE(dbo.canKeyBWriteBlock(0));
171
+
172
+  ASSERT_TRUE(dbo.canKeyAIncrementBlock(0));
173
+  ASSERT_TRUE(dbo.canKeyBIncrementBlock(0));
174
+
175
+  ASSERT_TRUE(dbo.canKeyADecrementBlock(0));
176
+  ASSERT_TRUE(dbo.canKeyBDecrementBlock(0));
177
+}
178
+
179
+TEST(AccessBitsDbo, canKeyDoThisOnThisBlock2)
180
+{
181
+  const unsigned char buf[4] = {0xef, 0x0f, 0x01, 0x00};
182
+  AccessBitsDbo dbo((const char*)buf);
183
+
184
+  ASSERT_TRUE(dbo.canKeyAReadBlock(0));
185
+  ASSERT_TRUE(dbo.canKeyBReadBlock(0));
186
+
187
+  ASSERT_FALSE(dbo.canKeyAWriteBlock(0));
188
+  ASSERT_FALSE(dbo.canKeyBWriteBlock(0));
189
+
190
+  ASSERT_FALSE(dbo.canKeyAIncrementBlock(0));
191
+  ASSERT_FALSE(dbo.canKeyBIncrementBlock(0));
192
+
193
+  ASSERT_FALSE(dbo.canKeyADecrementBlock(0));
194
+  ASSERT_FALSE(dbo.canKeyBDecrementBlock(0));
195
+}
196
+
197
+TEST(AccessBitsDbo, canKeyDoThisOnThisBlock3)
198
+{
199
+  const unsigned char buf[4] = {0xfe, 0x1f, 0x00, 0x00};
200
+  AccessBitsDbo dbo((const char*)buf);
201
+
202
+  ASSERT_TRUE(dbo.canKeyAReadBlock(0));
203
+  ASSERT_TRUE(dbo.canKeyBReadBlock(0));
204
+
205
+  ASSERT_FALSE(dbo.canKeyAWriteBlock(0));
206
+  ASSERT_TRUE(dbo.canKeyBWriteBlock(0));
207
+
208
+  ASSERT_FALSE(dbo.canKeyAIncrementBlock(0));
209
+  ASSERT_FALSE(dbo.canKeyBIncrementBlock(0));
210
+
211
+  ASSERT_FALSE(dbo.canKeyADecrementBlock(0));
212
+  ASSERT_FALSE(dbo.canKeyBDecrementBlock(0));
213
+}
214
+
215
+TEST(AccessBitsDbo, canKeyDoThisOnThisBlock4)
216
+{
217
+  const unsigned char buf[4] = {0xee, 0x1f, 0x01, 0x00};
218
+  AccessBitsDbo dbo((const char*)buf);
219
+
220
+  ASSERT_TRUE(dbo.canKeyAReadBlock(0));
221
+  ASSERT_TRUE(dbo.canKeyBReadBlock(0));
222
+
223
+  ASSERT_FALSE(dbo.canKeyAWriteBlock(0));
224
+  ASSERT_TRUE(dbo.canKeyBWriteBlock(0));
225
+
226
+  ASSERT_FALSE(dbo.canKeyAIncrementBlock(0));
227
+  ASSERT_TRUE(dbo.canKeyBIncrementBlock(0));
228
+
229
+  ASSERT_TRUE(dbo.canKeyADecrementBlock(0));
230
+  ASSERT_TRUE(dbo.canKeyBDecrementBlock(0));
231
+}
232
+
233
+TEST(AccessBitsDbo, canKeyDoThisOnThisBlock5)
234
+{
235
+  const unsigned char buf[4] = {0xff, 0x0e, 0x10, 0x00};
236
+  AccessBitsDbo dbo((const char*)buf);
237
+
238
+  ASSERT_TRUE(dbo.canKeyAReadBlock(0));
239
+  ASSERT_TRUE(dbo.canKeyBReadBlock(0));
240
+
241
+  ASSERT_FALSE(dbo.canKeyAWriteBlock(0));
242
+  ASSERT_FALSE(dbo.canKeyBWriteBlock(0));
243
+
244
+  ASSERT_FALSE(dbo.canKeyAIncrementBlock(0));
245
+  ASSERT_FALSE(dbo.canKeyBIncrementBlock(0));
246
+
247
+  ASSERT_TRUE(dbo.canKeyADecrementBlock(0));
248
+  ASSERT_TRUE(dbo.canKeyBDecrementBlock(0));
249
+}
250
+
251
+TEST(AccessBitsDbo, canKeyDoThisOnThisBlock6)
252
+{
253
+  const unsigned char buf[4] = {0xef, 0x0e, 0x11, 0x00};
254
+  AccessBitsDbo dbo((const char*)buf);
255
+
256
+  ASSERT_FALSE(dbo.canKeyAReadBlock(0));
257
+  ASSERT_TRUE(dbo.canKeyBReadBlock(0));
258
+
259
+  ASSERT_FALSE(dbo.canKeyAWriteBlock(0));
260
+  ASSERT_TRUE(dbo.canKeyBWriteBlock(0));
261
+
262
+  ASSERT_FALSE(dbo.canKeyAIncrementBlock(0));
263
+  ASSERT_FALSE(dbo.canKeyBIncrementBlock(0));
264
+
265
+  ASSERT_FALSE(dbo.canKeyADecrementBlock(0));
266
+  ASSERT_FALSE(dbo.canKeyBDecrementBlock(0));
267
+}
268
+
269
+TEST(AccessBitsDbo, canKeyDoThisOnThisBlock7)
270
+{
271
+  const unsigned char buf[4] = {0xfe, 0x1e, 0x10, 0x00};
272
+  AccessBitsDbo dbo((const char*)buf);
273
+
274
+  ASSERT_FALSE(dbo.canKeyAReadBlock(0));
275
+  ASSERT_TRUE(dbo.canKeyBReadBlock(0));
276
+
277
+  ASSERT_FALSE(dbo.canKeyAWriteBlock(0));
278
+  ASSERT_FALSE(dbo.canKeyBWriteBlock(0));
279
+
280
+  ASSERT_FALSE(dbo.canKeyAIncrementBlock(0));
281
+  ASSERT_FALSE(dbo.canKeyBIncrementBlock(0));
282
+
283
+  ASSERT_FALSE(dbo.canKeyADecrementBlock(0));
284
+  ASSERT_FALSE(dbo.canKeyBDecrementBlock(0));
285
+}
286
+
287
+TEST(AccessBitsDbo, canKeyDoThisOnThisBlock8)
288
+{
289
+  const unsigned char buf[4] = {0xee, 0x1e, 0x11, 0x00};
290
+  AccessBitsDbo dbo((const char*)buf);
291
+
292
+  ASSERT_FALSE(dbo.canKeyAReadBlock(0));
293
+  ASSERT_FALSE(dbo.canKeyBReadBlock(0));
294
+
295
+  ASSERT_FALSE(dbo.canKeyAWriteBlock(0));
296
+  ASSERT_FALSE(dbo.canKeyBWriteBlock(0));
297
+
298
+  ASSERT_FALSE(dbo.canKeyAIncrementBlock(0));
299
+  ASSERT_FALSE(dbo.canKeyBIncrementBlock(0));
300
+
301
+  ASSERT_FALSE(dbo.canKeyADecrementBlock(0));
302
+  ASSERT_FALSE(dbo.canKeyBDecrementBlock(0));
303
+}
304
+
94 305
 int main(int argc, char* argv[])
95 306
 {
96 307
     std::cout << "LibNfc version: " << LibNfc::getVersion() << std::endl;

Loading…
Отказ
Запис