mirror of
https://github.com/safing/portmaster
synced 2025-09-01 18:19:12 +00:00
Improve Interpreter matching
This commit is contained in:
parent
130cc40fea
commit
4940280737
1 changed files with 23 additions and 8 deletions
|
@ -7,10 +7,12 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/google/shlex"
|
"github.com/google/shlex"
|
||||||
|
|
||||||
|
"github.com/safing/portbase/utils/osdetail"
|
||||||
"github.com/safing/portmaster/process"
|
"github.com/safing/portmaster/process"
|
||||||
"github.com/safing/portmaster/profile"
|
"github.com/safing/portmaster/profile"
|
||||||
)
|
)
|
||||||
|
@ -24,7 +26,8 @@ func init() {
|
||||||
type interpType struct {
|
type interpType struct {
|
||||||
process.TagDescription
|
process.TagDescription
|
||||||
|
|
||||||
Regex *regexp.Regexp
|
Extensions []string
|
||||||
|
Regex *regexp.Regexp
|
||||||
}
|
}
|
||||||
|
|
||||||
var knownInterperters = []interpType{
|
var knownInterperters = []interpType{
|
||||||
|
@ -33,35 +36,40 @@ var knownInterperters = []interpType{
|
||||||
ID: "python-script",
|
ID: "python-script",
|
||||||
Name: "Python Script",
|
Name: "Python Script",
|
||||||
},
|
},
|
||||||
Regex: regexp.MustCompile(`^(/usr)?/bin/python[23]\.[0-9]+$`),
|
Extensions: []string{".py", ".py2", ".py3"},
|
||||||
|
Regex: regexp.MustCompile(`^(/usr)?/bin/python[23](\.[0-9]+)?$`),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
TagDescription: process.TagDescription{
|
TagDescription: process.TagDescription{
|
||||||
ID: "shell-script",
|
ID: "shell-script",
|
||||||
Name: "Shell Script",
|
Name: "Shell Script",
|
||||||
},
|
},
|
||||||
Regex: regexp.MustCompile(`^(/usr)?/bin/(ba|k|z|a)?sh$`),
|
Extensions: []string{".sh", ".bash", ".ksh", ".zsh", ".ash"},
|
||||||
|
Regex: regexp.MustCompile(`^(/usr)?/bin/(ba|k|z|a)?sh$`),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
TagDescription: process.TagDescription{
|
TagDescription: process.TagDescription{
|
||||||
ID: "perl-script",
|
ID: "perl-script",
|
||||||
Name: "Perl Script",
|
Name: "Perl Script",
|
||||||
},
|
},
|
||||||
Regex: regexp.MustCompile(`^(/usr)?/bin/perl$`),
|
Extensions: []string{".pl"},
|
||||||
|
Regex: regexp.MustCompile(`^(/usr)?/bin/perl$`),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
TagDescription: process.TagDescription{
|
TagDescription: process.TagDescription{
|
||||||
ID: "ruby-script",
|
ID: "ruby-script",
|
||||||
Name: "Ruby Script",
|
Name: "Ruby Script",
|
||||||
},
|
},
|
||||||
Regex: regexp.MustCompile(`^(/usr)?/bin/ruby$`),
|
Extensions: []string{".rb"},
|
||||||
|
Regex: regexp.MustCompile(`^(/usr)?/bin/ruby$`),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
TagDescription: process.TagDescription{
|
TagDescription: process.TagDescription{
|
||||||
ID: "nodejs-script",
|
ID: "nodejs-script",
|
||||||
Name: "NodeJS Script",
|
Name: "NodeJS Script",
|
||||||
},
|
},
|
||||||
Regex: regexp.MustCompile(`^(/usr)?/bin/node(js)?$`),
|
Extensions: []string{".js"},
|
||||||
|
Regex: regexp.MustCompile(`^(/usr)?/bin/node(js)?$`),
|
||||||
},
|
},
|
||||||
/*
|
/*
|
||||||
While similar to nodejs, electron is a bit harder as it uses a multiple processes
|
While similar to nodejs, electron is a bit harder as it uses a multiple processes
|
||||||
|
@ -148,16 +156,23 @@ func (h *InterpHandler) CreateProfile(p *process.Process) *profile.Profile {
|
||||||
args = args[1:]
|
args = args[1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a nice script name from filename.
|
||||||
|
scriptName := filepath.Base(args[0])
|
||||||
|
for _, ext := range it.Extensions {
|
||||||
|
scriptName, _ = strings.CutSuffix(scriptName, ext)
|
||||||
|
}
|
||||||
|
scriptName = osdetail.GenerateBinaryNameFromPath(scriptName)
|
||||||
|
|
||||||
return profile.New(&profile.Profile{
|
return profile.New(&profile.Profile{
|
||||||
Source: profile.SourceLocal,
|
Source: profile.SourceLocal,
|
||||||
Name: fmt.Sprintf("%s: %s", it.Name, args[0]),
|
Name: fmt.Sprintf("%s: %s", it.Name, scriptName),
|
||||||
PresentationPath: tag.Value,
|
PresentationPath: tag.Value,
|
||||||
UsePresentationPath: true,
|
UsePresentationPath: true,
|
||||||
Fingerprints: []profile.Fingerprint{
|
Fingerprints: []profile.Fingerprint{
|
||||||
{
|
{
|
||||||
Type: profile.FingerprintTypeTagID,
|
Type: profile.FingerprintTypeTagID,
|
||||||
Operation: profile.FingerprintOperationEqualsID,
|
|
||||||
Key: it.ID,
|
Key: it.ID,
|
||||||
|
Operation: profile.FingerprintOperationEqualsID,
|
||||||
Value: tag.Value,
|
Value: tag.Value,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Reference in a new issue