Skip to content

Commit

Permalink
Making the script work when a bad lib is the last entry in the .gnu.v…
Browse files Browse the repository at this point in the history
…ersion_r table
  • Loading branch information
saboya committed Dec 28, 2018
1 parent 5f29f96 commit 1ef1adc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ This is known to work with Spotify 1.0.45 and 1.0.47 64-bit.

This script is not POSIX-compliant. I wrote it with Bash in mind, may or may not work with other shells.

## Known issues

This script probably won't work if one of the problematic libraries is the first or last in the .gnu.version_r table. I intend to address this soon™.

## Useful resources

* https://en.wikipedia.org/wiki/Executable_and_Linkable_Format#Section_header
Expand Down
22 changes: 11 additions & 11 deletions spotify-patcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,28 +87,28 @@ IFS=$'\n'
LIBS=($(readelf -V $SPOTIFY_BIN 2>/dev/null | sed '/^$/,/^$/d' | grep "File:"))

for lib in ${LIBS[@]}; do
if ! is_bad_lib $lib; then
GOOD_OFFSETS+=($(parse_lib_offset $lib))
fi
done
IFS=$IFS_pre

for lib in ${GOOD_OFFSETS[@]}; do
lib_offset=$(parse_lib_offset $lib)

if [ ! -z ${last_good+x} ]; then
last_pointer_byteoffset=$(($GNU_VERSION_OFFSET+$last_good+0xc))
last_pointer=$(hexdump -s $last_pointer_byteoffset -n 2 -e '"0x%04x\n"' $SPOTIFY_BIN)
if is_bad_lib $lib; then
echo $lib
printf "Bad lib found, updating pointer:\n"

if [[ $(($lib_offset)) != $(($last_good+$last_pointer)) ]]; then
new_offset=$(printf '%04x%s' $(($lib_offset-$last_good)))
printf "Bad lib found, updating pointer:\n"

if [[ $lib == ${LIBS[-1]} ]]; then
printf " Bad lib is last lib, setting pointer to 0.\n"
new_offset=$(printf '%04x%s' 0)
fi

printf " Writing 0x%s to 0x%X\n" $new_offset $last_pointer_byteoffset
echo -ne "\x${new_offset:2:4}\x${new_offset:0:2}" | dd of=$SPOTIFY_BIN seek=$last_pointer_byteoffset oflag=seek_bytes bs=2 count=1 conv=notrunc status=none
fi
fi

last_good=$lib_offset
last_pointer_byteoffset=$(($GNU_VERSION_OFFSET+$last_good+0xc))
last_pointer=$(hexdump -s $last_pointer_byteoffset -n 2 -e '"0x%04x\n"' $SPOTIFY_BIN)
done

update_header
Expand Down

0 comments on commit 1ef1adc

Please sign in to comment.