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
|
@ -20,6 +20,8 @@ const (
|
|||
waitTimeArg = "waitTime"
|
||||
saveOutputArg = "saveOutput"
|
||||
fullDepsArg = "fullDeps"
|
||||
fullStaticAnalysis = "fullStaticAnalysis"
|
||||
typeAnalysis = "typeAnalysis"
|
||||
)
|
||||
|
||||
// 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,
|
||||
&argparse.Options{Required: false, Default: false,
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package dependtool
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/fatih/color"
|
||||
"runtime"
|
||||
|
@ -26,6 +27,12 @@ func RunAnalyserTool(homeDir string, data *u.Data) {
|
|||
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
|
||||
programPath, err := u.GetProgramPath(&*args.StringArg[programArg])
|
||||
if err != nil {
|
||||
|
@ -51,11 +58,14 @@ func RunAnalyserTool(homeDir string, data *u.Data) {
|
|||
checkMachOS(&programPath)
|
||||
}
|
||||
|
||||
if typeAnalysis == 0 || typeAnalysis == 1 {
|
||||
// Run static analyser
|
||||
u.PrintHeader1("(1.1) RUN STATIC ANALYSIS")
|
||||
runStaticAnalyser(args, programName, programPath, outFolder, data)
|
||||
}
|
||||
|
||||
// Run dynamic analyser
|
||||
if typeAnalysis == 0 || typeAnalysis == 2 {
|
||||
if strings.ToLower(runtime.GOOS) == "linux" {
|
||||
u.PrintHeader1("(1.2) RUN DYNAMIC ANALYSIS")
|
||||
runDynamicAnalyser(args, programName, programPath, outFolder, data)
|
||||
|
@ -63,6 +73,7 @@ func RunAnalyserTool(homeDir string, data *u.Data) {
|
|||
// dtruss/dtrace on mac needs to disable system integrity protection
|
||||
u.PrintWarning("Dynamic analysis is not currently supported on macOS")
|
||||
}
|
||||
}
|
||||
|
||||
// Save Data to JSON
|
||||
if err = u.RecordDataJson(outFolder+programName, data); err != nil {
|
||||
|
|
|
@ -181,6 +181,7 @@ func staticAnalyser(args u.Arguments, data *u.Data, programPath string) {
|
|||
|
||||
programName := *args.StringArg[programArg]
|
||||
fullDeps := *args.BoolArg[fullDepsArg]
|
||||
fullStaticAnalysis := *args.BoolArg[fullStaticAnalysis]
|
||||
|
||||
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" {
|
||||
// Gather Data from apt-cache
|
||||
u.PrintHeader2("(*) Gathering dependencies from apt-cache depends")
|
||||
|
|
Loading…
Add table
Reference in a new issue