def generate_registers(self, regs, outpath):
        try:
            regs = filters["no_access_mechanism"].filter_exclusive(regs)
            regs = transforms["remove_reserved_0"].transform(regs)
            regs = transforms["remove_reserved_1"].transform(regs)
            regs = transforms["remove_preserved"].transform(regs)
            regs = transforms["special_to_underscore"].transform(regs)
            regs = transforms["insert_valid_first_character"].transform(regs)

            logger.info("Generating C++ header file registers to: " + str(outpath))

            for reg in regs:
                include_guard = "PAL_" + reg.name.upper() + "_H"
                self.gadgets["pal.include_guard"].name = include_guard

                outfile_path = os.path.join(outpath, reg.name.lower() + ".h")
                outfile_path = os.path.abspath(outfile_path)

                with open(outfile_path, "w") as outfile:
                    self.gadgets["pal.cxx.namespace"].name = "pal"
                    self._generate_register(outfile, reg)

            self.gadgets["pal.cxx.namespace"].indent_contents = False

        except Exception as e:
            msg = "{g} failed to generate output {out}: {exception}".format(
                g=str(type(self).__name__),
                out=outpath,
                exception=e)
            raise PalGeneratorException(msg)
Beispiel #2
0
    def generate_registers(self, regs, outpath):
        try:
            for reg in regs:
                outfile = reg.name.lower() + ".yml"
                outfile_path = os.path.abspath(os.path.join(outpath, outfile))
                with open(outfile_path, "w") as outfile:
                    self._generate(outfile, reg)

        except Exception as e:
            msg = "{g} failed to generate output {out}: {exception}".format(
                g=str(type(self).__name__), out=outpath, exception=e)
            raise PalGeneratorException(msg)
Beispiel #3
0
    def generate(self, regs, outpath):
        try:
            outfile_path = os.path.abspath(os.path.join(outpath, "pal.h"))
            logger.info("Generating C Header: " + str(outfile_path))

            regs = transforms["remove_reserved_0"].transform(regs)
            regs = transforms["remove_reserved_1"].transform(regs)
            regs = transforms["remove_reserved_sign_extended"].transform(regs)
            regs = transforms["remove_implementation_defined"].transform(regs)
            regs = transforms["special_to_underscore"].transform(regs)
            regs = transforms["remove_redundant_am"].transform(regs)
            regs = transforms["remove_redundant_fields"].transform(regs)
            regs = transforms["unique_fieldset_names"].transform(regs)

            regs = filters["no_access_mechanism"].filter_exclusive(regs)

            if config.encoded_functions:
                msg = "Encoded accessors are only supported for aarch64 "
                msg += "registers (aarch32 and external not supported)"
                logger.warn(msg)
                regs = filters["aarch64"].filter_inclusive(regs)

            self.gadgets["pal.header_depends"].includes = [
                "<stdint.h>",
                "aarch32_gcc_accessor_macros.h",
                "aarch64_gcc_accessor_macros.h"
            ]

            unique = []
            for reg in regs:
                external_mechs = reg.access_mechanisms["ldr"] + \
                                 reg.access_mechanisms["str"]
                for mech in external_mechs:
                    if mech.component not in unique:
                        unique.append(mech.component)
            self.gadgets["pal.external_component"].components = unique

            with open(outfile_path, "w") as outfile:
                self._generate(outfile, regs)

        except Exception as e:
            msg = "{g} failed to generate output {out}: {exception}".format(
                g=str(type(self).__name__),
                out=outpath,
                exception=e)
            raise PalGeneratorException(msg)
Beispiel #4
0
    def generate(self, regs, outpath):
        try:
            regs = transforms["remove_reserved_0"].transform(regs)
            regs = transforms["remove_reserved_1"].transform(regs)
            regs = transforms["remove_reserved_sign_extended"].transform(regs)
            regs = transforms["remove_implementation_defined"].transform(regs)
            regs = transforms["special_to_underscore"].transform(regs)
            regs = transforms["insert_valid_first_character"].transform(regs)
            regs = transforms["remove_redundant_am"].transform(regs)
            regs = transforms["remove_redundant_fields"].transform(regs)
            regs = transforms["unique_fieldset_names"].transform(regs)

            regs = filters["no_access_mechanism"].filter_exclusive(regs)

            logger.info("Generating outputs to: " + str(outpath))

            for reg in regs:
                include_guard = "PAL_" + reg.name.upper() + "_H"
                self.gadgets["pal.include_guard"].name = include_guard
                self.gadgets["pal.header_depends"].includes = ["<stdint.h>"]

                if config.print_mechanism == "printf_utf8":
                    self.gadgets["pal.header_depends"].includes.extend(
                        ["<stdio.h>", "<inttypes.h>"])

                if config.access_mechanism == "libpal":
                    self.gadgets["pal.header_depends"].includes.extend([
                        "<libpal.h>",
                        "<string.h>",  # for memset
                    ])

                outfile_path = os.path.join(outpath, reg.name.lower() + ".h")
                outfile_path = os.path.abspath(outfile_path)

                with open(outfile_path, "w") as outfile:
                    self.gadgets["pal.cxx.namespace"].name = "pal"
                    self._generate_register(outfile, reg)

        except Exception as e:
            msg = "{g} failed to generate output {out}: {exception}".format(
                g=str(type(self).__name__), out=outpath, exception=e)
            raise PalGeneratorException(msg)
Beispiel #5
0
    def generate_instructions(self, instructions, outpath):
        try:
            logger.info("Generating C header file instructions to: " + str(outpath))

            for inst in instructions:
                include_guard = "PAL_EXECUTE_" + inst.name.upper() + "_H"
                self.gadgets["pal.include_guard"].name = include_guard

                outfile_path = os.path.join(outpath, inst.name.lower() + ".h")
                outfile_path = os.path.abspath(outfile_path)

                with open(outfile_path, "w") as outfile:
                    self._generate_instruction(outfile, inst)

        except Exception as e:
            msg = "{g} failed to generate output {out}: {exception}".format(
                g=str(type(self).__name__),
                out=outpath,
                exception=e)
            raise PalGeneratorException(msg)