Last active
June 3, 2018 15:01
-
-
Save perillamint/49fd44e2bb13fabedb3e69a2997fb351 to your computer and use it in GitHub Desktop.
Nintendo Switch system title batch decrypter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
HACTOOL=./hactool/hactool | |
KEYFILE=nintendo-switch-keys.dat | |
decrypt-nca() { | |
NCAFILE=$1 | |
TARGDIR=$2 | |
TITLEID=$($HACTOOL -k $KEYFILE -i $NCAFILE 2>/dev/null | grep Title\ ID\: | head -n 1 | sed 's/ //g' | cut -d ':' -f 2) | |
CONTENTTYPE=$($HACTOOL -k $KEYFILE -i $NCAFILE 2>/dev/null | grep Content\ Type\: | sed 's/ //g' | cut -d ':' -f 2) | |
if [ -z "$TITLEID" ]; then | |
echo "Failed to decode NCA file: $NCAFILE" | |
exit 1 | |
fi | |
TARGETFILE=$TARGDIR/$TITLEID.nca | |
if [ "$CONTENTTYPE" = 'Meta' ]; then | |
TARGETFILE=$TARGDIR/$TITLEID.meta.nca | |
fi | |
$HACTOOL -k $KEYFILE --plaintext="$TARGETFILE" $NCAFILE 2>/dev/null > /dev/null | |
} | |
usage() { | |
echo "Usage: $1 <encrypted system titles location> <decrypted output directory>" | |
exit 1 | |
} | |
SYSDIR=$1 | |
TARGETDIR=$2 | |
if [ -z "$SYSDIR" ]; then | |
usage $0 | |
exit 1; | |
fi | |
if [ -z "$TARGETDIR" ]; then | |
usage $0 | |
exit 1; | |
fi | |
NCAFILES=$(find "$SYSDIR" -type f) | |
mkdir -p "${TARGETDIR}" | |
for i in $NCAFILES; do | |
echo "Decrypting ${i}"; | |
decrypt-nca "${i}" "${TARGETDIR}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment