Debian Codegraph @

caplets/caplet.go

raw symbols SCIP
1 package capletsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/
2
3 import (
4 "fmtscip-go gomod github.com/golang/go/src go1.16 fmt/"
5 "path/filepathscip-go gomod github.com/golang/go/src go1.16 `path/filepath`/"
6 "stringsscip-go gomod github.com/golang/go/src go1.16 strings/"
7
8 "github.com/evilsocket/islazy/fsscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/fs`/"
9 )
10
11 type Scriptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Script# struct {
12 Pathscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Script#Path. string `json:"path"`
13 Sizescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Script#Size. int64 `json:"size"`
14 Codescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Script#Code. []string `json:"code"`
15 }
16
17 func newScriptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/newScript().(path string, size int64) Scriptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Script# {
18 return Scriptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Script#{
19 Pathscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Script#Path.: path,
20 Sizescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Script#Size.: size,
21 Codescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Script#Code.: make([]string, 0),
22 }
23 }
24
25 type Capletscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Caplet# struct {
26 Scriptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Caplet#Script.
27 Namescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Caplet#Name. string `json:"name"`
28 Scriptsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Caplet#Scripts. []Scriptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Script# `json:"scripts"`
29 }
30
31 func NewCapletscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/NewCaplet().(name string, path string, size int64) Capletscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Caplet# {
32 return Capletscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Caplet#{
33 Scriptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Caplet#Script.: newScriptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/newScript().(path, size),
34 Namescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Caplet#Name.: name,
35 Scriptsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Caplet#Scripts.: make([]Scriptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Script#, 0),
36 }
37 }
38
39 func (cap *Capletscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Caplet#) Evalscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Caplet#Eval().(argv []string, lineCb func(line string) error) error {
40 if argv == nil {
41 argv = []string{}
42 }
43 // the caplet might include other files (include directive, proxy modules, etc),
44 // temporarily change the working directory
45 return fsscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/fs`/.Chdirscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/fs`/Chdir().(filepathscip-go gomod github.com/golang/go/src go1.16 `path/filepath`/.Dirscip-go gomod github.com/golang/go/src go1.16 `path/filepath`/Dir().(cap.Pathscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Script#Path.), func() error {
46 for _, line := range cap.Codescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/caplets`/Script#Code. {
47 // skip empty lines and comments
48 if line == "" || line[0] == '#' {
49 continue
50 }
51 // replace $0 with argv[0], $1 with argv[1] and so on
52 for i, arg := range argv {
53 what := fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().("$%d", i)
54 line = stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Replacescip-go gomod github.com/golang/go/src go1.16 strings/Replace().(line, what, arg, -1)
55 }
56
57 if err := lineCb(line); err != nil {
58 return err
59 }
60 }
61 return nil
62 })
63 }