objects.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:cuckoo-ioc 作者: FafnerKeyZee 项目源码 文件源码
def get_type(self):
        """Get MIME file type.
        @return: file type.
        """
        file_type = None
        if HAVE_MAGIC:
            try:
                ms = magic.open(magic.MAGIC_NONE)
                ms.load()
                file_type = ms.file(self.file_path)
            except:
                try:
                    file_type = magic.from_file(self.file_path)
                except Exception as e:
                    log.debug("Error getting magic from file %s: %s",
                              self.file_path, e)
            finally:
                try:
                    ms.close()
                except:
                    pass

        if file_type is None:
            try:
                p = subprocess.Popen(["file", "-b", self.file_path],
                                     stdout=subprocess.PIPE)
                file_type = p.stdout.read().strip()
            except Exception as e:
                log.debug("Error running file(1) on %s: %s",
                          self.file_path, e)

        return file_type
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号