diff --git a/PS3/PS3roms.7z b/PS3/PS3roms.7z new file mode 100644 index 0000000..e3307a7 Binary files /dev/null and b/PS3/PS3roms.7z differ diff --git a/PS3/PS3roms/dkeys.7z b/PS3/PS3roms/dkeys.7z deleted file mode 100644 index 0c32896..0000000 Binary files a/PS3/PS3roms/dkeys.7z and /dev/null differ diff --git a/PS3/ps3_decrypt.sh b/PS3/ps3_decrypt.sh deleted file mode 100644 index 1a34647..0000000 --- a/PS3/ps3_decrypt.sh +++ /dev/null @@ -1,65 +0,0 @@ -#!/bin/bash - -TODO_DIR="/home/$USER/Downloads/PS3/PS3ISO/" -DONE_DIR="/home/$USER/Downloads/PS3/PS3ISO/READY/" - -if [ ! -d "$TODO_DIR" ]; then - mkdir "$TODO_DIR" -fi - -if [ ! -d "$DONE_DIR" ]; then - mkdir "$DONE_DIR" -fi - -if [[ $# -eq 0 ]]; then - set -- *.zip -fi - -for file in "$@" -do - if [[ ! "$file" =~ \.zip$ ]]; then - continue - fi - - if [[ "$file" == "-d" ]] || [[ "$file" == "--keep" ]] || [[ "$file" == "-k" ]]; then - delete_zip=false - shift - continue - fi - - if [[ "$file" == "-dkey="* ]]; then - dkey=$(echo "$file" | cut -d= -f2) - shift - continue - fi - - extracted_file=$(zipinfo -1 "$file" "*.iso" | grep -i '\.iso$') - unzip -j -o -q "$file" "*.iso" -d "$TODO_DIR" - - clear - filename=$(basename "$extracted_file") - done_file="$DONE_DIR/$filename" - - if [[ -n "$dkey" ]]; then - if libray -i "$extracted_file" -o "$done_file" -k "$dkey"; then - echo "File processed successfully" - rm -rf "$extracted_file" - rm -rf "$dkey" - rename 's/ \(.*\)//' "$done_file" - else - echo "Error processing file" - fi - else - if libray -i "$extracted_file" -o "$done_file"; then - echo "File processed successfully" - rm -rf "$extracted_file" - rename 's/ \(.*\)//' "$done_file" - else - echo "Error processing file" - fi - fi - - if [[ "$delete_zip" != "false" ]]; then - rm -rf "$file" - fi -done \ No newline at end of file diff --git a/PS3/ps3_extract.sh b/PS3/ps3_extract.sh new file mode 100755 index 0000000..604eb73 --- /dev/null +++ b/PS3/ps3_extract.sh @@ -0,0 +1,181 @@ +#!/bin/bash +# ____ _ _ +# / ___|| |_| |__ ___ _ __ ___ +# \___ \| __| '_ \ / _ \| '_ \ / _ \ +# ___) | |_| | | | (_) | |_) | __/ +# |____/ \__|_| |_|\___/| .__/ \___| +# |_| +# +# + +TODO_FOLDER="./todo" +DKEYS_FOLDER="./dkeys" + +DONE_FOLDER="./done" +ENCRYPTED_ISO="$DONE_FOLDER/encrypted" +DECRYPTED_ISO="$DONE_FOLDER/decrypted" +EXTRACTED_ISO="$DONE_FOLDER/extracted" +ZIP_FOLDER="$DONE_FOLDER/zip" +NEED_KEY="$DONE_FOLDER/need_key" +TO_DELETE_FOLDER="$DONE_FOLDER/to_delete" + +install_dependencies() { + if [ -x "$(command -v apt-get)" ]; then + echo "Detected Debian-based distribution." + sudo apt-get update + sudo apt-get install -y p7zip-full wget + sudo pip install libray + elif [ -x "$(command -v yum)" ]; then + echo "Detected Red Hat-based distribution." + sudo yum install -y p7zip wget + sudo pip install libray + elif [ -x "$(command -v pacman)" ]; then + echo "Detected Arch-based distribution." + sudo pacman -Sy --noconfirm p7zip wget + sudo pip install libray + elif [ -x "$(command -v dnf)" ]; then + echo "Detected Rocky Linux." + sudo dnf install -y p7zip wget + sudo pip install libray + else + echo "Unsupported distribution. Please install Python 3 manually." + exit 1 + fi +} + +check_if_folders_exists() { + folders=("$ENCRYPTED_ISO" "$DECRYPTED_ISO" "$EXTRACTED_ISO" "$ZIP_FOLDER" "$NEED_KEY" "$TO_DELETE_FOLDER") + for folder in "${folders[@]}"; do + if [ ! -d "$folder" ]; then + mkdir -p "$folder" + fi + done +} + +get_dkeys() { + wget -q https://git.sthope.dev/sthope/Emulation-and-ROMs/raw/branch/main/PS3/PS3roms/dkeys.7z -P ./ + 7z x ./dkeys.7z >/dev/null 2>&1 + rm -rf ./dkeys.7z +} + +extract_zips() { + for file in "$TODO_FOLDER"/*.zip; do + if [ -f "$file" ]; then + 7z x "$file" -o"$ENCRYPTED_ISO">/dev/null 2>&1 + if [ $? -ne 0 ]; then + echo "Error extracting $file" + fi + fi + done +} + +decrypt_iso() { + for file in "$ENCRYPTED_ISO"/*.iso; do + if [ -f "$file" ]; then + decrypted_iso="$DECRYPTED_ISO/$(basename "$file")" + if libray -i "$file" -o "$decrypted_iso" >/dev/null 2>&1; then + mv "$file" "$TO_DELETE_FOLDER" + else + mv "$file" "$NEED_KEY" + for key_file in "$NEED_KEY"/*.iso; do + if [ -f "$key_file" ]; then + get_dkeys + decrypted_iso="$DECRYPTED_ISO/$(basename "$key_file")" + dkey_file="$DKEYS_FOLDER/$(basename "$key_file" .iso).dkey" + DKEY="$(cat "$dkey_file")" + libray -i "$key_file" -o "$decrypted_iso" -d "$DKEY" >/dev/null 2>&1 + if [ $? -eq 0 ]; then + mv "$key_file" "$TO_DELETE_FOLDER" + else + echo "Error decrypting $key_file" + fi + fi + done + fi + fi + done + rm -rf $DKEYS_FOLDER +} + +extract_decrypted() { + for file in "$DECRYPTED_ISO"/*.iso; do + if [ -f "$file" ]; then + decrypted_iso=$(basename "$DECRYPTED_ISO/$(basename "$file" ".$extension" | cut -d. -f1)") + 7z x "$file" -o"$EXTRACTED_ISO/$decrypted_iso">/dev/null 2>&1 + if [ $? -ne 0 ]; then + echo "Error extracting decrypted $file" + fi + fi + done +} + +decrypt_with_dkeys() { + for file in "$NEED_KEY"/*.iso; do + if [ -f "$file" ]; then + decrypted_iso="$DECRYPTED_ISO/$(basename "$file")" + key_file="$DKEYS_FOLDER/$(basename "$file" .iso).dkey" + DKEY="$(cat "$key_file")" + libray -i "$file" -o "$decrypted_iso" -d "$DKEY" + if [ $? -eq 0 ]; then + mv "$file" "$TO_DELETE_FOLDER" + else + echo "Error extracting $file" + fi + fi + done +} + +# cleanup() { +# mv $EXTRACTED_ISO ./ +# rm -rf "$DONE_FOLDER" +# } + +cleanup() { + case "$1" in + --decrypted_isos) + mv "$DECRYPTED_ISO" ./ + rm -rf "$DONE_FOLDER" + ;; + --extracted_isos) + mv "$EXTRACTED_ISO" ./ + rm -rf "$DONE_FOLDER" + ;; + --zip_folder) + mv "$ZIP_FOLDER" ./ + rm -rf "$DONE_FOLDER" + ;; + --encrypted_isos) + mv "$TO_DELETE_FOLDER" ./ + rm -rf "$DONE_FOLDER" + ;; + *) + echo "Invalid option. Usage: $0 --clean-up [--decrypted_isos|--extracted_isos|--zip_folder|--encrypted_isos]" + exit 1 + ;; + esac +} + +if [ "$1" == "--extract-all" ]; then + check_if_folders_exists + extract_zips +elif [ "$1" == "--decrypt-all" ]; then + check_if_folders_exists + decrypt_iso +elif [ "$1" == "--extract-decrypted-all" ]; then + check_if_folders_exists + extract_decrypted +elif [ "$1" == "--need-dkey" ]; then + check_if_folders_exists + check_keys +elif [ "$1" == "--clean-up" ]; then + cleanup $2 +elif [ "$1" == "--all" ]; then + check_if_folders_exists + extract_zips + decrypt_iso + extract_decrypted + cleanup $2 +else + echo "Usage: $0 {--extract-all|--decrypt-all|--extract-decrypted-all|--need-dkey|--all}" + exit 1 +fi