This commit is contained in:
Ian Skinner 2023-08-19 22:17:51 -04:00 committed by GitHub
parent 3bc02ca6fc
commit c22e4ccdca

View File

@ -2,7 +2,6 @@
# 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
@ -12,11 +11,13 @@ echo "================================================="
declare -i x=0
declare -i i=1
declare -i z=1
echo "Extracting odd CIAs..."
echo "================================================="
sed 1d romfs-dir.txt | while IFS=, read -r START_HEADER; read NEXT_HEADER
do
echo " Check CIA length"
echo "CIA $i header at ${START_HEADER}"
echo "Next header at ${NEXT_HEADER}"
echo "Finding CIA $i end from CIA $((i + 1)) header... "
@ -34,7 +35,10 @@ do
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 " Extract CIA:"
CIA_LENGTH=$(((NEXT_HEADER - START_HEADER) - x + 1))
dd skip=${START_HEADER} count=${CIA_LENGTH} if=romfs.bin of="$i.cia" bs=1
echo "CIA $i saved as '$i.cia'"
echo "================================================="
i+=2
done < romfs-dir.txt
@ -43,6 +47,7 @@ echo "Extracting even CIAs..."
echo "================================================="
sed 1d romfs-dir.txt | while IFS=, read -r START_HEADER; read NEXT_HEADER
do
echo " Check CIA length"
echo "CIA $i header at ${START_HEADER}"
echo "Next header at ${NEXT_HEADER}"
echo "Finding CIA $i end from CIA $((i + 1)) header... "
@ -60,7 +65,12 @@ do
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 " Extract CIA:"
CIA_LENGTH=$(((NEXT_HEADER - START_HEADER) - x + 1))
CIA_NUMBER+=1
dd skip=${START_HEADER} count=${CIA_LENGTH} if=romfs.bin of="$i.cia" bs=1
echo "CIA $i output as '$i.cia', ${CIA_LENGTH} bytes."
CIA_LENGTH=""
echo "================================================="
i+=2
done
done