aboutcode-org / typecode

7 stars 9 forks source link

Add support for Mach-0 macOS/iOS executables #39

Open pombredanne opened 9 months ago

pombredanne commented 9 months ago

See https://en.wikipedia.org/wiki/Mach-O

They have these characteristics:

we should have a basic detection to qualify these as binaries and executables.

pombredanne commented 9 months ago

A simple way to go may be:

def is_macho(self):
    return (
        self.filetype_file.lower().startswith('mach-o')
        or self.mimetype_file.lower().startswith("application/x-mach-binary")
    )

or from a file location

def is_macho(location):
    t = get_type(location)
    return (
        t.filetype_file.lower().startswith('mach-o')
        or t.mimetype_file.lower().startswith("application/x-mach-binary")
    )
pombredanne commented 9 months ago

A small truncated file is enough for testing: For instance: head -c 100 GoReSym_mac > bar and bar is only 100 bytes.