This is the mail archive of the
cygwin-apps
mailing list for the Cygwin project.
Re: [patch/RFA] rebase: Add -n option.
- From: Corinna Vinschen <corinna-cygwin at cygwin dot com>
- To: cygwin-apps at cygwin dot com, Jason Tishler <jason at tishler dot net>
- Date: Sat, 28 Apr 2012 14:10:57 +0200
- Subject: Re: [patch/RFA] rebase: Add -n option.
- References: <20120423173029.GC25385@calimero.vinschen.de>
- Reply-to: cygwin-apps at cygwin dot com
Jason, Ping?
Corinna
On Apr 23 19:30, Corinna Vinschen wrote:
> Hi Jason,
>
>
> per the discussion starting at
> http://cygwin.com/ml/cygwin/2012-04/msg00443.html
> I would like to apply the following patch to rebase and friends.
>
>
> Thanks,
> Corinna
>
>
> ChangeLog:
>
> * configure.ac (AC_INIT): Bump version to 4.2.0.
> * configure: Regenerate.
> * peflagsall.in: Set DefaultDynBase to 0 to remove the dynamicbase
> flag by default, rather than to set it. Add .oct to DefaultSuffixes,
> just as in rebaseall.in. Fix help text accordingly.
> * rebase.c (long_options): Add --no-dynamicbase.
> (short_options): Add -n.
> (parse_args): Handle -n/--no-dynamicbase option. Set
> ReBaseDropDynamicbaseFlag flag.
> (usage): Add text for new -n/--no-dynamicbase option.
> * rebaseall.in: Call rebase with -n flag on Cygwin.
> * README: Document all aforementioned changes.
>
> imagehelper/ChangeLog:
>
> * imagehelper.h (ReBaseDropDynamicbaseFlag): Declare.
> * rebaseimage.cc: Include windows.h. Handle old w32api releases.
> (ReBaseDropDynamicbaseFlag): Define.
> (ReBaseImage64): Drop IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE flag
> in DllCharacteristics if successfully rebased and
> ReBaseDropDynamicbaseFlag is true.
>
>
> Index: README
> ===================================================================
> RCS file: /sourceware/projects/cygwin-apps-home/cvsfiles/rebase/README,v
> retrieving revision 1.3
> diff -u -p -r1.3 README
> --- README 19 Mar 2012 17:57:48 -0000 1.3
> +++ README 23 Apr 2012 17:27:52 -0000
> @@ -142,8 +142,8 @@ dlls on your entire system:
> Both procedures may be combined into a single, 4-step procedure if desired.
>
> Note that by default, peflagsall will set the tsaware flag on all executables
> -(ash.exe and peflags.exe themselves excluded), and will set the dynamicbase
> -flag on all 'dll' and 'so' files (cygwin1.dll and cyglsa64.dll excluded).
> +(ash.exe and peflags.exe themselves excluded), and will remove the dynamicbase
> +flag on all 'dll', 'so' and 'oct' files (cygwin1.dll and cyglsa64.dll excluded).
>
> If you are used to using the -s option with rebaseall, to add additional
> suffixes to the rebase list (such as .oct), be warned that peflags behaves
> @@ -176,7 +176,7 @@ where:
> -p => skip test for running ash or dash only. This option is supposed to
> be used by Cygwin's setup tool. Only use it if you know what you're
> doing!
> - -s => specify DLL suffix, use multiple if necessary (default: dll, so)
> + -s => specify DLL suffix, use multiple if necessary (default: dll, so, oct)
> -T => specify filelist (or stdin) to list additional files
> -4 => operate only on 32bit objects (ignore 64bit objects) (*)
> -8 => operate only on 64bit objects (ignore 32bit objects) (*)
> @@ -197,15 +197,15 @@ The following is the peflagsall command
>
> peflagsall [-p extra_args] [-d bool] [-t bool] [-s suffix] [-T FileList | -] [-vnh]
>
> - When invoked with no arguments, peflagsall modifies every cygwin exe|dll|so
> - on the system: .exe files have their tsaware flag set, while .dll and .so files
> - have their dynamicbase flag set. However, if any of [-d|-t|-s] are specified
> - then ONLY the actions so specified will occur.
> + When invoked with no arguments, peflagsall modifies every cygwin exe|dll|so|oct
> + on the system: .exe files have their tsaware flag set, while .dll, .so and .oct
> + files have their dynamicbase flag removed. However, if any of [-d|-t|-s] are
> + specified then ONLY the actions so specified will occur.
> -p extra_args pass extra_args to peflags.exe
> -d bool set the dynamicbase flag to 'bool' on all specified files
> -t bool set the tsaware flag to 'bool' on all specified files
> -s suffix search for all files with the specified suffix(es)
> - default: 'exe|dll|so'
> + default: 'exe|dll|so|oct'
> -T FileList in addition to files located via the normal search and
> suffix list, also operate on files listed in FileList
> May be '-' which indicates stdin
> @@ -244,6 +244,7 @@ The following is the rebase command line
> files top-down from there. Without this option the
> files are rebased from BaseAddress bottom-up.
> With the -s option, this option is implicitly set.
> + -n, --no-dynamicbase Remove PE dynamicbase flag from rebased DLLs, if set.
> -o, --offset=OFFSET Specify an additional offset between adjacent DLLs
> when rebasing. Default is no offset.
> -t, --touch Use this option to make sure the file's modification
> Index: configure.ac
> ===================================================================
> RCS file: /sourceware/projects/cygwin-apps-home/cvsfiles/rebase/configure.ac,v
> retrieving revision 1.7
> diff -u -p -r1.7 configure.ac
> --- configure.ac 19 Mar 2012 17:57:48 -0000 1.7
> +++ configure.ac 23 Apr 2012 17:27:52 -0000
> @@ -2,7 +2,7 @@
> # configure.ac for rebase
>
> AC_PREREQ([2.64])
> -AC_INIT([rebase], [4.1.0], [cygwin@cygwin.com])
> +AC_INIT([rebase], [4.2.0], [cygwin@cygwin.com])
> AC_CONFIG_AUX_DIR([build-aux])
> AC_CONFIG_SRCDIR([peflags.c])
> AC_PREFIX_DEFAULT([/usr])
> Index: peflagsall.in
> ===================================================================
> RCS file: /sourceware/projects/cygwin-apps-home/cvsfiles/rebase/peflagsall.in,v
> retrieving revision 1.2
> diff -u -p -r1.2 peflagsall.in
> --- peflagsall.in 29 Jul 2011 13:17:44 -0000 1.2
> +++ peflagsall.in 23 Apr 2012 17:27:52 -0000
> @@ -28,12 +28,12 @@ ProgramName=${0##*/}
> ProgramOptions='p:d:t:s:T:knvh'
> DefaultExtraArgs=
> DefaultTSAware=1
> -DefaultDynBase=1
> +DefaultDynBase=0
> DefaultKeep=
> DefaultDoNothing=
> DefaultVerbose=
> DefaultFileList=
> -DefaultSuffixes='exe|dll|so'
> +DefaultSuffixes='exe|dll|so|oct'
>
> # Define functions
> usage_string="usage: $ProgramName [-p extra_args] [-d bool] [-t bool] [-s suffix] [-T FileList | -] [-vnh]"
> @@ -47,14 +47,14 @@ long_help ()
> {
> echo "$usage_string"
> echo "When invoked with no arguments, $ProgramName modifies every cygwin $DefaultSuffixes"
> - echo "on the system: .exe files have their tsaware flag set, while .dll and .so files"
> - echo "have their dynamicbase flag set. However, if any of [-d|-t|-s] are specified"
> - echo "then ONLY the actions so specified will occur."
> + echo "on the system: .exe files have their tsaware flag set, while .dll, .so and .oct"
> + echo "files have their dynamicbase flag removed. However, if any of [-d|-t|-s] are"
> + echo "specified then ONLY the actions so specified will occur."
> echo " -p extra_args pass extra_args to peflags.exe"
> echo " -d bool set the dynamicbase flag to 'bool' on all specified files"
> echo " -t bool set the tsaware flag to 'bool' on all specified files"
> echo " -s suffix search for all files with the specified suffix(es)"
> - echo " default: 'exe|dll|so'"
> + echo " default: 'exe|dll|so|oct'"
> echo " -T FileList in addition to files located via the normal search and"
> echo " suffix list, also operate on files listed in FileList"
> echo " May be '-' which indicates stdin"
> Index: rebase.c
> ===================================================================
> RCS file: /sourceware/projects/cygwin-apps-home/cvsfiles/rebase/rebase.c,v
> retrieving revision 1.14
> diff -u -p -r1.14 rebase.c
> --- rebase.c 26 Mar 2012 23:45:52 -0000 1.14
> +++ rebase.c 23 Apr 2012 17:27:53 -0000
> @@ -1072,13 +1072,13 @@ static struct option long_options[] = {
> {"database", no_argument, NULL, 's'},
> {"touch", no_argument, NULL, 't'},
> {"filelist", required_argument, NULL, 'T'},
> - {"usage", no_argument, NULL, 'h'},
> + {"no-dynamicbase", no_argument, NULL, 'n'},
> {"verbose", no_argument, NULL, 'v'},
> {"version", no_argument, NULL, 'V'},
> {NULL, no_argument, NULL, 0 }
> };
>
> -static const char *short_options = "48b:dhio:qstT:vV";
> +static const char *short_options = "48b:dhino:qstT:vV";
>
> void
> parse_args (int argc, char *argv[])
> @@ -1126,6 +1126,9 @@ parse_args (int argc, char *argv[])
> case 'T':
> file_list = optarg;
> break;
> + case 'n':
> + ReBaseDropDynamicbaseFlag = TRUE;
> + break;
> case 'v':
> verbose = TRUE;
> break;
> @@ -1278,6 +1281,7 @@ Rebase PE files, usually DLLs, to a spec
> files top-down from there. Without this option the\n\
> files are rebased from BaseAddress bottom-up.\n\
> With the -s option, this option is implicitly set.\n\
> + -n, --no-dynamicbase Remove PE dynamicbase flag from rebased DLLs, if set.\n\
> -o, --offset=OFFSET Specify an additional offset between adjacent DLLs\n\
> when rebasing. Default is no offset.\n\
> -t, --touch Use this option to make sure the file's modification\n\
> Index: rebaseall.in
> ===================================================================
> RCS file: /sourceware/projects/cygwin-apps-home/cvsfiles/rebase/rebaseall.in,v
> retrieving revision 1.7
> diff -u -p -r1.7 rebaseall.in
> --- rebaseall.in 19 Mar 2012 17:57:48 -0000 1.7
> +++ rebaseall.in 23 Apr 2012 17:27:53 -0000
> @@ -33,6 +33,7 @@ ProgramOptions='48b:o:ps:tT:v'
> DefaultBaseAddress=0x70000000
> DefaultOffset=@DEFAULT_OFFSET_VALUE@
> DefaultTouch=
> +DefaultNoDyn=
> DefaultVerbose=
> DefaultFileList=
> DefaultSuffixes='dll|so|oct'
> @@ -57,6 +58,7 @@ trap cleanup 1 2 15
> BaseAddress=""
> Offset="${DefaultOffset}"
> Touch="${DefaultTouch}"
> +NoDyn="${DefaultNoDyn}"
> Verbose="${DefaultVerbose}"
> FileList="${DefaultFileList}"
> Suffixes="${DefaultSuffixes}"
> @@ -203,6 +205,9 @@ case $Platform in
> sed -e '/cygwin1\.dll$/d' -e '/cyglsa.*\.dll$/d' \
> -e '/sys-root\/mingw/d' -e 's/^/\//' \
> -e '/d?ash\.exe$/d' -e '/rebase\.exe$/d' >"${TmpFile}"
> + # Unconditionally add the -n flag so rebased DLLs get the
> + # dynamicbase flag removed.
> + NoDyn='-n'
> ;;
> mingw|msys)
> for f in /bin /lib
> @@ -224,9 +229,9 @@ fi
>
> if [ -z "${BaseAddress}" ]
> then
> - rebase "${Verbose}" "${Touch}" -s "${Mach}" -T "${TmpFile}"
> + rebase "${Verbose}" "${Touch}" "${NoDyn}" -s "${Mach}" -T "${TmpFile}"
> else
> - rebase "${Verbose}" "${Touch}" -s "${Mach}" -b "${BaseAddress}" -o "${Offset}" -T "${TmpFile}"
> + rebase "${Verbose}" "${Touch}" "${NoDyn}" -s "${Mach}" -b "${BaseAddress}" -o "${Offset}" -T "${TmpFile}"
> fi
> ExitCode=$?
>
> Index: imagehelper/imagehelper.h
> ===================================================================
> RCS file: /sourceware/projects/cygwin-apps-home/cvsfiles/rebase/imagehelper/imagehelper.h,v
> retrieving revision 1.6
> diff -u -p -r1.6 imagehelper.h
> --- imagehelper/imagehelper.h 19 Mar 2012 17:57:49 -0000 1.6
> +++ imagehelper/imagehelper.h 23 Apr 2012 17:27:53 -0000
> @@ -30,6 +30,9 @@ extern "C" {
> /* Set to TRUE if ReBaseImage{64} should also set the files last write
> time to TimeStamp when the file has been successfully rebased. */
> extern BOOL ReBaseChangeFileTime;
> +/* Set to TRUE, if rebasing should also drop the /DYNAMICBASE flag
> + from the PE flags. */
> +extern BOOL ReBaseDropDynamicbaseFlag;
>
> BOOL ReBaseImage64(
> LPCSTR CurrentImageName,
> Index: imagehelper/rebaseimage.cc
> ===================================================================
> RCS file: /sourceware/projects/cygwin-apps-home/cvsfiles/rebase/imagehelper/rebaseimage.cc,v
> retrieving revision 1.5
> diff -u -p -r1.5 rebaseimage.cc
> --- imagehelper/rebaseimage.cc 19 Mar 2012 17:57:49 -0000 1.5
> +++ imagehelper/rebaseimage.cc 23 Apr 2012 17:27:53 -0000
> @@ -21,10 +21,17 @@
> #include <iostream>
> #include <sstream>
>
> +#include <windows.h>
> +/* Take care of old w32api releases which screwed up the definition. */
> +#ifndef IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE
> +# define IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE 0x40
> +#endif
> +
> #include "objectfile.h"
> #include "imagehelper.h"
>
> BOOL ReBaseChangeFileTime = FALSE;
> +BOOL ReBaseDropDynamicbaseFlag = FALSE;
>
> BOOL ReBaseImage64 (
> LPCSTR CurrentImageName,
> @@ -121,12 +128,22 @@ BOOL ReBaseImage64 (
> return false;
> }
>
> - if (!fGoingDown)
> - *NewImageBase += *NewImageSize;
> -
> if (ReBaseChangeFileTime)
> dll.setFileTime (TimeStamp);
>
> + if (ReBaseDropDynamicbaseFlag)
> + {
> + if (dll.is64bit ())
> + ntheader64->OptionalHeader.DllCharacteristics
> + &= ~IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE;
> + else
> + ntheader32->OptionalHeader.DllCharacteristics
> + &= ~IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE;
> + }
> +
> + if (!fGoingDown)
> + *NewImageBase += *NewImageSize;
> +
> SetLastError(NO_ERROR);
> return true;
> }
>
> --
> Corinna Vinschen Please, send mails regarding Cygwin to
> Cygwin Project Co-Leader cygwin AT cygwin DOT com
> Red Hat
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Project Co-Leader cygwin AT cygwin DOT com
Red Hat