How to use gilgamesh - 10 common examples

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_memory(self, addr: str, size: str, step: str) -> None:
        """Show an hex view of a region of ROM, starting from
        ADDR and spanning SIZE bytes, in groups of STEP bytes."""

        def build_header(step: int) -> str:
            s = []
            for n in range(0, (16 // step) * step, step):
                s.append(f"{n:02X}")
            s.append("")
            return (" " * ((2 * step) - 1)).join(s)

        addr_int = self._label_to_pc(addr)
        size_int = int(size[1:] if size[0] == "$" else int(size))
        step_int = int(step)
        if step_int > 16:
            raise GilgameshError("Can only build groups up to 16 bytes.")

        s = []
        header = build_header(step_int)
        s += ["" + (" " * 8) + "│ "]
        s += [header]
        s += ["\n" + ("─" * 8) + "┼" + ("─" * len(header)) + "\n"]

        colors, color_idx = ["lightgrey", "cyan"], 0
        nl_threshold = (16 // step_int) * step_int

        for i in range(addr_int, addr_int + size_int, step_int):
            if (i - addr_int) % nl_threshold == 0:
                if i - addr_int:
                    s.append("\n")
                s.append("${:06X} │ ".format(i))
github AndreaOrru / gilgamesh / tests / test_state.py View on Github external
def test_state_expr(self):
        change = StateChange()
        self.assertEqual(str(change), "none")

        change = StateChange(m=0)
        self.assertEqual(str(change), "m=0")
        change = StateChange(x=1)
        self.assertEqual(str(change), "x=1")

        change = StateChange(m=0, x=1)
        self.assertEqual(str(change), "m=0,x=1")
github AndreaOrru / gilgamesh / tests / test_state.py View on Github external
def test_apply_inference(self):
        change = StateChange(m=1, x=1)
        inference = StateChange(m=1, x=None)

        change.apply_inference(inference)
        self.assertEqual(change.m, None)
        self.assertEqual(change.x, 1)
github AndreaOrru / gilgamesh / tests / test_state.py View on Github external
def test_repr(self):
        change = StateChange()
        self.assertEqual(repr(change), "")

        change = StateChange(unknown=True)
        self.assertEqual(repr(change), "")

        change = StateChange(m=1)
        self.assertEqual(repr(change), "")

        change = StateChange(m=1, x=1)
        self.assertEqual(repr(change), "")
github AndreaOrru / gilgamesh / tests / test_state.py View on Github external
def test_repr(self):
        change = StateChange()
        self.assertEqual(repr(change), "")

        change = StateChange(unknown=True)
        self.assertEqual(repr(change), "")

        change = StateChange(m=1)
        self.assertEqual(repr(change), "")

        change = StateChange(m=1, x=1)
        self.assertEqual(repr(change), "")
github AndreaOrru / gilgamesh / tests / test_state.py View on Github external
def test_from_state_expr(self):
        change = StateChange.from_expr("none")
        self.assertEqual(change, StateChange())

        change = StateChange.from_expr("m=0")
        self.assertEqual(change, StateChange(m=0))
        change = StateChange.from_expr("x=1")
        self.assertEqual(change, StateChange(x=1))

        change = StateChange.from_expr("m=0,x=1")
        self.assertEqual(change, StateChange(m=0, x=1))
        change = StateChange.from_expr("x=0,m=1")
        self.assertEqual(change, StateChange(x=0, m=1))
github AndreaOrru / gilgamesh / tests / test_log.py View on Github external
def test_assert_state_change(self):
        # Assertion.
        unknown = self.log.subroutines[0x800B]
        self.log.assert_subroutine_state_change(unknown, 0x800B, StateChange())
        self.assertTrue(self.log.dirty)
        self.log.analyze()
        self.assertFalse(self.log.dirty)

        reset = self.log.subroutines_by_label["reset"]
        unknown = self.log.subroutines[0x800B]

        self.assertIn(0x8005, reset.instructions)
        self.assertIn(0x8008, reset.instructions)
        self.assertTrue(unknown.indirect_jumps)
        self.assertTrue(unknown.has_asserted_state_change)
        self.assertFalse(unknown.has_unknown_return_state)

        # Deassertion.
        self.log.deassert_subroutine_state_change(0x800B, 0x800B)
        self.assertTrue(self.log.dirty)
github AndreaOrru / gilgamesh / tests / test_state.py View on Github external
def test_simplify(self):
        state = State(m=0, x=1)

        change = StateChange()
        self.assertEqual(change.simplify(state), StateChange())

        change = StateChange(m=0)
        self.assertEqual(change.simplify(state), StateChange())

        change = StateChange(m=0, x=1)
        self.assertEqual(change.simplify(state), StateChange())

        change = StateChange(m=0, x=0)
        self.assertEqual(change.simplify(state), StateChange(x=0))

        change = StateChange(unknown=True)
        self.assertEqual(change.simplify(state), StateChange(unknown=True))
github AndreaOrru / gilgamesh / tests / test_state.py View on Github external
def test_apply_inference(self):
        change = StateChange(m=1, x=1)
        inference = StateChange(m=1, x=None)

        change.apply_inference(inference)
        self.assertEqual(change.m, None)
        self.assertEqual(change.x, 1)
github AndreaOrru / gilgamesh / tests / test_state.py View on Github external
def test_from_state_expr(self):
        state = State.from_expr("m=0,x=1")
        self.assertEqual(state, State(m=0, x=1))

        state = State.from_expr("x=0,m=1")
        self.assertEqual(state, State(x=0, m=1))