2022-06-15 15:41:19 +00:00
|
|
|
# Mobile Verification Toolkit (MVT)
|
|
|
|
# Copyright (c) 2021-2022 Claudio Guarnieri.
|
|
|
|
# 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
|
|
|
|
import os
|
|
|
|
from pathlib import Path
|
2022-08-16 11:39:55 +00:00
|
|
|
from typing import Callable, Optional
|
2022-06-15 15:41:19 +00:00
|
|
|
from zipfile import ZipFile
|
|
|
|
|
|
|
|
from mvt.common.command import Command
|
|
|
|
|
|
|
|
from .modules.bugreport import BUGREPORT_MODULES
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class CmdAndroidCheckBugreport(Command):
|
|
|
|
|
2022-08-16 11:39:55 +00:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
target_path: Optional[str] = "",
|
|
|
|
results_path: Optional[str] = "",
|
|
|
|
ioc_files: Optional[list] = [],
|
|
|
|
module_name: Optional[str] = "",
|
|
|
|
serial: Optional[str] = "",
|
|
|
|
fast_mode: Optional[bool] = False,
|
|
|
|
) -> None:
|
2022-06-16 13:01:07 +00:00
|
|
|
super().__init__(target_path=target_path, results_path=results_path,
|
|
|
|
ioc_files=ioc_files, module_name=module_name,
|
|
|
|
serial=serial, fast_mode=fast_mode, log=log)
|
2022-06-15 15:41:19 +00:00
|
|
|
|
2022-08-12 14:20:16 +00:00
|
|
|
self.name = "check-bugreport"
|
|
|
|
self.modules = BUGREPORT_MODULES
|
|
|
|
|
2022-06-15 15:41:19 +00:00
|
|
|
self.bugreport_format = None
|
|
|
|
self.bugreport_archive = None
|
|
|
|
self.bugreport_files = []
|
|
|
|
|
2022-07-06 16:38:16 +00:00
|
|
|
def init(self) -> None:
|
2022-06-15 15:41:19 +00:00
|
|
|
if os.path.isfile(self.target_path):
|
|
|
|
self.bugreport_format = "zip"
|
|
|
|
self.bugreport_archive = ZipFile(self.target_path)
|
|
|
|
for file_name in self.bugreport_archive.namelist():
|
|
|
|
self.bugreport_files.append(file_name)
|
|
|
|
elif os.path.isdir(self.target_path):
|
|
|
|
self.bugreport_format = "dir"
|
|
|
|
parent_path = Path(self.target_path).absolute().as_posix()
|
2022-08-12 14:20:16 +00:00
|
|
|
for root, _, subfiles in os.walk(os.path.abspath(self.target_path)):
|
2022-06-15 15:41:19 +00:00
|
|
|
for file_name in subfiles:
|
2022-08-12 17:14:05 +00:00
|
|
|
file_path = os.path.relpath(os.path.join(root, file_name),
|
|
|
|
parent_path)
|
|
|
|
self.bugreport_files.append(file_path)
|
2022-06-15 15:41:19 +00:00
|
|
|
|
2022-07-06 16:38:16 +00:00
|
|
|
def module_init(self, module: Callable) -> None:
|
2022-06-15 15:41:19 +00:00
|
|
|
if self.bugreport_format == "zip":
|
|
|
|
module.from_zip(self.bugreport_archive, self.bugreport_files)
|
|
|
|
else:
|
|
|
|
module.from_folder(self.target_path, self.bugreport_files)
|