Skip to content
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

Adding stdin and stdout support #49

Merged
merged 36 commits into from
Dec 21, 2023
Merged

Adding stdin and stdout support #49

merged 36 commits into from
Dec 21, 2023

Conversation

zyronix
Copy link
Collaborator

@zyronix zyronix commented Aug 2, 2023

Stdin / Stdout support

Description

This pull requests adds support for stdin support and stdout support. It changes quite some behavior aswell.

Changes

  • By default, when no --input is specified, stdin will be used.
  • By default, when no --ouput is specified, stdout will be used (thus printing results to stdout).
  • By default when logfile is specified, only lines that break/are removed are now added to this file.
  • This same behavior can be enabled for the commandline using --verbose
  • To enable the old behavior to log all changes, use the --debug option. This will print or write all changes made to any line.

Usage

hashcat rockyou.txt --stdout -r best64.txt | demeuk --check-min-length 5 --check-max-length 32 -j all | sort -u

@zyronix zyronix requested a review from rixvet August 2, 2023 17:57
@zyronix
Copy link
Collaborator Author

zyronix commented Aug 2, 2023

@rixvet Could you review this? It is bit experimental, but should work.
What do you think of this feature?
If no --input is given, should it go to stdin by default?

@zyronix zyronix marked this pull request as draft August 2, 2023 18:02
@zyronix zyronix changed the title WIP: Adding stdin support Adding stdin support Aug 2, 2023
@zyronix zyronix self-assigned this Aug 2, 2023
rixvet added 8 commits August 3, 2023 16:36
This will:
  - Fix mutex locking issues when running multiple demeuk together
  - Remove temponary file requirements
  - Simplify codebase by considering files and pipes equal
Appending by default can be highly confusing, overwrite yet safeguard
against overwriting existing files
Add visualize of amount of threads being used. This makes clear to
the user more threads are possible as config argument
Copy link
Member

@rixvet rixvet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the code and start playing around removing duplicate code. Turned out to be bit much to show in review comments. Thus started a new branch for illustration purposes for more details see #50

@zyronix zyronix changed the title Adding stdin support Adding stdin and stdout support Sep 8, 2023
@zyronix zyronix marked this pull request as ready for review December 11, 2023 17:16


def main():
#
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line?

Copy link
Contributor

@GingerGeneste GingerGeneste left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine, we discussed already a few points.
Two additions in the review:

  • Dont forget to update the readme as well (docs are fine)
  • Dont forget to check if the input file exists / let the script throw an error if it doesnt.

bin/demeuk.py Outdated
return ({'results': results, 'log': log})


def chunkify(filename, size=1024 * 1024):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using the global CHUNK_SIZE instead of addressing the size=1024*1024 like this?

bin/demeuk.py Show resolved Hide resolved
bin/demeuk.py Outdated
p_log_file.close()
print(f'Main: done combining results. Output found in {output_file}, logs found in {log_file}')
# Check file permissions and existence
def file_writable_check(filepath, name):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this function inside the main routine and not outside of the main routine?

bin/demeuk.py Outdated
file_errno += 1
exit(2)
if output_file:
file_writable_check(output_file, "Output")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file_writable_check verifies if the output file is writeable by opening it in append. In line 1489 you open the file in write-mode. This clears the possibly existing file without mentioning it. Is this intended behaviour?

else:
p_log_file = stderr

def write_results(results):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this (and the following functions) in main and not outside of it?

bin/demeuk.py Outdated

write_log(f'Running demeuk - {version}{linesep}')
if input_file:
with Pool(a_threads, init_worker) as pool:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The with Pool() call can be placed outside of the if/else statement. This is a slight improvement to avoid code-reuse but not neccesary.



# Quick to default logging to stderr instead
def stderr_print(*args, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing is printed if the verbose flag is False. Which is odd if it is an error that is thrown.

bin/demeuk.py Show resolved Hide resolved
@zyronix zyronix merged commit 1a9f8ec into master Dec 21, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants