More fixes discovered based on Deedra's work.
This commit is contained in:
1 parent
de31e5b513
commit
17052c5147
22 files changed
+561
-76
No files matched your search
@@ -11,8 +11,9 @@
|
||||
#define PROBE_DEPTH 16
|
||||
static WNDPROC original, outer_original;
|
||||
static uintptr_t deepest, hook_stack;
|
||||
static BOOL nested, destroy_on_set;
|
||||
static BOOL nested, destroy_on_set, destroy_on_get, protect_on_length;
|
||||
static unsigned calls, forwarded_sets;
|
||||
static unsigned text_queries;
|
||||
|
||||
typedef struct EditStateProbe {
|
||||
WCHAR *text;
|
||||
@@ -33,6 +34,15 @@ static LRESULT CALLBACK passthrough(HWND window, UINT message, WPARAM wp, LPARAM
|
||||
static LRESULT CALLBACK application_proc(HWND window, UINT message, WPARAM wp, LPARAM lp) {
|
||||
volatile char marker = 0;
|
||||
++calls;
|
||||
if (message == WM_GETTEXT) ++text_queries;
|
||||
if (message == WM_GETTEXTLENGTH && protect_on_length) {
|
||||
protect_on_length = FALSE;
|
||||
SendMessageW(window, EM_SETPASSWORDCHAR, '*', 0);
|
||||
}
|
||||
if (message == WM_GETTEXT && destroy_on_get) {
|
||||
DestroyWindow(window);
|
||||
return 0;
|
||||
}
|
||||
if (message == PROBE_MESSAGE) {
|
||||
if (wp) return SendMessageA(window, PROBE_MESSAGE, wp - 1, 0);
|
||||
deepest = (uintptr_t)▮
|
||||
@@ -134,6 +144,9 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
largeText[largeLength] = 0;
|
||||
if (!SetWindowTextA(window, largeText)) { free(largeText); return 12; }
|
||||
// Programmatic transcript replacement is lazy. Navigation/focus still
|
||||
// obtains a complete snapshot through the stack-safe direct query.
|
||||
SendMessageW(window, RegisterWindowMessageW(EDIT_FOCUS_MESSAGE), 0, 0);
|
||||
EditStateProbe *state = (EditStateProbe *)GetPropW(window, EDIT_STATE_PROPERTY);
|
||||
if (!state || !state->text || state->length != largeLength ||
|
||||
state->text[largeLength] != 0) {
|
||||
@@ -148,12 +161,53 @@ int main(int argc, char **argv) {
|
||||
return 13;
|
||||
}
|
||||
}
|
||||
size_t bytes = offsetof(WineAccessEditText, text) + ((size_t)largeLength + 1) * sizeof(WCHAR);
|
||||
WineAccessEditText *request = calloc(1, bytes);
|
||||
if (!request) return 16;
|
||||
request->capacity = largeLength + 1;
|
||||
SendMessageW(window, RegisterWindowMessageW(EDIT_REVIEW_MESSAGE), 0, (LPARAM)request);
|
||||
if (request->status != 1 || request->copied != largeLength || request->text[largeLength]) return 17;
|
||||
for (DWORD i = 0; i < largeLength; ++i)
|
||||
if (request->text[i] != (unsigned char)largeText[i]) return 18;
|
||||
free(request);
|
||||
free(largeText);
|
||||
printf("large ANSI snapshot: %lu UTF-16 units\n", (unsigned long)state->length);
|
||||
}
|
||||
UnhookWindowsHookEx(text_hook);
|
||||
// Destroy while the accessibility callback is busy; it must defer freeing
|
||||
// its state until the application's callback has returned.
|
||||
unsigned queries_before = text_queries;
|
||||
for (unsigned i = 0; i < 2000; ++i) {
|
||||
SetWindowTextA(window, "incoming transcript line");
|
||||
SendMessageW(window, EM_SETSEL, (WPARAM)-1, (LPARAM)-1);
|
||||
SendMessageW(window, EM_REPLACESEL, FALSE, (LPARAM)L" another line");
|
||||
}
|
||||
if (text_queries != queries_before) return 19;
|
||||
printf("background transcript burst: no full-text reads for 2000 updates\n");
|
||||
SendMessageW(window, RegisterWindowMessageW(EDIT_FOCUS_MESSAGE), 0, 0);
|
||||
WineAccessEditText *private_query = calloc(1, offsetof(WineAccessEditText, text) + 64 * sizeof(WCHAR));
|
||||
if (!private_query) return 22;
|
||||
private_query->capacity = 64;
|
||||
protect_on_length = TRUE;
|
||||
SendMessageW(window, RegisterWindowMessageW(EDIT_REVIEW_MESSAGE), 0, (LPARAM)private_query);
|
||||
EditStateProbe *protected_state = (EditStateProbe *)GetPropW(window, EDIT_STATE_PROPERTY);
|
||||
if (!protected_state || protected_state->text || protected_state->known || private_query->status) return 23;
|
||||
free(private_query);
|
||||
SendMessageW(window, EM_SETPASSWORDCHAR, 0, 0);
|
||||
// Destroy while the native review callback is busy. Its state must survive
|
||||
// until the application's query returns, then be freed exactly once.
|
||||
destroy_on_get = TRUE;
|
||||
WineAccessEditText *destroy_query = calloc(1, offsetof(WineAccessEditText, text) + 64 * sizeof(WCHAR));
|
||||
if (!destroy_query) return 20;
|
||||
destroy_query->capacity = 64;
|
||||
SendMessageW(window, RegisterWindowMessageW(EDIT_REVIEW_MESSAGE), 0, (LPARAM)destroy_query);
|
||||
if (IsWindow(window) || destroy_query->status) return 21;
|
||||
free(destroy_query);
|
||||
destroy_on_get = FALSE;
|
||||
// Also retain the application's destruction-during-replacement check.
|
||||
window = CreateWindowA("Edit", "initial", WS_POPUP | ES_MULTILINE,
|
||||
0, 0, 200, 100, NULL, NULL, GetModuleHandleW(NULL), NULL);
|
||||
original = (WNDPROC)SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)application_proc);
|
||||
focus.hwnd = window;
|
||||
callback(HC_ACTION, 0, (LPARAM)&focus);
|
||||
destroy_on_set = TRUE;
|
||||
SetWindowTextA(window, "destroy");
|
||||
if (IsWindow(window)) return 7;
|
||||
|
||||
Reference in new issue
Block a user