Add analysis argument to further handle the analysis
Signed-off-by: Gaulthier Gain <gaulthier.gain@uliege.be>
This commit is contained in:
parent
4425c80017
commit
0031a3612a
3 changed files with 55 additions and 16 deletions
|
@ -13,13 +13,15 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
programArg = "program"
|
programArg = "program"
|
||||||
testFileArg = "testFile"
|
testFileArg = "testFile"
|
||||||
configFileArg = "configFile"
|
configFileArg = "configFile"
|
||||||
optionsArg = "options"
|
optionsArg = "options"
|
||||||
waitTimeArg = "waitTime"
|
waitTimeArg = "waitTime"
|
||||||
saveOutputArg = "saveOutput"
|
saveOutputArg = "saveOutput"
|
||||||
fullDepsArg = "fullDeps"
|
fullDepsArg = "fullDeps"
|
||||||
|
fullStaticAnalysis = "fullStaticAnalysis"
|
||||||
|
typeAnalysis = "typeAnalysis"
|
||||||
)
|
)
|
||||||
|
|
||||||
// parseLocalArguments parses arguments of the application.
|
// parseLocalArguments parses arguments of the application.
|
||||||
|
@ -45,6 +47,12 @@ func parseLocalArguments(p *argparse.Parser, args *u.Arguments) error {
|
||||||
args.InitArgParse(p, args, u.BOOL, "", fullDepsArg,
|
args.InitArgParse(p, args, u.BOOL, "", fullDepsArg,
|
||||||
&argparse.Options{Required: false, Default: false,
|
&argparse.Options{Required: false, Default: false,
|
||||||
Help: "Show dependencies of dependencies"})
|
Help: "Show dependencies of dependencies"})
|
||||||
|
args.InitArgParse(p, args, u.BOOL, "", fullStaticAnalysis,
|
||||||
|
&argparse.Options{Required: false, Default: false,
|
||||||
|
Help: "Full static analysis (analyse shared libraries too)"})
|
||||||
|
args.InitArgParse(p, args, u.INT, "", typeAnalysis,
|
||||||
|
&argparse.Options{Required: false, Default: 0,
|
||||||
|
Help: "Kind of analysis (0: both; 1: static; 2: dynamic)"})
|
||||||
|
|
||||||
return u.ParserWrapper(p, os.Args)
|
return u.ParserWrapper(p, os.Args)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package dependtool
|
package dependtool
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
@ -26,6 +27,12 @@ func RunAnalyserTool(homeDir string, data *u.Data) {
|
||||||
u.PrintErr(err)
|
u.PrintErr(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the kind of analysis (0: both; 1: static; 2: dynamic)
|
||||||
|
typeAnalysis := *args.IntArg[typeAnalysis]
|
||||||
|
if typeAnalysis < 0 || typeAnalysis > 2 {
|
||||||
|
u.PrintErr(errors.New("analysis argument must be between [0,2]"))
|
||||||
|
}
|
||||||
|
|
||||||
// Get program path
|
// Get program path
|
||||||
programPath, err := u.GetProgramPath(&*args.StringArg[programArg])
|
programPath, err := u.GetProgramPath(&*args.StringArg[programArg])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -51,17 +58,21 @@ func RunAnalyserTool(homeDir string, data *u.Data) {
|
||||||
checkMachOS(&programPath)
|
checkMachOS(&programPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run static analyser
|
if typeAnalysis == 0 || typeAnalysis == 1 {
|
||||||
u.PrintHeader1("(1.1) RUN STATIC ANALYSIS")
|
// Run static analyser
|
||||||
runStaticAnalyser(args, programName, programPath, outFolder, data)
|
u.PrintHeader1("(1.1) RUN STATIC ANALYSIS")
|
||||||
|
runStaticAnalyser(args, programName, programPath, outFolder, data)
|
||||||
|
}
|
||||||
|
|
||||||
// Run dynamic analyser
|
// Run dynamic analyser
|
||||||
if strings.ToLower(runtime.GOOS) == "linux" {
|
if typeAnalysis == 0 || typeAnalysis == 2 {
|
||||||
u.PrintHeader1("(1.2) RUN DYNAMIC ANALYSIS")
|
if strings.ToLower(runtime.GOOS) == "linux" {
|
||||||
runDynamicAnalyser(args, programName, programPath, outFolder, data)
|
u.PrintHeader1("(1.2) RUN DYNAMIC ANALYSIS")
|
||||||
} else {
|
runDynamicAnalyser(args, programName, programPath, outFolder, data)
|
||||||
// dtruss/dtrace on mac needs to disable system integrity protection
|
} else {
|
||||||
u.PrintWarning("Dynamic analysis is not currently supported on macOS")
|
// dtruss/dtrace on mac needs to disable system integrity protection
|
||||||
|
u.PrintWarning("Dynamic analysis is not currently supported on macOS")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save Data to JSON
|
// Save Data to JSON
|
||||||
|
|
|
@ -181,6 +181,7 @@ func staticAnalyser(args u.Arguments, data *u.Data, programPath string) {
|
||||||
|
|
||||||
programName := *args.StringArg[programArg]
|
programName := *args.StringArg[programArg]
|
||||||
fullDeps := *args.BoolArg[fullDepsArg]
|
fullDeps := *args.BoolArg[fullDepsArg]
|
||||||
|
fullStaticAnalysis := *args.BoolArg[fullStaticAnalysis]
|
||||||
|
|
||||||
staticData := &data.StaticData
|
staticData := &data.StaticData
|
||||||
|
|
||||||
|
@ -222,6 +223,25 @@ func staticAnalyser(args u.Arguments, data *u.Data, programPath string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Detect symbols from shared libraries
|
||||||
|
if fullStaticAnalysis {
|
||||||
|
u.PrintHeader2("(*) Gathering symbols and system calls of shared libraries from binary file")
|
||||||
|
for key, path := range staticData.SharedLibs {
|
||||||
|
if len(path) > 0 {
|
||||||
|
fmt.Printf("\t-> Analysing %s - %s\n", key, path[0])
|
||||||
|
if err := gatherStaticSymbols(path[0], staticData); err != nil {
|
||||||
|
u.PrintWarning(err)
|
||||||
|
}
|
||||||
|
if err := gatherStaticSystemCalls(path[0], "-D", staticData); err != nil {
|
||||||
|
// Check without the dynamic argument
|
||||||
|
if err := gatherStaticSystemCalls(path[0], "", staticData); err != nil {
|
||||||
|
u.PrintWarning(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if strings.ToLower(runtime.GOOS) == "linux" {
|
if strings.ToLower(runtime.GOOS) == "linux" {
|
||||||
// Gather Data from apt-cache
|
// Gather Data from apt-cache
|
||||||
u.PrintHeader2("(*) Gathering dependencies from apt-cache depends")
|
u.PrintHeader2("(*) Gathering dependencies from apt-cache depends")
|
||||||
|
|
Loading…
Add table
Reference in a new issue