How to detect that mime type is for executable file?
Asked Answered
S

2

6

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.

Seaboard answered 23/2, 2016 at 5:37 Comment(0)
S
17

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)

Sojourn answered 23/2, 2016 at 14:18 Comment(0)
B
1

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

Brainstorming answered 23/2, 2016 at 5:47 Comment(1)
,i don't want to make lots of checks for the list of executable files mime types.Seaboard

© 2022 - 2024 — McMap. All rights reserved.