Your hex editor should color-code bytes

(simonomi.dev)

143 points | by tobr 2 days ago

24 comments

  • dspillett 2 hours ago
    Everything should try do some basic syntax highlighting IMO. Not too much, or it just becomes a sea of formatting that doesn't help at all. It is surprising how much difference just a little splash of colour can make if it isn't overdone. If possible, always include configuration options for the user though, so those with colour-blindness issues can tweak things to their needs, those who are just fussy can make the output fit with their finely adjusted system-wide colour schemes¹, and even better, where you can, allow bold/italic/other as well as colours so that those who barely see colour at all can play too.

    Of course none of this helps those using screen-readers and other tech, so make sure that all your fancy colouring & such is additive so if it is all “lost” no meaning is absolutely lost with it.

    --------

    [1] Some people can be very vocal about this, more so than if highlighting isn't possible at all. If you give any output formatting they'll expect you to match, or be able to be made to match, their preferred style.

    • PunchyHamster 1 minute ago
      As long as you just give people list of settings for colors, they can pick as much color or monochrome as they want.

      So by all means "color everything", people have different opinions on what they want colored so give them option

    • finaard 33 minutes ago
      I'd recommend for every developer to get one or more colourblind friends. I have some, and regularly send them screenshots of what I'm working on to get feedback what they can see and what they can read/can't read.

      They've been absolutely invaluable for making sure their kind of people can't use my apps properly.

      • gortok 5 minutes ago
        8% of the male population has some form of colorblindness (for women it’s around 0.5%). I have deuteranomaly colorblindness. If you search for images on the internet related to that type of colorblindness you’ll find representations of how we see color and how we see the world.

        It is not a fun condition to have, and leads to lots of problems in my everyday life. This blog post accidentally accentuated that issue, since the colors are (to what I can understand) very similar looking to me as a colorblind person.

        1 in 12 men and 1 in 200 women go through the same sorts of experiences, and it’s worth it, if you aren’t color deficient, to try out some of the colorblindness sites and see the world as we do.

        https://www.colourblindawareness.org/colour-blindness/colour...

  • cuechan 51 minutes ago
    For anyone who regularly has to look at/analyze binary files, i highly recommend ImHex [1].

    Its a hex editor built with imgui and has a lot of built in tools. Imo the best feature is the data structure editor. You can write a data type definition similar to C and it overlays it on the hexdump and parses it in a structured way while you type.

    It also has a node based editor.

    1: https://github.com/WerWolv/ImHex

  • PunchyHamster 2 minutes ago
    I wonder how hard it would be to color code repeating sequences
  • roelschroeven 45 minutes ago
    When you're going to color-code bytes in a hex dump, I would expect each ASCII character in the right column to have the same color as the hex byte in the left column, making it easier to pair them. I wonder why that wasn't done here.
  • delta_p_delta_x 1 hour ago

      > Your hex editor should colour-code bytes so it is easier for users to distinguish patterns
      > Article is fully in lowercase, which makes it harder for readers to make out sentences and the flow of the article
      > mfw the irony
    • gblargg 44 minutes ago
      The text smashed up to the left border doesn't help either.
  • nticompass 25 minutes ago
    I used to use wxHexEditor and that had a feature where I could select a section of the file and highlight it in a color. When I was working to decode a certain file format, I used that to color-code different sections of the file and it was super useful. Those color-codes were stored in a separate file so you could load them back in.
  • NooneAtAll3 54 minutes ago
    Why did author decide that best way to demonstrate his idea would be by cutting contrast in half?

    color-coding might be a great solution, but you don't really know beforehand which byte values are important. Manually selecting C0 to make it stand out it just ctrl+f with extra steps. (But I wouldn't mind something like "color 00 separate from ascii separate from the rest)

    • seszett 50 minutes ago
      > Manually selecting C0 to make it stand out

      That's not what they did, actually. C0 is the only byte in there that's above 3F or so, and it's far from it. Hence the very different colour, and the lack of contrast between the colours of the other bytes.

  • kokakiwi 50 minutes ago
    ImHex (https://imhex.werwolv.net/) is also a really nice Hex editor with tons of plugins (patterns, file support, etc.) and even an embedded language for adding more patterns easily
  • ChrisRR 13 minutes ago
    What a bad way to illustrate your point by using such similar looking pastel colours
  • Archelaos 2 hours ago
    This article made me think how I could use similar techinques to colour code the data in database tables. Has anyone here tried that and has some recommendations where to start, etc.?
  • bandrami 3 hours ago
    Emacs's hexl-mode does this, incidentally, though annoyingly by default it makes all faces the same color. I never understood why it defines the faces but then doesn't customize them.
  • red_admiral 48 minutes ago
    My hex editor should let me turn syntax highlighting on and off; follow my personal color theme (and not produce light gray on white in the terminal); and let me highlight specific things I'm searching for like OD OA or FF FE.
  • psychoslave 2 hours ago
    That said, even colored these dumps still feels unappealing to me — so yes this is admittedly subjective gut jumping in the conversation. I get that occult form can also be an attractive force.

    The post put on the table an interesting point about how to improve the presentation layer to fit what’s human cognition is good at spotting (in general, or at least for the expected audience with some training). And it does start proposing something with these color schemes. But isn’t it kind of missing the forest for the tree? Actually why do we even have rendering with [012345678ABCDEF], when a specific set of (colored/imaged?) glyphs would be able to make more obvious what’s on the table? Or even beyond the hexadecimal grouping, wouldn’t be more relevant to render something "intuitively" far more easy to grap without several layer of internalized interpretation through acculturation?

    • GuB-42 1 hour ago
      I can't think of anything better than a hex dump for representing raw binary data. I don't mean that there are no others, equally good representations, but hex dumps win because of familiarity.

      Of course, if you know about the format, there are better ways, but it goes beyond the scope of a hex editor, though the most advanced ones support things like template files and can display structured data, disassembly, etc...

    • q3k 58 minutes ago
      > Actually why do we even have rendering with [012345678ABCDEF], when a specific set of (colored/imaged?) glyphs would be able to make more obvious what’s on the table?

      Most of us have internalized the relationship between digits in [0-9] for a very long time. Adding 6 more glyphs after that is quite easy (and they're also somewhat well known in the world), and after a while you stop even thinking about the glyphs consciously anyway. A hex 'C' intuitively means to me '4 from the end'. A hex 'F' intuitively means to me 'all 4 bits are set to 1'. I don't see any advantage to switching to a different glyph set for this base, other than disruption for disruption's sake.

      > Or even beyond the hexadecimal grouping, wouldn’t be more relevant to render something "intuitively" far more easy to grap without several layer of internalized interpretation through acculturation?

      Modern computers deal with 8-bit bytes, and their word sizes are a multiple of bytes - unless you're dealing with bit-packed data, which is comparatively rare (closest is bit twiddling of MMIO registers, which is when you sometimes switch to binary; although for a 4-bit hex nibble you can still learn arbitrary combinations of bits on/off into its value).

      This means you can group 8 bits into 1 digits of 8 bits as one glyph (alphabet too large to be useful), 2 digits of 4 (hex), 4 digits of 2 (alphabet too small to give a benefit over binary) and 8 digits of 1 (binary). Hex just works really well as a practical middle ground.

      Back when computers used 12 bit words (PDP-8 and friends) octal (4 digits of 3 bits represented in the 0-7 alphabet) was more popular.

      • js8 23 minutes ago
        I thought about a similar concept for fun - each hex digit was replaced by 4x4 pixel matrix, where amount of pixels roughly corresponded to the value. So dot for 0, two dots for 1, checkerboard for 8 etc.

        Then byte was represented as 16x16 matrix where each 4x4 area had the lower digit pattern, and these were arranged in the shape of the higher digit.

        But at the end of the day, it wasn't really more readable.

  • js8 3 hours ago
    I think semantic coloring (based on structure) is more useful. Also (can't help as someone working with z/OS), if you really want to make hex output readable, I recommend using big-endian machine.
  • xyx0826 2 hours ago
    If you analyze binary files often, I highly recommend binvis - http://binvis.io/. It creates a colored minimap for files it loads and has two available arrangements. Pixel color is based on range of bytes, eg ASCII/null bytes/FF bytes. Besides, it’s a pretty basic hex viewer that runs in your browser. The minimap is extremely powerful for identifying interesting areas and patterns in unknown data.
    • pratyahava 1 hour ago
      > it’s a pretty basic hex viewer that runs in your browser

      excuse me? "basic" and "runs in your browser" together sound very contradictory to me. while doing things i actually feel (yes, emotionally) much better when there is no browser open on my machine, but only text editors, vcs gui and file managers, and terminals of course. and sometimes i reject an idea to start a browser just thinking how much ram it will take (ha, what a progress we have done - one github issue tab, with text only and no images, takes 180mb of ram).

      • franga2000 1 hour ago
        It's basic bause it does like two things. It's not advanced or complex. HN is also a basic forum, even though it runs in a browser.
  • azalemeth 2 hours ago
    I really like hexyl [1], which does this by default.

    https://github.com/sharkdp/hexyl

    • kqr 2 hours ago
      The author uses hexyl as an example of trying, but not doing it right.
  • greatgib 1 hour ago
    To me the random colors at each byte is messing up with my brain making it hard to fast identify C0 or any other value that I could more easily identify in all black.

    But color would be nice more based on the bytes logic.

    Eventually the 00 in a shaded grey instead of black, and in best case scenario by logic unit based on your protocol. And worst case scenario by groups of words or so.

  • asibahi 2 hours ago
    When I read this article a few days ago it inspired me to create my own hex viewer : https://ar-ms.me/thoughts/3sl-a-sweet-hex-utility/

    The cool thing about it imo (outside of colors) is a `--windows` flag. Which separates the hex view into partitions: so `-w 2:-3:5` shows the first two bytes on a line, then skips three bytes, then shows the next 5 bytes on a line, then the rest of the file. Easy to use combined with a terminal's up arrow.

  • adv_zxy 1 hour ago
    radare2 also has excellent hex viewing/editing support, if one manages to grok the usage of it.
  • a_t48 3 hours ago
    I've started doing this with hashes in a CLI I'm working on. For slow prints, it's somewhat helpful https://asciinema.org/a/aD38Pk88CZgSZqtq but for debug dumps with many many hashes it really helps readability and tracking hashes across lines.
  • ralferoo 48 minutes ago
    I actually stopped reading after the intro because I fundamentally disagreed with its premise. The "find the C0" took me about 1/4 second with uncoloured. Looking at the coloured took my eyes about 3 seconds to recover from the colour overload, then I was scanning down and found the colours so distracting with the constant switching between orange, pink and yellows than it took me a total of about 5 seconds to scan down as far as the blue C0. Maybe if it was all uncoloured and blue just for that, I might have actually noticed it looking different earlier.

    It's been a while since I used hexedit on Linux, but I think that highlighted search results in reverse colours, just like less does for text search. Personally, I'd prefer that to colours.

  • 7bit 1 hour ago
    > it’s much easier to pick out the unique byte when it’s a different color! human brains are really good at spotting visual patterns—given the right format

    Don't really see the advantage. Unique bytes have no unique meaning across data types.

    The only good syntax highlight to me is 00 and perhaps FF. But that's my opinion of course.

    Anything else that has no direct relation to what you're looking at is meaningless.

    • masklinn 46 minutes ago
      > The only good syntax highlight to me is 00 and perhaps FF. But that's my opinion of course.

      Would probably make the most sense to have various ranges you can enable depending on what you’re looking for (or to look for patterns) e.g. for single byte coloration I could see

      - nul

      - printable / non-printable ascii

      - non-ascii

      - UTF8 leading / continuation

      - separators

      - start/end pairs (both printable and non printable)

    • gblargg 48 minutes ago
      It would be interesting to do a heat map coloring based on frequency of that value.
  • samzong_ 2 hours ago
    [dead]