suricata
detect-byte-extract.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2024 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Anoop Saldanha <anoopsaldanha@gmail.com>
22  */
23 
24 #include "suricata-common.h"
25 #include "decode.h"
26 
27 #include "detect.h"
28 #include "detect-engine.h"
29 #include "detect-content.h"
30 #include "detect-pcre.h"
31 #include "detect-bytejump.h"
32 #include "detect-bytetest.h"
33 #include "detect-byte-extract.h"
34 #include "detect-isdataat.h"
35 #include "detect-engine-build.h"
36 
37 #include "rust.h"
38 
39 #include "app-layer-protos.h"
40 
41 #include "util-byte.h"
42 #include "util-debug.h"
43 #include "util-unittest-helper.h"
44 
45 /* the base to be used if string mode is specified. These options would be
46  * specified in DetectByteParseData->base */
47 #define DETECT_BYTE_EXTRACT_BASE_HEX BaseHex
48 #define DETECT_BYTE_EXTRACT_BASE_DEC BaseDec
49 #define DETECT_BYTE_EXTRACT_BASE_OCT BaseOct
50 
51 /* the max no of bytes that can be extracted in string mode - (string, hex)
52  * (string, oct) or (string, dec) */
53 #define STRING_MAX_BYTES_TO_EXTRACT_FOR_OCT 23
54 #define STRING_MAX_BYTES_TO_EXTRACT_FOR_DEC 20
55 #define STRING_MAX_BYTES_TO_EXTRACT_FOR_HEX 14
56 /* the max no of bytes that can be extracted in non-string mode */
57 #define NO_STRING_MAX_BYTES_TO_EXTRACT 8
58 
59 static int DetectByteExtractSetup(DetectEngineCtx *, Signature *, const char *);
60 #ifdef UNITTESTS
61 static void DetectByteExtractRegisterTests(void);
62 #endif
63 static void DetectByteExtractFree(DetectEngineCtx *, void *);
64 
65 /**
66  * \brief Registers the keyword handlers for the "byte_extract" keyword.
67  */
69 {
70  sigmatch_table[DETECT_BYTE_EXTRACT].name = "byte_extract";
71  sigmatch_table[DETECT_BYTE_EXTRACT].desc = "extract <num of bytes> at a particular <offset> and store it in <var_name>";
72  sigmatch_table[DETECT_BYTE_EXTRACT].url = "/rules/payload-keywords.html#byte-extract";
74  sigmatch_table[DETECT_BYTE_EXTRACT].Setup = DetectByteExtractSetup;
75  sigmatch_table[DETECT_BYTE_EXTRACT].Free = DetectByteExtractFree;
76 #ifdef UNITTESTS
77  sigmatch_table[DETECT_BYTE_EXTRACT].RegisterTests = DetectByteExtractRegisterTests;
78 #endif
79 }
80 
82  const Signature *s, const uint8_t *payload, uint32_t payload_len, uint64_t *value,
83  uint8_t endian)
84 {
85  if (payload_len == 0) {
86  return 0;
87  }
88 
89  /* Calculate the ptr value for the bytetest and length remaining in
90  * the packet from that point.
91  */
92  const uint8_t *ptr;
93  int32_t len;
94  SCDetectByteExtractData *data = (SCDetectByteExtractData *)smd->ctx;
95  if (data->flags & DETECT_BYTE_EXTRACT_FLAG_RELATIVE) {
96  SCLogDebug("relative, working with det_ctx->buffer_offset %"PRIu32", "
97  "data->offset %"PRIu32"", det_ctx->buffer_offset, data->offset);
98 
99  ptr = payload + det_ctx->buffer_offset;
100  len = payload_len - det_ctx->buffer_offset;
101 
102  ptr += data->offset;
103  len -= data->offset;
104 
105  /* No match if there is no relative base */
106  if (len <= 0) {
107  return 0;
108  }
109  //PrintRawDataFp(stdout,ptr,len);
110  } else {
111  SCLogDebug("absolute, data->offset %"PRIu32"", data->offset);
112 
113  ptr = payload + data->offset;
114  len = payload_len - data->offset;
115  }
116 
117  /* Validate that the to-be-extracted is within the packet */
118  if (ptr < payload || data->nbytes > len) {
119  SCLogDebug("Data not within payload pkt=%p, ptr=%p, len=%"PRIu32", nbytes=%d",
120  payload, ptr, len, data->nbytes);
121  return 0;
122  }
123 
124  /* Extract the byte data */
125  uint64_t val = 0;
126  int extbytes;
127  if (data->flags & DETECT_BYTE_EXTRACT_FLAG_STRING) {
128  extbytes = ByteExtractStringUint64(&val, data->base,
129  data->nbytes, (const char *)ptr);
130  if (extbytes <= 0) {
131  /* ByteExtractStringUint64() set val to 0 if there is no numeric value in data string */
132  if (val == 0) {
133  SCLogDebug("No Numeric value");
134  return 0;
135  } else {
136  SCLogDebug("error extracting %d bytes of string data: %d",
137  data->nbytes, extbytes);
138  return -1;
139  }
140  }
141  } else {
142  int endianness = (endian == BigEndian) ? BYTE_BIG_ENDIAN : BYTE_LITTLE_ENDIAN;
143  extbytes = ByteExtractUint64(&val, endianness, data->nbytes, ptr);
144  if (extbytes != data->nbytes) {
145  SCLogDebug("error extracting %d bytes of numeric data: %d",
146  data->nbytes, extbytes);
147  return 0;
148  }
149  }
150 
151  /* Adjust the jump value based on flags */
152  val *= data->multiplier_value;
153  if (data->flags & DETECT_BYTE_EXTRACT_FLAG_ALIGN) {
154  if ((val % data->align_value) != 0) {
155  val += data->align_value - (val % data->align_value);
156  }
157  }
158 
159  ptr += extbytes;
160 
161  det_ctx->buffer_offset = (uint32_t)(ptr - payload);
162 
163  *value = val;
164  SCLogDebug("extracted value is %"PRIu64, val);
165  return 1;
166 }
167 
168 /**
169  * \internal
170  * \brief Used to parse byte_extract arg.
171  *
172  * \param de_ctx Pointer to the detection engine context
173  * \arg The argument to parse.
174  *
175  * \param bed On success an instance containing the parsed data.
176  * On failure, NULL.
177  */
178 static inline SCDetectByteExtractData *DetectByteExtractParse(
179  DetectEngineCtx *de_ctx, const char *arg)
180 {
181  SCDetectByteExtractData *bed = SCByteExtractParse(arg);
182  if (bed == NULL) {
183  SCLogError("invalid byte_extract values");
184  goto error;
185  }
186 
187  if (bed->flags & DETECT_BYTE_EXTRACT_FLAG_SLICE) {
188  SCLogError("byte_extract slice not yet supported; see issue #6831");
189  goto error;
190  }
191  if (bed->flags & DETECT_BYTE_EXTRACT_FLAG_STRING) {
192  if (bed->base == DETECT_BYTE_EXTRACT_BASE_OCT) {
193  /* if are dealing with octal nos, the max no that can fit in a 8
194  * byte value is 01777777777777777777777 */
195  if (bed->nbytes > STRING_MAX_BYTES_TO_EXTRACT_FOR_OCT) {
196  SCLogError("byte_extract can't process "
197  "more than %d bytes in \"string\" extraction",
199  goto error;
200  }
201  } else if (bed->base == DETECT_BYTE_EXTRACT_BASE_DEC) {
202  /* if are dealing with decimal nos, the max no that can fit in a 8
203  * byte value is 18446744073709551615 */
204  if (bed->nbytes > STRING_MAX_BYTES_TO_EXTRACT_FOR_DEC) {
205  SCLogError("byte_extract can't process "
206  "more than %d bytes in \"string\" extraction",
208  goto error;
209  }
210  } else if (bed->base == DETECT_BYTE_EXTRACT_BASE_HEX) {
211  /* if are dealing with hex nos, the max no that can fit in a 8
212  * byte value is 0xFFFFFFFFFFFFFFFF */
213  if (bed->nbytes > STRING_MAX_BYTES_TO_EXTRACT_FOR_HEX) {
214  SCLogError("byte_extract can't process "
215  "more than %d bytes in \"string\" extraction",
217  goto error;
218  }
219  } else {
220  ; // just a placeholder. we won't reach here.
221  }
222  } else {
223  if (bed->nbytes > NO_STRING_MAX_BYTES_TO_EXTRACT) {
224  SCLogError("byte_extract can't process "
225  "more than %d bytes in \"non-string\" extraction",
227  goto error;
228  }
229  /* if string has not been specified and no endian option has been
230  * specified, then set the default endian level of BIG */
231  if (!(bed->flags & DETECT_BYTE_EXTRACT_FLAG_ENDIAN))
232  bed->endian = BigEndian;
233  }
234  return bed;
235 
236  error:
237  if (bed != NULL)
238  DetectByteExtractFree(de_ctx, bed);
239  return NULL;
240 }
241 
242 /**
243  * \brief The setup function for the byte_extract keyword for a signature.
244  *
245  * \param de_ctx Pointer to the detection engine context.
246  * \param s Pointer to signature for the current Signature being parsed
247  * from the rules.
248  * \param m Pointer to the head of the SigMatch for the current rule
249  * being parsed.
250  * \param arg Pointer to the string holding the keyword value.
251  *
252  * \retval 0 On success.
253  * \retval -1 On failure.
254  */
255 static int DetectByteExtractSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg)
256 {
257  SigMatch *prev_pm = NULL;
258  SCDetectByteExtractData *data = NULL;
259  int ret = -1;
260 
261  data = DetectByteExtractParse(de_ctx, arg);
262  if (data == NULL)
263  goto error;
264 
265  int sm_list;
266  if (s->init_data->list != DETECT_SM_LIST_NOTSET) {
267  sm_list = s->init_data->list;
268 
269  if (data->flags & DETECT_BYTE_EXTRACT_FLAG_RELATIVE) {
271  }
272  } else if (data->endian == EndianDCE) {
273  if (data->flags & DETECT_BYTE_EXTRACT_FLAG_RELATIVE) {
276  if (prev_pm == NULL) {
277  sm_list = DETECT_SM_LIST_PMATCH;
278  } else {
279  sm_list = SigMatchListSMBelongsTo(s, prev_pm);
280  if (sm_list < 0)
281  goto error;
282  }
283  } else {
284  sm_list = DETECT_SM_LIST_PMATCH;
285  }
286 
288  goto error;
289 
290  } else if (data->flags & DETECT_BYTE_EXTRACT_FLAG_RELATIVE) {
293  if (prev_pm == NULL) {
294  sm_list = DETECT_SM_LIST_PMATCH;
295  } else {
296  sm_list = SigMatchListSMBelongsTo(s, prev_pm);
297  if (sm_list < 0)
298  goto error;
299  }
300 
301  } else {
302  sm_list = DETECT_SM_LIST_PMATCH;
303  }
304 
305  if (data->endian == EndianDCE) {
307  goto error;
308 
309  if ((DETECT_BYTE_EXTRACT_FLAG_BASE | DETECT_BYTE_EXTRACT_FLAG_STRING) ==
310  (data->flags & (DETECT_BYTE_EXTRACT_FLAG_BASE | DETECT_BYTE_EXTRACT_FLAG_STRING))) {
311  SCLogError("Invalid option. "
312  "A byte_jump keyword with dce holds other invalid modifiers.");
313  goto error;
314  }
315  }
316 
317  SigMatch *prev_bed_sm = DetectGetLastSMByListId(s, sm_list,
318  DETECT_BYTE_EXTRACT, -1);
319  if (prev_bed_sm == NULL)
320  data->local_id = 0;
321  else
322  data->local_id = ((SCDetectByteExtractData *)prev_bed_sm->ctx)->local_id + 1;
323  if (data->local_id > de_ctx->byte_extract_max_local_id)
324  de_ctx->byte_extract_max_local_id = data->local_id;
325 
326  if (SCSigMatchAppendSMToList(de_ctx, s, DETECT_BYTE_EXTRACT, (SigMatchCtx *)data, sm_list) ==
327  NULL) {
328  goto error;
329  }
330 
331  if (!(data->flags & DETECT_BYTE_EXTRACT_FLAG_RELATIVE))
332  goto okay;
333 
334  if (prev_pm == NULL)
335  goto okay;
336 
337  if (prev_pm->type == DETECT_CONTENT) {
338  DetectContentData *cd = (DetectContentData *)prev_pm->ctx;
340  } else if (prev_pm->type == DETECT_PCRE) {
341  DetectPcreData *pd = (DetectPcreData *)prev_pm->ctx;
343  }
344 
345  okay:
346  ret = 0;
347  return ret;
348  error:
349  DetectByteExtractFree(de_ctx, data);
350  return ret;
351 }
352 
353 /**
354  * \brief Used to free instances of SCDetectByteExtractData.
355  *
356  * \param ptr Instance of SCDetectByteExtractData to be freed.
357  */
358 static void DetectByteExtractFree(DetectEngineCtx *de_ctx, void *ptr)
359 {
360  SCByteExtractFree(ptr);
361 }
362 
363 /**
364  * \brief Lookup the SigMatch for a named byte_extract variable.
365  *
366  * \param arg The name of the byte_extract variable to lookup.
367  * \param s Pointer the signature to look in.
368  *
369  * \retval A pointer to the SigMatch if found, otherwise NULL.
370  */
371 SigMatch *DetectByteExtractRetrieveSMVar(const char *arg, int sm_list, const Signature *s)
372 {
373  for (uint32_t x = 0; x < s->init_data->buffer_index; x++) {
374  SigMatch *sm = s->init_data->buffers[x].head;
375  while (sm != NULL) {
376  if (sm->type == DETECT_BYTE_EXTRACT) {
377  const SCDetectByteExtractData *bed = (const SCDetectByteExtractData *)sm->ctx;
378  if (strcmp(bed->name, arg) == 0) {
379  return sm;
380  }
381  }
382  sm = sm->next;
383  }
384  }
385 
386  for (int list = 0; list < DETECT_SM_LIST_MAX; list++) {
387  SigMatch *sm = s->init_data->smlists[list];
388  while (sm != NULL) {
389  // Make sure that the linked buffers ore on the same list
390  if (sm->type == DETECT_BYTE_EXTRACT && (sm_list == -1 || sm_list == list)) {
391  const SCDetectByteExtractData *bed = (const SCDetectByteExtractData *)sm->ctx;
392  if (strcmp(bed->name, arg) == 0) {
393  return sm;
394  }
395  }
396  sm = sm->next;
397  }
398  }
399 
400  return NULL;
401 }
402 
403 /*************************************Unittests********************************/
404 
405 #ifdef UNITTESTS
406 
407 #include "detect-engine-buffer.h"
408 
409 static int g_file_data_buffer_id = 0;
410 static int g_http_uri_buffer_id = 0;
411 
412 static int DetectByteExtractTest01(void)
413 {
414  int result = 0;
415 
416  SCDetectByteExtractData *bed = DetectByteExtractParse(NULL, "4, 2, one");
417  if (bed == NULL)
418  goto end;
419 
420  if (bed->nbytes != 4 || bed->offset != 2 || strcmp(bed->name, "one") != 0 || bed->flags != 0 ||
421  bed->endian != BigEndian || bed->align_value != 0 ||
422  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
423  goto end;
424  }
425 
426  result = 1;
427  end:
428  if (bed != NULL)
429  DetectByteExtractFree(NULL, bed);
430  return result;
431 }
432 
433 static int DetectByteExtractTest02(void)
434 {
435  int result = 0;
436 
437  SCDetectByteExtractData *bed = DetectByteExtractParse(NULL, "4, 2, one, relative");
438  if (bed == NULL)
439  goto end;
440 
441  if (bed->nbytes != 4 || bed->offset != 2 || strcmp(bed->name, "one") != 0 ||
442  bed->flags != DETECT_BYTE_EXTRACT_FLAG_RELATIVE || bed->endian != BigEndian ||
443  bed->align_value != 0 ||
444  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
445  goto end;
446  }
447 
448  result = 1;
449  end:
450  if (bed != NULL)
451  DetectByteExtractFree(NULL, bed);
452  return result;
453 }
454 
455 static int DetectByteExtractTest03(void)
456 {
457  int result = 0;
458 
459  SCDetectByteExtractData *bed = DetectByteExtractParse(NULL, "4, 2, one, multiplier 10");
460  if (bed == NULL)
461  goto end;
462 
463  if (bed->nbytes != 4 || bed->offset != 2 || strcmp(bed->name, "one") != 0 ||
464  bed->flags != DETECT_BYTE_EXTRACT_FLAG_MULTIPLIER || bed->endian != BigEndian ||
465  bed->align_value != 0 || bed->multiplier_value != 10) {
466  goto end;
467  }
468 
469  result = 1;
470  end:
471  if (bed != NULL)
472  DetectByteExtractFree(NULL, bed);
473  return result;
474 }
475 
476 static int DetectByteExtractTest04(void)
477 {
478  int result = 0;
479 
480  SCDetectByteExtractData *bed =
481  DetectByteExtractParse(NULL, "4, 2, one, relative, multiplier 10");
482  if (bed == NULL)
483  goto end;
484 
485  if (bed->nbytes != 4 || bed->offset != 2 || strcmp(bed->name, "one") != 0 ||
486  bed->flags !=
487  (DETECT_BYTE_EXTRACT_FLAG_RELATIVE | DETECT_BYTE_EXTRACT_FLAG_MULTIPLIER) ||
488  bed->endian != BigEndian || bed->align_value != 0 || bed->multiplier_value != 10) {
489  goto end;
490  }
491 
492  result = 1;
493  end:
494  if (bed != NULL)
495  DetectByteExtractFree(NULL, bed);
496  return result;
497 }
498 
499 static int DetectByteExtractTest05(void)
500 {
501  int result = 0;
502 
503  SCDetectByteExtractData *bed = DetectByteExtractParse(NULL, "4, 2, one, big");
504  if (bed == NULL)
505  goto end;
506 
507  if (bed->nbytes != 4 || bed->offset != 2 || strcmp(bed->name, "one") != 0 ||
508  bed->flags != DETECT_BYTE_EXTRACT_FLAG_ENDIAN || bed->endian != BigEndian ||
509  bed->align_value != 0 ||
510  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
511  goto end;
512  }
513 
514  result = 1;
515  end:
516  if (bed != NULL)
517  DetectByteExtractFree(NULL, bed);
518  return result;
519 }
520 
521 static int DetectByteExtractTest06(void)
522 {
523  int result = 0;
524 
525  SCDetectByteExtractData *bed = DetectByteExtractParse(NULL, "4, 2, one, little");
526  if (bed == NULL)
527  goto end;
528 
529  if (bed->nbytes != 4 || bed->offset != 2 || strcmp(bed->name, "one") != 0 ||
530  bed->flags != DETECT_BYTE_EXTRACT_FLAG_ENDIAN || bed->endian != LittleEndian ||
531  bed->align_value != 0 ||
532  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
533  goto end;
534  }
535 
536  result = 1;
537  end:
538  if (bed != NULL)
539  DetectByteExtractFree(NULL, bed);
540  return result;
541 }
542 
543 static int DetectByteExtractTest07(void)
544 {
545  int result = 0;
546 
547  SCDetectByteExtractData *bed = DetectByteExtractParse(NULL, "4, 2, one, dce");
548  if (bed == NULL)
549  goto end;
550 
551  if (bed->nbytes != 4 || bed->offset != 2 || strcmp(bed->name, "one") != 0 ||
552  bed->flags != DETECT_BYTE_EXTRACT_FLAG_ENDIAN || bed->endian != EndianDCE ||
553  bed->align_value != 0 ||
554  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
555  goto end;
556  }
557 
558  result = 1;
559  end:
560  if (bed != NULL)
561  DetectByteExtractFree(NULL, bed);
562  return result;
563 }
564 
565 static int DetectByteExtractTest08(void)
566 {
567  int result = 0;
568 
569  SCDetectByteExtractData *bed = DetectByteExtractParse(NULL, "4, 2, one, string, hex");
570  if (bed == NULL)
571  goto end;
572 
573  if (bed->nbytes != 4 || bed->offset != 2 || strcmp(bed->name, "one") != 0 ||
574  bed->flags != (DETECT_BYTE_EXTRACT_FLAG_BASE | DETECT_BYTE_EXTRACT_FLAG_STRING) ||
575  bed->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed->align_value != 0 ||
576  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
577  goto end;
578  }
579 
580  result = 1;
581  end:
582  if (bed != NULL)
583  DetectByteExtractFree(NULL, bed);
584  return result;
585 }
586 
587 static int DetectByteExtractTest09(void)
588 {
589  int result = 0;
590 
591  SCDetectByteExtractData *bed = DetectByteExtractParse(NULL, "4, 2, one, string, oct");
592  if (bed == NULL)
593  goto end;
594 
595  if (bed->nbytes != 4 || bed->offset != 2 || strcmp(bed->name, "one") != 0 ||
596  bed->flags != (DETECT_BYTE_EXTRACT_FLAG_BASE | DETECT_BYTE_EXTRACT_FLAG_STRING) ||
597  bed->base != DETECT_BYTE_EXTRACT_BASE_OCT || bed->align_value != 0 ||
598  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
599  goto end;
600  }
601 
602  result = 1;
603  end:
604  if (bed != NULL)
605  DetectByteExtractFree(NULL, bed);
606  return result;
607 }
608 
609 static int DetectByteExtractTest10(void)
610 {
611  int result = 0;
612 
613  SCDetectByteExtractData *bed = DetectByteExtractParse(NULL, "4, 2, one, string, dec");
614  if (bed == NULL)
615  goto end;
616 
617  if (bed->nbytes != 4 || bed->offset != 2 || strcmp(bed->name, "one") != 0 ||
618  bed->base != DETECT_BYTE_EXTRACT_BASE_DEC || bed->align_value != 0 ||
619  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
620  goto end;
621  }
622 
623  result = 1;
624  end:
625  if (bed != NULL)
626  DetectByteExtractFree(NULL, bed);
627  return result;
628 }
629 
630 static int DetectByteExtractTest11(void)
631 {
632  int result = 0;
633 
634  SCDetectByteExtractData *bed = DetectByteExtractParse(NULL, "4, 2, one, align 4");
635  if (bed == NULL)
636  goto end;
637 
638  if (bed->nbytes != 4 || bed->offset != 2 || strcmp(bed->name, "one") != 0 ||
639  bed->flags != DETECT_BYTE_EXTRACT_FLAG_ALIGN || bed->endian != BigEndian ||
640  bed->align_value != 4 ||
641  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
642  goto end;
643  }
644 
645  result = 1;
646  end:
647  if (bed != NULL)
648  DetectByteExtractFree(NULL, bed);
649  return result;
650 }
651 
652 static int DetectByteExtractTest12(void)
653 {
654  int result = 0;
655 
656  SCDetectByteExtractData *bed = DetectByteExtractParse(NULL, "4, 2, one, align 4, relative");
657  if (bed == NULL)
658  goto end;
659 
660  if (bed->nbytes != 4 || bed->offset != 2 || strcmp(bed->name, "one") != 0 ||
661  bed->flags != (DETECT_BYTE_EXTRACT_FLAG_ALIGN | DETECT_BYTE_EXTRACT_FLAG_RELATIVE) ||
662  bed->endian != BigEndian || bed->align_value != 4 ||
663  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
664  goto end;
665  }
666 
667  result = 1;
668  end:
669  if (bed != NULL)
670  DetectByteExtractFree(NULL, bed);
671  return result;
672 }
673 
674 static int DetectByteExtractTest13(void)
675 {
676  int result = 0;
677 
678  SCDetectByteExtractData *bed =
679  DetectByteExtractParse(NULL, "4, 2, one, align 4, relative, big");
680  if (bed == NULL)
681  goto end;
682 
683  if (bed->nbytes != 4 || bed->offset != 2 || strcmp(bed->name, "one") != 0 ||
684  bed->flags != (DETECT_BYTE_EXTRACT_FLAG_ALIGN | DETECT_BYTE_EXTRACT_FLAG_ENDIAN |
685  DETECT_BYTE_EXTRACT_FLAG_RELATIVE) ||
686  bed->endian != BigEndian || bed->align_value != 4 ||
687  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
688  goto end;
689  }
690 
691  result = 1;
692  end:
693  if (bed != NULL)
694  DetectByteExtractFree(NULL, bed);
695  return result;
696 }
697 
698 static int DetectByteExtractTest14(void)
699 {
700  int result = 0;
701 
702  SCDetectByteExtractData *bed =
703  DetectByteExtractParse(NULL, "4, 2, one, align 4, relative, dce");
704  if (bed == NULL)
705  goto end;
706 
707  if (bed->nbytes != 4 || bed->offset != 2 || strcmp(bed->name, "one") != 0 ||
708  bed->flags != (DETECT_BYTE_EXTRACT_FLAG_ALIGN | DETECT_BYTE_EXTRACT_FLAG_ENDIAN |
709  DETECT_BYTE_EXTRACT_FLAG_RELATIVE) ||
710  bed->endian != EndianDCE || bed->align_value != 4 ||
711  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
712  goto end;
713  }
714 
715  result = 1;
716  end:
717  if (bed != NULL)
718  DetectByteExtractFree(NULL, bed);
719  return result;
720 }
721 
722 static int DetectByteExtractTest15(void)
723 {
724  int result = 0;
725 
726  SCDetectByteExtractData *bed =
727  DetectByteExtractParse(NULL, "4, 2, one, align 4, relative, little");
728  if (bed == NULL)
729  goto end;
730 
731  if (bed->nbytes != 4 || bed->offset != 2 || strcmp(bed->name, "one") != 0 ||
732  bed->flags != (DETECT_BYTE_EXTRACT_FLAG_ALIGN | DETECT_BYTE_EXTRACT_FLAG_ENDIAN |
733  DETECT_BYTE_EXTRACT_FLAG_RELATIVE) ||
734  bed->endian != LittleEndian || bed->align_value != 4 ||
735  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
736  goto end;
737  }
738 
739  result = 1;
740  end:
741  if (bed != NULL)
742  DetectByteExtractFree(NULL, bed);
743  return result;
744 }
745 
746 static int DetectByteExtractTest16(void)
747 {
748  int result = 0;
749 
750  SCDetectByteExtractData *bed =
751  DetectByteExtractParse(NULL, "4, 2, one, align 4, relative, little, multiplier 2");
752  if (bed == NULL)
753  goto end;
754 
755  if (bed->nbytes != 4 || bed->offset != 2 || strcmp(bed->name, "one") != 0 ||
756  bed->flags != (DETECT_BYTE_EXTRACT_FLAG_ALIGN | DETECT_BYTE_EXTRACT_FLAG_RELATIVE |
757  DETECT_BYTE_EXTRACT_FLAG_ENDIAN |
758  DETECT_BYTE_EXTRACT_FLAG_MULTIPLIER) ||
759  bed->endian != LittleEndian || bed->align_value != 4 || bed->multiplier_value != 2) {
760  goto end;
761  }
762 
763  result = 1;
764  end:
765  if (bed != NULL)
766  DetectByteExtractFree(NULL, bed);
767  return result;
768 }
769 
770 static int DetectByteExtractTest17(void)
771 {
772  int result = 0;
773 
774  SCDetectByteExtractData *bed = DetectByteExtractParse(NULL, "4, 2, one, align 4, "
775  "relative, little, "
776  "multiplier 2, string hex");
777  if (bed != NULL)
778  goto end;
779 
780  result = 1;
781  end:
782  if (bed != NULL)
783  DetectByteExtractFree(NULL, bed);
784  return result;
785 }
786 
787 static int DetectByteExtractTest18(void)
788 {
789  int result = 0;
790 
791  SCDetectByteExtractData *bed = DetectByteExtractParse(NULL, "4, 2, one, align 4, "
792  "relative, little, "
793  "multiplier 2, "
794  "relative");
795  if (bed != NULL)
796  goto end;
797 
798  result = 1;
799  end:
800  if (bed != NULL)
801  DetectByteExtractFree(NULL, bed);
802  return result;
803 }
804 
805 static int DetectByteExtractTest19(void)
806 {
807  int result = 0;
808 
809  SCDetectByteExtractData *bed = DetectByteExtractParse(NULL, "4, 2, one, align 4, "
810  "relative, little, "
811  "multiplier 2, "
812  "little");
813  if (bed != NULL)
814  goto end;
815 
816  result = 1;
817  end:
818  if (bed != NULL)
819  DetectByteExtractFree(NULL, bed);
820  return result;
821 }
822 
823 static int DetectByteExtractTest20(void)
824 {
825  int result = 0;
826 
827  SCDetectByteExtractData *bed = DetectByteExtractParse(NULL, "4, 2, one, align 4, "
828  "relative, "
829  "multiplier 2, "
830  "align 2");
831  if (bed != NULL)
832  goto end;
833 
834  result = 1;
835  end:
836  if (bed != NULL)
837  DetectByteExtractFree(NULL, bed);
838  return result;
839 }
840 
841 static int DetectByteExtractTest21(void)
842 {
843  int result = 0;
844 
845  SCDetectByteExtractData *bed = DetectByteExtractParse(NULL, "4, 2, one, align 4, "
846  "multiplier 2, "
847  "relative, "
848  "multiplier 2");
849  if (bed != NULL)
850  goto end;
851 
852  result = 1;
853  end:
854  if (bed != NULL)
855  DetectByteExtractFree(NULL, bed);
856  return result;
857 }
858 
859 static int DetectByteExtractTest22(void)
860 {
861  int result = 0;
862 
863  SCDetectByteExtractData *bed = DetectByteExtractParse(NULL, "4, 2, one, align 4, "
864  "string hex, "
865  "relative, "
866  "string hex");
867  if (bed != NULL)
868  goto end;
869 
870  result = 1;
871  end:
872  if (bed != NULL)
873  DetectByteExtractFree(NULL, bed);
874  return result;
875 }
876 
877 static int DetectByteExtractTest23(void)
878 {
879  int result = 0;
880 
881  SCDetectByteExtractData *bed = DetectByteExtractParse(NULL, "4, 2, one, align 4, "
882  "string hex, "
883  "relative, "
884  "string oct");
885  if (bed != NULL)
886  goto end;
887 
888  result = 1;
889  end:
890  if (bed != NULL)
891  DetectByteExtractFree(NULL, bed);
892  return result;
893 }
894 
895 static int DetectByteExtractTest24(void)
896 {
897  int result = 0;
898 
899  SCDetectByteExtractData *bed = DetectByteExtractParse(NULL, "24, 2, one, align 4, "
900  "string hex, "
901  "relative");
902  if (bed != NULL)
903  goto end;
904 
905  result = 1;
906  end:
907  if (bed != NULL)
908  DetectByteExtractFree(NULL, bed);
909  return result;
910 }
911 
912 static int DetectByteExtractTest25(void)
913 {
914  int result = 0;
915 
916  SCDetectByteExtractData *bed = DetectByteExtractParse(NULL, "9, 2, one, align 4, "
917  "little, "
918  "relative");
919  if (bed != NULL)
920  goto end;
921 
922  result = 1;
923  end:
924  if (bed != NULL)
925  DetectByteExtractFree(NULL, bed);
926  return result;
927 }
928 
929 static int DetectByteExtractTest26(void)
930 {
931  int result = 0;
932 
933  SCDetectByteExtractData *bed = DetectByteExtractParse(NULL, "4, 2, one, align 4, "
934  "little, "
935  "relative, "
936  "multiplier 65536");
937  if (bed != NULL)
938  goto end;
939 
940  result = 1;
941  end:
942  if (bed != NULL)
943  DetectByteExtractFree(NULL, bed);
944  return result;
945 }
946 
947 static int DetectByteExtractTest27(void)
948 {
949  int result = 0;
950 
951  SCDetectByteExtractData *bed = DetectByteExtractParse(NULL, "4, 2, one, align 4, "
952  "little, "
953  "relative, "
954  "multiplier 0");
955  if (bed != NULL)
956  goto end;
957 
958  result = 1;
959  end:
960  if (bed != NULL)
961  DetectByteExtractFree(NULL, bed);
962  return result;
963 }
964 
965 static int DetectByteExtractTest28(void)
966 {
967  int result = 0;
968 
969  SCDetectByteExtractData *bed = DetectByteExtractParse(NULL, "23, 2, one, string, oct");
970  if (bed == NULL)
971  goto end;
972 
973  result = 1;
974  end:
975  if (bed != NULL)
976  DetectByteExtractFree(NULL, bed);
977  return result;
978 }
979 
980 static int DetectByteExtractTest29(void)
981 {
982  int result = 0;
983 
984  SCDetectByteExtractData *bed = DetectByteExtractParse(NULL, "24, 2, one, string, oct");
985  if (bed != NULL)
986  goto end;
987 
988  result = 1;
989  end:
990  if (bed != NULL)
991  DetectByteExtractFree(NULL, bed);
992  return result;
993 }
994 
995 static int DetectByteExtractTest30(void)
996 {
997  int result = 0;
998 
999  SCDetectByteExtractData *bed = DetectByteExtractParse(NULL, "20, 2, one, string, dec");
1000  if (bed == NULL)
1001  goto end;
1002 
1003  result = 1;
1004  end:
1005  if (bed != NULL)
1006  DetectByteExtractFree(NULL, bed);
1007  return result;
1008 }
1009 
1010 static int DetectByteExtractTest31(void)
1011 {
1012  int result = 0;
1013 
1014  SCDetectByteExtractData *bed = DetectByteExtractParse(NULL, "21, 2, one, string, dec");
1015  if (bed != NULL)
1016  goto end;
1017 
1018  result = 1;
1019  end:
1020  if (bed != NULL)
1021  DetectByteExtractFree(NULL, bed);
1022  return result;
1023 }
1024 
1025 static int DetectByteExtractTest32(void)
1026 {
1027  int result = 0;
1028 
1029  SCDetectByteExtractData *bed = DetectByteExtractParse(NULL, "14, 2, one, string, hex");
1030  if (bed == NULL)
1031  goto end;
1032 
1033  result = 1;
1034  end:
1035  if (bed != NULL)
1036  DetectByteExtractFree(NULL, bed);
1037  return result;
1038 }
1039 
1040 static int DetectByteExtractTest33(void)
1041 {
1042  int result = 0;
1043 
1044  SCDetectByteExtractData *bed = DetectByteExtractParse(NULL, "15, 2, one, string, hex");
1045  if (bed != NULL)
1046  goto end;
1047 
1048  result = 1;
1049  end:
1050  if (bed != NULL)
1051  DetectByteExtractFree(NULL, bed);
1052  return result;
1053 }
1054 
1055 static int DetectByteExtractTest34(void)
1056 {
1057  DetectEngineCtx *de_ctx = NULL;
1058  int result = 0;
1059  Signature *s = NULL;
1060  SigMatch *sm = NULL;
1061  DetectContentData *cd = NULL;
1062  SCDetectByteExtractData *bed = NULL;
1063 
1065  if (de_ctx == NULL)
1066  goto end;
1067 
1068  de_ctx->flags |= DE_QUIET;
1069  s = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
1070  "(msg:\"Testing bytejump_body\"; "
1071  "content:\"one\"; "
1072  "byte_extract:4,2,two,relative,string,hex; "
1073  "sid:1;)");
1074  if (de_ctx->sig_list == NULL) {
1075  result = 0;
1076  goto end;
1077  }
1078 
1079  if (s->init_data->smlists_tail[DETECT_SM_LIST_PMATCH] == NULL) {
1080  result = 0;
1081  goto end;
1082  }
1083 
1085  if (sm->type != DETECT_CONTENT) {
1086  result = 0;
1087  goto end;
1088  }
1089  cd = (DetectContentData *)sm->ctx;
1090  if (cd->flags & DETECT_CONTENT_RAWBYTES ||
1091  strncmp((char *)cd->content, "one", cd->content_len) != 0 ||
1092  cd->flags & DETECT_CONTENT_NOCASE ||
1093  cd->flags & DETECT_CONTENT_WITHIN ||
1097  cd->flags & DETECT_CONTENT_NEGATED ) {
1098  printf("one failed\n");
1099  result = 0;
1100  goto end;
1101  }
1102 
1103  sm = sm->next;
1104  if (sm->type != DETECT_BYTE_EXTRACT) {
1105  result = 0;
1106  goto end;
1107  }
1108  bed = (SCDetectByteExtractData *)sm->ctx;
1109  if (bed->nbytes != 4 || bed->offset != 2 || strncmp(bed->name, "two", cd->content_len) != 0 ||
1110  bed->flags != (DETECT_BYTE_EXTRACT_FLAG_RELATIVE | DETECT_BYTE_EXTRACT_FLAG_BASE |
1111  DETECT_BYTE_EXTRACT_FLAG_STRING) ||
1112  bed->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed->align_value != 0 ||
1113  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
1114  goto end;
1115  }
1116 
1117  result = 1;
1118 
1119  end:
1123 
1124  return result;
1125 }
1126 
1127 static int DetectByteExtractTest35(void)
1128 {
1129  DetectEngineCtx *de_ctx = NULL;
1130  int result = 0;
1131  Signature *s = NULL;
1132  SigMatch *sm = NULL;
1133  DetectContentData *cd = NULL;
1134  DetectPcreData *pd = NULL;
1135  SCDetectByteExtractData *bed = NULL;
1136 
1138  if (de_ctx == NULL)
1139  goto end;
1140 
1141  de_ctx->flags |= DE_QUIET;
1142  s = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
1143  "(msg:\"Testing bytejump_body\"; "
1144  "content:\"one\"; pcre:/asf/; "
1145  "byte_extract:4,0,two,relative,string,hex; "
1146  "sid:1;)");
1147  if (de_ctx->sig_list == NULL) {
1148  result = 0;
1149  goto end;
1150  }
1151 
1152  if (s->init_data->smlists_tail[DETECT_SM_LIST_PMATCH] == NULL) {
1153  result = 0;
1154  goto end;
1155  }
1156 
1158  if (sm->type != DETECT_CONTENT) {
1159  result = 0;
1160  goto end;
1161  }
1162  cd = (DetectContentData *)sm->ctx;
1163  if (cd->flags & DETECT_CONTENT_RAWBYTES ||
1164  strncmp((char *)cd->content, "one", cd->content_len) != 0 ||
1165  cd->flags & DETECT_CONTENT_NOCASE ||
1166  cd->flags & DETECT_CONTENT_WITHIN ||
1170  cd->flags & DETECT_CONTENT_NEGATED ) {
1171  printf("one failed\n");
1172  result = 0;
1173  goto end;
1174  }
1175 
1176  sm = sm->next;
1177  if (sm->type != DETECT_PCRE) {
1178  result = 0;
1179  goto end;
1180  }
1181  pd = (DetectPcreData *)sm->ctx;
1182  if (pd->flags != DETECT_PCRE_RELATIVE_NEXT) {
1183  result = 0;
1184  goto end;
1185  }
1186 
1187  sm = sm->next;
1188  if (sm->type != DETECT_BYTE_EXTRACT) {
1189  result = 0;
1190  goto end;
1191  }
1192  bed = (SCDetectByteExtractData *)sm->ctx;
1193  if (bed->nbytes != 4 || bed->offset != 0 || strcmp(bed->name, "two") != 0 ||
1194  bed->flags != (DETECT_BYTE_EXTRACT_FLAG_RELATIVE | DETECT_BYTE_EXTRACT_FLAG_BASE |
1195  DETECT_BYTE_EXTRACT_FLAG_STRING) ||
1196  bed->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed->align_value != 0 ||
1197  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
1198  goto end;
1199  }
1200 
1201  result = 1;
1202 
1203  end:
1207 
1208  return result;
1209 }
1210 
1211 static int DetectByteExtractTest36(void)
1212 {
1215  de_ctx->flags |= DE_QUIET;
1216 
1217  Signature *s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any ("
1218  "content:\"one\"; byte_jump:1,13; "
1219  "byte_extract:4,0,two,relative,string,hex; "
1220  "sid:1;)");
1221  FAIL_IF_NULL(s);
1223 
1225  FAIL_IF(sm->type != DETECT_CONTENT);
1228  FAIL_IF(strncmp((char *)cd->content, "one", cd->content_len) != 0);
1235 
1236  sm = sm->next;
1237  FAIL_IF(sm->type != DETECT_BYTEJUMP);
1239  FAIL_IF(bjd->flags != 0);
1240  sm = sm->next;
1242  SCDetectByteExtractData *bed = (SCDetectByteExtractData *)sm->ctx;
1243  FAIL_IF(bed->nbytes != 4);
1244  FAIL_IF(bed->offset != 0);
1245  FAIL_IF(strcmp(bed->name, "two") != 0);
1246  FAIL_IF(bed->flags != (DETECT_BYTE_EXTRACT_FLAG_RELATIVE | DETECT_BYTE_EXTRACT_FLAG_BASE |
1247  DETECT_BYTE_EXTRACT_FLAG_STRING));
1248  FAIL_IF(bed->base != DETECT_BYTE_EXTRACT_BASE_HEX);
1249  FAIL_IF(bed->align_value != 0);
1250  FAIL_IF(bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT);
1251 
1253  PASS;
1254 }
1255 
1256 static int DetectByteExtractTest37(void)
1257 {
1258  DetectEngineCtx *de_ctx = NULL;
1259  int result = 0;
1260  Signature *s = NULL;
1261  SigMatch *sm = NULL;
1262  DetectContentData *cd = NULL;
1263  DetectContentData *ud = NULL;
1264  SCDetectByteExtractData *bed = NULL;
1265 
1267  if (de_ctx == NULL)
1268  goto end;
1269 
1270  de_ctx->flags |= DE_QUIET;
1271  s = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
1272  "(msg:\"Testing bytejump_body\"; "
1273  "content:\"one\"; uricontent:\"two\"; "
1274  "byte_extract:4,0,two,relative,string,hex; "
1275  "sid:1;)");
1276  if (de_ctx->sig_list == NULL) {
1277  result = 0;
1278  goto end;
1279  }
1280 
1281  if (s->init_data->smlists_tail[DETECT_SM_LIST_PMATCH] == NULL) {
1282  result = 0;
1283  goto end;
1284  }
1285 
1287  if (sm->type != DETECT_CONTENT) {
1288  result = 0;
1289  goto end;
1290  }
1291  cd = (DetectContentData *)sm->ctx;
1292  if (cd->flags & DETECT_CONTENT_RAWBYTES ||
1293  strncmp((char *)cd->content, "one", cd->content_len) != 0 ||
1294  cd->flags & DETECT_CONTENT_NOCASE ||
1295  cd->flags & DETECT_CONTENT_WITHIN ||
1299  cd->flags & DETECT_CONTENT_NEGATED ) {
1300  printf("one failed\n");
1301  result = 0;
1302  goto end;
1303  }
1304 
1305  if (sm->next != NULL) {
1306  result = 0;
1307  goto end;
1308  }
1309 
1310  sm = DetectBufferGetFirstSigMatch(s, g_http_uri_buffer_id);
1311  if (sm->type != DETECT_CONTENT) {
1312  result = 0;
1313  goto end;
1314  }
1315  ud = (DetectContentData *)sm->ctx;
1316  if (ud->flags & DETECT_CONTENT_RAWBYTES ||
1317  strncmp((char *)ud->content, "two", cd->content_len) != 0 ||
1318  ud->flags & DETECT_CONTENT_NOCASE ||
1319  ud->flags & DETECT_CONTENT_WITHIN ||
1323  ud->flags & DETECT_CONTENT_NEGATED ) {
1324  printf("two failed\n");
1325  result = 0;
1326  goto end;
1327  }
1328 
1329  sm = sm->next;
1330  if (sm->type != DETECT_BYTE_EXTRACT) {
1331  result = 0;
1332  goto end;
1333  }
1334  bed = (SCDetectByteExtractData *)sm->ctx;
1335  if (bed->nbytes != 4 || bed->offset != 0 || strcmp(bed->name, "two") != 0 ||
1336  bed->flags != (DETECT_BYTE_EXTRACT_FLAG_RELATIVE | DETECT_BYTE_EXTRACT_FLAG_BASE |
1337  DETECT_BYTE_EXTRACT_FLAG_STRING) ||
1338  bed->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed->align_value != 0 ||
1339  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
1340  goto end;
1341  }
1342 
1343  result = 1;
1344 
1345  end:
1349 
1350  return result;
1351 }
1352 
1353 static int DetectByteExtractTest38(void)
1354 {
1355  DetectEngineCtx *de_ctx = NULL;
1356  int result = 0;
1357  Signature *s = NULL;
1358  SigMatch *sm = NULL;
1359  DetectContentData *cd = NULL;
1360  DetectContentData *ud = NULL;
1361  SCDetectByteExtractData *bed = NULL;
1362 
1364  if (de_ctx == NULL)
1365  goto end;
1366 
1367  de_ctx->flags |= DE_QUIET;
1368  s = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
1369  "(msg:\"Testing bytejump_body\"; "
1370  "content:\"one\"; uricontent:\"two\"; "
1371  "byte_extract:4,0,two,string,hex; "
1372  "sid:1;)");
1373  if (de_ctx->sig_list == NULL) {
1374  result = 0;
1375  goto end;
1376  }
1377 
1378  if (s->init_data->smlists_tail[DETECT_SM_LIST_PMATCH] == NULL) {
1379  result = 0;
1380  goto end;
1381  }
1382 
1384  if (sm->type != DETECT_CONTENT) {
1385  result = 0;
1386  goto end;
1387  }
1388  cd = (DetectContentData *)sm->ctx;
1389  if (cd->flags & DETECT_CONTENT_RAWBYTES ||
1390  strncmp((char *)cd->content, "one", cd->content_len) != 0 ||
1391  cd->flags & DETECT_CONTENT_NOCASE ||
1392  cd->flags & DETECT_CONTENT_WITHIN ||
1396  cd->flags & DETECT_CONTENT_NEGATED ) {
1397  printf("one failed\n");
1398  result = 0;
1399  goto end;
1400  }
1401 
1402  sm = sm->next;
1403  if (sm->type != DETECT_BYTE_EXTRACT) {
1404  result = 0;
1405  goto end;
1406  }
1407  bed = (SCDetectByteExtractData *)sm->ctx;
1408  if (bed->nbytes != 4 || bed->offset != 0 || strcmp(bed->name, "two") != 0 ||
1409  bed->flags != (DETECT_BYTE_EXTRACT_FLAG_BASE | DETECT_BYTE_EXTRACT_FLAG_STRING) ||
1410  bed->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed->align_value != 0 ||
1411  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
1412  goto end;
1413  }
1414 
1415  sm = DetectBufferGetFirstSigMatch(s, g_http_uri_buffer_id);
1416  if (sm->type != DETECT_CONTENT) {
1417  result = 0;
1418  goto end;
1419  }
1420  ud = (DetectContentData *)sm->ctx;
1421  if (ud->flags & DETECT_CONTENT_RAWBYTES ||
1422  strncmp((char *)ud->content, "two", cd->content_len) != 0 ||
1423  ud->flags & DETECT_CONTENT_NOCASE ||
1424  ud->flags & DETECT_CONTENT_WITHIN ||
1428  ud->flags & DETECT_CONTENT_NEGATED ) {
1429  printf("two failed\n");
1430  result = 0;
1431  goto end;
1432  }
1433 
1434  if (sm->next != NULL) {
1435  result = 0;
1436  goto end;
1437  }
1438 
1439  result = 1;
1440 
1441  end:
1445 
1446  return result;
1447 }
1448 
1449 static int DetectByteExtractTest39(void)
1450 {
1451  DetectEngineCtx *de_ctx = NULL;
1452  int result = 0;
1453  Signature *s = NULL;
1454  SigMatch *sm = NULL;
1455  DetectContentData *cd = NULL;
1456  DetectContentData *ud = NULL;
1457  SCDetectByteExtractData *bed = NULL;
1458 
1460  if (de_ctx == NULL)
1461  goto end;
1462 
1463  de_ctx->flags |= DE_QUIET;
1464  s = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
1465  "(msg:\"Testing bytejump_body\"; "
1466  "content:\"one\"; content:\"two\"; http_uri; "
1467  "byte_extract:4,0,two,relative,string,hex; "
1468  "sid:1;)");
1469  if (de_ctx->sig_list == NULL) {
1470  result = 0;
1471  goto end;
1472  }
1473 
1474  if (s->init_data->smlists_tail[DETECT_SM_LIST_PMATCH] == NULL) {
1475  result = 0;
1476  goto end;
1477  }
1478 
1480  if (sm->type != DETECT_CONTENT) {
1481  result = 0;
1482  goto end;
1483  }
1484  cd = (DetectContentData *)sm->ctx;
1485  if (cd->flags & DETECT_CONTENT_RAWBYTES ||
1486  strncmp((char *)cd->content, "one", cd->content_len) != 0 ||
1487  cd->flags & DETECT_CONTENT_NOCASE ||
1488  cd->flags & DETECT_CONTENT_WITHIN ||
1492  cd->flags & DETECT_CONTENT_NEGATED ) {
1493  printf("one failed\n");
1494  result = 0;
1495  goto end;
1496  }
1497 
1498  if (sm->next != NULL) {
1499  result = 0;
1500  goto end;
1501  }
1502 
1503  sm = DetectBufferGetFirstSigMatch(s, g_http_uri_buffer_id);
1504  if (sm->type != DETECT_CONTENT) {
1505  result = 0;
1506  goto end;
1507  }
1508  ud = (DetectContentData *)sm->ctx;
1509  if (ud->flags & DETECT_CONTENT_RAWBYTES ||
1510  strncmp((char *)ud->content, "two", cd->content_len) != 0 ||
1511  ud->flags & DETECT_CONTENT_NOCASE ||
1512  ud->flags & DETECT_CONTENT_WITHIN ||
1516  ud->flags & DETECT_CONTENT_NEGATED ) {
1517  printf("two failed\n");
1518  result = 0;
1519  goto end;
1520  }
1521 
1522  sm = sm->next;
1523  if (sm->type != DETECT_BYTE_EXTRACT) {
1524  result = 0;
1525  goto end;
1526  }
1527  bed = (SCDetectByteExtractData *)sm->ctx;
1528  if (bed->nbytes != 4 || bed->offset != 0 || strcmp(bed->name, "two") != 0 ||
1529  bed->flags != (DETECT_BYTE_EXTRACT_FLAG_RELATIVE | DETECT_BYTE_EXTRACT_FLAG_BASE |
1530  DETECT_BYTE_EXTRACT_FLAG_STRING) ||
1531  bed->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed->align_value != 0 ||
1532  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
1533  goto end;
1534  }
1535 
1536  result = 1;
1537 
1538  end:
1542 
1543  return result;
1544 }
1545 
1546 static int DetectByteExtractTest40(void)
1547 {
1548  DetectEngineCtx *de_ctx = NULL;
1549  int result = 0;
1550  Signature *s = NULL;
1551  SigMatch *sm = NULL;
1552  DetectContentData *cd = NULL;
1553  DetectContentData *ud = NULL;
1554  SCDetectByteExtractData *bed = NULL;
1555 
1557  if (de_ctx == NULL)
1558  goto end;
1559 
1560  de_ctx->flags |= DE_QUIET;
1561  s = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
1562  "(msg:\"Testing bytejump_body\"; "
1563  "content:\"one\"; content:\"two\"; http_uri; "
1564  "byte_extract:4,0,two,string,hex; "
1565  "sid:1;)");
1566  if (de_ctx->sig_list == NULL) {
1567  result = 0;
1568  goto end;
1569  }
1570 
1571  if (s->init_data->smlists_tail[DETECT_SM_LIST_PMATCH] == NULL) {
1572  result = 0;
1573  goto end;
1574  }
1575 
1577  if (sm->type != DETECT_CONTENT) {
1578  result = 0;
1579  goto end;
1580  }
1581  cd = (DetectContentData *)sm->ctx;
1582  if (cd->flags & DETECT_CONTENT_RAWBYTES ||
1583  strncmp((char *)cd->content, "one", cd->content_len) != 0 ||
1584  cd->flags & DETECT_CONTENT_NOCASE ||
1585  cd->flags & DETECT_CONTENT_WITHIN ||
1589  cd->flags & DETECT_CONTENT_NEGATED ) {
1590  printf("one failed\n");
1591  result = 0;
1592  goto end;
1593  }
1594 
1595  sm = sm->next;
1596  if (sm->type != DETECT_BYTE_EXTRACT) {
1597  result = 0;
1598  goto end;
1599  }
1600  bed = (SCDetectByteExtractData *)sm->ctx;
1601  if (bed->nbytes != 4 || bed->offset != 0 || strcmp(bed->name, "two") != 0 ||
1602  bed->flags != (DETECT_BYTE_EXTRACT_FLAG_STRING | DETECT_BYTE_EXTRACT_FLAG_BASE) ||
1603  bed->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed->align_value != 0 ||
1604  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
1605  goto end;
1606  }
1607 
1608  sm = DetectBufferGetFirstSigMatch(s, g_http_uri_buffer_id);
1609  if (sm->type != DETECT_CONTENT) {
1610  result = 0;
1611  goto end;
1612  }
1613  ud = (DetectContentData *)sm->ctx;
1614  if (ud->flags & DETECT_CONTENT_RAWBYTES ||
1615  strncmp((char *)ud->content, "two", cd->content_len) != 0 ||
1616  ud->flags & DETECT_CONTENT_NOCASE ||
1617  ud->flags & DETECT_CONTENT_WITHIN ||
1621  ud->flags & DETECT_CONTENT_NEGATED ) {
1622  printf("two failed\n");
1623  result = 0;
1624  goto end;
1625  }
1626 
1627  if (sm->next != NULL) {
1628  result = 0;
1629  goto end;
1630  }
1631 
1632  result = 1;
1633 
1634  end:
1638 
1639  return result;
1640 }
1641 
1642 static int DetectByteExtractTest41(void)
1643 {
1644  DetectEngineCtx *de_ctx = NULL;
1645  int result = 0;
1646  Signature *s = NULL;
1647  SigMatch *sm = NULL;
1648  DetectContentData *cd = NULL;
1649  SCDetectByteExtractData *bed = NULL;
1650 
1652  if (de_ctx == NULL)
1653  goto end;
1654 
1655  de_ctx->flags |= DE_QUIET;
1656  s = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
1657  "(msg:\"Testing bytejump_body\"; "
1658  "content:\"one\"; "
1659  "byte_extract:4,0,two,string,hex; "
1660  "byte_extract:4,0,three,string,hex; "
1661  "sid:1;)");
1662  if (de_ctx->sig_list == NULL) {
1663  result = 0;
1664  goto end;
1665  }
1666 
1667  if (s->init_data->smlists_tail[DETECT_SM_LIST_PMATCH] == NULL) {
1668  result = 0;
1669  goto end;
1670  }
1671 
1673  if (sm->type != DETECT_CONTENT) {
1674  result = 0;
1675  goto end;
1676  }
1677  cd = (DetectContentData *)sm->ctx;
1678  if (cd->flags & DETECT_CONTENT_RAWBYTES ||
1679  strncmp((char *)cd->content, "one", cd->content_len) != 0 ||
1680  cd->flags & DETECT_CONTENT_NOCASE ||
1681  cd->flags & DETECT_CONTENT_WITHIN ||
1685  cd->flags & DETECT_CONTENT_NEGATED ) {
1686  printf("one failed\n");
1687  result = 0;
1688  goto end;
1689  }
1690 
1691  sm = sm->next;
1692  if (sm->type != DETECT_BYTE_EXTRACT) {
1693  result = 0;
1694  goto end;
1695  }
1696  bed = (SCDetectByteExtractData *)sm->ctx;
1697  if (bed->nbytes != 4 || bed->offset != 0 || strcmp(bed->name, "two") != 0 ||
1698  bed->flags != (DETECT_BYTE_EXTRACT_FLAG_STRING | DETECT_BYTE_EXTRACT_FLAG_BASE) ||
1699  bed->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed->align_value != 0 ||
1700  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
1701  goto end;
1702  }
1703  if (bed->local_id != 0) {
1704  result = 0;
1705  goto end;
1706  }
1707 
1708  sm = sm->next;
1709  if (sm->type != DETECT_BYTE_EXTRACT) {
1710  result = 0;
1711  goto end;
1712  }
1713  bed = (SCDetectByteExtractData *)sm->ctx;
1714  if (bed->nbytes != 4 || bed->offset != 0 || strcmp(bed->name, "three") != 0 ||
1715  bed->flags != (DETECT_BYTE_EXTRACT_FLAG_STRING | DETECT_BYTE_EXTRACT_FLAG_BASE) ||
1716  bed->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed->align_value != 0 ||
1717  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
1718  goto end;
1719  }
1720  if (bed->local_id != 1) {
1721  result = 0;
1722  goto end;
1723  }
1724 
1725  result = 1;
1726 
1727  end:
1731 
1732  return result;
1733 }
1734 
1735 static int DetectByteExtractTest42(void)
1736 {
1737  DetectEngineCtx *de_ctx = NULL;
1738  int result = 0;
1739  Signature *s = NULL;
1740  SigMatch *sm = NULL;
1741  DetectContentData *cd = NULL;
1742  DetectContentData *ud = NULL;
1743  SCDetectByteExtractData *bed = NULL;
1744 
1746  if (de_ctx == NULL)
1747  goto end;
1748 
1749  de_ctx->flags |= DE_QUIET;
1750  s = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
1751  "(msg:\"Testing bytejump_body\"; "
1752  "content:\"one\"; "
1753  "byte_extract:4,0,two,string,hex; "
1754  "uricontent: \"three\"; "
1755  "byte_extract:4,0,four,string,hex,relative; "
1756  "byte_extract:4,0,five,string,hex; "
1757  "sid:1;)");
1758  if (de_ctx->sig_list == NULL) {
1759  result = 0;
1760  goto end;
1761  }
1762 
1763  if (s->init_data->smlists_tail[DETECT_SM_LIST_PMATCH] == NULL) {
1764  result = 0;
1765  goto end;
1766  }
1767 
1769  if (sm->type != DETECT_CONTENT) {
1770  result = 0;
1771  goto end;
1772  }
1773  cd = (DetectContentData *)sm->ctx;
1774  if (cd->flags & DETECT_CONTENT_RAWBYTES ||
1775  strncmp((char *)cd->content, "one", cd->content_len) != 0 ||
1776  cd->flags & DETECT_CONTENT_NOCASE ||
1777  cd->flags & DETECT_CONTENT_WITHIN ||
1781  cd->flags & DETECT_CONTENT_NEGATED ) {
1782  printf("one failed\n");
1783  result = 0;
1784  goto end;
1785  }
1786 
1787  sm = sm->next;
1788  if (sm->type != DETECT_BYTE_EXTRACT) {
1789  result = 0;
1790  goto end;
1791  }
1792  bed = (SCDetectByteExtractData *)sm->ctx;
1793  if (bed->nbytes != 4 || bed->offset != 0 || strcmp(bed->name, "two") != 0 ||
1794  bed->flags != (DETECT_BYTE_EXTRACT_FLAG_STRING | DETECT_BYTE_EXTRACT_FLAG_BASE) ||
1795  bed->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed->align_value != 0 ||
1796  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
1797  goto end;
1798  }
1799  if (bed->local_id != 0) {
1800  result = 0;
1801  goto end;
1802  }
1803 
1804  sm = sm->next;
1805  if (sm->type != DETECT_BYTE_EXTRACT) {
1806  result = 0;
1807  goto end;
1808  }
1809  bed = (SCDetectByteExtractData *)sm->ctx;
1810  if (bed->nbytes != 4 || bed->offset != 0 || strcmp(bed->name, "five") != 0 ||
1811  bed->flags != (DETECT_BYTE_EXTRACT_FLAG_STRING | DETECT_BYTE_EXTRACT_FLAG_BASE) ||
1812  bed->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed->align_value != 0 ||
1813  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
1814  goto end;
1815  }
1816  if (bed->local_id != 1) {
1817  result = 0;
1818  goto end;
1819  }
1820 
1821  if (sm->next != NULL)
1822  goto end;
1823 
1824  sm = DetectBufferGetFirstSigMatch(s, g_http_uri_buffer_id);
1825  if (sm->type != DETECT_CONTENT) {
1826  result = 0;
1827  goto end;
1828  }
1829  ud = (DetectContentData *)sm->ctx;
1830  if (ud->flags & DETECT_CONTENT_RAWBYTES ||
1831  strncmp((char *)ud->content, "three", cd->content_len) != 0 ||
1832  ud->flags & DETECT_CONTENT_NOCASE ||
1833  ud->flags & DETECT_CONTENT_WITHIN ||
1837  ud->flags & DETECT_CONTENT_NEGATED ) {
1838  printf("two failed\n");
1839  result = 0;
1840  goto end;
1841  }
1842 
1843  sm = sm->next;
1844  if (sm->type != DETECT_BYTE_EXTRACT) {
1845  result = 0;
1846  goto end;
1847  }
1848  bed = (SCDetectByteExtractData *)sm->ctx;
1849  if (bed->nbytes != 4 || bed->offset != 0 || strcmp(bed->name, "four") != 0 ||
1850  bed->flags != (DETECT_BYTE_EXTRACT_FLAG_RELATIVE | DETECT_BYTE_EXTRACT_FLAG_BASE |
1851  DETECT_BYTE_EXTRACT_FLAG_STRING) ||
1852  bed->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed->align_value != 0 ||
1853  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
1854  goto end;
1855  }
1856  if (bed->local_id != 0) {
1857  result = 0;
1858  goto end;
1859  }
1860 
1861  if (sm->next != NULL)
1862  goto end;
1863 
1864  result = 1;
1865 
1866  end:
1870 
1871  return result;
1872 }
1873 
1874 static int DetectByteExtractTest43(void)
1875 {
1876  DetectEngineCtx *de_ctx = NULL;
1877  int result = 0;
1878  Signature *s = NULL;
1879  SigMatch *sm = NULL;
1880  DetectContentData *cd = NULL;
1881  SCDetectByteExtractData *bed = NULL;
1882 
1884  if (de_ctx == NULL)
1885  goto end;
1886 
1887  de_ctx->flags |= DE_QUIET;
1888  s = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
1889  "(msg:\"Testing bytejump_body\"; "
1890  "content:\"one\"; "
1891  "byte_extract:4,0,two,string,hex; "
1892  "content: \"three\"; offset:two; "
1893  "sid:1;)");
1894  if (de_ctx->sig_list == NULL) {
1895  result = 0;
1896  goto end;
1897  }
1898 
1899  if (s->init_data->smlists_tail[DETECT_SM_LIST_PMATCH] == NULL) {
1900  result = 0;
1901  goto end;
1902  }
1903 
1905  if (sm->type != DETECT_CONTENT) {
1906  result = 0;
1907  goto end;
1908  }
1909  cd = (DetectContentData *)sm->ctx;
1910  if (cd->flags & DETECT_CONTENT_RAWBYTES ||
1911  strncmp((char *)cd->content, "one", cd->content_len) != 0 ||
1912  cd->flags & DETECT_CONTENT_NOCASE ||
1913  cd->flags & DETECT_CONTENT_WITHIN ||
1917  cd->flags & DETECT_CONTENT_NEGATED ) {
1918  printf("one failed\n");
1919  result = 0;
1920  goto end;
1921  }
1922 
1923  sm = sm->next;
1924  if (sm->type != DETECT_BYTE_EXTRACT) {
1925  result = 0;
1926  goto end;
1927  }
1928  bed = (SCDetectByteExtractData *)sm->ctx;
1929  if (bed->nbytes != 4 || bed->offset != 0 || strcmp(bed->name, "two") != 0 ||
1930  bed->flags != (DETECT_BYTE_EXTRACT_FLAG_BASE | DETECT_BYTE_EXTRACT_FLAG_STRING) ||
1931  bed->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed->align_value != 0 ||
1932  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
1933  goto end;
1934  }
1935  if (bed->local_id != 0) {
1936  result = 0;
1937  goto end;
1938  }
1939 
1940  sm = sm->next;
1941  if (sm->type != DETECT_CONTENT) {
1942  result = 0;
1943  goto end;
1944  }
1945  cd = (DetectContentData *)sm->ctx;
1946  if (strncmp((char *)cd->content, "three", cd->content_len) != 0 ||
1948  cd->offset != bed->local_id) {
1949  printf("three failed\n");
1950  result = 0;
1951  goto end;
1952  }
1953 
1954  if (sm->next != NULL)
1955  goto end;
1956 
1957  result = 1;
1958 
1959  end:
1963 
1964  return result;
1965 }
1966 
1967 static int DetectByteExtractTest44(void)
1968 {
1969  DetectEngineCtx *de_ctx = NULL;
1970  int result = 0;
1971  Signature *s = NULL;
1972  SigMatch *sm = NULL;
1973  DetectContentData *cd = NULL;
1974  SCDetectByteExtractData *bed1 = NULL;
1975  SCDetectByteExtractData *bed2 = NULL;
1976 
1978  if (de_ctx == NULL)
1979  goto end;
1980 
1981  de_ctx->flags |= DE_QUIET;
1982  s = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
1983  "(msg:\"Testing bytejump_body\"; "
1984  "content:\"one\"; "
1985  "byte_extract:4,0,two,string,hex; "
1986  "byte_extract:4,0,three,string,hex; "
1987  "content: \"four\"; offset:two; "
1988  "content: \"five\"; offset:three; "
1989  "sid:1;)");
1990  if (de_ctx->sig_list == NULL) {
1991  result = 0;
1992  goto end;
1993  }
1994 
1995  if (s->init_data->smlists_tail[DETECT_SM_LIST_PMATCH] == NULL) {
1996  result = 0;
1997  goto end;
1998  }
1999 
2001  if (sm->type != DETECT_CONTENT) {
2002  result = 0;
2003  goto end;
2004  }
2005  cd = (DetectContentData *)sm->ctx;
2006  if (cd->flags & DETECT_CONTENT_RAWBYTES ||
2007  strncmp((char *)cd->content, "one", cd->content_len) != 0 ||
2008  cd->flags & DETECT_CONTENT_NOCASE ||
2009  cd->flags & DETECT_CONTENT_WITHIN ||
2013  cd->flags & DETECT_CONTENT_NEGATED ) {
2014  printf("one failed\n");
2015  result = 0;
2016  goto end;
2017  }
2018 
2019  sm = sm->next;
2020  if (sm->type != DETECT_BYTE_EXTRACT) {
2021  result = 0;
2022  goto end;
2023  }
2024  bed1 = (SCDetectByteExtractData *)sm->ctx;
2025  if (bed1->nbytes != 4 || bed1->offset != 0 || strcmp(bed1->name, "two") != 0 ||
2026  bed1->flags != (DETECT_BYTE_EXTRACT_FLAG_STRING | DETECT_BYTE_EXTRACT_FLAG_BASE) ||
2027  bed1->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed1->align_value != 0 ||
2028  bed1->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
2029  goto end;
2030  }
2031  if (bed1->local_id != 0) {
2032  result = 0;
2033  goto end;
2034  }
2035 
2036  sm = sm->next;
2037  if (sm->type != DETECT_BYTE_EXTRACT) {
2038  result = 0;
2039  goto end;
2040  }
2041  bed2 = (SCDetectByteExtractData *)sm->ctx;
2042 
2043  sm = sm->next;
2044  if (sm->type != DETECT_CONTENT) {
2045  result = 0;
2046  goto end;
2047  }
2048  cd = (DetectContentData *)sm->ctx;
2049  if (strncmp((char *)cd->content, "four", cd->content_len) != 0 ||
2051  cd->offset != bed1->local_id) {
2052  printf("four failed\n");
2053  result = 0;
2054  goto end;
2055  }
2056 
2057  sm = sm->next;
2058  if (sm->type != DETECT_CONTENT) {
2059  result = 0;
2060  goto end;
2061  }
2062  cd = (DetectContentData *)sm->ctx;
2063  if (strncmp((char *)cd->content, "five", cd->content_len) != 0 ||
2066  cd->offset != bed2->local_id) {
2067  printf("five failed\n");
2068  result = 0;
2069  goto end;
2070  }
2071 
2072  if (sm->next != NULL)
2073  goto end;
2074 
2075  result = 1;
2076 
2077  end:
2081 
2082  return result;
2083 }
2084 
2085 static int DetectByteExtractTest45(void)
2086 {
2087  DetectEngineCtx *de_ctx = NULL;
2088  int result = 0;
2089  Signature *s = NULL;
2090  SigMatch *sm = NULL;
2091  DetectContentData *cd = NULL;
2092  SCDetectByteExtractData *bed = NULL;
2093 
2095  if (de_ctx == NULL)
2096  goto end;
2097 
2098  de_ctx->flags |= DE_QUIET;
2099  s = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
2100  "(msg:\"Testing bytejump_body\"; "
2101  "content:\"one\"; "
2102  "byte_extract:4,0,two,string,hex; "
2103  "content: \"three\"; depth:two; "
2104  "sid:1;)");
2105  if (de_ctx->sig_list == NULL) {
2106  result = 0;
2107  goto end;
2108  }
2109 
2110  if (s->init_data->smlists_tail[DETECT_SM_LIST_PMATCH] == NULL) {
2111  result = 0;
2112  goto end;
2113  }
2114 
2116  if (sm->type != DETECT_CONTENT) {
2117  result = 0;
2118  goto end;
2119  }
2120  cd = (DetectContentData *)sm->ctx;
2121  if (cd->flags & DETECT_CONTENT_RAWBYTES ||
2122  strncmp((char *)cd->content, "one", cd->content_len) != 0 ||
2123  cd->flags & DETECT_CONTENT_NOCASE ||
2124  cd->flags & DETECT_CONTENT_WITHIN ||
2128  cd->flags & DETECT_CONTENT_NEGATED ) {
2129  printf("one failed\n");
2130  result = 0;
2131  goto end;
2132  }
2133 
2134  sm = sm->next;
2135  if (sm->type != DETECT_BYTE_EXTRACT) {
2136  result = 0;
2137  goto end;
2138  }
2139  bed = (SCDetectByteExtractData *)sm->ctx;
2140  if (bed->nbytes != 4 || bed->offset != 0 || strcmp(bed->name, "two") != 0 ||
2141  bed->flags != (DETECT_BYTE_EXTRACT_FLAG_STRING | DETECT_BYTE_EXTRACT_FLAG_BASE) ||
2142  bed->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed->align_value != 0 ||
2143  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
2144  goto end;
2145  }
2146  if (bed->local_id != 0) {
2147  result = 0;
2148  goto end;
2149  }
2150 
2151  sm = sm->next;
2152  if (sm->type != DETECT_CONTENT) {
2153  result = 0;
2154  goto end;
2155  }
2156  cd = (DetectContentData *)sm->ctx;
2157  if (strncmp((char *)cd->content, "three", cd->content_len) != 0 ||
2159  cd->depth != bed->local_id || cd->offset != 0) {
2160  printf("three failed\n");
2161  result = 0;
2162  goto end;
2163  }
2164 
2165  if (sm->next != NULL)
2166  goto end;
2167 
2168  result = 1;
2169 
2170  end:
2174 
2175  return result;
2176 }
2177 
2178 static int DetectByteExtractTest46(void)
2179 {
2180  DetectEngineCtx *de_ctx = NULL;
2181  int result = 0;
2182  Signature *s = NULL;
2183  SigMatch *sm = NULL;
2184  DetectContentData *cd = NULL;
2185  SCDetectByteExtractData *bed1 = NULL;
2186  SCDetectByteExtractData *bed2 = NULL;
2187 
2189  if (de_ctx == NULL)
2190  goto end;
2191 
2192  de_ctx->flags |= DE_QUIET;
2193  s = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
2194  "(msg:\"Testing bytejump_body\"; "
2195  "content:\"one\"; "
2196  "byte_extract:4,0,two,string,hex; "
2197  "byte_extract:4,0,three,string,hex; "
2198  "content: \"four\"; depth:two; "
2199  "content: \"five\"; depth:three; "
2200  "sid:1;)");
2201  if (de_ctx->sig_list == NULL) {
2202  result = 0;
2203  goto end;
2204  }
2205 
2206  if (s->init_data->smlists_tail[DETECT_SM_LIST_PMATCH] == NULL) {
2207  result = 0;
2208  goto end;
2209  }
2210 
2212  if (sm->type != DETECT_CONTENT) {
2213  result = 0;
2214  goto end;
2215  }
2216  cd = (DetectContentData *)sm->ctx;
2217  if (cd->flags & DETECT_CONTENT_RAWBYTES ||
2218  strncmp((char *)cd->content, "one", cd->content_len) != 0 ||
2219  cd->flags & DETECT_CONTENT_NOCASE ||
2220  cd->flags & DETECT_CONTENT_WITHIN ||
2224  cd->flags & DETECT_CONTENT_NEGATED ) {
2225  printf("one failed\n");
2226  result = 0;
2227  goto end;
2228  }
2229 
2230  sm = sm->next;
2231  if (sm->type != DETECT_BYTE_EXTRACT) {
2232  result = 0;
2233  goto end;
2234  }
2235  bed1 = (SCDetectByteExtractData *)sm->ctx;
2236  if (bed1->nbytes != 4 || bed1->offset != 0 || strcmp(bed1->name, "two") != 0 ||
2237  bed1->flags != (DETECT_BYTE_EXTRACT_FLAG_STRING | DETECT_BYTE_EXTRACT_FLAG_BASE) ||
2238  bed1->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed1->align_value != 0 ||
2239  bed1->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
2240  goto end;
2241  }
2242  if (bed1->local_id != 0) {
2243  result = 0;
2244  goto end;
2245  }
2246 
2247  sm = sm->next;
2248  if (sm->type != DETECT_BYTE_EXTRACT) {
2249  result = 0;
2250  goto end;
2251  }
2252  bed2 = (SCDetectByteExtractData *)sm->ctx;
2253 
2254  sm = sm->next;
2255  if (sm->type != DETECT_CONTENT) {
2256  result = 0;
2257  goto end;
2258  }
2259  cd = (DetectContentData *)sm->ctx;
2260  if (strncmp((char *)cd->content, "four", cd->content_len) != 0 ||
2262  cd->depth != bed1->local_id) {
2263  printf("four failed\n");
2264  result = 0;
2265  goto end;
2266  }
2267 
2268  sm = sm->next;
2269  if (sm->type != DETECT_CONTENT) {
2270  result = 0;
2271  goto end;
2272  }
2273  cd = (DetectContentData *)sm->ctx;
2274  if (strncmp((char *)cd->content, "five", cd->content_len) != 0 ||
2277  cd->depth != bed2->local_id) {
2278  printf("five failed\n");
2279  result = 0;
2280  goto end;
2281  }
2282 
2283  if (sm->next != NULL)
2284  goto end;
2285 
2286  result = 1;
2287 
2288  end:
2292 
2293  return result;
2294 }
2295 
2296 static int DetectByteExtractTest47(void)
2297 {
2298  DetectEngineCtx *de_ctx = NULL;
2299  int result = 0;
2300  Signature *s = NULL;
2301  SigMatch *sm = NULL;
2302  DetectContentData *cd = NULL;
2303  SCDetectByteExtractData *bed = NULL;
2304 
2306  if (de_ctx == NULL)
2307  goto end;
2308 
2309  de_ctx->flags |= DE_QUIET;
2310  s = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
2311  "(msg:\"Testing bytejump_body\"; "
2312  "content:\"one\"; "
2313  "byte_extract:4,0,two,string,hex; "
2314  "content: \"three\"; distance:two; "
2315  "sid:1;)");
2316  if (de_ctx->sig_list == NULL) {
2317  result = 0;
2318  goto end;
2319  }
2320 
2321  if (s->init_data->smlists_tail[DETECT_SM_LIST_PMATCH] == NULL) {
2322  result = 0;
2323  goto end;
2324  }
2325 
2327  if (sm->type != DETECT_CONTENT) {
2328  result = 0;
2329  goto end;
2330  }
2331  cd = (DetectContentData *)sm->ctx;
2332  if (cd->flags & DETECT_CONTENT_RAWBYTES ||
2333  strncmp((char *)cd->content, "one", cd->content_len) != 0 ||
2334  cd->flags & DETECT_CONTENT_NOCASE ||
2335  cd->flags & DETECT_CONTENT_WITHIN ||
2339  cd->flags & DETECT_CONTENT_NEGATED ) {
2340  printf("one failed\n");
2341  result = 0;
2342  goto end;
2343  }
2344 
2345  sm = sm->next;
2346  if (sm->type != DETECT_BYTE_EXTRACT) {
2347  result = 0;
2348  goto end;
2349  }
2350  bed = (SCDetectByteExtractData *)sm->ctx;
2351  if (bed->nbytes != 4 || bed->offset != 0 || strcmp(bed->name, "two") != 0 ||
2352  bed->flags != (DETECT_BYTE_EXTRACT_FLAG_STRING | DETECT_BYTE_EXTRACT_FLAG_BASE) ||
2353  bed->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed->align_value != 0 ||
2354  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
2355  goto end;
2356  }
2357  if (bed->local_id != 0) {
2358  result = 0;
2359  goto end;
2360  }
2361 
2362  sm = sm->next;
2363  if (sm->type != DETECT_CONTENT) {
2364  result = 0;
2365  goto end;
2366  }
2367  cd = (DetectContentData *)sm->ctx;
2368  if (strncmp((char *)cd->content, "three", cd->content_len) != 0 ||
2369  cd->flags !=
2371  cd->distance != bed->local_id || cd->offset != 0 || cd->depth != 0) {
2372  printf("three failed\n");
2373  result = 0;
2374  goto end;
2375  }
2376 
2377  if (sm->next != NULL)
2378  goto end;
2379 
2380  result = 1;
2381 
2382  end:
2386 
2387  return result;
2388 }
2389 
2390 static int DetectByteExtractTest48(void)
2391 {
2392  DetectEngineCtx *de_ctx = NULL;
2393  int result = 0;
2394  Signature *s = NULL;
2395  SigMatch *sm = NULL;
2396  DetectContentData *cd = NULL;
2397  SCDetectByteExtractData *bed1 = NULL;
2398  SCDetectByteExtractData *bed2 = NULL;
2399 
2401  if (de_ctx == NULL)
2402  goto end;
2403 
2404  de_ctx->flags |= DE_QUIET;
2405  s = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
2406  "(msg:\"Testing bytejump_body\"; "
2407  "content:\"one\"; "
2408  "byte_extract:4,0,two,string,hex; "
2409  "byte_extract:4,0,three,string,hex; "
2410  "content: \"four\"; distance:two; "
2411  "content: \"five\"; distance:three; "
2412  "sid:1;)");
2413  if (de_ctx->sig_list == NULL) {
2414  result = 0;
2415  goto end;
2416  }
2417 
2418  if (s->init_data->smlists_tail[DETECT_SM_LIST_PMATCH] == NULL) {
2419  result = 0;
2420  goto end;
2421  }
2422 
2424  if (sm->type != DETECT_CONTENT) {
2425  result = 0;
2426  goto end;
2427  }
2428  cd = (DetectContentData *)sm->ctx;
2429  if (cd->flags & DETECT_CONTENT_RAWBYTES ||
2430  strncmp((char *)cd->content, "one", cd->content_len) != 0 ||
2431  cd->flags & DETECT_CONTENT_NOCASE ||
2432  cd->flags & DETECT_CONTENT_WITHIN ||
2436  cd->flags & DETECT_CONTENT_NEGATED ) {
2437  printf("one failed\n");
2438  result = 0;
2439  goto end;
2440  }
2441 
2442  sm = sm->next;
2443  if (sm->type != DETECT_BYTE_EXTRACT) {
2444  result = 0;
2445  goto end;
2446  }
2447  bed1 = (SCDetectByteExtractData *)sm->ctx;
2448  if (bed1->nbytes != 4 || bed1->offset != 0 || strcmp(bed1->name, "two") != 0 ||
2449  bed1->flags != (DETECT_BYTE_EXTRACT_FLAG_STRING | DETECT_BYTE_EXTRACT_FLAG_BASE) ||
2450  bed1->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed1->align_value != 0 ||
2451  bed1->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
2452  goto end;
2453  }
2454  if (bed1->local_id != 0) {
2455  result = 0;
2456  goto end;
2457  }
2458 
2459  sm = sm->next;
2460  if (sm->type != DETECT_BYTE_EXTRACT) {
2461  result = 0;
2462  goto end;
2463  }
2464  bed2 = (SCDetectByteExtractData *)sm->ctx;
2465 
2466  sm = sm->next;
2467  if (sm->type != DETECT_CONTENT) {
2468  result = 0;
2469  goto end;
2470  }
2471  cd = (DetectContentData *)sm->ctx;
2472  if (strncmp((char *)cd->content, "four", cd->content_len) != 0 ||
2475  cd->distance != bed1->local_id || cd->depth != 0 || cd->offset != 0) {
2476  printf("four failed\n");
2477  result = 0;
2478  goto end;
2479  }
2480 
2481  sm = sm->next;
2482  if (sm->type != DETECT_CONTENT) {
2483  result = 0;
2484  goto end;
2485  }
2486  cd = (DetectContentData *)sm->ctx;
2487  if (strncmp((char *)cd->content, "five", cd->content_len) != 0 ||
2490  cd->distance != bed2->local_id ||
2491  cd->depth != 0 ||
2492  cd->offset != 0) {
2493  printf("five failed\n");
2494  result = 0;
2495  goto end;
2496  }
2497 
2498  if (sm->next != NULL)
2499  goto end;
2500 
2501  result = 1;
2502 
2503  end:
2507 
2508  return result;
2509 }
2510 
2511 static int DetectByteExtractTest49(void)
2512 {
2513  DetectEngineCtx *de_ctx = NULL;
2514  int result = 0;
2515  Signature *s = NULL;
2516  SigMatch *sm = NULL;
2517  DetectContentData *cd = NULL;
2518  SCDetectByteExtractData *bed = NULL;
2519 
2521  if (de_ctx == NULL)
2522  goto end;
2523 
2524  de_ctx->flags |= DE_QUIET;
2525  s = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
2526  "(msg:\"Testing bytejump_body\"; "
2527  "content:\"one\"; "
2528  "byte_extract:4,0,two,string,hex; "
2529  "content: \"three\"; within:two; "
2530  "sid:1;)");
2531  if (de_ctx->sig_list == NULL) {
2532  result = 0;
2533  goto end;
2534  }
2535 
2536  if (s->init_data->smlists_tail[DETECT_SM_LIST_PMATCH] == NULL) {
2537  result = 0;
2538  goto end;
2539  }
2540 
2542  if (sm->type != DETECT_CONTENT) {
2543  result = 0;
2544  goto end;
2545  }
2546  cd = (DetectContentData *)sm->ctx;
2547  if (cd->flags & DETECT_CONTENT_RAWBYTES ||
2548  strncmp((char *)cd->content, "one", cd->content_len) != 0 ||
2549  cd->flags & DETECT_CONTENT_NOCASE ||
2550  cd->flags & DETECT_CONTENT_WITHIN ||
2554  cd->flags & DETECT_CONTENT_NEGATED ) {
2555  printf("one failed\n");
2556  result = 0;
2557  goto end;
2558  }
2559 
2560  sm = sm->next;
2561  if (sm->type != DETECT_BYTE_EXTRACT) {
2562  result = 0;
2563  goto end;
2564  }
2565  bed = (SCDetectByteExtractData *)sm->ctx;
2566  if (bed->nbytes != 4 || bed->offset != 0 || strcmp(bed->name, "two") != 0 ||
2567  bed->flags != (DETECT_BYTE_EXTRACT_FLAG_STRING | DETECT_BYTE_EXTRACT_FLAG_BASE) ||
2568  bed->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed->align_value != 0 ||
2569  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
2570  goto end;
2571  }
2572  if (bed->local_id != 0) {
2573  result = 0;
2574  goto end;
2575  }
2576 
2577  sm = sm->next;
2578  if (sm->type != DETECT_CONTENT) {
2579  result = 0;
2580  goto end;
2581  }
2582  cd = (DetectContentData *)sm->ctx;
2583  if (strncmp((char *)cd->content, "three", cd->content_len) != 0 ||
2585  cd->within != bed->local_id || cd->offset != 0 || cd->depth != 0 || cd->distance != 0) {
2586  printf("three failed\n");
2587  result = 0;
2588  goto end;
2589  }
2590 
2591  if (sm->next != NULL)
2592  goto end;
2593 
2594  result = 1;
2595 
2596  end:
2600 
2601  return result;
2602 }
2603 
2604 static int DetectByteExtractTest50(void)
2605 {
2606  DetectEngineCtx *de_ctx = NULL;
2607  int result = 0;
2608  Signature *s = NULL;
2609  SigMatch *sm = NULL;
2610  DetectContentData *cd = NULL;
2611  SCDetectByteExtractData *bed1 = NULL;
2612  SCDetectByteExtractData *bed2 = NULL;
2613 
2615  if (de_ctx == NULL)
2616  goto end;
2617 
2618  de_ctx->flags |= DE_QUIET;
2619  s = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
2620  "(msg:\"Testing bytejump_body\"; "
2621  "content:\"one\"; "
2622  "byte_extract:4,0,two,string,hex; "
2623  "byte_extract:4,0,three,string,hex; "
2624  "content: \"four\"; within:two; "
2625  "content: \"five\"; within:three; "
2626  "sid:1;)");
2627  if (de_ctx->sig_list == NULL) {
2628  result = 0;
2629  goto end;
2630  }
2631 
2632  if (s->init_data->smlists_tail[DETECT_SM_LIST_PMATCH] == NULL) {
2633  result = 0;
2634  goto end;
2635  }
2636 
2638  if (sm->type != DETECT_CONTENT) {
2639  result = 0;
2640  goto end;
2641  }
2642  cd = (DetectContentData *)sm->ctx;
2643  if (cd->flags & DETECT_CONTENT_RAWBYTES ||
2644  strncmp((char *)cd->content, "one", cd->content_len) != 0 ||
2645  cd->flags & DETECT_CONTENT_NOCASE ||
2646  cd->flags & DETECT_CONTENT_WITHIN ||
2650  cd->flags & DETECT_CONTENT_NEGATED ) {
2651  printf("one failed\n");
2652  result = 0;
2653  goto end;
2654  }
2655 
2656  sm = sm->next;
2657  if (sm->type != DETECT_BYTE_EXTRACT) {
2658  result = 0;
2659  goto end;
2660  }
2661  bed1 = (SCDetectByteExtractData *)sm->ctx;
2662  if (bed1->nbytes != 4 || bed1->offset != 0 || strcmp(bed1->name, "two") != 0 ||
2663  bed1->flags != (DETECT_BYTE_EXTRACT_FLAG_STRING | DETECT_BYTE_EXTRACT_FLAG_BASE) ||
2664  bed1->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed1->align_value != 0 ||
2665  bed1->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
2666  goto end;
2667  }
2668  if (bed1->local_id != 0) {
2669  result = 0;
2670  goto end;
2671  }
2672 
2673  sm = sm->next;
2674  if (sm->type != DETECT_BYTE_EXTRACT) {
2675  result = 0;
2676  goto end;
2677  }
2678  bed2 = (SCDetectByteExtractData *)sm->ctx;
2679 
2680  sm = sm->next;
2681  if (sm->type != DETECT_CONTENT) {
2682  result = 0;
2683  goto end;
2684  }
2685  cd = (DetectContentData *)sm->ctx;
2686  if (strncmp((char *)cd->content, "four", cd->content_len) != 0 ||
2689  cd->within != bed1->local_id || cd->depth != 0 || cd->offset != 0 ||
2690  cd->distance != 0) {
2691  printf("four failed\n");
2692  result = 0;
2693  goto end;
2694  }
2695 
2696  sm = sm->next;
2697  if (sm->type != DETECT_CONTENT) {
2698  result = 0;
2699  goto end;
2700  }
2701  cd = (DetectContentData *)sm->ctx;
2702  if (strncmp((char *)cd->content, "five", cd->content_len) != 0 ||
2705  cd->within != bed2->local_id ||
2706  cd->depth != 0 ||
2707  cd->offset != 0 ||
2708  cd->distance != 0) {
2709  printf("five failed\n");
2710  result = 0;
2711  goto end;
2712  }
2713 
2714  if (sm->next != NULL)
2715  goto end;
2716 
2717  result = 1;
2718 
2719  end:
2723 
2724  return result;
2725 }
2726 
2727 static int DetectByteExtractTest51(void)
2728 {
2729  DetectEngineCtx *de_ctx = NULL;
2730  int result = 0;
2731  Signature *s = NULL;
2732  SigMatch *sm = NULL;
2733  DetectContentData *cd = NULL;
2734  SCDetectByteExtractData *bed = NULL;
2735  DetectBytetestData *btd = NULL;
2736 
2738  if (de_ctx == NULL)
2739  goto end;
2740 
2741  de_ctx->flags |= DE_QUIET;
2742  s = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
2743  "(msg:\"Testing bytejump_body\"; "
2744  "content:\"one\"; "
2745  "byte_extract:4,0,two,string,hex; "
2746  "byte_test: 2,=,10, two; "
2747  "sid:1;)");
2748  if (de_ctx->sig_list == NULL) {
2749  result = 0;
2750  goto end;
2751  }
2752 
2753  if (s->init_data->smlists_tail[DETECT_SM_LIST_PMATCH] == NULL) {
2754  result = 0;
2755  goto end;
2756  }
2757 
2759  if (sm->type != DETECT_CONTENT) {
2760  result = 0;
2761  goto end;
2762  }
2763  cd = (DetectContentData *)sm->ctx;
2764  if (cd->flags & DETECT_CONTENT_RAWBYTES ||
2765  strncmp((char *)cd->content, "one", cd->content_len) != 0 ||
2766  cd->flags & DETECT_CONTENT_NOCASE ||
2767  cd->flags & DETECT_CONTENT_WITHIN ||
2771  cd->flags & DETECT_CONTENT_NEGATED ) {
2772  printf("one failed\n");
2773  result = 0;
2774  goto end;
2775  }
2776 
2777  sm = sm->next;
2778  if (sm->type != DETECT_BYTE_EXTRACT) {
2779  result = 0;
2780  goto end;
2781  }
2782  bed = (SCDetectByteExtractData *)sm->ctx;
2783  if (bed->nbytes != 4 || bed->offset != 0 || strcmp(bed->name, "two") != 0 ||
2784  bed->flags != (DETECT_BYTE_EXTRACT_FLAG_STRING | DETECT_BYTE_EXTRACT_FLAG_BASE) ||
2785  bed->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed->align_value != 0 ||
2786  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
2787  goto end;
2788  }
2789  if (bed->local_id != 0) {
2790  result = 0;
2791  goto end;
2792  }
2793 
2794  sm = sm->next;
2795  if (sm->type != DETECT_BYTETEST) {
2796  result = 0;
2797  goto end;
2798  }
2799  btd = (DetectBytetestData *)sm->ctx;
2800  if (btd->flags != DETECT_BYTETEST_OFFSET_VAR ||
2801  btd->value != 10 ||
2802  btd->offset != 0) {
2803  printf("three failed\n");
2804  result = 0;
2805  goto end;
2806  }
2807 
2808  if (sm->next != NULL)
2809  goto end;
2810 
2811  result = 1;
2812 
2813  end:
2817 
2818  return result;
2819 }
2820 
2821 static int DetectByteExtractTest52(void)
2822 {
2823  DetectEngineCtx *de_ctx = NULL;
2824  int result = 0;
2825  Signature *s = NULL;
2826  SigMatch *sm = NULL;
2827  DetectContentData *cd = NULL;
2828  SCDetectByteExtractData *bed1 = NULL;
2829  DetectBytetestData *btd = NULL;
2830 
2832  if (de_ctx == NULL)
2833  goto end;
2834 
2835  de_ctx->flags |= DE_QUIET;
2836  s = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
2837  "(msg:\"Testing bytejump_body\"; "
2838  "content:\"one\"; "
2839  "byte_extract:4,0,two,string,hex; "
2840  "byte_extract:4,0,three,string,hex; "
2841  "byte_test: 2,=,two,three; "
2842  "byte_test: 3,=,10,three; "
2843  "sid:1;)");
2844  if (de_ctx->sig_list == NULL) {
2845  result = 0;
2846  goto end;
2847  }
2848 
2849  if (s->init_data->smlists_tail[DETECT_SM_LIST_PMATCH] == NULL) {
2850  result = 0;
2851  goto end;
2852  }
2853 
2855  if (sm->type != DETECT_CONTENT) {
2856  result = 0;
2857  goto end;
2858  }
2859  cd = (DetectContentData *)sm->ctx;
2860  if (cd->flags & DETECT_CONTENT_RAWBYTES ||
2861  strncmp((char *)cd->content, "one", cd->content_len) != 0 ||
2862  cd->flags & DETECT_CONTENT_NOCASE ||
2863  cd->flags & DETECT_CONTENT_WITHIN ||
2867  cd->flags & DETECT_CONTENT_NEGATED ) {
2868  printf("one failed\n");
2869  result = 0;
2870  goto end;
2871  }
2872 
2873  sm = sm->next;
2874  if (sm->type != DETECT_BYTE_EXTRACT) {
2875  result = 0;
2876  goto end;
2877  }
2878  bed1 = (SCDetectByteExtractData *)sm->ctx;
2879  if (bed1->nbytes != 4 || bed1->offset != 0 || strcmp(bed1->name, "two") != 0 ||
2880  bed1->flags != (DETECT_BYTE_EXTRACT_FLAG_STRING | DETECT_BYTE_EXTRACT_FLAG_BASE) ||
2881  bed1->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed1->align_value != 0 ||
2882  bed1->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
2883  goto end;
2884  }
2885  if (bed1->local_id != 0) {
2886  result = 0;
2887  goto end;
2888  }
2889 
2890  sm = sm->next;
2891  if (sm->type != DETECT_BYTE_EXTRACT) {
2892  result = 0;
2893  goto end;
2894  }
2895 
2896  sm = sm->next;
2897  if (sm->type != DETECT_BYTETEST) {
2898  result = 0;
2899  goto end;
2900  }
2901  btd = (DetectBytetestData *)sm->ctx;
2902  if (btd->flags != (DETECT_BYTETEST_OFFSET_VAR |
2904  btd->value != 0 ||
2905  btd->offset != 1) {
2906  printf("three failed\n");
2907  result = 0;
2908  goto end;
2909  }
2910 
2911  sm = sm->next;
2912  if (sm->type != DETECT_BYTETEST) {
2913  result = 0;
2914  goto end;
2915  }
2916  btd = (DetectBytetestData *)sm->ctx;
2917  if (btd->flags != DETECT_BYTETEST_OFFSET_VAR ||
2918  btd->value != 10 ||
2919  btd->offset != 1) {
2920  printf("four failed\n");
2921  result = 0;
2922  goto end;
2923  }
2924 
2925  if (sm->next != NULL)
2926  goto end;
2927 
2928  result = 1;
2929 
2930  end:
2934 
2935  return result;
2936 }
2937 
2938 static int DetectByteExtractTest53(void)
2939 {
2942  de_ctx->flags |= DE_QUIET;
2943 
2944  Signature *s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any ("
2945  "content:\"one\"; "
2946  "byte_extract:4,0,two,string,hex; "
2947  "byte_jump: 2,two; "
2948  "sid:1;)");
2949  FAIL_IF_NULL(s);
2951 
2953  FAIL_IF(sm->type != DETECT_CONTENT);
2956 
2957  sm = sm->next;
2958  FAIL_IF_NULL(sm);
2960  SCDetectByteExtractData *bed = (SCDetectByteExtractData *)sm->ctx;
2961 
2962  FAIL_IF(bed->nbytes != 4);
2963  FAIL_IF(bed->offset != 0);
2964  FAIL_IF(strcmp(bed->name, "two") != 0);
2965  FAIL_IF(bed->flags != (DETECT_BYTE_EXTRACT_FLAG_BASE | DETECT_BYTE_EXTRACT_FLAG_STRING));
2966  FAIL_IF(bed->base != DETECT_BYTE_EXTRACT_BASE_HEX);
2967  FAIL_IF(bed->align_value != 0);
2968  FAIL_IF(bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT);
2969  FAIL_IF(bed->local_id != 0);
2970 
2971  sm = sm->next;
2972  FAIL_IF_NULL(sm);
2973  FAIL_IF(sm->type != DETECT_BYTEJUMP);
2975 
2977  FAIL_IF(bjd->offset != 0);
2978 
2979  FAIL_IF_NOT_NULL(sm->next);
2981  PASS;
2982 }
2983 
2984 static int DetectByteExtractTest54(void)
2985 {
2986  DetectEngineCtx *de_ctx = NULL;
2987  int result = 0;
2988  Signature *s = NULL;
2989  SigMatch *sm = NULL;
2990  DetectContentData *cd = NULL;
2991  SCDetectByteExtractData *bed1 = NULL;
2992  DetectBytejumpData *bjd = NULL;
2993 
2995  if (de_ctx == NULL)
2996  goto end;
2997 
2998  de_ctx->flags |= DE_QUIET;
2999  s = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
3000  "(msg:\"Testing bytejump_body\"; "
3001  "content:\"one\"; "
3002  "byte_extract:4,0,two,string,hex; "
3003  "byte_extract:4,0,three,string,hex; "
3004  "byte_jump: 2,two; "
3005  "byte_jump: 3,three; "
3006  "sid:1;)");
3007  if (de_ctx->sig_list == NULL) {
3008  result = 0;
3009  goto end;
3010  }
3011 
3012  if (s->init_data->smlists_tail[DETECT_SM_LIST_PMATCH] == NULL) {
3013  result = 0;
3014  goto end;
3015  }
3016 
3018  if (sm->type != DETECT_CONTENT) {
3019  result = 0;
3020  goto end;
3021  }
3022  cd = (DetectContentData *)sm->ctx;
3023  if (cd->flags & DETECT_CONTENT_RAWBYTES ||
3024  strncmp((char *)cd->content, "one", cd->content_len) != 0 ||
3025  cd->flags & DETECT_CONTENT_NOCASE ||
3026  cd->flags & DETECT_CONTENT_WITHIN ||
3030  cd->flags & DETECT_CONTENT_NEGATED ) {
3031  printf("one failed\n");
3032  result = 0;
3033  goto end;
3034  }
3035 
3036  sm = sm->next;
3037  if (sm->type != DETECT_BYTE_EXTRACT) {
3038  result = 0;
3039  goto end;
3040  }
3041  bed1 = (SCDetectByteExtractData *)sm->ctx;
3042  if (bed1->nbytes != 4 || bed1->offset != 0 || strcmp(bed1->name, "two") != 0 ||
3043  bed1->flags != (DETECT_BYTE_EXTRACT_FLAG_STRING | DETECT_BYTE_EXTRACT_FLAG_BASE) ||
3044  bed1->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed1->align_value != 0 ||
3045  bed1->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
3046  goto end;
3047  }
3048  if (bed1->local_id != 0) {
3049  result = 0;
3050  goto end;
3051  }
3052 
3053  sm = sm->next;
3054  if (sm->type != DETECT_BYTE_EXTRACT) {
3055  result = 0;
3056  goto end;
3057  }
3058 
3059  sm = sm->next;
3060  if (sm->type != DETECT_BYTEJUMP) {
3061  result = 0;
3062  goto end;
3063  }
3064  bjd = (DetectBytejumpData *)sm->ctx;
3065  if (bjd->flags != DETECT_BYTEJUMP_OFFSET_VAR || bjd->offset != 0) {
3066  printf("three failed\n");
3067  result = 0;
3068  goto end;
3069  }
3070 
3071  sm = sm->next;
3072  if (sm->type != DETECT_BYTEJUMP) {
3073  result = 0;
3074  goto end;
3075  }
3076  bjd = (DetectBytejumpData *)sm->ctx;
3078  FAIL_IF(bjd->offset != 1);
3079 
3080  if (sm->next != NULL)
3081  goto end;
3082 
3083  result = 1;
3084 
3085  end:
3089 
3090  return result;
3091 }
3092 
3093 static int DetectByteExtractTest55(void)
3094 {
3095  DetectEngineCtx *de_ctx = NULL;
3096  int result = 0;
3097  Signature *s = NULL;
3098  SigMatch *sm = NULL;
3099  DetectContentData *cd = NULL;
3100  SCDetectByteExtractData *bed1 = NULL;
3101  SCDetectByteExtractData *bed2 = NULL;
3102 
3104  if (de_ctx == NULL)
3105  goto end;
3106 
3107  de_ctx->flags |= DE_QUIET;
3108  s = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
3109  "(msg:\"Testing byte_extract\"; "
3110  "content:\"one\"; "
3111  "byte_extract:4,0,two,string,hex; "
3112  "byte_extract:4,0,three,string,hex; "
3113  "byte_extract:4,0,four,string,hex; "
3114  "byte_extract:4,0,five,string,hex; "
3115  "content: \"four\"; within:two; distance:three; "
3116  "sid:1;)");
3117  if (de_ctx->sig_list == NULL) {
3118  goto end;
3119  }
3120 
3121  if (s->init_data->smlists_tail[DETECT_SM_LIST_PMATCH] == NULL) {
3122  goto end;
3123  }
3124 
3126  if (sm->type != DETECT_CONTENT) {
3127  goto end;
3128  }
3129  cd = (DetectContentData *)sm->ctx;
3130  if (cd->flags & DETECT_CONTENT_RAWBYTES ||
3131  strncmp((char *)cd->content, "one", cd->content_len) != 0 ||
3132  cd->flags & DETECT_CONTENT_NOCASE ||
3133  cd->flags & DETECT_CONTENT_WITHIN ||
3137  cd->flags & DETECT_CONTENT_NEGATED ) {
3138  printf("one failed: ");
3139  goto end;
3140  }
3141 
3142  sm = sm->next;
3143  if (sm->type != DETECT_BYTE_EXTRACT) {
3144  goto end;
3145  }
3146  bed1 = (SCDetectByteExtractData *)sm->ctx;
3147  if (bed1->nbytes != 4 || bed1->offset != 0 || strcmp(bed1->name, "two") != 0 ||
3148  bed1->flags != (DETECT_BYTE_EXTRACT_FLAG_STRING | DETECT_BYTE_EXTRACT_FLAG_BASE) ||
3149  bed1->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed1->align_value != 0 ||
3150  bed1->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
3151  goto end;
3152  }
3153  if (bed1->local_id != 0) {
3154  goto end;
3155  }
3156 
3157  sm = sm->next;
3158  if (sm->type != DETECT_BYTE_EXTRACT) {
3159  goto end;
3160  }
3161  bed2 = (SCDetectByteExtractData *)sm->ctx;
3162 
3163  sm = sm->next;
3164  if (sm->type != DETECT_BYTE_EXTRACT) {
3165  goto end;
3166  }
3167 
3168  sm = sm->next;
3169  if (sm->type != DETECT_BYTE_EXTRACT) {
3170  goto end;
3171  }
3172 
3173  sm = sm->next;
3174  if (sm->type != DETECT_CONTENT) {
3175  goto end;
3176  }
3177  cd = (DetectContentData *)sm->ctx;
3178  if (strncmp((char *)cd->content, "four", cd->content_len) != 0 ||
3179  cd->flags !=
3182  cd->within != bed1->local_id || cd->distance != bed2->local_id) {
3183  printf("four failed: ");
3184  goto end;
3185  }
3186 
3187  if (sm->next != NULL) {
3188  goto end;
3189  }
3190 
3191  result = 1;
3192 
3193  end:
3197 
3198  return result;
3199 }
3200 
3201 static int DetectByteExtractTest56(void)
3202 {
3203  DetectEngineCtx *de_ctx = NULL;
3204  int result = 0;
3205  Signature *s = NULL;
3206  SigMatch *sm = NULL;
3207  DetectContentData *cd = NULL;
3208  SCDetectByteExtractData *bed1 = NULL;
3209  SCDetectByteExtractData *bed2 = NULL;
3210 
3212  if (de_ctx == NULL)
3213  goto end;
3214 
3215  de_ctx->flags |= DE_QUIET;
3216  s = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
3217  "(msg:\"Testing bytejump_body\"; "
3218  "uricontent:\"urione\"; "
3219  "content:\"one\"; "
3220  "byte_extract:4,0,two,string,hex; "
3221  "byte_extract:4,0,three,string,hex; "
3222  "byte_extract:4,0,four,string,hex; "
3223  "byte_extract:4,0,five,string,hex; "
3224  "content: \"four\"; within:two; distance:three; "
3225  "sid:1;)");
3226  if (de_ctx->sig_list == NULL) {
3227  result = 0;
3228  goto end;
3229  }
3230 
3231  if (s->init_data->smlists_tail[DETECT_SM_LIST_PMATCH] == NULL) {
3232  result = 0;
3233  goto end;
3234  }
3235 
3236  sm = DetectBufferGetFirstSigMatch(s, g_http_uri_buffer_id);
3237  if (sm->type != DETECT_CONTENT) {
3238  result = 0;
3239  goto end;
3240  }
3241  cd = (DetectContentData *)sm->ctx;
3242  if (cd->flags & DETECT_CONTENT_RAWBYTES ||
3243  strncmp((char *)cd->content, "urione", cd->content_len) != 0 ||
3244  cd->flags & DETECT_CONTENT_NOCASE ||
3245  cd->flags & DETECT_CONTENT_WITHIN ||
3249  cd->flags & DETECT_CONTENT_NEGATED ) {
3250  printf("one failed\n");
3251  result = 0;
3252  goto end;
3253  }
3254 
3255  if (sm->next != NULL)
3256  goto end;
3257 
3259  if (sm->type != DETECT_CONTENT) {
3260  result = 0;
3261  goto end;
3262  }
3263  cd = (DetectContentData *)sm->ctx;
3264  if (cd->flags & DETECT_CONTENT_RAWBYTES ||
3265  strncmp((char *)cd->content, "one", cd->content_len) != 0 ||
3266  cd->flags & DETECT_CONTENT_NOCASE ||
3267  cd->flags & DETECT_CONTENT_WITHIN ||
3271  cd->flags & DETECT_CONTENT_NEGATED ) {
3272  printf("one failed\n");
3273  result = 0;
3274  goto end;
3275  }
3276 
3277  sm = sm->next;
3278  if (sm->type != DETECT_BYTE_EXTRACT) {
3279  result = 0;
3280  goto end;
3281  }
3282  bed1 = (SCDetectByteExtractData *)sm->ctx;
3283  if (bed1->nbytes != 4 || bed1->offset != 0 || strcmp(bed1->name, "two") != 0 ||
3284  bed1->flags != (DETECT_BYTE_EXTRACT_FLAG_STRING | DETECT_BYTE_EXTRACT_FLAG_BASE) ||
3285  bed1->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed1->align_value != 0 ||
3286  bed1->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
3287  goto end;
3288  }
3289  if (bed1->local_id != 0) {
3290  result = 0;
3291  goto end;
3292  }
3293 
3294  sm = sm->next;
3295  if (sm->type != DETECT_BYTE_EXTRACT) {
3296  result = 0;
3297  goto end;
3298  }
3299  bed2 = (SCDetectByteExtractData *)sm->ctx;
3300 
3301  sm = sm->next;
3302  if (sm->type != DETECT_BYTE_EXTRACT) {
3303  result = 0;
3304  goto end;
3305  }
3306 
3307  sm = sm->next;
3308  if (sm->type != DETECT_BYTE_EXTRACT) {
3309  result = 0;
3310  goto end;
3311  }
3312 
3313  sm = sm->next;
3314  if (sm->type != DETECT_CONTENT) {
3315  result = 0;
3316  goto end;
3317  }
3318  cd = (DetectContentData *)sm->ctx;
3319  if (strncmp((char *)cd->content, "four", cd->content_len) != 0 ||
3324  cd->within != bed1->local_id ||
3325  cd->distance != bed2->local_id ) {
3326  printf("four failed\n");
3327  result = 0;
3328  goto end;
3329  }
3330 
3331  if (sm->next != NULL) {
3332  goto end;
3333  }
3334 
3335  result = 1;
3336 
3337  end:
3341 
3342  return result;
3343 }
3344 
3345 static int DetectByteExtractTest57(void)
3346 {
3347  DetectEngineCtx *de_ctx = NULL;
3348  int result = 0;
3349  Signature *s = NULL;
3350  SigMatch *sm = NULL;
3351  DetectContentData *cd = NULL;
3352  SCDetectByteExtractData *bed1 = NULL;
3353  SCDetectByteExtractData *bed2 = NULL;
3354  SCDetectByteExtractData *bed3 = NULL;
3355  SCDetectByteExtractData *bed4 = NULL;
3356 
3358  if (de_ctx == NULL)
3359  goto end;
3360 
3361  de_ctx->flags |= DE_QUIET;
3362  s = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
3363  "(msg:\"Testing bytejump_body\"; "
3364  "content:\"one\"; "
3365  "uricontent: \"urione\"; "
3366  "byte_extract:4,0,two,string,hex,relative; "
3367  "byte_extract:4,0,three,string,hex,relative; "
3368  "byte_extract:4,0,four,string,hex,relative; "
3369  "byte_extract:4,0,five,string,hex,relative; "
3370  "uricontent: \"four\"; within:two; distance:three; "
3371  "sid:1;)");
3372  if (de_ctx->sig_list == NULL) {
3373  result = 0;
3374  goto end;
3375  }
3376 
3377  if (s->init_data->smlists_tail[DETECT_SM_LIST_PMATCH] == NULL) {
3378  result = 0;
3379  goto end;
3380  }
3381 
3383  if (sm->type != DETECT_CONTENT) {
3384  result = 0;
3385  goto end;
3386  }
3387  cd = (DetectContentData *)sm->ctx;
3388  if (cd->flags & DETECT_CONTENT_RAWBYTES ||
3389  strncmp((char *)cd->content, "one", cd->content_len) != 0 ||
3390  cd->flags & DETECT_CONTENT_NOCASE ||
3391  cd->flags & DETECT_CONTENT_WITHIN ||
3395  cd->flags & DETECT_CONTENT_NEGATED ) {
3396  printf("one failed\n");
3397  result = 0;
3398  goto end;
3399  }
3400 
3401  if (sm->next != NULL)
3402  goto end;
3403 
3404  sm = DetectBufferGetFirstSigMatch(s, g_http_uri_buffer_id);
3405  if (sm->type != DETECT_CONTENT) {
3406  result = 0;
3407  goto end;
3408  }
3409  cd = (DetectContentData *)sm->ctx;
3410  if (cd->flags & DETECT_CONTENT_RAWBYTES ||
3411  strncmp((char *)cd->content, "urione", cd->content_len) != 0 ||
3412  cd->flags & DETECT_CONTENT_NOCASE ||
3413  cd->flags & DETECT_CONTENT_WITHIN ||
3417  cd->flags & DETECT_CONTENT_NEGATED ) {
3418  printf("one failed\n");
3419  result = 0;
3420  goto end;
3421  }
3422 
3423  sm = sm->next;
3424  if (sm->type != DETECT_BYTE_EXTRACT) {
3425  result = 0;
3426  goto end;
3427  }
3428  bed1 = (SCDetectByteExtractData *)sm->ctx;
3429  if (bed1->nbytes != 4 || bed1->offset != 0 || strcmp(bed1->name, "two") != 0 ||
3430  bed1->flags != (DETECT_BYTE_EXTRACT_FLAG_STRING | DETECT_BYTE_EXTRACT_FLAG_BASE |
3431  DETECT_BYTE_EXTRACT_FLAG_RELATIVE) ||
3432  bed1->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed1->align_value != 0 ||
3433  bed1->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
3434  goto end;
3435  }
3436  if (bed1->local_id != 0) {
3437  result = 0;
3438  goto end;
3439  }
3440 
3441  sm = sm->next;
3442  if (sm->type != DETECT_BYTE_EXTRACT) {
3443  result = 0;
3444  goto end;
3445  }
3446  bed2 = (SCDetectByteExtractData *)sm->ctx;
3447  if (bed2->local_id != 1) {
3448  result = 0;
3449  goto end;
3450  }
3451 
3452  sm = sm->next;
3453  if (sm->type != DETECT_BYTE_EXTRACT) {
3454  result = 0;
3455  goto end;
3456  }
3457  bed3 = (SCDetectByteExtractData *)sm->ctx;
3458  if (bed3->local_id != 2) {
3459  result = 0;
3460  goto end;
3461  }
3462 
3463  sm = sm->next;
3464  if (sm->type != DETECT_BYTE_EXTRACT) {
3465  result = 0;
3466  goto end;
3467  }
3468  bed4 = (SCDetectByteExtractData *)sm->ctx;
3469  if (bed4->local_id != 3) {
3470  result = 0;
3471  goto end;
3472  }
3473 
3474  sm = sm->next;
3475  if (sm->type != DETECT_CONTENT) {
3476  result = 0;
3477  goto end;
3478  }
3479  cd = (DetectContentData *)sm->ctx;
3480  if (strncmp((char *)cd->content, "four", cd->content_len) != 0 ||
3485  cd->within != bed1->local_id ||
3486  cd->distance != bed2->local_id) {
3487  printf("four failed\n");
3488  result = 0;
3489  goto end;
3490  }
3491 
3492  if (sm->next != NULL) {
3493  goto end;
3494  }
3495 
3496  result = 1;
3497 
3498  end:
3502 
3503  return result;
3504 }
3505 
3506 static int DetectByteExtractTest58(void)
3507 {
3508  DetectEngineCtx *de_ctx = NULL;
3509  int result = 0;
3510  Signature *s = NULL;
3511  SigMatch *sm = NULL;
3512  DetectContentData *cd = NULL;
3513  SCDetectByteExtractData *bed1 = NULL;
3514  DetectBytejumpData *bjd = NULL;
3515  DetectIsdataatData *isdd = NULL;
3516 
3518  if (de_ctx == NULL)
3519  goto end;
3520 
3521  de_ctx->flags |= DE_QUIET;
3522  s = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
3523  "(msg:\"Testing bytejump_body\"; "
3524  "content:\"one\"; "
3525  "byte_extract:4,0,two,string,hex; "
3526  "byte_extract:4,0,three,string,hex; "
3527  "byte_jump: 2,two; "
3528  "byte_jump: 3,three; "
3529  "isdataat: three; "
3530  "sid:1;)");
3531  if (de_ctx->sig_list == NULL) {
3532  result = 0;
3533  goto end;
3534  }
3535 
3536  if (s->init_data->smlists_tail[DETECT_SM_LIST_PMATCH] == NULL) {
3537  result = 0;
3538  goto end;
3539  }
3540 
3542  if (sm->type != DETECT_CONTENT) {
3543  result = 0;
3544  goto end;
3545  }
3546  cd = (DetectContentData *)sm->ctx;
3547  if (cd->flags & DETECT_CONTENT_RAWBYTES ||
3548  strncmp((char *)cd->content, "one", cd->content_len) != 0 ||
3549  cd->flags & DETECT_CONTENT_NOCASE ||
3550  cd->flags & DETECT_CONTENT_WITHIN ||
3554  cd->flags & DETECT_CONTENT_NEGATED ) {
3555  printf("one failed\n");
3556  result = 0;
3557  goto end;
3558  }
3559 
3560  sm = sm->next;
3561  if (sm->type != DETECT_BYTE_EXTRACT) {
3562  result = 0;
3563  goto end;
3564  }
3565  bed1 = (SCDetectByteExtractData *)sm->ctx;
3566  if (bed1->nbytes != 4 || bed1->offset != 0 || strcmp(bed1->name, "two") != 0 ||
3567  bed1->flags != (DETECT_BYTE_EXTRACT_FLAG_STRING | DETECT_BYTE_EXTRACT_FLAG_BASE) ||
3568  bed1->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed1->align_value != 0 ||
3569  bed1->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
3570  goto end;
3571  }
3572  if (bed1->local_id != 0) {
3573  result = 0;
3574  goto end;
3575  }
3576 
3577  sm = sm->next;
3578  if (sm->type != DETECT_BYTE_EXTRACT) {
3579  result = 0;
3580  goto end;
3581  }
3582 
3583  sm = sm->next;
3584  if (sm->type != DETECT_BYTEJUMP) {
3585  result = 0;
3586  goto end;
3587  }
3588  bjd = (DetectBytejumpData *)sm->ctx;
3589  if (bjd->flags != DETECT_BYTEJUMP_OFFSET_VAR || bjd->offset != 0) {
3590  printf("three failed\n");
3591  result = 0;
3592  goto end;
3593  }
3594 
3595  sm = sm->next;
3596  if (sm->type != DETECT_BYTEJUMP) {
3597  result = 0;
3598  goto end;
3599  }
3600  bjd = (DetectBytejumpData *)sm->ctx;
3601  if (bjd->flags != DETECT_BYTEJUMP_OFFSET_VAR || bjd->offset != 1) {
3602  printf("four failed\n");
3603  result = 0;
3604  goto end;
3605  }
3606 
3607  sm = sm->next;
3608  if (sm->type != DETECT_ISDATAAT) {
3609  result = 0;
3610  goto end;
3611  }
3612  isdd = (DetectIsdataatData *)sm->ctx;
3613  if (isdd->flags != ISDATAAT_OFFSET_VAR ||
3614  isdd->dataat != 1) {
3615  printf("isdataat failed\n");
3616  result = 0;
3617  goto end;
3618  }
3619 
3620  if (sm->next != NULL)
3621  goto end;
3622 
3623  result = 1;
3624 
3625  end:
3629 
3630  return result;
3631 }
3632 
3633 static int DetectByteExtractTest59(void)
3634 {
3637  de_ctx->flags |= DE_QUIET;
3638 
3639  Signature *s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any ("
3640  "content:\"one\"; "
3641  "byte_extract:4,0,two,string,hex; "
3642  "byte_extract:4,0,three,string,hex; "
3643  "byte_jump: 2,two; "
3644  "byte_jump: 3,three; "
3645  "isdataat: three,relative; "
3646  "sid:1;)");
3647  FAIL_IF_NULL(s);
3648 
3651  FAIL_IF(sm->type != DETECT_CONTENT);
3652 
3655  FAIL_IF(strncmp((char *)cd->content, "one", cd->content_len) != 0);
3662 
3663  sm = sm->next;
3664  FAIL_IF_NULL(sm);
3666 
3667  SCDetectByteExtractData *bed1 = (SCDetectByteExtractData *)sm->ctx;
3668  FAIL_IF(bed1->nbytes != 4);
3669  FAIL_IF(bed1->offset != 0);
3670  FAIL_IF(strcmp(bed1->name, "two") != 0);
3671  printf("a\n");
3672  FAIL_IF(bed1->flags != (DETECT_BYTE_EXTRACT_FLAG_BASE | DETECT_BYTE_EXTRACT_FLAG_STRING));
3673  printf("b\n");
3674  FAIL_IF(bed1->base != DETECT_BYTE_EXTRACT_BASE_HEX);
3675  FAIL_IF(bed1->align_value != 0);
3676  FAIL_IF(bed1->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT);
3677 
3678  FAIL_IF(bed1->local_id != 0);
3679 
3680  sm = sm->next;
3681  FAIL_IF_NULL(sm);
3683 
3684  sm = sm->next;
3685  FAIL_IF_NULL(sm);
3686  FAIL_IF(sm->type != DETECT_BYTEJUMP);
3687 
3690  FAIL_IF(bjd->offset != 0);
3691 
3692  sm = sm->next;
3693  FAIL_IF_NULL(sm);
3694  FAIL_IF(sm->type != DETECT_BYTEJUMP);
3695 
3696  bjd = (DetectBytejumpData *)sm->ctx;
3698  FAIL_IF(bjd->offset != 1);
3699 
3700  sm = sm->next;
3701  FAIL_IF_NULL(sm);
3702  FAIL_IF(sm->type != DETECT_ISDATAAT);
3703  DetectIsdataatData *isdd = (DetectIsdataatData *)sm->ctx;
3705  FAIL_IF(isdd->dataat != 1);
3706 
3707  FAIL_IF(sm->next != NULL);
3709 
3710  PASS;
3711 }
3712 
3713 static int DetectByteExtractTest60(void)
3714 {
3715  DetectEngineCtx *de_ctx = NULL;
3716  int result = 0;
3717  Signature *s = NULL;
3718  SigMatch *sm = NULL;
3719  DetectContentData *cd = NULL;
3720  SCDetectByteExtractData *bed1 = NULL;
3721  DetectIsdataatData *isdd = NULL;
3722 
3724  if (de_ctx == NULL)
3725  goto end;
3726 
3727  de_ctx->flags |= DE_QUIET;
3728  s = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
3729  "(msg:\"Testing bytejump_body\"; "
3730  "content:\"one\"; "
3731  "byte_extract:4,0,two,string,hex,relative; "
3732  "uricontent: \"three\"; "
3733  "byte_extract:4,0,four,string,hex,relative; "
3734  "isdataat: two; "
3735  "sid:1;)");
3736  if (de_ctx->sig_list == NULL) {
3737  result = 0;
3738  goto end;
3739  }
3740 
3741  if (s->init_data->smlists_tail[DETECT_SM_LIST_PMATCH] == NULL) {
3742  result = 0;
3743  goto end;
3744  }
3745 
3747  if (sm->type != DETECT_CONTENT) {
3748  result = 0;
3749  goto end;
3750  }
3751  cd = (DetectContentData *)sm->ctx;
3752  if (cd->flags & DETECT_CONTENT_RAWBYTES ||
3753  strncmp((char *)cd->content, "one", cd->content_len) != 0 ||
3754  cd->flags & DETECT_CONTENT_NOCASE ||
3755  cd->flags & DETECT_CONTENT_WITHIN ||
3759  cd->flags & DETECT_CONTENT_NEGATED ) {
3760  printf("one failed\n");
3761  result = 0;
3762  goto end;
3763  }
3764 
3765  sm = sm->next;
3766  if (sm->type != DETECT_BYTE_EXTRACT) {
3767  result = 0;
3768  goto end;
3769  }
3770  bed1 = (SCDetectByteExtractData *)sm->ctx;
3771  if (bed1->nbytes != 4 || bed1->offset != 0 || strcmp(bed1->name, "two") != 0 ||
3772  bed1->flags != (DETECT_BYTE_EXTRACT_FLAG_STRING | DETECT_BYTE_EXTRACT_FLAG_BASE |
3773  DETECT_BYTE_EXTRACT_FLAG_RELATIVE) ||
3774  bed1->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed1->align_value != 0 ||
3775  bed1->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
3776  goto end;
3777  }
3778  if (bed1->local_id != 0) {
3779  result = 0;
3780  goto end;
3781  }
3782 
3783  sm = sm->next;
3784  if (sm->type != DETECT_ISDATAAT) {
3785  result = 0;
3786  goto end;
3787  }
3788  isdd = (DetectIsdataatData *)sm->ctx;
3789  if (isdd->flags != (ISDATAAT_OFFSET_VAR) ||
3790  isdd->dataat != bed1->local_id) {
3791  printf("isdataat failed\n");
3792  result = 0;
3793  goto end;
3794  }
3795 
3796  if (sm->next != NULL)
3797  goto end;
3798 
3799  sm = DetectBufferGetFirstSigMatch(s, g_http_uri_buffer_id);
3800  if (sm == NULL) {
3801  result = 0;
3802  goto end;
3803  }
3804  if (sm->type != DETECT_CONTENT) {
3805  result = 0;
3806  goto end;
3807  }
3808  cd = (DetectContentData *)sm->ctx;
3810  strncmp((char *)cd->content, "three", cd->content_len) != 0) {
3811  printf("one failed\n");
3812  result = 0;
3813  goto end;
3814  }
3815 
3816  sm = sm->next;
3817  if (sm->type != DETECT_BYTE_EXTRACT) {
3818  result = 0;
3819  goto end;
3820  }
3821  bed1 = (SCDetectByteExtractData *)sm->ctx;
3822  if (bed1->nbytes != 4 || bed1->offset != 0 || strcmp(bed1->name, "four") != 0 ||
3823  bed1->flags != (DETECT_BYTE_EXTRACT_FLAG_STRING | DETECT_BYTE_EXTRACT_FLAG_BASE |
3824  DETECT_BYTE_EXTRACT_FLAG_RELATIVE) ||
3825  bed1->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed1->align_value != 0 ||
3826  bed1->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
3827  goto end;
3828  }
3829  if (bed1->local_id != 0) {
3830  result = 0;
3831  goto end;
3832  }
3833 
3834  if (sm->next != NULL)
3835  goto end;
3836 
3837  result = 1;
3838 
3839  end:
3843 
3844  return result;
3845 }
3846 
3847 static int DetectByteExtractTest61(void)
3848 {
3849  DetectEngineCtx *de_ctx = NULL;
3850  int result = 0;
3851  Signature *s = NULL;
3852  SigMatch *sm = NULL;
3853  DetectContentData *cd = NULL;
3854  SCDetectByteExtractData *bed1 = NULL;
3855  DetectIsdataatData *isdd = NULL;
3856 
3858  if (de_ctx == NULL)
3859  goto end;
3860 
3861  de_ctx->flags |= DE_QUIET;
3862  s = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
3863  "(msg:\"Testing bytejump_body\"; "
3864  "content:\"one\"; "
3865  "byte_extract:4,0,two,string,hex,relative; "
3866  "uricontent: \"three\"; "
3867  "byte_extract:4,0,four,string,hex,relative; "
3868  "isdataat: four, relative; "
3869  "sid:1;)");
3870  if (de_ctx->sig_list == NULL) {
3871  result = 0;
3872  goto end;
3873  }
3874 
3875  if (s->init_data->smlists_tail[DETECT_SM_LIST_PMATCH] == NULL) {
3876  result = 0;
3877  goto end;
3878  }
3879 
3881  if (sm->type != DETECT_CONTENT) {
3882  result = 0;
3883  goto end;
3884  }
3885  cd = (DetectContentData *)sm->ctx;
3886  if (cd->flags & DETECT_CONTENT_RAWBYTES ||
3887  strncmp((char *)cd->content, "one", cd->content_len) != 0 ||
3888  cd->flags & DETECT_CONTENT_NOCASE ||
3889  cd->flags & DETECT_CONTENT_WITHIN ||
3893  cd->flags & DETECT_CONTENT_NEGATED ) {
3894  printf("one failed\n");
3895  result = 0;
3896  goto end;
3897  }
3898 
3899  sm = sm->next;
3900  if (sm->type != DETECT_BYTE_EXTRACT) {
3901  result = 0;
3902  goto end;
3903  }
3904  bed1 = (SCDetectByteExtractData *)sm->ctx;
3905  if (bed1->nbytes != 4 || bed1->offset != 0 || strcmp(bed1->name, "two") != 0 ||
3906  bed1->flags != (DETECT_BYTE_EXTRACT_FLAG_STRING | DETECT_BYTE_EXTRACT_FLAG_BASE |
3907  DETECT_BYTE_EXTRACT_FLAG_RELATIVE) ||
3908  bed1->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed1->align_value != 0 ||
3909  bed1->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
3910  goto end;
3911  }
3912  if (bed1->local_id != 0) {
3913  result = 0;
3914  goto end;
3915  }
3916 
3917  if (sm->next != NULL)
3918  goto end;
3919 
3920  sm = DetectBufferGetFirstSigMatch(s, g_http_uri_buffer_id);
3921  if (sm == NULL) {
3922  result = 0;
3923  goto end;
3924  }
3925  if (sm->type != DETECT_CONTENT) {
3926  result = 0;
3927  goto end;
3928  }
3929  cd = (DetectContentData *)sm->ctx;
3931  strncmp((char *)cd->content, "three", cd->content_len) != 0) {
3932  printf("one failed\n");
3933  result = 0;
3934  goto end;
3935  }
3936 
3937  sm = sm->next;
3938  if (sm->type != DETECT_BYTE_EXTRACT) {
3939  result = 0;
3940  goto end;
3941  }
3942  bed1 = (SCDetectByteExtractData *)sm->ctx;
3943  if (bed1->nbytes != 4 || bed1->offset != 0 || strcmp(bed1->name, "four") != 0 ||
3944  bed1->flags != (DETECT_BYTE_EXTRACT_FLAG_STRING | DETECT_BYTE_EXTRACT_FLAG_BASE |
3945  DETECT_BYTE_EXTRACT_FLAG_RELATIVE) ||
3946  bed1->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed1->align_value != 0 ||
3947  bed1->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
3948  goto end;
3949  }
3950  if (bed1->local_id != 0) {
3951  result = 0;
3952  goto end;
3953  }
3954 
3955  sm = sm->next;
3956  if (sm->type != DETECT_ISDATAAT) {
3957  result = 0;
3958  goto end;
3959  }
3960  isdd = (DetectIsdataatData *)sm->ctx;
3961  if (isdd->flags != (ISDATAAT_OFFSET_VAR |
3962  ISDATAAT_RELATIVE) ||
3963  isdd->dataat != bed1->local_id) {
3964  printf("isdataat failed\n");
3965  result = 0;
3966  goto end;
3967  }
3968 
3969  if (sm->next != NULL)
3970  goto end;
3971 
3972  result = 1;
3973 
3974  end:
3978 
3979  return result;
3980 }
3981 
3982 static int DetectByteExtractTest62(void)
3983 {
3984  DetectEngineCtx *de_ctx = NULL;
3985  int result = 0;
3986  Signature *s = NULL;
3987  SigMatch *sm = NULL;
3988  SCDetectByteExtractData *bed = NULL;
3989 
3991  if (de_ctx == NULL)
3992  goto end;
3993 
3994  de_ctx->flags |= DE_QUIET;
3995  s = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
3996  "(file_data; byte_extract:4,2,two,relative,string,hex; "
3997  "sid:1;)");
3998  if (de_ctx->sig_list == NULL) {
3999  goto end;
4000  }
4001 
4002  sm = DetectBufferGetFirstSigMatch(s, g_file_data_buffer_id);
4003  if (sm == NULL) {
4004  goto end;
4005  }
4006  if (sm->type != DETECT_BYTE_EXTRACT) {
4007  goto end;
4008  }
4009  bed = (SCDetectByteExtractData *)sm->ctx;
4010  if (bed->nbytes != 4 || bed->offset != 2 || strncmp(bed->name, "two", 3) != 0 ||
4011  bed->flags != (DETECT_BYTE_EXTRACT_FLAG_STRING | DETECT_BYTE_EXTRACT_FLAG_BASE |
4012  DETECT_BYTE_EXTRACT_FLAG_RELATIVE) ||
4013  bed->base != DETECT_BYTE_EXTRACT_BASE_HEX || bed->align_value != 0 ||
4014  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
4015  goto end;
4016  }
4017 
4018  result = 1;
4019 
4020  end:
4024 
4025  return result;
4026 }
4027 
4028 static int DetectByteExtractTest63(void)
4029 {
4030  int result = 0;
4031 
4032  SCDetectByteExtractData *bed = DetectByteExtractParse(NULL, "4, -2, one");
4033  if (bed == NULL)
4034  goto end;
4035 
4036  if (bed->nbytes != 4 || bed->offset != -2 || strcmp(bed->name, "one") != 0 || bed->flags != 0 ||
4037  bed->endian != BigEndian || bed->align_value != 0 ||
4038  bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
4039  goto end;
4040  }
4041 
4042  result = 1;
4043  end:
4044  if (bed != NULL)
4045  DetectByteExtractFree(NULL, bed);
4046  return result;
4047 }
4048 
4049 static int DetectByteExtractTestParseNoBase(void)
4050 {
4051  int result = 0;
4052 
4053  SCDetectByteExtractData *bed = DetectByteExtractParse(NULL, "4, 2, one, string");
4054  if (bed == NULL)
4055  goto end;
4056 
4057  if (bed->nbytes != 4) {
4058  goto end;
4059  }
4060  if (bed->offset != 2) {
4061  goto end;
4062  }
4063  if (strcmp(bed->name, "one") != 0) {
4064  goto end;
4065  }
4066  if (bed->flags != DETECT_BYTE_EXTRACT_FLAG_STRING) {
4067  goto end;
4068  }
4069  if (bed->base != DETECT_BYTE_EXTRACT_BASE_DEC) {
4070  goto end;
4071  }
4072  if (bed->align_value != 0) {
4073  goto end;
4074  }
4075  if (bed->multiplier_value != DETECT_BYTE_EXTRACT_MULTIPLIER_DEFAULT) {
4076  goto end;
4077  }
4078 
4079  result = 1;
4080  end:
4081  if (bed != NULL)
4082  DetectByteExtractFree(NULL, bed);
4083  return result;
4084 }
4085 
4086 static void DetectByteExtractRegisterTests(void)
4087 {
4088  g_file_data_buffer_id = DetectBufferTypeGetByName("file_data");
4089  g_http_uri_buffer_id = DetectBufferTypeGetByName("http_uri");
4090 
4091  UtRegisterTest("DetectByteExtractTest01", DetectByteExtractTest01);
4092  UtRegisterTest("DetectByteExtractTest02", DetectByteExtractTest02);
4093  UtRegisterTest("DetectByteExtractTest03", DetectByteExtractTest03);
4094  UtRegisterTest("DetectByteExtractTest04", DetectByteExtractTest04);
4095  UtRegisterTest("DetectByteExtractTest05", DetectByteExtractTest05);
4096  UtRegisterTest("DetectByteExtractTest06", DetectByteExtractTest06);
4097  UtRegisterTest("DetectByteExtractTest07", DetectByteExtractTest07);
4098  UtRegisterTest("DetectByteExtractTest08", DetectByteExtractTest08);
4099  UtRegisterTest("DetectByteExtractTest09", DetectByteExtractTest09);
4100  UtRegisterTest("DetectByteExtractTest10", DetectByteExtractTest10);
4101  UtRegisterTest("DetectByteExtractTest11", DetectByteExtractTest11);
4102  UtRegisterTest("DetectByteExtractTest12", DetectByteExtractTest12);
4103  UtRegisterTest("DetectByteExtractTest13", DetectByteExtractTest13);
4104  UtRegisterTest("DetectByteExtractTest14", DetectByteExtractTest14);
4105  UtRegisterTest("DetectByteExtractTest15", DetectByteExtractTest15);
4106  UtRegisterTest("DetectByteExtractTest16", DetectByteExtractTest16);
4107  UtRegisterTest("DetectByteExtractTest17", DetectByteExtractTest17);
4108  UtRegisterTest("DetectByteExtractTest18", DetectByteExtractTest18);
4109  UtRegisterTest("DetectByteExtractTest19", DetectByteExtractTest19);
4110  UtRegisterTest("DetectByteExtractTest20", DetectByteExtractTest20);
4111  UtRegisterTest("DetectByteExtractTest21", DetectByteExtractTest21);
4112  UtRegisterTest("DetectByteExtractTest22", DetectByteExtractTest22);
4113  UtRegisterTest("DetectByteExtractTest23", DetectByteExtractTest23);
4114  UtRegisterTest("DetectByteExtractTest24", DetectByteExtractTest24);
4115  UtRegisterTest("DetectByteExtractTest25", DetectByteExtractTest25);
4116  UtRegisterTest("DetectByteExtractTest26", DetectByteExtractTest26);
4117  UtRegisterTest("DetectByteExtractTest27", DetectByteExtractTest27);
4118  UtRegisterTest("DetectByteExtractTest28", DetectByteExtractTest28);
4119  UtRegisterTest("DetectByteExtractTest29", DetectByteExtractTest29);
4120  UtRegisterTest("DetectByteExtractTest30", DetectByteExtractTest30);
4121  UtRegisterTest("DetectByteExtractTest31", DetectByteExtractTest31);
4122  UtRegisterTest("DetectByteExtractTest32", DetectByteExtractTest32);
4123  UtRegisterTest("DetectByteExtractTest33", DetectByteExtractTest33);
4124  UtRegisterTest("DetectByteExtractTest34", DetectByteExtractTest34);
4125  UtRegisterTest("DetectByteExtractTest35", DetectByteExtractTest35);
4126  UtRegisterTest("DetectByteExtractTest36", DetectByteExtractTest36);
4127  UtRegisterTest("DetectByteExtractTest37", DetectByteExtractTest37);
4128  UtRegisterTest("DetectByteExtractTest38", DetectByteExtractTest38);
4129  UtRegisterTest("DetectByteExtractTest39", DetectByteExtractTest39);
4130  UtRegisterTest("DetectByteExtractTest40", DetectByteExtractTest40);
4131  UtRegisterTest("DetectByteExtractTest41", DetectByteExtractTest41);
4132  UtRegisterTest("DetectByteExtractTest42", DetectByteExtractTest42);
4133 
4134  UtRegisterTest("DetectByteExtractTest43", DetectByteExtractTest43);
4135  UtRegisterTest("DetectByteExtractTest44", DetectByteExtractTest44);
4136 
4137  UtRegisterTest("DetectByteExtractTest45", DetectByteExtractTest45);
4138  UtRegisterTest("DetectByteExtractTest46", DetectByteExtractTest46);
4139 
4140  UtRegisterTest("DetectByteExtractTest47", DetectByteExtractTest47);
4141  UtRegisterTest("DetectByteExtractTest48", DetectByteExtractTest48);
4142 
4143  UtRegisterTest("DetectByteExtractTest49", DetectByteExtractTest49);
4144  UtRegisterTest("DetectByteExtractTest50", DetectByteExtractTest50);
4145 
4146  UtRegisterTest("DetectByteExtractTest51", DetectByteExtractTest51);
4147  UtRegisterTest("DetectByteExtractTest52", DetectByteExtractTest52);
4148 
4149  UtRegisterTest("DetectByteExtractTest53", DetectByteExtractTest53);
4150  UtRegisterTest("DetectByteExtractTest54", DetectByteExtractTest54);
4151 
4152  UtRegisterTest("DetectByteExtractTest55", DetectByteExtractTest55);
4153  UtRegisterTest("DetectByteExtractTest56", DetectByteExtractTest56);
4154  UtRegisterTest("DetectByteExtractTest57", DetectByteExtractTest57);
4155 
4156  UtRegisterTest("DetectByteExtractTest58", DetectByteExtractTest58);
4157  UtRegisterTest("DetectByteExtractTest59", DetectByteExtractTest59);
4158  UtRegisterTest("DetectByteExtractTest60", DetectByteExtractTest60);
4159  UtRegisterTest("DetectByteExtractTest61", DetectByteExtractTest61);
4160  UtRegisterTest("DetectByteExtractTest62", DetectByteExtractTest62);
4161  UtRegisterTest("DetectByteExtractTest63", DetectByteExtractTest63);
4162 
4163  UtRegisterTest("DetectByteExtractTestParseNoBase",
4164  DetectByteExtractTestParseNoBase);
4165 }
4166 #endif /* UNITTESTS */
DETECT_CONTENT_NOCASE
#define DETECT_CONTENT_NOCASE
Definition: detect-content.h:29
DetectContentData_::offset
uint16_t offset
Definition: detect-content.h:107
util-byte.h
DetectBytetestData_::flags
uint16_t flags
Definition: detect-bytetest.h:58
DETECT_BYTETEST_VALUE_VAR
#define DETECT_BYTETEST_VALUE_VAR
Definition: detect-bytetest.h:49
SigTableElmt_::url
const char * url
Definition: detect.h:1545
DETECT_CONTENT_RELATIVE_NEXT
#define DETECT_CONTENT_RELATIVE_NEXT
Definition: detect-content.h:66
SignatureInitDataBuffer_::head
SigMatch * head
Definition: detect.h:543
detect-content.h
len
uint8_t len
Definition: app-layer-dnp3.h:2
DetectEngineThreadCtx_::buffer_offset
uint32_t buffer_offset
Definition: detect.h:1340
detect-engine.h
DETECT_SM_LIST_PMATCH
@ DETECT_SM_LIST_PMATCH
Definition: detect.h:120
FAIL_IF_NULL
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
Definition: util-unittest.h:89
SignatureInitData_::smlists
struct SigMatch_ * smlists[DETECT_SM_LIST_MAX]
Definition: detect.h:666
SigTableElmt_::desc
const char * desc
Definition: detect.h:1544
ByteExtractUint64
int ByteExtractUint64(uint64_t *res, int e, uint16_t len, const uint8_t *bytes)
Definition: util-byte.c:74
sigmatch_table
SigTableElmt * sigmatch_table
Definition: detect-parse.c:78
NO_STRING_MAX_BYTES_TO_EXTRACT
#define NO_STRING_MAX_BYTES_TO_EXTRACT
Definition: detect-byte-extract.c:57
ALPROTO_DCERPC
@ ALPROTO_DCERPC
Definition: app-layer-protos.h:44
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1529
DETECT_CONTENT_DISTANCE_VAR
#define DETECT_CONTENT_DISTANCE_VAR
Definition: detect-content.h:47
DetectBufferGetFirstSigMatch
SigMatch * DetectBufferGetFirstSigMatch(const Signature *s, const uint32_t buf_id)
Definition: detect-engine-buffer.c:157
SigTableElmt_::name
const char * name
Definition: detect.h:1542
SignatureInitData_::smlists_tail
struct SigMatch_ * smlists_tail[DETECT_SM_LIST_MAX]
Definition: detect.h:668
DETECT_BYTEJUMP
@ DETECT_BYTEJUMP
Definition: detect-engine-register.h:92
ISDATAAT_OFFSET_VAR
#define ISDATAAT_OFFSET_VAR
Definition: detect-isdataat.h:30
DetectContentData_::within
int32_t within
Definition: detect-content.h:109
UtRegisterTest
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Definition: util-unittest.c:101
DetectIsdataatData_::flags
uint8_t flags
Definition: detect-isdataat.h:34
DETECT_CONTENT
@ DETECT_CONTENT
Definition: detect-engine-register.h:78
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:282
detect-isdataat.h
DETECT_BYTE_EXTRACT_BASE_DEC
#define DETECT_BYTE_EXTRACT_BASE_DEC
Definition: detect-byte-extract.c:48
SigMatchData_::ctx
SigMatchCtx * ctx
Definition: detect.h:372
DETECT_CONTENT_NO_DOUBLE_INSPECTION_REQUIRED
#define DETECT_CONTENT_NO_DOUBLE_INSPECTION_REQUIRED
Definition: detect-content.h:55
SCDetectGetLastSMFromLists
SigMatch * SCDetectGetLastSMFromLists(const Signature *s,...)
Returns the sm with the largest index (added latest) from the lists passed to us.
Definition: detect-parse.c:600
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:995
DETECT_CONTENT_RAWBYTES
#define DETECT_CONTENT_RAWBYTES
Definition: detect-content.h:38
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2912
DETECT_CONTENT_DEPTH_VAR
#define DETECT_CONTENT_DEPTH_VAR
Definition: detect-content.h:46
rust.h
DE_QUIET
#define DE_QUIET
Definition: detect.h:334
DETECT_BYTE_EXTRACT_BASE_HEX
#define DETECT_BYTE_EXTRACT_BASE_HEX
Definition: detect-byte-extract.c:47
DetectIsdataatData_
Definition: detect-isdataat.h:32
DetectContentData_
Definition: detect-content.h:93
DetectPcreData_::flags
uint16_t flags
Definition: detect-pcre.h:52
SigCleanSignatures
void SigCleanSignatures(DetectEngineCtx *de_ctx)
Definition: detect-engine-build.c:56
SCDetectSignatureSetAppProto
int SCDetectSignatureSetAppProto(Signature *s, AppProto alproto)
Definition: detect-parse.c:2613
ByteExtractStringUint64
int ByteExtractStringUint64(uint64_t *res, int base, size_t len, const char *str)
Definition: util-byte.c:189
DetectBytetestData_
Definition: detect-bytetest.h:53
DetectEngineAppendSig
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
Definition: detect-parse.c:3965
SigMatchData_
Data needed for Match()
Definition: detect.h:369
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1524
detect-pcre.h
DetectBytejumpData_
Definition: detect-bytejump.h:47
DetectBytejumpData_::offset
int32_t offset
Definition: detect-bytejump.h:51
util-unittest-helper.h
DetectBufferTypeGetByName
int DetectBufferTypeGetByName(const char *name)
Definition: detect-engine.c:1452
DetectGetLastSMByListId
SigMatch * DetectGetLastSMByListId(const Signature *s, int list_id,...)
Returns the sm with the largest index (added last) from the list passed to us as an id.
Definition: detect-parse.c:694
DetectByteExtractDoMatch
int DetectByteExtractDoMatch(DetectEngineThreadCtx *det_ctx, const SigMatchData *smd, const Signature *s, const uint8_t *payload, uint32_t payload_len, uint64_t *value, uint8_t endian)
Definition: detect-byte-extract.c:81
STRING_MAX_BYTES_TO_EXTRACT_FOR_OCT
#define STRING_MAX_BYTES_TO_EXTRACT_FOR_OCT
Definition: detect-byte-extract.c:53
decode.h
FAIL_IF_NOT_NULL
#define FAIL_IF_NOT_NULL(expr)
Fail a test if expression evaluates to non-NULL.
Definition: util-unittest.h:96
util-debug.h
PASS
#define PASS
Pass the test.
Definition: util-unittest.h:105
DETECT_CONTENT_DISTANCE
#define DETECT_CONTENT_DISTANCE
Definition: detect-content.h:30
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:22
DetectEngineThreadCtx_
Definition: detect.h:1316
DETECT_CONTENT_DEPTH
#define DETECT_CONTENT_DEPTH
Definition: detect-content.h:33
SignatureInitData_::list
int list
Definition: detect.h:645
DetectByteExtractRetrieveSMVar
SigMatch * DetectByteExtractRetrieveSMVar(const char *arg, int sm_list, const Signature *s)
Lookup the SigMatch for a named byte_extract variable.
Definition: detect-byte-extract.c:371
SCSigMatchAppendSMToList
SigMatch * SCSigMatchAppendSMToList(DetectEngineCtx *de_ctx, Signature *s, uint16_t type, SigMatchCtx *ctx, const int list)
Append a SigMatch to the list type.
Definition: detect-parse.c:424
detect.h
DETECT_BYTE_EXTRACT_BASE_OCT
#define DETECT_BYTE_EXTRACT_BASE_OCT
Definition: detect-byte-extract.c:49
SigMatch_::next
struct SigMatch_ * next
Definition: detect.h:364
DETECT_CONTENT_NEGATED
#define DETECT_CONTENT_NEGATED
Definition: detect-content.h:40
SigInit
Signature * SigInit(DetectEngineCtx *de_ctx, const char *sigstr)
Parses a signature and adds it to the Detection Engine Context.
Definition: detect-parse.c:3618
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:363
BYTE_BIG_ENDIAN
#define BYTE_BIG_ENDIAN
Definition: util-byte.h:29
SigGroupCleanup
int SigGroupCleanup(DetectEngineCtx *de_ctx)
Definition: detect-engine-build.c:2371
DETECT_BYTETEST_OFFSET_VAR
#define DETECT_BYTETEST_OFFSET_VAR
Definition: detect-bytetest.h:50
DetectContentData_::depth
uint16_t depth
Definition: detect-content.h:106
detect-engine-build.h
ISDATAAT_RELATIVE
#define ISDATAAT_RELATIVE
Definition: detect-isdataat.h:27
detect-bytejump.h
DetectContentData_::flags
uint32_t flags
Definition: detect-content.h:104
Signature_::init_data
SignatureInitData * init_data
Definition: detect.h:775
DETECT_CONTENT_DISTANCE_NEXT
#define DETECT_CONTENT_DISTANCE_NEXT
Definition: detect-content.h:58
SigTableElmt_::Match
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
Definition: detect.h:1504
DetectEngineCtx_::byte_extract_max_local_id
int32_t byte_extract_max_local_id
Definition: detect.h:1077
DETECT_PCRE
@ DETECT_PCRE
Definition: detect-engine-register.h:80
SigMatchCtx_
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:355
DETECT_CONTENT_WITHIN_VAR
#define DETECT_CONTENT_WITHIN_VAR
Definition: detect-content.h:48
DETECT_SM_LIST_NOTSET
#define DETECT_SM_LIST_NOTSET
Definition: detect.h:145
DETECT_BYTETEST
@ DETECT_BYTETEST
Definition: detect-engine-register.h:91
BYTE_LITTLE_ENDIAN
#define BYTE_LITTLE_ENDIAN
Definition: util-byte.h:30
FAIL_IF
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
Definition: util-unittest.h:71
suricata-common.h
SigMatch_::type
uint16_t type
Definition: detect.h:361
STRING_MAX_BYTES_TO_EXTRACT_FOR_DEC
#define STRING_MAX_BYTES_TO_EXTRACT_FOR_DEC
Definition: detect-byte-extract.c:54
detect-byte-extract.h
DetectContentData_::distance
int32_t distance
Definition: detect-content.h:108
DETECT_CONTENT_WITHIN_NEXT
#define DETECT_CONTENT_WITHIN_NEXT
Definition: detect-content.h:57
DetectContentData_::content
uint8_t * content
Definition: detect-content.h:94
detect-engine-buffer.h
DetectEngineCtx_::sig_list
Signature * sig_list
Definition: detect.h:1005
SignatureInitData_::buffers
SignatureInitDataBuffer * buffers
Definition: detect.h:671
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:274
SigMatchListSMBelongsTo
int SigMatchListSMBelongsTo(const Signature *s, const SigMatch *key_sm)
Definition: detect-parse.c:799
DETECT_CONTENT_OFFSET
#define DETECT_CONTENT_OFFSET
Definition: detect-content.h:32
DETECT_BYTE_EXTRACT
@ DETECT_BYTE_EXTRACT
Definition: detect-engine-register.h:94
DETECT_CONTENT_MPM
#define DETECT_CONTENT_MPM
Definition: detect-content.h:61
Signature_
Signature container.
Definition: detect.h:692
SigMatch_
a single match condition for a signature
Definition: detect.h:360
payload_len
uint16_t payload_len
Definition: stream-tcp-private.h:1
DETECT_ISDATAAT
@ DETECT_ISDATAAT
Definition: detect-engine-register.h:102
DETECT_SM_LIST_MAX
@ DETECT_SM_LIST_MAX
Definition: detect.h:136
DetectBytetestData_::offset
int32_t offset
Definition: detect-bytetest.h:60
DetectIsdataatData_::dataat
uint16_t dataat
Definition: detect-isdataat.h:33
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2873
DetectByteExtractRegister
void DetectByteExtractRegister(void)
Registers the keyword handlers for the "byte_extract" keyword.
Definition: detect-byte-extract.c:68
DETECT_PCRE_RELATIVE_NEXT
#define DETECT_PCRE_RELATIVE_NEXT
Definition: detect-pcre.h:34
app-layer-protos.h
DetectPcreData_
Definition: detect-pcre.h:48
DetectContentData_::content_len
uint16_t content_len
Definition: detect-content.h:95
DETECT_BYTEMATH
@ DETECT_BYTEMATH
Definition: detect-engine-register.h:93
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:997
DETECT_CONTENT_FAST_PATTERN
#define DETECT_CONTENT_FAST_PATTERN
Definition: detect-content.h:34
SignatureInitData_::buffer_index
uint32_t buffer_index
Definition: detect.h:672
STRING_MAX_BYTES_TO_EXTRACT_FOR_HEX
#define STRING_MAX_BYTES_TO_EXTRACT_FOR_HEX
Definition: detect-byte-extract.c:55
DetectBytetestData_::value
uint64_t value
Definition: detect-bytetest.h:62
DETECT_CONTENT_WITHIN
#define DETECT_CONTENT_WITHIN
Definition: detect-content.h:31
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1531
DETECT_BYTEJUMP_OFFSET_VAR
#define DETECT_BYTEJUMP_OFFSET_VAR
Definition: detect-bytejump.h:44
DetectBytejumpData_::flags
uint16_t flags
Definition: detect-bytejump.h:50
DETECT_CONTENT_OFFSET_VAR
#define DETECT_CONTENT_OFFSET_VAR
Definition: detect-content.h:45
detect-bytetest.h