Sfoglia il codice sorgente

finished command, basic command, byte array

master
Robin Thoni 9 anni fa
parent
commit
e1d6626ca7
6 ha cambiato i file con 41 aggiunte e 4 eliminazioni
  1. 17
    1
      DBO/ScBasicCommand.cpp
  2. 3
    1
      DBO/ScBasicCommand.h
  3. 2
    0
      DBO/ScByteArray.h
  4. 2
    2
      DBO/ScByteArray.hxx
  5. 13
    0
      DBO/ScCommand.cpp
  6. 4
    0
      DBO/ScCommand.h

+ 17
- 1
DBO/ScBasicCommand.cpp Vedi File

@@ -2,14 +2,30 @@
2 2
 // Created by robin on 6/27/15.
3 3
 //
4 4
 
5
+#include <string>
5 6
 #include "ScBasicCommand.h"
6 7
 
7 8
 ScBasicCommand::ScBasicCommand(const std::string &data)
8 9
 {
10
+    DWORD size = 0;
9 11
     for (auto c : data)
10 12
     {
11
-
13
+        if (isxdigit(c))
14
+            ++size;
15
+    }
16
+    auto d = new BYTE[size];
17
+    size = 0;
18
+    for (int i = 0; i < data.size(); ++i)
19
+    {
20
+        auto c = data[i];
21
+        if (isxdigit(c))
22
+            d[size++] = hexToDec(c);
12 23
     }
24
+    _data = ScByteArray(d, size);
25
+}
26
+
27
+ScBasicCommand::~ScBasicCommand()
28
+{
13 29
 }
14 30
 
15 31
 ScByteArray ScBasicCommand::getData() const

+ 3
- 1
DBO/ScBasicCommand.h Vedi File

@@ -6,7 +6,7 @@
6 6
 # define LIBPCSC_CPPTOOLS_SCBASICCOMMAND_H
7 7
 
8 8
 
9
-# include <bits/stringfwd.h>
9
+# include <string>
10 10
 # include "ScCommand.h"
11 11
 
12 12
 class ScBasicCommand : public ScCommand {
@@ -14,6 +14,8 @@ class ScBasicCommand : public ScCommand {
14 14
 public:
15 15
     ScBasicCommand(const std::string& data);
16 16
 
17
+    virtual ~ScBasicCommand();
18
+
17 19
     virtual ScByteArray getData() const override;
18 20
 
19 21
 private:

+ 2
- 0
DBO/ScByteArray.h Vedi File

@@ -16,6 +16,8 @@ public:
16 16
 
17 17
     inline ScByteArray(const ScByteArray& data);
18 18
 
19
+    inline ~ScByteArray();
20
+
19 21
     inline DWORD getSize() const;
20 22
 
21 23
     inline BYTE* getData() const;

+ 2
- 2
DBO/ScByteArray.hxx Vedi File

@@ -23,9 +23,9 @@ ScByteArray::ScByteArray(const ScByteArray &data)
23 23
     _data = (BYTE*)memcpy(malloc(_size), data._data, _size);
24 24
 }
25 25
 
26
-DWORD ScByteArray::getSize() const
26
+ScByteArray::~ScByteArray()
27 27
 {
28
-    return _size;
28
+    delete[] _data;
29 29
 }
30 30
 
31 31
 BYTE* ScByteArray::getData() const

+ 13
- 0
DBO/ScCommand.cpp Vedi File

@@ -3,3 +3,16 @@
3 3
 //
4 4
 
5 5
 #include "ScCommand.h"
6
+
7
+ScCommand::~ScCommand()
8
+{
9
+}
10
+
11
+int ScCommand::hexToDec(const char c)
12
+{
13
+    if (c >= 'a')
14
+        return 10 + (c - ('a' - 'A')) - 'A';
15
+    if (c >= 'A')
16
+        return 10 + c - 'A';
17
+    return c - '0';
18
+}

+ 4
- 0
DBO/ScCommand.h Vedi File

@@ -10,8 +10,12 @@
10 10
 class ScCommand {
11 11
 
12 12
 public:
13
+    virtual ~ScCommand();
14
+
13 15
     virtual ScByteArray getData() const = 0;
14 16
 
17
+    static int hexToDec(const char c);
18
+
15 19
 };
16 20
 
17 21
 # include "ScCommand.hxx"

Loading…
Annulla
Salva