-
Notifications
You must be signed in to change notification settings - Fork 0
/
NspUpdaterRun
100 lines (83 loc) · 2.35 KB
/
NspUpdaterRun
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
# check if command line argument is empty or not present
if [ -z $1 ]; then
basensp=$(ls -S *.nsp | head -1)
updatensp=$(ls -Sr *.nsp | head -1)
else
basensp=$1
fi
if [ -z $2 ]; then
updatensp=$(ls -Sr *.nsp | head -1)
else
updatensp=$2
fi
echo $basensp
echo $updatensp
mkdir -p ~/.switch
cp prod.keys ~/.switch
touch ~/.switch/title.keys
mkdir temp hactool_out
cd hactool_out
# derive title keys from base and update NSPs
derivekey () {
title=$(xxd *.tik | grep -oP -m 1 "(?<=2a0: ).{39}" | sed 's/ //g')
key=$(xxd *.tik | grep -oP -m 1 "(?<=180: ).{39}" | sed 's/ //g')
sed -i "/$title=$key/d" ~/.switch/title.keys
echo $title=$key >> ~/.switch/title.keys
}
../hactool -t pfs0 "../$basensp" --outdir .
derivekey
rm *
../hactool -t pfs0 "../$updatensp" --outdir .
derivekey
rm *
# extract base NSP and move program NCA to temp dir
../hactool -t pfs0 "../$basensp" --outdir .
for i in *.nca
do
type=$(../hactool $i | grep -oP "(?<=Content Type:\s{23}).*")
if [ $type == "Program" ]; then
basenca=$i
mv $i ../temp
fi
done
rm *
# extract update NSP and move program & control NCAs to temp dir
../hactool -t pfs0 "../$updatensp" --outdir .
for i in *.nca
do
type=$(../hactool $i | grep -oP "(?<=Content Type:\s{23}).*")
if [ $type == "Program" ]; then
updatenca=$i
mv $i ../temp
elif [ $type == "Control" ]; then
controlnca=$i
mv $i ../temp
fi
done
rm *
cd ..
rm -rf hactool_out
cp hactool temp/
cp hacpack temp/
cd temp
# parse Title ID from base program NCA
titleid=$(./hactool $basenca | grep -oP "(?<=Title ID:\s{27}).*")
# extract base and update NCAs into romfs end exefs
mkdir exefs romfs
./hactool --basenca="$basenca" $updatenca --romfsdir="romfs" --exefsdir="exefs"
rm $basenca $updatenca
# pack romfs and exefs into one NCA
mkdir nca
./hacpack --type="nca" --ncatype="program" --plaintext --exefsdir="exefs" --romfsdir="romfs" --titleid="$titleid" --outdir="nca"
patchednca=$(ls nca)
mv $controlnca nca
rm -rf exefs romfs
# generate meta NCA from patched NCA and control NCA
./hacpack --type="nca" --ncatype="meta" --titletype="application" --programnca="nca/$patchednca" --controlnca="nca/$controlnca" --titleid="$titleid" --outdir="nca"
# pack all three NCAs into an NSP
mkdir nsp
./hacpack --type="nsp" --ncadir="nca" --titleid="$titleid" --outdir="nsp"
cd ..
mv temp/nsp/$titleid.nsp ./$titleid[Updated].nsp
rm -rf temp