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,
174 if ((int32_t)depth > (int32_t)(prev_buffer_offset + det_ctx->
byte_values[cd->
within] + distance)) {
175 depth = prev_buffer_offset +
179 if ((int32_t)depth > (int32_t)(prev_buffer_offset + cd->
within + distance)) {
180 depth = prev_buffer_offset + cd->
within + distance;
183 SCLogDebug(
"cd->within %"PRIi32
", det_ctx->buffer_offset %"PRIu32
", depth %"PRIu32,
184 cd->
within, prev_buffer_offset, depth);
187 if (stream_start_offset != 0 && prev_buffer_offset == 0) {
188 if (depth <= stream_start_offset) {
190 }
else if (depth >= (stream_start_offset + buffer_len)) {
193 depth = depth - (uint32_t)stream_start_offset;
204 if (cd->
depth != 0) {
205 if ((cd->
depth + prev_buffer_offset) < depth) {
206 depth = prev_buffer_offset + cd->
depth;
230 if (cd->
depth != 0) {
236 if (depth <= stream_start_offset) {
238 }
else if (depth >= (stream_start_offset + buffer_len)) {
241 depth = (uint32_t)(depth - stream_start_offset);
252 prev_buffer_offset = 0;
265 if (prev_offset != 0)
270 if (depth > buffer_len)
275 if (
offset > depth || depth == 0) {
283 const uint8_t *sbuffer = buffer +
offset;
284 uint32_t sbuffer_len = depth -
offset;
285 SCLogDebug(
"sbuffer_len %" PRIu32
" depth: %" PRIu32
", buffer_len: %" PRIu32,
286 sbuffer_len, depth, buffer_len);
288 BUG_ON(sbuffer_len > buffer_len);
290 const uint8_t *found;
292 SCLogDebug(
"depth < buffer_len while DETECT_CONTENT_ENDS_WITH is set. Can't possibly match.");
310 goto no_match_discontinue;
319 uint32_t match_offset = (uint32_t)((found - buffer) + cd->
content_len);
321 SCLogDebug(
"content %" PRIu32
" matched at offset %" PRIu32
322 ", but negated so no match",
323 cd->
id, match_offset);
329 if (sbuffer_len != match_offset) {
330 SCLogDebug(
"content \"%s\" %" PRIu32
" matched at offset %" PRIu32
331 ", but not at end of buffer so match",
337 goto no_match_discontinue;
342 SCLogDebug(
"content %" PRIu32
" matched at offset %" PRIu32
"", cd->
id, match_offset);
369 int r = DetectEngineContentInspectionInternal(det_ctx,
ctx, s, smd + 1,
p,
f,
370 buffer, buffer_len, stream_start_offset,
flags, inspection_mode);
373 }
else if (r == -1) {
374 SCLogDebug(
"'next sm' said to discontinue this right now");
381 SCLogDebug(
"'next sm' does not depend on me, so we can give up");
385 SCLogDebug(
"'next sm' depends on me %p, lets see what we can do (flags %u)", cd,
389 prev_offset = (match_offset - (cd->
content_len - 1));
390 SCLogDebug(
"trying to see if there is another match after prev_offset %" PRIu32,
405 uint32_t dataat = id->
dataat;
408 if (be_value >= 100000000) {
410 SCLogDebug(
"extracted value %"PRIu64
" very big: no match", be_value);
413 SCLogDebug(
"extracted value way %"PRIu64
" very big: match", be_value);
416 dataat = (uint32_t)be_value;
417 SCLogDebug(
"isdataat: using value %u from byte_extract local_id %u", dataat, id->
dataat);
422 SCLogDebug(
"det_ctx->buffer_offset + dataat %"PRIu32
" > %"PRIu32, det_ctx->
buffer_offset + dataat, buffer_len);
426 goto no_match_discontinue;
437 if (dataat < buffer_len) {
441 goto no_match_discontinue;
447 SCLogDebug(
"absolute isdataat mismatch, id->isdataat %"PRIu32
", buffer_len %"PRIu32
"", dataat, buffer_len);
451 goto no_match_discontinue;
461 uint32_t prev_offset = 0;
470 SCLogDebug(
"no relative match coming up, so this is a match");
481 r = DetectEngineContentInspectionInternal(det_ctx,
ctx, s, smd + 1,
p,
f, buffer,
482 buffer_len, stream_start_offset,
flags, inspection_mode);
485 }
else if (r == -1) {
489 if (prev_offset == 0) {
505 uint16_t btflags = btd->
flags;
507 uint64_t value = btd->
value;
508 int32_t nbytes = btd->
nbytes;
526 btflags |= ((
flags & DETECT_CI_FLAGS_DCE_LE) ?
539 uint16_t bjflags = bjd->
flags;
555 SCLogDebug(
"[BJ] using nbytes value %d [index n/a]", nbytes);
563 bjflags |= ((
flags & DETECT_CI_FLAGS_DCE_LE) ?
568 det_ctx, s, smd->
ctx, buffer, buffer_len, bjflags, nbytes,
offset)) {
576 const SCDetectByteExtractData *bed = (
const SCDetectByteExtractData *)smd->
ctx;
577 uint8_t endian = bed->endian;
581 if ((bed->flags & DETECT_BYTE_EXTRACT_FLAG_ENDIAN) && endian == EndianDCE &&
582 flags & (DETECT_CI_FLAGS_DCE_LE | DETECT_CI_FLAGS_DCE_BE)) {
586 endian |= ((
flags & DETECT_CI_FLAGS_DCE_LE) ? LittleEndian : BigEndian);
590 &det_ctx->
byte_values[bed->local_id], endian) != 1) {
594 SCLogDebug(
"[BE] Fetched value for index %d: %"PRIu64,
595 bed->local_id, det_ctx->
byte_values[bed->local_id]);
600 const DetectByteMathData *bmd = (
const DetectByteMathData *)smd->
ctx;
601 uint8_t endian = bmd->endian;
605 if ((bmd->flags & DETECT_BYTEMATH_FLAG_ENDIAN) && endian == (int)EndianDCE &&
606 flags & (DETECT_CI_FLAGS_DCE_LE | DETECT_CI_FLAGS_DCE_BE)) {
609 endian = (uint8_t)((
flags & DETECT_CI_FLAGS_DCE_LE) ? LittleEndian : BigEndian);
612 if (bmd->flags & DETECT_BYTEMATH_FLAG_RVALUE_VAR) {
615 rvalue = bmd->rvalue;
619 if (bmd->flags & DETECT_BYTEMATH_FLAG_NBYTES_VAR) {
620 nbytes = (uint8_t)det_ctx->
byte_values[bmd->nbytes];
622 nbytes = bmd->nbytes;
626 &det_ctx->
byte_values[bmd->local_id], endian) != 1) {
630 SCLogDebug(
"[BM] Fetched value for index %d: %"PRIu64,
631 bmd->local_id, det_ctx->
byte_values[bmd->local_id]);
637 const uint64_t data_size = buffer_len + stream_start_offset;
640 goto no_match_discontinue;
654 goto no_match_discontinue;
664 goto no_match_discontinue;
670 const DetectUrilenData *urilend = (
const DetectUrilenData *)smd->
ctx;
671 if (buffer_len > UINT16_MAX) {
680 goto no_match_discontinue;
699 int r = DetectEngineContentInspectionInternal(det_ctx,
ctx, s,
728 no_match_discontinue:
737 int r = DetectEngineContentInspectionInternal(det_ctx,
ctx, s, smd + 1,
p,
f, buffer,
738 buffer_len, stream_start_offset,
flags, inspection_mode);
752 const uint32_t buffer_len,
const uint64_t stream_start_offset,
const uint8_t
flags,
759 int r = DetectEngineContentInspectionInternal(det_ctx, &
ctx, s, smd,
p,
f, buffer, buffer_len,
760 stream_start_offset,
flags, inspection_mode);
780 int r = DetectEngineContentInspectionInternal(det_ctx, &
ctx, s, smd,
p,
f, b->
inspect,
791 bool absent_data =
false;