Results 1 to 7 of 7

Thread: Tracking Clipboard Paste

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    167

    Tracking Clipboard Paste

    I hope someone can answer me here...

    I want to track the windows clipboard paste,
    here is an example of I want to do:
    Lets say we have 5 strings, we save the first string in clipboard, I want to paste this string only once, when the string is pasted anywhere, I want to save the next string in the clipboard (get rid of the first string)...

    so a way to do this would be to hook GetClipboardData and then in the hook function use EmptyClipboard and then SetClipboardData to put the next string in the clipboard...

    the problem is I can't find how to hook the GetClipboardData, all the tut and code hook the entire keyboard, I would be thankful if someone can help me hook the GetClipboardData or show me a better way to do this...
    Thanks
    Im using Visual Studio 2008 Professional Edition
    .Net Framework 3.5

  2. #2
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Ubuntu Haters Club
    Posts
    405

    Re: Tracking Clipboard Paste

    I don't know how exactly you're wanting to go about a function hook, but if we're talking C:
    Code:
    #include <windows.h>
    #pragma comment(lib, "detours.lib")
    #include "detours.h" // Detours for everything else
    
    HANDLE (WINAPI *origGetClipboardData)(UINT uFormat);
    HANDLE WINAPI hookGetClipboardData(UINT uFormat) {
    	// Do whatever
    
    	// Call original
    	return origGetClipboardData(uFormat);
    }
    void doHooking() {
    	origGetClipboardData = (HANDLE (__stdcall *)(UINT))DetourFunction((PBYTE)GetClipboardData, (PBYTE)hookGetClipboardData);
    }
    Last edited by RudiVisser; Jun 3rd, 2008 at 06:15 PM.
    » Twitter: @rudi_visser : Website: www.rudiv.se «

    If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    167

    Re: Tracking Clipboard Paste

    hmm ok, if we're gonna do it in C, I need more help, so the code above applies the hook, where can I check if the paste is actually done?
    like If(Paste) { /*do something*/ } ?
    thanks
    Im using Visual Studio 2008 Professional Edition
    .Net Framework 3.5

  4. #4
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Ubuntu Haters Club
    Posts
    405

    Re: Tracking Clipboard Paste

    Well one of us doesn't understand something

    I thought that by your mentioning of the functions GetClipboardData, EmptyClipboard and SetClipboardData - You knew the process which would happen. I was just helping you with the hook

    Providing the user hasn't got any applications running that are going to abnormally call GetClipboardData, you can just set your next string in that function.

    I'm guessing you want the same functionality as one of these powerpasters, where you list a lot of strings and each time you paste from the clipboard it has a different one? I'm fairly sure that it would work to just alter the data on every call to GetClipboardData.
    » Twitter: @rudi_visser : Website: www.rudiv.se «

    If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    167

    Re: Tracking Clipboard Paste

    ok, I'm not so good in C ... so yea I kinda need more help
    I'm trying to run ur code
    Code:
    #include <windows.h>
    #include <stdio.h>
    #pragma comment(lib, "detours.lib")
    #include "detours.h" // Detours for everything else
    
    HANDLE (WINAPI *origGetClipboardData)(UINT uFormat);
    HANDLE WINAPI hookGetClipboardData(UINT uFormat) {
    	// Do whatever
        printf("test\n");
    	// Call original
    	return origGetClipboardData(uFormat);
    }
    void doHooking() {
    	origGetClipboardData = (HANDLE (__stdcall *)(UINT))DetourFunction((PBYTE)GetClipboardData, (PBYTE)hookGetClipboardData);
    }
    but I'm getting the error:
    (.text+0x3c)||undefined reference to `_DetourFunction@8'|
    text+0x104)||undefined reference to `_WinMain@16'|
    ||=== Build finished: 2 errors, 0 warnings ===|
    can you please help ?
    and btw, according to my code, when will the program print test ? when Clipboard changes ? or is used ? or never ?
    Im using Visual Studio 2008 Professional Edition
    .Net Framework 3.5

  6. #6
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Ubuntu Haters Club
    Posts
    405

    Re: Tracking Clipboard Paste

    Hmmm well I'm unsure, I made a test app that hooks the GetClipboardData function, tried to Paste, and the hook wasn't called - So either that function isn't used by Windows Ctrl-V/Right-Click->Paste, or it's the wrong function all together.

    I had a look around for example clipboard history managers (as they'll probably use the same concept that you want to do) and I think the closest one I found (infact almost the only one that isn't closed source) was Ditto, but I think it may be too complex for what you're doing. I don't have the time (at the moment) to go through it and see exactly how it works, if I have time later I'll take a look for you.
    » Twitter: @rudi_visser : Website: www.rudiv.se «

    If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    167

    Re: Tracking Clipboard Paste

    some people told me to use SetClipboardViewer API, but I'm not sure it will work, do you have any idea if this API can help ?
    Im using Visual Studio 2008 Professional Edition
    .Net Framework 3.5

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width