This commit is contained in:
Ian Skinner 2023-08-19 20:56:37 -04:00 committed by GitHub
commit 3bc02ca6fc

66
extract-gigaleak-csu.sh Normal file
View File

@ -0,0 +1,66 @@
# extract-gigaleak-csu
# Lillian Skinner
# Last modified 2023/08/19
# Extracts firmware CIAs from the RomFS of "SystemUpdater-0_13-0927-UnFixedKey.csu". This can't be done with other tools as 0.13.0 doesn't use the normal RomFS format.
# So far this only gets the start/end addresses of the CIAs.
echo "Finding CIA headers in file..."
od -t x -A d romfs.bin | grep "00002020 00000000 00000a00 00000350" | sed 's/ .*//' | sed 's/^0*//' > romfs-dir.txt
# Get start address of every CIA header and store to file
echo "Found all headers!"
echo "================================================="
declare -i x=0
declare -i i=1
echo "Extracting odd CIAs..."
echo "================================================="
sed 1d romfs-dir.txt | while IFS=, read -r START_HEADER; read NEXT_HEADER
do
echo "CIA $i header at ${START_HEADER}"
echo "Next header at ${NEXT_HEADER}"
echo "Finding CIA $i end from CIA $((i + 1)) header... "
y="00"
x=0
z="00"
while [ "$y" = "00" ]; do
x+=1
y=$(od -j $((NEXT_HEADER - x)) -N 1 -x -A n romfs.bin | sed 's|[ ,]||g' | sed 's/^..//');
# Get bytes one backwards from next header
# printf '%x\n' $((NEXT_HEADER - x))
# echo $y
# echo $x
done
echo "End found!"
echo "Non-zerobyte ($y) at $((NEXT_HEADER - x))"
echo "Padding from CIA $i to $((i + 1)) is $((x - 1)) bytes."
echo "CIA $i done!"
echo "================================================="
i+=2
done < romfs-dir.txt
echo "Extracting even CIAs..."
echo "================================================="
sed 1d romfs-dir.txt | while IFS=, read -r START_HEADER; read NEXT_HEADER
do
echo "CIA $i header at ${START_HEADER}"
echo "Next header at ${NEXT_HEADER}"
echo "Finding CIA $i end from CIA $((i + 1)) header... "
y="00"
x=0
z="00"
while [ "$y" = "00" ]; do
x+=1
y=$(od -j $((NEXT_HEADER - x)) -N 1 -x -A n romfs.bin | sed 's|[ ,]||g' | sed 's/^..//');
# Get bytes one backwards from next header
# printf '%x\n' $((NEXT_HEADER - x))
# echo $y
# echo $x
done
echo "End found!"
echo "Non-zerobyte ($y) at $((NEXT_HEADER - x))"
echo "Padding from CIA $i to $((i + 1)) is $((x - 1)) bytes."
echo "CIA $i done!"
echo "================================================="
i+=2
done