File tree Expand file tree Collapse file tree 3 files changed +29
-0
lines changed
Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -110,3 +110,11 @@ file and create signatures based on those results.
110110 .. versionadded :: 3.8.0
111111
112112 Returns the minimum of two unsigned integer values.
113+
114+ .. c :function :: tonumber(bool )
115+
116+ .. versionadded :: 4.0.5
117+
118+ Returns 0 or 1, it's useful when writing a score based rule.
119+
120+ *Example: math.tonumber(SubRule1) \* 60 + math.tonumber(SubRule2) \* 20 + math.tonumber(SubRule3) \* 70 > 80 *
Original file line number Diff line number Diff line change @@ -605,6 +605,10 @@ define_function(max)
605605 return_integer (i > j ? i : j );
606606}
607607
608+ define_function (tonumber )
609+ {
610+ return_integer (integer_argument (1 ) ? 1 : 0 );
611+ }
608612
609613begin_declarations
610614 declare_float ("MEAN_BYTES" );
@@ -621,6 +625,7 @@ begin_declarations
621625 declare_function ("entropy" , "s" , "f" , string_entropy );
622626 declare_function ("min" , "ii" , "i" , min );
623627 declare_function ("max" , "ii" , "i" , max );
628+ declare_function ("tonumber" , "b" , "i" , tonumber );
624629end_declarations
625630
626631
Original file line number Diff line number Diff line change @@ -28,6 +28,22 @@ int main(int argc, char** argv)
2828 }" ,
2929 "A" );
3030
31+ assert_true_rule_blob (
32+ "import \"math\" \
33+ rule test { \
34+ condition: \
35+ math.tonumber(1 == 1) \
36+ }" ,
37+ "A" );
38+
39+ assert_false_rule_blob (
40+ "import \"math\" \
41+ rule test { \
42+ condition: \
43+ math.tonumber(1 > 2) \
44+ }" ,
45+ "A" );
46+
3147 yr_finalize ();
3248
3349 YR_DEBUG_FPRINTF (
You can’t perform that action at this time.
0 commit comments