Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Does Qt have a mechanism like the `file` utility to read info about a file?



  • Hi all, I hope you are doing well.

    I need to read information about some executables that the user loads on KDbg. Usually on Linux this can be done by running file executable and various info will be returned.

    Example:

    $ file test
    test: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, with debug_info, not stripped
    
    $ file ri-t.o
    ri-t.o: ELF 64-bit LSB relocatable, UCB RISC-V, RVC, double-float ABI, version 1 (SYSV), not stripped
    

    I could use QProcess::start to run file ... but I need a portable way or this doesn't happen at all. I want to read the CPU the executable targets and possibly other stuff (ie if it's stripped etc).

    Please tell me I can do this. Thank you for your time.



  • @Petross404_Petros-S
    No, Qt does not have a utility like file.

    Unless it has changed since my day, file uses /etc/magic for its information. It looks at first-ish bytes in file. (It might have some extra hardcoded stuff, I don't know.) You could write this effectively from a Qt program if that's what you wanted to do.

    I want to read the CPU the executable targets and possibly other stuff (ie if it's stripped etc).

    That can probably be done other ways. ld gets involved in that, at least for its own architecture.



  • Sure enough, the last one is a very good approach, but when KDbg will run under Windows I will have problem. Anyway, I will mark this as solved, since there is nothing more to be done. Qt just doesn't have this functionality.

    Thank you for your time.


Log in to reply