What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Plug-Ins » Pathcou - TrackPopupMenuEx

Pathcou - TrackPopupMenuEx
Author: Message:
TheBlasphemer
Senior Member
****

Avatar

Posts: 714
Reputation: 47
37 / – / –
Joined: Mar 2004
RE: Pathcou - TrackPopupMenuEx
This is what I use in StuffPlug:
code:
void *HookImportedFunction(const char *Dll, const char *FuncName, int Ordinal, void *Function)
{
    DWORD oldProtect;
    void *PrevValue=0;

    DWORD image_base = (DWORD)GetModuleHandle(NULL);
    IMAGE_DOS_HEADER *idh = (IMAGE_DOS_HEADER *)image_base;
    IMAGE_FILE_HEADER *ifh = (IMAGE_FILE_HEADER *)(image_base +
        idh->e_lfanew + sizeof(DWORD));
    IMAGE_OPTIONAL_HEADER *ioh = (IMAGE_OPTIONAL_HEADER *)((DWORD)(ifh) +
        sizeof(IMAGE_FILE_HEADER));
    IMAGE_IMPORT_DESCRIPTOR *iid = (IMAGE_IMPORT_DESCRIPTOR *)(image_base +
        ioh->DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress);

    VirtualProtect((LPVOID)(image_base +
        ioh->DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT].VirtualAddress),
        ioh->DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT].Size, PAGE_READWRITE,
        &oldProtect);

    while(iid->Name)
    {
        if(lstrcmpiA(Dll, (char *)(image_base + iid->Name)) == 0)
        {
            //trace_printf("Found descriptor: %s\n", dhook->name);
            IMAGE_THUNK_DATA * pThunk = (IMAGE_THUNK_DATA *)
                ((DWORD)iid->OriginalFirstThunk + image_base);
            IMAGE_THUNK_DATA * pThunk2 = (IMAGE_THUNK_DATA *)
                ((DWORD)iid->FirstThunk + image_base);
            while(pThunk->u1.AddressOfData)
            {
                char * name = 0;
                int ordinal;
                // Imported by ordinal only:
                if(pThunk->u1.Ordinal & 0x80000000)
                    ordinal = pThunk->u1.Ordinal & 0xffff;
                else    // Imported by name, with ordinal hint
                {
                    IMAGE_IMPORT_BY_NAME * pname = (IMAGE_IMPORT_BY_NAME *)
                        ((DWORD)pThunk->u1.AddressOfData + image_base);
                    ordinal = pname->Hint;
                    name = (char *)pname->Name;
                }

                if(name != 0 && FuncName && strcmp(name, FuncName) == 0)
                {
                    //trace_printf("Found entry name: %s\n", ehook->name);
                    PrevValue = (void*)pThunk2->u1.Function;
                    pThunk2->u1.Function = (DWORD)Function;
                }
                else if(ordinal == Ordinal)
                {
                    //trace_printf("Found entry ordinal: %s\n", ehook->name);
                    PrevValue = (void*)pThunk2->u1.Function;
                    pThunk2->u1.Function = (DWORD)Function;
                }

                pThunk++;
                pThunk2++;
            }
        }
        iid++;
    }
    return PrevValue;
}


This post was edited on 06-14-2005 at 09:23 PM by TheBlasphemer.
[Image: theblasp.png]
06-14-2005 09:22 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Pathcou - TrackPopupMenuEx - by TazDevil on 06-11-2005 at 02:33 PM
RE: Pathcou - TrackPopupMenuEx - by absorbation on 06-11-2005 at 03:12 PM
RE: Pathcou - TrackPopupMenuEx - by Dempsey on 06-11-2005 at 03:25 PM
RE: Pathcou - TrackPopupMenuEx - by Stigmata on 06-11-2005 at 03:33 PM
RE: Pathcou - TrackPopupMenuEx - by Dempsey on 06-11-2005 at 03:34 PM
RE: Pathcou - TrackPopupMenuEx - by TazDevil on 06-11-2005 at 03:41 PM
RE: Pathcou - TrackPopupMenuEx - by Dempsey on 06-11-2005 at 04:03 PM
RE: Pathcou - TrackPopupMenuEx - by TazDevil on 06-11-2005 at 04:07 PM
RE: Pathcou - TrackPopupMenuEx - by Dempsey on 06-11-2005 at 04:19 PM
RE: Pathcou - TrackPopupMenuEx - by TazDevil on 06-11-2005 at 04:27 PM
RE: Pathcou - TrackPopupMenuEx - by Stigmata on 06-11-2005 at 04:42 PM
RE: Pathcou - TrackPopupMenuEx - by TazDevil on 06-11-2005 at 05:26 PM
RE: Pathcou - TrackPopupMenuEx - by TazDevil on 06-14-2005 at 04:58 PM
RE: Pathcou - TrackPopupMenuEx - by Patchou on 06-14-2005 at 08:28 PM
RE: Pathcou - TrackPopupMenuEx - by TheBlasphemer on 06-14-2005 at 09:22 PM
THANKS A MILLION - by TazDevil on 06-15-2005 at 06:38 AM
RE: Pathcou - TrackPopupMenuEx - by RaceProUK on 06-15-2005 at 07:29 PM
RE: Pathcou - TrackPopupMenuEx - by TazDevil on 06-15-2005 at 11:10 PM
RE: Pathcou - TrackPopupMenuEx - by Patchou on 06-16-2005 at 04:48 PM
RE: Pathcou - TrackPopupMenuEx - by TazDevil on 06-17-2005 at 01:00 AM
RE: Pathcou - TrackPopupMenuEx - by Patchou on 06-17-2005 at 05:44 AM
RE: Pathcou - TrackPopupMenuEx - by TazDevil on 06-17-2005 at 08:45 AM
RE: Pathcou - TrackPopupMenuEx - by RaceProUK on 06-17-2005 at 01:55 PM
RE: Pathcou - TrackPopupMenuEx - by TazDevil on 06-17-2005 at 02:27 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On