def run(self):
        """Run analysis.
        @return: results dict.
        """
        self.key = "static"
        static = {}

        # Does the target file still exist?
        if self.task["category"] != "file" or \
                not os.path.exists(self.file_path):
            return
        package = self.task.get("package")

        if self.task["category"] == "file":
            ext = os.path.splitext(self.task["target"])[1].lstrip(".").lower()
        else:
            ext = None

        if ext == "exe" or "PE32" in File(self.file_path).get_type():
            if HAVE_PEFILE:
                static.update(PortableExecutable(self.file_path).run())
            static["keys"] = self._get_keys()

        if "Mach-O" in File(self.file_path).get_type():
            if HAVE_MACHOLIB:
                static.update(MachOExecutable(self.file_path).run())
            else:
                log.critical("You do not have the MACHOLIB library installed ")
            static["keys"] = self._get_keys()

        if package == "wsf" or ext == "wsf":
            static["wsf"] = WindowsScriptFile(self.file_path).run()

        if package in ("doc", "ppt", "xls") or ext in self.office_ext:
            static["office"] = OfficeDocument(self.file_path).run()

        def pdf_worker(filepath):
            return PdfDocument(filepath).run()

        if package == "pdf" or ext == "pdf":
            timeout = int(self.options.get("pdf_timeout", 60))
            static["pdf"] = dispatch(
                pdf_worker, (self.file_path,), timeout=timeout
            )

        return static
Exemple #2
0
    def run(self):
        """Run analysis.
        @return: results dict.
        """
        self.key = "static"
        static = {}

        # Does the target file still exist?
        if self.task["category"] != "file" or \
                not os.path.exists(self.file_path):
            return

        package = self.task.get("package")

        if self.task["category"] == "file":
            ext = os.path.splitext(self.task["target"])[1].lstrip(".").lower()
        else:
            ext = None

        if ext == "exe" or "PE32" in File(self.file_path).get_type():
            if HAVE_PEFILE:
                static.update(PortableExecutable(self.file_path).run())
            static["keys"] = self._get_keys()

        if package == "wsf" or ext == "wsf":
            static["wsf"] = WindowsScriptFile(self.file_path).run()

        if package in ("doc", "ppt", "xls") or ext in self.office_ext:
            static["office"] = OfficeDocument(self.file_path).run()

        def pdf_worker(filepath):
            return PdfDocument(filepath).run()

        if package == "pdf" or ext == "pdf":
            timeout = int(self.options.get("pdf_timeout", 60))
            static["pdf"] = dispatch(
                pdf_worker, (self.file_path,), timeout=timeout
            )

        return static