How to use the gilgamesh.disassembly.SubroutineDisassembly 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
def do_edit(self) -> None:
        """Interactively edit the subroutine(s) using an external editor."""
        if not self.subroutine:
            raise GilgameshError("No selected subroutine.")
        disassembly = SubroutineDisassembly(self.subroutine)
        disassembly.edit()
        if self.log.dirty:
            self.do_analyze()
github AndreaOrru / gilgamesh / gilgamesh / app.py View on Github external
old_labels = set(self.log.subroutines_by_label.keys())
        saved_log = deepcopy(self.log.save())

        # Add the target pcs as entry point.
        for pc in target_pcs:
            label = self.log.preserved_labels.get(pc, f"sub_{pc:06X}")
            self.do_entrypoint(f"${pc:06X}", label, state_expr)
        # Execute the analysis again.
        self.log.analyze()
        new_labels = self.log.subroutines_by_label.keys() - old_labels

        # Get the disassembly of the target subroutines,
        # highlighting new undiscovered subroutines in red.
        for pc in target_pcs:
            subroutine = self.log.subroutines[pc]
            disassembly = SubroutineDisassembly(subroutine, new_labels)
            disassemblies.append(disassembly.get_html())

        # Restore previous log.
        self.log.load(saved_log)
        return disassemblies
github AndreaOrru / gilgamesh / gilgamesh / app.py View on Github external
def do_query_references(self, label_or_pc: str) -> None:
        """Given an address, list the instructions pointing to it."""
        pc = self._label_to_pc(label_or_pc)
        references = self.log.references[pc]

        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))
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())