108 Packet *
p,
Flow *
f,
const uint8_t *buffer,
const uint32_t buffer_len,
109 const uint64_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;
162 if (distance < 0 && (uint32_t)(abs(distance)) >
offset)
167 SCLogDebug(
"cd->distance %"PRIi32
", offset %"PRIu32
", depth %"PRIu32,
175 (int32_t)(prev_buffer_offset +
177 depth = prev_buffer_offset +
181 if ((int32_t)depth > (int32_t)(prev_buffer_offset + cd->
within + distance)) {
182 depth = prev_buffer_offset + cd->
within + distance;
185 SCLogDebug(
"cd->within %"PRIi32
", det_ctx->buffer_offset %"PRIu32
", depth %"PRIu32,
186 cd->
within, prev_buffer_offset, depth);
189 if (stream_start_offset != 0 && prev_buffer_offset == 0) {
190 if (depth <= stream_start_offset) {
192 }
else if (depth >= (stream_start_offset + buffer_len)) {
195 depth = depth - (uint32_t)stream_start_offset;
203 depth = prev_buffer_offset +
207 if (cd->
depth != 0) {
208 if ((cd->
depth + prev_buffer_offset) < depth) {
209 depth = prev_buffer_offset + cd->
depth;
233 if (cd->
depth != 0) {
239 if (depth <= stream_start_offset) {
241 }
else if (depth >= (stream_start_offset + buffer_len)) {
244 depth = (uint32_t)(depth - stream_start_offset);
255 prev_buffer_offset = 0;
268 if (prev_offset != 0)
273 if (depth > buffer_len)
278 if (
offset > depth || depth == 0) {
286 const uint8_t *sbuffer = buffer +
offset;
287 uint32_t sbuffer_len = depth -
offset;
288 SCLogDebug(
"sbuffer_len %" PRIu32
" depth: %" PRIu32
", buffer_len: %" PRIu32,
289 sbuffer_len, depth, buffer_len);
291 BUG_ON(sbuffer_len > buffer_len);
293 const uint8_t *found;
295 SCLogDebug(
"depth < buffer_len while DETECT_CONTENT_ENDS_WITH is set. Can't possibly match.");
313 goto no_match_discontinue;
322 uint32_t match_offset = (uint32_t)((found - buffer) + cd->
content_len);
324 SCLogDebug(
"content %" PRIu32
" matched at offset %" PRIu32
325 ", but negated so no match",
326 cd->
id, match_offset);
332 if (sbuffer_len != match_offset) {
333 SCLogDebug(
"content \"%s\" %" PRIu32
" matched at offset %" PRIu32
334 ", but not at end of buffer so match",
340 goto no_match_discontinue;
345 SCLogDebug(
"content %" PRIu32
" matched at offset %" PRIu32
"", cd->
id, match_offset);
372 int r = DetectEngineContentInspectionInternal(det_ctx,
ctx, s, smd + 1,
p,
f,
373 buffer, buffer_len, stream_start_offset,
flags, inspection_mode);
376 }
else if (r == -1) {
377 SCLogDebug(
"'next sm' said to discontinue this right now");
384 SCLogDebug(
"'next sm' does not depend on me, so we can give up");
388 SCLogDebug(
"'next sm' depends on me %p, lets see what we can do (flags %u)", cd,
392 prev_offset = (match_offset - (cd->
content_len - 1));
393 SCLogDebug(
"trying to see if there is another match after prev_offset %" PRIu32,
408 uint32_t dataat = id->
dataat;
411 if (be_value >= 100000000) {
413 SCLogDebug(
"extracted value %"PRIu64
" very big: no match", be_value);
416 SCLogDebug(
"extracted value way %"PRIu64
" very big: match", be_value);
419 dataat = (uint32_t)be_value;
420 SCLogDebug(
"isdataat: using value %u from byte_extract local_id %u", dataat, id->
dataat);
425 SCLogDebug(
"det_ctx->buffer_offset + dataat %"PRIu32
" > %"PRIu32, det_ctx->
buffer_offset + dataat, buffer_len);
429 goto no_match_discontinue;
440 if (dataat < buffer_len) {
444 goto no_match_discontinue;
450 SCLogDebug(
"absolute isdataat mismatch, id->isdataat %"PRIu32
", buffer_len %"PRIu32
"", dataat, buffer_len);
454 goto no_match_discontinue;
464 uint32_t prev_offset = 0;
473 SCLogDebug(
"no relative match coming up, so this is a match");
484 r = DetectEngineContentInspectionInternal(det_ctx,
ctx, s, smd + 1,
p,
f, buffer,
485 buffer_len, stream_start_offset,
flags, inspection_mode);
488 }
else if (r == -1) {
492 if (prev_offset == 0) {
508 uint16_t btflags = btd->
flags;
510 uint64_t value = btd->
value;
511 int32_t nbytes = btd->
nbytes;
529 btflags |= ((
flags & DETECT_CI_FLAGS_DCE_LE) ?
542 uint16_t bjflags = bjd->
flags;
558 SCLogDebug(
"[BJ] using nbytes value %d [index n/a]", nbytes);
566 bjflags |= ((
flags & DETECT_CI_FLAGS_DCE_LE) ?
571 det_ctx, s, smd->
ctx, buffer, buffer_len, bjflags, nbytes,
offset)) {
579 const SCDetectByteExtractData *bed = (
const SCDetectByteExtractData *)smd->
ctx;
580 uint8_t endian = bed->endian;
584 if ((bed->flags & DETECT_BYTE_EXTRACT_FLAG_ENDIAN) && endian == EndianDCE &&
585 flags & (DETECT_CI_FLAGS_DCE_LE | DETECT_CI_FLAGS_DCE_BE)) {
589 endian |= ((
flags & DETECT_CI_FLAGS_DCE_LE) ? LittleEndian : BigEndian);
601 SCLogDebug(
"[BE] Fetched value for index %d: %" PRIu64, bed->local_id,
607 const DetectByteMathData *bmd = (
const DetectByteMathData *)smd->
ctx;
608 uint8_t endian = bmd->endian;
612 if ((bmd->flags & DETECT_BYTEMATH_FLAG_ENDIAN) && endian == (int)EndianDCE &&
613 flags & (DETECT_CI_FLAGS_DCE_LE | DETECT_CI_FLAGS_DCE_BE)) {
616 endian = (uint8_t)((
flags & DETECT_CI_FLAGS_DCE_LE) ? LittleEndian : BigEndian);
619 if (bmd->flags & DETECT_BYTEMATH_FLAG_RVALUE_VAR) {
622 rvalue = bmd->rvalue;
626 if (bmd->flags & DETECT_BYTEMATH_FLAG_NBYTES_VAR) {
629 nbytes = bmd->nbytes;
641 SCLogDebug(
"[BM] Fetched value for index %d: %" PRIu64, bmd->local_id,
648 const uint64_t data_size = buffer_len + stream_start_offset;
651 goto no_match_discontinue;
665 goto no_match_discontinue;
675 goto no_match_discontinue;
681 const DetectUrilenData *urilend = (
const DetectUrilenData *)smd->
ctx;
682 if (buffer_len > UINT16_MAX) {
691 goto no_match_discontinue;
710 int r = DetectEngineContentInspectionInternal(det_ctx,
ctx, s,
739 no_match_discontinue:
748 int r = DetectEngineContentInspectionInternal(det_ctx,
ctx, s, smd + 1,
p,
f, buffer,
749 buffer_len, stream_start_offset,
flags, inspection_mode);
763 const uint32_t buffer_len,
const uint64_t stream_start_offset,
const uint8_t
flags,
770 int r = DetectEngineContentInspectionInternal(det_ctx, &
ctx, s, smd,
p,
f, buffer, buffer_len,
771 stream_start_offset,
flags, inspection_mode);
791 int r = DetectEngineContentInspectionInternal(det_ctx, &
ctx, s, smd,
p,
f, b->
inspect,
802 bool absent_data =
false;