2022-01-30 02:34:16 +00:00
|
|
|
# Mobile Verification Toolkit (MVT)
|
2022-01-30 19:15:01 +00:00
|
|
|
# Copyright (c) 2021-2022 The MVT Project Authors.
|
2022-01-30 02:34:16 +00:00
|
|
|
# Use of this software is governed by the MVT License 1.1 that can be found at
|
|
|
|
# https://license.mvt.re/1.1/
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
from .base import AndroidExtraction
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class DumpsysBatteryHistory(AndroidExtraction):
|
2022-01-30 15:02:24 +00:00
|
|
|
"""This module extracts records from battery history events."""
|
2022-01-30 02:34:16 +00:00
|
|
|
|
|
|
|
def __init__(self, file_path=None, base_folder=None, output_folder=None,
|
|
|
|
serial=None, fast_mode=False, log=None, results=[]):
|
|
|
|
super().__init__(file_path=file_path, base_folder=base_folder,
|
|
|
|
output_folder=output_folder, fast_mode=fast_mode,
|
|
|
|
log=log, results=results)
|
|
|
|
|
|
|
|
def check_indicators(self):
|
|
|
|
for result in self.results:
|
2022-02-01 13:27:00 +00:00
|
|
|
ioc = self.indicators.check_app_id(result["package_name"])
|
2022-01-30 02:34:16 +00:00
|
|
|
if ioc:
|
2022-01-30 19:29:09 +00:00
|
|
|
result["matched_indicator"] = ioc
|
2022-01-30 02:34:16 +00:00
|
|
|
self.detected.append(result)
|
|
|
|
continue
|
|
|
|
|
2022-01-31 11:58:33 +00:00
|
|
|
@staticmethod
|
|
|
|
def parse_battery_history(output):
|
|
|
|
results = []
|
|
|
|
|
2022-01-30 02:34:16 +00:00
|
|
|
for line in output.split("\n")[1:]:
|
|
|
|
if line.strip() == "":
|
|
|
|
break
|
|
|
|
|
|
|
|
time_elapsed, rest = line.strip().split(" ", 1)
|
|
|
|
|
|
|
|
start = line.find(" 100 ")
|
|
|
|
if start == -1:
|
|
|
|
continue
|
|
|
|
|
|
|
|
line = line[start+5:]
|
|
|
|
|
|
|
|
event = ""
|
|
|
|
if line.startswith("+job"):
|
|
|
|
event = "start_job"
|
|
|
|
elif line.startswith("-job"):
|
|
|
|
event = "end_job"
|
|
|
|
elif line.startswith("+running +wake_lock="):
|
|
|
|
event = "wake"
|
|
|
|
else:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if event in ["start_job", "end_job"]:
|
|
|
|
uid = line[line.find("=")+1:line.find(":")]
|
|
|
|
service = line[line.find(":")+1:].strip('"')
|
2022-02-01 13:27:00 +00:00
|
|
|
package_name = service.split("/")[0]
|
2022-01-30 14:20:03 +00:00
|
|
|
elif event == "wake":
|
2022-01-30 02:34:16 +00:00
|
|
|
uid = line[line.find("=")+1:line.find(":")]
|
2022-01-30 14:20:03 +00:00
|
|
|
service = line[line.find("*walarm*:")+9:].split(" ")[0].strip('"').strip()
|
|
|
|
if service == "" or "/" not in service:
|
|
|
|
continue
|
2022-01-30 02:34:16 +00:00
|
|
|
|
2022-02-01 13:27:00 +00:00
|
|
|
package_name = service.split("/")[0]
|
2022-01-30 14:20:03 +00:00
|
|
|
else:
|
|
|
|
continue
|
2022-01-30 02:34:16 +00:00
|
|
|
|
2022-01-31 11:58:33 +00:00
|
|
|
results.append({
|
2022-01-30 02:34:16 +00:00
|
|
|
"time_elapsed": time_elapsed,
|
|
|
|
"event": event,
|
|
|
|
"uid": uid,
|
2022-02-01 13:27:00 +00:00
|
|
|
"package_name": package_name,
|
2022-01-30 02:34:16 +00:00
|
|
|
"service": service,
|
|
|
|
})
|
|
|
|
|
2022-01-31 11:58:33 +00:00
|
|
|
return results
|
2022-01-30 02:34:16 +00:00
|
|
|
|
|
|
|
def run(self):
|
|
|
|
self._adb_connect()
|
|
|
|
|
|
|
|
output = self._adb_command("dumpsys batterystats --history")
|
2022-01-31 11:58:33 +00:00
|
|
|
self.results = self.parse_battery_history(output)
|
|
|
|
|
|
|
|
self.log.info("Extracted %d records from battery history", len(self.results))
|
2022-01-30 02:34:16 +00:00
|
|
|
|
|
|
|
self._adb_disconnect()
|