mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-10-01 12:07:42 +03:00
Logical Combination of patterns.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2017, Intel Corporation
|
||||
* Copyright (c) 2015-2018, Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -45,6 +45,7 @@
|
||||
#include "parser/buildstate.h"
|
||||
#include "parser/dump.h"
|
||||
#include "parser/Component.h"
|
||||
#include "parser/logical_combination.h"
|
||||
#include "parser/parse_error.h"
|
||||
#include "parser/Parser.h" // for flags
|
||||
#include "parser/position.h"
|
||||
@@ -111,7 +112,13 @@ ParsedExpression::ParsedExpression(unsigned index_in, const char *expression,
|
||||
const hs_expr_ext *ext)
|
||||
: expr(index_in, flags & HS_FLAG_ALLOWEMPTY, flags & HS_FLAG_SINGLEMATCH,
|
||||
false, flags & HS_FLAG_PREFILTER, SOM_NONE, report, 0, MAX_OFFSET,
|
||||
0, 0, 0) {
|
||||
0, 0, 0, flags & HS_FLAG_QUIET) {
|
||||
// We disallow SOM + Quiet.
|
||||
if ((flags & HS_FLAG_QUIET) && (flags & HS_FLAG_SOM_LEFTMOST)) {
|
||||
throw CompileError("HS_FLAG_QUIET is not supported in "
|
||||
"combination with HS_FLAG_SOM_LEFTMOST.");
|
||||
}
|
||||
flags &= ~HS_FLAG_QUIET;
|
||||
ParseMode mode(flags);
|
||||
|
||||
component = parse(expression, mode);
|
||||
@@ -234,6 +241,45 @@ void addExpression(NG &ng, unsigned index, const char *expression,
|
||||
DEBUG_PRINTF("index=%u, id=%u, flags=%u, expr='%s'\n", index, id, flags,
|
||||
expression);
|
||||
|
||||
if (flags & HS_FLAG_COMBINATION) {
|
||||
if (flags & ~(HS_FLAG_COMBINATION | HS_FLAG_QUIET |
|
||||
HS_FLAG_SINGLEMATCH)) {
|
||||
throw CompileError("only HS_FLAG_QUIET and HS_FLAG_SINGLEMATCH "
|
||||
"are supported in combination "
|
||||
"with HS_FLAG_COMBINATION.");
|
||||
}
|
||||
if (flags & HS_FLAG_QUIET) {
|
||||
DEBUG_PRINTF("skip QUIET logical combination expression %u\n", id);
|
||||
} else {
|
||||
u32 ekey = INVALID_EKEY;
|
||||
u64a min_offset = 0;
|
||||
u64a max_offset = MAX_OFFSET;
|
||||
if (flags & HS_FLAG_SINGLEMATCH) {
|
||||
ekey = ng.rm.getExhaustibleKey(id);
|
||||
}
|
||||
if (ext) {
|
||||
validateExt(*ext);
|
||||
if (ext->flags & ~(HS_EXT_FLAG_MIN_OFFSET |
|
||||
HS_EXT_FLAG_MAX_OFFSET)) {
|
||||
throw CompileError("only HS_EXT_FLAG_MIN_OFFSET and "
|
||||
"HS_EXT_FLAG_MAX_OFFSET extra flags "
|
||||
"are supported in combination "
|
||||
"with HS_FLAG_COMBINATION.");
|
||||
}
|
||||
if (ext->flags & HS_EXT_FLAG_MIN_OFFSET) {
|
||||
min_offset = ext->min_offset;
|
||||
}
|
||||
if (ext->flags & HS_EXT_FLAG_MAX_OFFSET) {
|
||||
max_offset = ext->max_offset;
|
||||
}
|
||||
}
|
||||
ng.rm.pl.parseLogicalCombination(id, expression, ekey, min_offset,
|
||||
max_offset);
|
||||
DEBUG_PRINTF("parsed logical combination expression %u\n", id);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Ensure that our pattern isn't too long (in characters).
|
||||
if (strlen(expression) > cc.grey.limitPatternLength) {
|
||||
throw CompileError("Pattern length exceeds limit.");
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Intel Corporation
|
||||
* Copyright (c) 2017-2018, Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -46,12 +46,12 @@ public:
|
||||
bool highlander_in, bool utf8_in, bool prefilter_in,
|
||||
som_type som_in, ReportID report_in, u64a min_offset_in,
|
||||
u64a max_offset_in, u64a min_length_in, u32 edit_distance_in,
|
||||
u32 hamm_distance_in)
|
||||
u32 hamm_distance_in, bool quiet_in)
|
||||
: index(index_in), report(report_in), allow_vacuous(allow_vacuous_in),
|
||||
highlander(highlander_in), utf8(utf8_in), prefilter(prefilter_in),
|
||||
som(som_in), min_offset(min_offset_in), max_offset(max_offset_in),
|
||||
min_length(min_length_in), edit_distance(edit_distance_in),
|
||||
hamm_distance(hamm_distance_in) {}
|
||||
hamm_distance(hamm_distance_in), quiet(quiet_in) {}
|
||||
|
||||
/**
|
||||
* \brief Index of the expression represented by this graph.
|
||||
@@ -98,6 +98,9 @@ public:
|
||||
*/
|
||||
u32 edit_distance;
|
||||
u32 hamm_distance;
|
||||
|
||||
/** \brief Quiet on match. */
|
||||
bool quiet;
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user