Documentation ¶
Index ¶
- Constants
- func CapabilityGraph(pkgs []*packages.Package, queriedPackages map[*types.Package]struct{}, ...)
- func GetCapabilityCounts(pkgs []*packages.Package, queriedPackages map[*types.Package]struct{}, ...) *cpb.CapabilityCountList
- func GetCapabilityInfo(pkgs []*packages.Package, queriedPackages map[*types.Package]struct{}, ...) *cpb.CapabilityInfoList
- func GetCapabilityStats(pkgs []*packages.Package, queriedPackages map[*types.Package]struct{}, ...) *cpb.CapabilityStatList
- func GetClassifier(excludeUnanalyzed bool) *interesting.Classifier
- func GetQueriedPackages(pkgs []*packages.Package) map[*types.Package]struct{}
- func LoadPackages(packageNames []string, lcfg LoadConfig) ([]*packages.Package, error)
- func RunCapslock(args []string, output string, pkgs []*packages.Package, ...) error
- type CapabilityCounter
- type Classifier
- type Config
- type LoadConfig
Constants ¶
const PackagesLoadModeNeeded packages.LoadMode = packages.NeedName | packages.NeedFiles | packages.NeedCompiledGoFiles | packages.NeedImports | packages.NeedDeps | packages.NeedTypes | packages.NeedSyntax | packages.NeedTypesInfo | packages.NeedTypesSizes | packages.NeedModule
PackagesLoadModeNeeded is a packages.LoadMode that has all the bits set for the information that this package uses to perform its analysis. Users should load packages for analysis using this LoadMode (or a superset.)
Variables ¶
This section is empty.
Functions ¶
func CapabilityGraph ¶
func CapabilityGraph(pkgs []*packages.Package, queriedPackages map[*types.Package]struct{}, config *Config, outputCall func(from, to *callgraph.Node), outputCapability func(fn *callgraph.Node, c cpb.Capability), )
CapabilityGraph analyzes the callgraph for the packages in pkgs.
It outputs the graph containing all paths from a function belonging to one of the packages in queriedPackages to a function which has some capability.
outputCall is called for each edge between two nodes. outputCapability is called for each node in the graph that has some capability.
func GetCapabilityCounts ¶
func GetCapabilityCounts(pkgs []*packages.Package, queriedPackages map[*types.Package]struct{}, config *Config) *cpb.CapabilityCountList
GetCapabilityCount analyzes the packages in pkgs. For each function in those packages which have a path in the callgraph to an "interesting" function (see the "interesting" package), we give an aggregate count of the capability usage.
func GetCapabilityInfo ¶
func GetCapabilityInfo(pkgs []*packages.Package, queriedPackages map[*types.Package]struct{}, config *Config) *cpb.CapabilityInfoList
GetCapabilityInfo analyzes the packages in pkgs. For each function in those packages which have a path in the callgraph to an "interesting" function (see the "interesting" package), we log details of the capability usage.
One CapabilityInfo is returned for every (function, capability) pair, with one example path in the callgraph that demonstrates that capability.
func GetCapabilityStats ¶
func GetCapabilityStats(pkgs []*packages.Package, queriedPackages map[*types.Package]struct{}, config *Config) *cpb.CapabilityStatList
GetCapabilityStats analyzes the packages in pkgs. For each function in those packages which have a path in the callgraph to an "interesting" function (see the "interesting" package), we give aggregated statistics about the capability usage.
func GetClassifier ¶
func GetClassifier(excludeUnanalyzed bool) *interesting.Classifier
GetClassifier returns a classifier for mapping packages and functions to the appropriate capability. If excludedUnanalyzed is true, the UNANALYZED capability is never returned.
func GetQueriedPackages ¶
GetQueriedPackages builds a set of *types.Package matching the input query so that we can limit the output to only functions in these packages, not their dependencies too.
func LoadPackages ¶
func LoadPackages(packageNames []string, lcfg LoadConfig) ([]*packages.Package, error)
Types ¶
type CapabilityCounter ¶
type CapabilityCounter struct {
// contains filtered or unexported fields
}
type Classifier ¶ added in v0.2.0
type Classifier interface { // FunctionCategory returns a Category for the given function specified by // a package name and function name. Examples of function names include // "math.Cos", "(time.Time).Clock", and "(*sync.Cond).Signal". // // If the return value is Unspecified, then we have not declared it to be // either safe or unsafe, so its descendants will have to be considered by the // static analysis. FunctionCategory(pkg string, name string) cpb.Capability // IncludeCall returns true if a call from one function to another should be // considered when searching for transitive capabilities. Usually this should // return true, unless there is some reason to know that the particular call // cannot lead to additional capabilities for a function. IncludeCall(caller string, callee string) bool }
Classifier is an interface for types that help map code features to capabilities.
type Config ¶ added in v0.2.0
type Config struct { Classifier Classifier DisableBuiltin bool }
Config holds configuration for the analyzer.
type LoadConfig ¶
LoadConfig specifies the build tags, GOOS value, and GOARCH value to use when loading packages. These will be used to determine when a file's build constraint is satisfied. See https://pkg.go.dev/cmd/go#hdr-Build_constraints for more information.