Agent: Extract method _copy_file() from _leave_readme()

Reworks the logic in _leave_readme() to reduce indenting and improve
clarity and extracts the logic to copy the file into _copy_readme_file()
This commit is contained in:
Mike Salvatore 2021-07-08 12:04:50 -04:00
parent 7454ee72b2
commit 92c5c3b682
1 changed files with 16 additions and 10 deletions

View File

@ -97,15 +97,21 @@ class RansomwarePayload:
self._telemetry_messenger.send_telemetry(encryption_attempt) self._telemetry_messenger.send_telemetry(encryption_attempt)
def _leave_readme(self): def _leave_readme(self):
if self._readme_enabled: if not self._readme_enabled:
return
readme_dest_path = self._target_dir / README_DEST readme_dest_path = self._target_dir / README_DEST
if readme_dest_path.exists(): if readme_dest_path.exists():
LOG.warning(f"{readme_dest_path} already exists, not leaving a new README.txt") LOG.warning(f"{readme_dest_path} already exists, not leaving a new README.txt")
return return
LOG.info(f"Leaving a ransomware README file at {readme_dest_path}") self._copy_readme_file(readme_dest_path)
def _copy_readme_file(self, dest: Path):
LOG.info(f"Leaving a ransomware README file at {dest}")
try: try:
self._copy_file(README_SRC, readme_dest_path) self._copy_file(README_SRC, dest)
except Exception as ex: except Exception as ex:
LOG.warning(f"An error occurred while attempting to leave a README.txt file: {ex}") LOG.warning(f"An error occurred while attempting to leave a README.txt file: {ex}")