Bug fixes and reorganization of code.

This commit is contained in:
ak47 committed 2026-10-10 22:27:12 -04:00
1 parent 5f78168c57
commit cbce83581a
10 files changed
+148 -81

No files matched your search

+9 -25
View File
@@ -1,16 +1,14 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
#include "native_items.h"
#include "control_class.h"
#include "native_query.h"
#include <commctrl.h>
#include <cstddef>
#include <cstring>
#include <iterator>
namespace {
bool query(HWND window, UINT message, WPARAM wp, LPARAM lp, DWORD_PTR *result) {
return SendMessageTimeoutW(window, message, wp, lp, SMTO_ABORTIFHUNG,
100, result) != 0;
}
using native_control::query;
bool is_tab(HWND window) {
wchar_t className[128] = {};
return GetClassNameW(window, className, std::size(className)) &&
@@ -75,23 +73,11 @@ NativeItem read_native_item(HWND window) {
const auto key = native_item_key(window);
item.key = key;
if (!key.item) return item;
DWORD processId = 0;
GetWindowThreadProcessId(window, &processId);
HANDLE process = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ |
PROCESS_VM_WRITE | PROCESS_QUERY_LIMITED_INFORMATION,
FALSE, processId);
if (!process) return item;
BOOL wow64 = FALSE;
if (!IsWow64Process(process, &wow64)) { CloseHandle(process); return item; }
void *remote = VirtualAllocEx(process, nullptr, bufferSize,
MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
if (!remote || (wow64 && reinterpret_cast<uintptr_t>(remote) > UINT32_MAX)) {
if (remote) VirtualFreeEx(process, remote, 0, MEM_RELEASE);
CloseHandle(process);
return item;
}
native_control::RemoteBuffer remote(window, bufferSize);
if (!remote) return item;
const bool wow64 = remote.is32Bit();
BYTE buffer[bufferSize] = {};
const auto address = reinterpret_cast<uintptr_t>(remote) + textOffset;
const auto address = remote.address(textOffset);
if (tab && wow64) {
const Tab32 data{TCIF_TEXT, 0, 0, static_cast<uint32_t>(address), textCapacity};
memcpy(buffer, &data, sizeof(data));
@@ -108,10 +94,10 @@ NativeItem read_native_item(HWND window) {
memcpy(buffer, &data, sizeof(data));
}
DWORD_PTR result = 0;
if (WriteProcessMemory(process, remote, buffer, sizeof(buffer), nullptr) &&
if (remote.write(buffer, sizeof(buffer)) &&
query(window, tab ? TCM_GETITEMW : TVM_GETITEMW, tab ? key.item - 1 : 0,
reinterpret_cast<LPARAM>(remote), &result) && result &&
ReadProcessMemory(process, remote, buffer, sizeof(buffer), nullptr)) {
static_cast<LPARAM>(remote.address()), &result) && result &&
remote.read(buffer, sizeof(buffer))) {
wchar_t text[textCapacity] = {};
memcpy(text, buffer + textOffset, sizeof(text));
text[textCapacity - 1] = L'\0';
@@ -130,7 +116,5 @@ NativeItem read_native_item(HWND window) {
}
}
}
VirtualFreeEx(process, remote, 0, MEM_RELEASE);
CloseHandle(process);
return item;
}