Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect that mime type is for executable file?

I am using Apache Tika to detect the mime type of an input stream and I was wondering if there's a ready method to detect that this file is an executable file, there's a big list of executable files mime types here:

http://www.file-extensions.org/filetype/extension/name/program-executable-files

and I was wondering about the best way to cover them all.

like image 593
Mahmoud Saleh Avatar asked Feb 23 '16 05:02

Mahmoud Saleh


Video Answer


2 Answers

Apache Tika's mime-types have a hierarchy. So, you don't need to check for all possible executable types, all you need to do is check if the detected type has a parent that's one of the handful of executable umbrella types

For Windows, the main one is application/x-msdownload. You might also want to check for application/x-ms-installer too

For Unix, the main one is application/x-elf, but you potentially also want to check for the scripting formats such as application/x-sh, text/x-perl, text/x-python etc.

As for how to go from a Mimetype in Tika to its parent, you'll want this existing answer here - "Correct use of Apache Tika MediaType". (Note that you need to recurse, in case there are multiple levels between the detected mime type and the base executable parent type)

like image 66
Gagravarr Avatar answered Oct 08 '22 15:10

Gagravarr


for microsoft windows the mime type is application/x-msdownload. look at this http://www.freeformatter.com/mime-types-list.html

like image 28
Musaddique Avatar answered Oct 08 '22 14:10

Musaddique