Arnau478 / hevi

Hex viewer
https://arnau478.github.io/hevi/
GNU General Public License v3.0
56 stars 2 forks source link

Add a flag to aggressively interpret hex -> binary #39

Open GrayHatter opened 3 weeks ago

GrayHatter commented 3 weeks ago

Quite often I find myself reading a binary file into vim, editing it through xxd and trying to return that new hex text file back to binary. When I append into the middle of some data, it often breaks the counting, which breaks xxd. e.g.

starting with

00000000: 5468 6973 2069 7320 6120 6269 6e61 7279  This is a binary
00000010: 2066 696c 6520 7768 6572 6520 2d3e 3c2d   file where -><-
00000020: 2073 686f 756c 6420 636f 6e74 6169 6e20   should contain
00000030: 7468 6520 776f 7264 2068 6576 6920 0a    the word hevi .

editing to

00000000: 5468 6973 2069 7320 6120 6269 6e61 7279  This is a binary
00000010: 2066 696c 6520 7768 6572 6520 2d3e 68 6576 69 3c2d   file where -><-
00000020: 2073 686f 756c 6420 636f 6e74 6169 6e20   should contain
00000030: 7468 6520 776f 7264 2068 6576 6920 0a    the word hevi .

causes xdd to error instead of parsing the hex. I'd like to have a flag that would allow hevi to parse it, and generate the binary.

Bonus points if it could detect mistakes and output the formatting back to vim with the error inline where detected. Or it could return an error, and the result suggestion and require the user to approve/fix it.

Arnau478 commented 3 weeks ago

Editing/creating binaries was never the goal of hevi. That said, I think this use case doesn't interfere with the dump functionality. Thus, I am willing to consider implementing this. How would it work exactly? Would it have to parse the output format? What about flags like --offset/--no-offset? Those would make parsing difficult, although I guess we could use the | characters. So, a line would either be [offset] | <data> | [ascii] or <data> (for raw mode).

Also, from the example, I assume it should handle non-normalized lines (>16 bytes), am I right?