tlsLibHunter 0.3.0__tar.gz → 0.3.2__tar.gz
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.
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/CHANGELOG.md +31 -0
- {tlslibhunter-0.3.0/tlsLibHunter.egg-info → tlslibhunter-0.3.2}/PKG-INFO +25 -3
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/README.md +24 -1
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/setup.py +4 -5
- tlslibhunter-0.3.2/tests/test_android_related.py +268 -0
- tlslibhunter-0.3.2/tests/test_multi_process.py +247 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2/tlsLibHunter.egg-info}/PKG-INFO +25 -3
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlsLibHunter.egg-info/SOURCES.txt +4 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/about.py +1 -1
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/cli.py +89 -29
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/config.py +3 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/hunter.py +29 -0
- tlslibhunter-0.3.2/tlslibhunter/multi_process.py +150 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/output/json_formatter.py +5 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/output/plain_formatter.py +8 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/output/table_formatter.py +31 -0
- tlslibhunter-0.3.2/tlslibhunter/utils/android_related.py +208 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/LICENSE +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/MANIFEST.in +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/pyproject.toml +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/setup.cfg +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tests/test_adb.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tests/test_android_extractor_serial.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tests/test_android_process.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tests/test_classifier.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tests/test_cli.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tests/test_config.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tests/test_encoding.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tests/test_evidence_classification.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tests/test_fingerprints.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tests/test_memory_extractor.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tests/test_module_scanner_gates.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tests/test_native_dsc_extractor.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tests/test_output_formatters.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tests/test_pipeline_filtering.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tests/test_platform_overrides.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tests/test_reattach_session_adoption.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tests/test_resource_release.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tests/test_scan_truncation.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tests/test_tls_indicators.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tests/test_unfreeze_attach.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tests/test_wrong_target_attach.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlsLibHunter.egg-info/dependency_links.txt +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlsLibHunter.egg-info/entry_points.txt +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlsLibHunter.egg-info/requires.txt +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlsLibHunter.egg-info/top_level.txt +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/__init__.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/__main__.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/backends/__init__.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/backends/base.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/backends/frida_backend.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/extractor/__init__.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/extractor/android_extractor.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/extractor/base.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/extractor/disk_extractor.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/extractor/dyld_cache_extractor.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/extractor/ios_extractor.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/extractor/memory_extractor.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/extractor/native_dsc_extractor.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/extractor/strategy.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/output/__init__.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/output/_utils.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/platforms/__init__.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/platforms/android.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/platforms/base.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/platforms/detection.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/platforms/ios.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/platforms/linux.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/platforms/macos.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/platforms/windows.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/scanner/__init__.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/scanner/classifier.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/scanner/fingerprints.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/scanner/module_scanner.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/scanner/results.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/scanner/tls_indicators.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/scripts/extractor_agent.js +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/scripts/scanner_agent.js +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/utils/__init__.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/utils/adb.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/utils/android_process.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/utils/encoding.py +0 -0
- {tlslibhunter-0.3.0 → tlslibhunter-0.3.2}/tlslibhunter/utils/process_resolver.py +0 -0
|
@@ -5,6 +5,37 @@ All notable changes to tlsLibHunter will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
6
6
|
This file starts at 0.2.9; earlier versions are documented only in git history.
|
|
7
7
|
|
|
8
|
+
## [0.3.2]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- **Hint about related Android processes** — after attaching, tlsLibHunter
|
|
12
|
+
looks up the target's other processes (same package or same app UID) and
|
|
13
|
+
the package hosting the foreground UI. When another app hosts the UI it
|
|
14
|
+
logs a WARNING naming those PIDs, e.g. for the Gemini app
|
|
15
|
+
(`com.google.android.apps.bard`), whose launcher trampolines to the Google
|
|
16
|
+
app: "Foreground UI of 'com.google.android.apps.bard' is hosted by
|
|
17
|
+
'com.google.android.googlequicksearchbox' (PIDs 568 :search, 12274
|
|
18
|
+
:googleapp, ...). TLS traffic is likely there". Other processes of the
|
|
19
|
+
same app are reported at INFO.
|
|
20
|
+
- **`--all-processes`** (Android) — scans the target and then every related
|
|
21
|
+
process (UI host first, then sibling processes) through the regular
|
|
22
|
+
single-process scan with the same options (`--unfreeze`, `-o`/extraction
|
|
23
|
+
into per-PID directories, `-d`, ...). A process that cannot be scanned
|
|
24
|
+
(attach timeout, isolated/permission-denied, exited) is logged and the
|
|
25
|
+
remaining scans continue. Prints each process's table plus a combined
|
|
26
|
+
summary table; `-f json` prints one combined document. For Gemini this
|
|
27
|
+
finds the TLS libraries of the Google app processes that actually carry
|
|
28
|
+
its traffic. On other platforms it warns and scans only the target.
|
|
29
|
+
|
|
30
|
+
## [0.3.1]
|
|
31
|
+
|
|
32
|
+
### Fixed
|
|
33
|
+
- **Packaging warnings on install** — removed the deprecated
|
|
34
|
+
`License :: OSI Approved :: MIT License` classifier (the SPDX `license="MIT"`
|
|
35
|
+
field already declares it) and listed `tlslibhunter.scripts` explicitly as a
|
|
36
|
+
package so the bundled Frida agents (`*.js`) are no longer flagged as
|
|
37
|
+
"Package would be ignored".
|
|
38
|
+
|
|
8
39
|
## [0.3.0]
|
|
9
40
|
|
|
10
41
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tlsLibHunter
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.2
|
|
4
4
|
Summary: Identifies TLS/SSL libraries in running processes using Frida-based dynamic instrumentation.
|
|
5
5
|
Home-page: https://github.com/monkeywave/tlsLibHunter
|
|
6
6
|
Author: Daniel Baier
|
|
@@ -9,7 +9,6 @@ License: MIT
|
|
|
9
9
|
Project-URL: Source, https://github.com/monkeywave/tlsLibHunter
|
|
10
10
|
Project-URL: Issues, https://github.com/monkeywave/tlsLibHunter/issues
|
|
11
11
|
Keywords: frida,ssl,tls,instrumentation,security
|
|
12
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
13
12
|
Classifier: Operating System :: OS Independent
|
|
14
13
|
Classifier: Natural Language :: English
|
|
15
14
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
@@ -47,7 +46,7 @@ Dynamic: summary
|
|
|
47
46
|
|
|
48
47
|
|
|
49
48
|
# TLSLibHunter
|
|
50
|
-
 [](https://badge.fury.io/py/tlslibhunter) [](https://github.com/monkeywave/tlsLibHunter/actions/workflows/publish.yml)
|
|
51
50
|
[](https://github.com/monkeywave/tlsLibHunter/actions/workflows/lint.yml)
|
|
52
51
|
|
|
53
52
|
|
|
@@ -76,6 +75,9 @@ tlsLibHunter com.example.app -m -l
|
|
|
76
75
|
# JSON output
|
|
77
76
|
tlsLibHunter firefox -l -f json
|
|
78
77
|
|
|
78
|
+
# Android: scan the app AND its related processes (e.g. Gemini -> Google app)
|
|
79
|
+
tlsLibHunter Gemini --serial ABC123 --unfreeze --all-processes -l
|
|
80
|
+
|
|
79
81
|
# Full, unfiltered diagnostic scan (show known false positives + low-confidence hits)
|
|
80
82
|
tlsLibHunter com.example.app -m -l --scan-everything
|
|
81
83
|
|
|
@@ -133,6 +135,26 @@ extractions = hunter.extract(result, output_dir="./extracted_libs")
|
|
|
133
135
|
- Backend abstraction (currently only frida but might be extended to other frameworks in the future)
|
|
134
136
|
|
|
135
137
|
|
|
138
|
+
## Apps whose traffic runs in other processes (`--all-processes`)
|
|
139
|
+
|
|
140
|
+
tlsLibHunter attaches to **one** process. On Android the TLS traffic is not always there: apps
|
|
141
|
+
split work across several processes (`pkg:remote`, ...), and some are trampolines whose UI is
|
|
142
|
+
hosted by another package. Example: the Gemini app (`com.google.android.apps.bard`) hands its UI
|
|
143
|
+
to the Google app (`com.google.android.googlequicksearchbox:search`, `:googleapp`, ...).
|
|
144
|
+
|
|
145
|
+
After attaching, tlsLibHunter therefore logs a hint naming those related processes (WARNING when
|
|
146
|
+
another package hosts the foreground UI, INFO for other processes of the same app).
|
|
147
|
+
|
|
148
|
+
With `--all-processes` (Android only) it scans the target first and then every related process
|
|
149
|
+
(foreground-UI host first, then the app's other processes), each through the normal single-process
|
|
150
|
+
scan with the same options (`--unfreeze`, `-o`, `-l`, `-d`, ...). A process that cannot be scanned
|
|
151
|
+
(attach timeout, isolated/permission-denied, exited) is logged and skipped; the remaining scans
|
|
152
|
+
continue. Each process gets its usual results table, followed by a combined summary table
|
|
153
|
+
(process, PID, libraries found or error). With `-f json` a single combined document is printed:
|
|
154
|
+
`{"target": ..., "processes": [{"process", "pid", "error", "scan", "extractions"}, ...]}`.
|
|
155
|
+
Extracted libraries go to `./tls_libs_<pid>` per related process, or to `<DIR>/<pid>` with
|
|
156
|
+
`-o DIR`. On other platforms the flag logs a warning and only the target is scanned.
|
|
157
|
+
|
|
136
158
|
## Result filtering & scan depth
|
|
137
159
|
|
|
138
160
|
By default the results table is curated to show only **genuine, hookable TLS stacks** so the
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
# TLSLibHunter
|
|
9
|
-
 [](https://badge.fury.io/py/tlslibhunter) [](https://github.com/monkeywave/tlsLibHunter/actions/workflows/publish.yml)
|
|
10
10
|
[](https://github.com/monkeywave/tlsLibHunter/actions/workflows/lint.yml)
|
|
11
11
|
|
|
12
12
|
|
|
@@ -35,6 +35,9 @@ tlsLibHunter com.example.app -m -l
|
|
|
35
35
|
# JSON output
|
|
36
36
|
tlsLibHunter firefox -l -f json
|
|
37
37
|
|
|
38
|
+
# Android: scan the app AND its related processes (e.g. Gemini -> Google app)
|
|
39
|
+
tlsLibHunter Gemini --serial ABC123 --unfreeze --all-processes -l
|
|
40
|
+
|
|
38
41
|
# Full, unfiltered diagnostic scan (show known false positives + low-confidence hits)
|
|
39
42
|
tlsLibHunter com.example.app -m -l --scan-everything
|
|
40
43
|
|
|
@@ -92,6 +95,26 @@ extractions = hunter.extract(result, output_dir="./extracted_libs")
|
|
|
92
95
|
- Backend abstraction (currently only frida but might be extended to other frameworks in the future)
|
|
93
96
|
|
|
94
97
|
|
|
98
|
+
## Apps whose traffic runs in other processes (`--all-processes`)
|
|
99
|
+
|
|
100
|
+
tlsLibHunter attaches to **one** process. On Android the TLS traffic is not always there: apps
|
|
101
|
+
split work across several processes (`pkg:remote`, ...), and some are trampolines whose UI is
|
|
102
|
+
hosted by another package. Example: the Gemini app (`com.google.android.apps.bard`) hands its UI
|
|
103
|
+
to the Google app (`com.google.android.googlequicksearchbox:search`, `:googleapp`, ...).
|
|
104
|
+
|
|
105
|
+
After attaching, tlsLibHunter therefore logs a hint naming those related processes (WARNING when
|
|
106
|
+
another package hosts the foreground UI, INFO for other processes of the same app).
|
|
107
|
+
|
|
108
|
+
With `--all-processes` (Android only) it scans the target first and then every related process
|
|
109
|
+
(foreground-UI host first, then the app's other processes), each through the normal single-process
|
|
110
|
+
scan with the same options (`--unfreeze`, `-o`, `-l`, `-d`, ...). A process that cannot be scanned
|
|
111
|
+
(attach timeout, isolated/permission-denied, exited) is logged and skipped; the remaining scans
|
|
112
|
+
continue. Each process gets its usual results table, followed by a combined summary table
|
|
113
|
+
(process, PID, libraries found or error). With `-f json` a single combined document is printed:
|
|
114
|
+
`{"target": ..., "processes": [{"process", "pid", "error", "scan", "extractions"}, ...]}`.
|
|
115
|
+
Extracted libraries go to `./tls_libs_<pid>` per related process, or to `<DIR>/<pid>` with
|
|
116
|
+
`-o DIR`. On other platforms the flag logs a warning and only the target is scanned.
|
|
117
|
+
|
|
95
118
|
## Result filtering & scan depth
|
|
96
119
|
|
|
97
120
|
By default the results table is curated to show only **genuine, hookable TLS stacks** so the
|
|
@@ -35,7 +35,9 @@ setup(
|
|
|
35
35
|
author=about.__author__,
|
|
36
36
|
author_email="daniel.baier@fkie.fraunhofer.de",
|
|
37
37
|
license="MIT",
|
|
38
|
-
|
|
38
|
+
# "tlslibhunter.scripts" holds only the Frida agents (*.js), so it has no
|
|
39
|
+
# __init__.py and find_packages() skips it; list it explicitly.
|
|
40
|
+
packages=find_packages(exclude=("tests",)) + ["tlslibhunter.scripts"],
|
|
39
41
|
python_requires=">=3.8",
|
|
40
42
|
install_requires=install_requires,
|
|
41
43
|
extras_require={
|
|
@@ -43,13 +45,10 @@ setup(
|
|
|
43
45
|
},
|
|
44
46
|
# Include non-Python assets inside the package
|
|
45
47
|
package_data={
|
|
46
|
-
"tlslibhunter": [
|
|
47
|
-
"scripts/*.js",
|
|
48
|
-
],
|
|
48
|
+
"tlslibhunter.scripts": ["*.js"],
|
|
49
49
|
},
|
|
50
50
|
include_package_data=True,
|
|
51
51
|
classifiers=[
|
|
52
|
-
"License :: OSI Approved :: MIT License",
|
|
53
52
|
"Operating System :: OS Independent",
|
|
54
53
|
"Natural Language :: English",
|
|
55
54
|
"Programming Language :: Python :: 3 :: Only",
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
"""Tests for discovering Android processes related to the attached target.
|
|
2
|
+
|
|
3
|
+
Samples are taken from a real device where the Gemini app
|
|
4
|
+
(com.google.android.apps.bard) hands its UI to the Google app's :search process.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import logging
|
|
8
|
+
|
|
9
|
+
import pytest
|
|
10
|
+
|
|
11
|
+
from tlslibhunter.config import HunterConfig
|
|
12
|
+
from tlslibhunter.hunter import TLSLibHunter
|
|
13
|
+
from tlslibhunter.utils import android_related as ar
|
|
14
|
+
from tlslibhunter.utils.android_related import ProcessEntry
|
|
15
|
+
|
|
16
|
+
MODULE_ADB = "tlslibhunter.utils.android_related.adb_shell"
|
|
17
|
+
BARD = "com.google.android.apps.bard"
|
|
18
|
+
GSA = "com.google.android.googlequicksearchbox"
|
|
19
|
+
|
|
20
|
+
PS_SAMPLE = """\
|
|
21
|
+
PID UID NAME
|
|
22
|
+
1 0 init
|
|
23
|
+
568 10156 com.google.android.googlequicksearchbox:search
|
|
24
|
+
1031 1000 android.hardware.camera.provider@2.7-service-google
|
|
25
|
+
5875 10156 com.google.android.googlequicksearchbox:interactor
|
|
26
|
+
6818 10301 com.google.android.apps.bard
|
|
27
|
+
13022 99078 com.google.android.webview:sandboxed_process0:org.chromium.content.app.SandboxedProcessService0:0
|
|
28
|
+
18860 10208 com.google.android.apps.nexuslauncher
|
|
29
|
+
19016 10162 com.google.android.gms
|
|
30
|
+
26820 10156 com.google.android.googlequicksearchbox:googleapp
|
|
31
|
+
29254 1000 com.google.SSRestartDetector
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
DUMPSYS_MODERN = """\
|
|
35
|
+
RootWindowContainer:
|
|
36
|
+
topResumedActivity=ActivityRecord{ca91732 u0 com.google.android.googlequicksearchbox/com.google.android.apps.search.assistant.surfaces.voice.robin.main.MainActivity t2241}
|
|
37
|
+
ResumedActivity: ActivityRecord{ca91732 u0 com.google.android.googlequicksearchbox/com.google.android.apps.search.assistant.surfaces.voice.robin.main.MainActivity t2241}
|
|
38
|
+
""" # noqa: E501 (verbatim device output)
|
|
39
|
+
|
|
40
|
+
DUMPSYS_LEGACY = """\
|
|
41
|
+
Stack #1:
|
|
42
|
+
mResumedActivity: ActivityRecord{4f2b1a u0 com.example.app/.MainActivity t12}
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def gsa_procs():
|
|
47
|
+
return [
|
|
48
|
+
ProcessEntry(568, 10156, f"{GSA}:search"),
|
|
49
|
+
ProcessEntry(5875, 10156, f"{GSA}:interactor"),
|
|
50
|
+
ProcessEntry(26820, 10156, f"{GSA}:googleapp"),
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class FakeAdb:
|
|
55
|
+
"""Answers adb_shell calls by command substring and records them."""
|
|
56
|
+
|
|
57
|
+
def __init__(self, responses):
|
|
58
|
+
self.responses = responses
|
|
59
|
+
self.calls = []
|
|
60
|
+
|
|
61
|
+
def __call__(self, cmd, serial=None):
|
|
62
|
+
self.calls.append((cmd, serial))
|
|
63
|
+
for needle, result in self.responses:
|
|
64
|
+
if needle in cmd:
|
|
65
|
+
return result
|
|
66
|
+
return 1, "unexpected"
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def install(monkeypatch, responses):
|
|
70
|
+
fake = FakeAdb(responses)
|
|
71
|
+
monkeypatch.setattr(MODULE_ADB, fake)
|
|
72
|
+
return fake
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class TestParsePsOutput:
|
|
76
|
+
def test_parses_rows_and_skips_header(self):
|
|
77
|
+
procs = ar.parse_ps_output(PS_SAMPLE)
|
|
78
|
+
assert procs[0] == ProcessEntry(1, 0, "init")
|
|
79
|
+
assert ProcessEntry(568, 10156, f"{GSA}:search") in procs
|
|
80
|
+
assert len(procs) == 10
|
|
81
|
+
|
|
82
|
+
def test_keeps_names_with_colons(self):
|
|
83
|
+
procs = ar.parse_ps_output(PS_SAMPLE)
|
|
84
|
+
assert any(p.name.endswith("SandboxedProcessService0:0") for p in procs)
|
|
85
|
+
|
|
86
|
+
@pytest.mark.parametrize("text", ["", "garbage", " PID UID NAME", "abc 10 x", "12"])
|
|
87
|
+
def test_malformed_input_yields_nothing(self, text):
|
|
88
|
+
assert ar.parse_ps_output(text) == []
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class TestParseForegroundPackage:
|
|
92
|
+
def test_modern_top_resumed_activity(self):
|
|
93
|
+
assert ar.parse_foreground_package(DUMPSYS_MODERN) == GSA
|
|
94
|
+
|
|
95
|
+
def test_legacy_m_resumed_activity(self):
|
|
96
|
+
assert ar.parse_foreground_package(DUMPSYS_LEGACY) == "com.example.app"
|
|
97
|
+
|
|
98
|
+
def test_top_resumed_wins_over_others(self):
|
|
99
|
+
text = DUMPSYS_LEGACY + "topResumedActivity=ActivityRecord{1 u0 com.top.app/.A t1}\n"
|
|
100
|
+
assert ar.parse_foreground_package(text) == "com.top.app"
|
|
101
|
+
|
|
102
|
+
@pytest.mark.parametrize("text", ["", "topResumedActivity=null", "mResumedActivity: null"])
|
|
103
|
+
def test_no_resumed_activity(self, text):
|
|
104
|
+
assert ar.parse_foreground_package(text) is None
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class TestPackageHelpers:
|
|
108
|
+
@pytest.mark.parametrize(
|
|
109
|
+
"name,expected",
|
|
110
|
+
[(BARD, BARD), (f"{GSA}:search", GSA), ("init", "init")],
|
|
111
|
+
)
|
|
112
|
+
def test_package_of(self, name, expected):
|
|
113
|
+
assert ar.package_of(name) == expected
|
|
114
|
+
|
|
115
|
+
@pytest.mark.parametrize(
|
|
116
|
+
"name,expected",
|
|
117
|
+
[(GSA, True), (f"{GSA}:search", True), (f"{GSA}x", False), ("com.google.android", False)],
|
|
118
|
+
)
|
|
119
|
+
def test_belongs_to_package(self, name, expected):
|
|
120
|
+
assert ar.belongs_to_package(name, GSA) is expected
|
|
121
|
+
|
|
122
|
+
@pytest.mark.parametrize(
|
|
123
|
+
"foreground,target,expected",
|
|
124
|
+
[
|
|
125
|
+
(GSA, BARD, True),
|
|
126
|
+
(BARD, BARD, False),
|
|
127
|
+
(None, BARD, False),
|
|
128
|
+
(GSA, None, False),
|
|
129
|
+
("com.android.systemui", BARD, False),
|
|
130
|
+
("com.google.android.apps.nexuslauncher", BARD, False),
|
|
131
|
+
],
|
|
132
|
+
)
|
|
133
|
+
def test_is_plausible_delegate(self, foreground, target, expected):
|
|
134
|
+
assert ar.is_plausible_delegate(foreground, target) is expected
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
class TestBuildRelatedProcesses:
|
|
138
|
+
def test_gemini_trampoline_to_gsa(self):
|
|
139
|
+
related = ar.build_related_processes(ar.parse_ps_output(PS_SAMPLE), 6818, None, GSA)
|
|
140
|
+
assert related.target_package == BARD
|
|
141
|
+
assert related.target_pid == 6818
|
|
142
|
+
assert related.sibling_processes == []
|
|
143
|
+
assert related.foreground_package == GSA
|
|
144
|
+
assert related.delegate_processes == gsa_procs()
|
|
145
|
+
assert related.has_delegate
|
|
146
|
+
assert related.related_pids == [568, 5875, 26820]
|
|
147
|
+
|
|
148
|
+
def test_siblings_by_package_and_uid(self):
|
|
149
|
+
related = ar.build_related_processes(ar.parse_ps_output(PS_SAMPLE), 568, None, GSA)
|
|
150
|
+
assert related.target_package == GSA
|
|
151
|
+
assert [p.pid for p in related.sibling_processes] == [5875, 26820]
|
|
152
|
+
assert not related.has_delegate
|
|
153
|
+
|
|
154
|
+
def test_system_uid_is_not_used_for_siblings(self):
|
|
155
|
+
related = ar.build_related_processes(ar.parse_ps_output(PS_SAMPLE), 29254, None, None)
|
|
156
|
+
assert related.sibling_processes == []
|
|
157
|
+
|
|
158
|
+
def test_falls_back_to_package_when_pid_unknown(self):
|
|
159
|
+
related = ar.build_related_processes(ar.parse_ps_output(PS_SAMPLE), None, GSA, None)
|
|
160
|
+
assert related.target_package == GSA
|
|
161
|
+
assert [p.pid for p in related.sibling_processes] == [568, 5875, 26820]
|
|
162
|
+
|
|
163
|
+
def test_unidentifiable_target(self):
|
|
164
|
+
assert ar.build_related_processes(ar.parse_ps_output(PS_SAMPLE), 4242, None, GSA) is None
|
|
165
|
+
|
|
166
|
+
def test_launcher_in_foreground_is_not_a_delegate(self):
|
|
167
|
+
launcher = "com.google.android.apps.nexuslauncher"
|
|
168
|
+
related = ar.build_related_processes(ar.parse_ps_output(PS_SAMPLE), 6818, None, launcher)
|
|
169
|
+
assert related.delegate_processes == []
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
class TestFindRelatedProcesses:
|
|
173
|
+
def test_queries_device_with_serial(self, monkeypatch):
|
|
174
|
+
fake = install(monkeypatch, [("ps -A", (0, PS_SAMPLE)), ("dumpsys", (0, DUMPSYS_MODERN))])
|
|
175
|
+
related = ar.find_related_processes("SER123", target_pid=6818)
|
|
176
|
+
assert related.delegate_processes == gsa_procs()
|
|
177
|
+
assert all(serial == "SER123" for _, serial in fake.calls)
|
|
178
|
+
|
|
179
|
+
def test_ps_failure_returns_none(self, monkeypatch):
|
|
180
|
+
install(monkeypatch, [("ps -A", (1, "error: device offline"))])
|
|
181
|
+
assert ar.find_related_processes("SER123", target_pid=6818) is None
|
|
182
|
+
|
|
183
|
+
def test_dumpsys_failure_keeps_siblings(self, monkeypatch):
|
|
184
|
+
install(monkeypatch, [("ps -A", (0, PS_SAMPLE)), ("dumpsys", (1, "boom"))])
|
|
185
|
+
related = ar.find_related_processes(None, target_pid=568)
|
|
186
|
+
assert related.foreground_package is None
|
|
187
|
+
assert [p.pid for p in related.sibling_processes] == [5875, 26820]
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
class TestFormatRelatedHint:
|
|
191
|
+
def test_delegate_warning(self):
|
|
192
|
+
related = ar.RelatedProcesses(BARD, 6818, [], GSA, gsa_procs())
|
|
193
|
+
level, message = ar.format_related_hint(related)
|
|
194
|
+
assert level == logging.WARNING
|
|
195
|
+
assert message == (
|
|
196
|
+
f"Foreground UI of '{BARD}' is hosted by '{GSA}' "
|
|
197
|
+
"(PIDs 568 :search, 5875 :interactor, 26820 :googleapp). "
|
|
198
|
+
"TLS traffic is likely there — scan those PIDs or use --all-processes."
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
def test_siblings_info(self):
|
|
202
|
+
related = ar.RelatedProcesses(GSA, 568, gsa_procs()[1:])
|
|
203
|
+
level, message = ar.format_related_hint(related)
|
|
204
|
+
assert level == logging.INFO
|
|
205
|
+
assert "PIDs 5875 :interactor, 26820 :googleapp" in message
|
|
206
|
+
assert "--all-processes" in message
|
|
207
|
+
|
|
208
|
+
def test_same_uid_sibling_with_other_name_is_labelled_in_full(self):
|
|
209
|
+
related = ar.RelatedProcesses(
|
|
210
|
+
"com.google.android.gms", 19016, [ProcessEntry(1, 10162, "com.google.process.gservices")]
|
|
211
|
+
)
|
|
212
|
+
_, message = ar.format_related_hint(related)
|
|
213
|
+
assert "1 com.google.process.gservices" in message
|
|
214
|
+
|
|
215
|
+
@pytest.mark.parametrize("related", [None, ar.RelatedProcesses(BARD, 6818)])
|
|
216
|
+
def test_nothing_to_report(self, related):
|
|
217
|
+
assert ar.format_related_hint(related) is None
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
class FakeDevice:
|
|
221
|
+
id = "SER123"
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
class FakeBackend:
|
|
225
|
+
def __init__(self, platform="android"):
|
|
226
|
+
self.platform = platform
|
|
227
|
+
|
|
228
|
+
def get_device(self, **kwargs):
|
|
229
|
+
return FakeDevice()
|
|
230
|
+
|
|
231
|
+
def get_device_platform(self, device):
|
|
232
|
+
return self.platform
|
|
233
|
+
|
|
234
|
+
def attach(self, device, target, timeout=10):
|
|
235
|
+
return object()
|
|
236
|
+
|
|
237
|
+
def describe_session(self, device, session):
|
|
238
|
+
return {"pid": 6818, "name": "Gemini"}
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def _initialize(monkeypatch, platform="android", target="Gemini"):
|
|
242
|
+
monkeypatch.setattr("tlslibhunter.backends.get_backend", lambda name: FakeBackend(platform))
|
|
243
|
+
hunter = TLSLibHunter.from_config(HunterConfig(target=target, mobile=True))
|
|
244
|
+
hunter._initialize()
|
|
245
|
+
return hunter
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
class TestHunterHint:
|
|
249
|
+
def test_warns_about_delegate_after_attach(self, monkeypatch, caplog):
|
|
250
|
+
fake = install(monkeypatch, [("ps -A", (0, PS_SAMPLE)), ("dumpsys", (0, DUMPSYS_MODERN))])
|
|
251
|
+
with caplog.at_level(logging.INFO, logger="tlslibhunter"):
|
|
252
|
+
hunter = _initialize(monkeypatch)
|
|
253
|
+
assert hunter._initialized
|
|
254
|
+
assert fake.calls[0][1] == "SER123"
|
|
255
|
+
warnings = [r.getMessage() for r in caplog.records if r.levelno == logging.WARNING]
|
|
256
|
+
assert any(f"hosted by '{GSA}'" in w for w in warnings)
|
|
257
|
+
|
|
258
|
+
def test_adb_errors_never_break_initialize(self, monkeypatch):
|
|
259
|
+
def explode(cmd, serial=None):
|
|
260
|
+
raise RuntimeError("adb exploded")
|
|
261
|
+
|
|
262
|
+
monkeypatch.setattr(MODULE_ADB, explode)
|
|
263
|
+
assert _initialize(monkeypatch)._initialized
|
|
264
|
+
|
|
265
|
+
def test_non_android_platform_skips_lookup(self, monkeypatch):
|
|
266
|
+
fake = install(monkeypatch, [])
|
|
267
|
+
_initialize(monkeypatch, platform="linux", target="firefox")
|
|
268
|
+
assert fake.calls == []
|