fix: bound native edit messages and identify empty IE infrastructure
This commit is contained in:
1 parent
bb98fe66dd
commit
8e486c1097
4 files changed
+132
-3
No files matched your search
@@ -108,6 +108,15 @@ def close_failed_startup(job, pcb_pid, *, baseline_pids=(), emit=lambda **event:
|
||||
for w in windows]
|
||||
benign = [w for w in observed if w['title'] == '' and w['class'] in (
|
||||
'UAC_InputIndicatorOverlayWnd', 'UAC Input Indicator')]
|
||||
for window in observed:
|
||||
if window['class'] == 'Internet Explorer_Hidden' and window['title'] == '':
|
||||
window['rect'] = list(win32gui.GetWindowRect(window['hwnd']))
|
||||
window['children'] = []
|
||||
win32gui.EnumChildWindows(window['hwnd'],
|
||||
lambda hwnd, _: window['children'].append(int(hwnd)), None)
|
||||
left, top, right, bottom = window['rect']
|
||||
if left == right and top == bottom and not window['children']:
|
||||
benign.append(window)
|
||||
unknown = [w for w in observed if w['hwnd'] not in main and w not in benign]
|
||||
result.update(owned_windows=observed, unknown_windows=unknown,
|
||||
benign_auxiliary_windows=benign)
|
||||
|
||||
@@ -241,6 +241,47 @@ def _dispatch_diagnostics(root, stage, app, library, *, paths=None):
|
||||
stream.write(json.dumps(record, ensure_ascii=False, default=str) + '\n')
|
||||
|
||||
|
||||
def _set_probe_field(hwnd, control_id, expected, root):
|
||||
"""Set/read a remote Edit with a one-second total message budget."""
|
||||
from ctypes import wintypes
|
||||
record = {'control_id': control_id, 'hwnd': int(hwnd), 'expected': expected,
|
||||
'actual': None, 'matched': False}
|
||||
deadline = time.monotonic() + 1.0
|
||||
try:
|
||||
user32 = ctypes.WinDLL('user32', use_last_error=True)
|
||||
send = user32.SendMessageTimeoutW
|
||||
send.argtypes = [wintypes.HWND, wintypes.UINT, wintypes.WPARAM, wintypes.LPARAM,
|
||||
wintypes.UINT, wintypes.UINT, ctypes.POINTER(ctypes.c_size_t)]
|
||||
send.restype = wintypes.LPARAM
|
||||
def message(code, count, buffer):
|
||||
remaining = min(1000, int((deadline - time.monotonic()) * 1000))
|
||||
if remaining <= 0:
|
||||
raise TimeoutError(f'原生字段消息超时:{control_id}')
|
||||
returned = ctypes.c_size_t()
|
||||
if not send(int(hwnd), code, count, ctypes.addressof(buffer), 0x0002,
|
||||
remaining, ctypes.byref(returned)):
|
||||
raise TimeoutError(f'原生字段消息超时或失败:{control_id}, Windows={ctypes.get_last_error()}')
|
||||
return returned.value
|
||||
text = ctypes.create_unicode_buffer(expected)
|
||||
if not message(0x000C, 0, text): # WM_SETTEXT
|
||||
raise RuntimeError(f'原生字段拒绝写入:{control_id}')
|
||||
buffer = ctypes.create_unicode_buffer(32768)
|
||||
copied = message(0x000D, len(buffer), buffer) # WM_GETTEXT, remote Edit marshalled by Windows.
|
||||
record['actual'] = buffer.value
|
||||
if copied >= len(buffer) - 1:
|
||||
raise RuntimeError(f'原生字段复读可能截断:{control_id}')
|
||||
if record['actual'] != expected:
|
||||
raise RuntimeError(f'原生新增字段回读失败:{control_id}')
|
||||
record['matched'] = True
|
||||
return record['actual']
|
||||
except Exception as error:
|
||||
record['exception'] = _exception_details(error)
|
||||
raise
|
||||
finally:
|
||||
with (Path(root)/'native-field-readback.jsonl').open('a', encoding='utf-8') as stream:
|
||||
stream.write(json.dumps(record, ensure_ascii=False, default=str) + '\n')
|
||||
|
||||
|
||||
def _probe_add_dialog(app, job, desktop, owned_pids, root, *, library=None):
|
||||
try:
|
||||
return _probe_add_dialog_impl(app, job, desktop, owned_pids, root, library=library)
|
||||
@@ -309,9 +350,7 @@ def _probe_add_dialog_impl(app, job, desktop, owned_pids, root, *, library=None)
|
||||
hwnd = win32gui.GetDlgItem(dialog, control)
|
||||
if not hwnd or win32gui.GetClassName(hwnd) != 'Edit':
|
||||
raise RuntimeError(f'原生新增字段身份不匹配:{control}')
|
||||
win32gui.SendMessage(hwnd, win32con.WM_SETTEXT, 0, value)
|
||||
if win32gui.GetWindowText(hwnd) != value:
|
||||
raise RuntimeError(f'原生新增字段回读失败:{control}')
|
||||
_set_probe_field(hwnd, control, value, root)
|
||||
_write_json(root/'submitted-fields.json', fields)
|
||||
ok = win32gui.GetDlgItem(dialog, 1083)
|
||||
if not ok:
|
||||
|
||||
Reference in new issue
Block a user