使用注入的代码和QWidget查找第三方QWidget :: find(hwnd)

时间:2021-06-07 09:25:46

I have a Qt Dll wich I inject into a third-party Application using windows detours library:

我有一个Qt Dll,我使用Windows绕道库注入第三方应用程序:

if(!DetourCreateProcessWithDll( Path, NULL, NULL, NULL, TRUE, 
                                CREATE_DEFAULT_ERROR_MODE | CREATE_SUSPENDED, NULL, NULL,
                                &si, &pi, "C:\\Program Files\\Microsoft Research\\Detours Express 2.1\\bin\\detoured.dll",
                                "C:\\Users\\Dave\\Documents\\Visual Studio 2008\\Projects\\XOR\\Debug\\XOR.dll", NULL))

and then I set a system-wide hook to intercept window creation:

然后我设置了一个系统范围的钩子来拦截窗口创建:

HHOOK h_hook = ::SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTProc, Status::getInstance()->getXORInstance(), 0);

Where XOR is my programs name, and Status::getInstance() is a Singleton where I keep globals.

其中XOR是我的程序名,而Status :: getInstance()是一个Singleton,我保持全局变量。

In my CBTProc callback, I want to intercept all windows that are QWidgets:

在我的CBTProc回调中,我想拦截所有QWidgets的窗口:

HWND hwnd= FindWindow(L"QWidget", NULL);

which works well, since I get a corresponding HWND (I checked with Spy++) Then, I want to get a pointer to the QWidget, so I can use its functions:

这很好用,因为我得到了一个相应的HWND(我用Spy ++检查过)然后,我想得到一个指向QWidget的指针,所以我可以使用它的函数:

QWidget* q = QWidget::find(hwnd);

but here's the problem, the returned pointer is always 0. Am I not injecting my code into the process properly? Or am I not using QWidget::find() as I should?

但这是问题所在,返回的指针始终为0.我是不是正确地将代码注入到进程中?或者我不是应该使用QWidget :: find()吗?

Thanks,

Dave

EDIT:If i change the QWidget::find() function to an exported function of my DLL, after setting the hooks (so I can set and catch a breakpoint), QWidgetPrivate::mapper is NULL.

编辑:如果我将QWidget :: find()函数更改为我的DLL的导出函数,在设置钩子后(所以我可以设置并捕获断点),QWidgetPrivate :: mapper为NULL。

2 个解决方案

#1


Answered:

Stupid mistake, I was compiling in Debug, so it was QtGui4d.dll and QtCore4d.dll that where loading, not QtCore4.dll and QtGui.dll

愚蠢的错误,我在Debug中编译,所以QtGui4d.dll和QtCore4d.dll在哪里加载,而不是QtCore4.dll和QtGui.dll

#2


Compare the addresses of `QWidgetPrivate::mapper in the DLL and in your code. Esp. if one is linked statically, there might be two instance of it, each with it's own, disjoint, set of widgets.

比较DLL和代码中`QWidgetPrivate :: mapper的地址。 ESP。如果一个静态链接,可能有两个实例,每个实例都有自己的,不相交的小部件组。

#1


Answered:

Stupid mistake, I was compiling in Debug, so it was QtGui4d.dll and QtCore4d.dll that where loading, not QtCore4.dll and QtGui.dll

愚蠢的错误,我在Debug中编译,所以QtGui4d.dll和QtCore4d.dll在哪里加载,而不是QtCore4.dll和QtGui.dll

#2


Compare the addresses of `QWidgetPrivate::mapper in the DLL and in your code. Esp. if one is linked statically, there might be two instance of it, each with it's own, disjoint, set of widgets.

比较DLL和代码中`QWidgetPrivate :: mapper的地址。 ESP。如果一个静态链接,可能有两个实例,每个实例都有自己的,不相交的小部件组。