summary refs log tree commit diff
path: root/pkgs/stdenv/cygwin/rebase-x86_64.sh
blob: 6dccdc40c7221b2b8a0db5fb744138e113da27e3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
fixupOutputHooks+=(_cygwinFixAutoImageBase)

_cygwinFixAutoImageBase() {
    if [ "${dontRebase-}" == 1 ] || [ ! -d "$prefix" ]; then
        return
    fi
    find "$prefix" -name "*.dll" -type f | while read DLL; do
        if [ -f /etc/rebasenix.nextbase ]; then
            NEXTBASE="$(</etc/rebasenix.nextbase)"
        fi
        NEXTBASE=${NEXTBASE:-0x200000001}

        REBASE=(`/bin/rebase -i $DLL`)
        BASE=${REBASE[2]}
        SIZE=${REBASE[4]}
        SKIP=$(((($SIZE>>16)+1)<<16))

        echo "REBASE FIX: $DLL $BASE -> $NEXTBASE"
        /bin/rebase -b $NEXTBASE $DLL
        NEXTBASE="0x`printf %x $(($NEXTBASE+$SKIP))`"

        echo $NEXTBASE > /etc/rebasenix.nextbase
    done
}