-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathomnidecode.go
More file actions
55 lines (43 loc) · 951 Bytes
/
omnidecode.go
File metadata and controls
55 lines (43 loc) · 951 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"github.com/zricethezav/gitleaks/v8/detect/codec"
"fmt"
"io"
"log"
"os"
"strconv"
)
func main() {
maxDecodeDepth := 8
var err error
if len(os.Args) == 2 || len(os.Args) > 3 {
log.Fatal("Usage:\n\tomnidecode [--depth n] < file")
}
if len(os.Args) == 3 && os.Args[2] == "--depth" {
maxDecodeDepth, err = strconv.Atoi(os.Args[3])
}
if err != nil {
log.Fatal(err)
}
rawData, err := io.ReadAll(os.Stdin)
if err != nil {
log.Fatal(err)
}
currentDecodeDepth := 0
data := string(rawData)
decoder := codec.NewDecoder()
encodedSegments := []*codec.EncodedSegment{}
for {
// increment the depth by 1 as we start our decoding pass
currentDecodeDepth++
// stop the loop if we've hit our max decoding depth
if currentDecodeDepth > maxDecodeDepth {
break
}
data, encodedSegments = decoder.Decode(data, encodedSegments)
if len(encodedSegments) == 0 {
break
}
}
fmt.Print(data)
}