-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeob.sh
56 lines (48 loc) · 1.51 KB
/
deob.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
# Default values
DIRECTORY="."
EXTENSION="mjs"
COMMAND="webcrack"
OUTPUT_EXTENSION="js"
# Help function
print_usage() {
echo "Usage: $0 [-d directory] [-e extension] [-c command] [-o output_extension]"
echo " -d: Directory to search (default: current directory)"
echo " -e: File extension to process (default: mjs)"
echo " -c: Command to run on each file (default: webcrack)"
echo " -o: Output file extension (default: js)"
exit 1
}
# Parse command line arguments
while getopts "d:e:c:o:h" opt; do
case $opt in
d) DIRECTORY="$OPTARG";;
e) EXTENSION="$OPTARG";;
c) COMMAND="$OPTARG";;
o) OUTPUT_EXTENSION="$OPTARG";;
h) print_usage;;
\?) print_usage;;
esac
done
# Validate directory exists
if [ ! -d "$DIRECTORY" ]; then
echo "Error: Directory '$DIRECTORY' does not exist"
exit 1
fi
# Find all files with the specified extension and process them
find "$DIRECTORY" -type f -name "*.$EXTENSION" | while read -r file; do
# Get the output filename by replacing the extension
output_file="${file%.$EXTENSION}.$OUTPUT_EXTENSION"
# Create output directory if it doesn't exist
output_dir=$(dirname "$output_file")
mkdir -p "$output_dir"
# Process the file
echo "Processing: $file -> $output_file"
$COMMAND "$file" > "$output_file"
# Check if command was successful
if [ $? -eq 0 ]; then
echo "Successfully processed: $file"
else
echo "Error processing: $file"
fi
done