tlsLibHunter 0.3.1__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.
Files changed (83) hide show
  1. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/CHANGELOG.md +22 -0
  2. {tlslibhunter-0.3.1/tlsLibHunter.egg-info → tlslibhunter-0.3.2}/PKG-INFO +25 -2
  3. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/README.md +24 -1
  4. tlslibhunter-0.3.2/tests/test_android_related.py +268 -0
  5. tlslibhunter-0.3.2/tests/test_multi_process.py +247 -0
  6. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2/tlsLibHunter.egg-info}/PKG-INFO +25 -2
  7. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlsLibHunter.egg-info/SOURCES.txt +4 -0
  8. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/about.py +1 -1
  9. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/cli.py +89 -29
  10. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/config.py +3 -0
  11. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/hunter.py +29 -0
  12. tlslibhunter-0.3.2/tlslibhunter/multi_process.py +150 -0
  13. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/output/json_formatter.py +5 -0
  14. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/output/plain_formatter.py +8 -0
  15. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/output/table_formatter.py +31 -0
  16. tlslibhunter-0.3.2/tlslibhunter/utils/android_related.py +208 -0
  17. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/LICENSE +0 -0
  18. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/MANIFEST.in +0 -0
  19. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/pyproject.toml +0 -0
  20. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/setup.cfg +0 -0
  21. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/setup.py +0 -0
  22. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tests/test_adb.py +0 -0
  23. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tests/test_android_extractor_serial.py +0 -0
  24. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tests/test_android_process.py +0 -0
  25. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tests/test_classifier.py +0 -0
  26. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tests/test_cli.py +0 -0
  27. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tests/test_config.py +0 -0
  28. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tests/test_encoding.py +0 -0
  29. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tests/test_evidence_classification.py +0 -0
  30. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tests/test_fingerprints.py +0 -0
  31. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tests/test_memory_extractor.py +0 -0
  32. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tests/test_module_scanner_gates.py +0 -0
  33. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tests/test_native_dsc_extractor.py +0 -0
  34. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tests/test_output_formatters.py +0 -0
  35. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tests/test_pipeline_filtering.py +0 -0
  36. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tests/test_platform_overrides.py +0 -0
  37. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tests/test_reattach_session_adoption.py +0 -0
  38. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tests/test_resource_release.py +0 -0
  39. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tests/test_scan_truncation.py +0 -0
  40. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tests/test_tls_indicators.py +0 -0
  41. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tests/test_unfreeze_attach.py +0 -0
  42. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tests/test_wrong_target_attach.py +0 -0
  43. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlsLibHunter.egg-info/dependency_links.txt +0 -0
  44. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlsLibHunter.egg-info/entry_points.txt +0 -0
  45. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlsLibHunter.egg-info/requires.txt +0 -0
  46. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlsLibHunter.egg-info/top_level.txt +0 -0
  47. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/__init__.py +0 -0
  48. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/__main__.py +0 -0
  49. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/backends/__init__.py +0 -0
  50. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/backends/base.py +0 -0
  51. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/backends/frida_backend.py +0 -0
  52. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/extractor/__init__.py +0 -0
  53. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/extractor/android_extractor.py +0 -0
  54. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/extractor/base.py +0 -0
  55. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/extractor/disk_extractor.py +0 -0
  56. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/extractor/dyld_cache_extractor.py +0 -0
  57. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/extractor/ios_extractor.py +0 -0
  58. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/extractor/memory_extractor.py +0 -0
  59. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/extractor/native_dsc_extractor.py +0 -0
  60. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/extractor/strategy.py +0 -0
  61. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/output/__init__.py +0 -0
  62. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/output/_utils.py +0 -0
  63. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/platforms/__init__.py +0 -0
  64. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/platforms/android.py +0 -0
  65. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/platforms/base.py +0 -0
  66. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/platforms/detection.py +0 -0
  67. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/platforms/ios.py +0 -0
  68. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/platforms/linux.py +0 -0
  69. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/platforms/macos.py +0 -0
  70. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/platforms/windows.py +0 -0
  71. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/scanner/__init__.py +0 -0
  72. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/scanner/classifier.py +0 -0
  73. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/scanner/fingerprints.py +0 -0
  74. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/scanner/module_scanner.py +0 -0
  75. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/scanner/results.py +0 -0
  76. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/scanner/tls_indicators.py +0 -0
  77. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/scripts/extractor_agent.js +0 -0
  78. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/scripts/scanner_agent.js +0 -0
  79. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/utils/__init__.py +0 -0
  80. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/utils/adb.py +0 -0
  81. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/utils/android_process.py +0 -0
  82. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/utils/encoding.py +0 -0
  83. {tlslibhunter-0.3.1 → tlslibhunter-0.3.2}/tlslibhunter/utils/process_resolver.py +0 -0
@@ -5,6 +5,28 @@ 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
+
8
30
  ## [0.3.1]
9
31
 
10
32
  ### Fixed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tlsLibHunter
3
- Version: 0.3.1
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
@@ -46,7 +46,7 @@ Dynamic: summary
46
46
 
47
47
 
48
48
  # TLSLibHunter
49
- ![version](https://img.shields.io/badge/version-0.3.1-blue) [![PyPI version](https://badge.fury.io/py/tlslibhunter.svg)](https://badge.fury.io/py/tlslibhunter) [![Publish status](https://github.com/monkeywave/tlsLibHunter/actions/workflows/publish.yml/badge.svg?branch=main)](https://github.com/monkeywave/tlsLibHunter/actions/workflows/publish.yml)
49
+ ![version](https://img.shields.io/badge/version-0.3.2-blue) [![PyPI version](https://badge.fury.io/py/tlslibhunter.svg)](https://badge.fury.io/py/tlslibhunter) [![Publish status](https://github.com/monkeywave/tlsLibHunter/actions/workflows/publish.yml/badge.svg?branch=main)](https://github.com/monkeywave/tlsLibHunter/actions/workflows/publish.yml)
50
50
  [![Lint](https://github.com/monkeywave/tlsLibHunter/actions/workflows/lint.yml/badge.svg)](https://github.com/monkeywave/tlsLibHunter/actions/workflows/lint.yml)
51
51
 
52
52
 
@@ -75,6 +75,9 @@ tlsLibHunter com.example.app -m -l
75
75
  # JSON output
76
76
  tlsLibHunter firefox -l -f json
77
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
+
78
81
  # Full, unfiltered diagnostic scan (show known false positives + low-confidence hits)
79
82
  tlsLibHunter com.example.app -m -l --scan-everything
80
83
 
@@ -132,6 +135,26 @@ extractions = hunter.extract(result, output_dir="./extracted_libs")
132
135
  - Backend abstraction (currently only frida but might be extended to other frameworks in the future)
133
136
 
134
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
+
135
158
  ## Result filtering & scan depth
136
159
 
137
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
- ![version](https://img.shields.io/badge/version-0.3.1-blue) [![PyPI version](https://badge.fury.io/py/tlslibhunter.svg)](https://badge.fury.io/py/tlslibhunter) [![Publish status](https://github.com/monkeywave/tlsLibHunter/actions/workflows/publish.yml/badge.svg?branch=main)](https://github.com/monkeywave/tlsLibHunter/actions/workflows/publish.yml)
9
+ ![version](https://img.shields.io/badge/version-0.3.2-blue) [![PyPI version](https://badge.fury.io/py/tlslibhunter.svg)](https://badge.fury.io/py/tlslibhunter) [![Publish status](https://github.com/monkeywave/tlsLibHunter/actions/workflows/publish.yml/badge.svg?branch=main)](https://github.com/monkeywave/tlsLibHunter/actions/workflows/publish.yml)
10
10
  [![Lint](https://github.com/monkeywave/tlsLibHunter/actions/workflows/lint.yml/badge.svg)](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
@@ -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 == []
@@ -0,0 +1,247 @@
1
+ """Tests for --all-processes orchestration (target + related Android processes)."""
2
+
3
+ import json
4
+ import logging
5
+
6
+ from tlslibhunter.backends.base import AttachTimeoutError
7
+ from tlslibhunter.cli import build_parser, main
8
+ from tlslibhunter.config import HunterConfig
9
+ from tlslibhunter.multi_process import (
10
+ ProcessScanOutcome,
11
+ config_for_pid,
12
+ related_pids_for,
13
+ safe_scan,
14
+ scan_all_processes,
15
+ summary_rows,
16
+ )
17
+ from tlslibhunter.output import get_formatter
18
+ from tlslibhunter.scanner.results import DetectedLibrary, ScanResult
19
+ from tlslibhunter.utils.android_related import ProcessEntry, RelatedProcesses
20
+
21
+ BARD = "com.google.android.apps.bard"
22
+ GSA = "com.google.android.googlequicksearchbox"
23
+
24
+
25
+ def _result(name, pid, libs, platform="android"):
26
+ return ScanResult(
27
+ target=name,
28
+ platform=platform,
29
+ libraries=[DetectedLibrary(name=lib, path=f"/x/{lib}") for lib in libs],
30
+ attached_process=name,
31
+ attached_pid=pid,
32
+ )
33
+
34
+
35
+ def _related(target_pid=6818):
36
+ return RelatedProcesses(
37
+ target_package=BARD,
38
+ target_pid=target_pid,
39
+ sibling_processes=[ProcessEntry(7000, 10301, f"{BARD}:remote")],
40
+ foreground_package=GSA,
41
+ delegate_processes=[ProcessEntry(568, 10156, f"{GSA}:search"), ProcessEntry(26820, 10156, f"{GSA}:googleapp")],
42
+ )
43
+
44
+
45
+ def _fake_find_related(related):
46
+ calls = []
47
+
48
+ def find(serial, pid, package):
49
+ calls.append((serial, pid, package))
50
+ return related
51
+
52
+ find.calls = calls
53
+ return find
54
+
55
+
56
+ class TestConfigForPid:
57
+ def test_attaches_by_pid_and_keeps_options(self):
58
+ base = HunterConfig(target="Gemini", serial="S1", unfreeze=True, spawn=True, list_only=True, debug=True)
59
+ cfg = config_for_pid(base, 568)
60
+ assert cfg.target == "568"
61
+ assert cfg.spawn is False
62
+ assert (cfg.serial, cfg.unfreeze, cfg.list_only, cfg.debug) == ("S1", True, True, True)
63
+ assert cfg.output_dir is None
64
+ assert cfg.effective_output_dir == "./tls_libs_568"
65
+
66
+ def test_output_dir_gets_per_pid_subdirectory(self, tmp_path):
67
+ cfg = config_for_pid(HunterConfig(target="Gemini", output_dir=str(tmp_path)), 568)
68
+ assert cfg.output_dir == str(tmp_path / "568")
69
+
70
+ def test_does_not_mutate_original(self):
71
+ base = HunterConfig(target="Gemini")
72
+ config_for_pid(base, 1)
73
+ assert base.target == "Gemini"
74
+
75
+
76
+ class TestRelatedPids:
77
+ def test_delegates_first_then_siblings(self):
78
+ outcome = ProcessScanOutcome(target="Gemini", result=_result(BARD, 6818, []))
79
+ find = _fake_find_related(_related())
80
+ pids = related_pids_for(outcome, HunterConfig(target="Gemini", serial="S1"), find)
81
+ assert pids == [568, 26820, 7000]
82
+ assert find.calls == [("S1", 6818, None)]
83
+
84
+ def test_target_pid_is_excluded(self):
85
+ related = _related()
86
+ related.sibling_processes.append(ProcessEntry(6818, 10301, BARD))
87
+ outcome = ProcessScanOutcome(target="Gemini", result=_result(BARD, 6818, []))
88
+ assert 6818 not in related_pids_for(outcome, HunterConfig(target="Gemini"), _fake_find_related(related))
89
+
90
+ def test_package_target_is_passed_for_lookup(self):
91
+ find = _fake_find_related(None)
92
+ outcome = ProcessScanOutcome(target=BARD, result=_result(BARD, 6818, []))
93
+ assert related_pids_for(outcome, HunterConfig(target=BARD), find) == []
94
+ assert find.calls == [(None, 6818, BARD)]
95
+
96
+ def test_failed_target_uses_pid_from_error(self):
97
+ find = _fake_find_related(_related())
98
+ outcome = ProcessScanOutcome(target="Gemini", error="timeout", pid=6818)
99
+ assert related_pids_for(outcome, HunterConfig(target="Gemini", mobile=True), find) == [568, 26820, 7000]
100
+
101
+ def test_non_android_warns_and_returns_nothing(self, caplog):
102
+ find = _fake_find_related(_related())
103
+ outcome = ProcessScanOutcome(target="firefox", result=_result("firefox", 1, [], platform="linux"))
104
+ with caplog.at_level(logging.WARNING, logger="tlslibhunter"):
105
+ assert related_pids_for(outcome, HunterConfig(target="firefox"), find) == []
106
+ assert "only supported on Android" in caplog.text
107
+ assert find.calls == []
108
+
109
+ def test_lookup_exception_is_contained(self):
110
+ def boom(*_):
111
+ raise RuntimeError("adb gone")
112
+
113
+ outcome = ProcessScanOutcome(target="Gemini", result=_result(BARD, 6818, []))
114
+ assert related_pids_for(outcome, HunterConfig(target="Gemini"), boom) == []
115
+
116
+
117
+ class TestFailureIsolation:
118
+ def test_safe_scan_records_error_and_pid(self):
119
+ def scan_one(cfg):
120
+ raise AttachTimeoutError("timed out", target=cfg.target, pid=568)
121
+
122
+ outcome = safe_scan(scan_one, HunterConfig(target="568"))
123
+ assert not outcome.succeeded
124
+ assert outcome.error == "timed out"
125
+ assert outcome.pid == 568
126
+
127
+ def test_one_failure_does_not_abort_remaining_scans(self):
128
+ scanned = []
129
+
130
+ def scan_one(cfg):
131
+ scanned.append(cfg.target)
132
+ if cfg.target == "568":
133
+ raise PermissionError("isolated process")
134
+ pid = 6818 if cfg.target == "Gemini" else int(cfg.target)
135
+ return ProcessScanOutcome(target=cfg.target, result=_result(cfg.target, pid, ["libssl.so"]))
136
+
137
+ outcomes = scan_all_processes(HunterConfig(target="Gemini"), scan_one, _fake_find_related(_related()))
138
+ assert scanned == ["Gemini", "568", "26820", "7000"]
139
+ assert [o.succeeded for o in outcomes] == [True, False, True, True]
140
+ assert outcomes[1].error == "isolated process"
141
+
142
+ def test_no_related_processes_scans_only_target(self):
143
+ def scan_one(cfg):
144
+ return ProcessScanOutcome(target=cfg.target, result=_result(BARD, 6818, []))
145
+
146
+ outcomes = scan_all_processes(HunterConfig(target="Gemini"), scan_one, _fake_find_related(None))
147
+ assert len(outcomes) == 1
148
+
149
+
150
+ class TestScanOneProcessKeepsPid:
151
+ def test_failure_after_attach_reports_hunter_pid(self, monkeypatch):
152
+ from tlslibhunter.cli import _scan_one_process
153
+ from tlslibhunter.hunter import TLSLibHunter
154
+
155
+ class _AttachedThenFails:
156
+ attached_pid = 13895
157
+
158
+ def __enter__(self):
159
+ return self
160
+
161
+ def __exit__(self, *exc):
162
+ return False
163
+
164
+ def scan(self):
165
+ raise RuntimeError("the connection is closed")
166
+
167
+ monkeypatch.setattr(TLSLibHunter, "from_config", classmethod(lambda cls, cfg: _AttachedThenFails()))
168
+ outcome = _scan_one_process(HunterConfig(target="Gemini", list_only=True), get_formatter("plain"), True)
169
+ assert outcome.error == "the connection is closed"
170
+ assert outcome.process_pid == 13895
171
+
172
+
173
+ class TestSummary:
174
+ def _outcomes(self):
175
+ return [
176
+ ProcessScanOutcome(target="Gemini", result=_result(BARD, 6818, ["libssl.so", "libhttpengine.so"])),
177
+ ProcessScanOutcome(target="568", error="timed out\nhint line", pid=568),
178
+ ProcessScanOutcome(target="7000", result=_result(f"{BARD}:remote", 7000, [])),
179
+ ]
180
+
181
+ def test_summary_rows(self):
182
+ assert summary_rows(self._outcomes()) == [
183
+ (BARD, "6818", "libssl.so, libhttpengine.so"),
184
+ ("568", "568", "ERROR: timed out"),
185
+ (f"{BARD}:remote", "7000", "none"),
186
+ ]
187
+
188
+ def test_incomplete_scan_is_flagged(self):
189
+ result = _result("gsa:googleapp", 12274, ["libssl.so"])
190
+ result.errors = ["Scan stopped: target process died"]
191
+ rows = summary_rows([ProcessScanOutcome(target="12274", result=result)])
192
+ assert rows == [("gsa:googleapp", "12274", "libssl.so (INCOMPLETE: 1 error(s))")]
193
+
194
+ def test_table_and_plain_summaries_list_every_process(self):
195
+ for fmt in ("table", "plain"):
196
+ text = get_formatter(fmt).format_process_summary("Gemini", self._outcomes())
197
+ assert "libhttpengine.so" in text
198
+ assert "ERROR: timed out" in text
199
+ assert "7000" in text
200
+
201
+ def test_json_summary_is_one_combined_document(self):
202
+ doc = json.loads(get_formatter("json").format_process_summary("Gemini", self._outcomes()))
203
+ assert doc["target"] == "Gemini"
204
+ assert [p["pid"] for p in doc["processes"]] == [6818, 568, 7000]
205
+ assert doc["processes"][0]["scan"]["tls_library_count"] == 2
206
+ assert doc["processes"][1]["scan"] is None
207
+ assert doc["processes"][1]["error"].startswith("timed out")
208
+
209
+
210
+ class TestCliWiring:
211
+ def test_flag_parses_and_defaults_false(self):
212
+ assert build_parser().parse_args(["Gemini", "--all-processes"]).all_processes is True
213
+ assert build_parser().parse_args(["Gemini"]).all_processes is False
214
+
215
+ def test_main_routes_to_orchestrator_and_prints_summary(self, monkeypatch, capsys):
216
+ captured = {}
217
+
218
+ def fake_scan_all(config, scan_one, find_related=None):
219
+ captured["config"] = config
220
+ return [ProcessScanOutcome(target="Gemini", result=_result(BARD, 6818, ["libssl.so"]))]
221
+
222
+ monkeypatch.setattr("tlslibhunter.multi_process.scan_all_processes", fake_scan_all)
223
+ assert main(["Gemini", "--serial", "S1", "--all-processes", "-l", "-f", "plain"]) == 0
224
+ assert captured["config"].all_processes is True
225
+ assert "All processes related to 'Gemini'" in capsys.readouterr().out
226
+
227
+ def test_main_returns_1_when_every_scan_failed(self, monkeypatch):
228
+ monkeypatch.setattr(
229
+ "tlslibhunter.multi_process.scan_all_processes",
230
+ lambda config, scan_one, find_related=None: [ProcessScanOutcome(target="Gemini", error="x")],
231
+ )
232
+ assert main(["Gemini", "--all-processes", "-l"]) == 1
233
+
234
+
235
+ class TestHintSuppressed:
236
+ def test_hint_not_logged_with_all_processes(self, monkeypatch):
237
+ from tlslibhunter.hunter import TLSLibHunter
238
+ from tlslibhunter.utils import android_related
239
+
240
+ monkeypatch.setattr(android_related, "find_related_processes", lambda *a: _related())
241
+ hunter = TLSLibHunter.from_config(HunterConfig(target="Gemini", all_processes=True))
242
+ hunter._platform = "android"
243
+ hunter._attached = {"pid": 6818}
244
+ logged = []
245
+ monkeypatch.setattr("tlslibhunter.hunter.logger.log", lambda *a: logged.append(a))
246
+ hunter._hint_related_android_processes()
247
+ assert logged == []