Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/protocols/common/utils/vardump/dump.go
2073 views
1
package vardump
2
3
import (
4
"strings"
5
6
"github.com/projectdiscovery/nuclei/v3/pkg/types"
7
mapsutil "github.com/projectdiscovery/utils/maps"
8
"github.com/yassinebenaid/godump"
9
)
10
11
// variables is a map of variables
12
type variables = map[string]any
13
14
// DumpVariables dumps the variables in a pretty format
15
func DumpVariables(data variables) string {
16
d := godump.Dumper{
17
Indentation: " ",
18
HidePrivateFields: false,
19
ShowPrimitiveNamedTypes: true,
20
}
21
22
d.Theme = godump.Theme{
23
String: godump.RGB{R: 138, G: 201, B: 38},
24
Quotes: godump.RGB{R: 112, G: 214, B: 255},
25
Bool: godump.RGB{R: 249, G: 87, B: 56},
26
Number: godump.RGB{R: 10, G: 178, B: 242},
27
Types: godump.RGB{R: 0, G: 150, B: 199},
28
Address: godump.RGB{R: 205, G: 93, B: 0},
29
PointerTag: godump.RGB{R: 110, G: 110, B: 110},
30
Nil: godump.RGB{R: 219, G: 57, B: 26},
31
Func: godump.RGB{R: 160, G: 90, B: 220},
32
Fields: godump.RGB{R: 189, G: 176, B: 194},
33
Chan: godump.RGB{R: 195, G: 154, B: 76},
34
UnsafePointer: godump.RGB{R: 89, G: 193, B: 180},
35
Braces: godump.RGB{R: 185, G: 86, B: 86},
36
}
37
38
return d.Sprint(process(data, Limit))
39
}
40
41
// process is a helper function that processes the variables
42
// and returns a new map of variables
43
func process(data variables, limit int) variables {
44
keys := mapsutil.GetSortedKeys(data)
45
vars := make(variables)
46
47
if limit == 0 {
48
limit = 255
49
}
50
51
for _, k := range keys {
52
v := types.ToString(data[k])
53
v = strings.ReplaceAll(strings.ReplaceAll(v, "\r", " "), "\n", " ")
54
if len(v) > limit {
55
v = v[:limit]
56
v += " [...]"
57
}
58
59
vars[k] = v
60
}
61
62
return vars
63
}
64
65