Page 1 of 1

How to fool window into thinking is has focus

Posted: Sun Oct 13, 2013 11:01 pm
by MiesterMan
So I've been researching this and found an MSDN that might explain how to do this, but I was wondering if micromacro already has this functionality.

If Micromacro can send any windows message it might be possible to manipulate what the window thinks. If not I'd need to hook the dll function that tells the game if it has focus. Anyone know the straight up way how to do this either way using micromacro?

The MSDN info is here: http://msdn.microsoft.com/en-us/library ... spx#active
Some of the surrounding topics are related to this issue too.

Re: How to fool window into thinking is has focus

Posted: Sun Oct 13, 2013 11:39 pm
by MiesterMan
Digging deeper, it would seem I need to hook this functionhttp://msdn.microsoft.com/en-us/library ... s.85).aspx

Re: How to fool window into thinking is has focus

Posted: Mon Oct 14, 2013 12:45 am
by MiesterMan
Alright, with this short program I found the address of USER32.DLL in the game I'm working on:

Code: Select all

local procId = findProcess("The Lord of the Rings Online*");
local Origin = getModuleAddress(procId, "User32.dll");
printf("0x%x",Origin);
And a list off offsets at http://www.autoitscript.com/forum/topic ... user32dll/

Edit: My mistake, I misread the chart for the info below this edit. The offset puts me in the ntdll.dll file though so I'm not sure where to go from here.

Re: How to fool window into thinking is has focus

Posted: Mon Oct 14, 2013 2:37 am
by Administrator
Are you running a 64-bit OS? I'm just making a wild guess here, but you're probably actually getting mislead by 32-bit emulation.

If you're going to do some real injection, you might consider writing a DLL to inject. You should use GetProcAddress() to locate the function (IsWindowEnabled).

Re: How to fool window into thinking is has focus

Posted: Mon Oct 14, 2013 9:47 pm
by MiesterMan
Administrator wrote:Are you running a 64-bit OS? I'm just making a wild guess here, but you're probably actually getting mislead by 32-bit emulation.

If you're going to do some real injection, you might consider writing a DLL to inject. You should use GetProcAddress() to locate the function (IsWindowEnabled).
GetProcAddress? That works? I mean, where is the label? I mean where is this proc label that MM uses to locate it?

Re: How to fool window into thinking is has focus

Posted: Mon Oct 14, 2013 10:21 pm
by Administrator
You can't use it from MicroMacro. It needs to be called from within the process you want the information from. An injected DLL would suffice. When it comes to function hooking, I really recommend using injectable DLLs where possible as that allows more direct control over the process and easier/more advanced hooks without needing to learn assembly.

Re: How to fool window into thinking is has focus

Posted: Tue Oct 15, 2013 9:14 am
by MiesterMan
Ah, see that is the reason I was considering using an injected DLL but I was trying to avoid it since it meant sharing the bot would require someone to download the DLL.

Anyways, I know how to make a DLL and how to access functions in one, but I've no idea how I would inject to hook a function in a DLL already in a program. Any tutorials available for this?

Re: How to fool window into thinking is has focus

Posted: Tue Oct 15, 2013 3:44 pm
by Administrator
I recommend Azorbix's detours to hook the functions. Makes it easy. GetProcAddress() is great for non-OO libraries (such as Winsock or OpenGL) that are linked in (doesn't mater if it is static or dynamic, so as long as you know the function name, use this). You can also just use the function address directly if you have to.

Oh, and make sure you compile your DLL as C; C++ will cause name-mangling which means it won't work.

Here's an example of hooking glBegin in OpenGL:

Code: Select all

typedef void ( APIENTRY *glBegin_t )( GLenum );

glBegin_t pglBegin = NULL;


void APIENTRY Hooked_glBegin( GLenum mode )
{
	// Add your own code here.

	// Call original function
	if(pglBegin)
		(*pglBegin)(mode);
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL,
                    DWORD     fdwReason,
                    LPVOID    lpvReserved)
{
   switch(fdwReason)
   {
   HMODULE hOpenGL = GetModuleHandle("opengl32.dll");
   case DLL_PROCESS_ATTACH:
      pglBegin     =   (glBegin_t)DetourFunc( (LPBYTE)GetProcAddress(hOpenGL, "glBegin"),
         (LPBYTE)&Hooked_glBegin,6);
      break;
   case DLL_PROCESS_DETACH:
      // Unhook it here; not providing an example
      break;
   }
   return TRUE;

}
I've attached Azorbix's detours library.