Merge pull request #241 from yallxe/main

Make utf-8 as a default for open()
This commit is contained in:
Nex 2022-01-29 14:44:16 +01:00 committed by GitHub
commit 67eea3edec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 18 additions and 15 deletions

3
.gitignore vendored
View File

@ -131,3 +131,6 @@ dmypy.json
# Temporal files
*~
# IDEA Dev Environment
.idea

View File

@ -57,7 +57,7 @@ class DownloadAPKs(AndroidExtraction):
: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)
return cls(packages=packages)
@ -173,7 +173,7 @@ class DownloadAPKs(AndroidExtraction):
def save_json(self):
"""Save the results to the package.json file."""
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)
def run(self):

View File

@ -27,7 +27,7 @@ class DumpsysBatterystats(AndroidExtraction):
if self.output_folder:
stats_path = os.path.join(self.output_folder,
"dumpsys_batterystats.txt")
with open(stats_path, "w") as handle:
with open(stats_path, "w", encoding="utf-8") as handle:
handle.write(stats)
log.info("Records from dumpsys batterystats stored at %s",
@ -37,7 +37,7 @@ class DumpsysBatterystats(AndroidExtraction):
if self.output_folder:
history_path = os.path.join(self.output_folder,
"dumpsys_batterystats_history.txt")
with open(history_path, "w") as handle:
with open(history_path, "w", encoding="utf-8") as handle:
handle.write(history)
log.info("History records from dumpsys batterystats stored at %s",

View File

@ -27,7 +27,7 @@ class DumpsysFull(AndroidExtraction):
if self.output_folder:
stats_path = os.path.join(self.output_folder,
"dumpsys.txt")
with open(stats_path, "w") as handle:
with open(stats_path, "w", encoding="utf-8") as handle:
handle.write(stats)
log.info("Full dumpsys output stored at %s",

View File

@ -28,7 +28,7 @@ class DumpsysPackages(AndroidExtraction):
if self.output_folder:
packages_path = os.path.join(self.output_folder,
"dumpsys_packages.txt")
with open(packages_path, "w") as handle:
with open(packages_path, "w", encoding="utf-8") as handle:
handle.write(output)
log.info("Records from dumpsys package stored at %s",

View File

@ -27,7 +27,7 @@ class DumpsysProcstats(AndroidExtraction):
if self.output_folder:
procstats_path = os.path.join(self.output_folder,
"dumpsys_procstats.txt")
with open(procstats_path, "w") as handle:
with open(procstats_path, "w", encoding="utf-8") as handle:
handle.write(output)
log.info("Records from dumpsys procstats stored at %s",

View File

@ -31,7 +31,7 @@ class Logcat(AndroidExtraction):
if self.output_folder:
logcat_path = os.path.join(self.output_folder,
"logcat.txt")
with open(logcat_path, "w") as handle:
with open(logcat_path, "w", encoding="utf-8") as handle:
handle.write(output)
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.txt")
with open(logcat_last_path, "w") as handle:
with open(logcat_last_path, "w", encoding="utf-8") as handle:
handle.write(last_output)
log.info("Logcat logs prior to last reboot stored at %s",

View File

@ -82,7 +82,7 @@ class Indicators:
ioc_file["file_path"] = 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:
data = json.load(handle)
except json.decoder.JSONDecodeError:

View File

@ -58,7 +58,7 @@ class MVTModule(object):
@classmethod
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)
if log:
log.info("Loaded %d results from \"%s\"",

View File

@ -185,7 +185,7 @@ class DecryptBackup:
return
try:
with open(key_path, 'w') as handle:
with open(key_path, 'w', encoding="utf-8") as handle:
handle.write(self._decryption_key)
except Exception as e:
log.exception(e)

View File

@ -86,5 +86,5 @@ class ShutdownLog(IOSExtraction):
def run(self):
self._find_ios_database(root_paths=SHUTDOWN_LOG_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())

View File

@ -34,7 +34,7 @@ class IOSVersionHistory(IOSExtraction):
def run(self):
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())
timestamp = datetime.datetime.strptime(log_line["timestamp"],

View File

@ -41,7 +41,7 @@ def generate_test_stix_file(file_path):
res.append(Relationship(i, "indicates", malware))
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))