SetWindowsHookExA

c++ / delphi package - dll injection and api hooking
Post Reply
shadowstar
Posts: 12
Joined: Fri Jul 09, 2004 2:09 pm
Location: China
Contact:

SetWindowsHookExA

Post by shadowstar »

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.
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

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.
shadowstar
Posts: 12
Joined: Fri Jul 09, 2004 2:09 pm
Location: China
Contact:

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

Post by shadowstar »

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
Contact:

Post by shadowstar »

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
...
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

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.
Post Reply