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 


I suck. SetWindowsHookEx DLL injection.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sun Nov 09, 2008 8:43 pm    Post subject: I suck. SetWindowsHookEx DLL injection. Reply with quote

GetProcAddress fails with ERROR_PROC_NOT_FOUND.

What am I overlooking within the DLL?

Inject
Code:
void Injector::Inject(void){
   if(CheckProcess()){
      HMODULE dll  = LoadLibrary(dll_name);
      FARPROC proc = GetProcAddress(dll, "GetMsgProc");
      HHOOK   hh    = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC)proc, dll, te.th32ThreadID);
      UnhookWindowsHookEx(hh);
   }
}


DLL
Code:
#include <Windows.h>

extern "C" __declspec(dllexport)LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam){
   return CallNextHookEx(0, nCode, wParam, lParam);
}

BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved){
   UNREFERENCED_PARAMETER(hinstDLL);
   UNREFERENCED_PARAMETER(fdwReason);
   switch(fdwReason)
   {
   case DLL_PROCESS_ATTACH:
      MessageBox(0, "Hi", "Sup", MB_OK);
      return TRUE;
   case DLL_PROCESS_DETACH:
      return TRUE;
   }
   return ERROR_SUCCESS;
}
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Sun Nov 09, 2008 8:49 pm    Post subject: Reply with quote

according the MSDN this doesn't have a library/dll ?

Import library None

http://msdn.microsoft.com/en-us/library/ms644981(VS.85).aspx

_________________
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sun Nov 09, 2008 8:56 pm    Post subject: Reply with quote

Quote:
SetWindowsHookEx

lpfn
[in] Pointer to the hook procedure. If the dwThreadId parameter is zero or specifies the identifier of a thread created by a different process, the lpfn parameter must point to a hook procedure in a DLL. Otherwise, lpfn can point to a hook procedure in the code associated with the current process.
hMod

[in] Handle to the DLL containing the hook procedure pointed to by the lpfn parameter. The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by the current process and if the hook procedure is within the code associated with the current process.
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Sun Nov 09, 2008 9:02 pm    Post subject: Reply with quote

slovach wrote:
Quote:
SetWindowsHookEx

lpfn
[in] Pointer to the hook procedure. If the dwThreadId parameter is zero or specifies the identifier of a thread created by a different process, the lpfn parameter must point to a hook procedure in a DLL. Otherwise, lpfn can point to a hook procedure in the code associated with the current process.
hMod

[in] Handle to the DLL containing the hook procedure pointed to by the lpfn parameter. The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by the current process and if the hook procedure is within the code associated with the current process.


oh duh. didnt read all the code. sorry.

_________________
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Sun Nov 09, 2008 10:22 pm    Post subject: Reply with quote

Try using ordinals, and see what happens then?

Edit: This is assuming that you've verified your dll has loaded correctly.

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
sloppy
Expert Cheater
Reputation: 0

Joined: 17 Aug 2008
Posts: 123

PostPosted: Sun Nov 09, 2008 11:01 pm    Post subject: Reply with quote

Yeah I think that could be the problem, check what the function name is exported as. I gave the code a try and the dll works fine using "_GetMsgProc@12" or "GetMsgProc" /w def file.
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sun Nov 09, 2008 11:04 pm    Post subject: Reply with quote

Damn, I should have thought of that.

Yeah, that's it.
Back to top
View user's profile Send private message
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