forked from johguse/ERADICATE2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModeFactory.cpp
90 lines (70 loc) · 1.97 KB
/
ModeFactory.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "ModeFactory.hpp"
#include "hexadecimal.hpp"
mode ModeFactory::benchmark() {
mode r;
r.function = ModeFunction::Benchmark;
return r;
}
mode ModeFactory::zerobytes() {
mode r;
r.function = ModeFunction::ZeroBytes;
return r;
}
mode ModeFactory::zeros() {
return range(0, 0);
}
mode ModeFactory::matching(const std::string strHex) {
mode r;
r.function = ModeFunction::Matching;
std::fill( r.data1, r.data1 + sizeof(r.data1), cl_uchar(0) );
std::fill( r.data2, r.data2 + sizeof(r.data2), cl_uchar(0) );
auto index = 0;
for( size_t i = 0; i < strHex.size(); i += 2 ) {
const auto indexHi = hexValueNoException(strHex[i]);
const auto indexLo = i + 1 < strHex.size() ? hexValueNoException(strHex[i+1]) : std::string::npos;
const auto valHi = (indexHi == std::string::npos) ? 0 : indexHi << 4;
const auto valLo = (indexLo == std::string::npos) ? 0 : indexLo;
const auto maskHi = (indexHi == std::string::npos) ? 0 : 0xF << 4;
const auto maskLo = (indexLo == std::string::npos) ? 0 : 0xF;
r.data1[index] = maskHi | maskLo;
r.data2[index] = valHi | valLo;
++index;
}
return r;
}
mode ModeFactory::leading(const char charLeading) {
mode r;
r.function = ModeFunction::Leading;
r.data1[0] = static_cast<cl_uchar>(hexValue(charLeading));
return r;
}
mode ModeFactory::range(const cl_uchar min, const cl_uchar max) {
mode r;
r.function = ModeFunction::Range;
r.data1[0] = min;
r.data2[0] = max;
return r;
}
mode ModeFactory::letters() {
return range(10, 15);
}
mode ModeFactory::numbers() {
return range(0, 9);
}
mode ModeFactory::leadingRange(const cl_uchar min, const cl_uchar max) {
mode r;
r.function = ModeFunction::LeadingRange;
r.data1[0] = min;
r.data2[0] = max;
return r;
}
mode ModeFactory::mirror() {
mode r;
r.function = ModeFunction::Mirror;
return r;
}
mode ModeFactory::doubles() {
mode r;
r.function = ModeFunction::Doubles;
return r;
}