-
Notifications
You must be signed in to change notification settings - Fork 4
/
decrypt.sh
executable file
·75 lines (54 loc) · 2.21 KB
/
decrypt.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/zsh
if [[ $(csrutil status) != *"disabled." ]]; then
echo "SIP must be disabled."
echo "Consult this documentation for help doing this: https://developer.apple.com/documentation/security/disabling_and_enabling_system_integrity_protection#3599244"
exit 1
fi
if [[ $(defaults read /Library/Preferences/com.apple.security.libraryvalidation.plist DisableLibraryValidation) != "1" ]]; then
echo "Library validation must be disabled."
echo "Disable it with: sudo defaults write /Library/Preferences/com.apple.security.libraryvalidation.plist DisableLibraryValidation -bool true"
exit 1
fi
function injectDylib {
DYLD_INSERT_LIBRARIES=./injected.dylib /System/Applications/Books.app/Contents/MacOS/Books
}
BOOKS_HOME=~/Library/Containers/com.apple.iBooksX/Data
BOOKS_EPUB_DIR=~/Library/Containers/com.apple.BKAgentService/Data/Documents/iBooks/Books
mkdir $BOOKS_HOME/tmp
mkdir ./decrypted_books
epubFiles=()
itemNames=()
for file in "$BOOKS_EPUB_DIR"/*.epub
do
itemName=$(xmllint --xpath "/plist/dict/key[text()='itemName']/following-sibling::*[1]/text()" "$file/iTunesMetadata.plist" 2>/dev/null)
if [[ -z "$itemName" ]]; then
echo "Failed to extract itemName from $file"
continue
fi
epubFiles+=("$file")
itemNames+=("$itemName")
done
select bookSel in "${itemNames[@]}";
do
# Validate the user's input
if [[ "$REPLY" =~ ^[0-9]+$ ]] && [ "$REPLY" -ge 1 ] && [ "$REPLY" -le ${#itemNames[@]} ]; then
selected_epub="${epubFiles[REPLY]}"
open "$BOOKS_HOME/tmp"
cp -R "$selected_epub" "$BOOKS_HOME/tmp"
injectDylib
fileName=$(basename "$selected_epub")
copiedFilePath="$BOOKS_HOME/tmp/$fileName"
decryptedEpubPath="${copiedFilePath%.epub}_decrypted.epub"
mv $decryptedEpubPath ./decrypted_books
rm -rf "$copiedFilePath"
# convert it to an actual epub...
cd "./decrypted_books/${fileName%.epub}_decrypted.epub"
zip -r "../${fileName}" .
# and now we clean up.
cd ../../
rm -rf "./decrypted_books/${fileName%.epub}_decrypted.epub"
else
echo "Invalid selection. Please select a number from 1 to ${#itemNames[@]}."
fi
break
done