Allow untested Desktop versions with compatibility warnings
This commit is contained in:
1 parent
d2b621bce7
commit
ab69f287b6
16 files changed
+1571
-1495
No files matched your search
+33
-13
@@ -1,16 +1,31 @@
|
||||
"""Shared verified Desktop process and window discovery."""
|
||||
import ctypes
|
||||
import hashlib
|
||||
import re
|
||||
import warnings
|
||||
from pathlib import Path
|
||||
SUPPORTED_BUILD = "2.2639.100.0"
|
||||
TESTED_BUILD = "2.2639.100.0"
|
||||
SUPPORTED_BUILD = TESTED_BUILD # Backward-compatible constant; not an allowlist.
|
||||
CORE_SHA256 = "c6da3c67eda66a8d48ff2ae11f68085f1f8250111138a6ae384d38eefb4da536"
|
||||
|
||||
def check_core_build(path):
|
||||
if 'WhatsAppDesktop_' + SUPPORTED_BUILD + '_' not in str(path):
|
||||
raise ValueError('Unsupported WhatsApp build: ' + str(path) +
|
||||
'; supported build is ' + SUPPORTED_BUILD + '. No hook installed.')
|
||||
if hashlib.sha256(Path(path).read_bytes()).hexdigest() != CORE_SHA256:
|
||||
raise ValueError('Unknown WebView2 Core DLL hash. No hook installed.')
|
||||
"""Describe tested-build compatibility without rejecting other versions.
|
||||
|
||||
Native object/method checks still determine whether the bridge can operate.
|
||||
File access failures remain errors; a hash mismatch alone is advisory.
|
||||
"""
|
||||
path = Path(path)
|
||||
match = re.search(r'WhatsAppDesktop_([0-9.]+)_', str(path), re.IGNORECASE)
|
||||
actual_build = match.group(1) if match else None
|
||||
actual_hash = hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
matched = actual_build == TESTED_BUILD and actual_hash == CORE_SHA256
|
||||
return {'tested_build': TESTED_BUILD, 'detected_build': actual_build,
|
||||
'tested_core_sha256': CORE_SHA256, 'detected_core_sha256': actual_hash,
|
||||
'matches_tested_configuration': matched,
|
||||
'warning': None if matched else
|
||||
'Untested WhatsApp/WebView configuration; attempting the bridge. '
|
||||
'Native object checks remain enabled. Compatibility is not verified; '
|
||||
'changed native layouts may cause failure or process instability.'}
|
||||
|
||||
def visible_ui_threads(pid):
|
||||
"""Inspect window ownership; no clicks, navigation or window messages."""
|
||||
@@ -36,8 +51,8 @@ def visible_ui_threads(pid):
|
||||
raise ctypes.WinError(ctypes.get_last_error())
|
||||
return threads
|
||||
|
||||
def detect_desktop_pid(requested_pid=None):
|
||||
"""Find the running supported Desktop host using Python and Windows APIs."""
|
||||
def detect_desktop_pid(requested_pid=None, compatibility=None):
|
||||
"""Find the running Desktop host using Python and Windows APIs."""
|
||||
import ctypes
|
||||
from ctypes import wintypes as w
|
||||
import hashlib
|
||||
@@ -91,8 +106,8 @@ def detect_desktop_pid(requested_pid=None):
|
||||
path = Path(entry.szExePath)
|
||||
if len(visible_ui_threads(pid)) == 1:
|
||||
try:
|
||||
check_core_build(path)
|
||||
candidates.append(pid)
|
||||
details = check_core_build(path)
|
||||
candidates.append((pid, details))
|
||||
except (ValueError, OSError) as error:
|
||||
rejected.append(str(error))
|
||||
break
|
||||
@@ -102,8 +117,13 @@ def detect_desktop_pid(requested_pid=None):
|
||||
finally:
|
||||
kernel.CloseHandle(snapshot)
|
||||
if not candidates:
|
||||
raise ValueError('; '.join(rejected) if rejected else 'No supported running WhatsApp Desktop host with one identifiable UI thread found; start WhatsApp normally')
|
||||
raise ValueError('; '.join(rejected) if rejected else 'No running WhatsApp Desktop host with one identifiable UI thread found; start WhatsApp normally')
|
||||
if len(candidates) != 1:
|
||||
raise ValueError('Multiple active Desktop hosts found; specify --pid: '+', '.join(map(str,candidates)))
|
||||
return candidates[0]
|
||||
raise ValueError('Multiple active Desktop hosts found; specify --pid: '+', '.join(str(item[0]) for item in candidates))
|
||||
selected, details = candidates[0]
|
||||
if compatibility is not None:
|
||||
compatibility.update(details)
|
||||
if details['warning']:
|
||||
warnings.warn(details['warning'], RuntimeWarning, stacklevel=2)
|
||||
return selected
|
||||
|
||||
Reference in new issue
Block a user