|
| 1 | +// androidqf - Android Quick Forensics |
| 2 | +// Copyright (c) 2021-2023 Claudio Guarnieri. |
| 3 | +// Use of this software is governed by the MVT License 1.1 that can be found at |
| 4 | +// https://license.mvt.re/1.1/ |
| 5 | + |
| 6 | +package modules |
| 7 | + |
| 8 | +import ( |
| 9 | + "slices" |
| 10 | + "path/filepath" |
| 11 | + "strings" |
| 12 | + |
| 13 | + "github.com/mvt-project/androidqf/acquisition" |
| 14 | + "github.com/mvt-project/androidqf/adb" |
| 15 | + "github.com/mvt-project/androidqf/log" |
| 16 | +) |
| 17 | + |
| 18 | +type Mounts struct { |
| 19 | + StoragePath string |
| 20 | +} |
| 21 | + |
| 22 | +func NewMounts() *Mounts { |
| 23 | + return &Mounts{} |
| 24 | +} |
| 25 | + |
| 26 | +func (m *Mounts) Name() string { |
| 27 | + return "mounts" |
| 28 | +} |
| 29 | + |
| 30 | +func (m *Mounts) InitStorage(storagePath string) error { |
| 31 | + m.StoragePath = storagePath |
| 32 | + return nil |
| 33 | +} |
| 34 | + |
| 35 | +func (m *Mounts) Run(acq *acquisition.Acquisition, fast bool) error { |
| 36 | + log.Info("Collecting mount information") |
| 37 | + |
| 38 | + var mountsData []string |
| 39 | + |
| 40 | + // Run "mount | grep '/system'" |
| 41 | + log.Debug("Running: mount | grep '/system'") |
| 42 | + out1, err1 := adb.Client.Shell("mount | grep '/system'") |
| 43 | + if err1 == nil && out1 != "" { |
| 44 | + lines := strings.Split(strings.TrimSpace(out1), "\n") |
| 45 | + for _, line := range lines { |
| 46 | + if strings.TrimSpace(line) != "" { |
| 47 | + mountsData = append(mountsData, strings.TrimSpace(line)) |
| 48 | + } |
| 49 | + } |
| 50 | + } else { |
| 51 | + log.Debug("mount | grep '/system' command failed or returned empty result") |
| 52 | + } |
| 53 | + |
| 54 | + // Run "cat /proc/mounts | grep '/system'" |
| 55 | + log.Debug("Running: cat /proc/mounts | grep '/system'") |
| 56 | + out2, err2 := adb.Client.Shell("cat /proc/mounts | grep '/system'") |
| 57 | + if err2 == nil && out2 != "" { |
| 58 | + lines := strings.Split(strings.TrimSpace(out2), "\n") |
| 59 | + for _, line := range lines { |
| 60 | + if strings.TrimSpace(line) != "" { |
| 61 | + trimmedLine := strings.TrimSpace(line) |
| 62 | + // Avoid duplicates |
| 63 | + found := slices.Contains(mountsData, trimmedLine) |
| 64 | + if !found { |
| 65 | + mountsData = append(mountsData, trimmedLine) |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | + } else { |
| 70 | + log.Debug("cat /proc/mounts | grep '/system' command failed or returned empty result") |
| 71 | + } |
| 72 | + |
| 73 | + log.Debugf("Found %d mount entries", len(mountsData)) |
| 74 | + |
| 75 | + return saveCommandOutputJson(filepath.Join(m.StoragePath, "mounts.json"), &mountsData) |
| 76 | +} |
0 commit comments