设置另一个程序的列表视图所选项目

发布于 2024-07-24 18:39:16 字数 666 浏览 3 评论 0原文

我希望能够选择在另一个程序的列表视图中选择哪个项目(我无权访问其代码)。 实际上,它是一个 SysListView32,我认为它是相同的。 我已经有了下面的代码,不幸的是,尽管编译了,但它似乎什么也没做(尽管 SendMessage() 返回 1)。

process=OpenProcess(PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE|PROCESS_QUERY_INFORMATION, FALSE, 0xD14); 

 _lvi=(LVITEM*)VirtualAllocEx(process, NULL, sizeof(LVITEM), MEM_COMMIT, PAGE_READWRITE); 

 lvi.state = LVIS_SELECTED | LVIS_FOCUSED;
 lvi.stateMask = LVIS_SELECTED | LVIS_FOCUSED; 

 WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL); 
 int abc = ::SendMessage((HWND)0x00050D30, LVM_SETITEMSTATE, (WPARAM)2, (LPARAM)_lvi); 
 VirtualFreeEx(process, _lvi, 0, MEM_RELEASE);

I want to be able to select which item is selected in another program's list view(I don't have access to its code). Actually, it is an SysListView32, which I assume is the same. I already have the following code, which unfortunely despite compiling, seems to do nothing (although SendMessage() returns 1).

process=OpenProcess(PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE|PROCESS_QUERY_INFORMATION, FALSE, 0xD14); 

 _lvi=(LVITEM*)VirtualAllocEx(process, NULL, sizeof(LVITEM), MEM_COMMIT, PAGE_READWRITE); 

 lvi.state = LVIS_SELECTED | LVIS_FOCUSED;
 lvi.stateMask = LVIS_SELECTED | LVIS_FOCUSED; 

 WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL); 
 int abc = ::SendMessage((HWND)0x00050D30, LVM_SETITEMSTATE, (WPARAM)2, (LPARAM)_lvi); 
 VirtualFreeEx(process, _lvi, 0, MEM_RELEASE);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

哀由 2024-07-31 18:39:16

以下代码对我来说就像一个魅力:

HANDLE hProcess = OpenProcess(PROCESS_VM_WRITE | PROCESS_VM_OPERATION, FALSE, 0x0000c130);
LPVOID epLvi = VirtualAllocEx(hProcess, NULL, 4096, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);

LVITEM lvi;
lvi.state = LVIS_FOCUSED | LVIS_SELECTED;
lvi.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
SIZE_T cbWritten = 0;
WriteProcessMemory(hProcess, epLvi, &lvi, sizeof(lvi), &cbWritten);
DWORD dw = SendMessage((HWND)0x00020C4C, LVM_SETITEMSTATE, 1, (LPARAM)epLvi);

VirtualFreeEx(hProcess, epLvi, 4096, MEM_DECOMMIT | MEM_RELEASE);
CloseHandle(hProcess);

您的代码可能无法工作有多种原因:

  • 正如 Michael Dunn 提到的,您需要保留并提交地址空间。 有趣的是,您的示例仅尝试MEM_COMMIT内存,然后MEM_RELEASE(这与MEM_RESERVE相反);
  • 您可能对拥有该窗口的进程没有足够的权限;
  • 您的进程和目标进程可能具有不同的位数。 在这种情况下,可能需要一些结构尺寸技巧。

如果所有这些都不起作用,我建议尝试不同的方法: IAccessible 在这里可能会有所帮助。 这里通常的免责声明:弄乱其他进程窗口和地址空间需要谨慎的方法,并且应该尽可能避免。

The following code works like a charm for me:

HANDLE hProcess = OpenProcess(PROCESS_VM_WRITE | PROCESS_VM_OPERATION, FALSE, 0x0000c130);
LPVOID epLvi = VirtualAllocEx(hProcess, NULL, 4096, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);

LVITEM lvi;
lvi.state = LVIS_FOCUSED | LVIS_SELECTED;
lvi.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
SIZE_T cbWritten = 0;
WriteProcessMemory(hProcess, epLvi, &lvi, sizeof(lvi), &cbWritten);
DWORD dw = SendMessage((HWND)0x00020C4C, LVM_SETITEMSTATE, 1, (LPARAM)epLvi);

VirtualFreeEx(hProcess, epLvi, 4096, MEM_DECOMMIT | MEM_RELEASE);
CloseHandle(hProcess);

There are several reasons why your code might not work:

  • as Michael Dunn mentioned, you need to reserve and commit the address space. Interesting is that your example only attempts to MEM_COMMIT the memory, but then MEM_RELEASE's it (which is opposite to MEM_RESERVE);
  • you might have not enough privileges to the process which owns the window;
  • your process and the target process might be of a different bitness. Some structure size tricks might be required in this case.

If all that doesn't work, I'd recommend trying a different approach: IAccessible might be helpful here. Usual disclaimers here: messing with other processes windows and address space requires careful approach and should be avoided if possible.

野稚 2024-07-31 18:39:16

如何初始化正在复制到目标进程内存中的源 LV_ITEM 的其余成员? 您是否在源 LV_ITEM 的“掩码”成员中包含 LVIF_STATE 标志? 如果不是,那么 ListView 将忽略您尝试指定的“state”和“stateMask”值。

How are you initializing the rest of the members of the source LV_ITEM that is being copyied into the target process's memory? Are you including the LVIF_STATE flag in the source LV_ITEM's "mask" member? If not, then the ListView will ignore the "state" and "stateMask" values that you are trying to specify.

夏の忆 2024-07-31 18:39:16

如果您遇到困难,有一个名为 AutoHotKey 的开源项目,它可以创建可以轻松选择列表中的项目等的脚本。

If you get stuck, there is an open source project called AutoHotKey that can create scripts that can easily select items in lists, etc.

冰之心 2024-07-31 18:39:16

您必须在提交内存之前保留地址空间。 您可以通过将 MEM_COMMIT 更改为 MEM_RESERVE|MEM_COMMIT 来同时执行这两项操作

You have to reserve address space before committing memory. You can do both at once by changing MEM_COMMIT to MEM_RESERVE|MEM_COMMIT

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文