unk-scanner 0.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.
@@ -0,0 +1,65 @@
1
+ """Python interface to the bundled static JavaScript scanner.
2
+
3
+ Requires Node.js >=22. Submitted source is parsed, never executed.
4
+ """
5
+ from __future__ import annotations
6
+
7
+ import json
8
+ from pathlib import Path
9
+ import re
10
+ import shutil
11
+ import subprocess
12
+ import sys
13
+
14
+ __version__ = "0.1.0"
15
+
16
+
17
+ class ScannerError(RuntimeError):
18
+ """The scanner could not produce a complete analysis."""
19
+
20
+
21
+ def _command() -> list[str]:
22
+ node = shutil.which("node")
23
+ if node is None:
24
+ raise ScannerError("Node.js 22 or later is required; install Node.js and put node on PATH")
25
+ try:
26
+ version = subprocess.run(
27
+ [node, "--version"], capture_output=True, text=True, timeout=5, check=True
28
+ ).stdout.strip()
29
+ except (OSError, subprocess.SubprocessError) as error:
30
+ raise ScannerError("Could not check the installed Node.js version") from error
31
+ match = re.fullmatch(r"v(\d+)\.\d+\.\d+(?:[-+].*)?", version)
32
+ if not match or int(match[1]) < 22:
33
+ raise ScannerError(f"Node.js 22 or later is required; found {version!r}")
34
+ return [node, str(Path(__file__).parent / "_engine" / "bin" / "unk-scanner.mjs")]
35
+
36
+
37
+ def scan(path: str | Path, *, gzip: bool = False, timeout: float = 30) -> dict:
38
+ """Return the scanner's JSON result for one file.
39
+
40
+ gzip explicitly enables bounded gzip decoding. Findings are review leads;
41
+ artifactMatches are separate identity records, not malware verdicts.
42
+ """
43
+ if timeout <= 0:
44
+ raise ValueError("timeout must be positive")
45
+ args = _command() + (["--gzip"] if gzip else []) + ["--", str(path)]
46
+ try:
47
+ result = subprocess.run(args, capture_output=True, text=True, encoding="utf-8", timeout=timeout)
48
+ except (OSError, subprocess.SubprocessError) as error:
49
+ raise ScannerError(f"Scanner process failed: {error}") from error
50
+ if result.returncode:
51
+ raise ScannerError(result.stderr.strip() or f"Scanner exited with code {result.returncode}")
52
+ try:
53
+ return json.loads(result.stdout)
54
+ except json.JSONDecodeError as error:
55
+ raise ScannerError("Scanner returned invalid JSON") from error
56
+
57
+
58
+ def main() -> int:
59
+ try:
60
+ return subprocess.run(_command() + sys.argv[1:], timeout=30).returncode
61
+ except (ScannerError, OSError, subprocess.SubprocessError) as error:
62
+ print(f"unk-scanner: {error}", file=sys.stderr)
63
+ return 2
64
+ except KeyboardInterrupt:
65
+ return 130
@@ -0,0 +1,3 @@
1
+ from . import main
2
+
3
+ raise SystemExit(main())
@@ -0,0 +1,25 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 UNK_DeadDrop research contributors
4
+
5
+ This license applies only to original code, tests, configuration and detection
6
+ rules in this companion repository. It does not cover research prose or any
7
+ third-party evidence.
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ SOFTWARE.
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ import { main } from '../src/cli.mjs';
3
+ main(process.argv.slice(2)).catch(error => {
4
+ process.stderr.write('unk-scanner: ' + error.message + '\n');
5
+ process.exitCode = 2;
6
+ });