 |
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
iPromise Grandmaster Cheater
Reputation: -1
Joined: 27 Jun 2009 Posts: 529 Location: Canada
|
Posted: Wed Nov 18, 2009 8:16 pm Post subject: [Help] SetWindowsHookEx Dll Injection |
|
|
Its not working, i'm testing it on notepad. What I do is do a global dll injection with my first temporary dll, this dll will go through all the hwnds through the WH_CBT hook and try to find my targets window title, and then if I found it I inject my second real dll and unhook my hook.
This is my console:
Code: |
#include <windows.h>
#include <iostream>
using namespace std;
void main()
{
HMODULE hDll = LoadLibraryA("C:\\...\\...\\Documents\\Visual Studio 2008\\Projects\\SetWindowsHookEx\\Debug\\System.dll");
HOOKPROC GetCBT = (HOOKPROC) GetProcAddress(hDll, "CBTProc");
HHOOK Hook = SetWindowsHookEx(WH_CBT, GetCBT, hDll, 0);
system("PAUSE");
}
|
This is my Dll:
Code: |
#include <windows.h>
#include <iostream>
using namespace std;
BOOL WINAPI DllMain(HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpReserved)
{
return TRUE;
}
LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode == HCBT_ACTIVATE)
{
HWND hWnd = (HWND) wParam;
char Title[500] = {0};
GetWindowTextA(hWnd, (LPSTR) Title, MAX_PATH);
if ((LPSTR) Title == "Untitled - Notepad")
{
LoadLibraryA("MyDll");
UnhookWindowsHookEx(0);
}
}
return CallNextHookEx(0, nCode, wParam, lParam);
}
|
Please help, this wont work, I keep clicking on Notepad when the dll is injected to try and get my WH_CBT callback to work.
|
|
Back to top |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Thu Nov 19, 2009 5:57 am Post subject: |
|
|
Try to just put a MessageBox in the CBTProc after nCode==HCBT_ACTIVATE to see if the message is even received.
Also:
When you want to unload the temporary dll, first unhook the WindowsHook and then use FreeLibraryAndExitThread() to unload and quit.
|
|
Back to top |
|
 |
iPromise Grandmaster Cheater
Reputation: -1
Joined: 27 Jun 2009 Posts: 529 Location: Canada
|
Posted: Thu Nov 19, 2009 6:45 pm Post subject: |
|
|
I tried putting MessageBox after nCode == HCBT_ACTIVATE, it works fine for other applications, but when I click on Notepad, for some reason I dont receive the message.
|
|
Back to top |
|
 |
iPromise Grandmaster Cheater
Reputation: -1
Joined: 27 Jun 2009 Posts: 529 Location: Canada
|
Posted: Thu Dec 03, 2009 6:44 pm Post subject: |
|
|
Found the problem, make sure nCode is:
Code: | if (nCode == HCBT_ACTIVATE || HCBT_SYSCOMMAND || HCBT_DESTROYWND)
{
}
|
|
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|