Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com From: "Ralf Habacker" To: "Cygwin" Subject: rebase addon - Bas and Size listing of dll's without rebasing Date: Wed, 26 Dec 2001 21:08:49 +0100 Message-ID: <000c01c18e49$22279220$526307d5@BRAMSCHE> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_000D_01C18E51.83EBFA20" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook 8.5, Build 4.71.2173.0 Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 ------=_NextPart_000_000D_01C18E51.83EBFA20 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hi, while porting kde2 the rebase tool solved some problems for me on using libtools libltdl. In the past I have to use the LTDL_DLOPEN_DEPLIBS in the config.h of libtldl, which enables loading of all dependency dll's of a lib and because of many dll's used for kde this slow down application loading significantly. If I haven't used this flag, cygwin tells about a "... can't remap ..." problem. After rebasing the dll's from the kdelibs, this error does not happens anymore and I can reject this config option. libltdl/config.h ... /* Define if the OS needs help to load dependent libraries for dlopen(). */ //#define LTDL_DLOPEN_DEPLIBS 1 .... On analysing this problem I added an option "-l" to the rebase tool to list dll's imagebase and -size without rebasing. It's very interesting to see how MS chooses there Imagebase. Because I hacked this very quick, I have used simple FILE structure and fopen/fread calls. Perhaps someone like to change this to iostream functionality. $ rebase -h rebase: unknown option -- h usage: rebase -b BaseAddress [-d] -o Offset ... rebase usage: rebase -l ... list Imagebase and -size of Example: $ rebase -l /opt/kde2/bin/*.dll c:\programme\cygwin\opt\kde2\bin\cygDCOP-1.dll - ImageBase: 74fb0000 ImageSize: 00026000 c:\programme\cygwin\opt\kde2\bin\cygartsc-0.dll - ImageBase: 74f80000 ImageSize: 00007000 c:\programme\cygwin\opt\kde2\bin\cygartsflow-0.dll - ImageBase: 74ee0000 ImageSize: 0007a000 c:\programme\cygwin\opt\kde2\bin\cygartsflow_idl-0.dll - ImageBase: 74e50000 ImageSize: 0006f000 c:\programme\cygwin\opt\kde2\bin\cygartskde.dll - ImageBase: 74df0000 ImageSize: 0003f000 c:\programme\cygwin\opt\kde2\bin\cygkICE-0.dll - ImageBase: 74db0000 ImageSize: 00017000 c:\programme\cygwin\opt\kde2\bin\cygkab-3.dll - ImageBase: 74d30000 ImageSize: 0005e000 c:\programme\cygwin\opt\kde2\bin\cygkbuildsycoca.dll - ImageBase: 74cf0000 ImageSize: 0001d000 c:\programme\cygwin\opt\kde2\bin\cygkdecore-3.dll - ImageBase: 74b30000 ImageSize: 00194000 c:\programme\cygwin\opt\kde2\bin\cygkdefakes-3.dll - ImageBase: 74b00000 ImageSize: 00007000 c:\programme\cygwin\opt\kde2\bin\cygkdeprint-0.dll - ImageBase: 74a50000 ImageSize: 00084000 c:\programme\cygwin\opt\kde2\bin\cygkdeprint_management-0.dll - ImageBase: 749b0000 ImageSize: 00075000 c:\programme\cygwin\opt\kde2\bin\cygkdesu-1.dll - ImageBase: 74960000 ImageSize: 0002d000 c:\programme\cygwin\opt\kde2\bin\cygkdeui-3.dll - ImageBase: 74750000 ImageSize: 001ee000 c:\programme\cygwin\opt\kde2\bin\cygkfile-3.dll - ImageBase: 74690000 ImageSize: 0009c000 c:\programme\cygwin\opt\kde2\bin\cygkio-3.dll - ImageBase: 74590000 ImageSize: 000d2000 c:\programme\cygwin\opt\kde2\bin\cygkjava-1.dll - ImageBase: 74540000 ImageSize: 00027000 c:\programme\cygwin\opt\kde2\bin\cygkjs-1.dll - ImageBase: 744d0000 ImageSize: 00044000 c:\programme\cygwin\opt\kde2\bin\cygkmedia2-0.dll - ImageBase: 74480000 ImageSize: 00025000 c:\programme\cygwin\opt\kde2\bin\cygkmedia2_idl-0.dll - ImageBase: 74400000 ImageSize: 00054000 c:\programme\cygwin\opt\kde2\bin\cygkmid-0.dll - ImageBase: 743c0000 ImageSize: 0001b000 c:\programme\cygwin\opt\kde2\bin\cygkonq-3.dll - ImageBase: 74300000 ImageSize: 0009c000 c:\programme\cygwin\opt\kde2\bin\cygkonqsidebartree_bookmarks-0.dll - ImageBase: 742d0000 ImageSize: 0000e000 c:\programme\cygwin\opt\kde2\bin\cygkparts-1.dll - ImageBase: 74270000 ImageSize: 00033000 c:\programme\cygwin\opt\kde2\bin\cygkspell-3.dll - ImageBase: 74220000 ImageSize: 00029000 c:\programme\cygwin\opt\kde2\bin\cygkssl-2.dll - ImageBase: 741d0000 ImageSize: 0002e000 c:\programme\cygwin\opt\kde2\bin\cygksycoca-3.dll - ImageBase: 740f0000 ImageSize: 000b9000 c:\programme\cygwin\opt\kde2\bin\cygktexteditor-0.dll - ImageBase: 740c0000 ImageSize: 0000f000 c:\programme\cygwin\opt\kde2\bin\cygltdl-0.dll - ImageBase: 74090000 ImageSize: 0000a000 c:\programme\cygwin\opt\kde2\bin\cygmcop-0.dll - ImageBase: 73f60000 ImageSize: 00101000 c:\programme\cygwin\opt\kde2\bin\cygmcop_mt-0.dll - ImageBase: 73f30000 ImageSize: 00007000 c:\programme\cygwin\opt\kde2\bin\cygqtmcop-0.dll - ImageBase: 73ef0000 ImageSize: 0001f000 c:\programme\cygwin\opt\kde2\bin\cygsoundserver_idl-0.dll - ImageBase: 73e70000 ImageSize: 0005a000 c:\programme\cygwin\opt\kde2\bin\cygxml2-2.dll - ImageBase: 73dc0000 ImageSize: 00085000 c:\programme\cygwin\opt\kde2\bin\cygxslt-0.dll - ImageBase: 73d70000 ImageSize: 00021000 Regards Ralf ------=_NextPart_000_000D_01C18E51.83EBFA20 Content-Type: application/octet-stream; name="rebase-list-option.dif" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="rebase-list-option.dif" --- rebase.cc.orig Mon Dec 24 11:33:46 2001=0A= +++ rebase.cc Wed Dec 26 19:53:36 2001=0A= @@ -28,6 +28,8 @@=0A= #include #include =20 +#include + using namespace std; =20 string PosixToWin32(const string& aPosixPath); @@ -39,6 +41,7 @@ ULONG theImageBase =3D 0; BOOL theDownFlag =3D FALSE; ULONG theOffset =3D 0; int theArgsIndex =3D 0; +int theListFlag =3D 0;=20 =20 void main(int argc, char* argv[]) @@ -48,10 +51,20 @@ main(int argc, char* argv[]) =20 for (int i =3D theArgsIndex; i < argc; i++) { + string aFile =3D PosixToWin32(argv[i]); + if (theListFlag) + { + long image[60];=20 + =20 + FILE *f =3D fopen(const_cast(aFile.c_str()),"r"); + fread(&image,sizeof(image),1,f); + printf("%-60s - ImageBase: %08x ImageSize: = %08x\n",aFile.c_str(),image[45],image[52]); + fclose(f); + } + else { if (theDownFlag) aNewImageBase -=3D theOffset; =20 - string aFile =3D PosixToWin32(argv[i]); ULONG anOldImageSize, anOldImageBase, aNewImageSize; ULONG aPrevNewImageBase =3D aNewImageBase; BOOL aStatus =3D ReBaseImage( @@ -82,6 +95,8 @@ main(int argc, char* argv[]) if (!theDownFlag) aNewImageBase +=3D theOffset; } + } + =20 =20 exit(0); } @@ -97,7 +112,7 @@ PosixToWin32(const string& aPosixPath) void ParseArgs(int argc, char* argv[]) { - const char* anOptions =3D "b:do:"; + const char* anOptions =3D "b:do:l:"; for (int anOption; (anOption =3D getopt(argc, argv, anOptions)) !=3D = -1;) { switch (anOption) @@ -111,6 +126,9 @@ ParseArgs(int argc, char* argv[]) case 'o': theOffset =3D StringToUlong(optarg); break; + case 'l': + theListFlag =3D 1; + break; default: Usage(); exit(1); @@ -118,12 +136,15 @@ ParseArgs(int argc, char* argv[]) } } =20 - if (theImageBase =3D=3D 0) + if (theImageBase =3D=3D 0 && !theListFlag) { Usage(); exit(1); } =20 + if (theListFlag) + theArgsIndex =3D optind-1; + else=20 theArgsIndex =3D optind; } =20 @@ -144,6 +165,7 @@ StringToUlong(const string& aString) void Usage() { - cerr << "usage: rebase -b BaseAddress [-d] -o Offset ImageFileName = ..." << endl; + cerr << "usage: rebase -b BaseAddress [-d] -o Offset ... = rebase " << endl; + cerr << "usage: rebase -l ... list Imagebase and -size = of " << endl; } =20 ------=_NextPart_000_000D_01C18E51.83EBFA20 Content-Type: application/octet-stream; name="rebase.cc" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="rebase.cc" /* * Copyright (c) 2001 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 the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id: rebase.cc,v 1.5 2001/12/18 20:21:19 jtishler Exp $ */ #include #include #include #include #include #include #include #include #include #include using namespace std; string PosixToWin32(const string& aPosixPath); void ParseArgs(int argc, char* argv[]); unsigned long StringToUlong(const string& aString); void Usage(); ULONG theImageBase = 0; BOOL theDownFlag = FALSE; ULONG theOffset = 0; int theArgsIndex = 0; int theListFlag = 0; void main(int argc, char* argv[]) { ParseArgs(argc, argv); ULONG aNewImageBase = theImageBase; for (int i = theArgsIndex; i < argc; i++) { string aFile = PosixToWin32(argv[i]); if (theListFlag) { long image[60]; FILE *f = fopen(const_cast(aFile.c_str()),"r"); fread(&image,sizeof(image),1,f); printf("%-60s - ImageBase: %08x ImageSize: %08x\n",aFile.c_str(),image[45],image[52]); fclose(f); } else { if (theDownFlag) aNewImageBase -= theOffset; ULONG anOldImageSize, anOldImageBase, aNewImageSize; ULONG aPrevNewImageBase = aNewImageBase; BOOL aStatus = ReBaseImage( const_cast(aFile.c_str()), // CurrentImageName 0, // SymbolPath TRUE, // fReBase FALSE, // fRebaseSysfileOk theDownFlag, // fGoingDown 0, // CheckImageSize &anOldImageSize, // OldImageSize &anOldImageBase, // OldImageBase &aNewImageSize, // NewImageSize &aNewImageBase, // NewImageBase time(0)); // TimeStamp // ReBaseImage seems to never returns false! DWORD aStatus2 = GetLastError(); if (aStatus2 != 0) { cerr << "ReBaseImage() failed with last error = " << GetLastError() << endl; exit(2); } cout << aFile << hex << ": new base = " << ((theDownFlag) ? aNewImageBase : aPrevNewImageBase) << ", new size = " << aNewImageSize + theOffset << endl; if (!theDownFlag) aNewImageBase += theOffset; } } exit(0); } string PosixToWin32(const string& aPosixPath) { char aWin32Path[MAX_PATH]; cygwin_conv_to_win32_path(aPosixPath.c_str(), aWin32Path); return aWin32Path; } void ParseArgs(int argc, char* argv[]) { const char* anOptions = "b:do:l:"; for (int anOption; (anOption = getopt(argc, argv, anOptions)) != -1;) { switch (anOption) { case 'b': theImageBase = StringToUlong(optarg); break; case 'd': theDownFlag = TRUE; break; case 'o': theOffset = StringToUlong(optarg); break; case 'l': theListFlag = 1; break; default: Usage(); exit(1); break; } } if (theImageBase == 0 && !theListFlag) { Usage(); exit(1); } if (theListFlag) theArgsIndex = optind-1; else theArgsIndex = optind; } unsigned long StringToUlong(const string& aString) { stringstream ss; unsigned long aUlong; string::size_type anIndex = aString.find("0x"); if (anIndex == 0) ss << hex << string(aString, 2, aString.size() - 2); else ss << aString; ss >> aUlong; return aUlong; } void Usage() { cerr << "usage: rebase -b BaseAddress [-d] -o Offset ... rebase " << endl; cerr << "usage: rebase -l ... list Imagebase and -size of " << endl; } ------=_NextPart_000_000D_01C18E51.83EBFA20 Content-Type: application/octet-stream; name="Makefile" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="Makefile" rebase: rebase.cc g++ -g -o $@ $< -limagehlp install: rebase /usr/bin/install rebase.exe /usr/local/bin ------=_NextPart_000_000D_01C18E51.83EBFA20 Content-Type: text/plain; charset=us-ascii -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/ ------=_NextPart_000_000D_01C18E51.83EBFA20--