[HN Gopher] Tweak: An Efficient Hex Editor ___________________________________________________________________ Tweak: An Efficient Hex Editor Author : hprotagonist Score : 58 points Date : 2021-02-26 18:29 UTC (4 hours ago) (HTM) web link (www.chiark.greenend.org.uk) (TXT) w3m dump (www.chiark.greenend.org.uk) | ridiculous_fish wrote: | I am the original author of Hex Fiend. Like Tweak, Hex Fiend uses | a BTree (actually a B+tree, which also cross-links nodes at the | same level, for easy iteration). Each interior node is annotated | with the amount of data contained in its subtree, so it is | possible to quickly find data at an offset. I think this is the | same as the author's idea. | | Hex Fiend has an additional trick: it can save files in-place | without needing additional disk space. It does this by computing | a dependency graph, and then writing chunks in topological order. | For example, say you have a 100 byte file, and the user inserts | 100 bytes at the beginning. We get a graph: | [100, 200) depends on [0, 100) [0, 100) from memory (no | dependencies) | | The topo sort means we'll write [100, 200) first, so its source | data is not overwritten. | | Here is Hex Fiend's B+tree: | https://github.com/HexFiend/HexFiend/blob/master/framework/s... | lifepillar wrote: | Thank you for making HexFiend, that's the top hex editor! | | One thing that I really really like about HexFiend is that | scrolling is very fast, yet precise and smooth, no matter the | size of the file. Is it based on custom classes? Scrolling in | macOS used to be quite ok up to several releases ago. Then it | became crappy, especially in some apps (AppleScript Editor | comes to my mind). | ridiculous_fish wrote: | Hex Fiend uses native Mac scrollbars, but manages its scroll | position itself. In Cocoa speak it uses NSScroller but not | NSScrollView. | jandrese wrote: | Nice. I'm personally not a fan of EMACS style control codes | everywhere, but I like the simple and straightforward interface. | nielsbot wrote: | For a Mac GUI app, try Hexfiend: https://hexfiend.com. (App store | link: https://apps.apple.com/us/app/hex-fiend/id1342896380?mt=12) | heyoni wrote: | That thing is the best. I don't understand exactly how it | works, but it can handle files up to any size without breaking | a sweat. | ttt0 wrote: | You don't have to load the entire file to RAM, you can read | just parts of it. | keehun wrote: | While chunking data, it's non-trivial to handle fast | scrolling and populating the scrollbars with the correct | size of what the eventual size would be. | comex wrote: | Non-trivial for sure. But much easier with a hex editor | than with, say, a standard text editor. No need to guess | how many lines some text takes up due to word wrapping; | no need to even search for newlines. There's a fixed | number of bytes per row, and a fixed row height, so | mapping between byte offset, line number, and pixel | y-position is just a matter of multiplying and dividing. | keehun wrote: | Agree. Nothing to argue there. | ttt0 wrote: | I might be wrong, but I believe the fastest way is to | seek to the end of file and that way you can get the | total file size. Or use like fstat or something | | Maybe scrolling is non trivial, but there is definitely a | lot of room for optimizations. You could store large | chunks in memory and populate them asynchronously with | smaller chunks from file for example. | | edit: I completely missed the point with the size, | comex's answer is way better | shaicoleman wrote: | Tweak misses the following things I expect in a hex editor: | | * No help screen to show the hotkeys | | * Changes aren't highlighted | | * Hotkeys are unintuitive unless you use Emacs (less than 5% of | users [1]) | | * No undo/redo | | * No search | | * No option for decimal offsets/size | | I've tried dozens of hex editors: | | * hexedit [2] is the best option for Linux, despite it being web | based. | | * dhex [3] is probably the best option for the terminal, but not | great. | | * HxD [4] is great if you're on Windows | | 1. | https://insights.stackoverflow.com/survey/2019#development-e... | | 2. https://hexed.it/ | | 3. https://www.dettus.net/dhex/ | | 4. https://mh-nexus.de/en/hxd/ | tyingq wrote: | Screenshot of it editing itself, in case someone wants to know | what it looks like: https://imgur.com/a/lndAWbm ___________________________________________________________________ (page generated 2021-02-26 23:00 UTC)