yaralyzer 0.9.6__tar.gz → 1.0.0__tar.gz

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 yaralyzer might be problematic. Click here for more details.

Files changed (29) hide show
  1. {yaralyzer-0.9.6 → yaralyzer-1.0.0}/CHANGELOG.md +3 -0
  2. {yaralyzer-0.9.6 → yaralyzer-1.0.0}/PKG-INFO +2 -2
  3. {yaralyzer-0.9.6 → yaralyzer-1.0.0}/README.md +1 -1
  4. {yaralyzer-0.9.6 → yaralyzer-1.0.0}/pyproject.toml +1 -1
  5. {yaralyzer-0.9.6 → yaralyzer-1.0.0}/yaralyzer/__init__.py +4 -1
  6. {yaralyzer-0.9.6 → yaralyzer-1.0.0}/yaralyzer/bytes_match.py +20 -2
  7. {yaralyzer-0.9.6 → yaralyzer-1.0.0}/yaralyzer/output/file_export.py +20 -0
  8. {yaralyzer-0.9.6 → yaralyzer-1.0.0}/yaralyzer/util/argument_parser.py +6 -1
  9. {yaralyzer-0.9.6 → yaralyzer-1.0.0}/yaralyzer/yara/yara_match.py +0 -1
  10. {yaralyzer-0.9.6 → yaralyzer-1.0.0}/.yaralyzer.example +0 -0
  11. {yaralyzer-0.9.6 → yaralyzer-1.0.0}/LICENSE +0 -0
  12. {yaralyzer-0.9.6 → yaralyzer-1.0.0}/yaralyzer/config.py +0 -0
  13. {yaralyzer-0.9.6 → yaralyzer-1.0.0}/yaralyzer/decoding/bytes_decoder.py +0 -0
  14. {yaralyzer-0.9.6 → yaralyzer-1.0.0}/yaralyzer/decoding/decoding_attempt.py +0 -0
  15. {yaralyzer-0.9.6 → yaralyzer-1.0.0}/yaralyzer/encoding_detection/character_encodings.py +0 -0
  16. {yaralyzer-0.9.6 → yaralyzer-1.0.0}/yaralyzer/encoding_detection/encoding_assessment.py +0 -0
  17. {yaralyzer-0.9.6 → yaralyzer-1.0.0}/yaralyzer/encoding_detection/encoding_detector.py +0 -0
  18. {yaralyzer-0.9.6 → yaralyzer-1.0.0}/yaralyzer/helpers/bytes_helper.py +0 -0
  19. {yaralyzer-0.9.6 → yaralyzer-1.0.0}/yaralyzer/helpers/dict_helper.py +0 -0
  20. {yaralyzer-0.9.6 → yaralyzer-1.0.0}/yaralyzer/helpers/file_helper.py +0 -0
  21. {yaralyzer-0.9.6 → yaralyzer-1.0.0}/yaralyzer/helpers/rich_text_helper.py +0 -0
  22. {yaralyzer-0.9.6 → yaralyzer-1.0.0}/yaralyzer/helpers/string_helper.py +0 -0
  23. {yaralyzer-0.9.6 → yaralyzer-1.0.0}/yaralyzer/output/decoding_attempts_table.py +0 -0
  24. {yaralyzer-0.9.6 → yaralyzer-1.0.0}/yaralyzer/output/file_hashes_table.py +0 -0
  25. {yaralyzer-0.9.6 → yaralyzer-1.0.0}/yaralyzer/output/regex_match_metrics.py +0 -0
  26. {yaralyzer-0.9.6 → yaralyzer-1.0.0}/yaralyzer/output/rich_console.py +0 -0
  27. {yaralyzer-0.9.6 → yaralyzer-1.0.0}/yaralyzer/util/logging.py +0 -0
  28. {yaralyzer-0.9.6 → yaralyzer-1.0.0}/yaralyzer/yara/yara_rule_builder.py +0 -0
  29. {yaralyzer-0.9.6 → yaralyzer-1.0.0}/yaralyzer/yaralyzer.py +0 -0
@@ -1,5 +1,8 @@
1
1
  # NEXT RELEASE
2
2
 
3
+ # 1.0.0
4
+ * Add `--export-json` option
5
+
3
6
  ### 0.9.6
4
7
  * Fix help message
5
8
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: yaralyzer
3
- Version: 0.9.6
3
+ Version: 1.0.0
4
4
  Summary: Visualize and force decode YARA and regex matches found in a file or byte stream. With colors. Lots of colors.
5
5
  Home-page: https://github.com/michelcrypt4d4mus/yaralyzer
6
6
  License: GPL-3.0-or-later
@@ -113,7 +113,7 @@ for bytes_match, bytes_decoder in yaralyzer.match_iterator():
113
113
  ```
114
114
 
115
115
  # Example Output
116
- The Yaralyzer can export visualizations to HTML, ANSI colored text, and SVG vector images using the file export functionality that comes with [Rich](https://github.com/Textualize/rich). SVGs can be turned into `png` format images with a tool like [Inkscape](https://inkscape.org/) or `cairosvg`. In our experience they both work though we've seen some glitchiness with `cairosvg`.
116
+ The Yaralyzer can export visualizations to HTML, ANSI colored text, and SVG vector images using the file export functionality that comes with [Rich](https://github.com/Textualize/rich) as well as a (somewhat limited) plain text JSON format. SVGs can be turned into `png` format images with a tool like [Inkscape](https://inkscape.org/) or `cairosvg`. In our experience they both work though we've seen some glitchiness with `cairosvg`.
117
117
 
118
118
  **PyPi Users:** If you are reading this document [on PyPi](https://pypi.org/project/yaralyzer/) be aware that it renders a lot better [over on GitHub](https://github.com/michelcrypt4d4mus/yaralyzer). Pretty pictures, footnotes that work, etc.
119
119
 
@@ -87,7 +87,7 @@ for bytes_match, bytes_decoder in yaralyzer.match_iterator():
87
87
  ```
88
88
 
89
89
  # Example Output
90
- The Yaralyzer can export visualizations to HTML, ANSI colored text, and SVG vector images using the file export functionality that comes with [Rich](https://github.com/Textualize/rich). SVGs can be turned into `png` format images with a tool like [Inkscape](https://inkscape.org/) or `cairosvg`. In our experience they both work though we've seen some glitchiness with `cairosvg`.
90
+ The Yaralyzer can export visualizations to HTML, ANSI colored text, and SVG vector images using the file export functionality that comes with [Rich](https://github.com/Textualize/rich) as well as a (somewhat limited) plain text JSON format. SVGs can be turned into `png` format images with a tool like [Inkscape](https://inkscape.org/) or `cairosvg`. In our experience they both work though we've seen some glitchiness with `cairosvg`.
91
91
 
92
92
  **PyPi Users:** If you are reading this document [on PyPi](https://pypi.org/project/yaralyzer/) be aware that it renders a lot better [over on GitHub](https://github.com/michelcrypt4d4mus/yaralyzer). Pretty pictures, footnotes that work, etc.
93
93
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "yaralyzer"
3
- version = "0.9.6"
3
+ version = "1.0.0"
4
4
  description = "Visualize and force decode YARA and regex matches found in a file or byte stream. With colors. Lots of colors."
5
5
  authors = ["Michel de Cryptadamus <michel@cryptadamus.com>"]
6
6
  readme = "README.md"
@@ -12,7 +12,7 @@ if not environ.get('INVOKED_BY_PYTEST', False):
12
12
  break
13
13
 
14
14
  from yaralyzer.config import YaralyzerConfig
15
- from yaralyzer.output.file_export import invoke_rich_export
15
+ from yaralyzer.output.file_export import export_json, invoke_rich_export
16
16
  from yaralyzer.output.rich_console import console
17
17
  from yaralyzer.util.argument_parser import get_export_basepath, parse_arguments
18
18
  from yaralyzer.util.logging import log
@@ -59,6 +59,9 @@ def yaralyze():
59
59
  if args.export_svg:
60
60
  invoke_rich_export(console.save_svg, output_basepath)
61
61
 
62
+ if args.export_json:
63
+ export_json(yaralyzer, output_basepath)
64
+
62
65
  if args.file_to_scan_path.endswith('.pdf'):
63
66
  console.print(PDFALYZER_MSG_TXT)
64
67
 
@@ -14,9 +14,8 @@ from yara import StringMatch, StringMatchInstance
14
14
 
15
15
  from yaralyzer.config import YaralyzerConfig
16
16
  from yaralyzer.helpers.rich_text_helper import prefix_with_plain_text_obj
17
- from yaralyzer.output.rich_console import ALERT_STYLE, GREY_ADDRESS
18
17
  from yaralyzer.output.file_hashes_table import bytes_hashes_table
19
- from yaralyzer.util.logging import log
18
+ from yaralyzer.output.rich_console import ALERT_STYLE, GREY_ADDRESS
20
19
 
21
20
 
22
21
  class BytesMatch:
@@ -157,6 +156,25 @@ class BytesMatch:
157
156
 
158
157
  return txt
159
158
 
159
+ def to_json(self) -> dict:
160
+ """Convert this BytesMatch to a JSON-serializable dict."""
161
+ json_dict = {
162
+ 'label': self.label,
163
+ 'match_length': self.match_length,
164
+ 'matched_bytes': self.bytes.hex(),
165
+ 'ordinal': self.ordinal,
166
+ 'start_idx': self.start_idx,
167
+ 'end_idx': self.end_idx,
168
+ 'surrounding_bytes': self.surrounding_bytes.hex(),
169
+ 'surrounding_start_idx': self.surrounding_start_idx,
170
+ 'surrounding_end_idx': self.surrounding_end_idx,
171
+ }
172
+
173
+ if self.match:
174
+ json_dict['pattern'] = self.match.re.pattern
175
+
176
+ return json_dict
177
+
160
178
  def _find_surrounding_bytes(self, num_before: Optional[int] = None, num_after: Optional[int] = None) -> None:
161
179
  """Find the surrounding bytes, making sure not to step off the beginning or end"""
162
180
  num_after = num_after or num_before or YaralyzerConfig.args.surrounding_bytes
@@ -1,9 +1,13 @@
1
+ import json
1
2
  import time
3
+ from argparse import Namespace
4
+ from pathlib import Path
2
5
  from os import path
3
6
 
4
7
  from rich.terminal_theme import TerminalTheme
5
8
 
6
9
  from yaralyzer.util.logging import log_and_print
10
+ from yaralyzer.yaralyzer import Yaralyzer
7
11
 
8
12
  # TerminalThemes are used when saving SVGS. This one just swaps white for black in DEFAULT_TERMINAL_THEME
9
13
  YARALYZER_TERMINAL_THEME = TerminalTheme(
@@ -47,6 +51,22 @@ _EXPORT_KWARGS = {
47
51
  }
48
52
 
49
53
 
54
+ def export_json(yaralyzer: Yaralyzer, output_basepath: str | None) -> str:
55
+ """Export YARA scan results to JSON. Returns the path to the output file that was written."""
56
+ output_path = f"{output_basepath or 'yara_matches'}.json"
57
+
58
+ matches_data = [
59
+ bytes_match.to_json()
60
+ for bytes_match, _bytes_decoder in yaralyzer.match_iterator()
61
+ ]
62
+
63
+ with open(output_path, 'w') as f:
64
+ json.dump(matches_data, f, indent=4)
65
+
66
+ log_and_print(f"YARA matches exported to JSON file: '{output_path}'")
67
+ return output_path
68
+
69
+
50
70
  def invoke_rich_export(export_method, output_file_basepath) -> str:
51
71
  """
52
72
  Announce the export, perform the export, announce completion.
@@ -179,6 +179,11 @@ export.add_argument('-html', '--export-html',
179
179
  const='html',
180
180
  help='export analysis to styled html files')
181
181
 
182
+ export.add_argument('-json', '--export-json',
183
+ action='store_const',
184
+ const='json',
185
+ help='export analysis to JSON files')
186
+
182
187
  export.add_argument('-out', '--output-dir',
183
188
  metavar='OUTPUT_DIR',
184
189
  help='write files to OUTPUT_DIR instead of current dir, does nothing if not exporting a file')
@@ -257,7 +262,7 @@ def parse_arguments(args: Optional[Namespace] = None):
257
262
  EncodingDetector.force_display_threshold = args.force_display_threshold
258
263
 
259
264
  # File export options
260
- if args.export_svg or args.export_txt or args.export_html:
265
+ if args.export_html or args.export_json or args.export_svg or args.export_txt:
261
266
  args.output_dir = args.output_dir or getcwd()
262
267
  elif args.output_dir:
263
268
  log.warning('--output-dir provided but no export option was chosen')
@@ -14,7 +14,6 @@ Rich text decorator for YARA match dicts, which look like this:
14
14
  }
15
15
  """
16
16
  import re
17
- from copy import deepcopy
18
17
  from numbers import Number
19
18
  from typing import Any, Dict
20
19
 
File without changes
File without changes
File without changes