示例#1
0
    def init(self):
        """Initialize."""

        init_status = False
        self.address_done = False
        self.total_bytes = 0
        self.address = []
        self.selected_bytes = []
        self.hex_lower = common.use_hex_lowercase()

        # Get Seetings from settings file
        group_size = self.view.settings().get("hex_viewer_bits", None)
        self.inspector_enabled = common.hv_settings("inspector", False)
        self.throttle = common.hv_settings("highlight_throttle", THROTTLING)
        self.max_highlight = common.hv_settings("highlight_max_bytes", MAX_HIGHIGHT)
        self.bytes_wide = self.view.settings().get("hex_viewer_actual_bytes", None)
        self.highlight_scope = common.hv_settings("highlight_scope", HIGHLIGHT_SCOPE)
        self.highlight_icon = common.hv_settings("highlight_icon", HIGHLIGHT_ICON)
        self.enable_fake_hex = common.hv_settings("enable_fake_hex_file", True)
        style = common.hv_settings("highlight_style", HIGHLIGHT_STYLE)

        if (group_size is None or self.bytes_wide is None) and self.enable_fake_hex:
            m = re.match(r'([\da-z]{8}):[\s]{2}((?:[\da-z]+[\s]{1})*)\s*\:[\w\W]*', self.view.substr(self.view.line(0)))
            if m is not None:
                starting_address = int(m.group(1), 16)
                hex_chars = m.group(2).split(' ')
                group_size = (len(hex_chars[0]) / 2) * 8
                self.bytes_wide = (len(hex_chars[0]) / 2) * (len(hex_chars) - 1)
                self.view.settings().set("hex_viewer_bits", group_size)
                self.view.settings().set("hex_viewer_actual_bytes", self.bytes_wide)
                self.view.settings().set("hex_viewer_fake", True)
                self.view.settings().set("hex_viewer_starting_address", starting_address)
                self.view.set_read_only(True)
                self.view.set_scratch(True)
                if common.hv_settings("inspector", False) and common.hv_settings("inspector_auto_show", False):
                    self.view.window().run_command("hex_show_inspector")

        # No icon?
        if self.highlight_icon == "none":
            self.highlight_icon = ""

        # Process highlight style
        self.highlight_style = 0
        if style == "outline":
            self.highlight_style = sublime.DRAW_OUTLINED
        elif style == "none":
            self.highlight_style = sublime.HIDDEN
        elif style == "underline":
            self.highlight_style = sublime.DRAW_EMPTY_AS_OVERWRITE

        # Process hex grouping
        if group_size is not None and self.bytes_wide is not None:
            self.group_size = group_size / common.BITS_PER_BYTE
            self.hex_char_range = common.get_hex_char_range(self.group_size, self.bytes_wide)
            init_status = True
        return init_status
示例#2
0
    def init(self):
        """Initialize."""

        init_status = False
        self.address_done = False
        self.total_bytes = 0
        self.address = []
        self.selected_bytes = []
        self.hex_lower = common.use_hex_lowercase()

        # Get Seetings from settings file
        group_size = self.view.settings().get("hex_viewer_bits", None)
        self.inspector_enabled = common.hv_settings("inspector", False)
        self.throttle = common.hv_settings("highlight_throttle", THROTTLING)
        self.max_highlight = common.hv_settings("highlight_max_bytes", MAX_HIGHIGHT)
        self.bytes_wide = self.view.settings().get("hex_viewer_actual_bytes", None)
        self.highlight_scope = common.hv_settings("highlight_scope", HIGHLIGHT_SCOPE)
        self.highlight_icon = common.hv_settings("highlight_icon", HIGHLIGHT_ICON)
        self.enable_fake_hex = common.hv_settings("enable_fake_hex_file", True)
        style = common.hv_settings("highlight_style", HIGHLIGHT_STYLE)

        if (group_size is None or self.bytes_wide is None) and self.enable_fake_hex:
            m = re.match(r'([\da-z]{8}):[\s]{2}((?:[\da-z]+[\s]{1})*)\s*\:[\w\W]*', self.view.substr(self.view.line(0)))
            if m is not None:
                starting_address = int(m.group(1), 16)
                hex_chars = m.group(2).split(' ')
                group_size = (len(hex_chars[0]) / 2) * 8
                self.bytes_wide = (len(hex_chars[0]) / 2) * (len(hex_chars) - 1)
                self.view.settings().set("hex_viewer_bits", group_size)
                self.view.settings().set("hex_viewer_actual_bytes", self.bytes_wide)
                self.view.settings().set("hex_viewer_fake", True)
                self.view.settings().set("hex_viewer_starting_address", starting_address)
                self.view.set_read_only(True)
                self.view.set_scratch(True)
                if common.hv_settings("inspector", False) and common.hv_settings("inspector_auto_show", False):
                    self.view.window().run_command("hex_show_inspector")

        # No icon?
        if self.highlight_icon == "none":
            self.highlight_icon = ""

        # Process highlight style
        self.highlight_style = 0
        if style == "outline":
            self.highlight_style = sublime.DRAW_OUTLINED
        elif style == "none":
            self.highlight_style = sublime.HIDDEN
        elif style == "underline":
            self.highlight_style = sublime.DRAW_EMPTY_AS_OVERWRITE

        # Process hex grouping
        if group_size is not None and self.bytes_wide is not None:
            self.group_size = group_size / common.BITS_PER_BYTE
            self.hex_char_range = common.get_hex_char_range(self.group_size, self.bytes_wide)
            init_status = True
        return init_status
示例#3
0
    def run(self):
        """Run command."""

        self.view = self.window.active_view()

        # Identify view
        if self.handshake != -1 and self.handshake == self.view.id():
            self.reset()
        self.handshake = self.view.id()

        # Single selection?
        if len(self.view.sel()) == 1:
            # Init
            if not self.init():
                self.reset()
                return
            sel = self.view.sel()[0]
            start = sel.begin()
            end = sel.end()
            num_bytes = 0

            # Get range of hex data
            line = self.view.line(start)
            range_start = line.begin() + common.ADDRESS_OFFSET
            range_end = range_start + common.get_hex_char_range(self.group_size, self.bytes_wide)
            hex_range = sublime.Region(range_start, range_end)

            if self.view.score_selector(start, "comment"):
                start, end, num_bytes = self.ascii_to_hex(start, end)

            # Determine if selection is within hex range
            if start >= hex_range.begin() and end <= hex_range.end():
                # Adjust beginning of selection to begining of first selected byte
                if num_bytes == 0:
                    start, end, num_bytes = common.adjust_hex_sel(self.view, start, end, self.group_size)

                # Get general line info for diffing and editing
                if num_bytes != 0:
                    self.ascii_pos = hex_range.end() + common.ASCII_OFFSET
                    self.total_bytes = num_bytes
                    self.start_pos = start
                    self.end_pos = end + 1
                    selection = self.view.substr(sublime.Region(start, end + 1))
                    self.line = {
                        "range": line,
                        "address": self.view.substr(sublime.Region(line.begin(), line.begin() + common.ADDRESS_OFFSET)),
                        "selection": selection.replace(" ", ""),
                        "data1": self.view.substr(sublime.Region(hex_range.begin(), start)).replace(" ", ""),
                        "data2": self.view.substr(sublime.Region(end + 1, hex_range.end() + 1)).replace(" ", "")
                    }

                    # Send selected bytes to be edited
                    self.edit_panel(selection.strip())
示例#4
0
    def run(self):
        """Run command."""

        self.view = self.window.active_view()

        # Identify view
        if self.handshake != -1 and self.handshake == self.view.id():
            self.reset()
        self.handshake = self.view.id()

        # Single selection?
        if len(self.view.sel()) == 1:
            # Init
            if not self.init():
                self.reset()
                return
            sel = self.view.sel()[0]
            start = sel.begin()
            end = sel.end()
            num_bytes = 0

            # Get range of hex data
            line = self.view.line(start)
            range_start = line.begin() + common.ADDRESS_OFFSET
            range_end = range_start + common.get_hex_char_range(self.group_size, self.bytes_wide)
            hex_range = sublime.Region(range_start, range_end)

            if self.view.score_selector(start, "comment"):
                start, end, num_bytes = self.ascii_to_hex(start, end)

            # Determine if selection is within hex range
            if start >= hex_range.begin() and end <= hex_range.end():
                # Adjust beginning of selection to begining of first selected byte
                if num_bytes == 0:
                    start, end, num_bytes = common.adjust_hex_sel(self.view, start, end, self.group_size)

                # Get general line info for diffing and editing
                if num_bytes != 0:
                    self.ascii_pos = hex_range.end() + common.ASCII_OFFSET
                    self.total_bytes = num_bytes
                    self.start_pos = start
                    self.end_pos = end + 1
                    selection = self.view.substr(sublime.Region(start, end + 1))
                    self.line = {
                        "range": line,
                        "address": self.view.substr(sublime.Region(line.begin(), line.begin() + common.ADDRESS_OFFSET)),
                        "selection": selection.replace(" ", ""),
                        "data1": self.view.substr(sublime.Region(hex_range.begin(), start)).replace(" ", ""),
                        "data2": self.view.substr(sublime.Region(end + 1, hex_range.end() + 1)).replace(" ", "")
                    }

                    # Send selected bytes to be edited
                    self.edit_panel(selection.strip())