[HN Gopher] Hexyl: A command-line hex viewer with colorized output ___________________________________________________________________ Hexyl: A command-line hex viewer with colorized output Author : hundredwatt Score : 122 points Date : 2023-06-16 16:56 UTC (6 hours ago) (HTM) web link (github.com) (TXT) w3m dump (github.com) | dang wrote: | Related: | | _Hexyl: A command-line hex viewer_ - | https://news.ycombinator.com/item?id=18865264 - Jan 2019 (113 | comments) | crabbone wrote: | Why would you need a _separate_ binary viewer / editor? | | This reminds me the absurd, but somehow common situation where | Java programmers in my office used IntelliJ IDEA to write Java, | but Notepad++ to view logs or edit INI files etc. | anamexis wrote: | Separate from what? | sitzkrieg wrote: | i do this. big heavy ide with project and debugger going full | blast. I might want to just pop open a log quickly and cba to | drag it into the IDE, np++ context menu done. more often tho, | reading logs on a non-main dev machine/vm/test/field | Conscat wrote: | Hexyl is what I love to use for quickly looking at a file. For | slightly more serious introspection I use Emacs' hexl-mode, which | also has basic editing capabilities. | jbaber wrote: | Hexyl's lovely and I copied its style for a hex editor. | | I don't understand why there are so many terminal hex viewers | that don't edit. | jmholla wrote: | What's your hex editor? | seanw444 wrote: | I'd also like to know. | CodeWriter23 wrote: | When I was coming up, we didn't have no dashed lines dividing the | displays into 8-byte segments. And color? Everything was orange | text on black. If you wanted green on black, you used a | coworker's terminal. | naikrovek wrote: | That's nice. | some_random wrote: | I love hexyl, but the colorized output does get in the way | sometimes when I'm copying out bytes | Pr0ject217 wrote: | Just out of curiosity (as I haven't needed to use a hex | viewer/editor in web dev) - what use-cases are you using this | for? | some_random wrote: | Reverse engineering! | Pr0ject217 wrote: | That sounds fun ;) | | Was there a first project you did that got you hooked? | some_random wrote: | Game hacking for sure, and it's still a blast. Playing | around with variables in cheat engine or messing with | save files is a fantastic way to get started as long as | you stick to single player games (multiplayer cheating is | way harder and usually unethical). | | https://cheatengine.org/ | camel-cdr wrote: | Does it handle files larger than memory? I've been using dhex for | that purpose. | jandrese wrote: | When you're only dumping a file memory use shouldn't be an | issue. It is the hex editors that run into memory problems. | camel-cdr wrote: | Ah, sorry, I didn't understand what this is for. | WalterBright wrote: | Here's mine, from 1986 or so. I still use it all the time: | #include <stdio.h> #define O1O printf #define OlO | putchar #define O10 exit #define Ol0 strlen | #define QLQ fopen #define OlQ fgetc #define O1Q | abs #define QO0 for typedef char lOL; | lOL*QI[] = {"Use:\012\011dump file\012","Unable to open file | '\x25s'\012", "\012"," ",""}; main(I,Il) | lOL*Il[]; { FILE *L; unsigned lO; | int Q,OL[' '^'0'],llO = EOF, | O=1,l=0,lll=O+O+O+l,OQ=056; lOL*llL="%2x "; | (I != 1<<1&&(O1O(QI[0]),O10(1011-1010))), ((L = | QLQ(Il[O],"r"))==0&&(O1O(QI[O],Il[O]),O10(O))); | lO = I-(O<<l<<O); while (L-l,1) { | QO0(Q = 0L;((Q &~(0x10-O))== l); | OL[Q++] = OlQ(L)); if (OL[0]==llO) break; | O1O("\0454x: ",lO); if (I == (1<<1)) | { QO0(Q=Ol0(QI[O<<O<<1]);Q<Ol0(QI[0]); | Q++)O1O((OL[Q]!=llO)?llL:QI[lll],OL[Q]);/*" | O10(QI[1O])*/ O1O(QI[lll]);{} | } QO0 (Q=0L;Q<1<<1<<1<<1<<1;Q+=Q<0100) | { (OL[Q]!=llO)? /* 0010 10lOQ 000LQL */ | ((D(OL[Q])==0&&(*(OL+O1Q(Q-l))=OQ)), | OlO(OL[Q])): | OlO(1<<(1<<1<<1)<<1); } | O1O(QI[01^10^9]); lO+=Q+0+l;} | } D(l) { return l>=' '&&l<='\~'; } | | I do like the colorized output of hexyl, though. | cornstalks wrote: | Was this for an obfuscated C challenge? | pmoriarty wrote: | Here's how Claude+[1] explained it: | | This program appears to be a hexadecimal dump utility. It | does the following: | | - It takes a filename as a command line argument and opens | that file for reading | | - It reads the file byte by byte until EOF | | - For each byte, it prints the hexadecimal value of the byte, | in the format "%2x " (i.e. 2 hex digits, a space) | | - After every 16 bytes, it prints the ASCII representation of | those bytes, replacing non-printable characters with "." | | - It also has some obfuscated logic with bitwise operations, | likely attempting to confuse the reader. | | So if you ran it like this: ./program | myfile.txt | | It would output something like: 54 65 78 74 | 20 66 69 6c 65 2e 0a 54 68 69 73 20 69 73 20 61 | 20 74 65 78 74 20 66 69 6c 65 2e 0a 54 68 65 | 20 71 75 69 63 6b 20 62 72 6f 77 6e 20 66 6f | 78 0a 6a 75 6d 70 73 20 6f 76 65 72 20 20 74 68 | 65 20 6c 61 7a 79 20 64 6f 67 0a 2e 2e 2e | | Which is the hexadecimal dump of the ASCII contents of | myfile.txt. | | The #defines are used to obfuscate the code and make it | harder to read, replacing printf with O1O, putchar with OlO, | etc. The D() function is used to check if a byte is a | printable ASCII character. | | So in summary, this program opens a file, reads it byte by | byte, prints the hex values, and prints the ASCII for | printable characters, as a hexadecimal dump utility. | | [1] - https://poe.com/Claude%2B | cornstalks wrote: | I'm well aware of how the code works. I was mostly | interested in _why_ it was written like that. nwiswell 's | comment[1] gave me the hint I needed to find that yes, this | was part of an obfuscated C challenge[2]. | | I know you mean well but LLMs are the very last resource | I'd turn to for help. Those things make crap up all the | time. | | [1]: https://news.ycombinator.com/item?id=36364283 | | [2]: https://www.ioccc.org/1986/bright/bright.c | WalterBright wrote: | > likely attempting to confuse the reader | | It's just ordinary C code. | throwaway675309 wrote: | Very obviously not. | | Nobody substitutes random three letter strings for | keywords in _ordinary C code_ unless they intend on some | trivial obfuscation. define O1O printf | #define OlO putchar #define O10 exit | #define Ol0 strlen #define QLQ fopen | #define OlQ fgetc #define O1Q abs #define | QO0 for typedef char lOL; | pmoriarty wrote: | After seeing an LLM do something like this, I've got to ask | people who think that LLMs are just "stochastic parrots", | "just predicting the next word", or are merely "a blurry | jpeg of the web" to think about what's really going on | here. | TheCleric wrote: | It didn't even answer the question though... | nwiswell wrote: | This exact code appears online as part of the IOCCC 1986 | (it was a submission), so it's likely that this was | indeed part of the training set for this LLM and that | there is a significant corpus of text discussing this | particular program and other obfuscated programs like it. | | I'm not ruling out that this LLM output is "partially | organic" rather than "fully regurgitated", but I'd be | much more interested to see this LLM explain an | obfuscated program that hasn't been floating around the | Internet for 35 years. | pmoriarty wrote: | It's easy to test it with something unpublished | faitswulff wrote: | Sharkdp is also responsible for some fantastic tools like | hyperfine for micro benchmarking, fd for finding files, bat which | is a colorized cat replacement and many more such utilities. | https://github.com/sharkdp is a real treasure trove of user- | friendly CLI tools. | 29athrowaway wrote: | burntsushi and sharkdp are the goats. | TacticalCoder wrote: | And both are members of HN! | fuzztester wrote: | I've used the XVI32 hex editor for Windows in the past. | | Written in Delphi. | | Split pane. | | Useful app. Free. | [deleted] | fuzztester wrote: | Get it here: | | http://www.chmaas.handshake.de/delphi/freeware/xvi32/xvi32.h... | | Just looked at it again. | | Has a lot of good features and positive comments. | | Including, "even used by Microsoft". | [deleted] | denysvitali wrote: | If you want a true Hex Editor (or better, Hex IDE), I strongly | suggest you to take a look ad ImHex [1]. | | [1]: https://github.com/WerWolv/ImHex | chx wrote: | Strongly related: is there a hex viewer where I can set , | preferably on-the-fly or with a command line switch record | delimiters so it colors the records? | naikrovek wrote: | how many different record separators do you have? | | ImHex may be useful to you if you only have a few. You can | write a pattern file which parses the whole file and displays | everything, if you want. | stusmall wrote: | I really like this tool for quick, easy debugging on binary | files. okteta used to be my go to, but it's rare I need editing. | I'm usually just take a quick look at the contents. | BlackLotus89 wrote: | Was looking at hexdump alternatives a week ago and between | huxdemp (hxd), xxd, hx, hd (not the alias for hexdump -C) and | hexdump this was my favourite. | | hx wasn't usable when parsing data streams... And clashes with | helix (hx) | | On systems where I can't install anything I would just use | hexdump -C or xxd | denysvitali wrote: | I've created an xxd clone called xd: | https://github.com/denysvitali/hexutils | | It just uses the same visualization but highlights the ASCII | chars ___________________________________________________________________ (page generated 2023-06-16 23:00 UTC)