diff --git a/src/actions/transformations/hex_decode.cc b/src/actions/transformations/hex_decode.cc index 5ee9bd8d..0265e67a 100644 --- a/src/actions/transformations/hex_decode.cc +++ b/src/actions/transformations/hex_decode.cc @@ -30,24 +30,28 @@ namespace ModSecurity { namespace actions { namespace transformations { + HexDecode::HexDecode(std::string action) : Transformation(action) { this->action_kind = 1; } + std::string HexDecode::evaluate(std::string value, Assay *assay) { - /** - * @todo Implement the transformation HexDecode - */ - if (assay) { -#ifndef NO_LOGS - assay->debug(4, "Transformation HexDecode is not implemented yet."); -#endif + int len = value.length(); + std::string newString; + + for(int i=0; i< len; i+=2) { + std::string byte = value.substr(i,2); + char chr = (char) (int)strtol(byte.c_str(), NULL, 16); + newString.push_back(chr); } - return value; + + return newString; } + } // namespace transformations } // namespace actions } // namespace ModSecurity diff --git a/src/actions/transformations/transformation.cc b/src/actions/transformations/transformation.cc index 5a48f2f0..e1e3b866 100644 --- a/src/actions/transformations/transformation.cc +++ b/src/actions/transformations/transformation.cc @@ -80,7 +80,7 @@ Transformation* Transformation::instantiate(std::string a) { IF_MATCH(compress_whitespace) { return new CompressWhitespace(a); } IF_MATCH(cssDecode) { return new CssDecode(a); } IF_MATCH(escape_seq_decode) { return new EscapeSeqDecode(a); } - IF_MATCH(hex_decode) { return new HexDecode(a); } + IF_MATCH(hexDecode) { return new HexDecode(a); } IF_MATCH(hexEncode) { return new HexEncode(a); } IF_MATCH(htmlEntityDecode) { return new HtmlEntityDecode(a); } IF_MATCH(jsDecode) { return new JsDecode(a); } diff --git a/test/test-cases/secrules-language-tests b/test/test-cases/secrules-language-tests index 444dfbea..635d86d6 160000 --- a/test/test-cases/secrules-language-tests +++ b/test/test-cases/secrules-language-tests @@ -1 +1 @@ -Subproject commit 444dfbea3390cf54f6d59e331bc4fbcabb77eb4e +Subproject commit 635d86d6f87d56de656da73e3026a6ef2cc9a5f1