mirror of
https://github.com/mvt-project/mvt.git
synced 2024-06-17 18:14:07 +00:00
Merge pull request #241 from yallxe/main
Make utf-8 as a default for open()
This commit is contained in:
commit
67eea3edec
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -131,3 +131,6 @@ dmypy.json
|
||||||
|
|
||||||
# Temporal files
|
# Temporal files
|
||||||
*~
|
*~
|
||||||
|
|
||||||
|
# IDEA Dev Environment
|
||||||
|
.idea
|
|
@ -57,7 +57,7 @@ class DownloadAPKs(AndroidExtraction):
|
||||||
:param json_path: Path to the apks.json file to parse.
|
:param json_path: Path to the apks.json file to parse.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
with open(json_path, "r") as handle:
|
with open(json_path, "r", encoding="utf-8") as handle:
|
||||||
packages = json.load(handle)
|
packages = json.load(handle)
|
||||||
return cls(packages=packages)
|
return cls(packages=packages)
|
||||||
|
|
||||||
|
@ -173,7 +173,7 @@ class DownloadAPKs(AndroidExtraction):
|
||||||
def save_json(self):
|
def save_json(self):
|
||||||
"""Save the results to the package.json file."""
|
"""Save the results to the package.json file."""
|
||||||
json_path = os.path.join(self.output_folder, "apks.json")
|
json_path = os.path.join(self.output_folder, "apks.json")
|
||||||
with open(json_path, "w") as handle:
|
with open(json_path, "w", encoding="utf-8") as handle:
|
||||||
json.dump(self.packages, handle, indent=4)
|
json.dump(self.packages, handle, indent=4)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
|
@ -27,7 +27,7 @@ class DumpsysBatterystats(AndroidExtraction):
|
||||||
if self.output_folder:
|
if self.output_folder:
|
||||||
stats_path = os.path.join(self.output_folder,
|
stats_path = os.path.join(self.output_folder,
|
||||||
"dumpsys_batterystats.txt")
|
"dumpsys_batterystats.txt")
|
||||||
with open(stats_path, "w") as handle:
|
with open(stats_path, "w", encoding="utf-8") as handle:
|
||||||
handle.write(stats)
|
handle.write(stats)
|
||||||
|
|
||||||
log.info("Records from dumpsys batterystats stored at %s",
|
log.info("Records from dumpsys batterystats stored at %s",
|
||||||
|
@ -37,7 +37,7 @@ class DumpsysBatterystats(AndroidExtraction):
|
||||||
if self.output_folder:
|
if self.output_folder:
|
||||||
history_path = os.path.join(self.output_folder,
|
history_path = os.path.join(self.output_folder,
|
||||||
"dumpsys_batterystats_history.txt")
|
"dumpsys_batterystats_history.txt")
|
||||||
with open(history_path, "w") as handle:
|
with open(history_path, "w", encoding="utf-8") as handle:
|
||||||
handle.write(history)
|
handle.write(history)
|
||||||
|
|
||||||
log.info("History records from dumpsys batterystats stored at %s",
|
log.info("History records from dumpsys batterystats stored at %s",
|
||||||
|
|
|
@ -27,7 +27,7 @@ class DumpsysFull(AndroidExtraction):
|
||||||
if self.output_folder:
|
if self.output_folder:
|
||||||
stats_path = os.path.join(self.output_folder,
|
stats_path = os.path.join(self.output_folder,
|
||||||
"dumpsys.txt")
|
"dumpsys.txt")
|
||||||
with open(stats_path, "w") as handle:
|
with open(stats_path, "w", encoding="utf-8") as handle:
|
||||||
handle.write(stats)
|
handle.write(stats)
|
||||||
|
|
||||||
log.info("Full dumpsys output stored at %s",
|
log.info("Full dumpsys output stored at %s",
|
||||||
|
|
|
@ -28,7 +28,7 @@ class DumpsysPackages(AndroidExtraction):
|
||||||
if self.output_folder:
|
if self.output_folder:
|
||||||
packages_path = os.path.join(self.output_folder,
|
packages_path = os.path.join(self.output_folder,
|
||||||
"dumpsys_packages.txt")
|
"dumpsys_packages.txt")
|
||||||
with open(packages_path, "w") as handle:
|
with open(packages_path, "w", encoding="utf-8") as handle:
|
||||||
handle.write(output)
|
handle.write(output)
|
||||||
|
|
||||||
log.info("Records from dumpsys package stored at %s",
|
log.info("Records from dumpsys package stored at %s",
|
||||||
|
|
|
@ -27,7 +27,7 @@ class DumpsysProcstats(AndroidExtraction):
|
||||||
if self.output_folder:
|
if self.output_folder:
|
||||||
procstats_path = os.path.join(self.output_folder,
|
procstats_path = os.path.join(self.output_folder,
|
||||||
"dumpsys_procstats.txt")
|
"dumpsys_procstats.txt")
|
||||||
with open(procstats_path, "w") as handle:
|
with open(procstats_path, "w", encoding="utf-8") as handle:
|
||||||
handle.write(output)
|
handle.write(output)
|
||||||
|
|
||||||
log.info("Records from dumpsys procstats stored at %s",
|
log.info("Records from dumpsys procstats stored at %s",
|
||||||
|
|
|
@ -31,7 +31,7 @@ class Logcat(AndroidExtraction):
|
||||||
if self.output_folder:
|
if self.output_folder:
|
||||||
logcat_path = os.path.join(self.output_folder,
|
logcat_path = os.path.join(self.output_folder,
|
||||||
"logcat.txt")
|
"logcat.txt")
|
||||||
with open(logcat_path, "w") as handle:
|
with open(logcat_path, "w", encoding="utf-8") as handle:
|
||||||
handle.write(output)
|
handle.write(output)
|
||||||
|
|
||||||
log.info("Current logcat logs stored at %s",
|
log.info("Current logcat logs stored at %s",
|
||||||
|
@ -39,7 +39,7 @@ class Logcat(AndroidExtraction):
|
||||||
|
|
||||||
logcat_last_path = os.path.join(self.output_folder,
|
logcat_last_path = os.path.join(self.output_folder,
|
||||||
"logcat_last.txt")
|
"logcat_last.txt")
|
||||||
with open(logcat_last_path, "w") as handle:
|
with open(logcat_last_path, "w", encoding="utf-8") as handle:
|
||||||
handle.write(last_output)
|
handle.write(last_output)
|
||||||
|
|
||||||
log.info("Logcat logs prior to last reboot stored at %s",
|
log.info("Logcat logs prior to last reboot stored at %s",
|
||||||
|
|
|
@ -82,7 +82,7 @@ class Indicators:
|
||||||
ioc_file["file_path"] = file_path
|
ioc_file["file_path"] = file_path
|
||||||
ioc_file["file_name"] = os.path.basename(file_path)
|
ioc_file["file_name"] = os.path.basename(file_path)
|
||||||
|
|
||||||
with open(file_path, "r") as handle:
|
with open(file_path, "r", encoding="utf-8") as handle:
|
||||||
try:
|
try:
|
||||||
data = json.load(handle)
|
data = json.load(handle)
|
||||||
except json.decoder.JSONDecodeError:
|
except json.decoder.JSONDecodeError:
|
||||||
|
|
|
@ -58,7 +58,7 @@ class MVTModule(object):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_json(cls, json_path, log=None):
|
def from_json(cls, json_path, log=None):
|
||||||
with open(json_path, "r") as handle:
|
with open(json_path, "r", encoding="utf-8") as handle:
|
||||||
results = json.load(handle)
|
results = json.load(handle)
|
||||||
if log:
|
if log:
|
||||||
log.info("Loaded %d results from \"%s\"",
|
log.info("Loaded %d results from \"%s\"",
|
||||||
|
|
|
@ -185,7 +185,7 @@ class DecryptBackup:
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(key_path, 'w') as handle:
|
with open(key_path, 'w', encoding="utf-8") as handle:
|
||||||
handle.write(self._decryption_key)
|
handle.write(self._decryption_key)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.exception(e)
|
log.exception(e)
|
||||||
|
|
|
@ -86,5 +86,5 @@ class ShutdownLog(IOSExtraction):
|
||||||
def run(self):
|
def run(self):
|
||||||
self._find_ios_database(root_paths=SHUTDOWN_LOG_PATH)
|
self._find_ios_database(root_paths=SHUTDOWN_LOG_PATH)
|
||||||
self.log.info("Found shutdown log at path: %s", self.file_path)
|
self.log.info("Found shutdown log at path: %s", self.file_path)
|
||||||
with open(self.file_path, "r") as handle:
|
with open(self.file_path, "r", encoding="utf-8") as handle:
|
||||||
self.process_shutdownlog(handle.read())
|
self.process_shutdownlog(handle.read())
|
||||||
|
|
|
@ -34,7 +34,7 @@ class IOSVersionHistory(IOSExtraction):
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
for found_path in self._get_fs_files_from_patterns(IOS_ANALYTICS_JOURNAL_PATHS):
|
for found_path in self._get_fs_files_from_patterns(IOS_ANALYTICS_JOURNAL_PATHS):
|
||||||
with open(found_path, "r") as analytics_log:
|
with open(found_path, "r", encoding="utf-8") as analytics_log:
|
||||||
log_line = json.loads(analytics_log.readline().strip())
|
log_line = json.loads(analytics_log.readline().strip())
|
||||||
|
|
||||||
timestamp = datetime.datetime.strptime(log_line["timestamp"],
|
timestamp = datetime.datetime.strptime(log_line["timestamp"],
|
||||||
|
|
|
@ -41,7 +41,7 @@ def generate_test_stix_file(file_path):
|
||||||
res.append(Relationship(i, "indicates", malware))
|
res.append(Relationship(i, "indicates", malware))
|
||||||
|
|
||||||
bundle = Bundle(objects=res)
|
bundle = Bundle(objects=res)
|
||||||
with open(file_path, "w+") as f:
|
with open(file_path, "w+", encoding="utf-8") as f:
|
||||||
f.write(bundle.serialize(pretty=True))
|
f.write(bundle.serialize(pretty=True))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user