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.
Re: DLL Injection with slots... ?!?!?
By "can't" what do you mean? Do you get an error message?
Re: DLL Injection with slots... ?!?!?
I did an internal connection (With two text fields in the main APP) and it worked.
Like this:
Code:
connect(lineEdit,
SIGNAL(textChanged
(QString)), lineEdit2,
SLOT(setText
(QString)));
But when I connect to my own DLL slot function, it didn't work (It didn't get to the slot function)
like this:
Code:
connect(lineEdit,
SIGNAL(textChanged
(QString)),
this,
SLOT(mySlot
()));
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?
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.
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).
Re: DLL Injection with slots... ?!?!?
Quote:
Originally Posted by
gilamran
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!
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"?
Re: DLL Injection with slots... ?!?!?
Quote:
Originally Posted by
gilamran
Is there a way to see if the connection is ok?
On runtime there will be a warning on the console.
Quote:
btw: what should I put instead of "this"?
A pointer to your "dll", since it should be the slots of the "dll", right?
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?
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.
Re: DLL Injection with slots... ?!?!?
Quote:
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)
Quote:
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)
Quote:
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!!!
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.
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
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.
Re: DLL Injection with slots... ?!?!?
Quote:
Originally Posted by
Lykurg
@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?
Re: DLL Injection with slots... ?!?!?
Quote:
Originally Posted by
gilamran
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
Quote:
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.
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!
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:
Code:
+-----------------------------------------------------------------------------------------+
| Application |
| |
| +---------------+ +-----------------------------------------+ |
| +---------------+| | Application code, contains objects. | |
| +---------------+|| | | |
|
+---------------+||| | mainWindow
(a
QMainWindow) | |
| | Linked |||+ | | | |
| | |
+ |
+-- label
(a
QLabel) | |
| +---------------+ +-----------------------------------------+ |
| | |
| v |
| +-------------------------------------------------------------------------------------+ |
| | Your injected DLL | |
| | | |
| | +--------------------------+ | |
| | | inside DLL | | |
| | | | | |
| | | Contains signals and | | |
| | | slots | | |
| | +--------------------------+ | |
| | | | |
| | v | |
| | +-------------------------------------------------------------------------+ | |
| | | Create an object: | Do this from within a context | | |
| | | | where the application event | | |
| | | MyClass *myclass = new MyClass; | loop is running. | | |
| | +-------------------------------------------------------------------------+ | |
| | | | |
| | v | |
| | +------------------------------------------------+ | |
| | | Example: | | |
| | | Suppose you have installed an application | | |
| | | event filter. | | |
| | | | | |
| | | Also, suppose you intercept the mainWindow | | |
| | | show event. | | |
| | | | | |
| | | From this event, you have a pointer to | | |
| | | mainWindow, let's call it pMainWindow | | |
| | | | | |
| | | Then you can write: | | |
| | | | | |
| | | connect(pMainWindow->button, SIGNAL(...), | | |
| | | myclass, SLOT(...)); | | |
| | | | | |
| | | | | |
| | | In pseudocode: | | |
| | | ---------------------------------------------- | | |
| | | when application started | | |
| | | install eventfilter | | |
| | | | | |
| | | when eventfilter gets called | | |
| | | check the event and the target object | | |
| | | if event = show and object = mainWindow | | |
| | | Create a new MyClass object if none | | |
| | | already exists. | | |
| | | Connect signals and slots | | |
| | | | | |
| | +------------------------------------------------+ | |
| | | |
| +-------------------------------------------------------------------------------------+ |
| |
+-----------------------------------------------------------------------------------------+
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.
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.
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.