Skip to content

Instantly share code, notes, and snippets.

@ajeddeloh
Created April 16, 2018 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajeddeloh/365cfed1d3a326362e05f78720baf4df to your computer and use it in GitHub Desktop.
Save ajeddeloh/365cfed1d3a326362e05f78720baf4df to your computer and use it in GitHub Desktop.
#!/bin/bash
versions="$(curl https://coreos.com/releases/releases.json 2>/dev/null | jq keys | jq .[] | tr -d '\"' | tr '\n' ' ')"
mkdir -p ~/grub-info/
LINUX_MOD='usr/lib/grub/i386-pc/linux.module'
LINUX_DEBUG="/usr/lib/debug/${LINUX_MOD}.debug"
function download_release() {
local major=$(cut -d. -f1 <<< $1)
if [[ $major -lt 926 ]]; then
return
fi
if [[ $major -gt 1722 ]]; then
return
fi
if [[ -d grub-info/$1 ]]; then
return
fi
echo "version $1"
mkdir grub-info/$1
pushd grub-info/$1
gsutil -q cp "gs://builds.developer.core-os.net/sdk/amd64/$1/pkgs/sys-boot/grub-*tbz2" .
for i in grub-*
do
mkdir $(basename -s .tbz2 $i)
mv $i $(basename -s .tbz2 $i)
pushd $(basename -s .tbz2 $i)
qtbz2 -s $i
tar xf ${i/.tbz2/.tar.bz2}
popd
done
popd
}
for i in $versions
do
download_release "$i"
done
for rel in grub-info/*
do
for grubver in $rel/*
do
if [[ $(basename $grubver) == 'grub-*' ]]; then
continue
fi
mod="$grubver/$LINUX_MOD"
hashsum=$(sha512sum $grubver/usr/lib/grub/i386-pc/linux.mod | cut -d' ' -f1)
if [[ -e $grubver/$LINUX_DEBUG ]]; then
eu-unstrip $mod $grubver/$LINUX_DEBUG -o /tmp/abcde
mod=/tmp/abcde
fi
offset="0x$(objdump -t $mod | grep linux_params | cut -d ' ' -f1)"
if [[ -z $offset ]]; then
echo $grubver failed
continue
fi
textoffset="0x$(objdump -h -w linux.mod | grep .text | tr -s ' '|cut -d' ' -f7)"
badval="$(($offset + (616*0x3fc) ))"
goodval="$(($offset + 616 ))"
# mangle it into a format usable bu printf
goodval="\\x$(python -c "import re; print(('\\\x'.join(re.findall('..', format(${goodval}, '08x'))[::-1])))")"
value="b8 $(python -c "import re; print((' '.join(re.findall('..', format(${badval}, '08x'))[::-1])))")"
opcode="0x$(objdump -d $mod | grep "$value" | cut -d':' -f1 | tr -d ' ')"
if [[ $opcode == "0x" ]]; then
# some early CL versions has two binpkgs where only one has the bad code
# skip versions that don't have bad code
continue
fi
# +1 to account for the opcode byte
fileoffset=$((${textoffset} + ${opcode} + 1))
echo $hashsum $fileoffset $goodval
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment