41 static void DetectTransformPcrexform(
InspectionBuffer *buffer,
void *options);
50 "modify buffer via PCRE before inspection";
53 DetectTransformPcrexform;
55 DetectTransformPcrexformFree;
57 DetectTransformPcrexformSetup;
68 pcre2_match_context_free(pxd->
context);
69 pcre2_code_free(pxd->
regex);
94 pxd->
context = pcre2_match_context_create(NULL);
103 pxd->
regex = pcre2_compile((PCRE2_SPTR8)regexstr, PCRE2_ZERO_TERMINATED, 0, &en, &eo, NULL);
104 if (pxd->
regex == NULL) {
105 PCRE2_UCHAR buffer[256];
106 pcre2_get_error_message(en, buffer,
sizeof(buffer));
107 SCLogError(
"pcre2 compile of \"%s\" failed at "
109 regexstr, (
int)eo, buffer);
110 pcre2_match_context_free(pxd->
context);
116 if (pcre2_pattern_info(pxd->
regex, PCRE2_INFO_CAPTURECOUNT, &nb) < 0) {
117 SCLogError(
"pcrexform failed getting info about capturecount");
118 DetectTransformPcrexformFree(
de_ctx, pxd);
122 SCLogError(
"pcrexform needs exactly one substring capture, found %" PRIu32, nb);
123 DetectTransformPcrexformFree(
de_ctx, pxd);
129 DetectTransformPcrexformFree(
de_ctx, pxd);
135 static void DetectTransformPcrexform(
InspectionBuffer *buffer,
void *options)
137 const char *input = (
const char *)buffer->
inspect;
141 pcre2_match_data *match = pcre2_match_data_create_from_pattern(pxd->
regex, NULL);
142 int ret = pcre2_match(pxd->
regex, (PCRE2_SPTR8)input, input_len, 0, 0, match, pxd->
context);
147 ret = pcre2_substring_get_bynumber(match, 1, (PCRE2_UCHAR8 **)&
str, &caplen);
151 pcre2_substring_free((PCRE2_UCHAR8 *)
str);
154 pcre2_match_data_free(match);