Skip to content

Instantly share code, notes, and snippets.

@bkifft
Created September 24, 2016 18:34
Show Gist options
  • Save bkifft/c6fa52dc39e29b85cb2787ac6dd633ed to your computer and use it in GitHub Desktop.
Save bkifft/c6fa52dc39e29b85cb2787ac6dd633ed to your computer and use it in GitHub Desktop.
#!/bin/bash
#requirements:
#sha1sum (part of coreutils)
#xxd (part of vim)
#https://github.com/socram8888/ulread
#https://github.com/socram8888/amiitool
#put ulread, ulwrite and amiitool in the same directory as this script
if [ $# -ne 2 ]
then
echo "Usage: $0 key_file encrypted_dump_file"
exit
fi
if [ "$(sha1sum "$1" |cut -d' ' -f1)" != "bbdbb49a917d14f7a997d327ba40d40c39e606ce" ]
then
echo "key_file not sane"
exit
fi
#get the empty tag uid:
taguid=$(./ulread -c2 |xxd -g1 -p)
#decrypt the dump
./amiitool -d -k $1 -i $2 -o dec.bin
#modify the uid record
echo "01D4: $taguid" | xxd -r - dec.bin
#reencrypt the uid modified dump
./amiitool -e -k $1 -i dec.bin -o enc.bin
#generate pw bytes
taguid1="$(echo $taguid | cut -b3,4)"
taguid2="$(echo $taguid | cut -b5,6)"
taguid3="$(echo $taguid | cut -b9,10)"
taguid4="$(echo $taguid | cut -b11,12)"
taguid5="$(echo $taguid | cut -b13,14)"
taguid6="$(echo $taguid | cut -b15,16)"
pw1="$(printf '%02X\n' $(( 0xAA ^ 0x$taguid1 ^ 0x$taguid3 )))"
pw2="$(printf '%02X\n' $(( 0x55 ^ 0x$taguid2 ^ 0x$taguid4 )))"
pw3="$(printf '%02X\n' $(( 0xAA ^ 0x$taguid3 ^ 0x$taguid5 )))"
pw4="$(printf '%02X\n' $(( 0x55 ^ 0x$taguid4 ^ 0x$taguid6 )))"
#add password and PACK
echo "0214: $pw1$pw2$pw3$pw4" | xxd -r - enc.bin #pw
echo "0218: 80800000" | xxd -r - enc.bin #pack
#create an intermediary bin
cp enc.bin med.bin
#set the default values in the intermediary bin
echo "000A: 0000" | xxd -r - med.bin
echo "0208: 000000BD040000FF0005" | xxd -r - med.bin
#write it
cat med.bin| ./ulwrite -l
cat enc.bin| ./ulwrite -l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment