-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path__main__.py
More file actions
54 lines (46 loc) · 3.15 KB
/
Copy path__main__.py
File metadata and controls
54 lines (46 loc) · 3.15 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
# -*- coding: UTF-8 -*-
from argparse import ArgumentParser, Namespace, RawTextHelpFormatter
from .__info__ import __author__, __copyright__, __email__, __license__, __source__, __version__
from .__init__ import *
from .__init__ import __all__ as _plots
def _parser(name: str, description: str, examples: list[str]) -> ArgumentParser:
descr = f"{name} {__version__}\n\nAuthor : {__author__} ({__email__})\nCopyright: {__copyright__}\nLicense :" \
f" {__license__}\nSource : {__source__}\n\n{description}.\n\n"
examples = [f"exeplot {e}" if not e.startswith("exeplot ") else e for e in examples]
return ArgumentParser(description=descr, formatter_class=RawTextHelpFormatter, add_help=False,
epilog="usage examples:\n " + "\n ".join(examples) if len(examples) > 0 else None)
def _setup(parser: ArgumentParser) -> Namespace: # pragma: no cover
args = parser.parse_args()
if hasattr(args, "verbose"):
import logging
logging.basicConfig(level=[logging.INFO, logging.DEBUG][args.verbose])
logging.getLogger("exeplot").level = [logging.INFO, logging.DEBUG][args.verbose]
return args
def main() -> None: # pragma: no cover
from os import makedirs
parser = _parser("Exeplot", "This tool allows to plot executable sample(s) in different ways",
["byte binary.exe", "entropy binary1.exe binary2.exe --scale"])
extra = parser.add_argument_group("extra arguments")
extra.add_argument("-h", "--help", action="help", help="show this help message and exit")
extra.add_argument("-v", "--verbose", action="store_true", help="display debug information (default: False)")
plots = parser.add_subparsers(dest="type", help="plot type")
for plot in _plots:
plot_func = globals()[plot]
plot_parser = plot_func.__args__(plots.add_parser(plot, help=plot_func.__doc__.strip(), add_help=False))
opt = plot_parser.add_argument_group("options")
if plot == "diff":
opt.add_argument("--no-colormap", action="store_true", help="do not display the color map (default: False)")
if plot == "entropy":
opt.add_argument("--no-entrypoint", action="store_true",
help="do not display the entry point (default: False)")
if plot in ["entropy", "pie"]:
opt.add_argument("--no-label", action="store_true", help="do not display the labels (default: False)")
opt.add_argument("--no-legend", action="store_true", help="do not display the legend (default: False)")
opt.add_argument("--no-title", action="store_true", help="do not display the title (default: False)")
extra = plot_parser.add_argument_group("extra arguments")
extra.add_argument("-h", "--help", action="help", help="show this help message and exit")
extra.add_argument("-i", "--interactive-mode", action="store_true", help="open Python console to edit the plot")
args = _setup(parser)
exe = args.executable if isinstance(args.executable, list) else [args.executable]
delattr(args, "executable")
globals()[args.type](*exe, **vars(args))