mufeedvh / pdfrip

A multi-threaded PDF password cracking utility equipped with commonly encountered password format builders and dictionary attacks.
MIT License
589 stars 67 forks source link

Split PDFRip into multiple crates #26

Closed Pommaq closed 6 months ago

Pommaq commented 6 months ago

This is a suggestion for how #23 can be performed, additionally I added a few tests and some code cleanup. It also partially splits all CLI interaction away from main.rs and into a separate crate as suggested by me in #18, the only part left would be to move the ProgressBar away from engine.rs and into cli-interaction as well somehow.

One way would be to allow engine.rs to take a callback which in the case of ProgressBar would simply increment the bar, then wrap engine::crack_file with something like

fn wrapper(
    no_workers: usize,
    cracker: PDFCracker,
    mut producer: Box<dyn Producer>,
) -> anyhow::Result<Option<Vec<u8>>> {
    let progress_bar = ProgressBar::new(producer.size() as u64);
    progress_bar.set_draw_delta(1000);
    progress_bar.set_style(ProgressStyle::default_bar()
            .template("{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {pos:>7}/{len:7} {percent}% {per_sec} ETA: {eta}"));

    let callback = || {
        progress_bar.inc(1);
    };

    let res = crack_file(no_workers, cracker, producer, callback);
    progress_bar.finish();

    return res;
}
Pommaq commented 6 months ago

Eh whatever, I had a bit of extra time. Now the CLI interface (all our non-log prints and parameter parsing) is compartmentalized into the cli-interface crate. This should ease future changes where stdout might not be available.

Pommaq commented 6 months ago

I am removing the workflow from this PR since I add one in #27 anyways

mufeedvh commented 6 months ago

This looks well organized now, nice! Thank you so much for the effort you're putting into this project @Pommaq, I really appreciate it! 🙌