From 2b169ae362b84307b14e2628b80803c00a203f0a Mon Sep 17 00:00:00 2001 From: Justin Bollinger Date: Mon, 13 Apr 2026 10:09:55 -0400 Subject: [PATCH] perf: combine d3ad0ne + T0XlC rules into single hashcat invocation Merge both rule files into a temporary combined file so hashcat only starts once per wordlist instead of twice, saving GPU initialization overhead on each dictionary attack iteration. Co-Authored-By: Claude Opus 4.6 (1M context) --- hate_crack/main.py | 86 +++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 46 deletions(-) diff --git a/hate_crack/main.py b/hate_crack/main.py index ce8200e..b2f9040 100755 --- a/hate_crack/main.py +++ b/hate_crack/main.py @@ -1233,54 +1233,48 @@ def hcatDictionary(hcatHashType, hcatHashFile): print("Killing PID {0}...".format(str(hcatProcess.pid))) hcatProcess.kill() + rule_d3ad0ne = get_rule_path("d3ad0ne.rule") + rule_toxic = get_rule_path("T0XlC.rule") for wordlist in hcatDictionaryWordlist: - rule_d3ad0ne = get_rule_path("d3ad0ne.rule") - cmd = [ - hcatBin, - "-m", - hcatHashType, - hcatHashFile, - "--session", - generate_session_id(), - "-o", - f"{hcatHashFile}.out", - wordlist, - "-r", - rule_d3ad0ne, - ] - cmd.extend(shlex.split(hcatTuning)) - _append_potfile_arg(cmd) - cmd = _add_debug_mode_for_rules(cmd) - hcatProcess = subprocess.Popen(cmd) + # Combine d3ad0ne + T0XlC rules into a single file so hashcat only + # starts once per wordlist instead of twice (saves GPU init overhead). + with tempfile.NamedTemporaryFile( + mode="wb", suffix=".rule", prefix="hate_crack_combined_", delete=False + ) as combined: + combined_path = combined.name + for rule_path in (rule_d3ad0ne, rule_toxic): + with open(rule_path, "rb") as rf: + data = rf.read() + combined.write(data) + if data and not data.endswith(b"\n"): + combined.write(b"\n") try: - hcatProcess.wait() - except KeyboardInterrupt: - print("Killing PID {0}...".format(str(hcatProcess.pid))) - hcatProcess.kill() - - rule_toxic = get_rule_path("T0XlC.rule") - cmd = [ - hcatBin, - "-m", - hcatHashType, - hcatHashFile, - "--session", - generate_session_id(), - "-o", - f"{hcatHashFile}.out", - wordlist, - "-r", - rule_toxic, - ] - cmd.extend(shlex.split(hcatTuning)) - _append_potfile_arg(cmd) - cmd = _add_debug_mode_for_rules(cmd) - hcatProcess = subprocess.Popen(cmd) - try: - hcatProcess.wait() - except KeyboardInterrupt: - print("Killing PID {0}...".format(str(hcatProcess.pid))) - hcatProcess.kill() + cmd = [ + hcatBin, + "-m", + hcatHashType, + hcatHashFile, + "--session", + generate_session_id(), + "-o", + f"{hcatHashFile}.out", + wordlist, + "-r", + combined_path, + ] + if _should_use_optimized_kernel("hcatDictionary"): + _insert_optimized_flag(cmd) + cmd.extend(shlex.split(hcatTuning)) + _append_potfile_arg(cmd) + cmd = _add_debug_mode_for_rules(cmd) + hcatProcess = subprocess.Popen(cmd) + try: + hcatProcess.wait() + except KeyboardInterrupt: + print("Killing PID {0}...".format(str(hcatProcess.pid))) + hcatProcess.kill() + finally: + os.unlink(combined_path) hcatDictionaryCount = lineCount(hcatHashFile + ".out") - hcatBruteCount