Skip to content

Commit

Permalink
Provide examples for most commands, enhance pyesc, remove superfluous…
Browse files Browse the repository at this point in the history
… printfesc
  • Loading branch information
nealey committed Aug 9, 2017
1 parent 5dd38fb commit 9079cc8
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 67 deletions.
2 changes: 2 additions & 0 deletions Makefile
Expand Up @@ -7,6 +7,8 @@ TARGETS += printfesc
TARGETS += xor
TARGETS += unhex
TARGETS += pcat
TARGETS += skip
TARGETS += hex

all: $(TARGETS)

Expand Down
53 changes: 28 additions & 25 deletions README.md
Expand Up @@ -42,15 +42,18 @@ Like the normal hd,
but with unicode characters to represent all 256 octets,
instead of using "." for unprintable characters.

$ printf "\0\x01\x02\x03\x30\x52\x9a" | hd
00000000 00 01 02 03 30 52 9a ┆·☺☻♥0RÜ┆
00000007


### unhex: unescape hex

Reads ASCII hex codes on stdin,
writes those octets to stdout.

The following pipe is equivalent to "cat":

./hd | cut -b 11-58 | ./unhex
$ echo 68 65 6c 6c 6f 0a | unhex
hello


### xor: xor mask octets
Expand All @@ -62,24 +65,27 @@ For a 16-value mask, the mask is applied to 16-octet chunks at a time.

The "-x" option treats values as hex.

The following pipe is equivalent to "cat":

./xor 42 | ./xor -x 2A
$ printf 'hello' | xor 22; echo
~szzy
$ printf 'hello' | xor 0x16; echo
~szzy
$ printf 'hello' | xor -x 16; echo
~szzy
$ printf 'bbbbbb' | xor 1 0; echo
cbcbcb


### skip: discard initial octets

Throws away some initial octets from stdin,
and sends the rest to stdout.
You could use `dd` for the same purpose.

This skip command:

skip 5

Is equivalent to this `dd` command:
You could use `dd` for the same purpose.

dd skip=5 bs=1 status=none
$ echo abcdefgh | dd skip=5 bs=1 status=none
fgh
$ echo abcdefgh | skip 5
fgh


### pcat: print text representation of pcap file
Expand Down Expand Up @@ -120,22 +126,19 @@ writing to output.

### hex: hex-encode input

The opposite of `unhex`.
The opposite of `unhex`:
encoding all input into a single output line.

The following is the equivalent of `cat`:

hex | unhex


### printfesc: printf escape input

Reads octets,
writes a string suitable for copy-paste into printf.
$ printf "hello\nworld\n" | hex
68 65 6c 6c 6f 0a 77 6f 72 6c 64 0a


### pyesc: python escape input

Escapes input octets for pasting into a python "print" statement.
Also suitable for use as a C string,
a Go string,
and many other languages' string literals.



$ printf "hello\nworld\n" | pyesc
hello\nworld\n
9 changes: 7 additions & 2 deletions hex.c
Expand Up @@ -11,10 +11,15 @@ main(int argc, char *argv[])
if (EOF == c) {
break;
}
printf("%02x ", c);
if (7 == count % 8) {

if (count) {
putchar(' ');
if (0 == count % 8) {
putchar(' ');
}
}

printf("%02x", c);
}
putchar('\n');

Expand Down
40 changes: 0 additions & 40 deletions printfesc.c

This file was deleted.

10 changes: 10 additions & 0 deletions pyesc.c
Expand Up @@ -8,7 +8,17 @@ main(int argc, char *argv[])

switch (c) {
case EOF:
putchar('\n');
return 0;
case 8:
printf("\\t");
break;
case 10:
printf("\\n");
break;
case 13:
printf("\\r");
break;
case 134:
printf("\\\\");
break;
Expand Down

0 comments on commit 9079cc8

Please sign in to comment.