How to use the gilgamesh.repl.print_html 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
s.append("\n")
                s.append("${:06X} │ ".format(i))

            for j, b in enumerate(self.rom.read(i, step_int)):
                color = (
                    "yellow"
                    if self.log.find_instruction(i + j) is not None
                    else colors[color_idx % len(colors)]
                )
                s.append("<{}>{:02X}".format(color, b, color))

            s.append(" ")
            color_idx += 1

        s.append("\n")
        print_html("".join(s))
github AndreaOrru / gilgamesh / gilgamesh / app.py View on Github external
def do_disassembly(self) -> None:
        """Show disassembly of selected subroutine."""
        if not self.subroutine:
            raise GilgameshError("No selected subroutine.")
        disassembly = SubroutineDisassembly(self.subroutine)
        print_html(disassembly.get_html())
github AndreaOrru / gilgamesh / gilgamesh / app.py View on Github external
instr_pc, suggestion[1]
                            )
                            made_suggestion = True
                        elif (
                            suggestion[0] == "subroutine" and suggestion[1] is not None
                        ):
                            self.log.assert_subroutine_state_change(
                                sub, instr_pc, suggestion[1]
                            )
                            made_suggestion = True
            if not made_suggestion:
                break

        new_suspect = self.log.n_suspect_subroutines - n_suspect
        if new_suspect > 0:
            print_html(
                f"Discovered {new_suspect} new suspect subroutine(s).\n"  # noqa
            )
github AndreaOrru / gilgamesh / gilgamesh / app.py View on Github external
def _do_load(self) -> bool:
        try:
            with open(self.rom.glm_path, "rb") as f:
                data = pickle.load(f)
            self.log.load(data)
            self.subroutine_pc = data["current_subroutine"]
        except OSError:
            return False
        else:
            print_html(f'"{self.rom.glm_name}" loaded successfully.\n')
            return True
github AndreaOrru / gilgamesh / gilgamesh / app.py View on Github external
def do_jumptable_preview(self, caller_pc: str, range_expr: str) -> None:
        """Preview the branches of a jumptable without affecting the analysis."""

        def gather_targets(caller_pc: int, target_pc: int, x: int) -> None:
            target_pcs.append(target_pc)

        target_pcs: List[int] = []
        self._do_jumptable_op(gather_targets, caller_pc, range_expr)

        caller_pc_int = self._label_to_pc(caller_pc)
        caller = self.log.any_instruction(caller_pc_int)
        disassemblies = self._print_preview_many(target_pcs, str(caller.state))
        separator = "\n\n\n{}".format(ROMDisassembly.HEADER)
        print_html(separator.join(disassemblies))
github AndreaOrru / gilgamesh / gilgamesh / app.py View on Github external
def save() -> None:
            data: Dict[str, Any] = {
                **self.log.save(),
                "current_subroutine": self.subroutine_pc,
            }
            with open(self.rom.glm_path, "wb") as f:
                pickle.dump(data, f, pickle.DEFAULT_PROTOCOL)
            print_html(f'"{self.rom.glm_name}" saved successfully.\n')
github AndreaOrru / gilgamesh / gilgamesh / app.py View on Github external
try:
                        sub = "{:16}".format(subroutine.label + ":")
                    except KeyError:
                        sub = "${:06X}{:5}".format(sub_pc, "")
                    s.append("{}  {}".format("\n" if last_sub else "", sub))
                else:
                    s.append("  {:16}".format(""))

                instruction = subroutine.instructions[instr_pc]
                code = self._print_instruction(instruction)
                s.append(f"  ${instr_pc:06X}  {code}-> ")
                s.append(self._print_state_change(change, show_asserted=False))

                last_sub = subroutine

        print_html("".join(s))
github AndreaOrru / gilgamesh / gilgamesh / app.py View on Github external
def do_analyze(self) -> None:
        """Run the analysis on the ROM."""
        n_suspect = self.log.n_suspect_subroutines
        self.log.analyze()

        new_suspect = self.log.n_suspect_subroutines - n_suspect
        if new_suspect > 0:
            print_html(
                f"Discovered {new_suspect} new suspect subroutine(s).\n"  # noqa
            )
github AndreaOrru / gilgamesh / gilgamesh / app.py View on Github external
s, last_sub = [], None
        for instr_pc, sub_pc in references:
            subroutine = self.log.subroutines[sub_pc]
            instruction = subroutine.instructions[instr_pc]
            disassembly = SubroutineDisassembly(subroutine)
            if not last_sub or sub_pc != last_sub.pc:
                s.append(
                    "{}{:16}".format(
                        "\n" if last_sub else "", subroutine.label + ":"
                    )
                )
            else:
                s.append("{:16}".format(""))
            s.append(disassembly.get_instruction_html(instruction))
            last_sub = subroutine
        print_html("".join(s))