-
Notifications
You must be signed in to change notification settings - Fork 0
/
pptx-breaker.sh
executable file
·50 lines (37 loc) · 957 Bytes
/
pptx-breaker.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
#!/bin/bash
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <pptx_file>"
exit 1
fi
file="$1"
res_file="${file%.*}_PASSWORD_REMOVED.pptx"
tmpdir=".tmp_$1"
xml_file="ppt/presentation.xml"
tag_name="p:modifyVerifier"
if [ ! -f "$file" ]; then
echo "Error: file '$1' does not exist"
fi
# Check file extension
if [ "${file##*.}" != "pptx" ]; then
echo "Error: only pptx files are supported."
exit 1
fi
# Unzip pptx contents
echo "Create temporary directory '$tmpdir'..."
mkdir "$tmpdir"
echo "Unzipping pptx to '$tmpdir/file'..."
cp "$file" "$tmpdir/$file"
cd "$tmpdir"
unzip "$file" > /dev/null
rm "$file"
echo "Removing evil XML tag..."
# Remove read-only mechanism
sed "s/<$tag_name [^>]*\/>//g" "${xml_file}" > "${xml_file}.tmp"
mv "${xml_file}.tmp" "${xml_file}"
echo "Wrapping things up..."
# Zip result file
zip -r "../$res_file" . > /dev/null
# Delete temporary directory
cd ..
rm -rf "$tmpdir"
echo "Success, output file is '$res_file'."