Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/js/global/helpers.go
2070 views
1
package global
2
3
import (
4
"encoding/base64"
5
6
"github.com/Mzack9999/goja"
7
"github.com/projectdiscovery/nuclei/v3/pkg/js/gojs"
8
)
9
10
func registerAdditionalHelpers(runtime *goja.Runtime) {
11
_ = gojs.RegisterFuncWithSignature(runtime, gojs.FuncOpts{
12
Name: "atob",
13
Signatures: []string{
14
"atob(string) string",
15
},
16
Description: "Base64 decodes a given string",
17
FuncDecl: func(call goja.FunctionCall) goja.Value {
18
input := call.Argument(0).String()
19
20
decoded, err := base64.StdEncoding.DecodeString(input)
21
if err != nil {
22
return goja.Null()
23
}
24
return runtime.ToValue(string(decoded))
25
},
26
})
27
28
_ = gojs.RegisterFuncWithSignature(runtime, gojs.FuncOpts{
29
Name: "btoa",
30
Signatures: []string{
31
"bota(string) string",
32
},
33
Description: "Base64 encodes a given string",
34
FuncDecl: func(call goja.FunctionCall) goja.Value {
35
input := call.Argument(0).String()
36
encoded := base64.StdEncoding.EncodeToString([]byte(input))
37
return runtime.ToValue(encoded)
38
},
39
})
40
}
41
42
func init() {
43
// these are dummy functions we use trigger documentation generation
44
// actual definations are in exports.js
45
_ = gojs.RegisterFuncWithSignature(nil, gojs.FuncOpts{
46
Name: "to_json",
47
Signatures: []string{
48
"to_json(any) object",
49
},
50
Description: "Converts a given object to JSON",
51
})
52
53
_ = gojs.RegisterFuncWithSignature(nil, gojs.FuncOpts{
54
Name: "dump_json",
55
Signatures: []string{
56
"dump_json(any)",
57
},
58
Description: "Prints a given object as JSON in console",
59
})
60
61
_ = gojs.RegisterFuncWithSignature(nil, gojs.FuncOpts{
62
Name: "to_array",
63
Signatures: []string{
64
"to_array(any) array",
65
},
66
Description: "Sets/Updates objects prototype to array to enable Array.XXX functions",
67
})
68
69
_ = gojs.RegisterFuncWithSignature(nil, gojs.FuncOpts{
70
Name: "hex_to_ascii",
71
Signatures: []string{
72
"hex_to_ascii(string) string",
73
},
74
Description: "Converts a given hex string to ascii",
75
})
76
77
}
78
79