/usr/share/doc/yara-doc/html/capi.html is in yara-doc 3.7.1-1ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 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 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The C API — yara 3.7.1 documentation</title>
<link rel="stylesheet" href="_static/classic.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '3.7.1',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="prev" title="Using YARA from Python" href="yarapython.html" />
</head>
<body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="yarapython.html" title="Using YARA from Python"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">yara 3.7.1 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="the-c-api">
<h1>The C API<a class="headerlink" href="#the-c-api" title="Permalink to this headline">¶</a></h1>
<p>You can integrate YARA into your C/C++ project by using the API provided by the
<em>libyara</em> library. This API gives you access to every YARA feature and it’s the
same API used by the command-line tools <code class="docutils literal"><span class="pre">yara</span></code> and <code class="docutils literal"><span class="pre">yarac</span></code>.</p>
<div class="section" id="initializing-and-finalizing-libyara">
<h2>Initializing and finalizing <em>libyara</em><a class="headerlink" href="#initializing-and-finalizing-libyara" title="Permalink to this headline">¶</a></h2>
<p>The first thing your program must do when using <em>libyara</em> is initializing the
library. This is done by calling the <a class="reference internal" href="#c.yr_initialize" title="yr_initialize"><code class="xref c c-func docutils literal"><span class="pre">yr_initialize()</span></code></a> function. This
function allocates any resources needed by the library and initializes internal
data structures. Its counterpart is <a class="reference internal" href="#c.yr_finalize" title="yr_finalize"><code class="xref c c-func docutils literal"><span class="pre">yr_finalize()</span></code></a>, which must be called
when you are finished using the library.</p>
<p>In a multi-threaded program only the main thread must call
<a class="reference internal" href="#c.yr_initialize" title="yr_initialize"><code class="xref c c-func docutils literal"><span class="pre">yr_initialize()</span></code></a> and <a class="reference internal" href="#c.yr_finalize" title="yr_finalize"><code class="xref c c-func docutils literal"><span class="pre">yr_finalize()</span></code></a>, but any additional thread
using the library must call <a class="reference internal" href="#c.yr_finalize_thread" title="yr_finalize_thread"><code class="xref c c-func docutils literal"><span class="pre">yr_finalize_thread()</span></code></a> before exiting.</p>
</div>
<div class="section" id="compiling-rules">
<h2>Compiling rules<a class="headerlink" href="#compiling-rules" title="Permalink to this headline">¶</a></h2>
<p>Before using your rules to scan any data you need to compile them into binary
form. For that purpose you’ll need a YARA compiler, which can be created with
<a class="reference internal" href="#c.yr_compiler_create" title="yr_compiler_create"><code class="xref c c-func docutils literal"><span class="pre">yr_compiler_create()</span></code></a>. After being used, the compiler must be destroyed
with <a class="reference internal" href="#c.yr_compiler_destroy" title="yr_compiler_destroy"><code class="xref c c-func docutils literal"><span class="pre">yr_compiler_destroy()</span></code></a>.</p>
<p>You can use <a class="reference internal" href="#c.yr_compiler_add_file" title="yr_compiler_add_file"><code class="xref c c-func docutils literal"><span class="pre">yr_compiler_add_file()</span></code></a>, <a class="reference internal" href="#c.yr_compiler_add_fd" title="yr_compiler_add_fd"><code class="xref c c-func docutils literal"><span class="pre">yr_compiler_add_fd()</span></code></a>, or
<a class="reference internal" href="#c.yr_compiler_add_string" title="yr_compiler_add_string"><code class="xref c c-func docutils literal"><span class="pre">yr_compiler_add_string()</span></code></a> to add one or more input sources to be
compiled. Both of these functions receive an optional namespace. Rules added
under the same namespace behave as if they were contained within the same
source file or string, so, rule identifiers must be unique among all the sources
sharing a namespace. If the namespace argument is <code class="docutils literal"><span class="pre">NULL</span></code> the rules are put
in the <em>default</em> namespace.</p>
<p>The <a class="reference internal" href="#c.yr_compiler_add_file" title="yr_compiler_add_file"><code class="xref c c-func docutils literal"><span class="pre">yr_compiler_add_file()</span></code></a>, <a class="reference internal" href="#c.yr_compiler_add_fd" title="yr_compiler_add_fd"><code class="xref c c-func docutils literal"><span class="pre">yr_compiler_add_fd()</span></code></a>, and
<a class="reference internal" href="#c.yr_compiler_add_string" title="yr_compiler_add_string"><code class="xref c c-func docutils literal"><span class="pre">yr_compiler_add_string()</span></code></a> functions return
the number of errors found in the source code. If the rules are correct they
will return 0. If any of these functions return an error the compiler can’t used
anymore, neither for adding more rules nor getting the compiled rules.</p>
<p>For obtaining detailed error information you must set a callback
function by using <a class="reference internal" href="#c.yr_compiler_set_callback" title="yr_compiler_set_callback"><code class="xref c c-func docutils literal"><span class="pre">yr_compiler_set_callback()</span></code></a> before calling
any of the compiling functions. The callback function has the following
prototype:</p>
<div class="highlight-c"><div class="highlight"><pre><span></span><span class="kt">void</span> <span class="n">callback_function</span><span class="p">(</span>
<span class="kt">int</span> <span class="n">error_level</span><span class="p">,</span>
<span class="k">const</span> <span class="kt">char</span><span class="o">*</span> <span class="n">file_name</span><span class="p">,</span>
<span class="kt">int</span> <span class="n">line_number</span><span class="p">,</span>
<span class="k">const</span> <span class="kt">char</span><span class="o">*</span> <span class="n">message</span><span class="p">,</span>
<span class="kt">void</span><span class="o">*</span> <span class="n">user_data</span><span class="p">)</span>
</pre></div>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 3.3.0.</span></p>
</div>
<p>Possible values for <code class="docutils literal"><span class="pre">error_level</span></code> are <code class="docutils literal"><span class="pre">YARA_ERROR_LEVEL_ERROR</span></code> and
<code class="docutils literal"><span class="pre">YARA_ERROR_LEVEL_WARNING</span></code>. The arguments <code class="docutils literal"><span class="pre">file_name</span></code> and <code class="docutils literal"><span class="pre">line_number</span></code>
contains the file name and line number where the error or warning occurs.
<code class="docutils literal"><span class="pre">file_name</span></code> is the one passed to <a class="reference internal" href="#c.yr_compiler_add_file" title="yr_compiler_add_file"><code class="xref c c-func docutils literal"><span class="pre">yr_compiler_add_file()</span></code></a> or
<a class="reference internal" href="#c.yr_compiler_add_fd" title="yr_compiler_add_fd"><code class="xref c c-func docutils literal"><span class="pre">yr_compiler_add_fd()</span></code></a>. It can be <code class="docutils literal"><span class="pre">NULL</span></code> if you passed <code class="docutils literal"><span class="pre">NULL</span></code> or if
you’re using <a class="reference internal" href="#c.yr_compiler_add_string" title="yr_compiler_add_string"><code class="xref c c-func docutils literal"><span class="pre">yr_compiler_add_string()</span></code></a>. The <code class="docutils literal"><span class="pre">user_data</span></code> pointer is the
same you passed to <a class="reference internal" href="#c.yr_compiler_set_callback" title="yr_compiler_set_callback"><code class="xref c c-func docutils literal"><span class="pre">yr_compiler_set_callback()</span></code></a>.</p>
<p>By default, for rules containing references to other files
(<code class="docutils literal"><span class="pre">include</span> <span class="pre">"filename.yara"</span></code>), yara will try to find those files on disk.
However, if you want to fetch the imported rules from another source (eg: from a
database or remote service), a callback function can be set with
<a class="reference internal" href="#c.yr_compiler_set_include_callback" title="yr_compiler_set_include_callback"><code class="xref c c-func docutils literal"><span class="pre">yr_compiler_set_include_callback()</span></code></a>.
The callback receives the following parameters:</p>
<blockquote>
<div><ul class="simple">
<li><code class="docutils literal"><span class="pre">include_name</span></code>: name of the requested file.</li>
<li><code class="docutils literal"><span class="pre">calling_rule_filename</span></code>: the requesting file name (NULL if not a file).</li>
<li><code class="docutils literal"><span class="pre">calling_rule_namespace</span></code>: namespace (NULL if undefined).</li>
<li><code class="docutils literal"><span class="pre">user_data</span></code> pointer is the same you passed to <a class="reference internal" href="#c.yr_compiler_set_include_callback" title="yr_compiler_set_include_callback"><code class="xref c c-func docutils literal"><span class="pre">yr_compiler_set_include_callback()</span></code></a>.</li>
</ul>
</div></blockquote>
<p>It should return the requested file’s content as a null-terminated string. The
memory for this string should be allocated by the callback function. Once it is
safe to free the memory used to return the callback’s result, the include_free
function passed to <a class="reference internal" href="#c.yr_compiler_set_include_callback" title="yr_compiler_set_include_callback"><code class="xref c c-func docutils literal"><span class="pre">yr_compiler_set_include_callback()</span></code></a> will be called.
If the memory does not need to be freed, NULL can be passed as include_free
instead. You can completely disable support for includes by setting a NULL
callback function with <a class="reference internal" href="#c.yr_compiler_set_include_callback" title="yr_compiler_set_include_callback"><code class="xref c c-func docutils literal"><span class="pre">yr_compiler_set_include_callback()</span></code></a>.</p>
<p>The callback function has the following prototype:</p>
<div class="highlight-c"><div class="highlight"><pre><span></span><span class="k">const</span> <span class="kt">char</span><span class="o">*</span> <span class="nf">include_callback</span><span class="p">(</span>
<span class="k">const</span> <span class="kt">char</span><span class="o">*</span> <span class="n">include_name</span><span class="p">,</span>
<span class="k">const</span> <span class="kt">char</span><span class="o">*</span> <span class="n">calling_rule_filename</span><span class="p">,</span>
<span class="k">const</span> <span class="kt">char</span><span class="o">*</span> <span class="n">calling_rule_namespace</span><span class="p">,</span>
<span class="kt">void</span><span class="o">*</span> <span class="n">user_data</span><span class="p">);</span>
</pre></div>
</div>
<p>The free function has the following prototype:</p>
<div class="highlight-c"><div class="highlight"><pre><span></span><span class="kt">void</span> <span class="nf">include_free</span><span class="p">(</span>
<span class="k">const</span> <span class="kt">char</span><span class="o">*</span> <span class="n">callback_result_ptr</span><span class="p">,</span>
<span class="kt">void</span><span class="o">*</span> <span class="n">user_data</span><span class="p">);</span>
</pre></div>
</div>
<p>After you successfully added some sources you can get the compiled rules
using the <a class="reference internal" href="#c.yr_compiler_get_rules" title="yr_compiler_get_rules"><code class="xref c c-func docutils literal"><span class="pre">yr_compiler_get_rules()</span></code></a> function. You’ll get a pointer to
a <a class="reference internal" href="#c.YR_RULES" title="YR_RULES"><code class="xref c c-type docutils literal"><span class="pre">YR_RULES</span></code></a> structure which can be used to scan your data as
described in <a class="reference internal" href="#scanning-data"><span class="std std-ref">Scanning data</span></a>. Once <a class="reference internal" href="#c.yr_compiler_get_rules" title="yr_compiler_get_rules"><code class="xref c c-func docutils literal"><span class="pre">yr_compiler_get_rules()</span></code></a> is
invoked you can not add more sources to the compiler, but you can get multiple
instances of the compiled rules by calling <a class="reference internal" href="#c.yr_compiler_get_rules" title="yr_compiler_get_rules"><code class="xref c c-func docutils literal"><span class="pre">yr_compiler_get_rules()</span></code></a>
multiple times.</p>
<p>Each instance of <a class="reference internal" href="#c.YR_RULES" title="YR_RULES"><code class="xref c c-type docutils literal"><span class="pre">YR_RULES</span></code></a> must be destroyed with
<a class="reference internal" href="#c.yr_rules_destroy" title="yr_rules_destroy"><code class="xref c c-func docutils literal"><span class="pre">yr_rules_destroy()</span></code></a>.</p>
</div>
<div class="section" id="saving-and-retrieving-compiled-rules">
<h2>Saving and retrieving compiled rules<a class="headerlink" href="#saving-and-retrieving-compiled-rules" title="Permalink to this headline">¶</a></h2>
<p>Compiled rules can be saved to a file and retrieved later by using
<a class="reference internal" href="#c.yr_rules_save" title="yr_rules_save"><code class="xref c c-func docutils literal"><span class="pre">yr_rules_save()</span></code></a> and <a class="reference internal" href="#c.yr_rules_load" title="yr_rules_load"><code class="xref c c-func docutils literal"><span class="pre">yr_rules_load()</span></code></a>. Rules compiled and saved
in one machine can be loaded in another machine as long as they have the same
endianness, no matter the operating system or if they are 32-bit or 64-bit
systems. However files saved with older versions of YARA may not work with
newer versions due to changes in the file layout.</p>
<p>You can also save and retrieve your rules to and from generic data streams by
using functions <a class="reference internal" href="#c.yr_rules_save_stream" title="yr_rules_save_stream"><code class="xref c c-func docutils literal"><span class="pre">yr_rules_save_stream()</span></code></a> and
<a class="reference internal" href="#c.yr_rules_load_stream" title="yr_rules_load_stream"><code class="xref c c-func docutils literal"><span class="pre">yr_rules_load_stream()</span></code></a>. These functions receive a pointer to a
<a class="reference internal" href="#c.YR_STREAM" title="YR_STREAM"><code class="xref c c-type docutils literal"><span class="pre">YR_STREAM</span></code></a> structure, defined as:</p>
<div class="highlight-c"><div class="highlight"><pre><span></span><span class="k">typedef</span> <span class="k">struct</span> <span class="n">_YR_STREAM</span>
<span class="p">{</span>
<span class="kt">void</span><span class="o">*</span> <span class="n">user_data</span><span class="p">;</span>
<span class="n">YR_STREAM_READ_FUNC</span> <span class="n">read</span><span class="p">;</span>
<span class="n">YR_STREAM_WRITE_FUNC</span> <span class="n">write</span><span class="p">;</span>
<span class="p">}</span> <span class="n">YR_STREAM</span><span class="p">;</span>
</pre></div>
</div>
<p>You must provide your own implementation for <code class="docutils literal"><span class="pre">read</span></code> and <code class="docutils literal"><span class="pre">write</span></code> functions.
The <code class="docutils literal"><span class="pre">read</span></code> function is used by <a class="reference internal" href="#c.yr_rules_load_stream" title="yr_rules_load_stream"><code class="xref c c-func docutils literal"><span class="pre">yr_rules_load_stream()</span></code></a> to read data
from your stream and the <code class="docutils literal"><span class="pre">write</span></code> function is used by
<a class="reference internal" href="#c.yr_rules_save_stream" title="yr_rules_save_stream"><code class="xref c c-func docutils literal"><span class="pre">yr_rules_save_stream()</span></code></a> to write data into your stream.</p>
<p>Your <code class="docutils literal"><span class="pre">read</span></code> and <code class="docutils literal"><span class="pre">write</span></code> functions must respond to these prototypes:</p>
<div class="highlight-c"><div class="highlight"><pre><span></span><span class="kt">size_t</span> <span class="nf">read</span><span class="p">(</span>
<span class="kt">void</span><span class="o">*</span> <span class="n">ptr</span><span class="p">,</span>
<span class="kt">size_t</span> <span class="n">size</span><span class="p">,</span>
<span class="kt">size_t</span> <span class="n">count</span><span class="p">,</span>
<span class="kt">void</span><span class="o">*</span> <span class="n">user_data</span><span class="p">);</span>
<span class="kt">size_t</span> <span class="nf">write</span><span class="p">(</span>
<span class="k">const</span> <span class="kt">void</span><span class="o">*</span> <span class="n">ptr</span><span class="p">,</span>
<span class="kt">size_t</span> <span class="n">size</span><span class="p">,</span>
<span class="kt">size_t</span> <span class="n">count</span><span class="p">,</span>
<span class="kt">void</span><span class="o">*</span> <span class="n">user_data</span><span class="p">);</span>
</pre></div>
</div>
<p>The <code class="docutils literal"><span class="pre">ptr</span></code> argument is a pointer to the buffer where the <code class="docutils literal"><span class="pre">read</span></code> function
should put the read data, or where the <code class="docutils literal"><span class="pre">write</span></code> function will find the data
that needs to be written to the stream. In both cases <code class="docutils literal"><span class="pre">size</span></code> is the size of
each element being read or written and <code class="docutils literal"><span class="pre">count</span></code> the number of elements. The
total size of the data being read or written is <code class="docutils literal"><span class="pre">size</span></code> * <code class="docutils literal"><span class="pre">count</span></code>. Both
functions must return the total size of the data read/written.</p>
<p>The <code class="docutils literal"><span class="pre">user_data</span></code> pointer is the same you specified in the
<a class="reference internal" href="#c.YR_STREAM" title="YR_STREAM"><code class="xref c c-type docutils literal"><span class="pre">YR_STREAM</span></code></a> structure. You can use it to pass arbitrary data to your
<code class="docutils literal"><span class="pre">read</span></code> and <code class="docutils literal"><span class="pre">write</span></code> functions.</p>
</div>
<div class="section" id="scanning-data">
<span id="id1"></span><h2>Scanning data<a class="headerlink" href="#scanning-data" title="Permalink to this headline">¶</a></h2>
<p>Once you have an instance of <a class="reference internal" href="#c.YR_RULES" title="YR_RULES"><code class="xref c c-type docutils literal"><span class="pre">YR_RULES</span></code></a> you can use it with either
<a class="reference internal" href="#c.yr_rules_scan_file" title="yr_rules_scan_file"><code class="xref c c-func docutils literal"><span class="pre">yr_rules_scan_file()</span></code></a>, <a class="reference internal" href="#c.yr_rules_scan_fd" title="yr_rules_scan_fd"><code class="xref c c-func docutils literal"><span class="pre">yr_rules_scan_fd()</span></code></a> or
<a class="reference internal" href="#c.yr_rules_scan_mem" title="yr_rules_scan_mem"><code class="xref c c-func docutils literal"><span class="pre">yr_rules_scan_mem()</span></code></a>. The results from the scan are returned to your
program via a callback function. The callback has the following prototype:</p>
<div class="highlight-c"><div class="highlight"><pre><span></span><span class="kt">int</span> <span class="nf">callback_function</span><span class="p">(</span>
<span class="kt">int</span> <span class="n">message</span><span class="p">,</span>
<span class="kt">void</span><span class="o">*</span> <span class="n">message_data</span><span class="p">,</span>
<span class="kt">void</span><span class="o">*</span> <span class="n">user_data</span><span class="p">);</span>
</pre></div>
</div>
<p>Possible values for <code class="docutils literal"><span class="pre">message</span></code> are:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">CALLBACK_MSG_RULE_MATCHING</span>
<span class="n">CALLBACK_MSG_RULE_NOT_MATCHING</span>
<span class="n">CALLBACK_MSG_SCAN_FINISHED</span>
<span class="n">CALLBACK_MSG_IMPORT_MODULE</span>
<span class="n">CALLBACK_MSG_MODULE_IMPORTED</span>
</pre></div>
</div>
<p>Your callback function will be called once for each rule with either
a <code class="docutils literal"><span class="pre">CALLBACK_MSG_RULE_MATCHING</span></code> or <code class="docutils literal"><span class="pre">CALLBACK_MSG_RULE_NOT_MATCHING</span></code> message,
depending if the rule is matching or not. In both cases a pointer to the
<a class="reference internal" href="#c.YR_RULE" title="YR_RULE"><code class="xref c c-type docutils literal"><span class="pre">YR_RULE</span></code></a> structure associated with the rule is passed in the
<code class="docutils literal"><span class="pre">message_data</span></code> argument. You just need to perform a typecast from
<code class="docutils literal"><span class="pre">void*</span></code> to <code class="docutils literal"><span class="pre">YR_RULE*</span></code> to access the structure.</p>
<p>This callback is also called with the <code class="docutils literal"><span class="pre">CALLBACK_MSG_IMPORT_MODULE</span></code> message.
All modules referenced by an <code class="docutils literal"><span class="pre">import</span></code> statement in the rules are imported
once for every file being scanned. In this case <code class="docutils literal"><span class="pre">message_data</span></code> points to a
<a class="reference internal" href="#c.YR_MODULE_IMPORT" title="YR_MODULE_IMPORT"><code class="xref c c-type docutils literal"><span class="pre">YR_MODULE_IMPORT</span></code></a> structure. This structure contains a <code class="docutils literal"><span class="pre">module_name</span></code>
field pointing to a null terminated string with the name of the module being
imported and two other fields <code class="docutils literal"><span class="pre">module_data</span></code> and <code class="docutils literal"><span class="pre">module_data_size</span></code>. These
fields are initially set to <code class="docutils literal"><span class="pre">NULL</span></code> and <code class="docutils literal"><span class="pre">0</span></code>, but your program can assign a
pointer to some arbitrary data to <code class="docutils literal"><span class="pre">module_data</span></code> while setting
<code class="docutils literal"><span class="pre">module_data_size</span></code> to the size of the data. This way you can pass additional
data to those modules requiring it, like the <a class="reference internal" href="modules/cuckoo.html#cuckoo-module"><span class="std std-ref">Cuckoo module</span></a> for example.</p>
<p>Once a module is imported the callback is called again with the
CALLBACK_MSG_MODULE_IMPORTED. When this happens <code class="docutils literal"><span class="pre">message_data</span></code> points to a
<code class="xref c c-type docutils literal"><span class="pre">YR_OBJECT_STRUCTURE</span></code> structure. This structure contains all the
information provided by the module about the currently scanned file.</p>
<p>Lastly, the callback function is also called with the
<code class="docutils literal"><span class="pre">CALLBACK_MSG_SCAN_FINISHED</span></code> message when the scan is finished. In this case
<code class="docutils literal"><span class="pre">message_data</span></code> is <code class="docutils literal"><span class="pre">NULL</span></code>.</p>
<p>Your callback function must return one of the following values:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">CALLBACK_CONTINUE</span>
<span class="n">CALLBACK_ABORT</span>
<span class="n">CALLBACK_ERROR</span>
</pre></div>
</div>
<p>If it returns <code class="docutils literal"><span class="pre">CALLBACK_CONTINUE</span></code> YARA will continue normally,
<code class="docutils literal"><span class="pre">CALLBACK_ABORT</span></code> will abort the scan but the result from the
<code class="docutils literal"><span class="pre">yr_rules_scan_XXXX</span></code> function will be <code class="docutils literal"><span class="pre">ERROR_SUCCESS</span></code>. On the other hand
<code class="docutils literal"><span class="pre">CALLBACK_ERROR</span></code> will abort the scanning too, but the result from
<code class="docutils literal"><span class="pre">yr_rules_scan_XXXX</span></code> will be <code class="docutils literal"><span class="pre">ERROR_CALLBACK_ERROR</span></code>.</p>
<p>The <code class="docutils literal"><span class="pre">user_data</span></code> argument passed to your callback function is the same you
passed <code class="docutils literal"><span class="pre">yr_rules_scan_XXXX</span></code>. This pointer is not touched by YARA, it’s just a
way for your program to pass arbitrary data to the callback function.</p>
<p>All <code class="docutils literal"><span class="pre">yr_rules_scan_XXXX</span></code> functions receive a <code class="docutils literal"><span class="pre">flags</span></code> argument and a
<code class="docutils literal"><span class="pre">timeout</span></code> argument. The only flag defined at this time is
<code class="docutils literal"><span class="pre">SCAN_FLAGS_FAST_MODE</span></code>, so you must pass either this flag or a zero value.
The <code class="docutils literal"><span class="pre">timeout</span></code> argument forces the function to return after the specified
number of seconds approximately, with a zero meaning no timeout at all.</p>
<p>The <code class="docutils literal"><span class="pre">SCAN_FLAGS_FAST_MODE</span></code> flag makes the scanning a little faster by avoiding
multiple matches of the same string when not necessary. Once the string was
found in the file it’s subsequently ignored, implying that you’ll have a
single match for the string, even if it appears multiple times in the scanned
data. This flag has the same effect of the <code class="docutils literal"><span class="pre">-f</span></code> command-line option described
in <a class="reference internal" href="commandline.html#command-line"><span class="std std-ref">Running YARA from the command-line</span></a>.</p>
</div>
<div class="section" id="api-reference">
<h2>API reference<a class="headerlink" href="#api-reference" title="Permalink to this headline">¶</a></h2>
<div class="section" id="data-structures">
<h3>Data structures<a class="headerlink" href="#data-structures" title="Permalink to this headline">¶</a></h3>
<dl class="type">
<dt id="c.YR_COMPILER">
<code class="descname">YR_COMPILER</code><a class="headerlink" href="#c.YR_COMPILER" title="Permalink to this definition">¶</a></dt>
<dd><p>Data structure representing a YARA compiler.</p>
</dd></dl>
<dl class="type">
<dt id="c.YR_MATCH">
<code class="descname">YR_MATCH</code><a class="headerlink" href="#c.YR_MATCH" title="Permalink to this definition">¶</a></dt>
<dd><p>Data structure representing a string match.</p>
<dl class="member">
<dt id="c.YR_MATCH.base">
int64_t <code class="descname">base</code><a class="headerlink" href="#c.YR_MATCH.base" title="Permalink to this definition">¶</a></dt>
<dd><p>Base offset/address for the match. While scanning a file this field is
usually zero, while scanning a process memory space this field is the
virtual address of the memory block where the match was found.</p>
</dd></dl>
<dl class="member">
<dt id="c.YR_MATCH.offset">
int64_t <code class="descname">offset</code><a class="headerlink" href="#c.YR_MATCH.offset" title="Permalink to this definition">¶</a></dt>
<dd><p>Offset of the match relative to <em>base</em>.</p>
</dd></dl>
<dl class="member">
<dt id="c.YR_MATCH.match_length">
int32_t <code class="descname">match_length</code><a class="headerlink" href="#c.YR_MATCH.match_length" title="Permalink to this definition">¶</a></dt>
<dd><p>Length of the matching string</p>
</dd></dl>
<dl class="member">
<dt id="c.YR_MATCH.data">
const uint8_t* <code class="descname">data</code><a class="headerlink" href="#c.YR_MATCH.data" title="Permalink to this definition">¶</a></dt>
<dd><p>Pointer to a buffer containing a portion of the matching string.</p>
</dd></dl>
<dl class="member">
<dt id="c.YR_MATCH.data_length">
int32_t <code class="descname">data_length</code><a class="headerlink" href="#c.YR_MATCH.data_length" title="Permalink to this definition">¶</a></dt>
<dd><p>Length of <code class="docutils literal"><span class="pre">data</span></code> buffer. <code class="docutils literal"><span class="pre">data_length</span></code> is the minimum of
<code class="docutils literal"><span class="pre">match_length</span></code> and <code class="docutils literal"><span class="pre">MAX_MATCH_DATA</span></code>.</p>
</dd></dl>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 3.5.0.</span></p>
</div>
</dd></dl>
<dl class="type">
<dt id="c.YR_META">
<code class="descname">YR_META</code><a class="headerlink" href="#c.YR_META" title="Permalink to this definition">¶</a></dt>
<dd><p>Data structure representing a metadata value.</p>
<dl class="member">
<dt id="c.YR_META.identifier">
const char* <code class="descname">identifier</code><a class="headerlink" href="#c.YR_META.identifier" title="Permalink to this definition">¶</a></dt>
<dd><p>Meta identifier.</p>
</dd></dl>
<dl class="member">
<dt id="c.YR_META.type">
int32_t <code class="descname">type</code><a class="headerlink" href="#c.YR_META.type" title="Permalink to this definition">¶</a></dt>
<dd><p>One of the following metadata types:</p>
<blockquote>
<div><code class="docutils literal"><span class="pre">META_TYPE_NULL</span></code>
<code class="docutils literal"><span class="pre">META_TYPE_INTEGER</span></code>
<code class="docutils literal"><span class="pre">META_TYPE_STRING</span></code>
<code class="docutils literal"><span class="pre">META_TYPE_BOOLEAN</span></code></div></blockquote>
</dd></dl>
</dd></dl>
<dl class="type">
<dt id="c.YR_MODULE_IMPORT">
<code class="descname">YR_MODULE_IMPORT</code><a class="headerlink" href="#c.YR_MODULE_IMPORT" title="Permalink to this definition">¶</a></dt>
<dd><dl class="member">
<dt id="c.YR_MODULE_IMPORT.module_name">
const char* <code class="descname">module_name</code><a class="headerlink" href="#c.YR_MODULE_IMPORT.module_name" title="Permalink to this definition">¶</a></dt>
<dd><p>Name of the module being imported.</p>
</dd></dl>
<dl class="member">
<dt id="c.YR_MODULE_IMPORT.module_data">
void* <code class="descname">module_data</code><a class="headerlink" href="#c.YR_MODULE_IMPORT.module_data" title="Permalink to this definition">¶</a></dt>
<dd><p>Pointer to additional data passed to the module. Initially set to
<code class="docutils literal"><span class="pre">NULL</span></code>, your program is responsible for setting this pointer while
handling the CALLBACK_MSG_IMPORT_MODULE message.</p>
</dd></dl>
<dl class="member">
<dt id="c.YR_MODULE_IMPORT.module_data_size">
size_t <code class="descname">module_data_size</code><a class="headerlink" href="#c.YR_MODULE_IMPORT.module_data_size" title="Permalink to this definition">¶</a></dt>
<dd><p>Size of additional data passed to module. Your program must set the
appropriate value if <code class="docutils literal"><span class="pre">module_data</span></code> is modified.</p>
</dd></dl>
</dd></dl>
<dl class="type">
<dt id="c.YR_RULE">
<code class="descname">YR_RULE</code><a class="headerlink" href="#c.YR_RULE" title="Permalink to this definition">¶</a></dt>
<dd><p>Data structure representing a single rule.</p>
<dl class="member">
<dt id="c.YR_RULE.identifier">
const char* <code class="descname">identifier</code><a class="headerlink" href="#c.YR_RULE.identifier" title="Permalink to this definition">¶</a></dt>
<dd><p>Rule identifier.</p>
</dd></dl>
<dl class="member">
<dt id="c.YR_RULE.tags">
const char* <code class="descname">tags</code><a class="headerlink" href="#c.YR_RULE.tags" title="Permalink to this definition">¶</a></dt>
<dd><p>Pointer to a sequence of null terminated strings with tag names. An
additional null character marks the end of the sequence. Example:
<code class="docutils literal"><span class="pre">tag1\0tag2\0tag3\0\0</span></code>. To iterate over the tags you can use
<a class="reference internal" href="#c.yr_rule_tags_foreach" title="yr_rule_tags_foreach"><code class="xref c c-func docutils literal"><span class="pre">yr_rule_tags_foreach()</span></code></a>.</p>
</dd></dl>
<dl class="member">
<dt id="c.YR_RULE.metas">
<a class="reference internal" href="#c.YR_META" title="YR_META">YR_META</a>* <code class="descname">metas</code><a class="headerlink" href="#c.YR_RULE.metas" title="Permalink to this definition">¶</a></dt>
<dd><p>Pointer to a sequence of <a class="reference internal" href="#c.YR_META" title="YR_META"><code class="xref c c-type docutils literal"><span class="pre">YR_META</span></code></a> structures. To iterate over the
structures use <a class="reference internal" href="#c.yr_rule_metas_foreach" title="yr_rule_metas_foreach"><code class="xref c c-func docutils literal"><span class="pre">yr_rule_metas_foreach()</span></code></a>.</p>
</dd></dl>
<dl class="member">
<dt id="c.YR_RULE.strings">
<a class="reference internal" href="#c.YR_STRING" title="YR_STRING">YR_STRING</a>* <code class="descname">strings</code><a class="headerlink" href="#c.YR_RULE.strings" title="Permalink to this definition">¶</a></dt>
<dd><p>Pointer to a sequence of <a class="reference internal" href="#c.YR_STRING" title="YR_STRING"><code class="xref c c-type docutils literal"><span class="pre">YR_STRING</span></code></a> structures. To iterate over the
structures use <a class="reference internal" href="#c.yr_rule_strings_foreach" title="yr_rule_strings_foreach"><code class="xref c c-func docutils literal"><span class="pre">yr_rule_strings_foreach()</span></code></a>.</p>
</dd></dl>
<dl class="member">
<dt id="c.YR_RULE.ns">
<a class="reference internal" href="#c.YR_NAMESPACE" title="YR_NAMESPACE">YR_NAMESPACE</a>* <code class="descname">ns</code><a class="headerlink" href="#c.YR_RULE.ns" title="Permalink to this definition">¶</a></dt>
<dd><p>Pointer to a <a class="reference internal" href="#c.YR_NAMESPACE" title="YR_NAMESPACE"><code class="xref c c-type docutils literal"><span class="pre">YR_NAMESPACE</span></code></a> structure.</p>
</dd></dl>
</dd></dl>
<dl class="type">
<dt id="c.YR_RULES">
<code class="descname">YR_RULES</code><a class="headerlink" href="#c.YR_RULES" title="Permalink to this definition">¶</a></dt>
<dd><p>Data structure representing a set of compiled rules.</p>
</dd></dl>
<dl class="type">
<dt id="c.YR_STREAM">
<code class="descname">YR_STREAM</code><a class="headerlink" href="#c.YR_STREAM" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 3.4.0.</span></p>
</div>
<p>Data structure representing a stream used with functions
<a class="reference internal" href="#c.yr_rules_load_stream" title="yr_rules_load_stream"><code class="xref c c-func docutils literal"><span class="pre">yr_rules_load_stream()</span></code></a> and <a class="reference internal" href="#c.yr_rules_save_stream" title="yr_rules_save_stream"><code class="xref c c-func docutils literal"><span class="pre">yr_rules_save_stream()</span></code></a>.</p>
<dl class="member">
<dt id="c.YR_STREAM.user_data">
void* <code class="descname">user_data</code><a class="headerlink" href="#c.YR_STREAM.user_data" title="Permalink to this definition">¶</a></dt>
<dd><p>A user-defined pointer.</p>
</dd></dl>
<dl class="member">
<dt id="c.YR_STREAM.read">
YR_STREAM_READ_FUNC <code class="descname">read</code><a class="headerlink" href="#c.YR_STREAM.read" title="Permalink to this definition">¶</a></dt>
<dd><p>A pointer to the stream’s read function provided by the user.</p>
</dd></dl>
<dl class="member">
<dt id="c.YR_STREAM.write">
YR_STREAM_WRITE_FUNC <code class="descname">write</code><a class="headerlink" href="#c.YR_STREAM.write" title="Permalink to this definition">¶</a></dt>
<dd><p>A pointer to the stream’s write function provided by the user.</p>
</dd></dl>
</dd></dl>
<dl class="type">
<dt id="c.YR_STRING">
<code class="descname">YR_STRING</code><a class="headerlink" href="#c.YR_STRING" title="Permalink to this definition">¶</a></dt>
<dd><p>Data structure representing a string declared in a rule.</p>
<dl class="member">
<dt id="c.YR_STRING.identifier">
const char* <code class="descname">identifier</code><a class="headerlink" href="#c.YR_STRING.identifier" title="Permalink to this definition">¶</a></dt>
<dd><p>String identifier.</p>
</dd></dl>
</dd></dl>
<dl class="type">
<dt id="c.YR_NAMESPACE">
<code class="descname">YR_NAMESPACE</code><a class="headerlink" href="#c.YR_NAMESPACE" title="Permalink to this definition">¶</a></dt>
<dd><p>Data structure representing a rule namespace.</p>
<dl class="member">
<dt id="c.YR_NAMESPACE.name">
const char* <code class="descname">name</code><a class="headerlink" href="#c.YR_NAMESPACE.name" title="Permalink to this definition">¶</a></dt>
<dd><p>Rule namespace.</p>
</dd></dl>
</dd></dl>
</div>
<div class="section" id="functions">
<h3>Functions<a class="headerlink" href="#functions" title="Permalink to this headline">¶</a></h3>
<dl class="function">
<dt id="c.yr_initialize">
int <code class="descname">yr_initialize</code><span class="sig-paren">(</span>void<span class="sig-paren">)</span><a class="headerlink" href="#c.yr_initialize" title="Permalink to this definition">¶</a></dt>
<dd><p>Initialize the library. Must be called by the main thread before using any
other function. Return <a class="reference internal" href="#c.ERROR_SUCCESS" title="ERROR_SUCCESS"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_SUCCESS</span></code></a> on success another error
code in case of error. The list of possible return codes vary according
to the modules compiled into YARA.</p>
</dd></dl>
<dl class="function">
<dt id="c.yr_finalize">
int <code class="descname">yr_finalize</code><span class="sig-paren">(</span>void<span class="sig-paren">)</span><a class="headerlink" href="#c.yr_finalize" title="Permalink to this definition">¶</a></dt>
<dd><p>Finalize the library. Must be called by the main free to release any
resource allocated by the library. Return <a class="reference internal" href="#c.ERROR_SUCCESS" title="ERROR_SUCCESS"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_SUCCESS</span></code></a> on
success another error code in case of error. The list of possible return
codes vary according to the modules compiled into YARA.</p>
</dd></dl>
<dl class="function">
<dt id="c.yr_finalize_thread">
void <code class="descname">yr_finalize_thread</code><span class="sig-paren">(</span>void<span class="sig-paren">)</span><a class="headerlink" href="#c.yr_finalize_thread" title="Permalink to this definition">¶</a></dt>
<dd><p>Any thread using the library, except the main thread, must call this
function when it finishes using the library.</p>
</dd></dl>
<dl class="function">
<dt id="c.yr_compiler_create">
int <code class="descname">yr_compiler_create</code><span class="sig-paren">(</span><a class="reference internal" href="#c.YR_COMPILER" title="YR_COMPILER">YR_COMPILER</a>**<em> compiler</em><span class="sig-paren">)</span><a class="headerlink" href="#c.yr_compiler_create" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a YARA compiler. You must pass the address of a pointer to a
<a class="reference internal" href="#c.YR_COMPILER" title="YR_COMPILER"><code class="xref c c-type docutils literal"><span class="pre">YR_COMPILER</span></code></a>, the function will set the pointer to the newly
allocated compiler. Returns one of the following error codes:</p>
<blockquote>
<div><p><a class="reference internal" href="#c.ERROR_SUCCESS" title="ERROR_SUCCESS"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_SUCCESS</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_INSUFFICIENT_MEMORY" title="ERROR_INSUFFICIENT_MEMORY"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_INSUFFICIENT_MEMORY</span></code></a></p>
</div></blockquote>
</dd></dl>
<dl class="function">
<dt id="c.yr_compiler_destroy">
void <code class="descname">yr_compiler_destroy</code><span class="sig-paren">(</span><a class="reference internal" href="#c.YR_COMPILER" title="YR_COMPILER">YR_COMPILER</a>*<em> compiler</em><span class="sig-paren">)</span><a class="headerlink" href="#c.yr_compiler_destroy" title="Permalink to this definition">¶</a></dt>
<dd><p>Destroy a YARA compiler.</p>
</dd></dl>
<dl class="function">
<dt id="c.yr_compiler_set_callback">
void <code class="descname">yr_compiler_set_callback</code><span class="sig-paren">(</span><a class="reference internal" href="#c.YR_COMPILER" title="YR_COMPILER">YR_COMPILER</a>*<em> compiler</em>, YR_COMPILER_CALLBACK_FUNC<em> callback</em>, void*<em> user_data</em><span class="sig-paren">)</span><a class="headerlink" href="#c.yr_compiler_set_callback" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionchanged">
<p><span class="versionmodified">Changed in version 3.3.0.</span></p>
</div>
<p>Set a callback for receiving error and warning information. The <em>user_data</em>
pointer is passed to the callback function.</p>
</dd></dl>
<dl class="function">
<dt id="c.yr_compiler_set_include_callback">
void <code class="descname">yr_compiler_set_include_callback</code><span class="sig-paren">(</span><a class="reference internal" href="#c.YR_COMPILER" title="YR_COMPILER">YR_COMPILER</a>*<em> compiler</em>, YR_COMPILER_INCLUDE_CALLBACK_FUNC<em> callback</em>, YR_COMPILER_INCLUDE_FREE_FUNC<em> include_free</em>, void*<em> user_data</em><span class="sig-paren">)</span><a class="headerlink" href="#c.yr_compiler_set_include_callback" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 3.7.0: </span>Set a callback to provide rules from a custom source when <code class="docutils literal"><span class="pre">include</span></code>
directive is invoked. The <em>user_data</em> pointer is untouched and passed back to
the callback function and to the free function. Once the callback’s result
is no longer needed, the include_free function will be called. If the memory
does not need to be freed, include_free can be set to NULL. If <em>callback</em> is
set to <code class="docutils literal"><span class="pre">NULL</span></code> support for include directives is disabled.</p>
</div>
</dd></dl>
<dl class="function">
<dt id="c.yr_compiler_add_file">
int <code class="descname">yr_compiler_add_file</code><span class="sig-paren">(</span><a class="reference internal" href="#c.YR_COMPILER" title="YR_COMPILER">YR_COMPILER</a>*<em> compiler</em>, FILE*<em> file</em>, const char*<em> namespace</em>, const char*<em> file_name</em><span class="sig-paren">)</span><a class="headerlink" href="#c.yr_compiler_add_file" title="Permalink to this definition">¶</a></dt>
<dd><p>Compile rules from a <em>file</em>. Rules are put into the specified <em>namespace</em>,
if <em>namespace</em> is <code class="docutils literal"><span class="pre">NULL</span></code> they will be put into the default namespace.
<em>file_name</em> is the name of the file for error reporting purposes and can be
set to <code class="docutils literal"><span class="pre">NULL</span></code>. Returns the number of errors found during compilation.</p>
</dd></dl>
<dl class="function">
<dt id="c.yr_compiler_add_fd">
int <code class="descname">yr_compiler_add_fd</code><span class="sig-paren">(</span><a class="reference internal" href="#c.YR_COMPILER" title="YR_COMPILER">YR_COMPILER</a>*<em> compiler</em>, YR_FILE_DESCRIPTOR<em> rules_fd</em>, const char*<em> namespace</em>, const char*<em> file_name</em><span class="sig-paren">)</span><a class="headerlink" href="#c.yr_compiler_add_fd" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 3.6.0.</span></p>
</div>
<p>Compile rules from a <em>file descriptor</em>. Rules are put into the specified <em>namespace</em>,
if <em>namespace</em> is <code class="docutils literal"><span class="pre">NULL</span></code> they will be put into the default namespace.
<em>file_name</em> is the name of the file for error reporting purposes and can be
set to <code class="docutils literal"><span class="pre">NULL</span></code>. Returns the number of errors found during compilation.</p>
</dd></dl>
<dl class="function">
<dt id="c.yr_compiler_add_string">
int <code class="descname">yr_compiler_add_string</code><span class="sig-paren">(</span><a class="reference internal" href="#c.YR_COMPILER" title="YR_COMPILER">YR_COMPILER</a>*<em> compiler</em>, const char*<em> string</em>, const char*<em> namespace_</em><span class="sig-paren">)</span><a class="headerlink" href="#c.yr_compiler_add_string" title="Permalink to this definition">¶</a></dt>
<dd><p>Compile rules from a <em>string</em>. Rules are put into the specified <em>namespace</em>,
if <em>namespace</em> is <code class="docutils literal"><span class="pre">NULL</span></code> they will be put into the default namespace.
Returns the number of errors found during compilation.</p>
</dd></dl>
<dl class="function">
<dt id="c.yr_compiler_get_rules">
int <code class="descname">yr_compiler_get_rules</code><span class="sig-paren">(</span><a class="reference internal" href="#c.YR_COMPILER" title="YR_COMPILER">YR_COMPILER</a>*<em> compiler</em>, <a class="reference internal" href="#c.YR_RULES" title="YR_RULES">YR_RULES</a>**<em> rules</em><span class="sig-paren">)</span><a class="headerlink" href="#c.yr_compiler_get_rules" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the compiled rules from the compiler. Returns one of the following error
codes:</p>
<blockquote>
<div><p><a class="reference internal" href="#c.ERROR_SUCCESS" title="ERROR_SUCCESS"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_SUCCESS</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_INSUFFICIENT_MEMORY" title="ERROR_INSUFFICIENT_MEMORY"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_INSUFFICIENT_MEMORY</span></code></a></p>
</div></blockquote>
</dd></dl>
<dl class="function">
<dt id="c.yr_compiler_define_integer_variable">
int <code class="descname">yr_compiler_define_integer_variable</code><span class="sig-paren">(</span><a class="reference internal" href="#c.YR_COMPILER" title="YR_COMPILER">YR_COMPILER</a>*<em> compiler</em>, const char*<em> identifier</em>, int64_t<em> value</em><span class="sig-paren">)</span><a class="headerlink" href="#c.yr_compiler_define_integer_variable" title="Permalink to this definition">¶</a></dt>
<dd><p>Defines an integer external variable.</p>
</dd></dl>
<dl class="function">
<dt id="c.yr_compiler_define_float_variable">
int <code class="descname">yr_compiler_define_float_variable</code><span class="sig-paren">(</span><a class="reference internal" href="#c.YR_COMPILER" title="YR_COMPILER">YR_COMPILER</a>*<em> compiler</em>, const char*<em> identifier</em>, double<em> value</em><span class="sig-paren">)</span><a class="headerlink" href="#c.yr_compiler_define_float_variable" title="Permalink to this definition">¶</a></dt>
<dd><p>Defines a float external variable.</p>
</dd></dl>
<dl class="function">
<dt id="c.yr_compiler_define_boolean_variable">
int <code class="descname">yr_compiler_define_boolean_variable</code><span class="sig-paren">(</span><a class="reference internal" href="#c.YR_COMPILER" title="YR_COMPILER">YR_COMPILER</a>*<em> compiler</em>, const char*<em> identifier</em>, int<em> value</em><span class="sig-paren">)</span><a class="headerlink" href="#c.yr_compiler_define_boolean_variable" title="Permalink to this definition">¶</a></dt>
<dd><p>Defines a boolean external variable.</p>
</dd></dl>
<dl class="function">
<dt id="c.yr_compiler_define_string_variable">
int <code class="descname">yr_compiler_define_string_variable</code><span class="sig-paren">(</span><a class="reference internal" href="#c.YR_COMPILER" title="YR_COMPILER">YR_COMPILER</a>*<em> compiler</em>, const char*<em> identifier</em>, const char*<em> value</em><span class="sig-paren">)</span><a class="headerlink" href="#c.yr_compiler_define_string_variable" title="Permalink to this definition">¶</a></dt>
<dd><p>Defines a string external variable.</p>
</dd></dl>
<dl class="function">
<dt id="c.yr_rules_destroy">
void <code class="descname">yr_rules_destroy</code><span class="sig-paren">(</span><a class="reference internal" href="#c.YR_RULES" title="YR_RULES">YR_RULES</a>*<em> rules</em><span class="sig-paren">)</span><a class="headerlink" href="#c.yr_rules_destroy" title="Permalink to this definition">¶</a></dt>
<dd><p>Destroy compiled rules.</p>
</dd></dl>
<dl class="function">
<dt id="c.yr_rules_save">
int <code class="descname">yr_rules_save</code><span class="sig-paren">(</span><a class="reference internal" href="#c.YR_RULES" title="YR_RULES">YR_RULES</a>*<em> rules</em>, const char*<em> filename</em><span class="sig-paren">)</span><a class="headerlink" href="#c.yr_rules_save" title="Permalink to this definition">¶</a></dt>
<dd><p>Save compiled <em>rules</em> into the file specified by <em>filename</em>. Returns one of the
following error codes:</p>
<blockquote>
<div><p><a class="reference internal" href="#c.ERROR_SUCCESS" title="ERROR_SUCCESS"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_SUCCESS</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_COULD_NOT_OPEN_FILE" title="ERROR_COULD_NOT_OPEN_FILE"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_COULD_NOT_OPEN_FILE</span></code></a></p>
</div></blockquote>
</dd></dl>
<dl class="function">
<dt id="c.yr_rules_save_stream">
int <code class="descname">yr_rules_save_stream</code><span class="sig-paren">(</span><a class="reference internal" href="#c.YR_RULES" title="YR_RULES">YR_RULES</a>*<em> rules</em>, <a class="reference internal" href="#c.YR_STREAM" title="YR_STREAM">YR_STREAM</a>*<em> stream</em><span class="sig-paren">)</span><a class="headerlink" href="#c.yr_rules_save_stream" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 3.4.0.</span></p>
</div>
<p>Save compiled <em>rules</em> into <em>stream</em>. Returns one of the following error codes:</p>
<blockquote>
<div><a class="reference internal" href="#c.ERROR_SUCCESS" title="ERROR_SUCCESS"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_SUCCESS</span></code></a></div></blockquote>
</dd></dl>
<dl class="function">
<dt id="c.yr_rules_load">
int <code class="descname">yr_rules_load</code><span class="sig-paren">(</span>const char*<em> filename</em>, <a class="reference internal" href="#c.YR_RULES" title="YR_RULES">YR_RULES</a>**<em> rules</em><span class="sig-paren">)</span><a class="headerlink" href="#c.yr_rules_load" title="Permalink to this definition">¶</a></dt>
<dd><p>Load compiled rules from the file specified by <em>filename</em>. Returns one of the
following error codes:</p>
<blockquote>
<div><p><a class="reference internal" href="#c.ERROR_SUCCESS" title="ERROR_SUCCESS"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_SUCCESS</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_INSUFFICIENT_MEMORY" title="ERROR_INSUFFICIENT_MEMORY"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_INSUFFICIENT_MEMORY</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_COULD_NOT_OPEN_FILE" title="ERROR_COULD_NOT_OPEN_FILE"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_COULD_NOT_OPEN_FILE</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_INVALID_FILE" title="ERROR_INVALID_FILE"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_INVALID_FILE</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_CORRUPT_FILE" title="ERROR_CORRUPT_FILE"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_CORRUPT_FILE</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_UNSUPPORTED_FILE_VERSION" title="ERROR_UNSUPPORTED_FILE_VERSION"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_UNSUPPORTED_FILE_VERSION</span></code></a></p>
</div></blockquote>
</dd></dl>
<dl class="function">
<dt id="c.yr_rules_load_stream">
int <code class="descname">yr_rules_load_stream</code><span class="sig-paren">(</span><a class="reference internal" href="#c.YR_STREAM" title="YR_STREAM">YR_STREAM</a>*<em> stream</em>, <a class="reference internal" href="#c.YR_RULES" title="YR_RULES">YR_RULES</a>**<em> rules</em><span class="sig-paren">)</span><a class="headerlink" href="#c.yr_rules_load_stream" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 3.4.0.</span></p>
</div>
<p>Load compiled rules from <em>stream</em>. Returns one of the following error codes:</p>
<blockquote>
<div><p><a class="reference internal" href="#c.ERROR_SUCCESS" title="ERROR_SUCCESS"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_SUCCESS</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_INSUFFICIENT_MEMORY" title="ERROR_INSUFFICIENT_MEMORY"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_INSUFFICIENT_MEMORY</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_INVALID_FILE" title="ERROR_INVALID_FILE"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_INVALID_FILE</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_CORRUPT_FILE" title="ERROR_CORRUPT_FILE"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_CORRUPT_FILE</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_UNSUPPORTED_FILE_VERSION" title="ERROR_UNSUPPORTED_FILE_VERSION"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_UNSUPPORTED_FILE_VERSION</span></code></a></p>
</div></blockquote>
</dd></dl>
<dl class="function">
<dt id="c.yr_rules_scan_mem">
int <code class="descname">yr_rules_scan_mem</code><span class="sig-paren">(</span><a class="reference internal" href="#c.YR_RULES" title="YR_RULES">YR_RULES</a>*<em> rules</em>, const uint8_t*<em> buffer</em>, size_t<em> buffer_size</em>, int<em> flags</em>, YR_CALLBACK_FUNC<em> callback</em>, void*<em> user_data</em>, int<em> timeout</em><span class="sig-paren">)</span><a class="headerlink" href="#c.yr_rules_scan_mem" title="Permalink to this definition">¶</a></dt>
<dd><p>Scan a memory buffer. Returns one of the following error codes:</p>
<blockquote>
<div><p><a class="reference internal" href="#c.ERROR_SUCCESS" title="ERROR_SUCCESS"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_SUCCESS</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_INSUFFICIENT_MEMORY" title="ERROR_INSUFFICIENT_MEMORY"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_INSUFFICIENT_MEMORY</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_TOO_MANY_SCAN_THREADS" title="ERROR_TOO_MANY_SCAN_THREADS"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_TOO_MANY_SCAN_THREADS</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_SCAN_TIMEOUT" title="ERROR_SCAN_TIMEOUT"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_SCAN_TIMEOUT</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_CALLBACK_ERROR" title="ERROR_CALLBACK_ERROR"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_CALLBACK_ERROR</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_TOO_MANY_MATCHES" title="ERROR_TOO_MANY_MATCHES"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_TOO_MANY_MATCHES</span></code></a></p>
</div></blockquote>
</dd></dl>
<dl class="function">
<dt id="c.yr_rules_scan_file">
int <code class="descname">yr_rules_scan_file</code><span class="sig-paren">(</span><a class="reference internal" href="#c.YR_RULES" title="YR_RULES">YR_RULES</a>*<em> rules</em>, const char*<em> filename</em>, int<em> flags</em>, YR_CALLBACK_FUNC<em> callback</em>, void*<em> user_data</em>, int<em> timeout</em><span class="sig-paren">)</span><a class="headerlink" href="#c.yr_rules_scan_file" title="Permalink to this definition">¶</a></dt>
<dd><p>Scan a file. Returns one of the following error codes:</p>
<blockquote>
<div><p><a class="reference internal" href="#c.ERROR_SUCCESS" title="ERROR_SUCCESS"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_SUCCESS</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_INSUFFICIENT_MEMORY" title="ERROR_INSUFFICIENT_MEMORY"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_INSUFFICIENT_MEMORY</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_COULD_NOT_MAP_FILE" title="ERROR_COULD_NOT_MAP_FILE"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_COULD_NOT_MAP_FILE</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_ZERO_LENGTH_FILE" title="ERROR_ZERO_LENGTH_FILE"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_ZERO_LENGTH_FILE</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_TOO_MANY_SCAN_THREADS" title="ERROR_TOO_MANY_SCAN_THREADS"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_TOO_MANY_SCAN_THREADS</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_SCAN_TIMEOUT" title="ERROR_SCAN_TIMEOUT"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_SCAN_TIMEOUT</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_CALLBACK_ERROR" title="ERROR_CALLBACK_ERROR"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_CALLBACK_ERROR</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_TOO_MANY_MATCHES" title="ERROR_TOO_MANY_MATCHES"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_TOO_MANY_MATCHES</span></code></a></p>
</div></blockquote>
</dd></dl>
<dl class="function">
<dt id="c.yr_rules_scan_fd">
int <code class="descname">yr_rules_scan_fd</code><span class="sig-paren">(</span><a class="reference internal" href="#c.YR_RULES" title="YR_RULES">YR_RULES</a>*<em> rules</em>, YR_FILE_DESCRIPTOR<em> fd</em>, int<em> flags</em>, YR_CALLBACK_FUNC<em> callback</em>, void*<em> user_data</em>, int<em> timeout</em><span class="sig-paren">)</span><a class="headerlink" href="#c.yr_rules_scan_fd" title="Permalink to this definition">¶</a></dt>
<dd><p>Scan a file descriptor. In POSIX systems <code class="docutils literal"><span class="pre">YR_FILE_DESCRIPTOR</span></code> is an <code class="docutils literal"><span class="pre">int</span></code>,
as returned by the <cite>open()</cite> function. In Windows <code class="docutils literal"><span class="pre">YR_FILE_DESCRIPTOR</span></code> is a
<code class="docutils literal"><span class="pre">HANDLE</span></code> as returned by <cite>CreateFile()</cite>.</p>
<p>Returns one of the following error codes:</p>
<blockquote>
<div><p><a class="reference internal" href="#c.ERROR_SUCCESS" title="ERROR_SUCCESS"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_SUCCESS</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_INSUFFICIENT_MEMORY" title="ERROR_INSUFFICIENT_MEMORY"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_INSUFFICIENT_MEMORY</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_COULD_NOT_MAP_FILE" title="ERROR_COULD_NOT_MAP_FILE"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_COULD_NOT_MAP_FILE</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_ZERO_LENGTH_FILE" title="ERROR_ZERO_LENGTH_FILE"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_ZERO_LENGTH_FILE</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_TOO_MANY_SCAN_THREADS" title="ERROR_TOO_MANY_SCAN_THREADS"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_TOO_MANY_SCAN_THREADS</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_SCAN_TIMEOUT" title="ERROR_SCAN_TIMEOUT"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_SCAN_TIMEOUT</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_CALLBACK_ERROR" title="ERROR_CALLBACK_ERROR"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_CALLBACK_ERROR</span></code></a></p>
<p><a class="reference internal" href="#c.ERROR_TOO_MANY_MATCHES" title="ERROR_TOO_MANY_MATCHES"><code class="xref c c-macro docutils literal"><span class="pre">ERROR_TOO_MANY_MATCHES</span></code></a></p>
</div></blockquote>
</dd></dl>
<dl class="function">
<dt id="c.yr_rule_tags_foreach">
<code class="descname">yr_rule_tags_foreach</code><span class="sig-paren">(</span>rule, tag<span class="sig-paren">)</span><a class="headerlink" href="#c.yr_rule_tags_foreach" title="Permalink to this definition">¶</a></dt>
<dd><p>Iterate over the tags of a given rule running the block of code that follows
each time with a different value for <em>tag</em> of type <code class="docutils literal"><span class="pre">const</span> <span class="pre">char*</span></code>. Example:</p>
<div class="highlight-c"><div class="highlight"><pre><span></span><span class="k">const</span> <span class="kt">char</span><span class="o">*</span> <span class="n">tag</span><span class="p">;</span>
<span class="cm">/* rule is a YR_RULE object */</span>
<span class="n">yr_rule_tags_foreach</span><span class="p">(</span><span class="n">rule</span><span class="p">,</span> <span class="n">tag</span><span class="p">)</span>
<span class="p">{</span>
<span class="p">..</span><span class="k">do</span> <span class="n">something</span> <span class="n">with</span> <span class="n">tag</span>
<span class="p">}</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="c.yr_rule_metas_foreach">
<code class="descname">yr_rule_metas_foreach</code><span class="sig-paren">(</span>rule, meta<span class="sig-paren">)</span><a class="headerlink" href="#c.yr_rule_metas_foreach" title="Permalink to this definition">¶</a></dt>
<dd><p>Iterate over the <a class="reference internal" href="#c.YR_META" title="YR_META"><code class="xref c c-type docutils literal"><span class="pre">YR_META</span></code></a> structures associated with a given rule
running the block of code that follows each time with a different value for
<em>meta</em>. Example:</p>
<div class="highlight-c"><div class="highlight"><pre><span></span><span class="n">YR_META</span><span class="o">*</span> <span class="n">meta</span><span class="p">;</span>
<span class="cm">/* rule is a YR_RULE object */</span>
<span class="n">yr_rule_metas_foreach</span><span class="p">(</span><span class="n">rule</span><span class="p">,</span> <span class="n">meta</span><span class="p">)</span>
<span class="p">{</span>
<span class="p">..</span><span class="k">do</span> <span class="n">something</span> <span class="n">with</span> <span class="n">meta</span>
<span class="p">}</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="c.yr_rule_strings_foreach">
<code class="descname">yr_rule_strings_foreach</code><span class="sig-paren">(</span>rule, string<span class="sig-paren">)</span><a class="headerlink" href="#c.yr_rule_strings_foreach" title="Permalink to this definition">¶</a></dt>
<dd><p>Iterate over the <a class="reference internal" href="#c.YR_STRING" title="YR_STRING"><code class="xref c c-type docutils literal"><span class="pre">YR_STRING</span></code></a> structures associated with a given rule
running the block of code that follows each time with a different value for
<em>string</em>. Example:</p>
<div class="highlight-c"><div class="highlight"><pre><span></span><span class="n">YR_STRING</span><span class="o">*</span> <span class="n">string</span><span class="p">;</span>
<span class="cm">/* rule is a YR_RULE object */</span>
<span class="n">yr_rule_strings_foreach</span><span class="p">(</span><span class="n">rule</span><span class="p">,</span> <span class="n">string</span><span class="p">)</span>
<span class="p">{</span>
<span class="p">..</span><span class="k">do</span> <span class="n">something</span> <span class="n">with</span> <span class="n">string</span>
<span class="p">}</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="c.yr_string_matches_foreach">
<code class="descname">yr_string_matches_foreach</code><span class="sig-paren">(</span>string, match<span class="sig-paren">)</span><a class="headerlink" href="#c.yr_string_matches_foreach" title="Permalink to this definition">¶</a></dt>
<dd><p>Iterate over the <a class="reference internal" href="#c.YR_MATCH" title="YR_MATCH"><code class="xref c c-type docutils literal"><span class="pre">YR_MATCH</span></code></a> structures associated with a given string
running the block of code that follows each time with a different value for
<em>match</em>. Example:</p>
<div class="highlight-c"><div class="highlight"><pre><span></span><span class="n">YR_MATCH</span><span class="o">*</span> <span class="n">match</span><span class="p">;</span>
<span class="cm">/* string is a YR_STRING object */</span>
<span class="n">yr_string_matches_foreach</span><span class="p">(</span><span class="n">string</span><span class="p">,</span> <span class="n">match</span><span class="p">)</span>
<span class="p">{</span>
<span class="p">..</span><span class="k">do</span> <span class="n">something</span> <span class="n">with</span> <span class="n">match</span>
<span class="p">}</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="c.yr_rules_foreach">
<code class="descname">yr_rules_foreach</code><span class="sig-paren">(</span>rules, rule<span class="sig-paren">)</span><a class="headerlink" href="#c.yr_rules_foreach" title="Permalink to this definition">¶</a></dt>
<dd><p>Iterate over each <a class="reference internal" href="#c.YR_RULE" title="YR_RULE"><code class="xref c c-type docutils literal"><span class="pre">YR_RULE</span></code></a> in a <a class="reference internal" href="#c.YR_RULES" title="YR_RULES"><code class="xref c c-type docutils literal"><span class="pre">YR_RULES</span></code></a> object running
the block of code that follows each time with a different value for
<em>rule</em>. Example:</p>
<div class="highlight-c"><div class="highlight"><pre><span></span><span class="n">YR_RULE</span><span class="o">*</span> <span class="n">rule</span><span class="p">;</span>
<span class="cm">/* rules is a YR_RULES object */</span>
<span class="n">yr_rules_foreach</span><span class="p">(</span><span class="n">rules</span><span class="p">,</span> <span class="n">rule</span><span class="p">)</span>
<span class="p">{</span>
<span class="p">..</span><span class="k">do</span> <span class="n">something</span> <span class="n">with</span> <span class="n">rule</span>
<span class="p">}</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="c.yr_rule_disable">
<code class="descname">yr_rule_disable</code><span class="sig-paren">(</span>rule<span class="sig-paren">)</span><a class="headerlink" href="#c.yr_rule_disable" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 3.7.0.</span></p>
</div>
<p>Disable the specified rule. Disabled rules are completely ignored during
the scanning process and they won’t match. If the disabled rule is used in
the condition of some other rule the value for the disabled rule is neither
true nor false but undefined. For more information about undefined values
see <a class="reference internal" href="writingrules.html#undefined-values"><span class="std std-ref">Undefined values</span></a>.</p>
</dd></dl>
<dl class="function">
<dt id="c.yr_rule_enable">
<code class="descname">yr_rule_enable</code><span class="sig-paren">(</span>rule<span class="sig-paren">)</span><a class="headerlink" href="#c.yr_rule_enable" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 3.7.0.</span></p>
</div>
<p>Enables the specified rule. After being disabled with <a class="reference internal" href="#c.yr_rule_disable" title="yr_rule_disable"><code class="xref c c-func docutils literal"><span class="pre">yr_rule_disable()</span></code></a>
a rule can be enabled again by using this function.</p>
</dd></dl>
</div>
<div class="section" id="error-codes">
<h3>Error codes<a class="headerlink" href="#error-codes" title="Permalink to this headline">¶</a></h3>
<dl class="macro">
<dt id="c.ERROR_SUCCESS">
<code class="descname">ERROR_SUCCESS</code><a class="headerlink" href="#c.ERROR_SUCCESS" title="Permalink to this definition">¶</a></dt>
<dd><p>Everything went fine.</p>
</dd></dl>
<dl class="macro">
<dt id="c.ERROR_INSUFFICIENT_MEMORY">
<code class="descname">ERROR_INSUFFICIENT_MEMORY</code><a class="headerlink" href="#c.ERROR_INSUFFICIENT_MEMORY" title="Permalink to this definition">¶</a></dt>
<dd><p>Insufficient memory to complete the operation.</p>
</dd></dl>
<dl class="macro">
<dt id="c.ERROR_COULD_NOT_OPEN_FILE">
<code class="descname">ERROR_COULD_NOT_OPEN_FILE</code><a class="headerlink" href="#c.ERROR_COULD_NOT_OPEN_FILE" title="Permalink to this definition">¶</a></dt>
<dd><p>File could not be opened.</p>
</dd></dl>
<dl class="macro">
<dt id="c.ERROR_COULD_NOT_MAP_FILE">
<code class="descname">ERROR_COULD_NOT_MAP_FILE</code><a class="headerlink" href="#c.ERROR_COULD_NOT_MAP_FILE" title="Permalink to this definition">¶</a></dt>
<dd><p>File could not be mapped into memory.</p>
</dd></dl>
<dl class="macro">
<dt id="c.ERROR_ZERO_LENGTH_FILE">
<code class="descname">ERROR_ZERO_LENGTH_FILE</code><a class="headerlink" href="#c.ERROR_ZERO_LENGTH_FILE" title="Permalink to this definition">¶</a></dt>
<dd><p>File length is zero.</p>
</dd></dl>
<dl class="macro">
<dt id="c.ERROR_INVALID_FILE">
<code class="descname">ERROR_INVALID_FILE</code><a class="headerlink" href="#c.ERROR_INVALID_FILE" title="Permalink to this definition">¶</a></dt>
<dd><p>File is not a valid rules file.</p>
</dd></dl>
<dl class="macro">
<dt id="c.ERROR_CORRUPT_FILE">
<code class="descname">ERROR_CORRUPT_FILE</code><a class="headerlink" href="#c.ERROR_CORRUPT_FILE" title="Permalink to this definition">¶</a></dt>
<dd><p>Rules file is corrupt.</p>
</dd></dl>
<dl class="macro">
<dt id="c.ERROR_UNSUPPORTED_FILE_VERSION">
<code class="descname">ERROR_UNSUPPORTED_FILE_VERSION</code><a class="headerlink" href="#c.ERROR_UNSUPPORTED_FILE_VERSION" title="Permalink to this definition">¶</a></dt>
<dd><p>File was generated by a different YARA and can’t be loaded by this version.</p>
</dd></dl>
<dl class="macro">
<dt id="c.ERROR_TOO_MANY_SCAN_THREADS">
<code class="descname">ERROR_TOO_MANY_SCAN_THREADS</code><a class="headerlink" href="#c.ERROR_TOO_MANY_SCAN_THREADS" title="Permalink to this definition">¶</a></dt>
<dd><p>Too many threads trying to use the same <a class="reference internal" href="#c.YR_RULES" title="YR_RULES"><code class="xref c c-type docutils literal"><span class="pre">YR_RULES</span></code></a> object
simultaneously. The limit is defined by <code class="docutils literal"><span class="pre">MAX_THREADS</span></code> in
<em>./include/yara/limits.h</em></p>
</dd></dl>
<dl class="macro">
<dt id="c.ERROR_SCAN_TIMEOUT">
<code class="descname">ERROR_SCAN_TIMEOUT</code><a class="headerlink" href="#c.ERROR_SCAN_TIMEOUT" title="Permalink to this definition">¶</a></dt>
<dd><p>Scan timed out.</p>
</dd></dl>
<dl class="macro">
<dt id="c.ERROR_CALLBACK_ERROR">
<code class="descname">ERROR_CALLBACK_ERROR</code><a class="headerlink" href="#c.ERROR_CALLBACK_ERROR" title="Permalink to this definition">¶</a></dt>
<dd><p>Callback returned an error.</p>
</dd></dl>
<dl class="macro">
<dt id="c.ERROR_TOO_MANY_MATCHES">
<code class="descname">ERROR_TOO_MANY_MATCHES</code><a class="headerlink" href="#c.ERROR_TOO_MANY_MATCHES" title="Permalink to this definition">¶</a></dt>
<dd><p>Too many matches for some string in your rules. This usually happens when
your rules contains very short or very common strings like <code class="docutils literal"><span class="pre">01</span> <span class="pre">02</span></code> or
<code class="docutils literal"><span class="pre">FF</span> <span class="pre">FF</span> <span class="pre">FF</span> <span class="pre">FF</span></code>. The limit is defined by <code class="docutils literal"><span class="pre">MAX_STRING_MATCHES</span></code> in
<em>./include/yara/limits.h</em></p>
</dd></dl>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">The C API</a><ul>
<li><a class="reference internal" href="#initializing-and-finalizing-libyara">Initializing and finalizing <em>libyara</em></a></li>
<li><a class="reference internal" href="#compiling-rules">Compiling rules</a></li>
<li><a class="reference internal" href="#saving-and-retrieving-compiled-rules">Saving and retrieving compiled rules</a></li>
<li><a class="reference internal" href="#scanning-data">Scanning data</a></li>
<li><a class="reference internal" href="#api-reference">API reference</a><ul>
<li><a class="reference internal" href="#data-structures">Data structures</a></li>
<li><a class="reference internal" href="#functions">Functions</a></li>
<li><a class="reference internal" href="#error-codes">Error codes</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="yarapython.html"
title="previous chapter">Using YARA from Python</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/capi.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<div><input type="text" name="q" /></div>
<div><input type="submit" value="Go" /></div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="yarapython.html" title="Using YARA from Python"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">yara 3.7.1 documentation</a> »</li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2014-2018, VirusTotal.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.6.6.
</div>
</body>
</html>
|