Results 1 to 20 of 63

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

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #17
    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.

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
  •  
Qt is a trademark of The Qt Company.