Created
May 4, 2022 05:58
-
-
Save qtc-de/5b11c54de806c34ed7435d9fa2ea7769 to your computer and use it in GitHub Desktop.
Search for strings within of zip or jar archives
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if ! command -v ugrep &> /dev/null; | |
then | |
echo "[-] Error: ugrep is not available, but required for this script." | |
exit 1 | |
fi | |
function usage() | |
{ | |
NAME=$(basename $0) | |
echo "Usage: $NAME <filter> [path]" | |
echo "" | |
echo "Arguments:" | |
echo " filter filter expression to search within the archived files" | |
echo " path path to perform the search on" | |
echo "" | |
echo "Description:" | |
echo " $NAME can be used to find files within zip or jar files that contain a" | |
echo " specific string or pattern. It is basically like grep for zip or jar files." | |
echo " The actual work is done by ugrep. This script is just a wrapper for simpified usage." | |
exit 0 | |
} | |
while getopts "h" arg; | |
do | |
case $arg in | |
h) | |
usage | |
;; | |
*) | |
usage | |
;; | |
esac | |
done | |
if [[ $# -eq 0 ]]; | |
then | |
usage; | |
fi | |
FILTER=$1 | |
S_PATH=$2 | |
find "${S_PATH:=.}" -type f \( -name '*.jar' -or -name '*.zip' \) -print0 | while IFS= read -r -d '' FILE; | |
do | |
ugrep -z "${FILTER:=''}" -I -- "${FILE}" /dev/null | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment