Hooking ShellExecuteEx crashing

c++ / delphi package - dll injection and api hooking
Post Reply
Davita
Posts: 163
Joined: Tue Sep 13, 2005 7:31 pm

Hooking ShellExecuteEx crashing

Post by Davita »

Hi

I have a very basic project which hooks ShellExecuteExA/W apis, but after callback functions are being called, the target process crashes. Here's the code:

Code: Select all

BOOL ShellExecuteExACallback(_Inout_ SHELLEXECUTEINFOA *pExecInfo)
{
    return ShellExecuteExANext(pExecInfo);
}

BOOL ShellExecuteExWCallback(_Inout_ SHELLEXECUTEINFOW *pExecInfo)
{
    return ShellExecuteExWNext(pExecInfo);
}


BOOL WINAPI DllMain(HINSTANCE hModule, DWORD fdwReason, LPVOID lpReserved)
{
    if(fdwReason == DLL_PROCESS_ATTACH) {
        InitializeMadCHook();
        CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);

        HookAPI("shell32.dll", "ShellExecuteExA", (PVOID) ShellExecuteExACallback, (PVOID*) &ShellExecuteExANext, 0);
        HookAPI("shell32.dll", "ShellExecuteExW", (PVOID) ShellExecuteExWCallback, (PVOID*) &ShellExecuteExWNext, 0);
    }

    return TRUE;
}
Any idea what's wrong with my code? Note that every other APIs I've tried works perfectly, it's only ShellExecuteEx api which is causing crash.
Davita
Posts: 163
Joined: Tue Sep 13, 2005 7:31 pm

Re: Hooking ShellExecuteEx crashing

Post by Davita »

My bad, I forgot to add WINAPI in callback functions declaration :)
Problem resolved.
madshi
Site Admin
Posts: 10766
Joined: Sun Mar 21, 2004 5:25 pm

Re: Hooking ShellExecuteEx crashing

Post by madshi »

Yeah, calling convention is the most common error, and always the first thing I check...
Post Reply