示例#1
0
 def test_temporary_file(self):
     a = Archive("tests/files/pdf0.zip")
     f = a.get_file("files/pdf0.pdf")
     filepath = f.file_path
     assert f.get_size() == 680
     assert os.path.exists(filepath)
     del f
     assert not os.path.exists(filepath)
示例#2
0
 def test_temporary_file(self):
     a = Archive("tests/files/pdf0.zip")
     f = a.get_file("files/pdf0.pdf")
     filepath = f.file_path
     assert f.get_size() == 680
     assert os.path.exists(filepath)
     del f
     assert not os.path.exists(filepath)
示例#3
0
    def run(self):
        """Run file information gathering.
        @return: information dict.
        """
        self.key = "target"

        ret = {
            "category": self.task["category"],
        }

        # We have to deal with file, archive, and URL targets.
        if self.task["category"] == "file":
            ret["file"] = {}

            # Let's try to get as much information as possible, i.e., the
            # filename if the file is not available anymore.
            if os.path.exists(self.file_path):
                ret["file"] = File(self.file_path).get_all()
            else:
                ret["file"]["path"] = None
                ret["file"]["yara"] = []

            ret["file"]["name"] = File(self.task["target"]).get_name()
        elif self.task["category"] == "archive":
            ret["filename"] = self.task["options"]["filename"]

            if os.path.exists(self.file_path):
                ret["archive"] = File(self.file_path).get_all()
                a = Archive(self.file_path)
                ret["file"] = a.get_file(ret["filename"]).get_all()
            else:
                ret["archive"] = {}
                ret["file"] = {}

            ret["archive"]["name"] = File(self.task["target"]).get_name()
            ret["human"] = "%s @ %s" % (
                ret["filename"], ret["archive"]["name"]
            )
            ret["file"]["name"] = os.path.basename(ret["filename"])
        elif self.task["category"] == "url":
            ret["url"] = self.task["target"]

        return ret
示例#4
0
    def run(self):
        """Run file information gathering.
        @return: information dict.
        """
        self.key = "target"

        ret = {
            "category": self.task["category"],
        }

        # We have to deal with file, archive, and URL targets.
        if self.task["category"] == "file":
            ret["file"] = {}

            # Let's try to get as much information as possible, i.e., the
            # filename if the file is not available anymore.
            if os.path.exists(self.file_path):
                ret["file"] = File(self.file_path).get_all()
            else:
                ret["file"]["path"] = None
                ret["file"]["yara"] = []

            ret["file"]["name"] = File(self.task["target"]).get_name()
        elif self.task["category"] == "archive":
            ret["filename"] = self.task["options"]["filename"]

            if os.path.exists(self.file_path):
                ret["archive"] = File(self.file_path).get_all()
                a = Archive(self.file_path)
                ret["file"] = a.get_file(ret["filename"]).get_all()
            else:
                ret["archive"] = {}
                ret["file"] = {}

            ret["archive"]["name"] = File(self.task["target"]).get_name()
            ret["human"] = "%s @ %s" % (ret["filename"],
                                        ret["archive"]["name"])
            ret["file"]["name"] = os.path.basename(ret["filename"])
        elif self.task["category"] == "url":
            ret["url"] = self.task["target"]

        return ret
示例#5
0
 def test_get_file(self):
     a = Archive("tests/files/pdf0.zip")
     assert a.get_file("files/pdf0.pdf").get_size() == 680
示例#6
0
 def test_get_file(self):
     a = Archive("tests/files/pdf0.zip")
     assert a.get_file("files/pdf0.pdf").get_size() == 680