🔮 Futuristic take on hexdump, made in Rust.

Overview

hex (hx)

Futuristic take on hexdump.

hx accepts a file path as input and outputs a hexadecimal colorized view to stdout.

$ hx tests/files/alphanumeric.txt
0x000000: 0x61 0x62 0x63 0x64 0x65 0x66 0x67 0x68 0x69 0x6a abcdefghij
0x00000a: 0x6b 0x69 0x6c 0x6d 0x6e 0x6f 0x70 0x71 0x72 0x73 kilmnopqrs
0x000014: 0x74 0x75 0x76 0x77 0x78 0x79 0x7a 0x30 0x31 0x32 tuvwxyz012
0x00001e: 0x33 0x34 0x35 0x36 0x37 0x38 0x39 0x0a 0x30 0x31 3456789.01
0x000028: 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x39 0x30 0x31 2345678901
0x000032: 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x39 0x30 0x31 2345678901
0x00003c: 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x39           23456789
   bytes: 68

hx also accepts stdin as input.

cat "tests/files/alphanumeric.txt" | hx
0x000000: 0x61 0x62 0x63 0x64 0x65 0x66 0x67 0x68 0x69 0x6a abcdefghij
0x00000a: 0x6b 0x69 0x6c 0x6d 0x6e 0x6f 0x70 0x71 0x72 0x73 kilmnopqrs
0x000014: 0x74 0x75 0x76 0x77 0x78 0x79 0x7a 0x30 0x31 0x32 tuvwxyz012
0x00001e: 0x33 0x34 0x35 0x36 0x37 0x38 0x39 0x0a 0x30 0x31 3456789.01
0x000028: 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x39 0x30 0x31 2345678901
0x000032: 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x39 0x30 0x31 2345678901
0x00003c: 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x39           23456789
   bytes: 68

build coverage

quick links

examples

lower hex format -fx

$ hx src/main.rs

lower hex output format

binary hex format -fb

$ hx -fb -c4 src/main.rs

binary hex output format

octal hex format -fo

$ hx -fo -c8 src/main.rs

octal hex output format

install

crates.io install

If cargo is already installed, simply:

cargo install hx

source install

From within the hx source code directory, simply execute:

make install

This will run the following cargo commands:

cargo build --release
cargo test --verbose --all -- --nocapture
cargo install --path .

Which will compile the release version, run tests and install release binary to <USERDIR>/.cargo/bin/hx.

If <USERDIR>/.cargo/bin is part of the PATH environment variable, hx should be able to be executed anywhere in the shell.

arch linux install

pacman -S hex

debian install

curl -sLO https://github.com/sitkevij/hex/releases/download/v0.4.1/hx_0.4.1_amd64.deb && dpkg -i hx_0.4.1_amd64.deb

docker run

cat README.md | docker run -i sitkevij/hx:latest

features

output arrays in rust, c, golang, python, kotlin, java, or swift

hx has a feature which can output the input file bytes as source code arrays.

For example:

rust array: -ar

$ hx -ar -c8 tests/files/tiny.txt
let ARRAY: [u8; 3] = [
    0x69, 0x6c, 0x0a
];

c array: -ac

$ hx -ac -c8 tests/files/tiny.txt
unsigned char ARRAY[3] = {
    0x69, 0x6c, 0x0a
};

golang array: -ag

$ hx -ag -c8 tests/files/tiny.txt
a := [3]byte{
    0x69, 0x6c, 0x0a,
}

python array: -ap

$ hx -ap -c8 tests/files/tiny.txt
a = [
    0x69, 0x6c, 0x0a
]

kotlin array: -ak

$ hx -ak -c8 tests/files/tiny.txt
val a = byteArrayOf(
    0x69, 0x6c, 0x0a
)

java array: -aj

$ hx -aj -c8 tests/files/tiny.txt
byte[] a = new byte[]{
    0x69, 0x6c, 0x0a
};

swift array: -as

$ hx -as -c8 tests/files/tiny.txt
let a: [UInt8] = [
    0x69, 0x6c, 0x0a
]

NO_COLOR support

hx will honor the NO_COLOR environment variable. If set, no color will be output to the terminal.

Rust no_color crate:

manual

hx
Futuristic take on hexdump, made in Rust.

USAGE:
    hx [OPTIONS] [INPUTFILE]
    <stdout> | hx [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -a, --array <array_format>    Set source code format output: rust (r), C (c), golang (g), python (p), kotlin (k), java (j) [possible values: r, c, g, p, k, j]
    -t, --color <color>           Set color tint terminal output. 0 to disable, 1 to enable [possible values: 0, 1]
    -c, --cols <columns>          Set column length
    -f, --format <format>         Set format of octet: Octal (o), LowerHex (x), UpperHex (X), Binary (b) [possible
                                  values: o, x, X, b]
    -u, --func <func_length>      Set function wave length
    -l, --len <len>               Set <len> bytes to read
    -p, --places <func_places>    Set function wave output decimal places

ARGS:
    <INPUTFILE>    Pass file path as an argument for hex dump

license

MIT

Comments
  • Generate source code for F# arrays

    Generate source code for F# arrays

    I added source code output for F# arrays. They use a semicolon instead of a comma as the delimiter, and each literal needs to have the uy suffix, or the F# compiler will complain. That's why I had to special case the new f array format.

    opened by jerekapyaho 3
  • `-ar` flags do not seem to work if they come before the filename.

    `-ar` flags do not seem to work if they come before the filename.

    ~
    ❯ touch test
    
    ~
    ❯ echo "Hello, world." > test
    
    ~
    ❯ time hx -ar test
    ^CCommand terminated by signal 2
    0.00user 0.00system 0:04.46elapsed 0%CPU (0avgtext+0avgdata 2528maxresident)k
    0inputs+0outputs (0major+107minor)pagefaults 0swaps
    
    ~ took 4s
    ❯ time hx test -ar
    let ARRAY: [u8; 14] = [
        0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x77, 0x6f, 0x72,
        0x6c, 0x64, 0x2e, 0x0a
    ];
    0.00user 0.00system 0:00.00elapsed 93%CPU (0avgtext+0avgdata 2796maxresident)k
    0inputs+0outputs (0major+112minor)pagefaults 0swaps
    
    ~```
    bug 
    opened by janaakhterov 3
  • Allow reading from stdin and make it streaming

    Allow reading from stdin and make it streaming

    Hi there,

    I made several changes to your tool to make it fit my needs, and looking at the issues I figured other people might want some of these changes as well.

    • Allow reading from stdin. This lets me use hx in sequence with other command line tools.
    • Make it streaming. So it doesn't read the entire resource in and try to hold it in memory.

    These are just some changes I made to make it work; if you dont' think they should be merged or needs other changes, feel free to let me know or close it.

    opened by iptq 3
  • SIGPIPE causes hex to crash

    SIGPIPE causes hex to crash

    When used in a pipeline hex will crash if a downstream program exits before hex finishes printing.

    To Reproduce

    $ dd if=/dev/random bs=512 count=10 | RUST_BACKTRACE=1 hx | head -n 10
    
    10+0 records in
    10+0 records out
    5120 bytes (5.1 kB, 5.0 KiB) copied, 0.001144 s, 4.5 MB/s
    0x000000: 0x24 0xfc 0xad 0xc8 0x27 0x0f 0x30 0x33 0x45 0x33 $...'.03E3
    0x00000a: 0x4c 0x49 0xcc 0x33 0x47 0x9e 0x6d 0x38 0xc6 0x6f LI.3G.m8.o
    0x000014: 0x86 0x7d 0xc2 0xd3 0x03 0x31 0xf9 0xbf 0xec 0xa4 .}...1....
    0x00001e: 0x36 0x33 0xf1 0x6e 0x8b 0x43 0xe6 0xab 0x7c 0xef 63.n.C..|.
    0x000028: 0x52 0xb4 0xdb 0xa1 0x63 0xe8 0x96 0x61 0xd8 0x2b R...c..a.+
    0x000032: 0x47 0xc6 0xad 0x86 0x86 0xf6 0x52 0xe3 0x54 0x58 G.....R.TX
    0x00003c: 0xfb 0x1b 0x80 0x50 0x79 0x80 0x11 0x31 0xa6 0x72 ...Py..1.r
    0x000046: 0x50 0xf8 0x77 0x96 0x50 0x13 0x39 0x17 0xfe 0xc7 P.w.P.9...
    0x000050: 0xef 0x40 0x78 0xe8 0xd5 0xfb 0xc6 0x4c 0x62 0x36 [email protected]
    0x00005a: 0xd9 0x32 0x18 0xe5 0x1d 0xc5 0xf0 0x95 0x35 0xdf .2......5.
    thread 'main' panicked at 'failed printing to stdout: Broken pipe (os error 32)', src/libstd/io/stdio.rs:822:9
    stack backtrace:
       0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
       1: core::fmt::write
       2: std::io::Write::write_fmt
       3: std::panicking::default_hook::{{closure}}
       4: std::panicking::default_hook
       5: std::panicking::rust_panic_with_hook
       6: rust_begin_unwind
       7: std::panicking::begin_panic_fmt
       8: std::io::stdio::_print
       9: hx::lib::run
      10: hx::main
      11: std::rt::lang_start::{{closure}}
      12: std::rt::lang_start_internal
      13: main
    note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
    

    In this situation head reads 10 lines from hex, prints them, and exits. This causes a SIGPIPE to be sent to hex which crashes. The expected behavior would be to handle the signal, stop printing, and cleanly exit.

    Environment

    Version: v0.3.0 (installed via cargo install hx) OS: macOS 10.14.6

    bug 
    opened by pR0Ps 2
  • Add installation instructions for Arch Linux

    Add installation instructions for Arch Linux

    Hey! hex can be installed from Arch Linux [community] repository: https://archlinux.org/packages/community/x86_64/hex/ This PR adds installation instruction to README.md

    opened by orhun 1
  • Ensures '--len' does not crash or hang

    Ensures '--len' does not crash or hang

    Fixes #24. Fixes #22.

    #24 is essentially a duplicates of #22, the root cause is the ordering of the checks inside the is_stdin function.

    I also simplified some parts of ìs_stdin.

    opened by poliorcetics 1
  • Make `hx` properly handle being passed invalid paths

    Make `hx` properly handle being passed invalid paths

    Fixes #26. Fixes #23.

    With this PR hx is now able to properly report an error when it is given a directory, an invalid filename or a broken pipe:

    # All those cases crashed previously.
    
    ❯ ./target/release/hx filename-missing
    error = "No such file or directory (os error 2)"
    
    ❯ ./target/release/hx src
    error = "Is a directory (os error 21)"
    
    ❯ ./target/release/hx symlink_to_dir
    error = "Is a directory (os error 21)"
    
    ❯ dd if=/dev/random bs=512 count=10 | RUST_BACKTRACE=1 ./target/debug/hx | head -n 10
    10+0 records in
    10+0 records out
    5120 bytes transferred in 0.000036 secs (142217460 bytes/sec)
    0x000000: 0x6c 0xdc 0x4f 0x43 0xfd 0x5e 0xb3 0xa7 0x79 0xaa l.OC.^..y.
    0x00000a: 0x6b 0x2c 0x81 0x47 0x00 0x10 0xa6 0x40 0xb5 0x6a k,[email protected]
    0x000014: 0x4d 0x31 0x5b 0x11 0x15 0x71 0xb8 0xa1 0xff 0x91 M1[..q....
    0x00001e: 0x2e 0xaa 0x69 0x77 0x52 0x2a 0x20 0xa6 0x52 0xe5 ..iwR* .R.
    0x000028: 0x41 0x2b 0x83 0x55 0x21 0x41 0x33 0xae 0xf8 0x38 A+.U!A3..8
    0x000032: 0xba 0x74 0xfe 0x23 0xc2 0xc9 0xf5 0x3d 0x28 0x8e .t.#...=(.
    0x00003c: 0xbc 0x0e 0xe1 0xa3 0xbf 0xda 0x81 0x92 0xc6 0xe9 ..........
    0x000046: 0x9f 0xb7 0x13 0x72 0x79 0xd3 0x1e 0x4c 0xd8 0x5d ...ry..L.]
    0x000050: 0x85 0x36 0x91 0x9f 0x13 0x7e 0x55 0x5f 0x7b 0xa6 .6...~U_{.
    0x00005a: 0x23 0xe7 0xed 0x54 0x47 0x9a 0x1c 0x54 0x91 0x85 #..TG..T..
    error = "Broken pipe (os error 32)"
    
    opened by poliorcetics 1
  • Passing a invalid filename causes a crash

    Passing a invalid filename causes a crash

    Describe the bug

    Passing an invalid filename to hx causes it to crash on a Result:

    To Reproduce Steps to reproduce the behavior:

    $ hx toto
    thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', $HOME/.config/rust/cargo/registry/src/github.com-1ecc6299db9ec823/hx-0.3.0/src/lib.rs:238:17
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    

    Expected behavior

    I expected the program to tell me I made a mistake.

    Desktop (please complete the following information):

    • OS: macOS 10.15.7

    Additional context

    $ hx --version
    hx 0.3.0
    

    I'll probably have the time to open a PR for a fix tomorrow if wanted.

    bug 
    opened by poliorcetics 1
  • --len argument causes hx to hang

    --len argument causes hx to hang

    Describe the bug Calling hx with the -l or --len argument causes it to hang indefinitely.

    To Reproduce Steps to reproduce the behavior: hx -l myfile.txt

    Desktop (please complete the following information):

    • OS: Arch linux

    Additional context Thanks for this great tool :)

    bug 
    opened by HagaiHargil 1
  • Feature/stdin support

    Feature/stdin support

    support stdin

    • dynamically detect stdin, file path and parameters
    • remove unused verbose param
    • refactor output_array() own function
    • add clippy command to Makefile
    • update edition
    opened by sitkevij 1
  • Ability to convert data given on stdin

    Ability to convert data given on stdin

    Is your feature request related to a problem? Please describe.

    The hexdump command and many Unix/Linux utilities allow operating on stdin either naturally cat FILE | util or by supplying special file name "-" like cat FILE | util -.

    A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

    Describe the solution you'd like

    If file name does not exist and it has name "-", read and process input from stdin

    Describe alternatives you've considered

    If file name is not supplied, check if there is an input on stdin and process it instead.

    Additional context

    Since hx is basically filter, those two invocations are the first ones I have tried and none has worked for me. It is not a deal breaker, but it might be considered as lack of polish that will hinder adoption of hx tool.

    Especially since in the second case I get panic instead of nicely formatted error message:

    $ cat FILE | hx -
    thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', /home/haku/.cargo/registry/src/github.com-1ecc6299db9ec823/hx-0.2.1/src/lib.rs:223:17
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    
    enhancement 
    opened by zdenek-crha 1
  • Add address and length to print

    Add address and length to print

    Is your feature request related to a problem? Please describe. No

    Describe the solution you'd like A --length and --address to specify the memory range to print

    Describe alternatives you've considered Less with search is terrible

    Additional context It helps developers

    opened by patrickelectric 0
  • Suggestion: rename hx

    Suggestion: rename hx

    I was unable to install hex because https://github.com/helix-editor/helix has hx.

    $ cargo install hx
    error: binary `hx` already exists in destination as part of `helix-term v0.6.0 (/home/x/helix/helix-term)`
    Add --force to overwrite
    
    opened by xor 0
  • Load only enough bytes to fill the console

    Load only enough bytes to fill the console

    Is your feature request related to a problem? Please describe. I'm always frustrated when I try to use hx for a very large file. For example, when trying to load a 3.1 GB binary file, it eventually used up 16 GB of RAM before I stopped the process.

    Describe the solution you'd like I think that a potential solution would involve replacing the fs::File::open with an unsafe memmap call. Just that would probably save a lot of memory usage.

    Describe alternatives you've considered Note that I'm not very familiar with the code at all (just started reading it today). That said, another alternative would be to not append the given line to the page.body for all of the bytes ... and maybe the truncate_len used in buf_to_array should be set to the console's number of lines somehow? The difficulty with that second approach is that at each console refresh, another part of the file will need to be parsed.

    opened by ChristopherRabotin 0
  • hex hx binary clashes with helix hx wrapper

    hex hx binary clashes with helix hx wrapper

    In my system, I have also installed installed the helix editor.

    • https://github.com/helix-editor/helix

    It is currently not yet on Crates

    • https://crates.io/crates/helix-editor
    • https://crates.io/crates/helix-term

    It provides a wrapper that uses the same binary name than hx, which therefore clashes.

    Is there a way to assign another name to the binary during build, e.g. hex? Then choosing an abbreviated version remains as simple as creating a symlink.

    opened by almereyda 1
  • Hide prefixes such as `0x`

    Hide prefixes such as `0x`

    Is your feature request related to a problem? Please describe. Currently, there's no options to disable prefixes like 0x as far as I know. The hexdump command doesn't show 0x so I can show more digits in a line.

    Describe the solution you'd like It would be better to add an option to disable prefixes.

    Describe alternatives you've considered The option -f, --format could have values to disable prefixes.

    Additional context

    help wanted 
    opened by maekawatoshiki 1
Releases(v0.4.2)
Owner
Julian Sitkevich
Julian Sitkevich
Yet another fancy watcher. (Rust)

funzzy Yet another fancy watcher. (Inspired by antr / entr) Configure execution of different commands using semantic yaml. # .watch.yaml # list here a

Cristian Oliveira 188 Dec 12, 2022
A modern replacement for ps written in Rust

procs procs is a replacement for ps written in Rust. Documentation quick links Features Platform Installation Usage Configuration Features Output by t

null 3.6k Jan 5, 2023
A more intuitive version of du in rust

Dust du + rust = dust. Like du but more intuitive. Why Because I want an easy way to see where my disk is being used. Demo Install Cargo cargo install

andy.boot 5.5k Jan 8, 2023
Blazing 💥 fast terminal-ui for git written in rust 🦀

Blazing fast terminal client for git written in Rust Features Fast and intuitive keyboard only control Context based help (no need to memorize tons of

Stephan Dilly 11.8k Jan 5, 2023
A simple and fast download accelerator, written in Rust

zou A simple and fast download accelerator, written in Rust Zou is a Snatch fork by @k0pernicus. Snatch is a fast and interruptable download accelerat

Antonin Carette 173 Dec 4, 2022
Fuzzy Finder in rust!

Life is short, skim! Half of our life is spent on navigation: files, lines, commands… You need skim! It is a general fuzzy finder that saves you time.

Jinzhou Zhang 3.7k Jan 4, 2023
A bash-like Unix shell written in Rust

Cicada Unix Shell Cicada is a simple Unix shell written in Rust. Documents Install cicada Environment Variables Cicada Builtins Completion RC File His

Hugo Wang 921 Dec 28, 2022
Performs distributed command execution, written in Rust w/ Tokio

Concurr: Distributed and Concurrent Command Execution, in Rust This project is dual licensed under MIT and Apache 2.0. Originally inspired by the GNU

Michael Murphy 93 Dec 18, 2022
A library to listen to global hotkeys in Rust

Rust Hotkey A library to listen to global hotkeys in Rust How to use See the examples folder for how to use this library. OS Support This lib aims to

James Birtles 44 Dec 12, 2022
Cross-platform Rust rewrite of the GNU coreutils

uutils coreutils uutils is an attempt at writing universal (as in cross-platform) CLI utilities in Rust. This repository is intended to aggregate GNU

null 13k Dec 30, 2022
A TUI system monitor written in Rust

NO LONGER MAINTAINED. For a similar program, check out https://github.com/ClementTsang/bottom. ytop Another TUI based system monitor, this time in Rus

Caleb Bassi 2.1k Jan 3, 2023
A rust layered configuration loader with zero-boilerplate configuration management.

salak A layered configuration loader with zero-boilerplate configuration management. About Features Placeholder Key Convension Cargo Features Default

Daniel YU 28 Sep 20, 2022
Untrusted IPC with maximum performance and minimum latency. On Rust, on Linux.

Untrusted IPC with maximum performance and minimum latency. On Rust, on Linux. When is this Rust crate useful? Performance or latency is crucial, and

null 72 Jan 3, 2023
An over-engineered rewrite of pipes.sh in Rust

pipes-rs An over-engineered rewrite of pipes.sh in Rust Installlation macOS Install using Homebrew or download manually from releases. $ brew install

Lucas 301 Dec 30, 2022
Trup-rewrite in rust! Finally!

Trup, but Rust! A Discord bot for the Unixporn community Now written in a good language! Dependencies Rust nightly sqlx-cli (if you need to change the

r/unixporn 106 Dec 22, 2022
A collection of small Rust programs for doing weird things

This is a repo of small programs, proof of concepts, or templates written in Rust that relate in some way to hacking and/or CTF. I think Rust is real

d3npa 22 Nov 9, 2022
🍂 A Rust-based simulated DOM (browser-independent replacement for web_sys)

DOM in Rust without a browser Hello and welcome. This library provides server-side or browserless simulation of a DOM. Example Usage use std::sync::Ar

Philip Peterson 45 Dec 13, 2022
Rust implementation to simply convert between coordinate systems

GeoMorph Simple conversion between different coordinate systems without external wrappers

Victor Lopes 10 Nov 8, 2022
A non-root version of traceroute written in Rust

tracepath-rs A non-root version of traceroute written in Rust for Linux.

Peter Malmgren 9 Dec 30, 2022