Browse Source

finished command, basic command, byte array

master
Robin Thoni 9 years ago
parent
commit
e1d6626ca7
6 changed files with 41 additions and 4 deletions
  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 View File

2
 // Created by robin on 6/27/15.
2
 // Created by robin on 6/27/15.
3
 //
3
 //
4
 
4
 
5
+#include <string>
5
 #include "ScBasicCommand.h"
6
 #include "ScBasicCommand.h"
6
 
7
 
7
 ScBasicCommand::ScBasicCommand(const std::string &data)
8
 ScBasicCommand::ScBasicCommand(const std::string &data)
8
 {
9
 {
10
+    DWORD size = 0;
9
     for (auto c : data)
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
 ScByteArray ScBasicCommand::getData() const
31
 ScByteArray ScBasicCommand::getData() const

+ 3
- 1
DBO/ScBasicCommand.h View File

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

+ 2
- 0
DBO/ScByteArray.h View File

16
 
16
 
17
     inline ScByteArray(const ScByteArray& data);
17
     inline ScByteArray(const ScByteArray& data);
18
 
18
 
19
+    inline ~ScByteArray();
20
+
19
     inline DWORD getSize() const;
21
     inline DWORD getSize() const;
20
 
22
 
21
     inline BYTE* getData() const;
23
     inline BYTE* getData() const;

+ 2
- 2
DBO/ScByteArray.hxx View File

23
     _data = (BYTE*)memcpy(malloc(_size), data._data, _size);
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
 BYTE* ScByteArray::getData() const
31
 BYTE* ScByteArray::getData() const

+ 13
- 0
DBO/ScCommand.cpp View File

3
 //
3
 //
4
 
4
 
5
 #include "ScCommand.h"
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 View File

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

Loading…
Cancel
Save