-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_analysis.py
More file actions
70 lines (56 loc) · 1.85 KB
/
Copy pathrun_analysis.py
File metadata and controls
70 lines (56 loc) · 1.85 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
import argparse
import importlib
import json
import sys
from pathlib import Path
def load_analyzer(module_path):
"""
Dynamically load analyzer module
Example: core.password_policy_analyzer
"""
try:
module = importlib.import_module(module_path)
if not hasattr(module, "run"):
raise AttributeError("Analyzer must expose a run() function")
return module
except Exception as e:
print(f"[ERROR] Failed to load analyzer: {e}")
sys.exit(1)
def main():
parser = argparse.ArgumentParser(description="ADShield Generic Analysis Runner")
parser.add_argument(
"--analyzer",
required=True,
help="Analyzer module path (e.g. core.password_policy_analyzer)"
)
parser.add_argument(
"--input",
required=True,
nargs="+",
help="Input JSON file path(s); some analyzers may require multiple files"
)
parser.add_argument(
"--output",
default=None,
help="Optional output file path (JSON)"
)
args = parser.parse_args()
analyzer = load_analyzer(args.analyzer)
# support one or more input files (some analyzers, e.g. stale_objects, need two)
input_paths = [Path(p) for p in args.input]
for p in input_paths:
if not p.exists():
print(f"[ERROR] Input file not found: {p}")
sys.exit(1)
# forward paths as separate arguments to the analyzer
report = analyzer.run(*[str(p) for p in input_paths])
if args.output:
output_path = Path(args.output)
output_path.parent.mkdir(parents=True, exist_ok=True)
with open(output_path, "w", encoding="utf-8") as f:
json.dump(report, f, indent=4)
print(f"[+] Report written to {output_path}")
else:
print(json.dumps(report, indent=4))
if __name__ == "__main__":
main()