-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery refactored master branch #1
base: master
Are you sure you want to change the base?
Conversation
if p.suffix == "": | ||
if not p.suffix: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function AttackTargets.add_target
refactored with the following changes:
- Move assignments closer to their usage (
move-assign
)
self.view.insert_text_message( | ||
f"### INITIALISING ###", | ||
update_idle=True | ||
) | ||
self.view.insert_text_message("### INITIALISING ###", update_idle=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function DictionaryAttack._attack_file
refactored with the following changes:
- Use named expression to simplify assignment and conditional [×2] (
use-named-expression
)
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function DictionaryAttack._crack_file
refactored with the following changes:
- Use
with
when 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function DictionaryAttack._store_password
refactored with the following changes:
- Use
with
when 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function MainPage._delete_tv_row
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
@@ -164,7 +161,6 @@ def set_current_target(self, current_target): | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function MainPage._launch_dictionary_attack
refactored with the following changes:
- Move assignments closer to their usage (
move-assign
)
Branch
master
refactored 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
master
branch, then run:Help us improve this pull request!