Conversation
| p = Path(self.file_path) | ||
| self.name = p.name | ||
| if p.suffix == "": | ||
| if not p.suffix: |
There was a problem hiding this comment.
Function File._setup refactored with the following changes:
- Replaces an empty collection equality with a boolean operation (
simplify-empty-collection-comparison)
| include_subfolders = target[1] | ||
| target_path = target[2] | ||
| if target_type == "File": | ||
| self._add_target_file(target_path=target_path) | ||
| else: | ||
| include_subfolders = target[1] |
There was a problem hiding this comment.
Function AttackTargets.add_target refactored with the following changes:
- Move assignments closer to their usage (
move-assign)
| f"### INITIALISING ###", | ||
| update_idle=True | ||
| ) | ||
| self.view.insert_text_message("### INITIALISING ###", update_idle=True) |
There was a problem hiding this comment.
Function DictionaryAttack.run refactored with the following changes:
- Replace f-string with no interpolated values with string [×2] (
remove-redundant-fstring)
| is_supported_type = self._is_supported_file(target_file) | ||
| if is_supported_type: | ||
| pw_required = self._attempt_open_file(target_file) | ||
| if pw_required: | ||
| if is_supported_type := self._is_supported_file(target_file): | ||
| if pw_required := self._attempt_open_file(target_file): |
There was a problem hiding this comment.
Function DictionaryAttack._attack_file refactored with the following changes:
- Use named expression to simplify assignment and conditional [×2] (
use-named-expression)
| # dont use readlines as it will store the whole file in memory.. | ||
| # just read line by line | ||
| pws = open(self.password_file, "r", encoding="latin1") | ||
| for attempt, password in enumerate(pws, 1): | ||
| password = password.strip() | ||
| if target_file.file_type == ".rar": | ||
| try: | ||
| # issue rarfile doesnt handle latin1 characters | ||
| # so use a different password file or amend the rockyouone | ||
| rar_obj = rarfile.RarFile(target_file.file_path, pwd=password) | ||
| found = True | ||
| found_password = password | ||
| last_attempt = attempt | ||
| rar_obj.extractall(self.save_destination) | ||
| break | ||
| except RuntimeError as err: | ||
| if str(err).startswith("Bad password"): | ||
| update_idle = (attempt % 5 == 0) | ||
| self.view.insert_text_message( | ||
| f"Attempt {attempt}: '{password}' failed.", | ||
| update_idle=update_idle | ||
| ) | ||
| if attempt % 250 == 0: | ||
| self.view.clear_text_output() | ||
| continue | ||
| else: | ||
| self.view.display_messagebox(err, "showerror") | ||
| with open(self.password_file, "r", encoding="latin1") as pws: | ||
| for attempt, password in enumerate(pws, 1): | ||
| password = password.strip() | ||
| if target_file.file_type == ".rar": | ||
| try: | ||
| # issue rarfile doesnt handle latin1 characters | ||
| # so use a different password file or amend the rockyouone | ||
| rar_obj = rarfile.RarFile(target_file.file_path, pwd=password) | ||
| found = True | ||
| found_password = password | ||
| last_attempt = attempt | ||
| rar_obj.extractall(self.save_destination) | ||
| break | ||
|
|
||
| elif target_file.file_type == ".zip": | ||
| try: | ||
| password_byte = bytes(password, "latin1") | ||
| ZipFile(target_file.file_path).extractall(path=self.save_destination, | ||
| pwd=password_byte) | ||
| found = True | ||
| found_password = password_byte.decode("latin1") | ||
| last_attempt = attempt | ||
| break | ||
| except RuntimeError as err: | ||
| if str(err).startswith("Bad password"): | ||
| update_idle = (attempt % 5 == 0) | ||
| self.view.insert_text_message( | ||
| f"Attempt {attempt}: '{password}' failed.", | ||
| update_idle=update_idle | ||
| ) | ||
| if attempt % 250 == 0: | ||
| self.view.clear_text_output() | ||
| else: | ||
| self.view.display_messagebox(err, "showerror") | ||
| except RuntimeError as err: | ||
| if str(err).startswith("Bad password"): | ||
| update_idle = (attempt % 5 == 0) | ||
| self.view.insert_text_message( | ||
| f"Attempt {attempt}: '{password}' failed.", | ||
| update_idle=update_idle | ||
| ) | ||
| if attempt % 250 == 0: | ||
| self.view.clear_text_output() | ||
| continue | ||
| else: | ||
| self.view.display_messagebox(err, "showerror") | ||
| break | ||
|
|
||
| elif target_file.file_type == ".zip": | ||
| try: | ||
| password_byte = bytes(password, "latin1") | ||
| ZipFile(target_file.file_path).extractall(path=self.save_destination, | ||
| pwd=password_byte) | ||
| found = True | ||
| found_password = password_byte.decode("latin1") | ||
| last_attempt = attempt | ||
| break | ||
| except zlib.error as zerr: | ||
| if str(zerr).startswith("Error -3"): | ||
| # If there are compression errors then skip | ||
| continue | ||
| else: | ||
| except RuntimeError as err: | ||
| if str(err).startswith("Bad password"): | ||
| update_idle = (attempt % 5 == 0) | ||
| self.view.insert_text_message( | ||
| f"Attempt {attempt}: '{password}' failed.", | ||
| update_idle=update_idle | ||
| ) | ||
| if attempt % 250 == 0: | ||
| self.view.clear_text_output() | ||
| else: | ||
| self.view.display_messagebox(err, "showerror") | ||
| break | ||
| except zlib.error as zerr: | ||
| if str(zerr).startswith("Error -3"): | ||
| # If there are compression errors then skip | ||
| continue | ||
| self.view.display_messagebox(zerr, "showerror") | ||
| break | ||
|
|
||
| pws.close() |
There was a problem hiding this comment.
Function DictionaryAttack._crack_file refactored with the following changes:
- Use
withwhen opening file to ensure closure (ensure-file-closed) - Remove unnecessary else after guard condition (
remove-unnecessary-else) - Replace f-string with no interpolated values with string (
remove-redundant-fstring)
This removes the following comments ( why? ):
# just read line by line
# dont use readlines as it will store the whole file in memory..
| f = open(dest, "a+") | ||
| f.write(line) | ||
| f.close() | ||
| with open(dest, "a+") as f: | ||
| f.write(line) |
There was a problem hiding this comment.
Function DictionaryAttack._store_password refactored with the following changes:
- Use
withwhen opening file to ensure closure (ensure-file-closed)
| selection = filedialog.askdirectory() | ||
| else: | ||
| type1 = ("All Files", "*.*") if not only_text else ("Text Files", "*.txt") | ||
| selection = filedialog.askopenfilename(initialdir="/", | ||
| title="Select a File", | ||
| filetype=[type1]) | ||
| return selection | ||
| return filedialog.askdirectory() | ||
| type1 = ("All Files", "*.*") if not only_text else ("Text Files", "*.txt") | ||
| return filedialog.askopenfilename( | ||
| initialdir="/", title="Select a File", filetype=[type1] | ||
| ) |
There was a problem hiding this comment.
Function MainPage._windows_dialog refactored with the following changes:
- Lift return into if (
lift-return-into-if) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| row = self.tv_target.selection() | ||
| if row: | ||
| if row := self.tv_target.selection(): |
There was a problem hiding this comment.
Function MainPage._delete_tv_row refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
| self.label_current_target["text"] = current_target | ||
|
|
||
| def _launch_dictionary_attack(self): | ||
| password_hash_type = "Plain Text" # self.hash.get() |
There was a problem hiding this comment.
Function MainPage._launch_dictionary_attack refactored with the following changes:
- Move assignments closer to their usage (
move-assign)
Branch
masterrefactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
masterbranch, then run:Help us improve this pull request!