Home · RSS · E-Mail · GitHub · GitLab · Twitter

Introducing multicode

Introduction

multicode is a simple tool to decode base64, hex, and protocol buffer data recursively. For example, it might be very useful when you store protocol buffers as a blob in your database. The protocol buffer file was encoded as base64 before and the database encodes blobs as hex values, thus we have three different encodings here. If you want to access the data from the database directly (e.g. for debugging purposes), you have to figure out how it was encoded exactly to do the correct decodings. This is the use case of the decode command of this tool. It will use a brute-force approach to encode the data. As long as one encoder (base64, hex, proto) was successful, it will use the result and try to decode it again with the same decoders, as it might be just an intermediate result.

The proto decoding is very “lightweight” and does not use proto definition files, which might be an advantage when you don’t know which proto file was used for encoding. On the other hand, you won’t be able to see the proto fields, only the stored values. So, there is still room for improvements.

This tool is highly inspired by a program written by my colleague at work (which is more bound to the use cases of the company and uses internal proto files for decoding).
I’ve asked how to credit him, but the answer was, that he doesn’t care about any credits on this. So, I concluded he didn’t want to be associated with the code I wrote ;-)

Read Me

multicode allows to input a (nested) base64, hex 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

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

Examples

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

Usage

  -base64
        use base64 decoding (default true)
  -hex
        use hex decoding (default true)
  -none
        disable all decodings
  -proto
        use proto decoding (default true)
  -v    verbose ouput mode

Home · RSS · E-Mail · GitHub · GitLab · Twitter