From 401fa12a5d45ec7b9663b8296929e90c0a2b481f Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Thu, 4 Nov 2021 19:36:16 +0000 Subject: [PATCH] Improvements to hashcat completion The main args completion no longer uses a bash while loop for splitting up the arguments making it much faster. I have also removed the use of FZF for looking up modes. This has been moved into the overidepartialcompletion file in includes. --- shells/zsh/completion/_hashcat | 21 ++++--------------- .../zsh/includes/overidepartialcompletion.zsh | 7 +++++++ 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/shells/zsh/completion/_hashcat b/shells/zsh/completion/_hashcat index 8fc86b93..060508f6 100644 --- a/shells/zsh/completion/_hashcat +++ b/shells/zsh/completion/_hashcat @@ -15,23 +15,11 @@ trim(){ } _args(){ - hashcat --help | sed -n '/Options/,/Hash modes/p' | tail -n +5 | head -n -2 | while read line; do - op="$(echo "$line" | cut -d"|" -f1 | trim)" - description="$(echo "$line" | cut -d"|" -f3 | trim)" - ty="$(echo "$line" | cut -d"|" -f2 | trim)" - echo "$op" | sed 's/,/\n/' | trim | awk "{print \$1 \":$description:$ty\"}" - done + hashcat --help | sed -n '/Options/,/Hash modes/p' | tail -n +5 | head -n -2 | awk -F '|' '{sub(/[ \t]+$/, "", $1); sub(/[ \t]+$/, "", $3); print $1 ":" $3 ":" $2}' | awk -F ':' '{ if ($1 ~ ",") { first=$1; second=$1; sub(/,.*/,"",first); sub(/.*,/,"",second); print first ":" $2 ":" $3 "\n" second ":" $2 ":" $3 } else {print $0} }' | trim } _hashes(){ - if $(type fzf > /dev/null); then - # If fzf if available, use it for hash completion - - hashcat --example-hashes | grep -E '(mode|Example\.Hash\.\.|Name|^$)' | awk -F ': ' '{print $NF}' | sed 's/Hash mode #//' | awk -v RS="\n\n" -F="\t" '{gsub("\n","\t",$0);print $0}' | fzf -d "\t" --header="Mode Type" --with-nth='1,2' --preview='echo {3}' --preview-window=up:1 --height=40% | cut -d' ' -f1 - else - hashcat --example-hashes | awk -v RS="\n\n" -F "\t" '{gsub("\n","\t",$0); print $1 ":" $2 }' | sed 's/MODE: //; s/TYPE: //' - fi - return 0 + hashcat --example-hashes | grep -E '(mode|Name|^$)' | awk -F ': ' '{print $NF}' | sed 's/Hash mode #//' | awk -v RS="\n\n" -F="\t" '{gsub("\n",":",$0);print $0}' } _basic_section(){ @@ -66,9 +54,8 @@ best_guess(){ case "$previousArg" in -m|--hash-type) - # hashes=("${(f)$(_hashes)}") - # _describe "Hashes" hashes ;; - compadd -- "$(_hashes)" ;; + hashes=("${(f)$(_hashes)}") + _describe "Hashes" hashes ;; -a|--attack-mode) ops=("${(f)$(_basic_section "Attack Modes")}") _describe "Modes" ops ;; diff --git a/shells/zsh/includes/overidepartialcompletion.zsh b/shells/zsh/includes/overidepartialcompletion.zsh index a9b31982..fb535cfe 100644 --- a/shells/zsh/includes/overidepartialcompletion.zsh +++ b/shells/zsh/includes/overidepartialcompletion.zsh @@ -53,6 +53,13 @@ overidecomplete(){ esac ;; ytaudio) toadd="\"$(cat "$HOME/Music/youtube-playlists" | fzf -d ' ' --with-nth=2 --preview='echo {1}' --preview-window=up:1 | cut -d' ' -f1)\""; ret=0 ;; + hashcat) + case "$lastWord" in + -m|--hash-type) toadd="$( hashcat --example-hashes | grep -E '(mode|Example\.Hash\.\.|Name|^$)' | awk -F ': ' '{print $NF}' | sed 's/Hash mode #//' | awk -v RS="\n\n" -F="\t" '{gsub("\n","\t",$0);print $0}' | fzf -d "\t" --header="Mode Type" --with-nth='1,2' --preview='echo {3}' --preview-window=up:1 --height=40% | cut -d' ' -f1)" + ret=0 + ;; + esac + ;; esac fi