Skip to content

Commit 3c04e42

Browse files
authored
docs: documentation improvements (VirusTotal#582)
These commit fixes a few small typos, confusing sentences, and missing examples in the docs.
1 parent b024c80 commit 3c04e42

5 files changed

Lines changed: 47 additions & 32 deletions

File tree

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
# Please keep the list sorted.
1010

11+
Akamai Technologies
1112
Gen Digital Inc.
1213
Google Inc.
1314
Marek Milkovič <milkovic.marek@gmail.com>

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
# Please keep the list sorted.
2828

29+
Amanda Greene <agreene@akamai.com>
2930
Jacob Latonis <jlatonis@me.com>
3031
Marek Milkovič <milkovic.marek@gmail.com>;<marek.milkovic@gendigital.com>
3132
Tomáš Ďuriš <duristomas67@gmail.com>

site/content/docs/modules/math.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ Examples:
7373

7474
Returns the serial correlation for the given string.
7575

76+
Examples:
77+
78+
`math.serial_correlation("BCA")` &rarr; `-0.5`
79+
7680
### mean(offset, size)
7781

7882
Returns the mean for the size bytes starting at offset. When scanning a running
@@ -87,6 +91,10 @@ Examples:
8791

8892
Returns the mean for the given string.
8993

94+
Examples:
95+
96+
`math.mean("ABCABC")` &rarr; `66.0`
97+
9098
### deviation(offset, size, mean)
9199

92100
Returns the deviation from the mean for the size bytes starting at offset. When
@@ -111,7 +119,7 @@ comparisons are inclusive.
111119

112120
Examples:
113121

114-
`math.in_range(math.deviation(0, filesize, math.MEAN_BYTES), 63.9, 64,1)`
122+
`math.in_range(math.deviation(0, filesize, math.MEAN_BYTES), 63.9, 64.1)`
115123

116124
### max(int, int)
117125

@@ -185,7 +193,9 @@ Converts the given integer to a string. Note: integers in YARA are signed.
185193

186194
Examples:
187195

188-
`math.to_string(10) == "10" Example: math.to_string(-1) == "-1"`
196+
`math.to_string(10) == "10"`
197+
198+
`math.to_string(-1) == "-1"`
189199

190200
### to_string(int, base)
191201

site/content/docs/writing_rules/external_variables.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ seo:
1818
noindex: false # false (default) or true
1919
---
2020

21-
External variables enable rules to depend on dynamic values from external
22-
sources. For instance, consider the following rule:
21+
Rules can reference external variables that are defined at compile time.
22+
For instance, consider the following rule:
2323

24-
```
24+
```yara
2525
rule VariableExample1 {
2626
condition:
2727
ext_var == 10
2828
}
2929
```
3030

31-
Here, `ext_var` is an external variable whose value is determined at
32-
run-time. External variables can be integers, strings, or booleans, depending
33-
on their assigned value.
31+
Here, `ext_var` is an external variable that is defined when the rule is
32+
compiled with the `--define ext_var=VALUE` flag.
3433

35-
Integer variables can replace integer constants in conditions, while boolean
36-
variables can act as boolean expressions. For example:
34+
External variables can be integers, strings, or booleans. Integer variables can
35+
replace integer constants in conditions, while boolean variables can act as
36+
boolean expressions. For example:
3737

3838
```yara
3939
rule VariableExample2 {
@@ -42,6 +42,9 @@ rule VariableExample2 {
4242
}
4343
```
4444

45+
The above rule may be compiled with the flags
46+
`-d bool_ext_var=true -d int_ext_var=100` for example.
47+
4548
External variables of type `string` can be used with any operators that works
4649
on strings, like `contains`, `startswith`, `endswith`, etc. Let's see some
4750
examples:
@@ -73,12 +76,15 @@ rule MatchesExample {
7376
}
7477
```
7578

76-
Every external variable used in your rules must be defined when the rules
77-
are being compiled. This can be done using the `--define` option (or `-d`) in
79+
The rules above could be compiled with the flag `-d string_ext_var=\"Hello\"`
80+
for example.
81+
82+
Every external variable used in your rules must be defined at compile time.
83+
This can be done using the `--define VAR=VALUE` option (or `-d VAR=VALUE`) in
7884
the command-line tool, or by using the appropriate API.
79-
(like [this one](
85+
(Like [this one](
8086
https://docs.rs/yara-x/latest/yara_x/struct.Compiler.html#method.define_global)
8187
in Rust or
8288
[this one]({{< ref "python.md" >}}#define_globalidentifier-value)
83-
in Python).
89+
in Python.)
8490

site/content/docs/writing_rules/text_patterns.md

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,16 @@ rule WideCharTextExample2 {
8787
}
8888
```
8989

90-
The `ascii` modifier can appear alone, without an accompanying `wide` modifier,
91-
but it's not necessary to write it because in absence of `wide` the string is
92-
assumed to be ASCII by default.
90+
Using the `ascii` modifier without `wide` is allowed but unnecessary; strings
91+
without `wide` are assumed to be ASCII by default.
9392

9493
## "xor" modifier
9594

9695
The `xor` modifier can be used to search for strings that are XORed with a
9796
single byte.
9897

99-
The following rule will search for every single byte XOR applied to the string "
100-
This program cannot" (including the plaintext string):
98+
The following rule will search for every single byte XOR applied to the string
99+
"This program cannot" (including the plaintext string):
101100

102101
```yara
103102
rule XorExample1 {
@@ -210,15 +209,13 @@ RoaXMgcHJvZ3JhbSBjYW5ub3
210209
UaGlzIHByb2dyYW0gY2Fubm90
211210
```
212211

213-
The `base64wide` modifier works just like the `base64` modifier but the results
214-
of the `base64` modifier are converted to wide.
212+
The `base64wide` modifier converts the results of the `base64` modifier to
213+
`wide` format.
215214

216-
The interaction between `base64` (or `base64wide`) and `wide` and `ascii` is as
217-
you might expect. `wide` and `ascii` are applied to the string first, and then
218-
the `base64` and `base64wide` modifiers are applied. At no point is the
219-
plaintext of the `ascii` or `wide` versions of the strings included in the
220-
search. If you want to also include those you can put them in a secondary
221-
pattern.
215+
First, `wide` and `ascii` are applied to the string, then the `base64` and
216+
`base64wide` modifiers are applied. The plaintext versions of the `ascii` or
217+
`wide` strings are never included in the search. If you want to include
218+
the plaintext string, put it in a second pattern.
222219

223220
The `base64` and `base64wide` modifiers also support a custom alphabet. For
224221
example:
@@ -234,11 +231,11 @@ rule Base64Example2 {
234231

235232
The alphabet must be 64 bytes long.
236233

237-
The `base64` and `base64wide` modifiers are only supported for text patterns
238-
that are at least 3 bytes long. Using these modifiers with a hex patterns,
239-
regular expression, or text patterns that are too short, will cause a compiler
240-
error. Also, the `xor`, `fullword`, and `nocase` modifiers used in combination
241-
with `base64` or `base64wide` will cause a compiler error.
234+
The `base64` and `base64wide` modifiers are only supported for patterns that
235+
are at least 3 bytes long. Using these modifiers with a hex pattern, regular
236+
expression, or text pattern that is too short will cause a compiler error. Also,
237+
the `xor`, `fullword`, and `nocase` modifiers used in combination with `base64`
238+
or `base64wide` will cause a compiler error.
242239

243240
{{< callout title="Incompatibility notice">}}
244241

0 commit comments

Comments
 (0)