Share data between applications
Hello, I would like to know how to share data between two Qt applications... Lets say that application 1 have some strings which I want to access in application 2... Shared memory or any other way of doing it...
I would also like to know how to access that data if I am not owner of the application... What I know is that two applications (which are not mine) are sharing data... How do I find out the way they are sharing it and access it?
You can use a QSharedMemory for this purpose. Maybe in conjunction with a QSystemSemaphore, if you need to implemented something like a "producer vs. consumer" pattern. The "main" (server) application will create the shared memory under a pre-defined key, so the "client" (slave) application can attach to that shared memory. All programs connected to the shared memory will just get a pointer to the shared memory region. You need to make sure that all "well behaving" application synchronize their access to the shared memory properly, so no "evil" things will happen. Of course a "malicious" application could always mess up your shared memory, but there's no easy protection against that case.
Thanks for the answer... If I am not owner of the application, how can I find that pre-defined key, so I can read data and show it in my application?
You must know the key beforehand, it's as simple as that. If some application exposes data that is intended to be processed by another application via a shared memory, then that application must also define under which fixed key the data will be available. I'd suggest to generate a GUID for this purpose.
(The application could also use a different key every time, but then the key must be made available at well-known location, e.g. at a specific registry path/key)
Is there a way to get that key? Reading application memory, reverse engineering, anything else? I guess there must be some program that can find out that key...
Why should that be needed? If an application intended to share data through a QSharedMemory, it would have to properly document under which key the shared memory is available and - even more important - it would have to properly document the layout of the data that is exposed in its shared memory region.
Of course, Qt uses underlying Operating System technologies to create the shared memory region. So, with some system tools, like Process Explorer on Windows, you can find the shared memory region - though the "native" key may be different than what you have specified in Qt, because Qt internally computes a Hash of your key! Anyway, all this is completely pointless, as long as you still don't know the data layout inside the shared memory region...
See also here:
[quote author="Anonymous" date="1416664815"]Is there a way to get that key? Reading application memory, reverse engineering, anything else? I guess there must be some program that can find out that key... [/quote]
Not in general. There are many ways that applications can share data. So if you want to make your own client for some data source, you'll need to do some tinkering to figure out how the existing apps talk to each other. If it were me, and the apps were on Linux, I'd probably start with a tool like strace to see what system calls were being used. It will give you some idea of whether or not a file is being written somewhere with hint data. Also, lsof will list open files, and can also show information about socket connections.
MuldeR you was right... Application is doing a lot of work with registry keys... Reading, querying, setting values into registry keys, mapping...