forked from Shell-Company/QRExfil
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathencode.sh
More file actions
executable file
·69 lines (56 loc) · 1.62 KB
/
Copy pathencode.sh
File metadata and controls
executable file
·69 lines (56 loc) · 1.62 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
function check_package() {
REQUIRED_PKG="$1"
PKG_OK=$(dpkg-query -W --showformat='${Status}\n' $REQUIRED_PKG 2> /dev/null | grep "install ok installed")
[ -n "$PKG_OK" ] && return $?
}
# requires qrencode and ffmpeg
check_package "qrencode" || { echo "[!] qrencode package is missing. Please install it: sudo apt-get install qrencode"; exit 1; }
check_package "ffmpeg" || { echo "[!] ffmpeg package is missing. Please install it: sudo apt-get install ffmpeg"; exit 1; }
# get file from input
file="$1"
output="$2"
# check if 2nd argument is provided
if [ -z "$output" ]; then
output="output.gif"
fi
# check if the file exists
if [ ! -f "$file" ]; then
echo "Input file not found"
exit 1
fi
# get size of file in bytes
# filesize=$(stat -f "%z" "$file" || stat -c%s "$file")
if [ "$(uname)" == "Darwin" ]; then
filesize=$(stat -f "%z" "$file")
else
filesize=$(stat -c%s "$file")
fi
# calculate size of each chunk
chunksize=64
# determine number of chunks
nchunks=$((filesize/chunksize))
# create chunks
echo "Creating chunks..."
for i in $(seq 0 $nchunks); do
dd if="$file" of=chunk_"$i" bs="$chunksize" skip="$i" count=1
echo "Created chunk $i"
done
# generate qrcode images
echo "Generating qrcodes..."
for i in $(seq 0 $nchunks); do
qrencode -t png -o frame_"$i".png < chunk_"$i" -s 8
echo "Generated qrcode $i"
done
# combine qrcode images into gif
echo "Creating gif..."
if [ "$(uname)" == "Darwin" ]; then
ffmpeg -y -r 10 -i frame_%d.png $output
else
ffmpeg -i frame_%d.png $output -y -r 10
fi
# clean up
echo "Cleaning up..."
rm -f chunk_*
rm -f frame_*
echo "Done!"