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

Class util

APKDeepLens.py:24–123  ·  view source on GitHub ↗

A static class for which contain some useful variables and methods

Source from the content-addressed store, hash-verified

22
23
24class util(util):
25 """
26 A static class for which contain some useful variables and methods
27 """
28
29 @staticmethod
30 def mod_print(text_output, color):
31 """
32 Better mod print. It gives the line number, file name in which error occured.
33 """
34 stack = traceback.extract_stack()
35 filename, line_no, func_name, text = stack[-2]
36 formatted_message = f"{filename}:{line_no}: {text_output}"
37 print(color + formatted_message + util.ENDC)
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) + "|"

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected