dexsect 4.1.0__py3-none-any.whl

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.
Files changed (74) hide show
  1. dexsect/__init__.py +4 -0
  2. dexsect/__main__.py +5 -0
  3. dexsect/catalog/EXTRACTION_CATALOG.json +4057 -0
  4. dexsect/catalog/__init__.py +0 -0
  5. dexsect/cli.py +1272 -0
  6. dexsect/core/__init__.py +0 -0
  7. dexsect/core/config.py +177 -0
  8. dexsect/core/context.py +181 -0
  9. dexsect/core/i18n.py +40 -0
  10. dexsect/core/pipeline.py +153 -0
  11. dexsect/core/platform_utils.py +164 -0
  12. dexsect/core/runner.py +124 -0
  13. dexsect/core/theme.py +64 -0
  14. dexsect/core/ui.py +405 -0
  15. dexsect/core/utils.py +150 -0
  16. dexsect/inspectors/__init__.py +0 -0
  17. dexsect/inspectors/assets_db_inspector.py +235 -0
  18. dexsect/inspectors/base.py +46 -0
  19. dexsect/inspectors/bundle_inspector.py +55 -0
  20. dexsect/inspectors/code_inspector.py +341 -0
  21. dexsect/inspectors/custom_rules_inspector.py +178 -0
  22. dexsect/inspectors/dex_inspector.py +144 -0
  23. dexsect/inspectors/manifest_inspector.py +503 -0
  24. dexsect/inspectors/native_fw_inspector.py +167 -0
  25. dexsect/inspectors/resources_inspector.py +195 -0
  26. dexsect/inspectors/scanner_inspector.py +153 -0
  27. dexsect/inspectors/signing_inspector.py +423 -0
  28. dexsect/inspectors/text_scanner.py +336 -0
  29. dexsect/locales/__init__.py +0 -0
  30. dexsect/locales/ar.json +130 -0
  31. dexsect/locales/de.json +51 -0
  32. dexsect/locales/en.json +110 -0
  33. dexsect/locales/es.json +51 -0
  34. dexsect/locales/fr.json +51 -0
  35. dexsect/locales/ja.json +51 -0
  36. dexsect/locales/pt.json +51 -0
  37. dexsect/locales/ru.json +51 -0
  38. dexsect/locales/tr.json +51 -0
  39. dexsect/locales/zh.json +51 -0
  40. dexsect/parsers/__init__.py +0 -0
  41. dexsect/parsers/axml.py +264 -0
  42. dexsect/parsers/bundle.py +214 -0
  43. dexsect/parsers/elf.py +396 -0
  44. dexsect/phases/__init__.py +0 -0
  45. dexsect/phases/base.py +102 -0
  46. dexsect/phases/decode.py +507 -0
  47. dexsect/phases/decompile.py +408 -0
  48. dexsect/phases/fingerprint.py +341 -0
  49. dexsect/phases/frameworks.py +377 -0
  50. dexsect/phases/mapper.py +41 -0
  51. dexsect/phases/native.py +188 -0
  52. dexsect/plugins/__init__.py +0 -0
  53. dexsect/plugins/base.py +20 -0
  54. dexsect/plugins/diff.py +162 -0
  55. dexsect/plugins/inspect.py +172 -0
  56. dexsect/plugins/report.py +80 -0
  57. dexsect/plugins/trace.py +141 -0
  58. dexsect/reporting/__init__.py +0 -0
  59. dexsect/reporting/analysis_report.py +1190 -0
  60. dexsect/reporting/diff_report.py +144 -0
  61. dexsect/reporting/sarif_report.py +109 -0
  62. dexsect/reporting/unpack_map.py +149 -0
  63. dexsect/rules/__init__.py +0 -0
  64. dexsect/rules/anti_analysis.json +45 -0
  65. dexsect/rules/crypto_audit.json +41 -0
  66. dexsect/rules/secrets_extended.json +46 -0
  67. dexsect/storage/__init__.py +0 -0
  68. dexsect/storage/findings_db.py +460 -0
  69. dexsect-4.1.0.dist-info/METADATA +532 -0
  70. dexsect-4.1.0.dist-info/RECORD +74 -0
  71. dexsect-4.1.0.dist-info/WHEEL +5 -0
  72. dexsect-4.1.0.dist-info/entry_points.txt +2 -0
  73. dexsect-4.1.0.dist-info/licenses/LICENSE +21 -0
  74. dexsect-4.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1190 @@
1
+ import html
2
+ import json
3
+ import re
4
+ import time
5
+ from collections import OrderedDict
6
+ from pathlib import Path
7
+ from typing import Any, Dict, List, Tuple
8
+
9
+ from .. import __version__
10
+ from ..core.context import WorkspaceState
11
+ from ..core.i18n import load_locale
12
+ from ..storage.findings_db import FindingsDB
13
+
14
+
15
+ BOILERPLATE_DOMAINS = {
16
+ "schemas.android.com",
17
+ "schemas.xmlsoap.org",
18
+ "www.w3.org",
19
+ "ns.adobe.com",
20
+ "purl.org",
21
+ "www.apache.org",
22
+ "apache.org",
23
+ "xml.org",
24
+ "xmlpull.org",
25
+ "javax.xml.org",
26
+ }
27
+
28
+ BOILERPLATE_URL_SUBSTRINGS = (
29
+ "schemas.android.com/apk/res",
30
+ "schemas.android.com/tools",
31
+ "schemas.android.com/aapt",
32
+ "www.w3.org/2000/",
33
+ "www.w3.org/1999/",
34
+ "ns.adobe.com/",
35
+ "www.apache.org/licenses/",
36
+ "apache.org/licenses/LICENSE",
37
+ "purl.org/dc/",
38
+ )
39
+
40
+ NOISY_ENABLED_CIDS = {"ACT-006", "SRV-003", "REC-003"}
41
+ MD_CTRL_RE = re.compile(r"[\x00-\x08\x0b\x0c\x0e-\x1f\x7f\ufffd]")
42
+
43
+
44
+ def _clean_md(val: Any) -> str:
45
+ return MD_CTRL_RE.sub("", str(val if val is not None else ""))
46
+
47
+
48
+ def _esc(val: Any) -> str:
49
+ return html.escape(str(val if val is not None else ""), quote=True)
50
+
51
+
52
+ def _load_catalog_specs() -> Dict[str, Dict[str, str]]:
53
+ cat_path = Path(__file__).resolve().parent.parent / "catalog" / "EXTRACTION_CATALOG.json"
54
+ if not cat_path.is_file():
55
+ return {}
56
+ try:
57
+ data = json.loads(cat_path.read_text(encoding="utf-8"))
58
+ return {
59
+ it["id"]: {"name": it.get("name", ""), "description": it.get("description", "")}
60
+ for it in data.get("items", [])
61
+ }
62
+ except Exception:
63
+ return {}
64
+
65
+
66
+ def _is_boilerplate_row(row: Dict[str, Any]) -> bool:
67
+ if row.get("scope") == "boilerplate":
68
+ return True
69
+ cid = row.get("catalog_id", "")
70
+ val = str(row.get("value", "")).lower()
71
+ if cid in NOISY_ENABLED_CIDS and row.get("title") == "Enabled=true":
72
+ return True
73
+ if cid == "NET-001" and val in BOILERPLATE_DOMAINS:
74
+ return True
75
+ if cid in ("URL-001", "URL-003", "URL-004"):
76
+ if any(sub in val for sub in BOILERPLATE_URL_SUBSTRINGS):
77
+ return True
78
+ return False
79
+
80
+
81
+ def _clean_and_collapse(rows: List[Dict[str, Any]], include_noise: bool) -> Tuple[List[Dict[str, Any]], int]:
82
+ hidden = 0
83
+ grouped: "OrderedDict[Tuple[str, str, str, str], Dict[str, Any]]" = OrderedDict()
84
+ for r in rows:
85
+ if not include_noise and _is_boilerplate_row(r):
86
+ hidden += 1
87
+ continue
88
+ key = (r["catalog_id"], r["unit_id"], r.get("scope", "app"), r["value"])
89
+ if key not in grouped:
90
+ entry = dict(r)
91
+ entry["hits"] = 1
92
+ grouped[key] = entry
93
+ else:
94
+ grouped[key]["hits"] += 1
95
+ return list(grouped.values()), hidden
96
+
97
+
98
+ def _build_executive_data(
99
+ state: WorkspaceState,
100
+ db: FindingsDB,
101
+ include_noise: bool,
102
+ ) -> Dict[str, Any]:
103
+ units = state.get_units()
104
+
105
+ def _first_val(cid: str) -> str:
106
+ res = db.query_findings(catalog_ids=[cid], limit=1)
107
+ return res[0]["value"] if res else "-"
108
+
109
+ pkg = _first_val("APP-001")
110
+ ver = f"{_first_val('APP-003')} ({_first_val('APP-004')})"
111
+ sdk = f"min={_first_val('APP-005')} / target={_first_val('APP-006')}"
112
+ flags = _first_val("SEC-001")
113
+
114
+ certs = [
115
+ {"unit": r["unit_id"], "title": r["title"], "value": r["value"]}
116
+ for r in db.query_findings(catalog_ids=["SIG-002", "SIG-004", "SIG-006", "SIG-007"], limit=40)
117
+ ]
118
+ unprotected = db.query_findings(catalog_ids=["ACT-005", "SEC-008"], unique_only=True, limit=200)
119
+ secrets = db.query_findings(catalog_ids=["CFG-004", "CFG-005"], unique_only=True, limit=100)
120
+ custom_hits = db.query_findings(catalog_ids=["CUSTOM-*"], limit=200)
121
+ jni_hits = db.query_findings(catalog_ids=["NAT-005"], limit=200)
122
+ elf_hard = db.query_findings(catalog_ids=["NAT-003"], limit=100)
123
+
124
+ raw_domains = db.query_findings(catalog_ids=["NET-001"], unique_only=True, limit=500)
125
+ clean_domains = [
126
+ r["value"] for r in raw_domains
127
+ if include_noise or (r.get("scope") != "boilerplate" and r["value"].lower() not in BOILERPLATE_DOMAINS)
128
+ ]
129
+
130
+ app_cnt = len(db.query_findings(scopes=["app"]))
131
+ tp_cnt = len(db.query_findings(scopes=["third_party"]))
132
+
133
+ return {
134
+ "package": pkg,
135
+ "version": ver,
136
+ "sdk": sdk,
137
+ "security_flags": flags,
138
+ "stacks": [f"[{u.unit_id}] {u.name}: {u.primary_stack or 'Unknown'}" for u in units],
139
+ "certs": certs,
140
+ "counts": {
141
+ "unprotected_exported": len(unprotected),
142
+ "secrets": len(secrets),
143
+ "custom_rules": len(custom_hits),
144
+ "jni_functions": len(jni_hits),
145
+ "elf_libs": len(elf_hard),
146
+ "clean_domains": len(clean_domains),
147
+ "scope_app": app_cnt,
148
+ "scope_third_party": tp_cnt,
149
+ },
150
+ "top_domains": clean_domains[:45],
151
+ "unprotected_sample": [r["value"] for r in unprotected[:25]],
152
+ "secrets_sample": [
153
+ {"title": r["title"], "value": r["value"], "file": Path(r["file_path"]).name if r.get("file_path") else "-"}
154
+ for r in secrets[:15]
155
+ ],
156
+ "elf_hardening": [{"lib": r["title"], "value": r["value"]} for r in elf_hard[:20]],
157
+ }
158
+
159
+
160
+ HTML_TEMPLATE = r"""<!DOCTYPE html>
161
+ <html lang="__LANG__" dir="__DIR__" data-theme="dark">
162
+ <head>
163
+ <meta charset="utf-8">
164
+ <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5">
165
+ <title>__PAGE_TITLE__</title>
166
+ <style>
167
+ :root[data-theme="dark"] {
168
+ --bg: #111015;
169
+ --sidebar: #16141C;
170
+ --card: #1B1823;
171
+ --card2: #231F2D;
172
+ --border: #35293A;
173
+ --text: #F5EFE6;
174
+ --muted: #A39AA8;
175
+ --accent: #FF8C24;
176
+ --accent-hi: #FFA94D;
177
+ --accent2: #B83B5E;
178
+ --accent-soft: rgba(255, 140, 36, 0.14);
179
+ --crimson-soft: rgba(184, 59, 94, 0.16);
180
+ --ok: #34D399;
181
+ --ok-soft: rgba(52, 211, 153, 0.14);
182
+ --warn: #FBBF24;
183
+ --warn-soft: rgba(251, 191, 36, 0.14);
184
+ --bad: #F87171;
185
+ --bad-soft: rgba(248, 113, 113, 0.14);
186
+ --hover: #292233;
187
+ --grid-line: rgba(184, 59, 94, 0.06);
188
+ --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
189
+ }
190
+ :root[data-theme="light"] {
191
+ --bg: #FAF7F2;
192
+ --sidebar: #FFFFFF;
193
+ --card: #FFFFFF;
194
+ --card2: #F4EFE8;
195
+ --border: #E5D9CF;
196
+ --text: #1B1622;
197
+ --muted: #6E6273;
198
+ --accent: #EA580C;
199
+ --accent-hi: #F97316;
200
+ --accent2: #9E2A4B;
201
+ --accent-soft: rgba(234, 88, 12, 0.10);
202
+ --crimson-soft: rgba(158, 42, 75, 0.10);
203
+ --ok: #059669;
204
+ --ok-soft: rgba(5, 150, 105, 0.10);
205
+ --warn: #D97706;
206
+ --warn-soft: rgba(217, 119, 6, 0.10);
207
+ --bad: #DC2626;
208
+ --bad-soft: rgba(220, 38, 38, 0.10);
209
+ --hover: #F6EFE6;
210
+ --grid-line: rgba(158, 42, 75, 0.04);
211
+ --shadow: 0 4px 18px rgba(27, 22, 34, 0.07);
212
+ }
213
+ * { box-sizing: border-box; }
214
+ html, body {
215
+ margin: 0; padding: 0; min-height: 100%;
216
+ background: var(--bg);
217
+ background-image:
218
+ linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
219
+ linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
220
+ background-size: 34px 34px;
221
+ color: var(--text);
222
+ font-family: system-ui, -apple-system, "Segoe UI", Roboto, Tahoma, Arial, sans-serif;
223
+ line-height: 1.48;
224
+ }
225
+ .app-shell { display: flex; min-height: 100vh; }
226
+
227
+ /* Sidebar */
228
+ .sidebar {
229
+ width: 274px; flex-shrink: 0; background: var(--sidebar);
230
+ border-inline-end: 1px solid var(--border);
231
+ display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 40;
232
+ transition: transform 0.22s ease;
233
+ }
234
+ .brand-box {
235
+ padding: 18px 16px; border-bottom: 1px solid var(--border);
236
+ background: linear-gradient(145deg, var(--card) 0%, var(--sidebar) 100%);
237
+ display: flex; align-items: center; gap: 12px;
238
+ }
239
+ .logo-mark {
240
+ width: 42px; height: 42px; border-radius: 10px; flex-shrink: 0;
241
+ background: radial-gradient(circle at 70% 35%, rgba(255,140,36,0.22), rgba(184,59,94,0.18) 70%, transparent);
242
+ border: 1px solid rgba(184, 59, 94, 0.55);
243
+ display: flex; align-items: center; justify-content: center;
244
+ box-shadow: 0 0 18px rgba(255, 140, 36, 0.16);
245
+ }
246
+ .brand-name { font-weight: 800; font-size: 18px; letter-spacing: 0.2px; display: flex; align-items: center; gap: 7px; }
247
+ .brand-dex { color: var(--accent); }
248
+ .brand-sect { color: var(--text); }
249
+ .brand-ver {
250
+ font-size: 10px; padding: 2px 7px; border-radius: 999px;
251
+ background: var(--crimson-soft); color: var(--accent-hi);
252
+ border: 1px solid rgba(184, 59, 94, 0.4); font-weight: 700;
253
+ }
254
+ .brand-sub { font-size: 11px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 185px; }
255
+
256
+ .nav-scroll { flex: 1; overflow-y: auto; padding: 12px 10px; }
257
+ .nav-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.9px; color: var(--accent2); padding: 10px 10px 5px; font-weight: 800; }
258
+ .nav-item {
259
+ display: flex; align-items: center; justify-content: space-between; gap: 8px;
260
+ padding: 9px 11px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600;
261
+ color: var(--text); margin-bottom: 3px; border: 1px solid transparent; transition: 0.14s;
262
+ }
263
+ .nav-item:hover { background: var(--hover); border-color: var(--border); }
264
+ .nav-item.active {
265
+ background: linear-gradient(90deg, var(--accent-soft), var(--crimson-soft));
266
+ color: var(--accent); border-color: rgba(255, 140, 36, 0.4);
267
+ }
268
+ .nav-cnt { font-size: 11px; font-family: ui-monospace, monospace; padding: 1px 7px; border-radius: 999px; background: var(--card2); color: var(--muted); }
269
+ .nav-item.active .nav-cnt { background: var(--accent); color: #111015; font-weight: 800; }
270
+
271
+ .sidebar-foot { padding: 12px; border-top: 1px solid var(--border); display: flex; gap: 8px; }
272
+ .sidebar-foot button { flex: 1; }
273
+
274
+ /* Main shell */
275
+ .main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
276
+ .topbar {
277
+ position: sticky; top: 0; z-index: 25;
278
+ background: var(--card); border-bottom: 1px solid var(--border);
279
+ padding: 11px 18px; display: flex; align-items: center; justify-content: space-between; gap: 10px;
280
+ }
281
+ .topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
282
+ .menu-btn { display: none; padding: 6px 10px; font-size: 18px; line-height: 1; border-color: var(--border); }
283
+ .topbar-title { font-size: 15.5px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
284
+ .topbar-meta { font-size: 11.5px; color: var(--muted); }
285
+ .topbar-actions { display: flex; gap: 6px; flex-wrap: wrap; }
286
+
287
+ button, select, input {
288
+ background: var(--card2); color: var(--text); border: 1px solid var(--border);
289
+ border-radius: 8px; padding: 7px 11px; font-size: 12.5px; min-height: 36px; font-family: inherit;
290
+ }
291
+ input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
292
+ button { cursor: pointer; font-weight: 600; transition: 0.14s; }
293
+ button:hover { border-color: var(--accent); }
294
+ .btn-accent {
295
+ background: linear-gradient(135deg, var(--accent), #E66D12);
296
+ color: #111015; border-color: var(--accent); font-weight: 800;
297
+ }
298
+ .btn-accent:hover { filter: brightness(1.08); }
299
+ .btn-sm { padding: 4px 9px; font-size: 11.5px; min-height: 28px; }
300
+
301
+ .content { padding: 18px; max-width: 1460px; width: 100%; margin: 0 auto; }
302
+
303
+ /* Executive Dashboard */
304
+ .kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
305
+ .kpi {
306
+ background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 14px;
307
+ box-shadow: var(--shadow); border-top: 3px solid var(--accent); position: relative; overflow: hidden;
308
+ }
309
+ .kpi:nth-child(even) { border-top-color: var(--accent2); }
310
+ .kpi-val { font-size: 24px; font-weight: 800; color: var(--accent); line-height: 1.1; }
311
+ .kpi:nth-child(even) .kpi-val { color: var(--text); }
312
+ .kpi-lbl { font-size: 12px; color: var(--muted); margin-top: 5px; font-weight: 600; }
313
+
314
+ .exec-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 14px; }
315
+ .card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 15px; box-shadow: var(--shadow); }
316
+ .card h3 {
317
+ margin: 0 0 12px; font-size: 14px; font-weight: 800; color: var(--accent);
318
+ display: flex; justify-content: space-between; align-items: center;
319
+ border-bottom: 1px solid var(--border); padding-bottom: 8px;
320
+ }
321
+ .kv { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: 12.5px; }
322
+ .kv:last-child { border-bottom: none; }
323
+ .kv-k { color: var(--muted); flex-shrink: 0; }
324
+ .kv-v { text-align: end; word-break: break-word; }
325
+
326
+ .bar-row { margin-bottom: 9px; cursor: pointer; }
327
+ .bar-row:hover .bar-lbl { color: var(--accent); }
328
+ .bar-head { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 3px; font-weight: 600; }
329
+ .bar-track { height: 7px; border-radius: 999px; background: var(--card2); overflow: hidden; }
330
+ .bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--accent2), var(--accent)); }
331
+
332
+ .ratio-bar { display: flex; height: 12px; border-radius: 999px; overflow: hidden; background: var(--card2); margin: 10px 0 6px; border: 1px solid var(--border); }
333
+ .ratio-app { background: var(--ok); }
334
+ .ratio-3p { background: var(--accent); }
335
+
336
+ .chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
337
+ .chip {
338
+ padding: 4px 9px; border-radius: 6px; font-size: 11.5px; background: var(--card2);
339
+ border: 1px solid var(--border); font-family: ui-monospace, monospace; direction: ltr; color: var(--text);
340
+ }
341
+
342
+ /* Explorer / Flexible View */
343
+ .controls-panel {
344
+ background: var(--card); border: 1px solid var(--border); border-radius: 12px;
345
+ padding: 12px; margin-bottom: 12px; box-shadow: var(--shadow);
346
+ }
347
+ .ctrl-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
348
+ .ctrl-row:last-child { margin-bottom: 0; }
349
+ .search-input { flex: 2; min-width: 200px; }
350
+ .excl-input { flex: 1; min-width: 160px; }
351
+ .toggle-pill {
352
+ display: inline-flex; align-items: center; gap: 5px; padding: 6px 10px;
353
+ border-radius: 8px; border: 1px solid var(--border); background: var(--card2);
354
+ font-size: 12px; cursor: pointer; user-select: none; min-height: 36px;
355
+ }
356
+ .toggle-pill.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 700; }
357
+
358
+ .view-seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
359
+ .view-seg button { border: none; border-radius: 0; border-inline-end: 1px solid var(--border); padding: 6px 11px; min-height: 34px; }
360
+ .view-seg button:last-child { border-inline-end: none; }
361
+ .view-seg button.active { background: var(--accent); color: #111015; font-weight: 800; }
362
+
363
+ .cid-bar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding-top: 8px; border-top: 1px solid var(--border); margin-top: 8px; }
364
+ .cid-chip {
365
+ padding: 3px 9px; border-radius: 999px; font-size: 11px; font-family: ui-monospace, monospace;
366
+ background: var(--card2); border: 1px solid var(--border); cursor: pointer; user-select: none;
367
+ }
368
+ .cid-chip:hover { border-color: var(--accent2); }
369
+ .cid-chip.selected { background: var(--accent); color: #111015; border-color: var(--accent); font-weight: 800; }
370
+
371
+ .col-menu-wrap { position: relative; }
372
+ .col-dropdown {
373
+ position: absolute; top: 40px; inset-inline-end: 0; z-index: 30;
374
+ background: var(--card); border: 1px solid var(--border); border-radius: 10px;
375
+ padding: 10px; min-width: 175px; box-shadow: var(--shadow); display: none;
376
+ }
377
+ .col-dropdown.open { display: block; }
378
+ .col-opt { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 12.5px; cursor: pointer; }
379
+ .col-opt input { min-height: auto; width: 15px; height: 15px; accent-color: var(--accent); }
380
+
381
+ .status-bar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; font-size: 12px; color: var(--muted); }
382
+
383
+ /* Desktop Table */
384
+ .table-wrap { background: var(--card); border: 1px solid var(--border); border-radius: 12px; overflow-x: auto; box-shadow: var(--shadow); }
385
+ table { width: 100%; border-collapse: collapse; font-size: 13px; }
386
+ th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: start; vertical-align: top; }
387
+ th { background: var(--card2); font-size: 11.5px; color: var(--muted); font-weight: 700; white-space: nowrap; }
388
+ tbody tr { cursor: pointer; transition: background 0.1s; }
389
+ tbody tr:hover { background: var(--hover); }
390
+
391
+ .badge {
392
+ display: inline-block; padding: 2px 8px; border-radius: 5px; font-family: ui-monospace, monospace;
393
+ font-size: 11px; font-weight: 800; background: var(--accent-soft); color: var(--accent);
394
+ border: 1px solid rgba(255, 140, 36, 0.3); direction: ltr; white-space: nowrap;
395
+ }
396
+ .pill { display: inline-block; padding: 2px 6px; border-radius: 5px; font-size: 11px; background: var(--card2); border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
397
+ .sc-app { background: var(--ok-soft); color: var(--ok); border-color: rgba(52,211,153,0.35); }
398
+ .sc-3p { background: var(--crimson-soft); color: var(--accent-hi); border-color: rgba(184,59,94,0.4); }
399
+ .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-word; font-size: 12px; direction: ltr; }
400
+ .val-clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
401
+
402
+ /* Card Grid View */
403
+ .cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 10px; }
404
+ .f-card {
405
+ background: var(--card); border: 1px solid var(--border); border-radius: 10px;
406
+ padding: 12px; display: flex; flex-direction: column; gap: 8px; cursor: pointer;
407
+ box-shadow: var(--shadow); transition: border-color 0.14s, transform 0.12s;
408
+ }
409
+ .f-card:hover { border-color: var(--accent); transform: translateY(-1px); }
410
+ .f-card-top { display: flex; justify-content: space-between; align-items: center; gap: 6px; flex-wrap: wrap; }
411
+ .f-card-pills { display: flex; gap: 4px; flex-wrap: wrap; }
412
+ .f-card-title { font-size: 13px; font-weight: 700; color: var(--text); }
413
+ .f-card-val { background: var(--card2); border: 1px solid var(--border); border-radius: 6px; padding: 7px 9px; font-size: 12px; max-height: 92px; overflow: hidden; }
414
+ .f-card-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); }
415
+
416
+ /* Grouped Accordion View */
417
+ .grp-box { background: var(--card); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; overflow: hidden; }
418
+ .grp-sum { padding: 11px 14px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--card2); font-weight: 700; font-size: 13px; list-style: none; }
419
+ .grp-sum-left { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
420
+ .grp-desc { font-weight: 400; font-size: 12px; color: var(--muted); }
421
+ .grp-body { padding: 10px 14px; }
422
+ .grp-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--border); cursor: pointer; }
423
+ .grp-row:last-child { border-bottom: none; }
424
+ .grp-row:hover { color: var(--accent); }
425
+
426
+ /* Modal Inspector Drawer */
427
+ .modal-bg {
428
+ position: fixed; inset: 0; background: rgba(9, 8, 12, 0.75); z-index: 60;
429
+ display: none; align-items: center; justify-content: center; padding: 14px;
430
+ }
431
+ .modal-bg.open { display: flex; }
432
+ .modal {
433
+ background: var(--card); border: 1px solid var(--border); border-radius: 14px;
434
+ max-width: 720px; width: 100%; max-height: 88vh; display: flex; flex-direction: column;
435
+ box-shadow: 0 20px 55px rgba(0, 0, 0, 0.65); border-top: 3px solid var(--accent);
436
+ }
437
+ .modal-hdr { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
438
+ .modal-hdr h3 { margin: 0; font-size: 15px; color: var(--accent); }
439
+ .modal-body { padding: 16px 18px; overflow-y: auto; font-size: 13px; }
440
+ .detail-block { margin-bottom: 12px; }
441
+ .detail-lbl { font-size: 11px; text-transform: uppercase; color: var(--accent2); font-weight: 800; margin-bottom: 4px; letter-spacing: 0.4px; }
442
+ .detail-pre {
443
+ background: var(--card2); border: 1px solid var(--border); border-radius: 8px;
444
+ padding: 10px; font-family: ui-monospace, monospace; font-size: 12px;
445
+ white-space: pre-wrap; word-break: break-word; direction: ltr; margin: 0; color: var(--text);
446
+ }
447
+
448
+ .backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 35; }
449
+ .backdrop.open { display: block; }
450
+ .load-more { text-align: center; padding: 14px; }
451
+ .empty-box { text-align: center; padding: 32px; color: var(--muted); background: var(--card); border-radius: 12px; border: 1px solid var(--border); }
452
+
453
+ @media (max-width: 960px) {
454
+ .sidebar { position: fixed; top: 0; bottom: 0; inset-inline-start: 0; transform: translateX(-105%); }
455
+ html[dir="rtl"] .sidebar { transform: translateX(105%); }
456
+ .sidebar.open { transform: translateX(0) !important; }
457
+ .menu-btn { display: inline-flex; align-items: center; justify-content: center; }
458
+ }
459
+ @media (max-width: 640px) {
460
+ .content { padding: 10px; }
461
+ .topbar { padding: 10px 12px; }
462
+ .kpis { grid-template-columns: repeat(2, 1fr); gap: 8px; }
463
+ .exec-grid { grid-template-columns: 1fr; }
464
+ .cards-grid { grid-template-columns: 1fr; }
465
+ .ctrl-row > select { flex: 1 1 45%; }
466
+ .search-input, .excl-input { flex: 1 1 100%; }
467
+ .topbar-actions .hide-mob { display: none; }
468
+ }
469
+ </style>
470
+ </head>
471
+ <body>
472
+ <div class="backdrop" id="backdrop" onclick="toggleSidebar(false)"></div>
473
+ <div class="app-shell">
474
+ <aside class="sidebar" id="sidebar">
475
+ <div class="brand-box">
476
+ <div class="logo-mark" aria-hidden="true">
477
+ <svg width="26" height="26" viewBox="0 0 24 24" fill="none">
478
+ <defs>
479
+ <linearGradient id="dsGrad" x1="0" y1="0" x2="1" y2="1">
480
+ <stop offset="0%" stop-color="#B83B5E"/>
481
+ <stop offset="100%" stop-color="#FF8C24"/>
482
+ </linearGradient>
483
+ </defs>
484
+ <path d="M12 2L4 5.5V11.5C4 16.8 7.4 21.1 12 22.5C16.6 21.1 20 16.8 20 11.5V5.5L12 2Z" stroke="url(#dsGrad)" stroke-width="1.8" fill="rgba(184,59,94,0.12)"/>
485
+ <line x1="12" y1="3.2" x2="12" y2="21.5" stroke="#B83B5E" stroke-width="1.2" opacity="0.8"/>
486
+ <path d="M7 9H9.5V12H8M7 15H9.5" stroke="#B83B5E" stroke-width="1.3" stroke-linecap="round"/>
487
+ <circle cx="15.5" cy="9" r="1.2" fill="#FF8C24"/>
488
+ <path d="M14.5 13H17M15.5 16H17.5" stroke="#FF8C24" stroke-width="1.4" stroke-linecap="round"/>
489
+ <circle cx="17.5" cy="13" r="1" fill="#FFA94D"/>
490
+ </svg>
491
+ </div>
492
+ <div>
493
+ <div class="brand-name"><span class="brand-dex">Dex</span><span class="brand-sect">Sect</span> <span class="brand-ver">v__VERSION__</span></div>
494
+ <div class="brand-sub" title="__TARGET_NAME__">__TARGET_NAME__</div>
495
+ </div>
496
+ </div>
497
+ <div class="nav-scroll" id="navList"></div>
498
+ <div class="sidebar-foot">
499
+ <button onclick="toggleTheme()" id="themeBtn">Theme</button>
500
+ </div>
501
+ </aside>
502
+
503
+ <div class="main">
504
+ <header class="topbar">
505
+ <div class="topbar-left">
506
+ <button class="menu-btn" onclick="toggleSidebar(true)" aria-label="Menu">☰</button>
507
+ <div>
508
+ <div class="topbar-title" id="pageHeaderTitle">__REPORT_TITLE__</div>
509
+ <div class="topbar-meta">__PROFILE_LABEL__: <strong>__PROFILE__</strong> &bull; __GEN_LABEL__: __GENERATED__</div>
510
+ </div>
511
+ </div>
512
+ <div class="topbar-actions">
513
+ <button class="btn-accent btn-sm" onclick="exportFiltered('json')">__BTN_EXPORT_JSON__</button>
514
+ <button class="btn-sm hide-mob" onclick="exportFiltered('csv')">__BTN_CSV__</button>
515
+ <button class="btn-sm hide-mob" onclick="exportFiltered('txt')">__BTN_TXT__</button>
516
+ </div>
517
+ </header>
518
+
519
+ <main class="content">
520
+ <div id="execView"></div>
521
+ <div id="explorerView" style="display:none">
522
+ <div class="controls-panel">
523
+ <div class="ctrl-row">
524
+ <input class="search-input" type="text" id="searchBox" placeholder="__SEARCH_PH__" oninput="resetAndRender()">
525
+ <input class="excl-input" type="text" id="excludeBox" placeholder="__EXCLUDE_PH__" oninput="resetAndRender()">
526
+ <span class="toggle-pill" id="regexToggle" onclick="toggleRegex()"><code>.*</code> __REGEX_LBL__</span>
527
+ <div class="view-seg">
528
+ <button id="vBtnTable" onclick="setViewMode('table')">__VIEW_TABLE__</button>
529
+ <button id="vBtnCards" onclick="setViewMode('cards')">__VIEW_CARDS__</button>
530
+ <button id="vBtnGrouped" onclick="setViewMode('grouped')">__VIEW_GROUPED__</button>
531
+ </div>
532
+ </div>
533
+ <div class="ctrl-row">
534
+ <select id="scopeFilter" onchange="resetAndRender()">
535
+ <option value="">__ALL_SCOPES__</option>
536
+ <option value="app">__SCOPE_APP__</option>
537
+ <option value="third_party">__SCOPE_3P__</option>
538
+ </select>
539
+ <select id="unitFilter" onchange="resetAndRender()"><option value="">__ALL_UNITS__</option></select>
540
+ <select id="layerFilter" onchange="resetAndRender()"><option value="">__ALL_LAYERS__</option></select>
541
+ <select id="sortFilter" onchange="resetAndRender()">
542
+ <option value="id">__SORT_ID__</option>
543
+ <option value="hits">__SORT_HITS__</option>
544
+ <option value="title">__SORT_TITLE__</option>
545
+ <option value="source">__SORT_SOURCE__</option>
546
+ </select>
547
+ <div class="col-menu-wrap">
548
+ <button onclick="toggleColMenu()" id="colMenuBtn">__COLS_BTN__ ▾</button>
549
+ <div class="col-dropdown" id="colDropdown"></div>
550
+ </div>
551
+ <button class="btn-sm" onclick="clearAllFilters()">__CLEAR_BTN__</button>
552
+ </div>
553
+ <div class="cid-bar" id="cidBar"></div>
554
+ </div>
555
+
556
+ <div class="status-bar">
557
+ <span id="statusNote"></span>
558
+ <div>
559
+ <button class="btn-sm" onclick="exportFiltered('csv')">__BTN_CSV__</button>
560
+ <button class="btn-sm" onclick="exportFiltered('txt')">__BTN_TXT__</button>
561
+ </div>
562
+ </div>
563
+
564
+ <div id="resultsContainer"></div>
565
+ <div id="loadMoreWrap" class="load-more" style="display:none">
566
+ <button onclick="loadMore()">__LOAD_MORE__</button>
567
+ </div>
568
+ </div>
569
+ </main>
570
+ </div>
571
+ </div>
572
+
573
+ <div class="modal-bg" id="detailModal" onclick="if(event.target===this) closeModal()">
574
+ <div class="modal">
575
+ <div class="modal-hdr">
576
+ <h3 id="modalTitle">__DETAILS_TITLE__</h3>
577
+ <button class="btn-sm" onclick="closeModal()">__CLOSE_BTN__</button>
578
+ </div>
579
+ <div class="modal-body" id="modalBody"></div>
580
+ </div>
581
+ </div>
582
+
583
+ <script>
584
+ const REPORT = __DEXSECT_JSON__;
585
+ const UI = REPORT.locale.ui;
586
+ const CAT = REPORT.catalog_specs || {};
587
+ let activeKey = "executive";
588
+ let viewMode = window.innerWidth <= 768 ? "cards" : "table";
589
+ let useRegex = false;
590
+ let selectedCids = new Set();
591
+ let currentFiltered = [];
592
+ let pageLimit = 100;
593
+
594
+ const COLS = [
595
+ { key: "unit", label: UI.col_unit, on: true },
596
+ { key: "scope", label: UI.col_scope, on: true },
597
+ { key: "layer", label: UI.col_layer, on: true },
598
+ { key: "title", label: UI.col_title, on: true },
599
+ { key: "hits", label: UI.col_hits, on: true },
600
+ { key: "source", label: UI.col_source, on: true },
601
+ ];
602
+
603
+ function esc(s) {
604
+ return String(s ?? "").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");
605
+ }
606
+
607
+ function toggleSidebar(open) {
608
+ document.getElementById("sidebar").classList.toggle("open", open);
609
+ document.getElementById("backdrop").classList.toggle("open", open);
610
+ }
611
+
612
+ function toggleTheme() {
613
+ const root = document.documentElement;
614
+ root.setAttribute("data-theme", root.getAttribute("data-theme") === "dark" ? "light" : "dark");
615
+ }
616
+
617
+ function getSectionRows(key) {
618
+ if (key === "all_findings") {
619
+ return REPORT.sections.filter(s => Array.isArray(s.rows) && s.rows.length).flatMap(s => s.rows);
620
+ }
621
+ const s = REPORT.sections.find(x => x.key === key);
622
+ return s ? (s.rows || []) : [];
623
+ }
624
+
625
+ function init() {
626
+ const allRows = getSectionRows("all_findings");
627
+ const nav = document.getElementById("navList");
628
+
629
+ let htmlNav = `<div class="nav-label">${esc(UI.nav_overview)}</div>`;
630
+ htmlNav += navItemHtml("executive", REPORT.sections[0].title, REPORT.units.length);
631
+ htmlNav += navItemHtml("all_findings", UI.all_findings, allRows.length);
632
+ htmlNav += `<div class="nav-label">${esc(UI.nav_domains)}</div>`;
633
+ REPORT.sections.slice(1).forEach(s => {
634
+ htmlNav += navItemHtml(s.key, s.title, s.count);
635
+ });
636
+ nav.innerHTML = htmlNav;
637
+
638
+ const uSel = document.getElementById("unitFilter");
639
+ REPORT.units.forEach(u => {
640
+ const o = document.createElement("option");
641
+ o.value = u.id;
642
+ o.textContent = `[${u.id}] ${u.name}`;
643
+ uSel.appendChild(o);
644
+ });
645
+
646
+ const colDrop = document.getElementById("colDropdown");
647
+ colDrop.innerHTML = COLS.map((c, idx) =>
648
+ `<label class="col-opt"><input type="checkbox" ${c.on ? "checked" : ""} onchange="toggleCol(${idx}, this.checked)"> ${esc(c.label)}</label>`
649
+ ).join("");
650
+
651
+ renderExecutive();
652
+ updateViewButtons();
653
+ switchSection("executive");
654
+ }
655
+
656
+ function navItemHtml(key, title, count) {
657
+ return `<div class="nav-item" data-key="${esc(key)}" onclick="switchSection('${esc(key)}')">
658
+ <span>${esc(title)}</span><span class="nav-cnt">${count}</span>
659
+ </div>`;
660
+ }
661
+
662
+ function switchSection(key) {
663
+ activeKey = key;
664
+ selectedCids.clear();
665
+ pageLimit = 100;
666
+ document.querySelectorAll(".nav-item").forEach(el => el.classList.toggle("active", el.dataset.key === key));
667
+ toggleSidebar(false);
668
+
669
+ const isExec = key === "executive";
670
+ document.getElementById("execView").style.display = isExec ? "block" : "none";
671
+ document.getElementById("explorerView").style.display = isExec ? "none" : "block";
672
+
673
+ const secObj = REPORT.sections.find(s => s.key === key);
674
+ document.getElementById("pageHeaderTitle").textContent = key === "all_findings" ? UI.all_findings : (secObj ? secObj.title : UI.report_title);
675
+
676
+ if (!isExec) {
677
+ populateDynamicFilters();
678
+ renderExplorer();
679
+ }
680
+ }
681
+
682
+ function renderExecutive() {
683
+ const ex = REPORT.executive;
684
+ const kpiCards = REPORT.kpis.map(k =>
685
+ `<div class="kpi"><div class="kpi-val">${esc(k.val)}</div><div class="kpi-lbl">${esc(k.lbl)}</div></div>`
686
+ ).join("");
687
+
688
+ const appCnt = ex.counts.scope_app || 0;
689
+ const tpCnt = ex.counts.scope_third_party || 0;
690
+ const totScope = Math.max(1, appCnt + tpCnt);
691
+ const appPct = Math.round((appCnt * 100) / totScope);
692
+ const tpPct = 100 - appPct;
693
+
694
+ const domBars = REPORT.sections.slice(1).filter(s => s.count > 0);
695
+ const maxDom = Math.max(1, ...domBars.map(s => s.count));
696
+ const barsHtml = domBars.map(s => {
697
+ const w = Math.max(4, Math.round((s.count * 100) / maxDom));
698
+ return `<div class="bar-row" onclick="switchSection('${esc(s.key)}')">
699
+ <div class="bar-head"><span class="bar-lbl">${esc(s.title)}</span><span>${s.count}</span></div>
700
+ <div class="bar-track"><div class="bar-fill" style="width:${w}%"></div></div>
701
+ </div>`;
702
+ }).join("");
703
+
704
+ const certsHtml = (ex.certs || []).slice(0, 10).map(c =>
705
+ `<div class="kv"><span class="kv-k">[${esc(c.unit)}] ${esc(c.title)}</span><span class="kv-v mono">${esc(c.value)}</span></div>`
706
+ ).join("") || `<div class="kv"><span class="kv-k">-</span><span>No cert data</span></div>`;
707
+
708
+ const elfHtml = (ex.elf_hardening || []).map(e =>
709
+ `<div class="kv"><span class="kv-k">${esc(e.lib)}</span><span class="kv-v mono">${esc(e.value)}</span></div>`
710
+ ).join("") || `<div class="kv"><span class="kv-k">-</span><span>No native .so files</span></div>`;
711
+
712
+ const domChips = (ex.top_domains || []).map(d => `<span class="chip">${esc(d)}</span>`).join("") || "-";
713
+ const unprotHtml = (ex.unprotected_sample || []).slice(0, 12).map(a =>
714
+ `<div class="kv"><span class="mono">${esc(a)}</span></div>`
715
+ ).join("") || `<div class="kv"><span>None</span></div>`;
716
+
717
+ document.getElementById("execView").innerHTML = `
718
+ <div class="kpis">${kpiCards}</div>
719
+ <div class="exec-grid">
720
+ <div class="card">
721
+ <h3>${esc(UI.exec_identity)}</h3>
722
+ <div class="kv"><span class="kv-k">${esc(UI.lbl_package)}</span><span class="kv-v mono">${esc(ex.package)}</span></div>
723
+ <div class="kv"><span class="kv-k">${esc(UI.lbl_version)}</span><span class="kv-v mono">${esc(ex.version)}</span></div>
724
+ <div class="kv"><span class="kv-k">${esc(UI.lbl_sdk)}</span><span class="kv-v mono">${esc(ex.sdk)}</span></div>
725
+ <div class="kv"><span class="kv-k">${esc(UI.lbl_stack)}</span><span class="kv-v mono">${esc((ex.stacks || []).join(" | "))}</span></div>
726
+ ${certsHtml}
727
+ </div>
728
+ <div class="card">
729
+ <h3>${esc(UI.exec_surface)}</h3>
730
+ <div class="kv"><span class="kv-k">Flags</span><span class="kv-v mono">${esc(ex.security_flags)}</span></div>
731
+ <div class="kv"><span class="kv-k">${esc(UI.lbl_unprotected)}</span><span class="kv-v mono">${ex.counts.unprotected_exported}</span></div>
732
+ <div class="kv"><span class="kv-k">${esc(UI.lbl_secrets)}</span><span class="kv-v mono">${ex.counts.secrets}</span></div>
733
+ <div class="kv"><span class="kv-k">${esc(UI.lbl_custom_rules)}</span><span class="kv-v mono">${ex.counts.custom_rules}</span></div>
734
+ <div style="margin-top:10px;">
735
+ <div class="bar-head"><span>${esc(UI.exec_scope_split)}</span><span>app ${appPct}% / 3rd-party ${tpPct}%</span></div>
736
+ <div class="ratio-bar"><div class="ratio-app" style="width:${appPct}%"></div><div class="ratio-3p" style="width:${tpPct}%"></div></div>
737
+ </div>
738
+ ${elfHtml}
739
+ </div>
740
+ <div class="card">
741
+ <h3>${esc(UI.nav_domains)}</h3>
742
+ ${barsHtml}
743
+ </div>
744
+ <div class="card">
745
+ <h3>${esc(UI.exec_domains)} (${ex.counts.clean_domains})</h3>
746
+ <div class="chip-list">${domChips}</div>
747
+ <h3 style="margin-top:14px">${esc(UI.lbl_unprotected)} (${ex.counts.unprotected_exported})</h3>
748
+ ${unprotHtml}
749
+ </div>
750
+ </div>
751
+ `;
752
+ }
753
+
754
+ function populateDynamicFilters() {
755
+ const rows = getSectionRows(activeKey);
756
+ const lSel = document.getElementById("layerFilter");
757
+ lSel.innerHTML = `<option value="">${esc(UI.all_layers)}</option>`;
758
+ [...new Set(rows.map(r => r.layer).filter(Boolean))].sort().forEach(ly => {
759
+ const o = document.createElement("option"); o.value = ly; o.textContent = ly; lSel.appendChild(o);
760
+ });
761
+
762
+ const cidCounts = {};
763
+ rows.forEach(r => { cidCounts[r.catalog_id] = (cidCounts[r.catalog_id] || 0) + 1; });
764
+ const bar = document.getElementById("cidBar");
765
+ const entries = Object.entries(cidCounts).sort((a, b) => a[0].localeCompare(b[0]));
766
+ if (entries.length === 0) {
767
+ bar.innerHTML = "";
768
+ return;
769
+ }
770
+ bar.innerHTML = `<span style="font-size:11.5px;color:var(--muted)">${esc(UI.quick_id_hint)}</span>` +
771
+ entries.map(([cid, cnt]) =>
772
+ `<span class="cid-chip ${selectedCids.has(cid) ? "selected" : ""}" onclick="toggleCid('${esc(cid)}')" title="${esc(CAT[cid]?.name || cid)}">${esc(cid)} (${cnt})</span>`
773
+ ).join("");
774
+ }
775
+
776
+ function toggleCid(cid) {
777
+ if (selectedCids.has(cid)) selectedCids.delete(cid);
778
+ else selectedCids.add(cid);
779
+ populateDynamicFilters();
780
+ resetAndRender();
781
+ }
782
+
783
+ function toggleRegex() {
784
+ useRegex = !useRegex;
785
+ document.getElementById("regexToggle").classList.toggle("on", useRegex);
786
+ resetAndRender();
787
+ }
788
+
789
+ function setViewMode(mode) {
790
+ viewMode = mode;
791
+ updateViewButtons();
792
+ renderExplorer();
793
+ }
794
+
795
+ function updateViewButtons() {
796
+ document.getElementById("vBtnTable").classList.toggle("active", viewMode === "table");
797
+ document.getElementById("vBtnCards").classList.toggle("active", viewMode === "cards");
798
+ document.getElementById("vBtnGrouped").classList.toggle("active", viewMode === "grouped");
799
+ }
800
+
801
+ function toggleColMenu() {
802
+ document.getElementById("colDropdown").classList.toggle("open");
803
+ }
804
+
805
+ function toggleCol(idx, checked) {
806
+ COLS[idx].on = checked;
807
+ renderExplorer();
808
+ }
809
+
810
+ function clearAllFilters() {
811
+ document.getElementById("searchBox").value = "";
812
+ document.getElementById("excludeBox").value = "";
813
+ document.getElementById("scopeFilter").value = "";
814
+ document.getElementById("unitFilter").value = "";
815
+ document.getElementById("layerFilter").value = "";
816
+ selectedCids.clear();
817
+ useRegex = false;
818
+ document.getElementById("regexToggle").classList.remove("on");
819
+ populateDynamicFilters();
820
+ resetAndRender();
821
+ }
822
+
823
+ function resetAndRender() { pageLimit = 100; renderExplorer(); }
824
+ function loadMore() { pageLimit += 200; renderExplorer(); }
825
+
826
+ function renderExplorer() {
827
+ const rows = getSectionRows(activeKey);
828
+ const qRaw = document.getElementById("searchBox").value.trim();
829
+ const exclRaw = document.getElementById("excludeBox").value.trim().toLowerCase();
830
+ const scopeVal = document.getElementById("scopeFilter").value;
831
+ const unitVal = document.getElementById("unitFilter").value;
832
+ const layerVal = document.getElementById("layerFilter").value;
833
+ const sortVal = document.getElementById("sortFilter").value;
834
+
835
+ let rx = null;
836
+ if (qRaw && useRegex) {
837
+ try { rx = new RegExp(qRaw, "i"); } catch (e) { rx = null; }
838
+ }
839
+ const qLow = qRaw.toLowerCase();
840
+ const exclTerms = exclRaw ? exclRaw.split(",").map(s => s.trim()).filter(Boolean) : [];
841
+
842
+ currentFiltered = rows.filter(r => {
843
+ if (selectedCids.size > 0 && !selectedCids.has(r.catalog_id)) return false;
844
+ if (scopeVal && (r.scope || "app") !== scopeVal) return false;
845
+ if (unitVal && r.unit_id !== unitVal) return false;
846
+ if (layerVal && r.layer !== layerVal) return false;
847
+ const blob = `${r.catalog_id} ${r.title} ${r.value} ${r.file_path} ${r.class_name}`.toLowerCase();
848
+ if (qRaw) {
849
+ if (rx) { if (!rx.test(blob)) return false; }
850
+ else if (!blob.includes(qLow)) return false;
851
+ }
852
+ for (const ex of exclTerms) {
853
+ if (blob.includes(ex)) return false;
854
+ }
855
+ return true;
856
+ });
857
+
858
+ if (sortVal === "hits") currentFiltered.sort((a, b) => (b.hits || 1) - (a.hits || 1));
859
+ else if (sortVal === "title") currentFiltered.sort((a, b) => String(a.title).localeCompare(String(b.title)));
860
+ else if (sortVal === "source") currentFiltered.sort((a, b) => String(a.file_path).localeCompare(String(b.file_path)));
861
+
862
+ const shown = currentFiltered.slice(0, pageLimit);
863
+ const secTitle = activeKey === "all_findings" ? UI.all_findings : (REPORT.sections.find(s => s.key === activeKey)?.title || "");
864
+ document.getElementById("statusNote").textContent = UI.showing_note
865
+ .replace("{shown}", shown.length)
866
+ .replace("{filtered}", currentFiltered.length)
867
+ .replace("{section}", secTitle);
868
+
869
+ const container = document.getElementById("resultsContainer");
870
+ const loadWrap = document.getElementById("loadMoreWrap");
871
+
872
+ if (shown.length === 0) {
873
+ container.innerHTML = `<div class="empty-box">${esc(UI.empty_rows)}</div>`;
874
+ loadWrap.style.display = "none";
875
+ return;
876
+ }
877
+
878
+ loadWrap.style.display = (viewMode !== "grouped" && currentFiltered.length > shown.length) ? "block" : "none";
879
+
880
+ if (viewMode === "table") {
881
+ const activeCols = COLS.filter(c => c.on);
882
+ const ths = `<th>${esc(UI.col_id)}</th>` +
883
+ activeCols.map(c => c.key === "title" ? `<th>${esc(c.label)}</th><th>${esc(UI.col_value)}</th>` : `<th>${esc(c.label)}</th>`).join("") +
884
+ (COLS.find(c => c.key === "title").on ? "" : `<th>${esc(UI.col_value)}</th>`);
885
+
886
+ const trs = shown.map((r, i) => {
887
+ const loc = r.file_path ? `${r.file_path.split("/").pop()}${r.line_no ? ":" + r.line_no : ""}` : "-";
888
+ const sc = r.scope || "app";
889
+ let tds = `<td><span class="badge">${esc(r.catalog_id)}</span></td>`;
890
+ if (COLS[0].on) tds += `<td><span class="pill">${esc(r.unit_id)}</span></td>`;
891
+ if (COLS[1].on) tds += `<td><span class="pill ${sc === "app" ? "sc-app" : "sc-3p"}">${esc(sc)}</span></td>`;
892
+ if (COLS[2].on) tds += `<td><span class="pill">${esc(r.layer || "-")}</span></td>`;
893
+ if (COLS[3].on) tds += `<td>${esc(r.title || "-")}</td>`;
894
+ tds += `<td><div class="mono val-clamp">${esc(r.value)}</div></td>`;
895
+ if (COLS[4].on) tds += `<td><span class="pill">×${r.hits || 1}</span></td>`;
896
+ if (COLS[5].on) tds += `<td class="mono">${esc(loc)}</td>`;
897
+ return `<tr onclick="openModal(${i})">${tds}</tr>`;
898
+ }).join("");
899
+
900
+ container.innerHTML = `<div class="table-wrap"><table><thead><tr>${ths}</tr></thead><tbody>${trs}</tbody></table></div>`;
901
+ } else if (viewMode === "cards") {
902
+ container.innerHTML = `<div class="cards-grid">` + shown.map((r, i) => {
903
+ const loc = r.file_path ? `${r.file_path.split("/").pop()}${r.line_no ? ":" + r.line_no : ""}` : "-";
904
+ const sc = r.scope || "app";
905
+ return `<div class="f-card" onclick="openModal(${i})">
906
+ <div class="f-card-top">
907
+ <span class="badge">${esc(r.catalog_id)}</span>
908
+ <div class="f-card-pills">
909
+ <span class="pill ${sc === "app" ? "sc-app" : "sc-3p"}">${esc(sc)}</span>
910
+ <span class="pill">${esc(r.layer || "-")}</span>
911
+ <span class="pill">×${r.hits || 1}</span>
912
+ </div>
913
+ </div>
914
+ <div class="f-card-title">${esc(r.title || "-")}</div>
915
+ <div class="f-card-val mono">${esc(r.value)}</div>
916
+ <div class="f-card-foot"><span class="mono">${esc(loc)}</span><span>[${esc(r.unit_id)}]</span></div>
917
+ </div>`;
918
+ }).join("") + `</div>`;
919
+ } else {
920
+ const groups = {};
921
+ currentFiltered.forEach((r, idx) => {
922
+ if (!groups[r.catalog_id]) groups[r.catalog_id] = [];
923
+ groups[r.catalog_id].push({ r, idx });
924
+ });
925
+ container.innerHTML = Object.entries(groups).sort((a, b) => a[0].localeCompare(b[0])).map(([cid, list]) => {
926
+ const spec = CAT[cid] || {};
927
+ const body = list.slice(0, 80).map(({ r, idx }) => {
928
+ const loc = r.file_path ? `${r.file_path.split("/").pop()}${r.line_no ? ":" + r.line_no : ""}` : "-";
929
+ return `<div class="grp-row" onclick="openModal(${idx})">
930
+ <span class="mono" style="flex:1">${esc(r.value)}</span>
931
+ <span class="pill">${esc(r.layer || "-")}</span>
932
+ <span class="pill">×${r.hits || 1}</span>
933
+ <span class="mono" style="color:var(--muted)">${esc(loc)}</span>
934
+ </div>`;
935
+ }).join("");
936
+ const moreNote = list.length > 80 ? `<div style="font-size:11.5px;color:var(--muted);padding-top:6px">Showing 80 of ${list.length}. Switch to Table/Cards or Export to see all.</div>` : "";
937
+ return `<details class="grp-box" open>
938
+ <summary class="grp-sum">
939
+ <div class="grp-sum-left"><span class="badge">${esc(cid)}</span><span>${esc(spec.name || cid)}</span><span class="grp-desc">${esc(spec.description || "")}</span></div>
940
+ <span class="nav-cnt">${list.length}</span>
941
+ </summary>
942
+ <div class="grp-body">${body}${moreNote}</div>
943
+ </details>`;
944
+ }).join("");
945
+ }
946
+ }
947
+
948
+ function openModal(filteredIdx) {
949
+ const r = currentFiltered[filteredIdx];
950
+ if (!r) return;
951
+ const spec = CAT[r.catalog_id] || {};
952
+ document.getElementById("modalTitle").innerHTML = `<span class="badge">${esc(r.catalog_id)}</span> ${esc(r.title || spec.name || "")}`;
953
+ document.getElementById("modalBody").innerHTML = `
954
+ <div class="detail-block"><div class="detail-lbl">${esc(UI.catalog_desc)}</div><div><strong>${esc(spec.name || r.catalog_id)}</strong> — ${esc(spec.description || "-")}</div></div>
955
+ <div class="detail-block"><div class="detail-lbl">${esc(UI.col_value)} <button class="btn-sm" onclick="copyText(currentFiltered[${filteredIdx}].value, this)">${esc(UI.btn_copy)}</button></div><pre class="detail-pre">${esc(r.value)}</pre></div>
956
+ <div class="detail-block"><div class="detail-lbl">${esc(UI.col_source)}</div><pre class="detail-pre">${esc((r.file_path || "-") + (r.line_no ? ":" + r.line_no : ""))}</pre></div>
957
+ <div class="detail-block"><div class="detail-lbl">${esc(UI.class_method)}</div><pre class="detail-pre">Unit: ${esc(r.unit_id)} | Scope: ${esc(r.scope || "app")} | Layer: ${esc(r.layer || "-")} | Hits: ${r.hits || 1}\nClass: ${esc(r.class_name || "-")} | Method: ${esc(r.method_name || "-")}</pre></div>
958
+ <div class="detail-block"><div class="detail-lbl">${esc(UI.extra_meta)}</div><pre class="detail-pre">${esc(JSON.stringify(r.extra || {}, null, 2))}</pre></div>
959
+ `;
960
+ document.getElementById("detailModal").classList.add("open");
961
+ }
962
+
963
+ function closeModal() { document.getElementById("detailModal").classList.remove("open"); }
964
+
965
+ function copyText(txt, btn) {
966
+ if (navigator.clipboard && navigator.clipboard.writeText) {
967
+ navigator.clipboard.writeText(txt).then(() => {
968
+ btn.textContent = UI.btn_copied;
969
+ setTimeout(() => btn.textContent = UI.btn_copy, 1200);
970
+ });
971
+ }
972
+ }
973
+
974
+ function exportFiltered(fmt) {
975
+ const data = activeKey === "executive" ? REPORT.executive : currentFiltered;
976
+ let content = "", mime = "text/plain", ext = fmt;
977
+ if (fmt === "json") {
978
+ content = JSON.stringify(data, null, 2);
979
+ mime = "application/json";
980
+ } else if (fmt === "csv") {
981
+ const rows = Array.isArray(data) ? data : [];
982
+ const header = ["catalog_id","unit_id","scope","layer","title","value","hits","file_path","line_no"];
983
+ const q = v => `"${String(v ?? "").replace(/"/g, '""')}"`;
984
+ content = [header.join(","), ...rows.map(r => header.map(h => q(r[h])).join(","))].join("\n");
985
+ mime = "text/csv";
986
+ } else {
987
+ const rows = Array.isArray(data) ? data : [];
988
+ content = [...new Set(rows.map(r => r.value))].join("\n");
989
+ }
990
+ const a = document.createElement("a");
991
+ a.href = URL.createObjectURL(new Blob([content], { type: mime }));
992
+ a.download = `dexsect_${activeKey}.${ext}`;
993
+ a.click();
994
+ }
995
+
996
+ init();
997
+ </script>
998
+ </body>
999
+ </html>
1000
+ """
1001
+
1002
+
1003
+ def generate_analysis_reports(
1004
+ state: WorkspaceState,
1005
+ db: FindingsDB,
1006
+ summary_data: Dict[str, Any],
1007
+ out_dir: Path,
1008
+ formats: List[str],
1009
+ lang: str = "en",
1010
+ include_noise: bool = False,
1011
+ full_json: bool = False,
1012
+ ) -> Dict[str, Path]:
1013
+ out_dir.mkdir(parents=True, exist_ok=True)
1014
+ generated: Dict[str, Path] = {}
1015
+ loc = load_locale(lang)
1016
+ ui_t = loc["ui"]
1017
+ kpi_t = loc["kpis"]
1018
+ sec_t = loc["sections"]
1019
+ cat_specs = _load_catalog_specs()
1020
+
1021
+ units = state.get_units()
1022
+ dom_counts = db.counts_by_domain()
1023
+ cat_counts = db.counts_by_catalog()
1024
+ total_findings = sum(dom_counts.values())
1025
+ html_row_cap = 2500
1026
+
1027
+ sections_spec = [
1028
+ ("overview", sec_t["overview"], ["APP-*", "BND-*", "SIG-*"]),
1029
+ ("permissions", sec_t["permissions"], ["PER-*"]),
1030
+ ("components", sec_t["components"], ["ACT-*", "SRV-*", "REC-*", "PRO-*"]),
1031
+ ("intents", sec_t["intents"], ["INT-*"]),
1032
+ ("network", sec_t["network"], ["URL-*", "NET-*", "NAPI-*", "CFG-*"]),
1033
+ ("code", sec_t["code"], ["COD-*", "KOT-*", "REF-*", "DEX-*"]),
1034
+ ("security", sec_t["security"], ["SEC-*", "CUSTOM-*"]),
1035
+ ("native_fw", sec_t["native_fw"], ["NAT-*", "FLT-*", "RN-*", "UNT-*", "WEB-*", "XAM-*"]),
1036
+ ("assets_db", sec_t["assets_db"], ["AST-*", "DB-*"]),
1037
+ ]
1038
+
1039
+ exec_data = _build_executive_data(state, db, include_noise=include_noise)
1040
+
1041
+ section_rows_html: Dict[str, List[Dict[str, Any]]] = {}
1042
+ section_hidden: Dict[str, int] = {}
1043
+ section_rows_json: Dict[str, List[Dict[str, Any]]] = {}
1044
+
1045
+ for key, _title, patterns in sections_spec:
1046
+ raw = db.query_findings(catalog_ids=patterns, limit=None if full_json else 5000)
1047
+ cleaned, hidden_cnt = _clean_and_collapse(raw, include_noise=include_noise)
1048
+ section_hidden[key] = hidden_cnt
1049
+ section_rows_html[key] = cleaned[:html_row_cap]
1050
+ section_rows_json[key] = raw if full_json else cleaned[:html_row_cap]
1051
+
1052
+ if "json" in formats or "all" in formats:
1053
+ json_path = out_dir / "ANALYSIS_REPORT.json"
1054
+ payload = {
1055
+ "dexsect_version": __version__,
1056
+ "generated_at": time.strftime("%Y-%m-%d %H:%M:%S"),
1057
+ "lang": loc["lang"],
1058
+ "include_noise": include_noise,
1059
+ "full_json": full_json,
1060
+ "target": state.data.get("target_input"),
1061
+ "input_kind": state.data.get("input_kind"),
1062
+ "workspace_root": str(state.root),
1063
+ "total_findings": total_findings,
1064
+ "executive_summary": exec_data,
1065
+ "counts_by_domain": dom_counts,
1066
+ "counts_by_catalog": cat_counts,
1067
+ "inspection_meta": summary_data,
1068
+ "sections": section_rows_json,
1069
+ }
1070
+ json_path.write_text(json.dumps(payload, indent=2, ensure_ascii=False), encoding="utf-8")
1071
+ generated["json"] = json_path
1072
+
1073
+ if "md" in formats or "all" in formats:
1074
+ md_t = loc.get("md", {})
1075
+ dom_t = loc.get("domains", {})
1076
+ md_path = out_dir / "ANALYSIS_REPORT.md"
1077
+ md = [
1078
+ f"# {md_t.get('title', 'DexSect Static Analysis Report')}",
1079
+ "",
1080
+ f"- **{md_t.get('target', 'Target')}:** `{_clean_md(state.data.get('target_input'))}` (`{state.data.get('input_kind')}`)",
1081
+ f"- **{md_t.get('pkg_ver', 'Package / Version')}:** `{_clean_md(exec_data['package'])}` (`{_clean_md(exec_data['version'])}`)",
1082
+ f"- **{md_t.get('sdk', 'SDK')}:** `{_clean_md(exec_data['sdk'])}`",
1083
+ f"- **{md_t.get('flags', 'Flags')}:** `{_clean_md(exec_data['security_flags'])}`",
1084
+ f"- **{md_t.get('profile', 'Profile')}:** `{summary_data.get('profile', 'standard')}` | **{md_t.get('total_findings', 'Total Findings')}:** `{total_findings}`",
1085
+ f"- **{md_t.get('scope_split', 'Scope Split')}:** `app={exec_data['counts']['scope_app']}` | `third_party={exec_data['counts']['scope_third_party']}`",
1086
+ "",
1087
+ f"## {md_t.get('top_domains', 'Top Clean Domains')}",
1088
+ "",
1089
+ ", ".join(f"`{_clean_md(d)}`" for d in exec_data["top_domains"][:30]) or f"_{md_t.get('none', 'None')}_",
1090
+ "",
1091
+ f"## {md_t.get('findings_by_domain', 'Findings by Domain')}",
1092
+ "",
1093
+ f"| {md_t.get('col_domain', 'Domain')} | {md_t.get('col_count', 'Count')} |",
1094
+ "| :--- | :---: |",
1095
+ ]
1096
+ for dom, cnt in dom_counts.items():
1097
+ md.append(f"| **{dom_t.get(dom, dom)}** | {cnt} |")
1098
+
1099
+ for key, title, _pats in sections_spec:
1100
+ rows = section_rows_html.get(key, [])
1101
+ md.extend(["", f"## {title} ({len(rows)} {md_t.get('items_unit', 'unique items')})", ""])
1102
+ if not rows:
1103
+ md.append(f"_{md_t.get('no_findings', 'No findings in this section.')}_")
1104
+ continue
1105
+ md.extend([
1106
+ f"| {ui_t['col_id']} | {ui_t['col_unit']} | {ui_t['col_scope']} | {ui_t['col_layer']} | {ui_t['col_title']} | {ui_t['col_value']} | {ui_t['col_hits']} | {ui_t['col_source']} |",
1107
+ "| :--- | :---: | :---: | :--- | :--- | :--- | :---: | :--- |",
1108
+ ])
1109
+ for r in rows[:100]:
1110
+ val = _clean_md(r["value"]).replace("|", "\\|").replace("\n", " ")[:110]
1111
+ loc_str = f"{Path(r['file_path']).name}:{r['line_no']}" if r.get("file_path") else "-"
1112
+ md.append(
1113
+ f"| `{r['catalog_id']}` | `{r['unit_id']}` | `{r.get('scope', 'app')}` | `{r.get('layer') or '-'}` | "
1114
+ f"{_clean_md(r.get('title') or '-')} | `{val}` | {r.get('hits', 1)} | `{_clean_md(loc_str)}` |"
1115
+ )
1116
+ md_path.write_text(_clean_md("\n".join(md) + "\n"), encoding="utf-8")
1117
+ generated["md"] = md_path
1118
+
1119
+ if "html" in formats or "all" in formats:
1120
+ html_path = out_dir / "ANALYSIS_REPORT.html"
1121
+ target_name = Path(str(state.data.get("target_input", "App"))).name
1122
+ kpis = [
1123
+ {"lbl": kpi_t["total_findings"], "val": str(total_findings)},
1124
+ {"lbl": kpi_t["units"], "val": str(len(units))},
1125
+ {"lbl": kpi_t["permissions"], "val": str(dom_counts.get("Permissions", 0))},
1126
+ {"lbl": ui_t["lbl_unprotected"], "val": str(exec_data["counts"]["unprotected_exported"])},
1127
+ {"lbl": kpi_t["network"], "val": str(exec_data["counts"]["clean_domains"])},
1128
+ {"lbl": ui_t["lbl_jni"], "val": str(exec_data["counts"]["jni_functions"])},
1129
+ {"lbl": ui_t["lbl_secrets"], "val": str(exec_data["counts"]["secrets"])},
1130
+ {"lbl": kpi_t["security"], "val": str(dom_counts.get("Security Indicators", 0))},
1131
+ ]
1132
+ embedded_data = {
1133
+ "locale": loc,
1134
+ "catalog_specs": cat_specs,
1135
+ "kpis": kpis,
1136
+ "executive": exec_data,
1137
+ "units": [{"id": u.unit_id, "name": u.name, "role": u.role, "depth": u.depth, "stack": u.primary_stack} for u in units],
1138
+ "sections": [
1139
+ {"key": "executive", "title": sec_t.get("executive", "Executive Summary"), "count": len(units), "is_exec": True, "rows": []},
1140
+ *[
1141
+ {"key": k, "title": t, "count": len(section_rows_html[k]), "hidden": section_hidden[k], "rows": section_rows_html[k]}
1142
+ for k, t, _ in sections_spec
1143
+ ],
1144
+ ],
1145
+ }
1146
+ safe_json = json.dumps(embedded_data, ensure_ascii=False).replace("</", "<\\/")
1147
+
1148
+ replacements = {
1149
+ "__LANG__": _esc(loc["lang"]),
1150
+ "__DIR__": _esc(loc["dir"]),
1151
+ "__PAGE_TITLE__": _esc(f"{ui_t['report_title']} - {target_name}"),
1152
+ "__VERSION__": _esc(__version__),
1153
+ "__TARGET_NAME__": _esc(target_name),
1154
+ "__REPORT_TITLE__": _esc(ui_t["report_title"]),
1155
+ "__PROFILE_LABEL__": _esc(ui_t["subtitle_profile"]),
1156
+ "__PROFILE__": _esc(summary_data.get("profile", "standard")),
1157
+ "__GEN_LABEL__": _esc(ui_t["subtitle_generated"]),
1158
+ "__GENERATED__": _esc(time.strftime("%Y-%m-%d %H:%M:%S")),
1159
+ "__BTN_EXPORT_JSON__": _esc(ui_t["btn_export_json"]),
1160
+ "__BTN_CSV__": _esc(ui_t["export_csv"]),
1161
+ "__BTN_TXT__": _esc(ui_t["export_txt"]),
1162
+ "__SEARCH_PH__": _esc(ui_t["search_placeholder"]),
1163
+ "__EXCLUDE_PH__": _esc(ui_t["exclude_placeholder"]),
1164
+ "__REGEX_LBL__": _esc(ui_t["regex_label"]),
1165
+ "__VIEW_TABLE__": _esc(ui_t["view_table"]),
1166
+ "__VIEW_CARDS__": _esc(ui_t["view_cards"]),
1167
+ "__VIEW_GROUPED__": _esc(ui_t["view_grouped"]),
1168
+ "__ALL_SCOPES__": _esc(ui_t["all_scopes"]),
1169
+ "__SCOPE_APP__": _esc(ui_t["scope_app"]),
1170
+ "__SCOPE_3P__": _esc(ui_t["scope_3p"]),
1171
+ "__ALL_UNITS__": _esc(ui_t["all_units"]),
1172
+ "__ALL_LAYERS__": _esc(ui_t["all_layers"]),
1173
+ "__SORT_ID__": _esc(ui_t["sort_id"]),
1174
+ "__SORT_HITS__": _esc(ui_t["sort_hits"]),
1175
+ "__SORT_TITLE__": _esc(ui_t["sort_title"]),
1176
+ "__SORT_SOURCE__": _esc(ui_t["sort_source"]),
1177
+ "__COLS_BTN__": _esc(ui_t["columns_btn"]),
1178
+ "__CLEAR_BTN__": _esc(ui_t["clear_filters"]),
1179
+ "__LOAD_MORE__": _esc(ui_t["btn_load_more"]),
1180
+ "__DETAILS_TITLE__": _esc(ui_t["details_title"]),
1181
+ "__CLOSE_BTN__": _esc(ui_t["close_btn"]),
1182
+ "__DEXSECT_JSON__": safe_json,
1183
+ }
1184
+ doc = HTML_TEMPLATE
1185
+ for k, v in replacements.items():
1186
+ doc = doc.replace(k, v)
1187
+ html_path.write_text(doc, encoding="utf-8")
1188
+ generated["html"] = html_path
1189
+
1190
+ return generated