Page 1 of 4 123 ... LastLast
Results 1 to 20 of 63

Thread: DLL Injection with slots... ?!?!?

  1. #1
    Join Date
    Oct 2010
    Posts
    48
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Question DLL Injection with slots... ?!?!?

    Hi,
    I'm quite new to QT so be nice ;-)
    I have a DLL that I inject into a QT application (I don't have the source)
    I want this DLL to get some signals from the application that it's injected into.

    the injection is working very well, and I have access to all the UI, I can even change values of text fields etc.

    BUT, I can't connect the DLL slots to the UI's signals.
    I've been reading about it a bit, but no one could give a good answer on how to do it.

    please please, help!

    Thanks
    Gil.

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DLL Injection with slots... ?!?!?

    By "can't" what do you mean? Do you get an error message?

  3. #3
    Join Date
    Oct 2010
    Posts
    48
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DLL Injection with slots... ?!?!?

    I did an internal connection (With two text fields in the main APP) and it worked.
    Like this:
    Qt Code:
    1. connect(lineEdit, SIGNAL(textChanged(QString)), lineEdit2, SLOT(setText(QString)));
    To copy to clipboard, switch view to plain text mode 

    But when I connect to my own DLL slot function, it didn't work (It didn't get to the slot function)
    like this:
    Qt Code:
    1. connect(lineEdit, SIGNAL(textChanged(QString)), this, SLOT(mySlot()));
    To copy to clipboard, switch view to plain text mode 

    As I'm guessing, I can't connect to slots that didn't compile with the main app.... My DLL's slot is not known to the main app...
    am I write? what's the work around?
    Last edited by wysota; 18th October 2010 at 13:55. Reason: missing [code] tags

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DLL Injection with slots... ?!?!?

    Are you sure you are using the exact same DLLs and library instance for Qt as the main application?

    I don't think the main app needs to know about your slots, as they defined by MOC, and as long as you are using the same version of MOC (and Qt) as the main app, it should find your slot at run time.

    If the app you are hooking into using a statically linked version of Qt, then it's a lot more difficult.

  5. #5
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: DLL Injection with slots... ?!?!?

    As squidge already said, signals and slots are handled by MOC.
    Thus, make sure that your injected DLL is processed by MOC before linking it (here I mean the actual linking of the DLL, not injecting it).

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: DLL Injection with slots... ?!?!?

    Quote Originally Posted by gilamran View Post
    But when I connect to my own DLL slot function, it didn't work (It didn't get to the slot function)
    like this:
    connect(lineEdit, SIGNAL(textChanged(QString)), this, SLOT(mySlot()));
    What error do you get or how do you know the dll slot isn't called? And this is surly not pointing to the dll!

  7. #7
    Join Date
    Oct 2010
    Posts
    48
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DLL Injection with slots... ?!?!?

    I don't know how to get the error... I just don't see the slot function being called.
    In the slot function I have a code that sends a log message. (The log is working great)

    Is there a way to see if the connection is ok?

    btw: what should I put instead of "this"?

  8. #8
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: DLL Injection with slots... ?!?!?

    Quote Originally Posted by gilamran View Post
    Is there a way to see if the connection is ok?
    On runtime there will be a warning on the console.

    btw: what should I put instead of "this"?
    A pointer to your "dll", since it should be the slots of the "dll", right?

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: DLL Injection with slots... ?!?!?

    Can you show us the header file for the object in the dll declaring the slot you wish to connect to?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DLL Injection with slots... ?!?!?

    tbh, I would have expected 'this' to work, as you are referring to a class in the same memory space as the application (since you have injected the dll into the application). Giving the dll instance to the connect call doesn't make sense to me, as then it wouldn't know which class to call the metacall methods.

  11. #11
    Join Date
    Oct 2010
    Posts
    48
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DLL Injection with slots... ?!?!?

    On runtime there will be a warning on the console.
    I'm unable to debug this... so where can I see the console? (Sorry if it's dumb question)

    A pointer to your "dll", since it should be the slots of the "dll", right?
    I'm ready to try anything, so where can I get this "dll" pointer from (Sorry again)

    can you show us the header file for the object in the dll declaring the slot you wish to connect to?
    Sure will, soon. (Currently at work)

    Some more info:
    • I'm using Visual studio
    • I'm injecting my dll (Using WinJect) into the BasicLayout QT example (Just for the tests)
    • I'm communicating with the DLL using windows WM_COPYDATA Messages


    MANY THANKS for your time and effort!!!

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: DLL Injection with slots... ?!?!?

    I'm unfamiliar with how WinJect works and possibly others thought that by "injecting" you meant something else. Is the "injected" dll in the same memory space as the main application or are they two different processes? If the latter then obviously signal/slot connections will not work.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    Join Date
    Oct 2010
    Posts
    48
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DLL Injection with slots... ?!?!?

    yea it's in the same memory space! this is what injection means.
    When injected you have access to all the QT objects, widgets, and you can call functions there, like change a some text fields, change data.. everything, if you're not injected... you can't

  14. #14
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: DLL Injection with slots... ?!?!?

    @squidge: Ok, now I am confused. Seems I have a logical understanding problem. I'll work that out for me Thanks.

  15. #15
    Join Date
    Oct 2010
    Posts
    48
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DLL Injection with slots... ?!?!?

    Quote Originally Posted by Lykurg View Post
    @squidge: Ok, now I am confused. Seems I have a logical understanding problem. I'll work that out for me Thanks.
    what do you need me to clarify?

  16. #16
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: DLL Injection with slots... ?!?!?

    Quote Originally Posted by gilamran View Post
    I'm unable to debug this... so where can I see the console?
    If you start your application on the command line and the slot can't be found a warning will be printed (or inside Qt Creator on the application output), but
    what do you need me to clarify?
    I get the "injecting" wrong (thought you would using QPluginLoader), so your slot should be found. So I am out of ideas right now.

  17. #17
    Join Date
    Oct 2010
    Posts
    48
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DLL Injection with slots... ?!?!?

    Ok, I'll check the command line error.
    And I'll post a short code that do what I say, maybe it'll be clear than.

    Thanks again!

  18. #18
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: DLL Injection with slots... ?!?!?

    I'm assuming you didn't create a plugin. This means a library exporting certain symbols that you use directly in the application you want to inject.

    I assume that you can not change the application code itself directly. If that's not the case, then see the examples and documentation of creating plugins or using libraries.

    Consider the following schema:
    Qt Code:
    1. +-----------------------------------------------------------------------------------------+
    2. | Application |
    3. | |
    4. | +---------------+ +-----------------------------------------+ |
    5. | +---------------+| | Application code, contains objects. | |
    6. | +---------------+|| | | |
    7. | +---------------+||| | mainWindow (a QMainWindow) | |
    8. | | Linked |||+ | | | |
    9. | | libraries ||+ | +-- button (a QPushButton) | |
    10. | | |+ | +-- label (a QLabel) | |
    11. | +---------------+ +-----------------------------------------+ |
    12. | | |
    13. | v |
    14. | +-------------------------------------------------------------------------------------+ |
    15. | | Your injected DLL | |
    16. | | | |
    17. | | +--------------------------+ | |
    18. | | | Class based on QObject | | |
    19. | | | inside DLL | | |
    20. | | | | | |
    21. | | | Contains signals and | | |
    22. | | | slots | | |
    23. | | +--------------------------+ | |
    24. | | | | |
    25. | | v | |
    26. | | +-------------------------------------------------------------------------+ | |
    27. | | | Create an object: | Do this from within a context | | |
    28. | | | | where the application event | | |
    29. | | | MyClass *myclass = new MyClass; | loop is running. | | |
    30. | | +-------------------------------------------------------------------------+ | |
    31. | | | | |
    32. | | v | |
    33. | | +------------------------------------------------+ | |
    34. | | | Example: | | |
    35. | | | Suppose you have installed an application | | |
    36. | | | event filter. | | |
    37. | | | | | |
    38. | | | Also, suppose you intercept the mainWindow | | |
    39. | | | show event. | | |
    40. | | | | | |
    41. | | | From this event, you have a pointer to | | |
    42. | | | mainWindow, let's call it pMainWindow | | |
    43. | | | | | |
    44. | | | Then you can write: | | |
    45. | | | | | |
    46. | | | connect(pMainWindow->button, SIGNAL(...), | | |
    47. | | | myclass, SLOT(...)); | | |
    48. | | | | | |
    49. | | | | | |
    50. | | | In pseudocode: | | |
    51. | | | ---------------------------------------------- | | |
    52. | | | when application started | | |
    53. | | | install eventfilter | | |
    54. | | | | | |
    55. | | | when eventfilter gets called | | |
    56. | | | check the event and the target object | | |
    57. | | | if event = show and object = mainWindow | | |
    58. | | | Create a new MyClass object if none | | |
    59. | | | already exists. | | |
    60. | | | Connect signals and slots | | |
    61. | | | | | |
    62. | | +------------------------------------------------+ | |
    63. | | | |
    64. | +-------------------------------------------------------------------------------------+ |
    65. | |
    66. +-----------------------------------------------------------------------------------------+
    To copy to clipboard, switch view to plain text mode 

    You create a dll that reimplements the application event function to install an event filter.
    In that event filter, you intercept the show event of a widget (for example). While intercepting that event, create a new QObject based object that contains signals and slots. Connect the slots of that object to the signals of the widget (or a member of that widget).

    Make sure that when you build your library, the definitions of all the classes are known (include the correct headers). Also make sure that your code is processed by MOC.

    Then inject the library in the program.

    How this is exactly done on Windows, I don't know. Maybe you don't need to reimplement the event function of the application in order to install an event filter. That would make it a little bit easier.

    EDIT: this is just a brainstorm from me. I do not assume that everything above is 100% correct.
    Last edited by tbscope; 17th October 2010 at 12:56.

  19. #19
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DLL Injection with slots... ?!?!?

    I think what he means is that the application doesn't know about the DLL and is not loading the DLL.

    Instead, he is using Winject to inject the DLL into the applications memory space, the application doesn't know the DLL has been injected. I assume it is being done this way because the source code of the original application isn't available and he wants to modify that application somehow. Maybe get some data from an existing Qt widget or manipulate the data somehow.

    Kinda similar to how flaab wanted to grab data from inside a Poker engine in his thread.

  20. #20
    Join Date
    Oct 2010
    Posts
    48
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DLL Injection with slots... ?!?!?

    This is almost the same thing... and we're talking about the same software, FullTiltPoker!
    But flaab is asking how to intercept into internal function of QString or somthing like that...
    I want my DLL to get signals from this software, like dataChanged, etc.

    I'm not building a poker bot like flaab, I'm collecting players statistics.

    for this, I need my DLL to be able to "connect" to the software UI signals.
    Thanks for clearing me up.

    Gil.

Similar Threads

  1. Signals & Slots!
    By qtoptus in forum Qt Programming
    Replies: 2
    Last Post: 15th April 2010, 01:50
  2. Can you use dependency injection with Qt?
    By photo_tom in forum Qt Programming
    Replies: 0
    Last Post: 20th February 2010, 18:34
  3. How do you add slots?
    By rakkar in forum Newbie
    Replies: 10
    Last Post: 26th August 2009, 23:11
  4. Slots or new slots
    By Colx007 in forum Qt Programming
    Replies: 3
    Last Post: 21st January 2008, 17:38
  5. signal and slots
    By vermarajeev in forum Qt Programming
    Replies: 4
    Last Post: 16th October 2007, 08:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.