(path)
Check the signature of the give file and returns what kind of executable
    matches.
Check the signature of the give file and returns what kind of executable
    matches.
Check the signature of the give file and returns what kind of executable matches .
def get_type(path):
    '''
    Check the signature of the give file and returns what kind of executable
    matches.
    '''
    with open(path, 'rb') as f:
        signature = f.read(4)
        if len(signature) < 4:
            return UNKNOWN
        signature = struct.unpack('>L', signature)[0]
        if signature == ELF_SIGNATURE:
            return ELF
        if signature in MACHO_SIGNATURES:
            return MACHO
        if signature != FAT_SIGNATURE:
            return UNKNOWN
        # We have to sanity check the second four bytes, because Java class
        # files use the same magic number as Mach-O fat binaries.
        # This logic is adapted from file(1), which says that Mach-O uses
        # these bytes to count the number of architectures within, while
        # Java uses it for a version number. Conveniently, there are only
        # 18 labelled Mach-O architectures, and Java's first released
        # class format used the version 43.0.
        num = f.read(4)
        if len(num) < 4:
            return UNKNOWN
        num = struct.unpack('>L', num)[0]
        if num < 20:
            return MACHO
        return UNKNOWN
def get_type ( path ) : with open ( path , 'rb' ) as f : signature = f . read ( 4 ) if len ( signature ) < 4 : return UNKNOWN signature = struct . unpack ( '>L' , signature ) [ 0 ] if signature == ELF_SIGNATURE : return ELF if signature in MACHO_SIGNATURES : return MACHO if signature != FAT_SIGNATURE : return UNKNOWN # We have to sanity check the second four bytes, because Java class # files use the same magic number as Mach-O fat binaries. # This logic is adapted from file(1), which says that Mach-O uses # these bytes to count the number of architectures within, while # Java uses it for a version number. Conveniently, there are only # 18 labelled Mach-O architectures, and Java's first released # class format used the version 43.0. num = f . read ( 4 ) if len ( num ) < 4 : return UNKNOWN num = struct . unpack ( '>L' , num ) [ 0 ] if num < 20 : return MACHO return UNKNOWN