MCPcopy Create free account
hub / github.com/d78ui98/APKDeepLens / print_summary

Method print_summary

APKDeepLens.py:40–106  ·  view source on GitHub ↗

Print a colour-coded summary table after scanning completes.

(results_dict)

Source from the content-addressed store, hash-verified

38
39 @staticmethod
40 def print_summary(results_dict):
41 """Print a colour-coded summary table after scanning completes."""
42 SEVS = ["CRITICAL", "HIGH", "MEDIUM", "LOW", "INFO"]
43 SEV_COLOR = {
44 "CRITICAL": util.FAIL,
45 "HIGH": util.WARNING,
46 "MEDIUM": util.OKCYAN,
47 "LOW": "",
48 "INFO": "",
49 }
50
51 def count_by_sev(findings):
52 counts = {s: 0 for s in SEVS}
53 for f in (findings or []):
54 sev = f.get("severity", "INFO")
55 if sev in counts:
56 counts[sev] += 1
57 return counts
58
59 manifest_counts = count_by_sev(results_dict.get("manifest_security", []))
60 code_counts = count_by_sev(results_dict.get("code_findings", []))
61 n_secrets = len(results_dict.get("hardcoded_secrets") or [])
62 n_insecure = len(results_dict.get("insecure_requests") or [])
63 n_danger = len(results_dict.get("dangerous_permission") or [])
64
65 cat_w = 30
66 col_keys = ["CRITICAL", "HIGH", "MEDIUM", "LOW", "INFO", "TOTAL"]
67 col_w = {"CRITICAL": 10, "HIGH": 6, "MEDIUM": 8, "LOW": 5, "INFO": 6, "TOTAL": 7}
68
69 sep = (
70 "+" + "-" * (cat_w + 2) + "+"
71 + "+".join("-" * (col_w[k] + 2) for k in col_keys)
72 + "+"
73 )
74
75 def fmt(val, w, color=""):
76 s = str(val).center(w)
77 return (" " + color + s + util.ENDC + " ") if color else (" " + s + " ")
78
79 def header_row():
80 cells = [fmt(k, col_w[k]) for k in col_keys]
81 return "| " + "Category".ljust(cat_w) + " |" + "|".join(cells) + "|"
82
83 def data_row(label, counts):
84 total = sum(counts.values())
85 cells = [fmt(counts[k], col_w[k], SEV_COLOR.get(k, "")) for k in col_keys[:-1]]
86 cells.append(fmt(total, col_w["TOTAL"], util.BOLD))
87 return "| " + label.ljust(cat_w) + " |" + "|".join(cells) + "|"
88
89 def count_row(label, count):
90 inner = len(sep) - 4
91 content = f"{label}: {count} total"
92 return "| " + content.ljust(inner) + " |"
93
94 print()
95 print(util.BOLD + " Scan Summary" + util.ENDC)
96 print(" " + sep)
97 print(" " + header_row())

Callers 1

APKDeepLens.pyFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected