Use bool variable instead using runtime packages + cosmetics
Signed-off-by: Gaulthier Gain <gaulthier.gain@uliege.be>
This commit is contained in:
parent
597c47c27d
commit
2fd1e898b9
2 changed files with 25 additions and 24 deletions
|
@ -52,25 +52,27 @@ func RunAnalyserTool(homeDir string, data *u.Data) {
|
||||||
// Display Minor Details
|
// Display Minor Details
|
||||||
displayProgramDetails(programName, programPath, args)
|
displayProgramDetails(programName, programPath, args)
|
||||||
|
|
||||||
// Check if the program is a binary
|
|
||||||
|
|
||||||
var elfFile *elf.File
|
var elfFile *elf.File
|
||||||
dynamicCompiled := false
|
isDynamic := false
|
||||||
if strings.ToLower(runtime.GOOS) == "linux" {
|
isLinux := strings.ToLower(runtime.GOOS) == "linux"
|
||||||
elfFile, dynamicCompiled = checkElf(&programPath)
|
|
||||||
|
// Check if the program is a binary
|
||||||
|
if isLinux {
|
||||||
|
elfFile, isDynamic = checkElf(&programPath)
|
||||||
} else if strings.ToLower(runtime.GOOS) == "darwin" {
|
} else if strings.ToLower(runtime.GOOS) == "darwin" {
|
||||||
|
u.PrintWarning("Static analysis is limited on macOS")
|
||||||
checkMachOS(&programPath)
|
checkMachOS(&programPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run static analyser
|
||||||
if typeAnalysis == 0 || typeAnalysis == 1 {
|
if typeAnalysis == 0 || typeAnalysis == 1 {
|
||||||
// Run static analyser
|
|
||||||
u.PrintHeader1("(1.1) RUN STATIC ANALYSIS")
|
u.PrintHeader1("(1.1) RUN STATIC ANALYSIS")
|
||||||
runStaticAnalyser(elfFile, dynamicCompiled, args, programName, programPath, outFolder, data)
|
runStaticAnalyser(elfFile, isDynamic, isLinux, args, programName, programPath, outFolder, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run dynamic analyser
|
// Run dynamic analyser
|
||||||
if typeAnalysis == 0 || typeAnalysis == 2 {
|
if typeAnalysis == 0 || typeAnalysis == 2 {
|
||||||
if strings.ToLower(runtime.GOOS) == "linux" {
|
if isLinux {
|
||||||
u.PrintHeader1("(1.2) RUN DYNAMIC ANALYSIS")
|
u.PrintHeader1("(1.2) RUN DYNAMIC ANALYSIS")
|
||||||
runDynamicAnalyser(args, programName, programPath, outFolder, data)
|
runDynamicAnalyser(args, programName, programPath, outFolder, data)
|
||||||
} else {
|
} else {
|
||||||
|
@ -153,10 +155,10 @@ func checkElf(programPath *string) (*elf.File, bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// runStaticAnalyser runs the static analyser
|
// runStaticAnalyser runs the static analyser
|
||||||
func runStaticAnalyser(elfFile *elf.File, dynamicCompiled bool, args *u.Arguments, programName, programPath,
|
func runStaticAnalyser(elfFile *elf.File, isDynamic, isLinux bool, args *u.Arguments, programName, programPath,
|
||||||
outFolder string, data *u.Data) {
|
outFolder string, data *u.Data) {
|
||||||
|
|
||||||
staticAnalyser(elfFile, dynamicCompiled, *args, data, programPath)
|
staticAnalyser(elfFile, isDynamic, isLinux, *args, data, programPath)
|
||||||
|
|
||||||
// Save static Data into text file if display mode is set
|
// Save static Data into text file if display mode is set
|
||||||
if *args.BoolArg[saveOutputArg] {
|
if *args.BoolArg[saveOutputArg] {
|
||||||
|
|
|
@ -11,8 +11,6 @@ import (
|
||||||
"debug/elf"
|
"debug/elf"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
|
||||||
"strings"
|
|
||||||
u "tools/srcs/common"
|
u "tools/srcs/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -192,7 +190,7 @@ func executeDependAptCache(programName string, data *u.StaticData,
|
||||||
// staticAnalyser runs the static analysis to get shared libraries,
|
// staticAnalyser runs the static analysis to get shared libraries,
|
||||||
// system calls and library calls of a given application.
|
// system calls and library calls of a given application.
|
||||||
//
|
//
|
||||||
func staticAnalyser(elfFile *elf.File, dynamicCompiled bool, args u.Arguments, data *u.Data, programPath string) {
|
func staticAnalyser(elfFile *elf.File, isDynamic, isLinux bool, args u.Arguments, data *u.Data, programPath string) {
|
||||||
|
|
||||||
programName := *args.StringArg[programArg]
|
programName := *args.StringArg[programArg]
|
||||||
fullDeps := *args.BoolArg[fullDepsArg]
|
fullDeps := *args.BoolArg[fullDepsArg]
|
||||||
|
@ -202,41 +200,42 @@ func staticAnalyser(elfFile *elf.File, dynamicCompiled bool, args u.Arguments, d
|
||||||
|
|
||||||
// If the program is a binary, runs static analysis tools
|
// If the program is a binary, runs static analysis tools
|
||||||
if len(programPath) > 0 {
|
if len(programPath) > 0 {
|
||||||
// Gather Data from binary file
|
|
||||||
|
|
||||||
// Init symbols members
|
// Init symbols members
|
||||||
staticData.Symbols = make(map[string]string)
|
staticData.Symbols = make(map[string]string)
|
||||||
staticData.SystemCalls = make(map[string]int)
|
staticData.SystemCalls = make(map[string]int)
|
||||||
staticData.SharedLibs = make(map[string][]string)
|
staticData.SharedLibs = make(map[string][]string)
|
||||||
|
|
||||||
if strings.ToLower(runtime.GOOS) == "linux" {
|
if isLinux {
|
||||||
|
// Gather Data from binary file
|
||||||
u.PrintHeader2("(*) Gathering symbols from binary file")
|
u.PrintHeader2("(*) Gathering symbols from binary file")
|
||||||
if err := gatherStaticSymbols(elfFile, dynamicCompiled, staticData); err != nil {
|
if err := gatherStaticSymbols(elfFile, isDynamic, staticData); err != nil {
|
||||||
u.PrintWarning(err)
|
u.PrintWarning(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
u.PrintHeader2("(*) Gathering shared libraries from binary file")
|
u.PrintHeader2("(*) Gathering shared libraries from binary file")
|
||||||
if strings.ToLower(runtime.GOOS) == "linux" {
|
if isLinux {
|
||||||
// Cannot use "elfFile.ImportedLibraries()" since we need the .so path
|
// Cannot use "elfFile.ImportedLibraries()" since we need the ".so" path
|
||||||
|
// So in that case, we need to rely on ldd
|
||||||
if err := gatherStaticSharedLibsLinux(programPath, staticData,
|
if err := gatherStaticSharedLibsLinux(programPath, staticData,
|
||||||
fullDeps); err != nil {
|
fullDeps); err != nil {
|
||||||
u.PrintWarning(err)
|
u.PrintWarning(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := elfFile.Close(); err != nil {
|
||||||
|
u.PrintWarning(err)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if err := gatherStaticSharedLibsMac(programPath, staticData,
|
if err := gatherStaticSharedLibsMac(programPath, staticData,
|
||||||
fullDeps); err != nil {
|
fullDeps); err != nil {
|
||||||
u.PrintWarning(err)
|
u.PrintWarning(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := elfFile.Close(); err != nil {
|
|
||||||
u.PrintWarning(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detect symbols from shared libraries
|
// Detect symbols from shared libraries
|
||||||
if fullStaticAnalysis {
|
if fullStaticAnalysis && isLinux {
|
||||||
u.PrintHeader2("(*) Gathering symbols and system calls of shared libraries from binary file")
|
u.PrintHeader2("(*) Gathering symbols and system calls of shared libraries from binary file")
|
||||||
for key, path := range staticData.SharedLibs {
|
for key, path := range staticData.SharedLibs {
|
||||||
if len(path) > 0 {
|
if len(path) > 0 {
|
||||||
|
@ -255,7 +254,7 @@ func staticAnalyser(elfFile *elf.File, dynamicCompiled bool, args u.Arguments, d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.ToLower(runtime.GOOS) == "linux" {
|
if isLinux {
|
||||||
// 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")
|
||||||
if err := gatherDependencies(programName, staticData, fullDeps); err != nil {
|
if err := gatherDependencies(programName, staticData, fullDeps); err != nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue