I know Linux has a built-in binary executable formats such as ELF, a.out, Shebang etc. I also know that the user is able to add his own supported formats to the system in '/proc/sys/fs/binfmt_misc'.
Now my goal is to cover all the possibilities here, so I could automatically (with a script) determine if a program is executable or not (and not just by the runable permission bit). I heard of the command file that can identify the file's format, and that it will print out the word 'executable' if it is an executable however - when I tested it with a jar file (which is listed on the binfmt_misc directory as an executable) it didn't print out the word 'executable'.
So I am asking for the best way to determine if a file is executable on a Linux system. If there is a way to run execve() just to get the return code (if the file isn't a supported executable - execve returns a matching error) then I could just intercept it and use it. The thing is that I need to do it without running the file on my system (or at least not let it change it in any way...).
Thanks!