-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
importlib fix for zipped pkg; catch stream decode errors; handle /Nam…
…es better
- Loading branch information
ashariyar
committed
Oct 13, 2022
1 parent
06f28dc
commit 262762a
Showing
5 changed files
with
36 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,32 @@ | ||
""" | ||
Class to help with the pre-configured YARA rules in /yara. | ||
""" | ||
import importlib.resources | ||
from importlib.resources import as_file, files | ||
from typing import Optional, Union | ||
|
||
from yaralyzer.yaralyzer import Yaralyzer | ||
|
||
YARA_RULES_DIR = importlib.resources.path('pdfalyzer', 'yara_rules') | ||
YARA_RULES_DIR = files('pdfalyzer').joinpath('yara_rules') | ||
|
||
YARA_RULES_FILES = [ | ||
'lprat.static_file_analysis.yara', | ||
'PDF.yara', | ||
'PDF_binary_stream.yara', | ||
] | ||
|
||
def get_file_yaralyzer(file_path_to_scan: str) -> Yaralyzer: | ||
"""Get a yaralyzer for a file path""" | ||
return Yaralyzer.for_rules_dirs([str(YARA_RULES_DIR)], file_path_to_scan) | ||
return _build_yaralyzer(file_path_to_scan) | ||
|
||
|
||
def get_bytes_yaralyzer(scannable: bytes, label: str) -> Yaralyzer: | ||
return Yaralyzer.for_rules_dirs([str(YARA_RULES_DIR)], scannable, label) | ||
return _build_yaralyzer(scannable, label) | ||
|
||
|
||
def _build_yaralyzer(scannable: Union[bytes, str], label: Optional[str] = None) -> Yaralyzer: | ||
# TODO: ugh this sucks (handling to extract .yara files from a python pkg zip) | ||
with as_file(YARA_RULES_DIR.joinpath(YARA_RULES_FILES[0])) as yara0: | ||
with as_file(YARA_RULES_DIR.joinpath(YARA_RULES_FILES[1])) as yara1: | ||
with as_file(YARA_RULES_DIR.joinpath(YARA_RULES_FILES[2])) as yara2: | ||
rules_paths = [str(y) for y in [yara0, yara1, yara2]] | ||
return Yaralyzer.for_rules_files(rules_paths, scannable, label) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "pdfalyzer" | ||
version = "1.10.7" | ||
version = "1.10.8" | ||
description = "A PDF analysis toolkit. Scan a PDF with relevant YARA rules, visualize its inner tree-like data structure in living color (lots of colors), force decodes of suspicious font binaries, and more." | ||
authors = ["Michel de Cryptadamus <[email protected]>"] | ||
license = "GPL-3.0-or-later" | ||
|