API hooking breakthru

This is a discussion on API hooking breakthru within the Windows Programming forums, part of the Platform Specific Boards category; I finally got into the text that I needed. WOOOHOOO! I am so happy. Now the question is, what is ...

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    170

    Talking API hooking breakthru

    I finally got into the text that I needed. WOOOHOOO! I am so happy.

    Now the question is, what is the best way to pass the text to my app. I have dll that sets the hook that is currently done via a simple launcher app. So, I add the InsertHook and RemoveHook calls into my application code, but I am unsure of how I extract the data from my dll. My first thougt was to use a file, but I am sure there is a muh better way that I just am not aware of.

    Has anyone pulled data from a dll before, and can give me pointers? I am a dll newbie. I suppose a logical method would be to write a function in the dll that would return all the text since the last call. I would really prefer a push from the DLL into my app, so that I always have the up-to-date data.

    Any help would be greatly appreciated.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Unsure how you you have implemented this, but if its a case of multiple copies of your dll being loaded into different processes (as is the case of conventional system hooks like keyloggers), then access to a file is difficult as sharing the handle is almost impossible.

    When I do stuff like this I like to use a MailSlot (CreateMailslot() API - like a namedpipe, but easier to use for this and available to 98/95/ME)...each dll opens the mailslot and post the info you want to record....your main app opens a thread and sits there reading the sent info and processing it.....Its a little work, but is pretty effective

  3. #3
    Registered User
    Join Date
    Aug 2002
    Posts
    170
    I'll give it a try. Sounds like what I need, I was thinking of using a pipe so this should do the trick.

    BTW, the trick to hooking the functions, was to also hook LoadLibrary. I found the code at codeguru.
    Best Regards,

    Bonkey

  4. #4
    Registered User
    Join Date
    Aug 2002
    Posts
    170
    I can't get it to compile. I have the SDK installed and it is the top of the list on include paths.

    I keep getting these errors no matter what I do.

    testlauncher.cpp(12) : error C2065: 'CreateMailSlot' : undeclared identifier
    testlauncher.cpp(12) : error C2440: '=' : cannot convert from 'int' to 'void *'

    here is the code:

    Code:
    #define WIN32_LEAN_AND_MEAN
    #include <windows.h>
    #include <winbase.h>
    #include "..\testdll\testdll.h"
    
    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    {
    	HANDLE MailSlot;
    	MailSlot=CreateMailSlot("\\\\.\\mailslot\\DLLTALK",0,0);
    
        InstallHook();
    
       // MessageBox( NULL, "Hook instaled", "TestLauncher", MB_OK );
    
    	int result=0;
    	char buffer[255];
    	unsigned long bytesread;
    	while(result != 1)
    	{
    		ReadFile(MailSlot,&buffer,250,&bytesread,NULL);
    		result=MessageBox(NULL,buffer,"Captured Text",MB_OKCANCEL);
    	}
     
    	RemoveHook();
    	CloseHandle(MailSlot);
        return 0;
    }
    Last edited by bonkey; 11-25-2002 at 05:56 PM.
    Best Regards,

    Bonkey

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    CreateMailslot != CreateMailSlot


    Also...it likes 4 params

  6. #6
    Registered User
    Join Date
    Aug 2002
    Posts
    170
    Thanks. Man I feel stupid
    Best Regards,

    Bonkey

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. platform specific API or C standard API
    By George2 in forum C Programming
    Replies: 1
    Last Post: 11-12-2007, 12:32 AM
  2. Strange error while attempting API hooking
    By cefarix in forum Windows Programming
    Replies: 2
    Last Post: 11-10-2006, 12:29 PM
  3. FILES in WinAPI
    By Garfield in forum Windows Programming
    Replies: 46
    Last Post: 10-02-2003, 06:51 PM
  4. API Hooking?
    By kes103 in forum Windows Programming
    Replies: 16
    Last Post: 11-21-2002, 09:43 AM
  5. OLE Clipboard :: Win32 API vs. MFC
    By kuphryn in forum Windows Programming
    Replies: 3
    Last Post: 08-11-2002, 05:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21