forked from johguse/ERADICATE2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModeFactory.cpp
164 lines (120 loc) · 4.33 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#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::leading(const char charLeading) {
mode r;
r.function = ModeFunction::Leading;
r.data1[0] = static_cast<cl_uchar>(hexValue(charLeading));
return r;
}
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::leadtrailing(const std::string start, const std::string end) {
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 index2 = 0;
for( size_t i = 0; i < end.size(); i += 2 ) {
const auto indexHi = hexValueNoException(end[i]);
const auto indexLo = i + 1 < end.size() ? hexValueNoException(end[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[20 - end.size()/2 + index2] = maskHi | maskLo;
r.data2[20 - end.size()/2 + index2] = valHi | valLo;
++index2;
}
auto index = 0;
for( size_t i = 0; i < start.size(); i += 2 ) {
const auto indexHi = hexValueNoException(start[i]);
const auto indexLo = i + 1 < start.size() ? hexValueNoException(start[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::trailing(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[20 - strHex.size()/2 + index] = maskHi | maskLo;
r.data2[20 - strHex.size()/2 + index] = valHi | valLo;
++index;
}
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;
}