SetWindowsHookExA

c++ / delphi package - dll injection and api hooking

SetWindowsHookExA

Postby shadowstar » Fri Jul 09, 2004 2:19 pm

Code: Select all
HHOOK
WINAPI SetWindowsHookExCallback(
    int idHook,
    HOOKPROC lpfn,
    HINSTANCE hMod,
    DWORD dwThreadId
    )
{
    char AppName[MAX_PATH];
    char DllName[MAX_PATH];

    if (GetModuleFileName(NULL, AppName, MAX_PATH) > 0
        && GetModuleFileName(hMod, DllName, MAX_PATH) > 0)
    {
        char HookText[1024];

        sprintf(HookText,
            "AppName: \"%s\",\n"
            "DllName: \"%s\".\n"
            "Is this hooking allowed?",
            AppName,
            DllName);
        if (MessageBox(
            NULL,
            HookText,
            "Warning",
            MB_ICONWARNING | MB_YESNO
            ) == ID_NO)
        {
            ::SetLastError(ERROR_ACCESS_DENIED);
            return NULL;
        }
    }
   
    return SetWindowsHookExNext(
        idHook,
        lpfn,
        hMod,
        dwThreadId
        );
}


The MessageBox can not be closed.
Last edited by shadowstar on Sat Jul 24, 2004 7:47 am, edited 1 time in total.
shadowstar
 
Posts: 12
Joined: Fri Jul 09, 2004 2:09 pm
Location: China

Postby madshi » Sun Jul 11, 2004 7:31 am

I can't say why this happens. Maybe the program which calls SetWindowsHookEx behaves somehow strangely and thus doesn't like the MessageBox call at all. Is it your own program which calls SetWindowsHookEx?

I suggest sending an IPC message to your application and let that show a message box and return the result back to the hook dll. You can see how that works in the HookProcessTermination demo.
madshi
Site Admin
 
Posts: 9880
Joined: Sun Mar 21, 2004 5:25 pm

can't hook the SetWindowsHookExA that was called by my DLL

Postby shadowstar » Sat Jul 24, 2004 8:06 am

can't hook the SetWindowsHookExA that was called by my DLL

Star.exe
|
v
Shadow.dll -> EnableHook -> SetWindowsHookExA
shadowstar
 
Posts: 12
Joined: Fri Jul 09, 2004 2:09 pm
Location: China

Postby shadowstar » Tue Jul 27, 2004 7:29 am

Can't create VCL form when handle Ipc message request.
Code: Select all
procedure HandleProcessTerminationRequest(name       : pchar;
                                          messageBuf : pointer;
                                          messageLen : dword;
                                          answerBuf  : pointer;
                                          answerLen  : dword); stdcall;
// this function is called by the ipc message whenever our dll contacts us
var s1, s2, s3 : string;
      Form1: TForm1;
begin
  Form1 := TForm1.Create(Application); // Process stop response on this line
...
shadowstar
 
Posts: 12
Joined: Fri Jul 09, 2004 2:09 pm
Location: China

Postby madshi » Wed Jul 28, 2004 6:56 am

I don't have the overview about what you're doing exactly. If you can create a small demo (please as small as possible) which reproduces the problems, I might have a look at it to see what's wrong.
madshi
Site Admin
 
Posts: 9880
Joined: Sun Mar 21, 2004 5:25 pm


Return to madCodeHook

Who is online

Users browsing this forum: No registered users and 5 guests

cron