Ejemplo n.º 1
0
    def parse(self, filepath: str, filename: str = "") -> Cert:
        """
        :param filepath: path of the CERT file
        :param filename: name of the CERT file
        :return: the parsed CERT file
        :raise: FileParsingError if cannot parse the file
        :raise: CertParsingError if cannot parse the file as a CERT
        """
        self.logger.debug(
            "Parsing CERT file: filepath=\"%s\", filename=\"%s\"", filepath,
            filename)
        file = FileParser(self.logger).parse(filepath, filename)
        raw = self.parse_cert(filepath)

        return Cert(filename=file.get_file_name(),
                    size=file.get_size(),
                    md5hash=file.get_md5(),
                    sha1hash=file.get_sha1(),
                    sha256hash=file.get_sha256(),
                    sha512hash=file.get_sha512(),
                    serial_number=self.__parse_string(
                        raw, pattern=r"^Serial number: (.*)$"),
                    validity=self.parse_validity(raw),
                    fingerprint=self.parse_fingerprint(raw),
                    owner=self.parse_participant(raw,
                                                 pattern=r"^Owner: (.*)$"),
                    issuer=self.parse_participant(raw,
                                                  pattern=r"^Issuer: (.*)$"))
Ejemplo n.º 2
0
    def parse(self, filepath: str, filename: str) -> Dex:
        """
        :param filepath: path of the dex file
        :param filename: name of the dex file
        :return: the parsed dex file
        :raise: FileParsingError if cannot parse the file
        """
        self.logger.debug("Parsing dex file: filepath=\"%s\", filename=\"%s\"",
                          filepath, filename)
        file = FileParser(self.logger).parse(filepath, filename)

        self.logger.debug("Extracting strings...")
        strings = self.parse_strings(filepath)
        self.logger.debug("Strings extracted: %d", len(strings))

        self.logger.debug("Extracting URLs...")
        urls = self.parse_signatures(signature=UriSignature(),
                                     strings=strings,
                                     min_string_len=6)
        self.logger.debug("URLs extracted: %s ", len(urls))

        self.logger.debug("Extracting shell commands...")
        shell_commands = self.parse_signatures(signature=ShellSignature(),
                                               strings=strings)
        self.logger.debug("Shell commands extracted: %s", len(shell_commands))

        # TODO: improve custom signatures parsing performance (commented in the meanwhile because far too slow)
        # self.logger.debug("Extracting custom signatures...")
        custom_signatures = [
        ]  # self.extract_signatures(signature=Signature(), strings=self._strings)
        # self.logger.debug("Custom signatures extracted: %s", len(custom_signatures))

        return Dex(
            filename=file.get_file_name(),
            size=file.get_size(),
            md5hash=file.get_md5(),
            sha1hash=file.get_sha1(),
            sha256hash=file.get_sha256(),
            sha512hash=file.get_sha512(),
            strings=strings,
            urls=urls,
            shell_commands=shell_commands,
            custom_signatures=custom_signatures,
        )