2020#include " src/actions/transformations/transformation.h"
2121
2222/* *
23- * for i in $(ls -l src/actions/transformations/*.h | awk {'print $9'}); do echo "#include \"$i\""; done;
23+ * for i in $(ls -l src/actions/transformations/\ *.h | awk {'print $9'}); do echo "#include \"$i\""; done;
2424 *
2525 */
2626#include " src/actions/transformations/base64_decode.h"
6464
6565
6666/* *
67- * for i in $(ls -l src/operators/*.h | awk {'print $9'}); do echo "#include \"$i\""; done;
67+ * for i in $(ls -l src/operators/\ *.h | awk {'print $9'}); do echo "#include \"$i\""; done;
6868 *
6969 */
7070#include " src/operators/begins_with.h"
@@ -121,6 +121,8 @@ using namespace modsecurity;
121121#endif
122122#include < signal.h>
123123#include < string.h>
124+ #include < memory>
125+ #include < vector>
124126
125127#ifndef __AFL_LOOP
126128#define __AFL_LOOP (x ) (1 )
@@ -132,7 +134,7 @@ inline void op_test(const std::string &opName, const std::string &s) {
132134 return ;
133135 }
134136 op->init (" " , nullptr );
135- op->evaluate (nullptr , nullptr , s, nullptr );
137+ op->evaluate (nullptr , nullptr , s);
136138 delete op;
137139}
138140
@@ -170,52 +172,34 @@ int main(int argc, char** argv) {
170172 /* *
171173 * Transformations, generated by:
172174 *
173- * for i in $(grep "class " -Ri src/actions/transformations/* | grep " :" | grep -v "InstantCache" | awk {'print $2'}); do echo $i *$(echo $i | awk '{print tolower($0)}') = new $i\(\"$i\"\)\; $(echo $i | awk '{print tolower($0)}')-\>evaluate\(s, NULL\)\; delete $(echo $i | awk '{print tolower($0)}')\;; done;
175+ * for i in $(grep "class " -Ri src/actions/transformations/\ * | grep " :" | grep -v "InstantCache" | awk {'print $2'}); do echo $i *$(echo $i | awk '{print tolower($0)}') = new $i\(\"$i\"\)\; $(echo $i | awk '{print tolower($0)}')-\>evaluate\(s, NULL\)\; delete $(echo $i | awk '{print tolower($0)}')\;; done;
174176 *
175177 */
176- Base64Decode *base64decode = new Base64Decode (" Base64Decode" ); base64decode->evaluate (s, NULL ); delete base64decode;
177- Base64DecodeExt *base64decodeext = new Base64DecodeExt (" Base64DecodeExt" ); base64decodeext->evaluate (s, NULL ); delete base64decodeext;
178- Base64Encode *base64encode = new Base64Encode (" Base64Encode" ); base64encode->evaluate (s, NULL ); delete base64encode;
179- CmdLine *cmdline = new CmdLine (" CmdLine" ); cmdline->evaluate (s, NULL ); delete cmdline;
180- CompressWhitespace *compresswhitespace = new CompressWhitespace (" CompressWhitespace" ); compresswhitespace->evaluate (s, NULL ); delete compresswhitespace;
181- CssDecode *cssdecode = new CssDecode (" CssDecode" ); cssdecode->evaluate (s, NULL ); delete cssdecode;
182- EscapeSeqDecode *escapeseqdecode = new EscapeSeqDecode (" EscapeSeqDecode" ); escapeseqdecode->evaluate (s, NULL ); delete escapeseqdecode;
183- HexDecode *hexdecode = new HexDecode (" HexDecode" ); hexdecode->evaluate (s, NULL ); delete hexdecode;
184- HexEncode *hexencode = new HexEncode (" HexEncode" ); hexencode->evaluate (s, NULL ); delete hexencode;
185- HtmlEntityDecode *htmlentitydecode = new HtmlEntityDecode (" HtmlEntityDecode" ); htmlentitydecode->evaluate (s, NULL ); delete htmlentitydecode;
186- JsDecode *jsdecode = new JsDecode (" JsDecode" ); jsdecode->evaluate (s, NULL ); delete jsdecode;
187- Length *length = new Length (" Length" ); length->evaluate (s, NULL ); delete length;
188- LowerCase *lowercase = new LowerCase (" LowerCase" ); lowercase->evaluate (s, NULL ); delete lowercase;
189- Md5 *md5 = new Md5 (" Md5" ); md5->evaluate (s, NULL ); delete md5;
190- None *none = new None (" None" ); none->evaluate (s, NULL ); delete none;
191- NormalisePath *normalisepath = new NormalisePath (" NormalisePath" ); normalisepath->evaluate (s, NULL ); delete normalisepath;
192- NormalisePathWin *normalisepathwin = new NormalisePathWin (" NormalisePathWin" ); normalisepathwin->evaluate (s, NULL ); delete normalisepathwin;
193- ParityEven7bit *parityeven7bit = new ParityEven7bit (" ParityEven7bit" ); parityeven7bit->evaluate (s, NULL ); delete parityeven7bit;
194- ParityOdd7bit *parityodd7bit = new ParityOdd7bit (" ParityOdd7bit" ); parityodd7bit->evaluate (s, NULL ); delete parityodd7bit;
195- ParityZero7bit *parityzero7bit = new ParityZero7bit (" ParityZero7bit" ); parityzero7bit->evaluate (s, NULL ); delete parityzero7bit;
196- RemoveComments *removecomments = new RemoveComments (" RemoveComments" ); removecomments->evaluate (s, NULL ); delete removecomments;
197- RemoveCommentsChar *removecommentschar = new RemoveCommentsChar (" RemoveCommentsChar" ); removecommentschar->evaluate (s, NULL ); delete removecommentschar;
198- RemoveNulls *removenulls = new RemoveNulls (" RemoveNulls" ); removenulls->evaluate (s, NULL ); delete removenulls;
199- RemoveWhitespace *removewhitespace = new RemoveWhitespace (" RemoveWhitespace" ); removewhitespace->evaluate (s, NULL ); delete removewhitespace;
200- ReplaceComments *replacecomments = new ReplaceComments (" ReplaceComments" ); replacecomments->evaluate (s, NULL ); delete replacecomments;
201- ReplaceNulls *replacenulls = new ReplaceNulls (" ReplaceNulls" ); replacenulls->evaluate (s, NULL ); delete replacenulls;
202- Sha1 *sha1 = new Sha1 (" Sha1" ); sha1->evaluate (s, NULL ); delete sha1;
203- SqlHexDecode *sqlhexdecode = new SqlHexDecode (" SqlHexDecode" ); sqlhexdecode->evaluate (s, NULL ); delete sqlhexdecode;
204- Transformation *transformation = new Transformation (" Transformation" ); transformation->evaluate (s, NULL ); delete transformation;
205- Trim *trim = new Trim (" Trim" ); trim->evaluate (s, NULL ); delete trim;
206- TrimLeft *trimleft = new TrimLeft (" TrimLeft" ); trimleft->evaluate (s, NULL ); delete trimleft;
207- TrimRight *trimright = new TrimRight (" TrimRight" ); trimright->evaluate (s, NULL ); delete trimright;
208- UpperCase *uppercase = new UpperCase (" UpperCase" ); uppercase->evaluate (s, NULL ); delete uppercase;
209- UrlDecode *urldecode = new UrlDecode (" UrlDecode" ); urldecode->evaluate (s, NULL ); delete urldecode;
210- UrlDecodeUni *urldecodeuni = new UrlDecodeUni (" UrlDecodeUni" ); urldecodeuni->evaluate (s, NULL ); delete urldecodeuni;
211- UrlEncode *urlencode = new UrlEncode (" UrlEncode" ); urlencode->evaluate (s, NULL ); delete urlencode;
212- Utf8ToUnicode *utf8tounicode = new Utf8ToUnicode (" Utf8ToUnicode" ); utf8tounicode->evaluate (s, NULL ); delete utf8tounicode;
178+ std::vector<std::string> transformationNames = {
179+ " Base64Decode" , " Base64DecodeExt" , " Base64Encode" , " CmdLine" ,
180+ " CompressWhitespace" , " CssDecode" , " EscapeSeqDecode" , " HexDecode" ,
181+ " HexEncode" , " HtmlEntityDecode" , " JsDecode" , " Length" , " LowerCase" ,
182+ " Md5" , " None" , " NormalisePath" , " NormalisePathWin" , " ParityEven7bit" ,
183+ " ParityOdd7bit" , " ParityZero7bit" , " RemoveComments" , " RemoveCommentsChar" ,
184+ " RemoveNulls" , " RemoveWhitespace" , " ReplaceComments" , " ReplaceNulls" ,
185+ " Sha1" , " SqlHexDecode" , " Transformation" , " Trim" , " TrimLeft" ,
186+ " TrimRight" , " UpperCase" , " UrlDecode" , " UrlDecodeUni" , " UrlEncode" ,
187+ " Utf8ToUnicode"
188+ };
189+ for (const auto &name : transformationNames) {
190+ std::unique_ptr<Transformation> transformation (Transformation::instantiate (name));
191+ if (transformation == nullptr ) {
192+ continue ;
193+ }
194+ std::string value = s;
195+ transformation->transform (value, t);
196+ }
213197
214198
215199 /* *
216200 * Operators, generated by:
217201 *
218- * for i in $(grep "class " -Ri src/operators/* | grep " :" | awk {'print $2'}); do echo $i *$(echo $i | awk '{print tolower($0)}') = new $i\(\"$i\", z, false\)\; $(echo $i | awk '{print tolower($0)}')-\>evaluate\(t, s\)\; delete $(echo $i | awk '{print tolower($0)}')\;; done;
202+ * for i in $(grep "class " -Ri src/operators/\ * | grep " :" | awk {'print $2'}); do echo $i *$(echo $i | awk '{print tolower($0)}') = new $i\(\"$i\", z, false\)\; $(echo $i | awk '{print tolower($0)}')-\>evaluate\(t, s\)\; delete $(echo $i | awk '{print tolower($0)}')\;; done;
219203 *
220204 */
221205op_test (" BeginsWith" , s);
0 commit comments