Quantcast
Channel: Active questions tagged linux-kernel - Stack Overflow
Viewing all articles
Browse latest Browse all 12241

How can I test if a file could be marked as executable and run? [duplicate]

$
0
0

This question already has an answer here:

Is there a way to test whether a file, if I mark it as executable with chmod +x file and run it with ./file will cause the operating system to execute it (or at least attempt to execute it), without actually executing it?

So far I have:

  1. On Mac and Linux (or other Unix), test whether the first two bytes are #!.
  2. On Linux, test whether the first four bytes are 0x7f454c46 (ELF magic number) and the e_type (offset 0x10) is ET_EXEC (0x0002).
  3. On Mac, check if the file is Mach-O and filetype is MH_EXECUTE. (Mach-O format is a bit more complicated and I haven't figured out the exact magic number(s) and offset for filetype yet.)
  4. ...other executable formats?

Is there a way to do this more easily and correctly?


Viewing all articles
Browse latest Browse all 12241

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>