Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[Help] SetWindowsHookEx Dll Injection

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
iPromise
Grandmaster Cheater
Reputation: -1

Joined: 27 Jun 2009
Posts: 529
Location: Canada

PostPosted: Wed Nov 18, 2009 8:16 pm    Post subject: [Help] SetWindowsHookEx Dll Injection Reply with quote

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
View user's profile Send private message MSN Messenger
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Thu Nov 19, 2009 5:57 am    Post subject: Reply with quote

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
View user's profile Send private message
iPromise
Grandmaster Cheater
Reputation: -1

Joined: 27 Jun 2009
Posts: 529
Location: Canada

PostPosted: Thu Nov 19, 2009 6:45 pm    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
iPromise
Grandmaster Cheater
Reputation: -1

Joined: 27 Jun 2009
Posts: 529
Location: Canada

PostPosted: Thu Dec 03, 2009 6:44 pm    Post subject: Reply with quote

Found the problem, make sure nCode is:

Code:
if (nCode == HCBT_ACTIVATE || HCBT_SYSCOMMAND || HCBT_DESTROYWND)
   {

   }
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites