#!/bin/dash export PATH=/bin l=${HOME}/.config/rebase b=${HOME}/.cache/rebase eb="${b}/rebase_epoch" db="${l}/dynpath.d" for d in ${b} ${db} ; do if [ ! -d ${d} ] ; then echo "Directory ${d} does not exist, trying to re-create." mkdir -p ${d} fi done BaseAddress='' if [ "x86_64" = $( uname -m ) ] ; then DefaultBaseAddress=0x400000000 else DefaultBaseAddress=0x070000000 fi rebuild="no" noaslr="no" verbose="" doSuffixes='dll|so|oct|mex|eln' exeSuffixes='exe' dynPaths=$( cat ${db}/* | sort -u ) dynLocs='' for d in ${dynPaths} ; do [ -d "${d}" ] && dynLocs="${dynLocs} ${d}" done usage () { echo " rebaselst [-h | --help | [ | ... ]] Commands, will be executed in order: ------------------------------------ --verbose Run some commands with verbose output. --rebuild Later commands will discard information in cache files and rebuild them from scratch. --no-rebuild Keep and use information in cache files. This is the default, can be used to cancel effect of a \"--rebuild\" earlier on the command line. update Update all caches. dyn Update cache for dynamic language modules and libraries. This currently implies \"--rebuild\" since modules could have been installed by the user and the cache would be outdated. --noaslr Remove ASLR and TSAware flags from dynamic objects. rebase Rebase with the information in cache files (i.e does not imply an \"update\"). peflags Set PE flags on executables with the information in cache files (i.e does not imply an \"update\"). " } check_file () { if [ "$2" = "yes" -a -e $1 ] ; then echo "removing $1" rm -f $1 fi if [ ! -e "${eb}" ] ; then touch -d "@0" "${eb}" || \ touch -d "1980-01-01 00:00 UTC" "${eb}" || \ touch -d "1999-05-03 07:29:06 UTC" "${eb}" || \ touch -d "2002-08-17 07:00 CEST" "${eb}" fi if [ ! -e "$1" ] ; then echo "creating empty $1" touch -r "${eb}" "$1" fi if [ "$2" != "nowrite" -a -e $1 ] ; then chmod 644 "$1" fi } _tr () { local IFS s r IFS="/-+.," for s in $1; do r="${r}_${s}" done echo "${r}" } update_file () { local IFS f g k l m f="$1" g="${f}.old" mv -f "${f}" "${g}" cat >"${f}" <>"${f}" chmod 444 "${f}" } rebase_do () { local g g="${b}/rebase_all" echo "Rebasing with list ${g}, built from $@." cat $@ | grep -vE '^#' | sort -u >"${g}" if [ ! -e "/etc/rebase.db.i386" -a ! -e "/etc/rebase.db.x86_64" ] ; then BaseAddress="-b ${DefaultBaseAddress}" fi rebase ${BaseAddress} ${verbose} -n -O -T "${g}" if [ "noaslr" = "yes" ] ; then peflags ${verbose} -d0 -t0 -T "${g}" fi BaseAddress='' } peflags_do () { local g g="${b}/rebase_all_exe" echo "Setting PE flags with list ${g}, built from $@." cat $@ | grep -vE '^#|ddd\/Ddd\.exe$' | sort -u >"${g}" peflags ${verbose} -t1 -T "${g}" } rebase_dyn () { local g g="${b}/rebase_dyn" check_file "${g}" "yes" if [ "x" = "${dynLocs:-x}" ] ; then touch "${g}" else echo "Looking for dynamic language modules/libraries in:" for d in ${dynLocs} ; do echo " ${d}" ; done echo "Updating rebase information for dynamic language modules/libraries ${g}." find ${dynLocs} -xdev -regextype posix-extended -regex ".*\.(${doSuffixes})$" -newer "${g}" >>"${g}" fi update_file "${g}" } if [ "$#" = "0" ] ; then set -- "--help" fi while [ $# -gt 0 ] ; do case "$1" in --verbose ) verbose=--verbose ;; --rebuild ) rebuild=yes ;; --noaslr ) noaslr=yes ;; --no-rebuild ) rebuild=no ;; rebase ) rebase_do "${b}/rebase_dyn" ;; peflags ) peflags_do "${b}/rebase_exe" ;; update ) shift set -- dummy dyn $@ ;; dyn ) rebase_dyn ;; -h|--help|* ) usage exit 127 ;; esac shift done exit 0