Hexyl: A command-line hex viewer with colorized output
github.com
github.com
#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.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.
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.
They do much better with popular languages.
So, in other words, they perform precisely how you’d expect a stochastic parrot to perform?
The more popular the language the more likely the training corpus includes both very similar code samples and explanation of those code samples, and also the more likely those two converge on a “reasonable” explanation.
Ask it something it’s likely to have seen an answer for and it’s likely to spit out that answer… interesting? Sure, impressive? Maybe… but still pretty well captured by “a fuzzy jpeg of the web”.
Or exactly like you'd expect a human to perform.
Train a human mostly on English, and they'll speak English. Train them mostly on Chinese, and they'll speak Chinese.
Ahh, but ask a human a question in a language they don’t understand and they’ll look at you with bewilderment, not confidently make up a stream of hallucinatory nonsense that only vaguely looks statistically right.
> Or exactly like you’d expect a human to perform.
Not exactly, no… but with just enough of the uncanny valley to make me think the more interesting thought: are we really not much more than stochastic parrots? Or, in other words, are we naturally just slightly more interesting than today’s state of the artificially stupid?
I mostly agree with the stochastic parrot interpretation, but that doesn't undermine the usefulness or impressiveness. Even if it's just a highly compressed search index, that level of compression is amazing.
Start by find-and-replacing those #defines. You can iteratively deobfuscate things by hand. It's PITA and takes time, but it's doable.
If you hit a roadblock, run it in a VM.
It's just ordinary C code.
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;It's right here, and your name is on it. https://www.ioccc.org/1986/bright/bright.c
It even won an award! https://www.ioccc.org/1986/bright/hint.html
I cribbed it from system .h files.
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.
Bitwise operations are commonplace to improve efficiency.
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
It just uses the same visualization but highlights the ASCII chars
I don't understand why there are so many terminal hex viewers that don't edit.
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.
> Programmers who don't have their editor open
Well... these aren't programmers. Maybe "aspiring programmers", as in someone who still have to learn how to use their computer. It's not anyone who would be considered a competent user.
I don't know if you know the feeling: it's like watching inexperienced chess players play -- you want to scream when you see them making dumb moves, but then the opponent also makes a dumb move, which makes it more funny than sad.
When I look over the shoulder of people who work like you describe your workflow, just like with chess, I feel this kind of mix of embarrassment and frustration -- it was so easy to do it right, yet you decided to do something silly instead.
Why not suggest a more appropriate workflow without the chastising or denigration? C'mon, you can be supportive.
Unfortunately, our industry has few small pockets where you can still find competent programmers every now and then, but you wouldn't see them using IDEA or VS Code. And then there's an ocean of... well, not even mediocrity, it's just hands down awful. Most programmers throughout their career will never see a competent programmer, and if they stay around will be promoted into management where they will lose the very modest skill they had. And the cycle will continue.
I've seen way too many people like that, and have an idea how that kind of belief is formed. I don't want to help those people. I want them gone.
I'm sorry you have this attitude towards people. I wish you the best.
A ”raw bytes” view can be useful in many situations.
Hexyl: A command-line hex viewer - https://news.ycombinator.com/item?id=18865264 - Jan 2019 (113 comments)
Written in Delphi.
Split pane.
Useful app. Free.
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".
I also use XVI32. It's honestly probably not the best hex editor out there anymore, but I've been using it for well over a decade now and I'm used to its quirks.
Yes. I've not used it a lot myself, because my work then did not involve a lot of hex editing, just occassional.
Good to know.
But for my needs the hex viewer that I've wrote works best. I need those number displays at the bottom and an easy way to go to relative and absolute offsets. See the screenshot at the bottom: https://github.com/panzi/rust-hox
0 - https://man.freebsd.org/cgi/man.cgi?query=xxd&apropos=0&sekt...
Was there a first project you did that got you hooked?
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.
I have been out of the bit land for a very, very long time -- the last of my assembly programs are old enough to drink -- but I am increasingly finding myself running hexdump again and it's not a great experience. I expected better in 2023 and here it is.
I will explore but https://github.com/WerWolv/ImHex/blob/c2e023f567d4e838ea69e6... this makes me super-duper hopeful. UTF-8 capable ex viewer, that'd be handy.
or
$ other_command_or_pipeline | od -cx
is from early versions of Unix. Prints both character and hexadecimal representation of each byte in the input.
$ man od
And right, it's output has issues for some uses.