module yaralyzer
Main Yaralyzer class and alternate constructors.
Global Variables
- output
- util
- config
- bytes_match
- decoding
- encoding_detection
- yaralyzer
- HEX
- REGEX
- BYTES_BRIGHTER
- MAX_FILENAME_LENGTH
- YARALYZE
- YARA_FILE_DOES_NOT_EXIST_ERROR_MSG
function yaralyze
yaralyze()
Entry point for Yaralyzer when invoked as a script. Args are parsed from the command line and environment variables. See yaralyze --help for details.
class Yaralyzer
Central class that handles setting up / compiling YARA rules and reading binary data from files as needed.
Alternate constructors are provided depending on whether:
-
YARA rules are already compiled
-
YARA rules should be compiled from a string
-
YARA rules should be read from a file
-
YARA rules should be read from a directory of .yara files
The real action happens in the __rich__console__() dunder method.
Attributes:
rules(yara.Rules): The YARA rules to use for scanning.rules_label(str): A label for the ruleset, typically derived from filenames or user input.scannable(bytes | str | Path): The data to scan. If it'sbytesthen that data is scanned; if it's a string it is treated as a file path to load bytes from.scannable_label(str, optional): A label for the binary data. Required ifscannableis rawbytes, otherwise defaults to the basename ofscannablefile.highlight_style(str, optional): The style to use for highlighting matches in the output._bytes(bytes): The binary data to scan, derived from thescannablearg.non_matches(list[dict]): A list of YARA rules that did not match the binary data.matches(list[YaraMatch]): A list of YaraMatch objects representing the matches found.extraction_stats(RegexMatchMetrics): Metrics related to decoding attempts on matched data
Raises:
TypeError: Ifscannableisbytesandscannable_labelis not provided.
method __init__
__init__(
rules: Rules,
rules_label: str,
scannable: str | bytes | Path,
scannable_label: str = '',
highlight_style: str = 'orange1',
non_matches: list[dict] = <factory>,
matches: list[YaraMatch] = <factory>,
extraction_stats: RegexMatchMetrics = <factory>
) → None
method export_basepath
export_basepath() → Path
Get the basepath (directory + filename without extension) for exported files.
classmethod for_patterns
for_patterns(
patterns: list[str],
patterns_type: Literal['hex', 'regex'],
scannable: bytes | str | Path,
scannable_label: str = '',
rules_label: str | None = None,
pattern_label: str | None = None,
regex_modifier: Optional[Literal['ascii', 'fullword', 'nocase', 'wide']] = None
) → Yaralyzer
Alternate constructor taking regex pattern strings. Rules label defaults to the patterns joined by comma.
Args:
patterns(list[str]): list of regex or hex patterns to build rules from.patterns_type(PatternType): Either"regex"or"hex"to indicate the type of patterns provided.scannable(Union[bytes, str]): The data to scan. Ifbytes, raw data is scanned; ifstr, it is treated as a file path to load bytes from.scannable_label(str | None, optional): Label for thescannabledata. Required ifscannableisbytes. If scannable is a file path, defaults to the file's basename.rules_label(str | None, optional): Label for the ruleset. Defaults to the patterns joined by comma.pattern_label(str | None, optional): Label for each pattern in the YARA rules. Defaults to "pattern".regex_modifier(str | None, optional): Optional regex modifier (e.g. "nocase", "ascii", "wide", etc). Only valid ifpatterns_typeis"regex".
classmethod for_rules_dirs
for_rules_dirs(
dirs: list[str] | list[Path] | list[str | Path],
scannable: bytes | str | Path,
scannable_label: str = ''
) → Yaralyzer
Alternate constructor that will load all .yara files in yara_rules_dir.
Args:
dirs(list[str]): list of directories to search for.yarafiles.scannable(Union[bytes, str]): The data to scan. Ifbytes, raw data is scanned; ifstr, it is treated as a file path to load bytes from.scannable_label(str | None, optional): Label for thescannabledata. Required ifscannableisbytes. If scannable is a file path, defaults to the file's basename.
Raises:
FileNotFoundError: Ifdirsis not a list of valid directories.
classmethod for_rules_files
for_rules_files(
yara_rules_files: list[str] | list[Path],
scannable: bytes | str | Path,
scannable_label: str = ''
) → Yaralyzer
Alternate constructor to load YARA rules from files and label rules with the filenames.
Args:
yara_rules_files(list[str]): list of file paths to YARA rules files.scannable(Union[bytes, str]): The data to scan. Ifbytes, raw data is scanned; ifstr, it is treated as a file path to load bytes from.scannable_label(str, optional): Label for thescannabledata. Required ifscannableisbytes. If scannable is a file path, defaults to the file's basename.
Raises:
FileNotFoundError: If any file inyara_rules_filesdoes not exist.TypeError: Ifyara_rules_filesis not a list of Paths or strings
method match_iterator
match_iterator() → Iterator[tuple[BytesMatch, BytesDecoder]]
Iterator version of yaralyze().
Yields:
tuple[BytesMatch, BytesDecoder]: Match and decode data tuple.
method yaralyze
yaralyze() → None
Use YARA to find matches and then force decode them.
This file was automatically generated via lazydocs.