Skip to content

Commit

Permalink
docs: some additions to the documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
plusvic committed May 14, 2024
1 parent d39aa57 commit 1a902ea
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
24 changes: 23 additions & 1 deletion site/content/docs/api/c.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,33 @@ rules in text form and compile them into a [YRX_RULES](#yrx_rules) object.

```c
enum YRX_RESULT yrx_compiler_create(
uint32_t flags,
struct YRX_COMPILER **compiler);
```
Creates a new compiler. It must be destroyed
with [yrx_compiler_destroy](#yrx_compiler_destroy).
with [yrx_compiler_destroy](#yrx_compiler_destroy). The `flags` argument can be
0, or any
combination of the following flags:
* YRX_COLORIZE_ERRORS
Add colors to error messages.
* YRX_RELAXED_RE_ESCAPE_SEQUENCES
Historically, YARA has accepted any character preceded by a backslash in a
regular expression, regardless of whether the sequence is valid. For example,
`\n`, `\t`, and `\w` are valid escape sequences in a regexp, but `\N`, `\T`,
and `\j` are not. YARA accepts all of these sequences. Valid escape
sequences are interpreted according to their special meaning (`\n` as a
new-line, `\w` as a word character, etc.), while invalid escape sequences are
interpreted simply as the character that appears after the backslash. Thus,
`\N` becomes `N`, and `\j` becomes `j`.
When this flag is set, YARA-X exhibits the same behaviour as YARA and accepts
these invalid escape sequences. By default, invalid escape sequences produce
an error in YARA-X.
#### yrx_compiler_destroy
Expand Down
22 changes: 22 additions & 0 deletions site/content/docs/api/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,28 @@ rules = yara_x.compile("rule test { condition: true }")
Type that represents a YARA-X compiler. It takes one or more sets of YARA
rules in text form and compile them into a [Rules](#rules) object.

#### .__init__(relaxed_re_escape_sequences=False)

Compiler constructor. The `relaxed_re_escape_sequences` determines whether
the compiler accepts invalid escape sequences in regular expressions.

Historically, YARA has accepted any character preceded by a backslash in a
regular expression, regardless of whether the sequence is valid. For example,
`\n`, `\t` and `\w` are valid escape sequences in a regexp, but `\N`, `\T` and
`\j` are not. YARA accepts all of these sequences. Valid escape sequences are
interpreted according to their special meaning (`\n` as a new-line, `\w` as a
word character, etc.), while invalid escape sequences are interpreted simply as
the character that appears after the backslash. Thus, `\N` becomes `N`, and `\j`
becomes `j`. By setting `relaxed_re_escape_sequences` to `True` the compiler
behaves as the YARA compiler and accepts these invalid escape sequences.

###### Example

```python
compiler = yara_x.Compiler(relaxed_re_escape_sequences=True)
compiler.add_source("rule test { $a = /\Release/ condition: $a }")
```

#### .add_source(string)

Adds some YARA source code to be compiled. Raises an exception if the source
Expand Down

0 comments on commit 1a902ea

Please sign in to comment.