multicode
allows to input a (nested) bits
, bytes
, hex
, base64
or proto
(protocol buffers) encoded sequence and will recursively try to decode it. This is helpful when you get encoded data but don't exactly know how it was encoded or decoding might lead to cumbersome command concatenation.
Binaries are available for all major platforms. See the releases page.
Using the Homebrew package manager for macOS:
brew install sj14/tap/multicode
It's also possible to install the current development snapshot with go get
:
go get -u github.com/sj14/multicode/cmd/decode
go get -u github.com/sj14/multicode/cmd/decode-web
-base64
use base64 decoding (default true)
-bit
use bit decoding (default true)
-byte
use byte decoding (default true)
-hex
use hex decoding (default true)
-proto
use proto decoding (default true)
-verbose
verbose output mode
-version
print version information
$ decode "72 101 108 108 111 32 87 111 114 108 100"
Hello World
First, let's encode a string with hex and base64 encoding:
$ echo hello there | xxd -p | base64
Njg2NTZjNmM2ZjIwNzQ2ODY1NzI2NTBhCg==
Decode:
$ decode Njg2NTZjNmM2ZjIwNzQ2ODY1NzI2NTBhCg==
hello there
Decode using the pipe:
$ echo Njg2NTZjNmM2ZjIwNzQ2ODY1NzI2NTBhCg== | decode
hello there
Decode in verbose mode:
$ decode -v Njg2NTZjNmM2ZjIwNzQ2ODY1NzI2NTBhCg==
- applied decoding 'base64':
68656C6C6F207468657265
- applied decoding 'hex':
hello there
- result:
hello there
Disable hex decoding:
$ decode -v -hex=false Njg2NTZjNmM2ZjIwNzQ2ODY1NzI2NTBhCg==
- applied decoding 'base64':
68656C6C6F207468657265
- result:
68656C6C6F207468657265
We can decode protocol buffer encodings without specifying a proto file. Based on the missing definition file, it's unfortunately not possible, to output the field names. Field names will be replaced by the field id.
Let's assume the following proto message:
message Message {
string query = 1;
int32 page_number = 2;
int32 result_per_page = 3;
enum Corpus {
UNIVERSAL = 0;
WEB = 1;
}
Corpus corpus = 4;
}
And we initialize the message like this:
Message{
Query: "my query",
PageNumber: 42,
Corpus: ComplexMessage_NEWS,
}
The hex decoded proto message (0a086d79207175657279102a2006
) will be decoded as:
$ decode 0a086d79207175657279102a2004
1:"my query" 2:42 4:6
docker build -f Dockerfile.decode -t decode .
docker run --rm -it decode
docker build -f Dockerfile.decode-web -t decode-web .
docker run --rm -it -p 8080:8080 decode-web