Skip to content

Commit

Permalink
Better help text (#28)
Browse files Browse the repository at this point in the history
* Better help text

* Modify README accordingly
  • Loading branch information
joohoi authored May 13, 2021
1 parent 1f38d24 commit d98b7d4
Show file tree
Hide file tree
Showing 26 changed files with 126 additions and 38 deletions.
50 changes: 20 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,40 @@ go install github.com/ffuf/pencode/cmd/pencode
```
pencode - complex payload encoder v0.2
Usage: ./pencode ENCODER1 ENCODER2 ENCODER3...
Usage: ./pencode FUNC1 FUNC2 FUNC3...
./pencode reads input from stdin, which is typically piped from another process.
Available encoders:
b64decode - Base64 decoder
ENCODERS
b64encode - Base64 encoder
filename.tmpl - Replaces string #PAYLOAD# in content of a file that has .tmpl extension.
hexdecode - Hex string decoder
hexencode - Hex string encoder
jsonescape - JSON escape
jsonunescape - JSON unescape
unicodedecode - Unicode escape string decode
unicodeencodeall - Unicode escape string encode (all characters)
urldecode - URL decode
urlencode - URL encode reserved characters
urlencodeall - URL encode all characters
utf16 - UTF-16 encoder (Little Endian)
utf16be - UTF-16 encoder (Big Endian)
xmlescape - XML escape
DECODERS
b64decode - Base64 decoder
hexdecode - Hex string decoder
jsonunescape - JSON unescape
unicodedecode - Unicode escape string decode
urldecode - URL decode
xmlunescape - XML unescape
HASHES
md5 - MD5 sum
sha1 - SHA1 checksum
sha224 - SHA224 checksum
sha256 - SHA256 checksum
sha384 - SHA384 checksum
sha512 - SHA512 checksum
OTHER
filename.tmpl - Replaces string #PAYLOAD# in content of a file that has .tmpl extension.
```

To urlencode, base64encode and hex encode a string:
Expand All @@ -47,24 +59,6 @@ $ echo 'what%ever'|pencode urlencode b64encode hexencode
64326868644355794e5756325a58493d
```

### Available encoders

- Base64 encoder
- Base64 decoder
- Hex string encoder
- Hex string decoder
- JSON escape encoder (reserved characters)
- JSON escape decoder
- Unicode escape string encoder
- Unicode escape string decoder
- URL encoder (reserved characters)
- URL encoder (all characters)
- URL decoder
- UTF16 encoder (Little Endian)
- UTF16 encoder (Big Endian)
- XML escape encoder (reserved characters)
- XML escape decoder

### Templating

Any command line parameter that is a file path ending with `.tmpl` is considered as a template file by
Expand Down Expand Up @@ -109,10 +103,6 @@ To get auto-complete working you need to `source` the `pencode-completion.fish`
source ~/path/to/pencode-completion.fish
```

### Upcoming

- Templating

### Usage as a library

```go
Expand Down
5 changes: 2 additions & 3 deletions cmd/pencode/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ func main() {

flag.Usage = func() {
fmt.Printf("pencode - complex payload encoder v%s\n\n", pencode.VERSION)
fmt.Printf("Usage: %s ENCODER1 ENCODER2 ENCODER3...\n\n", os.Args[0])
fmt.Printf("Usage: %s FUNC1 FUNC2 FUNC3...\n\n", os.Args[0])
fmt.Printf("%s reads input from stdin, which is typically piped from another process.\n\n", os.Args[0])
fmt.Printf("Available encoders:\n")
chain.Usage()
}

Expand Down Expand Up @@ -47,7 +46,7 @@ func main() {
if err != nil {
fmt.Printf(" [!] %s\n", err)
}
fmt.Println(string(output))
fmt.Print(string(output))
}

func readInput() string {
Expand Down
4 changes: 4 additions & 0 deletions pkg/pencode/base64decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ func (b Base64Decoder) Encode(input []byte) ([]byte, error) {
func (b Base64Decoder) HelpText() string {
return "Base64 decoder"
}

func (b Base64Decoder) Type() string {
return "decoders"
}
4 changes: 4 additions & 0 deletions pkg/pencode/base64encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ func (b Base64Encoder) Encode(input []byte) ([]byte, error) {
func (b Base64Encoder) HelpText() string {
return "Base64 encoder"
}

func (b Base64Encoder) Type() string {
return "encoders"
}
20 changes: 15 additions & 5 deletions pkg/pencode/encoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package pencode
import (
"fmt"
"sort"
"strings"
)

var availableEncoders = map[string]Encoder{
Expand Down Expand Up @@ -114,10 +115,19 @@ func (c *Chain) Usage() {
}
}
format := fmt.Sprintf(" %%-%ds- %%s\n", max_length+2)
names := c.GetEncoders()

for _, n := range names {
v := availableEncoders[n]
fmt.Printf(format, n, v.HelpText())
//names := c.GetEncoders()
for _, t := range []string{"encoders", "decoders", "hashes", "other"} {
fmt.Printf("%s\n", strings.ToUpper(t))
list := []string{}
for n, e := range availableEncoders {
if e.Type() == t {
list = append(list, fmt.Sprintf(format, n, e.HelpText()))
}
}
sort.Strings(list)
for _, i := range list {
fmt.Print(i)
}
fmt.Println()
}
}
4 changes: 4 additions & 0 deletions pkg/pencode/hexdecoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ func (h HexDecoder) Encode(input []byte) ([]byte, error) {
func (h HexDecoder) HelpText() string {
return "Hex string decoder"
}

func (h HexDecoder) Type() string {
return "decoders"
}
4 changes: 4 additions & 0 deletions pkg/pencode/hexencoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ func (h HexEncoder) Encode(input []byte) ([]byte, error) {
func (h HexEncoder) HelpText() string {
return "Hex string encoder"
}

func (h HexEncoder) Type() string {
return "encoders"
}
1 change: 1 addition & 0 deletions pkg/pencode/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package pencode
type Encoder interface {
Encode([]byte) ([]byte, error)
HelpText() string
Type() string
}
4 changes: 4 additions & 0 deletions pkg/pencode/jsondecode.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ func (u JSONUnescaper) Encode(input []byte) ([]byte, error) {
func (u JSONUnescaper) HelpText() string {
return "JSON unescape"
}

func (u JSONUnescaper) Type() string {
return "decoders"
}
4 changes: 4 additions & 0 deletions pkg/pencode/jsonencode.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ func (u JSONEscaper) Encode(input []byte) ([]byte, error) {
func (u JSONEscaper) HelpText() string {
return "JSON escape"
}

func (u JSONEscaper) Type() string {
return "encoders"
}
4 changes: 4 additions & 0 deletions pkg/pencode/md5.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ func (m MD5Hasher) Encode(input []byte) ([]byte, error) {
func (m MD5Hasher) HelpText() string {
return "MD5 sum"
}

func (m MD5Hasher) Type() string {
return "hashes"
}
4 changes: 4 additions & 0 deletions pkg/pencode/sha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ func (m SHA1Hasher) Encode(input []byte) ([]byte, error) {
func (m SHA1Hasher) HelpText() string {
return "SHA1 checksum"
}

func (m SHA1Hasher) Type() string {
return "hashes"
}
4 changes: 4 additions & 0 deletions pkg/pencode/sha224.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ func (m SHA224Hasher) Encode(input []byte) ([]byte, error) {
func (m SHA224Hasher) HelpText() string {
return "SHA224 checksum"
}

func (m SHA224Hasher) Type() string {
return "hashes"
}
4 changes: 4 additions & 0 deletions pkg/pencode/sha256.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ func (m SHA256Hasher) Encode(input []byte) ([]byte, error) {
func (m SHA256Hasher) HelpText() string {
return "SHA256 checksum"
}

func (m SHA256Hasher) Type() string {
return "hashes"
}
4 changes: 4 additions & 0 deletions pkg/pencode/sha384.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ func (m SHA384Hasher) Encode(input []byte) ([]byte, error) {
func (m SHA384Hasher) HelpText() string {
return "SHA384 checksum"
}

func (m SHA384Hasher) Type() string {
return "hashes"
}
4 changes: 4 additions & 0 deletions pkg/pencode/sha512.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ func (m SHA512Hasher) Encode(input []byte) ([]byte, error) {
func (m SHA512Hasher) HelpText() string {
return "SHA512 checksum"
}

func (m SHA512Hasher) Type() string {
return "hashes"
}
4 changes: 4 additions & 0 deletions pkg/pencode/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ func (t Template) Encode(input []byte) ([]byte, error) {
func (t Template) HelpText() string {
return "Replaces string #PAYLOAD# in content of a file that has .tmpl extension."
}

func (t Template) Type() string {
return "other"
}
4 changes: 4 additions & 0 deletions pkg/pencode/unicodedecode.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ func (u UnicodeDecode) HelpText() string {
return "Unicode escape string decode"
}

func (u UnicodeDecode) Type() string {
return "decoders"
}

//This functionality is copied from encoding/json/decode.go with minor modifications
func unquoteBytes(s []byte) []byte {
b := make([]byte, len(s)+2*utf8.UTFMax)
Expand Down
4 changes: 4 additions & 0 deletions pkg/pencode/unicodeencodeall.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ func (u UnicodeEncodeAll) Encode(input []byte) ([]byte, error) {
func (u UnicodeEncodeAll) HelpText() string {
return "Unicode escape string encode (all characters)"
}

func (u UnicodeEncodeAll) Type() string {
return "encoders"
}
4 changes: 4 additions & 0 deletions pkg/pencode/urldecode.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ func (u URLDecoder) Encode(input []byte) ([]byte, error) {
func (u URLDecoder) HelpText() string {
return "URL decode"
}

func (u URLDecoder) Type() string {
return "decoders"
}
4 changes: 4 additions & 0 deletions pkg/pencode/urlencode.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ func (u URLEncoder) Encode(input []byte) ([]byte, error) {
func (u URLEncoder) HelpText() string {
return "URL encode reserved characters"
}

func (u URLEncoder) Type() string {
return "encoders"
}
4 changes: 4 additions & 0 deletions pkg/pencode/urlencodeall.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ func (u URLEncoderAll) Encode(input []byte) ([]byte, error) {
func (u URLEncoderAll) HelpText() string {
return "URL encode all characters"
}

func (u URLEncoderAll) Type() string {
return "encoders"
}
4 changes: 4 additions & 0 deletions pkg/pencode/utf16beencoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ func (u UTF16BEEncode) Encode(input []byte) ([]byte, error) {
func (u UTF16BEEncode) HelpText() string {
return "UTF-16 encoder (Big Endian)"
}

func (u UTF16BEEncode) Type() string {
return "encoders"
}
4 changes: 4 additions & 0 deletions pkg/pencode/utf16leencoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ func (u UTF16LEEncode) Encode(input []byte) ([]byte, error) {
func (u UTF16LEEncode) HelpText() string {
return "UTF-16 encoder (Little Endian)"
}

func (u UTF16LEEncode) Type() string {
return "encoders"
}
4 changes: 4 additions & 0 deletions pkg/pencode/xmldecode.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ func (u XMLUnescaper) Encode(input []byte) ([]byte, error) {
func (u XMLUnescaper) HelpText() string {
return "XML unescape"
}

func (u XMLUnescaper) Type() string {
return "decoders"
}
4 changes: 4 additions & 0 deletions pkg/pencode/xmlencode.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ func (u XMLEscaper) Encode(input []byte) ([]byte, error) {
func (u XMLEscaper) HelpText() string {
return "XML escape"
}

func (u XMLEscaper) Type() string {
return "encoders"
}

0 comments on commit d98b7d4

Please sign in to comment.