Skip to content

Commit 5f8d3d5

Browse files
committed
docs: more improvements to documentation
1 parent 7c4e6be commit 5f8d3d5

File tree

17 files changed

+235
-21
lines changed

17 files changed

+235
-21
lines changed

site/content/blog/introducing-yara-x/index.md

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

21-
For over 15 years, YARA has been growing and evolving until it became
22-
an indispensable tool in every malware researcher's toolbox. Throughout this
23-
time YARA has seen numerous updates, with new features added and countless bugs
24-
fixed. But today, I'm excited to announce the biggest change yet: a complete
25-
rewrite.
21+
For over 15 years, [YARA](https://github.com/VirusTotal/yara) has been growing
22+
and evolving until it became an indispensable tool in every malware researcher's
23+
toolbox. Throughout this time YARA has seen numerous updates, with new features
24+
added and countless bugs fixed. But today, I'm excited to announce the biggest
25+
change yet: a full rewrite.
2626

27-
YARA-X is a completely new implementation of YARA, and it has the following
28-
goals:
27+
YARA-X is a completely new implementation of YARA in Rust, and it has the
28+
following goals:
2929

3030
* **Better user experience**: The new command-line interface is more modern and
3131
colorful, and error reports are now more explicative. More features aimed at

site/content/docs/api/_index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ menu:
1111
identifier: "apis"
1212
weight: 500
1313
toc: true
14+
sidebar:
15+
collapsed: true
1416
seo:
1517
title: "" # custom title (optional)
1618
description: "" # custom description (recommended)

site/content/docs/intro/_index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ menu:
1111
identifier: "intro"
1212
weight: 100
1313
toc: true
14+
sidebar:
15+
collapsed: true
1416
seo:
1517
title: "" # custom title (optional)
1618
description: "" # custom description (recommended)

site/content/docs/intro/yara_vs_yara-x.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,14 @@ its YARA counterpart:
4646

4747
* Colorful output, enhancing readability if the terminal supports it.
4848
* More information about the files being scanned.
49-
* Autocompletion support for multiple shells, including bash, zsh, and
50-
powershell, improving usability and efficiency during command entry.
49+
* Autocompletion support for multiple shells, including Bash, Zsh, and
50+
PowerShell, improving usability and efficiency during command entry.
5151
* Access to the output of YARA modules in YAML and JSON formats without
5252
requiring any YARA rule. This capability transforms YARA-X into a versatile
53-
file dissection tool supporting multiple file formats (PE, ELF, Mach-O, LNK).
53+
file dissection tool supporting multiple file formats, like
54+
[PE](https://en.wikipedia.org/wiki/Portable_Executable), [ELF](https://en.wikipedia.org/wiki/Executable_and_Linkable_Format),
55+
[Mach-O](https://en.wikipedia.org/wiki/Mach-O)
56+
and LNK (Windows link file).
5457

5558
### Higher overall performance
5659

site/content/docs/modules/console.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ rule example {
3434
}
3535
```
3636

37+
-------
38+
3739
## Functions
3840

3941
### log(string)

site/content/docs/modules/dotnet.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ rule BlopStream {
4343
}
4444
```
4545

46+
-------
47+
4648
## Module structure
4749

4850
| Field | Type |

site/content/docs/modules/elf.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ rule elf_64 {
3737
}
3838
```
3939

40+
-------
41+
4042
## Functions
4143

4244
### import_md5()
@@ -65,6 +67,8 @@ rule FindByTelfhash {
6567
}
6668
```
6769

70+
-------
71+
6872
## Module structure
6973

7074
| Field | Type |

site/content/docs/modules/hash.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ The `hash` module allows you to calculate hashes (MD5, SHA1, SHA256) and
2222
checksums from portions of your file and create signatures based on those
2323
hashes.
2424

25+
-------
26+
2527
## Functions
2628

2729
{{< callout context="caution" title="Important">}}

site/content/docs/modules/lnk.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ seo:
2121
The `lnk` module parses Windows Link files (.lnk), and exposes metadata
2222
contained in those files to YARA.
2323

24+
-------
25+
2426
## Module structure
2527

2628
| Field | Type | Description |

site/content/docs/modules/macho.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ seo:
1919
---
2020

2121
The `macho` module is very similar to the [pe]({{< ref "pe.md" >}}) module, but
22-
for [Match-O](https://en.wikipedia.org/wiki/Mach-O) files. This module exposes
23-
most of the fields present in a Mach-O file header. Let's see some examples:
22+
for [Mach-O](https://en.wikipedia.org/wiki/Mach-O) files. This module exposes
23+
most of the fields present in a Mach-O file header.
24+
25+
-------
2426

2527
### Module structure
2628

site/content/docs/modules/math.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ seo:
2121
The `math` module allows you to calculate certain values from portions of your
2222
file and create signatures based on those results.
2323

24+
-------
25+
2426
## Functions
2527

2628
### entropy(offset, size)

site/content/docs/modules/pe.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,98 @@ rule is_pe {
4848
}
4949
```
5050

51+
-------
52+
5153
## Functions
5254

55+
### exports(fn_name)
56+
57+
Returns true if the PE exports a function with the given name, or false
58+
otherwise.
59+
60+
### exports(fn_regex)
61+
62+
Returns true if the PE exports a function whose name matches the given regular
63+
expression, or false otherwise.
64+
65+
### exports(ordinal)
66+
67+
Returns true if the PE exports a function with the given ordinal, or false if
68+
otherwise.
69+
70+
### exports_index(fn_name)
71+
72+
Returns the index into the `export_details` array for the first exported
73+
function that matches the given name. The result is `undefined` if no
74+
function with such a name exists.
75+
76+
### exports_index(fn_regex)
77+
78+
Returns the index into the `export_details` array for the first exported
79+
function that matches the given regular expression. The result is `undefined` if
80+
none of the functions matches.
81+
82+
### exports_index(ordinal)
83+
84+
Returns the index into the `export_details` array for the first exported
85+
function that has the given ordinal number. The result is `undefined` if no
86+
function exists with such an ordinal exists.
87+
88+
### imports(dll_name)
89+
90+
Returns the number of functions that the PE imports from the given DLL. The
91+
DLL name is case-insensitive.
92+
93+
### imports(dll_name, fn_name)
94+
95+
Returns true if the PE imports the given function from the given DLL. The DLL
96+
name is case-insensitive, but the function name is case-sensitive.
97+
98+
### imports(dll_name, ordinal)
99+
100+
Returns true if the PE imports the given function by ordinal from the given DLL.
101+
The DLL name is case-insensitive.
102+
103+
### imports(dll_regex, fn_regex)
104+
105+
Returns the number of functions imported by the PE where the DLL name matches
106+
`dll_regexp` and the function name matches `fn_regexp`. Both arguments are
107+
case-sensitive, unless you use the `/i` modifier in the regexp.
108+
109+
###### Example
110+
111+
```
112+
import "pe"
113+
114+
rule ProcessMemory {
115+
condition:
116+
pe.imports(/kernel32.dll/i, /(Read|Write)ProcessMemory/) > 0
117+
}
118+
```
119+
120+
### imports(type, dll_name, fn_name)
121+
122+
Returns true if the PE imports `fn_name` from `dll_name`. The DLL
123+
name is case-insensitive. `type` allows to specify the kind of imports should be
124+
taken into account, the allowed values are:
125+
126+
| | |
127+
|----------------------|-----------------------------------|
128+
| `pe.IMPORT_STANDARD` | Standard imports only |
129+
| `pe.IMPORT_DELAYED` | Delayed imports only |
130+
| `pe.IMPORT_ANY` | Both standard and delayed imports |
131+
132+
###### Example
133+
134+
```
135+
import "pe"
136+
137+
rule ProcessMemory {
138+
condition:
139+
pe.imports(pe.IMPORT_DELAYED, "kernel32.dll", "WriteProcessMemory")
140+
}
141+
```
142+
53143
### is_32bit()
54144

55145
Returns true if the file is a 32-bit PE.
@@ -106,6 +196,30 @@ The returned hash string is always in lowercase.
106196

107197
{{< /callout >}}
108198

199+
### rich_signature.version(version, [toolid])
200+
201+
The PE rich signature contains information about the tools involved in the
202+
creation of the PE file. This function returns the number of tools that
203+
matches the given version and toolid, where toolid is optional.
204+
205+
###### Example
206+
207+
```
208+
import "pe"
209+
210+
rule WrongChecksum {
211+
condition:
212+
pe.rich_signature.version(24215, 261) == 61
213+
}
214+
```
215+
216+
### rich_signature.toolid(toolid, [version])
217+
218+
This function is similar to `rich_signature.version`, but the toolid argument
219+
is required while version is optional.
220+
221+
------
222+
109223
## Module structure
110224

111225
| Field | Type | Description |

site/content/docs/modules/string.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ seo:
2121

2222
The `string` module implements string utility functions.
2323

24+
-------
25+
2426
## Functions
2527

2628
### to_int(string)

site/content/docs/modules/time.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ seo:
2020

2121
The `time` module implements time utility functions.
2222

23+
-------
24+
2325
## Functions
2426

2527
### now()

site/content/docs/writing_rules/differences.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ menu:
99
docs:
1010
parent: ""
1111
identifier: "differences"
12-
weight: 280
12+
weight: 290
1313
toc: true
1414
seo:
1515
title: "" # custom title (optional)

site/content/docs/writing_rules/syntax.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ rule example {
3030
```
3131

3232
Each rule in YARA starts with the keyword `rule` followed by a rule identifier.
33-
Rules are generally composed of two sections: pattern definitions and condition.
34-
The pattern definition section is optional, and it can be omitted if the rule
35-
doesn't rely on any patterns (as in the first example), but the condition
36-
section is always required. The pattern definition section is where the patterns
37-
that will be part of the rule are defined. Patterns can be defined as plain
38-
text, raw bytes, or regular expressions, as shown in the following, more
39-
realistic, example:
33+
Rules are generally composed of two sections: patterns (a.k.a. strings)
34+
and condition. The pattern definition section is optional, and it
35+
can be omitted if the rule doesn't rely on any patterns (as in the first
36+
example), but the condition section is always required. The pattern definition
37+
section is where the patterns that will be part of the rule are defined.
38+
Patterns can be defined as plain text, raw bytes, or regular expressions, as
39+
shown in the following, more realistic, example:
4040

4141
```yara
4242
rule ExampleRule {
@@ -81,7 +81,7 @@ rule MetadataExample {
8181
```
8282

8383
As shown in the example, metadata identifiers are followed by an equal sign and
84-
the value assigned to them. Values can be strings (valid UTF8 only), integers,
84+
the value assigned to them. Values can be strings (valid UTF-8 only), integers,
8585
or one of the boolean values `true` or `false`.
8686

8787
Note that identifier/value pairs defined in the metadata section cannot be used
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
title: "Undefined values"
3+
description: "Explains what are undefined values in YARA"
4+
summary: ""
5+
date: 2023-09-07T16:13:18+02:00
6+
lastmod: 2023-09-07T16:13:18+02:00
7+
draft: false
8+
menu:
9+
docs:
10+
parent: ""
11+
identifier: "undefined"
12+
weight: 280
13+
toc: true
14+
seo:
15+
title: "" # custom title (optional)
16+
description: "" # custom description (recommended)
17+
canonical: "" # custom canonical URL (optional)
18+
noindex: false # false (default) or true
19+
---
20+
21+
Modules often leave variables in an undefined state, for example when the
22+
variable doesn't make sense in the current context (think of `pe.entry_point`
23+
while scanning a non-PE file). YARA handles undefined values in a way that
24+
allows the rule to keep its meaningfulness. Take a look at this rule:
25+
26+
```yara
27+
import "pe"
28+
29+
rule Test {
30+
strings:
31+
$a = "some string"
32+
condition:
33+
$a and pe.entry_point == 0x1000
34+
}
35+
```
36+
37+
If the scanned file isn't a PE file, this rule won't match even if "some string"
38+
is present because both conditions (the string's presence and the correct entry
39+
point) must be met. However, consider the `or` case:
40+
41+
```
42+
$a or pe.entry_point == 0x1000
43+
```
44+
45+
You would expect the rule to match if the file contains the string, even if it
46+
isn't a PE file. That's exactly how YARA behaves. The logic is as follows:
47+
48+
If the expression in the condition is `undefined`, it would be translated
49+
to `false` and the rule won't match.
50+
51+
Boolean operators `and` and `or` will treat `undefined` operands as `false`,
52+
Which means that:
53+
54+
* `undefined` and `true` is `false`
55+
* `undefined` and `false` is `false`
56+
* `undefined` or `true` is `true`
57+
* `undefined` or `false` is `false`
58+
59+
All the remaining operators, including the `not` operator, return `undefined` if
60+
any of their operands is `undefined`.
61+
62+
In the expression above, `pe.entry_point == 0x1000` will be undefined for non-PE
63+
files, because `pe.entry_point` is undefined for those files. This implies that
64+
`$a or pe.entry_point == 0x1000` will be `true` if and only if `$a` is `true`.
65+
66+
If the condition was `pe.entry_point == 0x1000` alone, it evaluates to `false`
67+
for non-PE files, and so will do `pe.entry_point != 0x1000` and `not
68+
pe.entry_point == 0x1000`, as none of these expressions make sense for non-PE
69+
files.
70+
71+
To check if some expression is defined use unary operator `defined`. Example:
72+
73+
`defined pe.entry_point`

0 commit comments

Comments
 (0)