[patch/RFA] rebase: Add -t option.

Corinna Vinschen corinna-cygwin@cygwin.com
Mon Mar 12 10:46:00 GMT 2012


Hi Jason,


as discussed in the thread starting at
http://cygwin.com/ml/cygwin/2012-03/msg00263.html
I propose a new option -t/--touch to rebase.  Below's my patch.


Thanks
Corinna


    ChangeLog:

	* rebase.c (long_options): Add --touch.
	(short_options): Add -t.
	(parse_args): Handle -t/--touch option. Set ReBaseChangeFileTime flag.
	(usage): Add text for new -t/--touch option.
	* rebaseall.in: Add -t option.

    imagehelper/ChangeLog:

	* imagehelper.h (ReBaseChangeFileTime): Declare.
	* objectfile.h (ObjectFile::setFileTime): New method.
	* rebaseimage.cc (ReBaseChangeFileTime): Define.
	(ReBaseImage64): Call ObjectFile::setFileTime if successfully rebased
	and ReBaseChangeFileTime is true.


Index: rebase.c
===================================================================
RCS file: /sourceware/projects/cygwin-apps-home/cvsfiles/rebase/rebase.c,v
retrieving revision 1.12
diff -u -p -r1.12 rebase.c
--- rebase.c	9 Aug 2011 09:32:47 -0000	1.12
+++ rebase.c	12 Mar 2012 10:43:04 -0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2002, 2003, 2004, 2008, 2011 Jason Tishler
+ * Copyright (c) 2001, 2002, 2003, 2004, 2008, 2011, 2012 Jason Tishler
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -1014,6 +1014,7 @@ static struct option long_options[] = {
   {"offset",	required_argument, NULL, 'o'},
   {"quiet",	no_argument,	   NULL, 'q'},
   {"database",	no_argument,	   NULL, 's'},
+  {"touch",	no_argument,	   NULL, 't'},
   {"filelist",	required_argument, NULL, 'T'},
   {"usage",	no_argument,	   NULL, 'h'},
   {"verbose",	no_argument,	   NULL, 'v'},
@@ -1021,7 +1022,7 @@ static struct option long_options[] = {
   {NULL,	no_argument,	   NULL,  0 }
 };
 
-static const char *short_options = "48b:dhio:qsT:vV";
+static const char *short_options = "48b:dhio:qstT:vV";
 
 void
 parse_args (int argc, char *argv[])
@@ -1063,6 +1064,9 @@ parse_args (int argc, char *argv[])
 	  /* FIXME: For now enforce top-down rebasing when using the database.*/
 	  down_flag = TRUE;
 	  break;
+	case 't':
+	  ReBaseChangeFileTime = TRUE;
+	  break;
 	case 'T':
 	  file_list = optarg;
 	  break;
@@ -1220,6 +1224,9 @@ Rebase PE files, usually DLLs, to a spec
                           With the -s option, this option is implicitly 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\
+                          time is bumped if it has been successfully rebased.\n\
+                          Usually rebase does not change the file's time.\n\
   -T, --filelist=FILE     Also rebase the files specified in FILE.  The format\n\
                           of FILE is one DLL per line.\n\
   -q, --quiet             Be quiet about non-critical issues.\n\
Index: rebaseall.in
===================================================================
RCS file: /sourceware/projects/cygwin-apps-home/cvsfiles/rebase/rebaseall.in,v
retrieving revision 1.6
diff -u -p -r1.6 rebaseall.in
--- rebaseall.in	24 Oct 2011 07:41:59 -0000	1.6
+++ rebaseall.in	12 Mar 2012 10:43:04 -0000
@@ -1,7 +1,7 @@
 #!/bin/@ASH@
 
 #
-# Copyright (c) 2003, 2005, 2006, 2008, 2011 Jason Tishler
+# Copyright (c) 2003, 2005, 2006, 2008, 2011, 2012 Jason Tishler
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -29,9 +29,10 @@ tp2=${tp1:-.}
 PATH=$(cd $tp2 && pwd):@bindir@:/bin
 
 ProgramName=${0##*/}
-ProgramOptions='48b:o:s:T:v'
+ProgramOptions='48b:o:s:tT:v'
 DefaultBaseAddress=0x70000000
 DefaultOffset=@DEFAULT_OFFSET_VALUE@
+DefaultTouch=
 DefaultVerbose=
 DefaultFileList=
 DefaultSuffixes='dll|so'
@@ -39,7 +40,7 @@ DefaultSuffixes='dll|so'
 # Define functions
 usage()
 {
-    echo "usage: ${ProgramName} [-b BaseAddress] [-o Offset] [-s DllSuffix] [-T FileList | -] [-4|-8] [-v]"
+    echo "usage: ${ProgramName} [-b BaseAddress] [-o Offset] [-s DllSuffix] [-T FileList | -] [-4|-8] [-t] [-v]"
     exit 1
 }
 
@@ -55,6 +56,7 @@ trap cleanup 1 2 15
 # Set defaults
 BaseAddress=""
 Offset="${DefaultOffset}"
+Touch="${DefaultTouch}"
 Verbose="${DefaultVerbose}"
 FileList="${DefaultFileList}"
 Suffixes="${DefaultSuffixes}"
@@ -140,6 +142,8 @@ do
 	Offset="${OPTARG}";;
     s)
 	Suffixes="${Suffixes}|${OPTARG}";;
+    t)
+    	Touch="-t";;
     T)
 	FileList="${OPTARG}";;
     v)
@@ -214,9 +218,9 @@ fi
 
 if [ -z "${BaseAddress}" ]
 then
-  rebase "${Verbose}" -s "${Mach}" -T "${TmpFile}"
+  rebase "${Verbose}" "${Touch}" -s "${Mach}" -T "${TmpFile}"
 else
-  rebase "${Verbose}" -s "${Mach}" -b "${BaseAddress}" -o "${Offset}" -T "${TmpFile}"
+  rebase "${Verbose}" "${Touch}" -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.5
diff -u -p -r1.5 imagehelper.h
--- imagehelper/imagehelper.h	10 Jul 2011 12:26:45 -0000	1.5
+++ imagehelper/imagehelper.h	12 Mar 2012 10:43:04 -0000
@@ -27,6 +27,10 @@
 extern "C" {
 #endif
 
+/* 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;
+
 BOOL ReBaseImage64(
   LPCSTR CurrentImageName,
   LPCSTR SymbolPath,       // ignored
Index: imagehelper/objectfile.h
===================================================================
RCS file: /sourceware/projects/cygwin-apps-home/cvsfiles/rebase/imagehelper/objectfile.h,v
retrieving revision 1.5
diff -u -p -r1.5 objectfile.h
--- imagehelper/objectfile.h	10 Jul 2011 12:26:45 -0000	1.5
+++ imagehelper/objectfile.h	12 Mar 2012 10:43:04 -0000
@@ -75,6 +75,18 @@ class ObjectFile : public Base
       return sections;
     }
 
+    void setFileTime (ULONG seconds_since_epoche)
+    {
+      LARGE_INTEGER filetime;
+/* 100ns difference between Windows and UNIX timebase. */
+#define FACTOR (0x19db1ded53e8000LL)
+/* # of 100ns intervals per second. */
+#define NSPERSEC 10000000LL
+      filetime.QuadPart = seconds_since_epoche * NSPERSEC + FACTOR;
+      if (!SetFileTime (hfile, NULL, NULL, (FILETIME *) &filetime))
+        std::cerr << "SetFileTime: " << GetLastError () << std::endl;
+    }
+
     ~ObjectFile();
 
 
Index: imagehelper/rebaseimage.cc
===================================================================
RCS file: /sourceware/projects/cygwin-apps-home/cvsfiles/rebase/imagehelper/rebaseimage.cc,v
retrieving revision 1.4
diff -u -p -r1.4 rebaseimage.cc
--- imagehelper/rebaseimage.cc	8 Jul 2011 07:18:55 -0000	1.4
+++ imagehelper/rebaseimage.cc	12 Mar 2012 10:43:04 -0000
@@ -24,6 +24,8 @@
 #include "objectfile.h"
 #include "imagehelper.h"
 
+BOOL ReBaseChangeFileTime = FALSE;
+
 BOOL ReBaseImage64 (
   LPCSTR CurrentImageName,
   LPCSTR SymbolPath,       // ignored
@@ -122,6 +124,9 @@ BOOL ReBaseImage64 (
   if (!fGoingDown)
     *NewImageBase += *NewImageSize;
 
+  if (ReBaseChangeFileTime)
+    dll.setFileTime (TimeStamp);
+
   SetLastError(NO_ERROR);
   return true;
 }

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat



More information about the Cygwin-apps mailing list