aproto

package module
v0.0.0-...-a653f9d Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2023 License: MIT Imports: 11 Imported by: 2

README

Deprecated

Use the python version instead: https://github.com/aj3423/protod

Decode protobuf without message definition.

Try it online

https://168.138.55.177/

Screenshot

pb

Usage of library aproto

The library provides two Renderers: Console and Html, which are used for Console program and web site.

  • ConsoleRenderer
  out, e := aproto.TryDump([]byte{...})
  fmt.Println(out)
  
  // or:
  out, e := aproto.TryDumpEx([]byte{...}, &aproto.ConsoleRenderer{})

  • HtmlRenderer (used on demo site)
  out, e := aproto.TryDumpEx([]byte{...}, &aproto.HtmlRenderer{})
  // transfer the output to client browser, render it with
  $('#div').text(out)
  • Or create other custom Renders, just follow the Renderer interface

Use the prebuilt tool "proto_decoder"

supported: text/file with hex-string/binary/base64/zlib encoding

eg:

  • hex string: pro 120123
  • space/tab/newline will be trimmed:
pro "08 01 12 03   04 05
  06 07 08
  09 10 111213"
  • base64 + zlib string: pro -b64 EgEj
  • binary file: pro -bin -file a.bin
  • zlib+base64 file: pro -zlib -b64 -file a.bin
  • ...

Or build it yourself

  1. Install Golang
  2. clone this repo: git clone https://github.com/aj3423/aproto
  3. go to binary dir: cd aproto/proto_decoder
  4. go build .

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var List []Charset = []Charset{
	&Utf8{},
}

Used to detect string encoding, utf8 by default Customize this array to decode other charset, eg: &GBK{} Custom charset causes too much miss-decoding, normal binary rendered as GBK, so disabled by default.

Functions

func Dump

func Dump(data []byte) string

dump to Console and ignore error

func TryDump

func TryDump(data []byte) (string, error)

dump to Console

func TryDumpEx

func TryDumpEx(data []byte, r Renderer) (string, error)

dump with all kinds of Renderer

Types

type Charset

type Charset interface {
	Match([]byte) ([]byte, error)
	Name() string
}

type Chunk

type Chunk interface {
	Render(indent string, r Renderer) string
	Type() ChunkType
}

---- interface ----

type ChunkType

type ChunkType int
const (
	CT_Varint ChunkType = iota
	CT_Fixed64
	CT_Struct
	CT_Deprecated_3
	CT_Deprecated_4
	CT_Fixed32
)

https://developers.google.com/protocol-buffers/docs/encoding

type ConsoleRenderer

type ConsoleRenderer struct {
}

--------------- Console ---------------

func (*ConsoleRenderer) ID

func (r *ConsoleRenderer) ID(s string) string

func (*ConsoleRenderer) IDTYPE

func (r *ConsoleRenderer) IDTYPE(s string) string

func (*ConsoleRenderer) INDENT

func (r *ConsoleRenderer) INDENT() string

func (*ConsoleRenderer) NEWLINE

func (r *ConsoleRenderer) NEWLINE() string

func (*ConsoleRenderer) NUM

func (r *ConsoleRenderer) NUM(s string) string

func (*ConsoleRenderer) STR

func (r *ConsoleRenderer) STR(s string) string

func (*ConsoleRenderer) TYPE

func (r *ConsoleRenderer) TYPE(s string) string

type Fixed32

type Fixed32 struct {
	IdType
	// contains filtered or unexported fields
}

---- fixed32 ----

func (*Fixed32) Render

func (x *Fixed32) Render(indent string, r Renderer) string

func (*Fixed32) Type

func (x *Fixed32) Type() ChunkType

type Fixed64

type Fixed64 struct {
	Value uint64
	IdType
}

---- fixed64 ----

func (*Fixed64) Render

func (x *Fixed64) Render(indent string, r Renderer) string

func (*Fixed64) Type

func (x *Fixed64) Type() ChunkType

type GBK

type GBK struct{}

---- GBK ----

func (*GBK) Match

func (x *GBK) Match(data []byte) ([]byte, error)

func (*GBK) Name

func (x *GBK) Name() string

type HtmlRenderer

type HtmlRenderer struct {
}

func (*HtmlRenderer) ID

func (r *HtmlRenderer) ID(s string) string

func (*HtmlRenderer) IDTYPE

func (r *HtmlRenderer) IDTYPE(s string) string

func (*HtmlRenderer) INDENT

func (r *HtmlRenderer) INDENT() string

func (*HtmlRenderer) NEWLINE

func (r *HtmlRenderer) NEWLINE() string

func (*HtmlRenderer) NUM

func (r *HtmlRenderer) NUM(s string) string

func (*HtmlRenderer) STR

func (r *HtmlRenderer) STR(s string) string

func (*HtmlRenderer) TYPE

func (r *HtmlRenderer) TYPE(s string) string

type IdType

type IdType struct {
	Id   int
	Type uint64
	// contains filtered or unexported fields
}

---- IdType ----

func (*IdType) Render

func (x *IdType) Render(indent string, r Renderer) string

type Renderer

type Renderer interface {
	INDENT() string       // indent string
	NEWLINE() string      // renders a new line
	IDTYPE(string) string // full id+type hex bytes
	ID(string) string     // only id number
	TYPE(string) string   // only type string
	NUM(string) string    // a number
	STR(string) string    // a string
}

type Struct

type Struct struct {
	IdType

	DataLen int

	Str      []byte  // is string, not struct
	Children []Chunk // is struct, not string
}

---- struct ----

func (*Struct) Render

func (x *Struct) Render(indent string, r Renderer) string

func (*Struct) Type

func (x *Struct) Type() ChunkType

type Utf8

type Utf8 struct{}

---- utf8 ----

func (*Utf8) Match

func (x *Utf8) Match(data []byte) ([]byte, error)

func (*Utf8) Name

func (x *Utf8) Name() string

type Varint

type Varint struct {
	IdType
	/*
		The value is either of:
			int32, int64, uint32, uint64, sint32, sint64, bool, enum
		So an 'uint64' should be enough for 8 bytes
	*/
	Value uint64
}

---- varint ----

func (*Varint) Render

func (x *Varint) Render(indent string, r Renderer) string

func (*Varint) Type

func (x *Varint) Type() ChunkType

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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