108 Packet *p,
Flow *f,
const uint8_t *buffer,
const uint32_t buffer_len,
109 const uint32_t stream_start_offset,
const uint8_t
flags,
115 ctx->recursion.count++;
122 if (smd == NULL || buffer == NULL) {
129 SCLogDebug(
"inspecting content %"PRIu32
" buffer_len %"PRIu32, cd->
id, buffer_len);
145 uint32_t prev_offset = 0;
149 uint32_t depth = buffer_len;
154 offset = prev_buffer_offset;
161 if (distance < 0 && (uint32_t)(abs(distance)) >
offset)
166 SCLogDebug(
"cd->distance %"PRIi32
", offset %"PRIu32
", depth %"PRIu32,
172 if ((int32_t)depth > (int32_t)(prev_buffer_offset + det_ctx->
byte_values[cd->
within] + distance)) {
176 if ((int32_t)depth > (int32_t)(prev_buffer_offset + cd->
within + distance)) {
177 depth = prev_buffer_offset + cd->
within + distance;
180 SCLogDebug(
"cd->within %"PRIi32
", det_ctx->buffer_offset %"PRIu32
", depth %"PRIu32,
181 cd->
within, prev_buffer_offset, depth);
184 if (stream_start_offset != 0 && prev_buffer_offset == 0) {
185 if (depth <= stream_start_offset) {
187 }
else if (depth >= (stream_start_offset + buffer_len)) {
190 depth = depth - stream_start_offset;
200 if (cd->
depth != 0) {
201 if ((cd->
depth + prev_buffer_offset) < depth) {
202 depth = prev_buffer_offset + cd->
depth;
223 if (cd->
depth != 0) {
229 if (depth <= stream_start_offset) {
231 }
else if (depth >= (stream_start_offset + buffer_len)) {
234 depth = depth - stream_start_offset;
243 prev_buffer_offset = 0;
256 if (prev_offset != 0)
261 if (depth > buffer_len)
266 if (
offset > depth || depth == 0) {
274 const uint8_t *sbuffer = buffer +
offset;
275 uint32_t sbuffer_len = depth -
offset;
276 SCLogDebug(
"sbuffer_len %" PRIu32
" depth: %" PRIu32
", buffer_len: %" PRIu32,
277 sbuffer_len, depth, buffer_len);
279 BUG_ON(sbuffer_len > buffer_len);
281 const uint8_t *found;
283 SCLogDebug(
"depth < buffer_len while DETECT_CONTENT_ENDS_WITH is set. Can't possibly match.");
301 goto no_match_discontinue;
310 uint32_t match_offset = (uint32_t)((found - buffer) + cd->
content_len);
312 SCLogDebug(
"content %" PRIu32
" matched at offset %" PRIu32
313 ", but negated so no match",
314 cd->
id, match_offset);
320 if (sbuffer_len != match_offset) {
321 SCLogDebug(
"content \"%s\" %" PRIu32
" matched at offset %" PRIu32
322 ", but not at end of buffer so match",
328 goto no_match_discontinue;
333 SCLogDebug(
"content %" PRIu32
" matched at offset %" PRIu32
"", cd->
id, match_offset);
360 int r = DetectEngineContentInspectionInternal(det_ctx,
ctx, s, smd + 1, p, f,
361 buffer, buffer_len, stream_start_offset,
flags, inspection_mode);
364 }
else if (r == -1) {
365 SCLogDebug(
"'next sm' said to discontinue this right now");
372 SCLogDebug(
"'next sm' does not depend on me, so we can give up");
376 SCLogDebug(
"'next sm' depends on me %p, lets see what we can do (flags %u)", cd,
380 prev_offset = (match_offset - (cd->
content_len - 1));
381 SCLogDebug(
"trying to see if there is another match after prev_offset %" PRIu32,
389 uint32_t dataat = id->
dataat;
392 if (be_value >= 100000000) {
394 SCLogDebug(
"extracted value %"PRIu64
" very big: no match", be_value);
397 SCLogDebug(
"extracted value way %"PRIu64
" very big: match", be_value);
400 dataat = (uint32_t)be_value;
401 SCLogDebug(
"isdataat: using value %u from byte_extract local_id %u", dataat, id->
dataat);
406 SCLogDebug(
"det_ctx->buffer_offset + dataat %"PRIu32
" > %"PRIu32, det_ctx->
buffer_offset + dataat, buffer_len);
410 goto no_match_discontinue;
421 if (dataat < buffer_len) {
425 goto no_match_discontinue;
431 SCLogDebug(
"absolute isdataat mismatch, id->isdataat %"PRIu32
", buffer_len %"PRIu32
"", dataat, buffer_len);
435 goto no_match_discontinue;
445 uint32_t prev_offset = 0;
455 SCLogDebug(
"no relative match coming up, so this is a match");
466 r = DetectEngineContentInspectionInternal(det_ctx,
ctx, s, smd + 1, p, f, buffer,
467 buffer_len, stream_start_offset,
flags, inspection_mode);
470 }
else if (r == -1) {
480 uint16_t btflags = btd->
flags;
482 uint64_t value = btd->
value;
483 int32_t nbytes = btd->
nbytes;
512 uint16_t bjflags = bjd->
flags;
536 det_ctx, s, smd->
ctx, buffer, buffer_len, bjflags, nbytes,
offset)) {
544 const SCDetectByteExtractData *bed = (
const SCDetectByteExtractData *)smd->
ctx;
545 uint8_t endian = bed->endian;
549 if ((bed->flags & DETECT_BYTE_EXTRACT_FLAG_ENDIAN) && endian == EndianDCE &&
558 &det_ctx->
byte_values[bed->local_id], endian) != 1) {
562 SCLogDebug(
"[BE] Fetched value for index %d: %"PRIu64,
563 bed->local_id, det_ctx->
byte_values[bed->local_id]);
568 const DetectByteMathData *bmd = (
const DetectByteMathData *)smd->
ctx;
569 uint8_t endian = bmd->endian;
573 if ((bmd->flags & DETECT_BYTEMATH_FLAG_ENDIAN) && endian == (int)EndianDCE &&
580 if (bmd->flags & DETECT_BYTEMATH_FLAG_RVALUE_VAR) {
583 rvalue = bmd->rvalue;
587 if (bmd->flags & DETECT_BYTEMATH_FLAG_NBYTES_VAR) {
588 nbytes = (uint8_t)det_ctx->
byte_values[bmd->nbytes];
590 nbytes = bmd->nbytes;
594 &det_ctx->
byte_values[bmd->local_id], endian) != 1) {
598 SCLogDebug(
"[BM] Fetched value for index %d: %"PRIu64,
599 bmd->local_id, det_ctx->
byte_values[bmd->local_id]);
605 const uint64_t data_size = buffer_len + stream_start_offset;
608 goto no_match_discontinue;
622 goto no_match_discontinue;
632 goto no_match_discontinue;
638 const DetectUrilenData *urilend = (
const DetectUrilenData *)smd->
ctx;
639 if (buffer_len > UINT16_MAX) {
648 goto no_match_discontinue;
666 int r = DetectEngineContentInspectionInternal(det_ctx,
ctx, s,
695 no_match_discontinue:
704 int r = DetectEngineContentInspectionInternal(det_ctx,
ctx, s, smd + 1, p, f, buffer,
705 buffer_len, stream_start_offset,
flags, inspection_mode);
719 const uint32_t buffer_len,
const uint32_t stream_start_offset,
const uint8_t
flags,
726 int r = DetectEngineContentInspectionInternal(det_ctx, &
ctx, s, smd, p, f, buffer, buffer_len,
727 stream_start_offset,
flags, inspection_mode);
750 int r = DetectEngineContentInspectionInternal(det_ctx, &
ctx, s, smd, p, f, b->
inspect,