From 1f756bf752f1fae16f50be57eb75d22c97639e6a Mon Sep 17 00:00:00 2001
From: jsteube <jens.steube@gmail.com>
Date: Tue, 3 Jan 2017 19:21:27 +0100
Subject: [PATCH] Include passwords for removed hashes present in the potfile
 to next loopback iteration

---
 docs/changes.txt |  1 +
 src/hashcat.c    | 10 ++++++++++
 src/potfile.c    | 15 ++++++++++++---
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/docs/changes.txt b/docs/changes.txt
index 2c0f98a7b..4ef897f19 100644
--- a/docs/changes.txt
+++ b/docs/changes.txt
@@ -5,6 +5,7 @@
 ##
 
 - Files: Use $HEX[...] in case the password includes the separater character, increases potfile reading performance
+- Loopback: Include passwords for removed hashes present in the potfile to next loopback iteration
 - New option --progress-only: Quickly provides ideal progress step size and time to process on the user hashes and selected options, then quit
 - Status screen: Reenabled automatic status screen display in case of stdin used
 - Truecrypt/Veracrypt: Use CRC32 to verify headers instead of fuzzy logic, greatly reduces false positives from 18:2^48 to 3:2^64
diff --git a/src/hashcat.c b/src/hashcat.c
index db015c9f6..79e254f6f 100644
--- a/src/hashcat.c
+++ b/src/hashcat.c
@@ -445,8 +445,18 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx)
   {
     EVENT (EVENT_POTFILE_REMOVE_PARSE_PRE);
 
+    if (user_options->loopback == true)
+    {
+      loopback_write_open (hashcat_ctx);
+    }
+
     potfile_remove_parse (hashcat_ctx);
 
+    if (user_options->loopback == true)
+    {
+      loopback_write_close (hashcat_ctx);
+    }
+
     EVENT (EVENT_POTFILE_REMOVE_PARSE_POST);
   }
 
diff --git a/src/potfile.c b/src/potfile.c
index a6b104d11..e9c06aa0b 100644
--- a/src/potfile.c
+++ b/src/potfile.c
@@ -10,6 +10,7 @@
 #include "event.h"
 #include "interface.h"
 #include "filehandling.h"
+#include "loopback.h"
 #include "outfile.h"
 #include "potfile.h"
 #include "locking.h"
@@ -282,9 +283,10 @@ void potfile_write_append (hashcat_ctx_t *hashcat_ctx, const char *out_buf, u8 *
 
 int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx)
 {
-  const hashconfig_t  *hashconfig  = hashcat_ctx->hashconfig;
-  const hashes_t      *hashes      = hashcat_ctx->hashes;
-  const potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx;
+  const hashconfig_t   *hashconfig   = hashcat_ctx->hashconfig;
+  const hashes_t       *hashes       = hashcat_ctx->hashes;
+  const loopback_ctx_t *loopback_ctx = hashcat_ctx->loopback_ctx;
+  const potfile_ctx_t  *potfile_ctx  = hashcat_ctx->potfile_ctx;
 
   if (potfile_ctx->enabled == false) return 0;
 
@@ -486,6 +488,13 @@ int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx)
     found->pw_buf[found->pw_len] = 0;
 
     found->cracked = 1;
+
+    // if enabled, update also the loopback file
+
+    if (loopback_ctx->fp != NULL)
+    {
+      loopback_write_append (hashcat_ctx, (u8 *) pw_buf, (unsigned int) pw_len);
+    }
   }
 
   hcfree (line_buf);