Skip to content

Hybrid external mode never calls the original mode's fix_state(), breaking --restore #5814

@solardiz

Description

@solardiz

I feel I may be missing something here, because @jfoug's documentation for hybrid external added to doc/EXTERNAL talks about defining restore() or not and related efficiency aspects, and the code certainly tries to support restore, but I just don't see how it can possibly work when the original mode's fix_state() is never called?

In particular, I observe this problem with -w --external=Shuffle, where actual progress through the wordlist is never saved (all writes to the .rec files write the line number as 0). Desired behavior is that without a restore() the shuffling for current word should start from scratch, but some progress through the wordlist (as limited by keys-per-crypt granularity) should be saved/restored.

The below patch appears to achieve the desired behavior in the above case, but I worry it may break something else?

+++ b/src/external.c
@@ -454,6 +454,8 @@ static void fix_state(void)
        rec_seq = seq;
 }
 
+static void (*saved_crk_fix_state)(void);
+
 void ext_hybrid_fix_state(void)
 {
        strcpy(hybrid_rec_word, int_word);
@@ -462,6 +464,9 @@ void ext_hybrid_fix_state(void)
        hybrid_actual_completed_resume = ext_hybrid_resume;
        hybrid_actual_completed_total  = ext_hybrid_total;
        strcpy(hybrid_actual_completed_base_word, int_hybrid_base_word);
+
+       if (saved_crk_fix_state)
+               saved_crk_fix_state();
 }
 
 void do_external_crack(struct db_main *db)
@@ -594,14 +599,13 @@ void do_external_crack(struct db_main *db)
  */
 
 
-extern void(*crk_fix_state)(void);
-void(*saved_crk_fix_state)(void);
-void save_fix_state(void(*new_crk_fix_state)(void))
+extern void (*crk_fix_state)(void);
+static void save_fix_state(void(*new_crk_fix_state)(void))
 {
        saved_crk_fix_state = crk_fix_state;
        crk_fix_state = new_crk_fix_state;
 }
-void restore_fix_state(void)
+static void restore_fix_state(void)
 {
        crk_fix_state = saved_crk_fix_state;
 }

(additions of static are not directly related, but helped me make sure those symbols were local to this file)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions