Commit 4379581
authored
Add console_callback to match call. (#194)
* Add console_callback to match call.
This provides the user with an interface to handle console.log() messages. If
not provided the log message is printed to stdout (limited to 1000 bytes based
upon https://docs.python.org/3/c-api/sys.html?highlight=stdout#c.PySys_WriteStdout).
Tested with the following (along with the updated tests):
wxs@wxs-mbp yara-python % cat test.py
import yara
r = """
import "console"
rule a { condition: console.log("Hello from Python!") }
"""
def console(message):
print(f"Callback: {message}")
rules = yara.compile(source=r)
rules.match("/bin/ls", console_callback=console)
rules.match("/bin/ls")
wxs@wxs-mbp yara-python % PYTHONPATH=build/lib.macosx-10.14-arm64-3.8 python3 test.py
Callback: Hello from Python!
Hello from Python!
wxs@wxs-mbp yara-python %
* Add comment.1 parent 08372e1 commit 4379581
2 files changed
+87
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
940 | 940 | | |
941 | 941 | | |
942 | 942 | | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
943 | 956 | | |
944 | 957 | | |
945 | 958 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
418 | 418 | | |
419 | 419 | | |
420 | 420 | | |
| 421 | + | |
421 | 422 | | |
422 | 423 | | |
423 | 424 | | |
| |||
691 | 692 | | |
692 | 693 | | |
693 | 694 | | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
694 | 747 | | |
695 | 748 | | |
696 | 749 | | |
| |||
870 | 923 | | |
871 | 924 | | |
872 | 925 | | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
873 | 930 | | |
874 | 931 | | |
875 | 932 | | |
| |||
1551 | 1608 | | |
1552 | 1609 | | |
1553 | 1610 | | |
1554 | | - | |
| 1611 | + | |
| 1612 | + | |
1555 | 1613 | | |
1556 | 1614 | | |
1557 | 1615 | | |
| |||
1574 | 1632 | | |
1575 | 1633 | | |
1576 | 1634 | | |
| 1635 | + | |
1577 | 1636 | | |
1578 | 1637 | | |
1579 | 1638 | | |
1580 | 1639 | | |
1581 | 1640 | | |
1582 | | - | |
| 1641 | + | |
1583 | 1642 | | |
1584 | 1643 | | |
1585 | 1644 | | |
| |||
1591 | 1650 | | |
1592 | 1651 | | |
1593 | 1652 | | |
1594 | | - | |
| 1653 | + | |
| 1654 | + | |
1595 | 1655 | | |
1596 | 1656 | | |
1597 | 1657 | | |
| |||
1633 | 1693 | | |
1634 | 1694 | | |
1635 | 1695 | | |
| 1696 | + | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
| 1706 | + | |
1636 | 1707 | | |
1637 | 1708 | | |
1638 | 1709 | | |
| |||
0 commit comments