Skip to content

Commit

Permalink
Adds fast mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Te-k committed Oct 25, 2023
1 parent 7ca493b commit 0b39878
Show file tree
Hide file tree
Showing 18 changed files with 46 additions and 38 deletions.
2 changes: 1 addition & 1 deletion acquisition/acquisition.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ func New() (*Acquisition, error) {

coll, err := adb.Client.GetCollector(acq.TmpDir, acq.Cpu)
if err != nil {
// Collector install failed, will use find instead
log.Debugf("failed to upload collector: %v", err)
return nil, fmt.Errorf("failed to upload collector: %v", err)
}
acq.Collector = coll

Expand Down
42 changes: 22 additions & 20 deletions adb/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Package struct {
ThirdParty bool `json:"third_party"`
}

func (a *ADB) getPackageFiles(packageName string) []PackageFile {
func (a *ADB) getPackageFiles(packageName string, fast bool) []PackageFile {
out, err := a.Shell("pm", "path", packageName)
if err != nil {
log.Errorf("Failed to get file paths for package %s: %v: %s", packageName, err, out)
Expand All @@ -57,23 +57,25 @@ func (a *ADB) getPackageFiles(packageName string) []PackageFile {
Path: packagePath,
}

// Not sure if this is useful or not considering packages may
// be downloaded later on
md5Out, err := a.Shell("md5sum", packagePath)
if err == nil {
packageFile.MD5 = strings.SplitN(md5Out, " ", 2)[0]
}
sha1Out, err := a.Shell("sha1sum", packagePath)
if err == nil {
packageFile.SHA1 = strings.SplitN(sha1Out, " ", 2)[0]
}
sha256Out, err := a.Shell("sha256sum", packagePath)
if err == nil {
packageFile.SHA256 = strings.SplitN(sha256Out, " ", 2)[0]
}
sha512Out, err := a.Shell("sha512sum", packagePath)
if err == nil {
packageFile.SHA512 = strings.SplitN(sha512Out, " ", 2)[0]
if !fast {
// Not sure if this is useful or not considering packages may
// be downloaded later on
md5Out, err := a.Shell("md5sum", packagePath)
if err == nil {
packageFile.MD5 = strings.SplitN(md5Out, " ", 2)[0]
}
sha1Out, err := a.Shell("sha1sum", packagePath)
if err == nil {
packageFile.SHA1 = strings.SplitN(sha1Out, " ", 2)[0]
}
sha256Out, err := a.Shell("sha256sum", packagePath)
if err == nil {
packageFile.SHA256 = strings.SplitN(sha256Out, " ", 2)[0]
}
sha512Out, err := a.Shell("sha512sum", packagePath)
if err == nil {
packageFile.SHA512 = strings.SplitN(sha512Out, " ", 2)[0]
}
}

packageFiles = append(packageFiles, packageFile)
Expand All @@ -83,7 +85,7 @@ func (a *ADB) getPackageFiles(packageName string) []PackageFile {
}

// GetPackages returns the list of installed package names.
func (a *ADB) GetPackages() ([]Package, error) {
func (a *ADB) GetPackages(fast bool) ([]Package, error) {
withInstaller := true
out, err := a.Shell("pm", "list", "packages", "-U", "-u", "-i")
if err != nil {
Expand Down Expand Up @@ -121,7 +123,7 @@ func (a *ADB) GetPackages() ([]Package, error) {
Disabled: false,
System: false,
ThirdParty: false,
Files: a.getPackageFiles(packageName),
Files: a.getPackageFiles(packageName, fast),
}

packages = append(packages, newPackage)
Expand Down
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ func main() {
var err error
var verbose bool
var list_modules bool
var fast bool
var module string

// Command line options
flag.BoolVar(&verbose, "verbose", false, "Verbose mode")
flag.BoolVar(&verbose, "v", false, "Verbose mode")
flag.BoolVar(&fast, "fast", false, "Fast mode")
flag.BoolVar(&verbose, "f", false, "Fast mode")
flag.BoolVar(&list_modules, "list", false, "List modules and exit")
flag.BoolVar(&list_modules, "l", false, "List modules and exit")
flag.StringVar(&module, "module", "", "Only execute a specific module")
Expand Down Expand Up @@ -105,7 +108,7 @@ func main() {
continue
}

err = mod.Run(acq)
err = mod.Run(acq, fast)
if err != nil {
log.Infof("ERROR: failed to run module %s: %v", mod.Name(), err)
}
Expand Down
2 changes: 1 addition & 1 deletion modules/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (b *Backup) InitStorage(storagePath string) error {
return nil
}

func (b *Backup) Run(acq *acquisition.Acquisition) error {
func (b *Backup) Run(acq *acquisition.Acquisition, fast bool) error {
log.Info("Would you like to take a backup of the device?")
promptBackup := promptui.Select{
Label: "Backup",
Expand Down
2 changes: 1 addition & 1 deletion modules/dumpsys.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (d *Dumpsys) InitStorage(storagePath string) error {
return nil
}

func (d *Dumpsys) Run(acq *acquisition.Acquisition) error {
func (d *Dumpsys) Run(acq *acquisition.Acquisition, fast bool) error {
log.Info("Collecting device diagnostic information. This might take a while...")

out, err := adb.Client.Shell("dumpsys")
Expand Down
2 changes: 1 addition & 1 deletion modules/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (e *Environment) InitStorage(storagePath string) error {
return nil
}

func (e *Environment) Run(acq *acquisition.Acquisition) error {
func (e *Environment) Run(acq *acquisition.Acquisition, fast bool) error {
log.Info("Collecting environment...")

out, err := adb.Client.Shell("env")
Expand Down
2 changes: 1 addition & 1 deletion modules/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (f *Files) InitStorage(storagePath string) error {
return nil
}

func (f *Files) Run(acq *acquisition.Acquisition) error {
func (f *Files) Run(acq *acquisition.Acquisition, fast bool) error {
log.Info("Collecting list of files... This might take a while...")
var fileFounds []string
var fileDetails []adb.FileInfo
Expand Down
2 changes: 1 addition & 1 deletion modules/getprop.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (g *GetProp) InitStorage(storagePath string) error {
return nil
}

func (g *GetProp) Run(acq *acquisition.Acquisition) error {
func (g *GetProp) Run(acq *acquisition.Acquisition, fast bool) error {
log.Info("Collecting device properties...")

out, err := adb.Client.Shell("getprop")
Expand Down
2 changes: 1 addition & 1 deletion modules/logcat.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (l *Logcat) InitStorage(storagePath string) error {
return nil
}

func (l *Logcat) Run(acq *acquisition.Acquisition) error {
func (l *Logcat) Run(acq *acquisition.Acquisition, fast bool) error {
log.Info("Collecting logcat...")

out, err := adb.Client.Shell("logcat", "-d", "-b", "all", "\"*:V\"")
Expand Down
5 changes: 4 additions & 1 deletion modules/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (l *Logs) InitStorage(storagePath string) error {
return nil
}

func (l *Logs) Run(acq *acquisition.Acquisition) error {
func (l *Logs) Run(acq *acquisition.Acquisition, fast bool) error {
log.Info("Collecting system logs...")

logFiles := []string{
Expand All @@ -62,11 +62,14 @@ func (l *Logs) Run(acq *acquisition.Acquisition) error {
}

logFiles = append(logFiles, files...)
log.Debugf("Files in %s: %s", logFolder, files)
}

for _, logFile := range logFiles {
localPath := filepath.Join(l.LogsPath, logFile)
localDir, _ := filepath.Split(localPath)
log.Debugf("From: %s", logFile)
log.Debugf("To: %s", localPath)

err := os.MkdirAll(localDir, 0o755)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion modules/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
type Module interface {
Name() string
InitStorage(storagePath string) error
Run(acq *acquisition.Acquisition) error
Run(acq *acquisition.Acquisition, fast bool) error
}

func List() []Module {
Expand Down
4 changes: 2 additions & 2 deletions modules/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ func (p *Packages) getPathToLocalCopy(packageName, filePath string) string {
return localPath
}

func (p *Packages) Run(acq *acquisition.Acquisition) error {
func (p *Packages) Run(acq *acquisition.Acquisition, fast bool) error {
log.Info("Collecting information on installed apps. This might take a while...")

packages, err := adb.Client.GetPackages()
packages, err := adb.Client.GetPackages(fast)
if err != nil {
return fmt.Errorf("failed to retrieve list of installed packages: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion modules/processes.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (p *Processes) InitStorage(storagePath string) error {
return nil
}

func (p *Processes) Run(acq *acquisition.Acquisition) error {
func (p *Processes) Run(acq *acquisition.Acquisition, fast bool) error {
log.Info("Collecting list of running processes...")

if acq.Collector == nil {
Expand Down
2 changes: 1 addition & 1 deletion modules/root_binaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (r *RootBinaries) InitStorage(storagePath string) error {
return nil
}

func (r *RootBinaries) Run(acq *acquisition.Acquisition) error {
func (r *RootBinaries) Run(acq *acquisition.Acquisition, fast bool) error {
log.Info("Checking for traces of rooting")
root_binaries := []string{
"su",
Expand Down
2 changes: 1 addition & 1 deletion modules/selinux.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (s *SELinux) InitStorage(storagePath string) error {
return nil
}

func (s *SELinux) Run(acq *acquisition.Acquisition) error {
func (s *SELinux) Run(acq *acquisition.Acquisition, fast bool) error {
log.Info("Collecting SELinux status...")

out, err := adb.Client.Shell("getenforce")
Expand Down
2 changes: 1 addition & 1 deletion modules/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (s *Services) InitStorage(storagePath string) error {
return nil
}

func (s *Services) Run(acq *acquisition.Acquisition) error {
func (s *Services) Run(acq *acquisition.Acquisition, fast bool) error {
log.Info("Collecting list of services...")

out, err := adb.Client.Shell("service list")
Expand Down
2 changes: 1 addition & 1 deletion modules/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (s *Settings) InitStorage(storagePath string) error {
return nil
}

func (s *Settings) Run(acq *acquisition.Acquisition) error {
func (s *Settings) Run(acq *acquisition.Acquisition, fast bool) error {
log.Info("Collecting device settings...")

for _, namespace := range []string{"system", "secure", "global"} {
Expand Down
2 changes: 1 addition & 1 deletion modules/temp.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (t *Temp) InitStorage(storagePath string) error {
return nil
}

func (t *Temp) Run(acq *acquisition.Acquisition) error {
func (t *Temp) Run(acq *acquisition.Acquisition, fast bool) error {
log.Info("Collecting files in tmp folder...")

// TODO: Also check default tmp folders
Expand Down

0 comments on commit 0b39878

Please sign in to comment.