2022-02-01 23:09:53 +00:00
|
|
|
# Mobile Verification Toolkit (MVT)
|
2022-05-08 12:53:50 +00:00
|
|
|
# Copyright (c) 2021-2022 Claudio Guarnieri.
|
2022-02-01 23:09:53 +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
|
|
|
|
|
2022-02-02 20:58:11 +00:00
|
|
|
from mvt.android.parsers import parse_dumpsys_battery_daily
|
2022-02-02 21:00:48 +00:00
|
|
|
|
2022-02-01 23:09:53 +00:00
|
|
|
from .base import BugReportModule
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class BatteryDaily(BugReportModule):
|
|
|
|
"""This module extracts records from battery daily updates."""
|
|
|
|
|
2022-06-17 20:30:46 +00:00
|
|
|
def __init__(self, file_path: str = None, target_path: str = None,
|
|
|
|
results_path: str = None, fast_mode: bool = False,
|
|
|
|
log: logging.Logger = None, results: list = []) -> None:
|
2022-06-15 15:41:19 +00:00
|
|
|
super().__init__(file_path=file_path, target_path=target_path,
|
|
|
|
results_path=results_path, fast_mode=fast_mode,
|
2022-02-01 23:09:53 +00:00
|
|
|
log=log, results=results)
|
|
|
|
|
2022-06-17 20:30:46 +00:00
|
|
|
def serialize(self, record: dict) -> None:
|
2022-02-01 23:09:53 +00:00
|
|
|
return {
|
|
|
|
"timestamp": record["from"],
|
|
|
|
"module": self.__class__.__name__,
|
|
|
|
"event": "battery_daily",
|
|
|
|
"data": f"Recorded update of package {record['package_name']} with vers {record['vers']}"
|
|
|
|
}
|
|
|
|
|
2022-06-17 20:30:46 +00:00
|
|
|
def check_indicators(self) -> None:
|
2022-02-01 23:09:53 +00:00
|
|
|
if not self.indicators:
|
|
|
|
return
|
|
|
|
|
|
|
|
for result in self.results:
|
|
|
|
ioc = self.indicators.check_app_id(result["package_name"])
|
|
|
|
if ioc:
|
|
|
|
result["matched_indicator"] = ioc
|
|
|
|
self.detected.append(result)
|
|
|
|
continue
|
|
|
|
|
2022-06-17 20:30:46 +00:00
|
|
|
def run(self) -> None:
|
2022-02-04 12:34:40 +00:00
|
|
|
content = self._get_dumpstate_file()
|
2022-02-01 23:09:53 +00:00
|
|
|
if not content:
|
2022-02-04 12:34:40 +00:00
|
|
|
self.log.error("Unable to find dumpstate file. Did you provide a valid bug report archive?")
|
2022-02-01 23:09:53 +00:00
|
|
|
return
|
|
|
|
|
2022-02-02 14:47:55 +00:00
|
|
|
lines = []
|
2022-02-01 23:09:53 +00:00
|
|
|
in_batterystats = False
|
|
|
|
in_daily = False
|
2022-02-03 18:40:36 +00:00
|
|
|
for line in content.decode(errors="ignore").splitlines():
|
2022-02-01 23:09:53 +00:00
|
|
|
if line.strip() == "DUMP OF SERVICE batterystats:":
|
|
|
|
in_batterystats = True
|
|
|
|
continue
|
|
|
|
|
|
|
|
if not in_batterystats:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if line.strip() == "Daily stats:":
|
|
|
|
lines.append(line)
|
|
|
|
in_daily = True
|
|
|
|
continue
|
|
|
|
|
|
|
|
if not in_daily:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if line.strip() == "":
|
|
|
|
break
|
|
|
|
|
|
|
|
lines.append(line)
|
|
|
|
|
2022-02-02 20:58:11 +00:00
|
|
|
self.results = parse_dumpsys_battery_daily("\n".join(lines))
|
2022-02-03 18:55:18 +00:00
|
|
|
|
|
|
|
self.log.info("Extracted a total of %d battery daily stats",
|
|
|
|
len(self.results))
|