Commit e14f096
authored
Add a "warnings" member to Rules. (#208)
When compiling rules that have warnings currently the only way to know they have
warnings is to specify error_on_warning=True to yara.compile(). This will throw
an exception that you can then check the warnings member of, like this:
```
r = 'rule a { strings: $a = "a" condition: $a } rule b { strings: $b = "b" condition: $b }'
try:
rules = yara.compile(source=r, error_on_warning=True)
except yara.WarningError as e:
print(e.warnings)
```
This stops the compilation process, so if you're trying to just know if there
are warnings but still run the rules there is no good way to do it without using
the exception mechanism and then compiling the rules a second time (with
error_on_warning not set).
This patch adds a warnings member to the compiled Rules object, which is always
set to a list of warning strings. If you want to error on warning you can still
use error_on_warning=True in yara.compile() and get the normal behavior, but if
you just want to compile and know if there are warnings you can now use this new
member without having to compile a second time.
Suggested by: Tom Lancaster
Fixes: #2071 parent 0a8659d commit e14f096
2 files changed
+41
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1132 | 1132 | | |
1133 | 1133 | | |
1134 | 1134 | | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
1135 | 1160 | | |
1136 | 1161 | | |
1137 | 1162 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
316 | 316 | | |
317 | 317 | | |
318 | 318 | | |
| 319 | + | |
319 | 320 | | |
320 | 321 | | |
321 | 322 | | |
| |||
347 | 348 | | |
348 | 349 | | |
349 | 350 | | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
350 | 362 | | |
351 | 363 | | |
352 | 364 | | |
| |||
399 | 411 | | |
400 | 412 | | |
401 | 413 | | |
402 | | - | |
| 414 | + | |
403 | 415 | | |
404 | 416 | | |
405 | 417 | | |
| |||
1517 | 1529 | | |
1518 | 1530 | | |
1519 | 1531 | | |
| 1532 | + | |
1520 | 1533 | | |
1521 | 1534 | | |
1522 | 1535 | | |
| |||
1528 | 1541 | | |
1529 | 1542 | | |
1530 | 1543 | | |
| 1544 | + | |
1531 | 1545 | | |
1532 | 1546 | | |
1533 | 1547 | | |
| |||
2435 | 2449 | | |
2436 | 2450 | | |
2437 | 2451 | | |
2438 | | - | |
2439 | | - | |
2440 | 2452 | | |
2441 | 2453 | | |
2442 | 2454 | | |
| |||
2451 | 2463 | | |
2452 | 2464 | | |
2453 | 2465 | | |
| 2466 | + | |
2454 | 2467 | | |
2455 | 2468 | | |
2456 | 2469 | | |
| |||
0 commit comments