multicode

module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2019 License: MIT

README

multicode

Build Status Go Report Card GoDoc

multicode allows to input a (nested) byte, hex, base64 or proto (protocol buffers) decoded sequence and will recursively try to encode it. This is helpful when you get encoded data but don't exactly know how it was encoded or encoding might lead to cumbersome command concatenation.

Installation

CLI
go get -u github.com/sj14/multicode/cmd/decode
Web Interface

Demo

go get -u github.com/sj14/multicode/cmd/decode-web

CLI Usage

  -base64
        use base64 decoding (default true)
  -byte
        use byte decoding (default true)
  -hex
        use hex decoding (default true)
  -proto
        use proto decoding (default true)
  -v    verbose output mode

CLI Examples

Decode byte input
$ decode "72 101 108 108 111 32 87 111 114 108 100"
Hello World
Decode nested decodings

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

Protobuf

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

Using with Docker

CLI Version
docker build -f Dockerfile.decode -t decode .
docker run --rm -it decode
Web Version
docker build -f Dockerfile.decode-web -t decode-web .
docker run --rm -it -p 8080:8080 decode-web

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL