MCPcopy
hub / github.com/BishopFox/jsluice / NewAnalyzer

Function NewAnalyzer

analyzer.go:23–43  ·  view source on GitHub ↗

NewAnalyzer accepts a slice of bytes representing some JavaScript source code and returns a pointer to a new Analyzer

(source []byte)

Source from the content-addressed store, hash-verified

21// NewAnalyzer accepts a slice of bytes representing some JavaScript
22// source code and returns a pointer to a new Analyzer
23func NewAnalyzer(source []byte) *Analyzer {
24 parser := sitter.NewParser()
25
26 parser.SetLanguage(javascript.GetLanguage())
27
28 if isProbablyHTML(source) {
29 source = extractInlineJS(source)
30 }
31
32 tree := parser.Parse(nil, source)
33
34 // TODO: Align how URLMatcher and SecretMatcher slices
35 // are loaded. At the moment we load URLMatchers now,
36 // and SecretMatchers only when GetSecrets is called.
37 // This is mostly because URL matching was written first,
38 // and then secret matching was added later.
39 return &Analyzer{
40 urlMatchers: AllURLMatchers(),
41 rootNode: NewNode(tree.RootNode(), source),
42 }
43}
44
45// Query peforms a tree-sitter query on the JavaScript being analyzed.
46// The provided function is called once for every node that captured by the query.

Callers 9

runQueryFunction · 0.92
extractURLsFunction · 0.92
extractSecretsFunction · 0.92
formatFunction · 0.92
mainFunction · 0.92
mainFunction · 0.92
mainFunction · 0.92
TestAnalyzerBasicURLsFunction · 0.85
TestAnalyzerBasicSecretsFunction · 0.85

Calls 5

isProbablyHTMLFunction · 0.85
extractInlineJSFunction · 0.85
AllURLMatchersFunction · 0.85
NewNodeFunction · 0.85
RootNodeMethod · 0.80

Tested by 2

TestAnalyzerBasicURLsFunction · 0.68
TestAnalyzerBasicSecretsFunction · 0.68