From 95be60884c7fc7cc9153e24647756592dff94707 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donncha=20=C3=93=20Cearbhaill?= Date: Fri, 22 Dec 2023 16:47:28 +0100 Subject: [PATCH] Add version information in CLI and output (#40) * Add version information in CLI and output * Add missing file and remove TODO note --- Makefile | 14 +++++++++----- acquisition/acquisition.go | 17 ++++++++++------- main.go | 10 +++++++++- utils/build.go | 4 ++++ 4 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 utils/build.go diff --git a/Makefile b/Makefile index d23481e..bb1b9d9 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,13 @@ BUILD_FOLDER = "$(shell pwd)/build" ASSETS_FOLDER = "$(shell pwd)/assets" +VERSION := $(shell git describe --always --long --dirty) +PACKAGE_PATH = github.com/mvt-project/androidqf + FLAGS_LINUX = GOOS=linux FLAGS_DARWIN = GOOS=darwin FLAGS_WINDOWS = GOOS=windows GOARCH=amd64 CC=i686-w64-mingw32-gcc CGO_ENABLED=1 +LD_FLAGS = -s -w -X ${PACKAGE_PATH}/utils.Version=${VERSION} # Set if binaries should be compressed with UPX. Zero disables UPX UPX_COMPRESS ?= "0" @@ -57,7 +61,7 @@ windows: @echo "[builder] Building Windows binary for amd64" - $(FLAGS_WINDOWS) go build --ldflags '-s -w -extldflags "-static"' -o $(BUILD_FOLDER)/androidqf_windows_amd64.exe . + $(FLAGS_WINDOWS) go build --ldflags '$(LD_FLAGS) -extldflags "-static"' -o $(BUILD_FOLDER)/androidqf_windows_amd64.exe . @echo "[builder] Done!" @@ -75,8 +79,8 @@ darwin: @echo "[builder] Building Darwin binary for amd64" - $(FLAGS_DARWIN) GOARCH=amd64 go build --ldflags '-s -w' -o $(BUILD_FOLDER)/androidqf_darwin_amd64 . - $(FLAGS_DARWIN) GOARCH=arm64 go build --ldflags '-s -w' -o $(BUILD_FOLDER)/androidqf_darwin_arm64 . + $(FLAGS_DARWIN) GOARCH=amd64 go build --ldflags '$(LD_FLAGS)' -o $(BUILD_FOLDER)/androidqf_darwin_amd64 . + $(FLAGS_DARWIN) GOARCH=arm64 go build --ldflags '$(LD_FLAGS)' -o $(BUILD_FOLDER)/androidqf_darwin_arm64 . @echo "[builder] Done!" @@ -94,8 +98,8 @@ linux: @echo "[builder] Building Linux binary for amd64" - @$(FLAGS_LINUX) GOARCH=amd64 go build --ldflags '-s -w' -o $(BUILD_FOLDER)/androidqf_linux_amd64 . - @$(FLAGS_LINUX) GOARCH=arm64 go build --ldflags '-s -w' -o $(BUILD_FOLDER)/androidqf_linux_arm64 . + @$(FLAGS_LINUX) GOARCH=amd64 go build --ldflags '$(LD_FLAGS)' -o $(BUILD_FOLDER)/androidqf_linux_amd64 . + @$(FLAGS_LINUX) GOARCH=arm64 go build --ldflags '$(LD_FLAGS)' -o $(BUILD_FOLDER)/androidqf_linux_arm64 . @echo "[builder] Done!" diff --git a/acquisition/acquisition.go b/acquisition/acquisition.go index 455b5c3..791fd10 100644 --- a/acquisition/acquisition.go +++ b/acquisition/acquisition.go @@ -20,17 +20,19 @@ import ( "github.com/mvt-project/androidqf/adb" "github.com/mvt-project/androidqf/assets" "github.com/mvt-project/androidqf/log" + "github.com/mvt-project/androidqf/utils" ) // Acquisition is the main object containing all phone information type Acquisition struct { - UUID string `json:"uuid"` - StoragePath string `json:"storage_path"` - Started time.Time `json:"started"` - Completed time.Time `json:"completed"` - Collector *adb.Collector `json:"collector"` - TmpDir string `json:"tmp_dir"` - Cpu string `json:"cpu"` + UUID string `json:"uuid"` + AndroidQFVersion string `json:"androidqf_version"` + StoragePath string `json:"storage_path"` + Started time.Time `json:"started"` + Completed time.Time `json:"completed"` + Collector *adb.Collector `json:"collector"` + TmpDir string `json:"tmp_dir"` + Cpu string `json:"cpu"` } // New returns a new Acquisition instance. @@ -38,6 +40,7 @@ func New() (*Acquisition, error) { acq := Acquisition{ UUID: uuid.New().String(), Started: time.Now().UTC(), + AndroidQFVersion: utils.Version, } acq.StoragePath = filepath.Join(rt.GetExecutableDirectory(), acq.UUID) diff --git a/main.go b/main.go index fe78d7d..187fc6e 100644 --- a/main.go +++ b/main.go @@ -16,6 +16,7 @@ import ( "github.com/mvt-project/androidqf/adb" "github.com/mvt-project/androidqf/log" "github.com/mvt-project/androidqf/modules" + "github.com/mvt-project/androidqf/utils" ) func init() { @@ -39,6 +40,7 @@ func systemPause() { func main() { var err error var verbose bool + var version_flag bool var list_modules bool var fast bool var module string @@ -52,11 +54,18 @@ func main() { flag.BoolVar(&list_modules, "l", false, "List modules and exit") flag.StringVar(&module, "module", "", "Only execute a specific module") flag.StringVar(&module, "m", "", "Only execute a specific module") + flag.BoolVar(&version_flag, "version", false, "Show version") + flag.Parse() if verbose { log.SetLogLevel(log.DEBUG) } + if version_flag { + log.Infof("AndroidQF version: %s", utils.Version) + os.Exit(0) + } + if list_modules { mods := modules.List() log.Info("List of modules:") @@ -66,7 +75,6 @@ func main() { os.Exit(0) } - // TODO: add version information log.Debug("Starting androidqf") adb.Client, err = adb.New() if err != nil { diff --git a/utils/build.go b/utils/build.go new file mode 100644 index 0000000..f6ab608 --- /dev/null +++ b/utils/build.go @@ -0,0 +1,4 @@ +package utils + +// Store the build verion information; set by linker flag +var Version string \ No newline at end of file