How to use the gilgamesh.repl.command function in gilgamesh

To help you get started, we’ve selected a few gilgamesh examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AndreaOrru / gilgamesh / gilgamesh / app.py View on Github external
    @command(container=True)
    def do_list(self) -> None:
        """List various types of entities."""
        ...
github AndreaOrru / gilgamesh / gilgamesh / app.py View on Github external
    @command()
    @argument("label_or_pc", complete_label)
    def do_deassert_subroutine(self, label_or_pc: str) -> None:
        """Remove previously defined subroutine assertions."""
        if self.subroutine_pc is None:
            raise GilgameshError("No selected subroutine.")
        instr_pc = self._label_to_pc(label_or_pc)
        self.log.deassert_subroutine_state_change(self.subroutine_pc, instr_pc)
github AndreaOrru / gilgamesh / gilgamesh / app.py View on Github external
    @command()
    @argument("label_or_pc", complete_label)
    @argument("state_expr")
    def do_assert_subroutine(self, label_or_pc: str, state_expr: str) -> None:
        """Define a known processor return state for a given subroutine.

        STATE_EXPR can accept the following values:
          - "none"         -> The subroutine does not change the state.
          - "m=0" or "m=1" -> The subroutine changes the state of m to 0 or 1.
          - "x=0" or "x=1" -> The subroutine changes the state of x to 0 or 1.
          - "m=0,x=0"      -> The subroutine changes the state of m to 0 and x to 0.
          - "m=0,x=1"      -> The subroutine changes the state of m to 0 and x to 1.
          - "m=1,x=0"      -> The subroutine changes the state of m to 1 and x to 0.
          - "m=1,x=1"      -> The subroutine changes the state of m to 1 and x to 1."""
        if not self.subroutine:
            raise GilgameshError("No selected subroutine.")
        # TODO: check that pc is an instruction inside the subroutine.
github AndreaOrru / gilgamesh / gilgamesh / app.py View on Github external
    @command(container=True)
    def do_query(self) -> None:
        """Query the analysis log in various ways."""
        ...
github AndreaOrru / gilgamesh / gilgamesh / app.py View on Github external
    @command(container=True)
    def do_jumptable(self) -> None:
        """Manage jump tables."""
        ...
github AndreaOrru / gilgamesh / gilgamesh / app.py View on Github external
    @command()
    def do_list_assertions_instructions(self) -> None:
        """List all instruction assertions provided by the user."""
        if not self.log.instruction_assertions:
            return

        s = ["ASSERTED INSTRUCTION STATE CHANGES:\n"]
        for pc, change in self.log.instruction_assertions.items():
            subroutines = self.log.instruction_subroutines(pc)
            instruction = self.log.any_instruction(pc)
            disassembly = self._print_instruction(instruction)

            s.append("  ${:06X}  {}-> ".format(pc, disassembly))
            s.append(self._print_state_change(change))
            if subroutines:
                s.append(
                    "    {}\n".format(
github AndreaOrru / gilgamesh / gilgamesh / app.py View on Github external
    @command()
    def do_list_jumptables(self) -> None:
        if not self.log.jump_assertions:
            return

        s = []
        for pc, targets in self.log.jump_assertions.items():
            subroutines = self.log.instruction_subroutines(pc)
            instruction = self.log.any_instruction(pc)
            disassembly = self._print_instruction(instruction)

            s.append("  ${:06X}  {}\n".format(pc, disassembly))
            if subroutines:
                s.append(
                    "    {}\n".format(
                        ", ".join(s.label for s in subroutines)
                    )
github AndreaOrru / gilgamesh / gilgamesh / app.py View on Github external
    @command()
    @argument("opcode", complete_opcode)
    def do_describe(self, opcode: str):
        """Describe an opcode."""
        op = Op.__members__[opcode.upper()]
        description = descriptions[op] + "\n"
        print_html(description)
github AndreaOrru / gilgamesh / gilgamesh / app.py View on Github external
    @command()
    def do_list_subroutines_unknown(self) -> None:
        """List subroutines with unknown return states.

        Subroutines can be flagged with various symbols:
          [!] -> Suspect instructions
          [?] -> Stack manipulation
          [*] -> Jump table
          [∞] -> Recursion
          [+] -> Multiple return states"""
        s = []
        for subroutine in self.log.subroutines.values():
            if subroutine.has_unknown_return_state:
                s.append(self._print_subroutine(subroutine))
        print_html("".join(s))
github AndreaOrru / gilgamesh / gilgamesh / app.py View on Github external
    @command()
    def do_debug(self) -> None:
        """Debug Gilgamesh itself."""
        breakpoint()