yara-x 1.5.0__cp38-abi3-macosx_14_0_arm64.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.

Binary file
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,385 @@
1
+ import typing
2
+ import collections
3
+
4
+ class Compiler:
5
+ r"""
6
+ Compiles YARA source code producing a set of compiled [`Rules`].
7
+ """
8
+ def __new__(
9
+ cls,
10
+ relaxed_re_syntax: bool = False,
11
+ error_on_slow_pattern: bool = False,
12
+ includes_enabled: bool = True,
13
+ ) -> Compiler:
14
+ r"""
15
+ Creates a new [`Compiler`].
16
+
17
+ The `relaxed_re_syntax` argument controls whether the compiler should
18
+ adopt a more relaxed syntax check for regular expressions, allowing
19
+ constructs that YARA-X doesn't accept by default.
20
+
21
+ YARA-X enforces stricter regular expression syntax compared to YARA.
22
+ For instance, YARA accepts invalid escape sequences and treats them
23
+ as literal characters (e.g., \R is interpreted as a literal 'R'). It
24
+ also allows some special characters to appear unescaped, inferring
25
+ their meaning from the context (e.g., `{` and `}` in `/foo{}bar/` are
26
+ literal, but in `/foo{0,1}bar/` they form the repetition operator
27
+ `{0,1}`).
28
+
29
+ The `error_on_slow_pattern` argument tells the compiler to treat slow
30
+ patterns as errors, instead of warnings.
31
+
32
+ The `includes_enabled` argument controls whether the compiler should
33
+ enable or disable the inclusion of files with the `include` directive.
34
+ """
35
+ ...
36
+
37
+ def add_source(self, src: str, origin: typing.Optional[str]) -> None:
38
+ r"""
39
+ Adds a YARA source code to be compiled.
40
+
41
+ This function may be invoked multiple times to add several sets of YARA
42
+ rules before calling [`Compiler::build`]. If the rules provided in
43
+ `src` contain errors that prevent compilation, the function will raise
44
+ an exception with the first error encountered. Additionally, the
45
+ compiler will store this error, along with any others discovered during
46
+ compilation, which can be accessed using [`Compiler::errors`].
47
+
48
+ Even if a previous invocation resulted in a compilation error, you can
49
+ continue calling this function. In such cases, any rules that failed to
50
+ compile will not be included in the final compiled set.
51
+
52
+ The optional parameter `origin` allows to specify the origin of the
53
+ source code. This usually receives the path of the file from where the
54
+ code was read, but it can be any arbitrary string that conveys information
55
+ about the source code's origin.
56
+ """
57
+ ...
58
+
59
+ def define_global(self, ident: str, value: typing.Any) -> None:
60
+ r"""
61
+ Defines a global variable and sets its initial value.
62
+
63
+ Global variables must be defined before calling [`Compiler::add_source`]
64
+ with some YARA rule that uses the variable. The variable will retain its
65
+ initial value when the [`Rules`] are used for scanning data, however
66
+ each scanner can change the variable's value by calling
67
+ [`crate::Scanner::set_global`].
68
+
69
+ The type of `value` must be: bool, str, bytes, int or float.
70
+
71
+ # Raises
72
+
73
+ [TypeError](https://docs.python.org/3/library/exceptions.html#TypeError)
74
+ if the type of `value` is not one of the supported ones.
75
+ """
76
+ ...
77
+
78
+ def new_namespace(self, namespace: str) -> None:
79
+ r"""
80
+ Creates a new namespace.
81
+
82
+ Further calls to [`Compiler::add_source`] will put the rules under the
83
+ newly created namespace.
84
+ """
85
+ ...
86
+
87
+ def ignore_module(self, module: str) -> None:
88
+ r"""
89
+ Tell the compiler that a YARA module is not supported.
90
+
91
+ Import statements for unsupported modules will be ignored without
92
+ errors, but a warning will be issued. Any rule that make use of an
93
+ ignored module will be ignored, while the rest of rules that
94
+ don't rely on that module will be correctly compiled.
95
+ """
96
+ ...
97
+
98
+ def build(self) -> Rules:
99
+ r"""
100
+ Builds the source code previously added to the compiler.
101
+
102
+ This function returns an instance of [`Rules`] containing all the rules
103
+ previously added with [`Compiler::add_source`] and sets the compiler
104
+ to its initial empty state.
105
+ """
106
+ ...
107
+
108
+ def errors(self) -> typing.Any:
109
+ r"""
110
+ Retrieves all errors generated by the compiler.
111
+
112
+ This method returns every error encountered during the compilation,
113
+ across all invocations of [`Compiler::add_source`].
114
+ """
115
+ ...
116
+
117
+ def warnings(self) -> typing.Any:
118
+ r"""
119
+ Retrieves all warnings generated by the compiler.
120
+
121
+ This method returns every warning encountered during the compilation,
122
+ across all invocations of [`Compiler::add_source`].
123
+ """
124
+ ...
125
+
126
+ def rule_name_regexp(self, regexp: str) -> None:
127
+ r"""
128
+ Tell the compiler that any rule must match this regular expression or it
129
+ will result in a compiler warning.
130
+
131
+ # Raises
132
+
133
+ [ValueError](https://docs.python.org/3/library/exceptions.html#ValueError)
134
+ if the regular expression is invalid.
135
+ """
136
+ ...
137
+
138
+ def required_metadata(self, regexp: typing.Dict[str, str]) -> None:
139
+ r"""
140
+ Specify required metadata identifiers and types for the values in each
141
+ rule. Any rule which does not meet these requirements will result in a
142
+ compiler warning.
143
+
144
+ The key in your dictionary corresponds to the metadata identifier and
145
+ the value in your dictionary corresponds to the required type for that
146
+ metadata in the rule.
147
+
148
+ Acceptable values are documented in [the config file](https://virustotal.github.io/yara-x/docs/cli/config-file/).
149
+ """
150
+ ...
151
+
152
+ class Scanner:
153
+ r"""
154
+ Scans data with already compiled YARA rules.
155
+
156
+ The scanner receives a set of compiled [`Rules`] and scans data with those
157
+ rules. The same scanner can be used for scanning multiple files or in-memory
158
+ data sequentially, but you need multiple scanners for scanning in parallel.
159
+ """
160
+
161
+ def __new__(cls, rules: Rules) -> Scanner:
162
+ r"""
163
+ Creates a new [`Scanner`] with a given set of [`Rules`].
164
+ """
165
+ ...
166
+
167
+ def scan(self, data: bytes) -> ScanResults:
168
+ r"""
169
+ Scans in-memory data.
170
+ """
171
+ ...
172
+
173
+ def scan_file(self, file: str) -> ScanResults:
174
+ r"""
175
+ Scans a file
176
+ """
177
+ ...
178
+
179
+ def set_global(self, ident: str, value: typing.Any):
180
+ r"""
181
+ Sets the value of a global variable.
182
+
183
+ The variable must has been previously defined by calling
184
+ [`Compiler::define_global`], and the type it has during the definition
185
+ must match the type of the new value.
186
+
187
+ The variable will retain the new value in subsequent scans, unless this
188
+ function is called again for setting a new value.
189
+
190
+ The type of `value` must be: `bool`, `str`, `bytes`, `int` or `float`.
191
+
192
+ # Raises
193
+
194
+ [TypeError](https://docs.python.org/3/library/exceptions.html#TypeError)
195
+ if the type of `value` is not one of the supported ones.
196
+ """
197
+ ...
198
+
199
+ def set_timeout(self, seconds: int):
200
+ r"""
201
+ Sets a timeout for each scan.
202
+
203
+ After setting a timeout scans will abort after the specified `seconds`.
204
+ """
205
+ ...
206
+
207
+ def console_log(self, callback: collections.abc.Callable[str]):
208
+ r"""
209
+ Sets a callback that is invoked every time a YARA rule calls the
210
+ `console` module.
211
+
212
+ The `callback` function is invoked with a string representing the
213
+ message being logged. The function can print the message to stdout,
214
+ append it to a file, etc. If no callback is set these messages are
215
+ ignored.
216
+ """
217
+ ...
218
+
219
+ class Formatter:
220
+ r"""
221
+ Formats YARA rules.
222
+ """
223
+ def __new__(
224
+ cls,
225
+ align_metadata: bool,
226
+ align_patterns: bool,
227
+ indent_section_headers: bool,
228
+ indent_section_contents: bool,
229
+ indent_spaces: int,
230
+ newline_before_curly_brace: bool,
231
+ empty_line_before_section_header: bool,
232
+ empty_line_after_section_header: bool,
233
+ ) -> Formatter:
234
+ r"""
235
+ Creates a new [`Formatter`].
236
+
237
+ `align_metadata` allows for aligning the equals signs in metadata definitions.
238
+ `align_patterns` allows for aligning the equals signs in pattern definitions.
239
+ `indent_section_headers` allows for indenting section headers.
240
+ `indent_section_contents` allows for indenting section contents.
241
+ `indent_spaces` is the number of spaces to use for indentation.
242
+ `newline_before_curly_brace` controls whether a newline is inserted before a curly brace.
243
+ `empty_line_before_section_header` controls whether an empty line is inserted before a section header.
244
+ `empty_line_after_section_header` controls whether an empty line is inserted after a section header.
245
+ """
246
+ ...
247
+
248
+ def format(self, input: typing.Any, output: typing.Any) -> str:
249
+ r"""
250
+ Format a YARA rule
251
+ """
252
+ ...
253
+
254
+ class Match:
255
+ r"""
256
+ Represents a match found for a pattern.
257
+ """
258
+ def offset(self) -> int:
259
+ r"""
260
+ Offset where the match occurred.
261
+ """
262
+ ...
263
+
264
+ def length(self) -> int:
265
+ r"""
266
+ Length of the match in bytes.
267
+ """
268
+ ...
269
+
270
+ def xor_key(self) -> typing.Optional[int]:
271
+ r"""
272
+ XOR key used for decrypting the data if the pattern had the xor
273
+ modifier, or None if otherwise.
274
+ """
275
+ ...
276
+
277
+ class Pattern:
278
+ r"""
279
+ Represents a pattern in a YARA rule.
280
+ """
281
+ def identifier(self) -> str:
282
+ r"""
283
+ Pattern identifier (e.g: '$a', '$foo').
284
+ """
285
+ ...
286
+
287
+ def matches(self) -> tuple:
288
+ r"""
289
+ Matches found for this pattern.
290
+ """
291
+ ...
292
+
293
+ class Rule:
294
+ r"""
295
+ Represents a rule that matched while scanning some data.
296
+ """
297
+ def identifier(self) -> str:
298
+ r"""
299
+ Returns the rule's name.
300
+ """
301
+ ...
302
+
303
+ def namespace(self) -> str:
304
+ r"""
305
+ Returns the rule's namespace.
306
+ """
307
+ ...
308
+
309
+ def tags(self) -> tuple:
310
+ r"""
311
+ Returns the rule's tags.
312
+ """
313
+ ...
314
+
315
+ def metadata(self) -> tuple:
316
+ r"""
317
+ A tuple of pairs `(identifier, value)` with the metadata associated to
318
+ the rule.
319
+ """
320
+ ...
321
+
322
+ def patterns(self) -> tuple:
323
+ r"""
324
+ Patterns defined by the rule.
325
+ """
326
+ ...
327
+
328
+ class Rules:
329
+ r"""
330
+ A set of YARA rules in compiled form.
331
+
332
+ This is the result of [`Compiler::build`].
333
+ """
334
+ def scan(self, data: bytes) -> ScanResults:
335
+ r"""
336
+ Scans in-memory data with these rules.
337
+ """
338
+ ...
339
+
340
+ def serialize_into(self, file: typing.Any) -> None:
341
+ r"""
342
+ Serializes the rules into a file-like object.
343
+ """
344
+ ...
345
+
346
+ @staticmethod
347
+ def deserialize_from(file: typing.Any) -> Rules:
348
+ r"""
349
+ Deserializes rules from a file-like object.
350
+ """
351
+ ...
352
+
353
+ class ScanResults:
354
+ r"""
355
+ Results produced by a scan operation.
356
+ """
357
+ def matching_rules(self) -> tuple:
358
+ r"""
359
+ Rules that matched during the scan.
360
+ """
361
+ ...
362
+
363
+ def module_outputs(self) -> dict:
364
+ r"""
365
+ Module output from the scan.
366
+ """
367
+ ...
368
+
369
+ def compile(src: str) -> Rules:
370
+ r"""
371
+ Compiles a YARA source code producing a set of compiled [`Rules`].
372
+
373
+ This function allows compiling simple rules that don't depend on external
374
+ variables. For more complex use cases you will need to use a [`Compiler`].
375
+ """
376
+ ...
377
+
378
+ class Module:
379
+ r"""A YARA-X module."""
380
+ def __new__(cls, name: str) -> Module:
381
+ r"""Creates a new [`Module`] with the given name, which must be a valid YARA-X module name."""
382
+ ...
383
+ def invoke(self, data: str) -> dict:
384
+ r"""Parse the data and collect module metadata."""
385
+ ...
yara_x/py.typed ADDED
File without changes
yara_x/yara_x.abi3.so ADDED
Binary file
@@ -0,0 +1,46 @@
1
+ Metadata-Version: 2.4
2
+ Name: yara-x
3
+ Version: 1.5.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,8 @@
1
+ yara_x-1.5.0.dist-info/RECORD,,
2
+ yara_x-1.5.0.dist-info/WHEEL,sha256=w0j8TAQ2dwtu41qL_sW49lKcDNy9dKYQVOa255cXFI4,130
3
+ yara_x-1.5.0.dist-info/METADATA,sha256=R8xh9lqnmE-9i-RuvjJsBPnq8obnorzdn7Lqm9dAkxs,1831
4
+ yara_x/__init__.pyi,sha256=T4g5Ujdu3fJ0Zeh5zoeeCZz7Aw1cIaaRjCoTkmclDzI,12055
5
+ yara_x/__init__.py,sha256=nMyCIYe2XAcE0xoh-kWfMlEZjVx9_cnT6O6Iaxh9JoM,107
6
+ yara_x/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ yara_x/yara_x.abi3.so,sha256=pQ53xtWY3UZllY8WJJpuhYzsGMiyCGw-qBI2PCOG91o,24212560
8
+ yara_x/.dylibs/liblzma.5.dylib,sha256=nS9N-V0A3ocAvJi87dwhSz7uoMXKcc48G5AhEa-H1vQ,185536
@@ -0,0 +1,6 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.9.3)
3
+ Root-Is-Purelib: false
4
+ Tag: cp38-abi3-macosx_14_0_arm64
5
+ Generator: delocate 0.13.0
6
+