yara-x 1.8.0__pp311-pypy311_pp73-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of yara-x might be problematic. Click here for more details.

yara_x/__init__.py ADDED
@@ -0,0 +1,5 @@
1
+ from .yara_x import *
2
+
3
+ __doc__ = yara_x.__doc__
4
+ if hasattr(yara_x, "__all__"):
5
+ __all__ = yara_x.__all__
yara_x/__init__.pyi ADDED
@@ -0,0 +1,436 @@
1
+ import collections
2
+
3
+ from typing import Any, Dict, BinaryIO, TextIO, Optional, Tuple, final
4
+
5
+ class CompileError(Exception):
6
+ r"""
7
+ Error occurred while compiling rules.
8
+ """
9
+
10
+ class ScanError(Exception):
11
+ r"""
12
+ Error occurred during a scan operation.
13
+ """
14
+
15
+ class TimeoutError(Exception):
16
+ r"""
17
+ Error indicating that a timeout occurred during a scan operation.
18
+ """
19
+
20
+ @final
21
+ class Compiler:
22
+ r"""
23
+ Compiles YARA source code producing a set of compiled [`Rules`].
24
+ """
25
+ def __new__(
26
+ cls,
27
+ relaxed_re_syntax: bool = False,
28
+ error_on_slow_pattern: bool = False,
29
+ includes_enabled: bool = True,
30
+ ) -> Compiler:
31
+ r"""
32
+ Creates a new [`Compiler`].
33
+
34
+ The `relaxed_re_syntax` argument controls whether the compiler should
35
+ adopt a more relaxed syntax check for regular expressions, allowing
36
+ constructs that YARA-X doesn't accept by default.
37
+
38
+ YARA-X enforces stricter regular expression syntax compared to YARA.
39
+ For instance, YARA accepts invalid escape sequences and treats them
40
+ as literal characters (e.g., \R is interpreted as a literal 'R'). It
41
+ also allows some special characters to appear unescaped, inferring
42
+ their meaning from the context (e.g., `{` and `}` in `/foo{}bar/` are
43
+ literal, but in `/foo{0,1}bar/` they form the repetition operator
44
+ `{0,1}`).
45
+
46
+ The `error_on_slow_pattern` argument tells the compiler to treat slow
47
+ patterns as errors, instead of warnings.
48
+
49
+ The `includes_enabled` argument controls whether the compiler should
50
+ enable or disable the inclusion of files with the `include` directive.
51
+ """
52
+ ...
53
+
54
+ def add_source(self, src: str, origin: Optional[str] = None) -> None:
55
+ r"""
56
+ Adds a YARA source code to be compiled.
57
+
58
+ This function may be invoked multiple times to add several sets of YARA
59
+ rules before calling [`Compiler::build`]. If the rules provided in
60
+ `src` contain errors that prevent compilation, the function will raise
61
+ an exception with the first error encountered. Additionally, the
62
+ compiler will store this error, along with any others discovered during
63
+ compilation, which can be accessed using [`Compiler::errors`].
64
+
65
+ Even if a previous invocation resulted in a compilation error, you can
66
+ continue calling this function. In such cases, any rules that failed to
67
+ compile will not be included in the final compiled set.
68
+
69
+ The optional parameter `origin` allows to specify the origin of the
70
+ source code. This usually receives the path of the file from where the
71
+ code was read, but it can be any arbitrary string that conveys information
72
+ about the source code's origin.
73
+ """
74
+ ...
75
+
76
+ def add_include_dir(self, dir: str) -> None:
77
+ r"""
78
+ Adds a directory to the list of directories where the compiler should
79
+ look for included files.
80
+ """
81
+ ...
82
+
83
+ def enable_includes(self, yes: bool) -> None:
84
+ r"""
85
+ Enables or disables the inclusion of files with the `include` directive.
86
+ """
87
+ ...
88
+
89
+ def define_global(self, ident: str, value: Any) -> None:
90
+ r"""
91
+ Defines a global variable and sets its initial value.
92
+
93
+ Global variables must be defined before calling [`Compiler::add_source`]
94
+ with some YARA rule that uses the variable. The variable will retain its
95
+ initial value when the [`Rules`] are used for scanning data, however
96
+ each scanner can change the variable's value by calling
97
+ [`crate::Scanner::set_global`].
98
+
99
+ The type of `value` must be: bool, str, bytes, int or float.
100
+
101
+ # Raises
102
+
103
+ [TypeError](https://docs.python.org/3/library/exceptions.html#TypeError)
104
+ if the type of `value` is not one of the supported ones.
105
+ """
106
+ ...
107
+
108
+ def new_namespace(self, namespace: str) -> None:
109
+ r"""
110
+ Creates a new namespace.
111
+
112
+ Further calls to [`Compiler::add_source`] will put the rules under the
113
+ newly created namespace.
114
+ """
115
+ ...
116
+
117
+ def ignore_module(self, module: str) -> None:
118
+ r"""
119
+ Tell the compiler that a YARA module is not supported.
120
+
121
+ Import statements for unsupported modules will be ignored without
122
+ errors, but a warning will be issued. Any rule that make use of an
123
+ ignored module will be ignored, while the rest of rules that
124
+ don't rely on that module will be correctly compiled.
125
+ """
126
+ ...
127
+
128
+ def build(self) -> Rules:
129
+ r"""
130
+ Builds the source code previously added to the compiler.
131
+
132
+ This function returns an instance of [`Rules`] containing all the rules
133
+ previously added with [`Compiler::add_source`] and sets the compiler
134
+ to its initial empty state.
135
+ """
136
+ ...
137
+
138
+ def errors(self) -> Any:
139
+ r"""
140
+ Retrieves all errors generated by the compiler.
141
+
142
+ This method returns every error encountered during the compilation,
143
+ across all invocations of [`Compiler::add_source`].
144
+ """
145
+ ...
146
+
147
+ def warnings(self) -> Any:
148
+ r"""
149
+ Retrieves all warnings generated by the compiler.
150
+
151
+ This method returns every warning encountered during the compilation,
152
+ across all invocations of [`Compiler::add_source`].
153
+ """
154
+ ...
155
+
156
+ def rule_name_regexp(self, regexp: str) -> None:
157
+ r"""
158
+ Tell the compiler that any rule must match this regular expression or it
159
+ will result in a compiler warning.
160
+
161
+ # Raises
162
+
163
+ [ValueError](https://docs.python.org/3/library/exceptions.html#ValueError)
164
+ if the regular expression is invalid.
165
+ """
166
+ ...
167
+
168
+ @final
169
+ class Scanner:
170
+ r"""
171
+ Scans data with already compiled YARA rules.
172
+
173
+ The scanner receives a set of compiled [`Rules`] and scans data with those
174
+ rules. The same scanner can be used for scanning multiple files or in-memory
175
+ data sequentially, but you need multiple scanners for scanning in parallel.
176
+ """
177
+
178
+ def __new__(cls, rules: Rules) -> Scanner:
179
+ r"""
180
+ Creates a new [`Scanner`] with a given set of [`Rules`].
181
+ """
182
+ ...
183
+
184
+ def scan(self, data: bytes) -> ScanResults:
185
+ r"""
186
+ Scans in-memory data.
187
+ """
188
+ ...
189
+
190
+ def scan_file(self, path: str) -> ScanResults:
191
+ r"""
192
+ Scans a file
193
+ """
194
+ ...
195
+
196
+ def set_global(self, ident: str, value: Any) -> None:
197
+ r"""
198
+ Sets the value of a global variable.
199
+
200
+ The variable must has been previously defined by calling
201
+ [`Compiler::define_global`], and the type it has during the definition
202
+ must match the type of the new value.
203
+
204
+ The variable will retain the new value in subsequent scans, unless this
205
+ function is called again for setting a new value.
206
+
207
+ The type of `value` must be: `bool`, `str`, `bytes`, `int` or `float`.
208
+
209
+ # Raises
210
+
211
+ [TypeError](https://docs.python.org/3/library/exceptions.html#TypeError)
212
+ if the type of `value` is not one of the supported ones.
213
+ """
214
+ ...
215
+
216
+ def set_timeout(self, seconds: int) -> None:
217
+ r"""
218
+ Sets a timeout for each scan.
219
+
220
+ After setting a timeout scans will abort after the specified `seconds`.
221
+ """
222
+ ...
223
+
224
+ def max_matches_per_pattern(self, matches: int) -> None:
225
+ r"""
226
+ Sets the maximum number of matches per pattern.
227
+
228
+ When some pattern reaches the specified number of `matches` it won't produce more matches.
229
+ """
230
+ ...
231
+
232
+ def console_log(self, callback: collections.abc.Callable[[str], Any]) -> None:
233
+ r"""
234
+ Sets a callback that is invoked every time a YARA rule calls the
235
+ `console` module.
236
+
237
+ The `callback` function is invoked with a string representing the
238
+ message being logged. The function can print the message to stdout,
239
+ append it to a file, etc. If no callback is set these messages are
240
+ ignored.
241
+ """
242
+ ...
243
+
244
+ @final
245
+ class Formatter:
246
+ r"""
247
+ Formats YARA rules.
248
+ """
249
+ def __new__(
250
+ cls,
251
+ align_metadata: bool = True,
252
+ align_patterns: bool = True,
253
+ indent_section_headers: bool = True,
254
+ indent_section_contents: bool = True,
255
+ indent_spaces: int = 2,
256
+ newline_before_curly_brace: bool = False,
257
+ empty_line_before_section_header: bool = True,
258
+ empty_line_after_section_header: bool = False,
259
+ ) -> Formatter:
260
+ r"""
261
+ Creates a new [`Formatter`].
262
+
263
+ `align_metadata` allows for aligning the equals signs in metadata definitions.
264
+ `align_patterns` allows for aligning the equals signs in pattern definitions.
265
+ `indent_section_headers` allows for indenting section headers.
266
+ `indent_section_contents` allows for indenting section contents.
267
+ `indent_spaces` is the number of spaces to use for indentation.
268
+ `newline_before_curly_brace` controls whether a newline is inserted before a curly brace.
269
+ `empty_line_before_section_header` controls whether an empty line is inserted before a section header.
270
+ `empty_line_after_section_header` controls whether an empty line is inserted after a section header.
271
+ """
272
+ ...
273
+
274
+ def format(self, input: TextIO, output: TextIO) -> None:
275
+ r"""
276
+ Format a YARA rule
277
+ """
278
+ ...
279
+
280
+ @final
281
+ class Match:
282
+ r"""
283
+ Represents a match found for a pattern.
284
+ """
285
+ @property
286
+ def offset(self) -> int:
287
+ r"""
288
+ Offset where the match occurred.
289
+ """
290
+ ...
291
+
292
+ @property
293
+ def length(self) -> int:
294
+ r"""
295
+ Length of the match in bytes.
296
+ """
297
+ ...
298
+
299
+ @property
300
+ def xor_key(self) -> Optional[int]:
301
+ r"""
302
+ XOR key used for decrypting the data if the pattern had the xor
303
+ modifier, or None if otherwise.
304
+ """
305
+ ...
306
+
307
+ @final
308
+ class Pattern:
309
+ r"""
310
+ Represents a pattern in a YARA rule.
311
+ """
312
+
313
+ @property
314
+ def identifier(self) -> str:
315
+ r"""
316
+ Pattern identifier (e.g: '$a', '$foo').
317
+ """
318
+ ...
319
+
320
+ @property
321
+ def matches(self) -> tuple:
322
+ r"""
323
+ Matches found for this pattern.
324
+ """
325
+ ...
326
+
327
+ @final
328
+ class Rule:
329
+ r"""
330
+ Represents a rule that matched while scanning some data.
331
+ """
332
+
333
+ @property
334
+ def identifier(self) -> str:
335
+ r"""
336
+ Returns the rule's name.
337
+ """
338
+ ...
339
+
340
+ @property
341
+ def namespace(self) -> str:
342
+ r"""
343
+ Returns the rule's namespace.
344
+ """
345
+ ...
346
+
347
+ @property
348
+ def tags(self) -> tuple:
349
+ r"""
350
+ Returns the rule's tags.
351
+ """
352
+ ...
353
+
354
+ @property
355
+ def metadata(self) -> tuple:
356
+ r"""
357
+ A tuple of pairs `(identifier, value)` with the metadata associated to
358
+ the rule.
359
+ """
360
+ ...
361
+
362
+ @property
363
+ def patterns(self) -> tuple:
364
+ r"""
365
+ Patterns defined by the rule.
366
+ """
367
+ ...
368
+
369
+ @final
370
+ class Rules:
371
+ r"""
372
+ A set of YARA rules in compiled form.
373
+
374
+ This is the result of [`Compiler::build`].
375
+ """
376
+
377
+ def __iter__(self) -> collections.abc.Iterator[Rule]:
378
+ ...
379
+
380
+ def scan(self, data: bytes) -> ScanResults:
381
+ r"""
382
+ Scans in-memory data with these rules.
383
+ """
384
+ ...
385
+
386
+ def serialize_into(self, file: BinaryIO) -> None:
387
+ r"""
388
+ Serializes the rules into a file-like object.
389
+ """
390
+ ...
391
+
392
+ @staticmethod
393
+ def deserialize_from(file: BinaryIO) -> Rules:
394
+ r"""
395
+ Deserializes rules from a file-like object.
396
+ """
397
+ ...
398
+
399
+ @final
400
+ class ScanResults:
401
+ r"""
402
+ Results produced by a scan operation.
403
+ """
404
+
405
+ @property
406
+ def matching_rules(self) -> Tuple[Rule, ...]:
407
+ r"""
408
+ Rules that matched during the scan.
409
+ """
410
+ ...
411
+
412
+ @property
413
+ def module_outputs(self) -> Dict[str, Any]:
414
+ r"""
415
+ Module output from the scan.
416
+ """
417
+ ...
418
+
419
+ def compile(src: str) -> Rules:
420
+ r"""
421
+ Compiles a YARA source code producing a set of compiled [`Rules`].
422
+
423
+ This function allows compiling simple rules that don't depend on external
424
+ variables. For more complex use cases you will need to use a [`Compiler`].
425
+ """
426
+ ...
427
+
428
+ @final
429
+ class Module:
430
+ r"""A YARA-X module."""
431
+ def __new__(cls, name: str) -> Module:
432
+ r"""Creates a new [`Module`] with the given name, which must be a valid YARA-X module name."""
433
+ ...
434
+ def invoke(self, data: str) -> Any:
435
+ r"""Parse the data and collect module metadata."""
436
+ ...
yara_x/py.typed ADDED
File without changes
Binary file
@@ -0,0 +1,46 @@
1
+ Metadata-Version: 2.4
2
+ Name: yara-x
3
+ Version: 1.8.0
4
+ Classifier: Programming Language :: Rust
5
+ Classifier: Programming Language :: Python :: Implementation :: CPython
6
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
7
+ Classifier: License :: OSI Approved :: BSD License
8
+ Summary: Python bindings for YARA-X
9
+ Keywords: pattern-matching,cybersecurity,forensics,malware,yara
10
+ Home-Page: https://virustotal.github.io/yara-x
11
+ Requires-Python: >=3.9
12
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
13
+ Project-URL: homepage, https://virustotal.github.io/yara-x
14
+ Project-URL: repository, https://github.com/VirusTotal/yara-x.git
15
+
16
+ ![PyPI - Version](https://img.shields.io/pypi/v/yara-x)
17
+ ![PyPI - License](https://img.shields.io/pypi/l/yara-x)
18
+ [![Documentation](https://img.shields.io/badge/doc-latest-blue.svg)](https://virustotal.github.io/yara-x/docs/api/python)
19
+ [![Downloads](https://pepy.tech/badge/yara-x)](https://pepy.tech/project/yara-x)
20
+ [![Downloads per week](https://pepy.tech/badge/yara-x/week)](https://pepy.tech/project/yara-x)
21
+ ![GitHub Repo stars](https://img.shields.io/github/stars/VirusTotal/yara-x)
22
+
23
+ The official Python library for [YARA-X](https://virustotal.github.io/yara-x).
24
+ Supports Python 3.9+ in Linux, MacOS and Windows.
25
+
26
+ ```python
27
+ import yara_x
28
+
29
+ rules = yara_x.compile('''
30
+ rule test {
31
+ strings:
32
+ $a = "foobar"
33
+ condition:
34
+ $a
35
+ }''')
36
+
37
+ results = rules.scan(b"foobar")
38
+
39
+ assert results.matching_rules[0].identifier == "test"
40
+ assert results.matching_rules[0].patterns[0].identifier == "$a"
41
+ assert results.matching_rules[0].patterns[0].matches[0].offset == 0
42
+ assert results.matching_rules[0].patterns[0].matches[0].length == 6
43
+ ```
44
+
45
+ For more information about how to use this library, please check
46
+ the [documentation](https://virustotal.github.io/yara-x/docs/api/python).
@@ -0,0 +1,7 @@
1
+ yara_x-1.8.0.dist-info/METADATA,sha256=wCzr4J-65wBP54iDA5xjwb9Q6iga0IGZ5stdhjms5wg,1861
2
+ yara_x-1.8.0.dist-info/WHEEL,sha256=sntf-nTtS3w_Jnm8p7KnTSiypYqLguH2JN4tcVpya64,103
3
+ yara_x/__init__.py,sha256=nMyCIYe2XAcE0xoh-kWfMlEZjVx9_cnT6O6Iaxh9JoM,107
4
+ yara_x/__init__.pyi,sha256=SFaI6UOt-aysXitemSe8mKGhPowhZ_w8tPL88efSGQw,13232
5
+ yara_x/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ yara_x/yara_x.pypy311-pp73-win_amd64.pyd,sha256=BF3hwZF07t_Y27f4XlrBprgNpmg0IHX-LnYXT8dum8Y,24235520
7
+ yara_x-1.8.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.9.5)
3
+ Root-Is-Purelib: false
4
+ Tag: pp311-pypy311_pp73-win_amd64