# Path: cemu/utils.py
# def hexdump(source: bytearray, length: int=0x10, separator: string='.', show_raw: bool=False, base: int=0x00) -> string:
#     """
#     Produces a `hexdump` command like output version of the bytearray given.
#     """
#     result = []
#     for i in range(0, len(source), length):
#         s = source[i:i+length]
# 
#         hexa = ' '.join(["%02X" % c for c in s])
#         text = ''.join( [chr(c) if 0x20 <= c < 0x7F else separator for c in s] )
# 
#         if show_raw:
#             result.append(hexa)
#         else:
#             result.append( "%#-.*x   %-*s  %s" % (16, base+i, 3*length, hexa, text) )
# 
#     return '\n'.join(result)


from PyQt5.QtWidgets import (
    QVBoxLayout,
    QHBoxLayout,
    QWidget,
    QDockWidget,
    QLineEdit,
    QTextEdit,
    QFrame,
    QLabel,
)
from PyQt5.QtGui import(
    QFont,
)
from PyQt5.QtCore import(
    QFileInfo,
    pyqtSignal,
    QEvent
)
from cemu.utils import hexdump
import unicorn
        # define signals
        self.refreshMemoryEditorSignal.connect(self.onRefreshMemoryEditor)
        self.root.signals["refreshMemoryEditor"] = self.refreshMemoryEditorSignal
        return


    def updateEditor(self) -> None:
        emu = self.root.emulator
        if not emu.is_running:
            self.__editor.setText("VM not running")
            return

        value = self.address.text()
        if value.lower().startswith("0x"):
            value = value[2:]

        if value.startswith("@"):
            # if the value of the "memory viewer" field starts with @.<section_name>
            try:
                addr = emu.lookup_map(value[1:])
            except KeyError:
                return

        elif value.startswith("$"):
            # if the value of the "memory viewer" field starts with $<register_name>
            reg_name = value[1:].upper()
            if reg_name not in emu.arch.registers:
                return
            addr = emu.get_register_value(reg_name)
            if addr is None:

# Path: cemu/utils.py
# def hexdump(source: bytearray, length: int=0x10, separator: string='.', show_raw: bool=False, base: int=0x00) -> string:
#     """
#     Produces a `hexdump` command like output version of the bytearray given.
#     """
#     result = []
#     for i in range(0, len(source), length):
#         s = source[i:i+length]
# 
#         hexa = ' '.join(["%02X" % c for c in s])
#         text = ''.join( [chr(c) if 0x20 <= c < 0x7F else separator for c in s] )
# 
#         if show_raw:
#             result.append(hexa)
#         else:
#             result.append( "%#-.*x   %-*s  %s" % (16, base+i, 3*length, hexa, text) )
# 
#     return '\n'.join(result)


# Path: cemu/ui/memory.py
from PyQt5.QtWidgets import (
    QVBoxLayout,
    QHBoxLayout,
    QWidget,
    QDockWidget,
    QLineEdit,
    QTextEdit,
    QFrame,
    QLabel,
)
from PyQt5.QtGui import(
    QFont,
)
from PyQt5.QtCore import(
    QFileInfo,
    pyqtSignal,
    QEvent
)
from cemu.utils import hexdump
import unicorn

        # define signals
        self.refreshMemoryEditorSignal.connect(self.onRefreshMemoryEditor)
        self.root.signals["refreshMemoryEditor"] = self.refreshMemoryEditorSignal
        return


    def updateEditor(self) -> None:
        emu = self.root.emulator
        if not emu.is_running:
            self.__editor.setText("VM not running")
            return

        value = self.address.text()
        if value.lower().startswith("0x"):
            value = value[2:]

        if value.startswith("@"):
            # if the value of the "memory viewer" field starts with @.<section_name>
            try:
                addr = emu.lookup_map(value[1:])
            except KeyError:
                return

        elif value.startswith("$"):
            # if the value of the "memory viewer" field starts with $<register_name>
            reg_name = value[1:].upper()
            if reg_name not in emu.arch.registers:
                return
            addr = emu.get_register_value(reg_name)
            if addr is None:

                return