-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.d.ts
More file actions
444 lines (429 loc) · 13.2 KB
/
Copy pathindex.d.ts
File metadata and controls
444 lines (429 loc) · 13.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
/* auto-generated by NAPI-RS */
/* eslint-disable */
/**
* The main YARA-X scanner struct.
*
* This struct represents compiled YARA rules and provides methods for scanning
* data and files. It includes performance optimizations like scanner caching.
*/
export declare class YaraX {
/** Returns the compiler warnings generated during the compilation process. */
getWarnings(): Array<CompilerWarning>
/**
* Sets the maximum number of matches per pattern.
*
* # Arguments
*
* * `max_matches` - The maximum number of matches per pattern
*/
setMaxMatchesPerPattern(maxMatches: number): void
/**
* Sets whether to use memory-mapped files for scanning.
*
* # Arguments
*
* * `use_mmap` - Whether to use memory-mapped files
*/
setUseMmap(useMmap: boolean): void
/** Sets the scan timeout in milliseconds. */
setTimeout(timeoutMs: number): void
/** Sets the match context size. */
setMatchContextSize(size: number): void
/**
* Scans the provided data using the compiled YARA rules.
*
* # Arguments
*
* * `env` - The N-API environment
* * `data` - The data to scan
* * `variables` - Optional variables to set for this scan
*
* # Returns
*
* A vector of matching rules
*/
scan(data: Buffer, variables?: Record<string, string | number | boolean>): Array<RuleMatch>
/**
* Scans a file using the compiled YARA rules.
*
* # Arguments
*
* * `env` - The N-API environment
* * `file_path` - Path to the file to scan
* * `variables` - Optional variables to set for this scan
*
* # Returns
*
* A vector of matching rules
*/
scanFile(filePath: string, variables?: Record<string, string | number | boolean>): Array<RuleMatch>
/**
* Emits a WASM file from the compiled YARA rules.
*
* # Arguments
*
* * `output_path` - Path where the WASM file should be written
*
* # Returns
*
* Ok(()) on success, or an error if emission fails
*/
emitWasmFile(outputPath: string): void
/**
* Scans the provided data asynchronously using the compiled YARA rules.
*
* # Arguments
*
* * `data` - The data to scan
* * `variables` - Optional variables to set for this scan
*
* # Returns
*
* An async task that resolves to a vector of matching rules
*/
scanAsync(data: Buffer, variables?: object | undefined | null): Promise<Array<RuleMatch>>
/**
* Scans a file asynchronously using the compiled YARA rules.
*
* # Arguments
*
* * `file_path` - Path to the file to scan
* * `variables` - Optional variables to set for this scan
*
* # Returns
*
* An async task that resolves to a vector of matching rules
*/
scanFileAsync(filePath: string, variables?: object | undefined | null): Promise<Array<RuleMatch>>
/**
* Emits a WASM file asynchronously from the compiled YARA rules.
*
* # Arguments
*
* * `output_path` - Path where the WASM file should be written
*
* # Returns
*
* An async task that completes when the WASM file is written
*/
emitWasmFileAsync(outputPath: string): Promise<unknown>
/**
* Adds a rule source to the YARA compiler.
*
* # Arguments
*
* * `rule_source` - The YARA rule source code to add
*
* # Returns
*
* Ok(()) on success, or an error if compilation fails
*
* # Performance Note
*
* This method recompiles all rules (existing + new) on each call, resulting
* in O(n) time per call and O(n²) total for n incremental additions.
* For better performance with many rules, use `compile()` with all sources
* at once, or use `add_rule_sources()` for batch addition.
*/
addRuleSource(ruleSource: string, namespace?: string | undefined | null): void
/**
* Adds multiple rule sources to the YARA compiler in a single compilation pass.
*
* This is more efficient than calling `add_rule_source()` multiple times,
* as it compiles all sources in a single pass instead of recompiling
* existing rules for each addition.
*
* # Arguments
*
* * `rule_sources` - Vector of rule sources to add
*
* # Returns
*
* Ok(()) on success, or an error if compilation fails
*
* # Performance
*
* O(n + m) where n = existing rules, m = new rules (single compilation pass).
* Compared to calling `add_rule_source()` m times: O(n × m + m²).
*/
addRuleSources(ruleSources: Array<RuleSource>): void
/**
* Adds a rule file to the YARA compiler.
*
* # Arguments
*
* * `file_path` - Path to the file containing YARA rules
*
* # Returns
*
* Ok(()) on success, or an error if reading or compilation fails
*/
addRuleFile(filePath: string, namespace?: string | undefined | null): void
/**
* Defines a variable for the YARA compiler.
*
* # Arguments
*
* * `name` - The variable name
* * `value` - The variable value
*
* # Returns
*
* Ok(()) on success, or an error if compilation fails
*/
defineVariable(name: string, value: string): void
}
/**
* Represents a module that is banned from being used in YARA rules.
*
* When a banned module is encountered, compilation will fail with the
* specified error message.
*/
export interface BannedModule {
/** The name of the banned module. */
name: string
/** The title of the error message if the module is used. */
errorTitle: string
/** The error message if the module is used. */
errorMessage: string
}
/**
* Compiles a YARA rule source string and returns a YaraX instance with the compiled rules.
*
* # Arguments
*
* * `rule_source` - The YARA rule source code
* * `options` - Optional compiler options
*
* # Returns
*
* A YaraX instance with compiled rules
*/
export declare function compile(ruleSource: string, options?: CompilerOptionsType | undefined | null): YaraXImpl
/**
* Compiles a YARA rule file to a WASM file.
*
* # Arguments
*
* * `rule_path` - Path to the file containing YARA rules
* * `output_path` - Path where the WASM file should be written
* * `options` - Optional compiler options
*
* # Returns
*
* Ok(()) on success, or an error if reading, compilation, or emission fails
*/
export declare function compileFileToWasm(rulePath: string, outputPath: string, options?: CompilerOptionsType | undefined | null): void
/**
* An error generated by the YARA compiler.
*
* Errors prevent successful compilation and must be resolved before
* the rules can be used.
*/
export interface CompilerError {
/** The code of the error. */
code: string
/** The message of the error. */
message: string
/** The source of the error, if available. */
source?: string
/** The line number where the error occurred, if available. */
line?: number
/** The column number where the error occurred, if available. */
column?: number
}
/**
* The result of compiling YARA rules.
*
* Contains any warnings or errors generated during the compilation process.
* If errors are present, the compilation failed.
*/
export interface CompileResult {
/** Any warnings generated during the compilation process. */
warnings: Array<CompilerWarning>
/** Any errors generated during the compilation process. */
errors: Array<CompilerError>
}
/**
* Options for configuring the YARA compiler.
*
* These options control various aspects of rule compilation including
* module handling, optimization, and feature flags.
*/
export interface CompilerOptions {
/** The namespace where the YARA rules should be compiled. */
namespace?: string
/** Defines global variables for the YARA rules. */
defineVariables?: object
/** A list of module names to ignore during compilation. */
ignoreModules?: Array<string>
/** A list of banned modules that cannot be used in the YARA rules. */
bannedModules?: Array<BannedModule>
/** A list of features to enable for the YARA rules. */
features?: Array<string>
/** Whether to use relaxed regular expression syntax. */
relaxedReSyntax?: boolean
/** Whether to optimize conditions in the YARA rules. */
conditionOptimization?: boolean
/** Whether to raise an error on slow patterns. */
errorOnSlowPattern?: boolean
/** Whether to raise an error on slow loops. */
errorOnSlowLoop?: boolean
/**
* Maximum number of warnings the compiler will report.
*
* When set, only the first `n` warnings are emitted; additional warnings
* are dropped. Useful for taming noisy rule corpora, particularly when
* the compiler warns on single-byte patterns and duplicate pattern values.
*/
maxWarnings?: number
/**
* Warning codes to disable during compilation.
*
* Each entry must be a valid YARA-X warning code (e.g. `"slow_pattern"`,
* `"duplicate_pattern_value"`, `"potentially_slow_loop"`). An invalid
* code produces a compilation error.
*/
disableWarnings?: Array<string>
/**
* Whether to enable or disable all compiler warnings.
*
* `true` (the default) leaves all warning types enabled. `false` silences
* every warning. Individual codes in `disable_warnings` are applied after
* this flag, so an explicitly disabled code stays off even when this is
* `true`.
*/
enableAllWarnings?: boolean
/** A list of directories where the compiler should look for included files. */
includeDirectories?: Array<string>
/** Whether to enable include statements in YARA rules. */
enableIncludes?: boolean
}
/**
* A warning generated by the YARA compiler.
*
* Warnings indicate potential issues that don't prevent compilation
* but may indicate problems with the rules.
*/
export interface CompilerWarning {
/** The code of the warning. */
code: string
/** The message of the warning. */
message: string
/** The source of the warning, if available. */
source?: string
/** The line number where the warning occurred, if available. */
line?: number
/** The column number where the warning occurred, if available. */
column?: number
}
/**
* Compiles a YARA rule source string to a WASM file.
*
* # Arguments
*
* * `rule_source` - The YARA rule source code
* * `output_path` - Path where the WASM file should be written
* * `options` - Optional compiler options
*
* # Returns
*
* Ok(()) on success, or an error if compilation or emission fails
*/
export declare function compileToWasm(ruleSource: string, outputPath: string, options?: CompilerOptionsType | undefined | null): void
/**
* Creates a new YaraX instance with empty rules and no source code.
*
* # Returns
*
* A new YaraX instance with empty rules
*/
export declare function create(): YaraXImpl
/**
* Creates a new YaraX instance from a file containing YARA rules.
*
* # Arguments
*
* * `rule_path` - Path to the file containing YARA rules
* * `options` - Optional compiler options
*
* # Returns
*
* A YaraX instance with compiled rules from the file
*/
export declare function fromFile(rulePath: string, options?: CompilerOptionsType | undefined | null): YaraXImpl
/**
* Represents a match found by a YARA rule pattern.
*
* Contains information about where the match occurred and what data was matched.
*/
export interface MatchData {
/** The offset of the match in the scanned data. */
offset: number
/** The length of the matched data. */
length: number
/** The matched data as a string. */
data: string
/** The identifier of the pattern that matched. */
identifier: string
/** The context around the matched data, if match_context_size is set. */
contextData?: string
/** The start offset of the actual match within the context data. */
contextMatchOffset?: number
}
/**
* Represents a matching rule found during scanning.
*
* Contains the rule's metadata, tags, and all pattern matches.
*/
export interface RuleMatch {
/** The identifier of the rule that matched. */
ruleIdentifier: string
/** The namespace of the rule that matched. */
namespace: string
/** The metadata associated with the rule that matched. */
meta: object
/** The tags associated with the rule that matched. */
tags: Array<string>
/** The matches found by the rule. */
matches: Array<MatchData>
}
/** A YARA rule source and the namespace it belongs to. */
export interface RuleSource {
/** The YARA rule source code. */
source: string
/** The namespace for the source. `None` means the default namespace. */
namespace?: string
}
/**
* Options for configuring scanning operations.
*
* These options control resource usage and performance characteristics
* during rule scanning.
*/
export interface ScanOptions {
/** Maximum number of matches per pattern. When a pattern reaches this limit, it won't produce more matches. */
maxMatchesPerPattern?: number
/** Whether to use memory-mapped files for scanning. Disabling this is safer but slower. */
useMmap?: boolean
/** Scan timeout in milliseconds. */
timeoutMs?: number
/** Optional number of bytes to include before and after the match. */
matchContextSize?: number
}
/**
* Compiles a YARA rule source string and returns any warnings or errors generated during the
* compilation process.
*
* This function validates YARA rules without creating a scanner instance.
*
* # Arguments
*
* * `rule_source` - The YARA rule source code
* * `options` - Optional compiler options
*
* # Returns
*
* A CompileResult containing any warnings and errors
*/
export declare function validate(ruleSource: string, options?: CompilerOptionsType | undefined | null): CompileResult