October 7, 2011

Bogdan Bogdan
Ant Farmer
57 posts

How to recognize that runtime-loaded *.dll uses Qt?

 

Hi,
I have such scenario: Application loads 3rd-party dll using LoadLibrary (winapi). Problem is that Application uses different version of Qt than dll does, which causes instability problems. Is there any simple way to check that dll uses Qt?
I could try to use pedump stuff to check what is inside dll, but it seems to be somewhat complex and I don’t know what to check to be sure that it becomes from Qt. Moreover, probably I should do this in separated process if I want to prevent loading such dll into Application memory space. Any other ideas?

6 replies

October 7, 2011

Gerolf Gerolf
Area 51 Engineer
3210 posts

In Win API, there are possibilities, to scan the binary file for it’s file dependencies. If there, some Qt libraries are found, you have a dependency :-)

But scanning a windows binary for dependencies is tricky:
the genral procedure is:

  1. map the dll into your memory as memory mapped file (read only)
  2. At the beginning of the file, something called the PIMAGE_DOS_HEADER is loacated
  3. You then have to extract the PIMAGE_NT_HEADER
  4. From that you can get the PIMAGE_IMPORT_DESCRIPTOR
  5. This one contains the names of the libraries to load
  6. done

Sounds easy, but has some tricky stuff like offset calculation, pointeraritmethik etc needed.

If you need mor infor about that, use google with some of thees names, you will find some results.

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

October 7, 2011

Bogdan Bogdan
Ant Farmer
57 posts

Well, as I wrote, pedump stuff :-) Question is if it works for statically linked Qt? Moreover someone could change Qt binary name (I noticed this few times), so I would rather need for example a particular Qt function signature which exists inside all Qt binaries. Other thing is that such dll could need Qt indirectly, so probably I need to analyse all dependencies.

October 7, 2011

Gerolf Gerolf
Area 51 Engineer
3210 posts

if Qt is linked statically, you will have problems, as you typically only find exported functions in the dll.
If it links dynamically, you can just check recursivly all loaded dlls.
If the Qt libraries are renamed, it’s getting interesting. You could check all dlls for some of the C-exported functions of QtCore…

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

October 7, 2011

Bogdan Bogdan
Ant Farmer
57 posts

Gerolf wrote:
if Qt is linked statically, you will have problems, as you typically only find exported functions in the dll.
It seems that I cannot check such dll. This way the only thing I can do is to load it in separated process, it would solve problem with different Qt versions.
Gerolf wrote:
If the Qt libraries are renamed, it’s getting interesting. You could check all dlls for some of the C-exported functions of QtCore…
I’m wondering if QtCore signatures would be enough. Is there possibility to use other Qt binaries without linking with QtCore?

October 7, 2011

Gerolf Gerolf
Area 51 Engineer
3210 posts

AFAIK, all modules use stuff from QtCore, if they really link against it? never tried.

The usage of different QtVersion inside one process is impossible, unless you rename one of the versions. If you have multiple version, and they are only used by dlls, you have the same problem, as the versioj is searched by the path environment variable. Even if yozu call it from a different process, on windows you have no chance to check, which version the dll was linked against.

But if all are using default builds and the same compiler version, it is safe to just use the newest one.

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

October 7, 2011

Bogdan Bogdan
Ant Farmer
57 posts

It seems that the safest solution will be to load unknown dll as separated process.

Thanks a lot for your help.

 
  ‹‹ [SOLVED] Interface class - undefined reference to vtable for MyInterface      Get string value from modified key press ››

You must log in to post a reply. Not a member yet? Register here!