Skip to content

Commit

Permalink
implemented the Amass Scripting Engine
Browse files Browse the repository at this point in the history
  • Loading branch information
caffix committed Jun 5, 2020
1 parent a6816c7 commit 1c3e0fb
Show file tree
Hide file tree
Showing 5 changed files with 534 additions and 7 deletions.
37 changes: 37 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"io/ioutil"
"log"
"net"
"os"
"path/filepath"
"regexp"
"strings"
"sync"
Expand Down Expand Up @@ -623,3 +625,38 @@ func (c *Config) loadResolverSettings(cfg *ini.File) error {
func (c *Config) UpdateConfig(update Updater) error {
return update.OverrideConfig(c)
}

// AcquireScripts returns all the default and user provided scripts for data sources.
func (c *Config) AcquireScripts() ([]string, error) {
scripts := getDefaultScripts()

dir := OutputDirectory(c.Dir)
if dir == "" {
return scripts, nil
}

finfo, err := os.Stat(dir)
if os.IsNotExist(err) || !finfo.IsDir() {
return scripts, errors.New("The output directory does not exist or is not a directory")
}

filepath.Walk(filepath.Join(dir, "scripts"), func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
// Is this file not a script?
if info.IsDir() || filepath.Ext(info.Name()) != ".ads" {
return nil
}
// Get the script content
data, err := ioutil.ReadFile(path)
if err != nil {
return err
}

scripts = append(scripts, string(data))
return nil
})

return scripts, nil
}
8 changes: 5 additions & 3 deletions config/statik/statik.go

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions config/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,28 @@ func uniqueIntAppend(s []int, e string) []int {
}
return s
}

func getDefaultScripts() []string {
fsOnce.Do(openTheFS)

var scripts []string
fs.Walk(StatikFS, "/scripts", func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
// Is this file not a script?
if info.IsDir() || filepath.Ext(info.Name()) != ".ads" {
return nil
}
// Get the script content
data, err := fs.ReadFile(StatikFS, path)
if err != nil {
return err
}

scripts = append(scripts, string(data))
return nil
})

return scripts
}

0 comments on commit 1c3e0fb

Please sign in to comment.