mirror of
https://github.com/mvt-project/mvt.git
synced 2026-10-12 02:37:12 +02:00
Update deprecated functions and other small changes (#533)
* also search for STIX2 files in directories in MVT_STIX2
* update datetime deprecations
* add variable declaration in __init__
* add str to return typed in cmd_download_apks.py
* change dictionary creations to dictionary literals
* replace call to set() with set literal
* fix incorrect docstrings
* remove whitespace according to PEP8: E203
* remove whitespace according to PEP8: E203
* remove unreachable return statement
* use Union[] instead of | operator for python 3.8/9 compatability
* Fix ruff formating of files
* Revert "also search for STIX2 files in directories in MVT_STIX2"
This reverts commit 287a11a2ee. We
have this change as a seperate PR in #527.
---------
Co-authored-by: Janik Besendorf <jb@reporter-ohne-grenzen.de>
Co-authored-by: Donncha Ó Cearbhaill <donncha.ocearbhaill@amnesty.org>
This commit is contained in:
9 files changed
+21
-22
No files matched your search
@@ -6,7 +6,7 @@
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from typing import Callable, Optional
|
from typing import Callable, Optional, Union
|
||||||
|
|
||||||
from rich.progress import track
|
from rich.progress import track
|
||||||
|
|
||||||
@@ -52,7 +52,9 @@ class DownloadAPKs(AndroidExtraction):
|
|||||||
packages = json.load(handle)
|
packages = json.load(handle)
|
||||||
return cls(packages=packages)
|
return cls(packages=packages)
|
||||||
|
|
||||||
def pull_package_file(self, package_name: str, remote_path: str) -> None:
|
def pull_package_file(
|
||||||
|
self, package_name: str, remote_path: str
|
||||||
|
) -> Union[str, None]:
|
||||||
"""Pull files related to specific package from the device.
|
"""Pull files related to specific package from the device.
|
||||||
|
|
||||||
:param package_name: Name of the package to download
|
:param package_name: Name of the package to download
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ class AndroidQFModule(MVTModule):
|
|||||||
log=log,
|
log=log,
|
||||||
results=results,
|
results=results,
|
||||||
)
|
)
|
||||||
|
self.parent_path = None
|
||||||
self._path: str = target_path
|
self._path: str = target_path
|
||||||
self.files: List[str] = []
|
self.files: List[str] = []
|
||||||
self.archive: Optional[zipfile.ZipFile] = None
|
self.archive: Optional[zipfile.ZipFile] = None
|
||||||
|
|||||||
@@ -91,5 +91,3 @@ class BugReportModule(MVTModule):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
return self._get_file_content(dumpstate_logs[0])
|
return self._get_file_content(dumpstate_logs[0])
|
||||||
|
|
||||||
return None
|
|
||||||
@@ -64,7 +64,7 @@ class IndicatorsUpdates:
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
def set_latest_check(self) -> None:
|
def set_latest_check(self) -> None:
|
||||||
timestamp = int(datetime.utcnow().timestamp())
|
timestamp = int(datetime.now().timestamp())
|
||||||
with open(self.latest_check_path, "w", encoding="utf-8") as handle:
|
with open(self.latest_check_path, "w", encoding="utf-8") as handle:
|
||||||
handle.write(str(timestamp))
|
handle.write(str(timestamp))
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ class IndicatorsUpdates:
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
def set_latest_update(self) -> None:
|
def set_latest_update(self) -> None:
|
||||||
timestamp = int(datetime.utcnow().timestamp())
|
timestamp = int(datetime.now().timestamp())
|
||||||
with open(self.latest_update_path, "w", encoding="utf-8") as handle:
|
with open(self.latest_update_path, "w", encoding="utf-8") as handle:
|
||||||
handle.write(str(timestamp))
|
handle.write(str(timestamp))
|
||||||
|
|
||||||
@@ -195,7 +195,7 @@ class IndicatorsUpdates:
|
|||||||
return latest_commit_ts
|
return latest_commit_ts
|
||||||
|
|
||||||
def should_check(self) -> Tuple[bool, int]:
|
def should_check(self) -> Tuple[bool, int]:
|
||||||
now = datetime.utcnow()
|
now = datetime.now()
|
||||||
latest_check_ts = self.get_latest_check()
|
latest_check_ts = self.get_latest_check()
|
||||||
latest_check_dt = datetime.fromtimestamp(latest_check_ts)
|
latest_check_dt = datetime.fromtimestamp(latest_check_ts)
|
||||||
|
|
||||||
|
|||||||
@@ -334,8 +334,6 @@ class URL:
|
|||||||
def get_domain(self) -> str:
|
def get_domain(self) -> str:
|
||||||
"""Get the domain from a URL.
|
"""Get the domain from a URL.
|
||||||
|
|
||||||
:param url: URL to parse
|
|
||||||
:type url: str
|
|
||||||
:returns: Domain name extracted from URL
|
:returns: Domain name extracted from URL
|
||||||
:rtype: str
|
:rtype: str
|
||||||
|
|
||||||
@@ -349,8 +347,6 @@ class URL:
|
|||||||
def get_top_level(self) -> str:
|
def get_top_level(self) -> str:
|
||||||
"""Get only the top-level domain from a URL.
|
"""Get only the top-level domain from a URL.
|
||||||
|
|
||||||
:param url: URL to parse
|
|
||||||
:type url: str
|
|
||||||
:returns: Top-level domain name extracted from URL
|
:returns: Top-level domain name extracted from URL
|
||||||
:rtype: str
|
:rtype: str
|
||||||
|
|
||||||
|
|||||||
@@ -53,8 +53,8 @@ def convert_chrometime_to_datetime(timestamp: int) -> datetime.datetime:
|
|||||||
def convert_datetime_to_iso(date_time: datetime.datetime) -> str:
|
def convert_datetime_to_iso(date_time: datetime.datetime) -> str:
|
||||||
"""Converts datetime to ISO string.
|
"""Converts datetime to ISO string.
|
||||||
|
|
||||||
:param datetime: datetime, naive or timezone aware
|
:param date_time: datetime, naive or timezone aware
|
||||||
:type datetime: datetime.datetime
|
:type date_time: datetime.datetime
|
||||||
:returns: ISO datetime string in YYYY-mm-dd HH:MM:SS.ms format.
|
:returns: ISO datetime string in YYYY-mm-dd HH:MM:SS.ms format.
|
||||||
:rtype: str
|
:rtype: str
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ def convert_unix_to_utc_datetime(
|
|||||||
:returns: datetime.
|
:returns: datetime.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return datetime.datetime.utcfromtimestamp(float(timestamp))
|
return datetime.datetime.fromtimestamp(float(timestamp), tz=datetime.timezone.utc)
|
||||||
|
|
||||||
|
|
||||||
def convert_unix_to_iso(timestamp: Union[int, float, str]) -> str:
|
def convert_unix_to_iso(timestamp: Union[int, float, str]) -> str:
|
||||||
|
|||||||
@@ -65,9 +65,11 @@ class Manifest(IOSExtraction):
|
|||||||
if "modified" not in record or "status_changed" not in record:
|
if "modified" not in record or "status_changed" not in record:
|
||||||
return records
|
return records
|
||||||
|
|
||||||
for timestamp in set(
|
for timestamp in {
|
||||||
[record["created"], record["modified"], record["status_changed"]]
|
record["created"],
|
||||||
):
|
record["modified"],
|
||||||
|
record["status_changed"],
|
||||||
|
}:
|
||||||
macb = ""
|
macb = ""
|
||||||
macb += "M" if timestamp == record["modified"] else "-"
|
macb += "M" if timestamp == record["modified"] else "-"
|
||||||
macb += "-"
|
macb += "-"
|
||||||
|
|||||||
@@ -129,8 +129,7 @@ class Analytics(IOSExtraction):
|
|||||||
data["isodate"] = isodate
|
data["isodate"] = isodate
|
||||||
elif row[0]:
|
elif row[0]:
|
||||||
isodate = convert_mactime_to_iso(row[0], False)
|
isodate = convert_mactime_to_iso(row[0], False)
|
||||||
data = {}
|
data = {"isodate": isodate}
|
||||||
data["isodate"] = isodate
|
|
||||||
elif row[1]:
|
elif row[1]:
|
||||||
isodate = ""
|
isodate = ""
|
||||||
data = plistlib.loads(row[1])
|
data = plistlib.loads(row[1])
|
||||||
|
|||||||
@@ -119,9 +119,10 @@ class Shortcuts(IOSExtraction):
|
|||||||
action_data = plistlib.load(io.BytesIO(shortcut.pop("action_data", [])))
|
action_data = plistlib.load(io.BytesIO(shortcut.pop("action_data", [])))
|
||||||
actions = []
|
actions = []
|
||||||
for action_entry in action_data:
|
for action_entry in action_data:
|
||||||
action = {}
|
action = {
|
||||||
action["identifier"] = action_entry["WFWorkflowActionIdentifier"]
|
"identifier": action_entry["WFWorkflowActionIdentifier"],
|
||||||
action["parameters"] = action_entry["WFWorkflowActionParameters"]
|
"parameters": action_entry["WFWorkflowActionParameters"],
|
||||||
|
}
|
||||||
|
|
||||||
# URLs might be in multiple fields, do a simple regex search
|
# URLs might be in multiple fields, do a simple regex search
|
||||||
# across the parameters.
|
# across the parameters.
|
||||||
|
|||||||
Reference in new issue
Block a user