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.
- dexsect/__init__.py +4 -0
- dexsect/__main__.py +5 -0
- dexsect/catalog/EXTRACTION_CATALOG.json +4057 -0
- dexsect/catalog/__init__.py +0 -0
- dexsect/cli.py +1272 -0
- dexsect/core/__init__.py +0 -0
- dexsect/core/config.py +177 -0
- dexsect/core/context.py +181 -0
- dexsect/core/i18n.py +40 -0
- dexsect/core/pipeline.py +153 -0
- dexsect/core/platform_utils.py +164 -0
- dexsect/core/runner.py +124 -0
- dexsect/core/theme.py +64 -0
- dexsect/core/ui.py +405 -0
- dexsect/core/utils.py +150 -0
- dexsect/inspectors/__init__.py +0 -0
- dexsect/inspectors/assets_db_inspector.py +235 -0
- dexsect/inspectors/base.py +46 -0
- dexsect/inspectors/bundle_inspector.py +55 -0
- dexsect/inspectors/code_inspector.py +341 -0
- dexsect/inspectors/custom_rules_inspector.py +178 -0
- dexsect/inspectors/dex_inspector.py +144 -0
- dexsect/inspectors/manifest_inspector.py +503 -0
- dexsect/inspectors/native_fw_inspector.py +167 -0
- dexsect/inspectors/resources_inspector.py +195 -0
- dexsect/inspectors/scanner_inspector.py +153 -0
- dexsect/inspectors/signing_inspector.py +423 -0
- dexsect/inspectors/text_scanner.py +336 -0
- dexsect/locales/__init__.py +0 -0
- dexsect/locales/ar.json +130 -0
- dexsect/locales/de.json +51 -0
- dexsect/locales/en.json +110 -0
- dexsect/locales/es.json +51 -0
- dexsect/locales/fr.json +51 -0
- dexsect/locales/ja.json +51 -0
- dexsect/locales/pt.json +51 -0
- dexsect/locales/ru.json +51 -0
- dexsect/locales/tr.json +51 -0
- dexsect/locales/zh.json +51 -0
- dexsect/parsers/__init__.py +0 -0
- dexsect/parsers/axml.py +264 -0
- dexsect/parsers/bundle.py +214 -0
- dexsect/parsers/elf.py +396 -0
- dexsect/phases/__init__.py +0 -0
- dexsect/phases/base.py +102 -0
- dexsect/phases/decode.py +507 -0
- dexsect/phases/decompile.py +408 -0
- dexsect/phases/fingerprint.py +341 -0
- dexsect/phases/frameworks.py +377 -0
- dexsect/phases/mapper.py +41 -0
- dexsect/phases/native.py +188 -0
- dexsect/plugins/__init__.py +0 -0
- dexsect/plugins/base.py +20 -0
- dexsect/plugins/diff.py +162 -0
- dexsect/plugins/inspect.py +172 -0
- dexsect/plugins/report.py +80 -0
- dexsect/plugins/trace.py +141 -0
- dexsect/reporting/__init__.py +0 -0
- dexsect/reporting/analysis_report.py +1190 -0
- dexsect/reporting/diff_report.py +144 -0
- dexsect/reporting/sarif_report.py +109 -0
- dexsect/reporting/unpack_map.py +149 -0
- dexsect/rules/__init__.py +0 -0
- dexsect/rules/anti_analysis.json +45 -0
- dexsect/rules/crypto_audit.json +41 -0
- dexsect/rules/secrets_extended.json +46 -0
- dexsect/storage/__init__.py +0 -0
- dexsect/storage/findings_db.py +460 -0
- dexsect-4.1.0.dist-info/METADATA +532 -0
- dexsect-4.1.0.dist-info/RECORD +74 -0
- dexsect-4.1.0.dist-info/WHEEL +5 -0
- dexsect-4.1.0.dist-info/entry_points.txt +2 -0
- dexsect-4.1.0.dist-info/licenses/LICENSE +21 -0
- dexsect-4.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
import platform
|
|
4
|
+
import re
|
|
5
|
+
import time
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any, Dict, List, Optional
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
SEQ_DIR_RE = re.compile(r"^(\d+)_")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def is_windows() -> bool:
|
|
14
|
+
return os.name == "nt"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def is_termux() -> bool:
|
|
18
|
+
return "com.termux" in os.environ.get("PREFIX", "") or Path("/data/data/com.termux").is_dir()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def enable_windows_vt100() -> None:
|
|
22
|
+
if not is_windows():
|
|
23
|
+
return
|
|
24
|
+
try:
|
|
25
|
+
import ctypes
|
|
26
|
+
kernel32 = ctypes.windll.kernel32
|
|
27
|
+
handle = kernel32.GetStdHandle(-11) # STD_OUTPUT_HANDLE
|
|
28
|
+
mode = ctypes.c_uint32()
|
|
29
|
+
if kernel32.GetConsoleMode(handle, ctypes.byref(mode)):
|
|
30
|
+
kernel32.SetConsoleMode(handle, mode.value | 0x0004) # ENABLE_VIRTUAL_TERMINAL_PROCESSING
|
|
31
|
+
except Exception:
|
|
32
|
+
pass
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def get_config_dir() -> Path:
|
|
36
|
+
if is_windows():
|
|
37
|
+
base = os.environ.get("APPDATA") or str(Path.home() / "AppData" / "Roaming")
|
|
38
|
+
return Path(base) / "dexsect"
|
|
39
|
+
base = os.environ.get("XDG_CONFIG_HOME") or str(Path.home() / ".config")
|
|
40
|
+
return Path(base) / "dexsect"
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def get_data_dir() -> Path:
|
|
44
|
+
if is_windows():
|
|
45
|
+
base = os.environ.get("LOCALAPPDATA") or str(Path.home() / "AppData" / "Local")
|
|
46
|
+
return Path(base) / "dexsect"
|
|
47
|
+
base = os.environ.get("XDG_DATA_HOME") or str(Path.home() / ".local" / "share")
|
|
48
|
+
return Path(base) / "dexsect"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def detect_os_family() -> str:
|
|
52
|
+
if is_termux():
|
|
53
|
+
return "termux"
|
|
54
|
+
if is_windows():
|
|
55
|
+
return "windows"
|
|
56
|
+
sys_name = platform.system().lower()
|
|
57
|
+
if sys_name == "darwin":
|
|
58
|
+
return "macos"
|
|
59
|
+
return "linux"
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class RunsRegistry:
|
|
63
|
+
"""Global XDG/AppData workspace index so shortcuts (01, latest) work from any directory."""
|
|
64
|
+
|
|
65
|
+
def __init__(self, index_file: Optional[Path] = None) -> None:
|
|
66
|
+
self.index_file = index_file or (get_data_dir() / "runs_index.json")
|
|
67
|
+
|
|
68
|
+
def _load(self) -> List[Dict[str, Any]]:
|
|
69
|
+
if not self.index_file.is_file():
|
|
70
|
+
return []
|
|
71
|
+
try:
|
|
72
|
+
data = json.loads(self.index_file.read_text(encoding="utf-8", errors="replace"))
|
|
73
|
+
return data if isinstance(data, list) else []
|
|
74
|
+
except Exception:
|
|
75
|
+
return []
|
|
76
|
+
|
|
77
|
+
def _save(self, entries: List[Dict[str, Any]]) -> None:
|
|
78
|
+
self.index_file.parent.mkdir(parents=True, exist_ok=True)
|
|
79
|
+
tmp = self.index_file.with_suffix(".tmp")
|
|
80
|
+
tmp.write_text(json.dumps(entries, indent=2, ensure_ascii=False), encoding="utf-8")
|
|
81
|
+
tmp.replace(self.index_file)
|
|
82
|
+
|
|
83
|
+
def register(
|
|
84
|
+
self,
|
|
85
|
+
ws_path: Path,
|
|
86
|
+
target_input: str = "",
|
|
87
|
+
package: str = "",
|
|
88
|
+
version: str = "",
|
|
89
|
+
status: str = "ACTIVE",
|
|
90
|
+
) -> None:
|
|
91
|
+
resolved = str(ws_path.resolve())
|
|
92
|
+
m = SEQ_DIR_RE.match(ws_path.name)
|
|
93
|
+
seq = int(m.group(1)) if m else None
|
|
94
|
+
entries = [e for e in self._load() if e.get("path") != resolved]
|
|
95
|
+
entries.append({
|
|
96
|
+
"seq": seq,
|
|
97
|
+
"name": ws_path.name,
|
|
98
|
+
"path": resolved,
|
|
99
|
+
"target": target_input,
|
|
100
|
+
"package": package,
|
|
101
|
+
"version": version,
|
|
102
|
+
"status": status,
|
|
103
|
+
"updated_at": time.strftime("%Y-%m-%d %H:%M:%S"),
|
|
104
|
+
"ts": time.time(),
|
|
105
|
+
})
|
|
106
|
+
# Keep most recent 200 runs
|
|
107
|
+
self._save(entries[-200:])
|
|
108
|
+
|
|
109
|
+
def list_runs(self, runs_root: Optional[Path] = None) -> List[Dict[str, Any]]:
|
|
110
|
+
by_path: Dict[str, Dict[str, Any]] = {}
|
|
111
|
+
for e in self._load():
|
|
112
|
+
p = Path(e.get("path", ""))
|
|
113
|
+
if p.is_dir() and (p / "workspace.json").is_file():
|
|
114
|
+
by_path[str(p.resolve())] = e
|
|
115
|
+
|
|
116
|
+
if runs_root and runs_root.is_dir():
|
|
117
|
+
for d in sorted(runs_root.iterdir()):
|
|
118
|
+
if d.is_dir() and (d / "workspace.json").is_file():
|
|
119
|
+
rp = str(d.resolve())
|
|
120
|
+
if rp not in by_path:
|
|
121
|
+
m = SEQ_DIR_RE.match(d.name)
|
|
122
|
+
by_path[rp] = {
|
|
123
|
+
"seq": int(m.group(1)) if m else None,
|
|
124
|
+
"name": d.name,
|
|
125
|
+
"path": rp,
|
|
126
|
+
"target": "",
|
|
127
|
+
"package": "",
|
|
128
|
+
"version": "",
|
|
129
|
+
"status": "INDEXED",
|
|
130
|
+
"updated_at": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(d.stat().st_mtime)),
|
|
131
|
+
"ts": d.stat().st_mtime,
|
|
132
|
+
}
|
|
133
|
+
return sorted(by_path.values(), key=lambda x: x.get("ts", 0), reverse=True)
|
|
134
|
+
|
|
135
|
+
def resolve_shortcut(self, raw_target: str, runs_root: Optional[Path] = None) -> Optional[Path]:
|
|
136
|
+
if runs_root and runs_root.is_dir():
|
|
137
|
+
local_dirs = [
|
|
138
|
+
d for d in runs_root.iterdir()
|
|
139
|
+
if d.is_dir() and (d / "workspace.json").is_file()
|
|
140
|
+
]
|
|
141
|
+
if local_dirs:
|
|
142
|
+
if raw_target.lower() == "latest":
|
|
143
|
+
return max(local_dirs, key=lambda d: d.stat().st_mtime).resolve()
|
|
144
|
+
if raw_target.isdigit():
|
|
145
|
+
prefix = f"{int(raw_target):02d}_"
|
|
146
|
+
matches = sorted(d for d in local_dirs if d.name.startswith(prefix))
|
|
147
|
+
if matches:
|
|
148
|
+
return matches[-1].resolve()
|
|
149
|
+
|
|
150
|
+
runs = self.list_runs(runs_root)
|
|
151
|
+
if not runs:
|
|
152
|
+
return None
|
|
153
|
+
if raw_target.lower() == "latest":
|
|
154
|
+
return Path(runs[0]["path"]).resolve()
|
|
155
|
+
if raw_target.isdigit():
|
|
156
|
+
want = int(raw_target)
|
|
157
|
+
for r in runs:
|
|
158
|
+
if r.get("seq") == want:
|
|
159
|
+
return Path(r["path"]).resolve()
|
|
160
|
+
prefix = f"{want:02d}_"
|
|
161
|
+
for r in runs:
|
|
162
|
+
if str(r.get("name", "")).startswith(prefix):
|
|
163
|
+
return Path(r["path"]).resolve()
|
|
164
|
+
return None
|
dexsect/core/runner.py
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import signal
|
|
3
|
+
import subprocess
|
|
4
|
+
import threading
|
|
5
|
+
import time
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Callable, List, Optional
|
|
8
|
+
|
|
9
|
+
from .platform_utils import is_windows
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class CommandRunner:
|
|
13
|
+
def __init__(self, java_xmx: Optional[str] = None, timeout_sec: int = 1800) -> None:
|
|
14
|
+
self.java_xmx = java_xmx
|
|
15
|
+
self.timeout_sec = max(30, int(timeout_sec)) if timeout_sec else 0
|
|
16
|
+
self._proc_lock = threading.Lock()
|
|
17
|
+
self._active_proc: Optional[subprocess.Popen] = None
|
|
18
|
+
self.interrupted = False
|
|
19
|
+
self.timed_out = False
|
|
20
|
+
|
|
21
|
+
def install_signal_handlers(self, on_interrupt: Optional[Callable[[int], None]] = None) -> None:
|
|
22
|
+
def handler(signum, frame):
|
|
23
|
+
self.interrupted = True
|
|
24
|
+
if on_interrupt:
|
|
25
|
+
on_interrupt(signum)
|
|
26
|
+
self.terminate_active()
|
|
27
|
+
|
|
28
|
+
signal.signal(signal.SIGINT, handler)
|
|
29
|
+
if hasattr(signal, "SIGTERM"):
|
|
30
|
+
signal.signal(signal.SIGTERM, handler)
|
|
31
|
+
|
|
32
|
+
def terminate_active(self) -> None:
|
|
33
|
+
with self._proc_lock:
|
|
34
|
+
proc = self._active_proc
|
|
35
|
+
if proc and proc.poll() is None:
|
|
36
|
+
if is_windows():
|
|
37
|
+
try:
|
|
38
|
+
proc.terminate()
|
|
39
|
+
except Exception:
|
|
40
|
+
pass
|
|
41
|
+
else:
|
|
42
|
+
try:
|
|
43
|
+
os.killpg(os.getpgid(proc.pid), signal.SIGTERM)
|
|
44
|
+
except Exception:
|
|
45
|
+
try:
|
|
46
|
+
proc.terminate()
|
|
47
|
+
except Exception:
|
|
48
|
+
pass
|
|
49
|
+
|
|
50
|
+
def run_streamed(
|
|
51
|
+
self,
|
|
52
|
+
cmd: List[str],
|
|
53
|
+
log_file: Path,
|
|
54
|
+
on_line: Optional[Callable[[str], None]] = None,
|
|
55
|
+
on_tick: Optional[Callable[[], None]] = None,
|
|
56
|
+
cwd: Optional[Path] = None,
|
|
57
|
+
inject_java_xmx: bool = False,
|
|
58
|
+
) -> int:
|
|
59
|
+
env = os.environ.copy()
|
|
60
|
+
if inject_java_xmx and self.java_xmx:
|
|
61
|
+
existing = env.get("JAVA_OPTS", "")
|
|
62
|
+
if "-Xmx" not in existing:
|
|
63
|
+
env["JAVA_OPTS"] = f"{existing} -Xmx{self.java_xmx}".strip()
|
|
64
|
+
j_existing = env.get("JADX_OPTS", "")
|
|
65
|
+
if "-Xmx" not in j_existing:
|
|
66
|
+
env["JADX_OPTS"] = f"{j_existing} -Xmx{self.java_xmx}".strip()
|
|
67
|
+
|
|
68
|
+
self.timed_out = False
|
|
69
|
+
popen_kwargs: dict = {
|
|
70
|
+
"stdout": subprocess.PIPE,
|
|
71
|
+
"stderr": subprocess.STDOUT,
|
|
72
|
+
"text": True,
|
|
73
|
+
"errors": "replace",
|
|
74
|
+
"bufsize": 1,
|
|
75
|
+
"cwd": str(cwd) if cwd else None,
|
|
76
|
+
"env": env,
|
|
77
|
+
}
|
|
78
|
+
if is_windows():
|
|
79
|
+
popen_kwargs["creationflags"] = getattr(subprocess, "CREATE_NEW_PROCESS_GROUP", 0)
|
|
80
|
+
else:
|
|
81
|
+
popen_kwargs["start_new_session"] = True
|
|
82
|
+
|
|
83
|
+
log_file.parent.mkdir(parents=True, exist_ok=True)
|
|
84
|
+
with log_file.open("w", encoding="utf-8", errors="replace") as lf:
|
|
85
|
+
lf.write(f"COMMAND: {' '.join(cmd)}\n")
|
|
86
|
+
if inject_java_xmx and self.java_xmx:
|
|
87
|
+
lf.write(f"JAVA_OPTS: {env.get('JAVA_OPTS', '')}\n")
|
|
88
|
+
lf.write("-" * 60 + "\n")
|
|
89
|
+
lf.flush()
|
|
90
|
+
|
|
91
|
+
proc = subprocess.Popen(cmd, **popen_kwargs)
|
|
92
|
+
with self._proc_lock:
|
|
93
|
+
self._active_proc = proc
|
|
94
|
+
|
|
95
|
+
def reader():
|
|
96
|
+
assert proc.stdout is not None
|
|
97
|
+
for raw in proc.stdout:
|
|
98
|
+
line = raw.rstrip("\r\n")
|
|
99
|
+
lf.write(line + "\n")
|
|
100
|
+
lf.flush()
|
|
101
|
+
if on_line:
|
|
102
|
+
on_line(line)
|
|
103
|
+
|
|
104
|
+
t = threading.Thread(target=reader, daemon=True)
|
|
105
|
+
t.start()
|
|
106
|
+
start_mono = time.monotonic()
|
|
107
|
+
|
|
108
|
+
while proc.poll() is None:
|
|
109
|
+
if self.timeout_sec > 0 and (time.monotonic() - start_mono) > self.timeout_sec:
|
|
110
|
+
self.timed_out = True
|
|
111
|
+
lf.write(f"\n[DEXSECT TIMEOUT] Process exceeded {self.timeout_sec}s limit; terminating.\n")
|
|
112
|
+
lf.flush()
|
|
113
|
+
self.terminate_active()
|
|
114
|
+
break
|
|
115
|
+
if on_tick:
|
|
116
|
+
on_tick()
|
|
117
|
+
time.sleep(0.25)
|
|
118
|
+
|
|
119
|
+
t.join(timeout=2.0)
|
|
120
|
+
rc = proc.returncode if proc.returncode is not None else (-9 if self.timed_out else -1)
|
|
121
|
+
|
|
122
|
+
with self._proc_lock:
|
|
123
|
+
self._active_proc = None
|
|
124
|
+
return rc
|
dexsect/core/theme.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
# Official DexSect Brand Palette (derived from project cover banner)
|
|
6
|
+
BRAND_PALETTE = {
|
|
7
|
+
"bg_void": "#111015",
|
|
8
|
+
"bg_sidebar": "#15131B",
|
|
9
|
+
"bg_card": "#1B1823",
|
|
10
|
+
"bg_card_alt": "#231F2D",
|
|
11
|
+
"border": "#33293A",
|
|
12
|
+
"dex_orange": "#FF8C24",
|
|
13
|
+
"dex_amber": "#FFA94D",
|
|
14
|
+
"sect_cream": "#F5EFE6",
|
|
15
|
+
"shield_crimson": "#B83B5E",
|
|
16
|
+
"text_muted": "#A39AA8",
|
|
17
|
+
"status_ok": "#34D399",
|
|
18
|
+
"status_warn": "#FBBF24",
|
|
19
|
+
"status_err": "#F87171",
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def supports_truecolor() -> bool:
|
|
24
|
+
ct = os.environ.get("COLORTERM", "").lower()
|
|
25
|
+
term = os.environ.get("TERM", "").lower()
|
|
26
|
+
return ("truecolor" in ct or "24bit" in ct or "xterm-256color" in term or "WT_SESSION" in os.environ)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class BrandColors:
|
|
30
|
+
"""DexSect Official Terminal Colors (24-bit Truecolor with 16-color fallback)."""
|
|
31
|
+
|
|
32
|
+
def __init__(self, enabled: bool = True) -> None:
|
|
33
|
+
if not enabled:
|
|
34
|
+
for attr in (
|
|
35
|
+
"RESET", "BOLD", "DIM", "ORANGE", "CREAM", "CRIMSON",
|
|
36
|
+
"MUTED", "OK", "WARN", "ERR", "INFO", "ACTIVE_BG",
|
|
37
|
+
):
|
|
38
|
+
setattr(self, attr, "")
|
|
39
|
+
return
|
|
40
|
+
|
|
41
|
+
self.RESET = "\033[0m"
|
|
42
|
+
self.BOLD = "\033[1m"
|
|
43
|
+
self.DIM = "\033[2m"
|
|
44
|
+
|
|
45
|
+
if supports_truecolor():
|
|
46
|
+
self.ORANGE = "\033[38;2;255;140;36m" # #FF8C24 (Dex)
|
|
47
|
+
self.CREAM = "\033[38;2;245;239;230m" # #F5EFE6 (Sect)
|
|
48
|
+
self.CRIMSON = "\033[38;2;184;59;94m" # #B83B5E (Shield Circuit)
|
|
49
|
+
self.MUTED = "\033[38;2;148;138;154m" # #948A9A
|
|
50
|
+
self.OK = "\033[38;2;52;211;153m" # #34D399
|
|
51
|
+
self.WARN = "\033[38;2;251;191;36m" # #FBBF24
|
|
52
|
+
self.ERR = "\033[38;2;248;113;113m" # #F87171
|
|
53
|
+
self.INFO = "\033[38;2;255;169;77m" # #FFA94D
|
|
54
|
+
self.ACTIVE_BG = "\033[48;2;42;31;45m"
|
|
55
|
+
else:
|
|
56
|
+
self.ORANGE = "\033[93m"
|
|
57
|
+
self.CREAM = "\033[97m"
|
|
58
|
+
self.CRIMSON = "\033[35m"
|
|
59
|
+
self.MUTED = "\033[90m"
|
|
60
|
+
self.OK = "\033[92m"
|
|
61
|
+
self.WARN = "\033[33m"
|
|
62
|
+
self.ERR = "\033[91m"
|
|
63
|
+
self.INFO = "\033[93m"
|
|
64
|
+
self.ACTIVE_BG = ""
|