'Parses /proc/sys/fs/binfmt_misc to find the interpreter for a file'

def binfmt_lookup(self):

    binfmt_misc = '/proc/sys/fs/binfmt_misc'
    if (not isinstance(self.process, process)):
        log.debug('Not    a    process')
        return ''
    if self.process._qemu:
        return self.process._qemu
    if (not os.path.isdir(binfmt_misc)):
        log.debug('No    binfmt_misc    dir')
        return ''
    exe_data = bytearray(self.read(self.exe))
    for entry in os.listdir(binfmt_misc):
        keys = {}
        path = os.path.join(binfmt_misc, entry)
        try:
            data = self.read(path)
        except Exception:
            continue
        for line in data.splitlines():
            try:
                (k, v) = line.split(None)
            except ValueError:
                continue
            keys[k] = v
        if ('magic' not in keys):
            continue
        magic = bytearray(unhex(keys['magic']))
        mask = bytearray(('\xff' * len(magic)))
        if ('mask' in keys):
            mask = bytearray(unhex(keys['mask']))
        for (i, mag) in enumerate(magic):
            if ((exe_data[i] & mask[i]) != mag):
                break
        else:
            return keys['interpreter']
    return ''
