--- rebase.cc.orig Mon Dec 24 11:33:46 2001 +++ rebase.cc Wed Dec 26 19:53:36 2001 @@ -28,6 +28,8 @@ #include #include +#include + using namespace std; string PosixToWin32(const string& aPosixPath); @@ -39,6 +41,7 @@ ULONG theImageBase = 0; BOOL theDownFlag = FALSE; ULONG theOffset = 0; int theArgsIndex = 0; +int theListFlag = 0; void main(int argc, char* argv[]) @@ -48,10 +51,20 @@ main(int argc, char* argv[]) 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; - string aFile = PosixToWin32(argv[i]); ULONG anOldImageSize, anOldImageBase, aNewImageSize; ULONG aPrevNewImageBase = aNewImageBase; BOOL aStatus = ReBaseImage( @@ -82,6 +95,8 @@ main(int argc, char* argv[]) if (!theDownFlag) aNewImageBase += theOffset; } + } + exit(0); } @@ -97,7 +112,7 @@ PosixToWin32(const string& aPosixPath) void ParseArgs(int argc, char* argv[]) { - const char* anOptions = "b:do:"; + const char* anOptions = "b:do:l:"; for (int anOption; (anOption = getopt(argc, argv, anOptions)) != -1;) { switch (anOption) @@ -111,6 +126,9 @@ ParseArgs(int argc, char* argv[]) case 'o': theOffset = StringToUlong(optarg); break; + case 'l': + theListFlag = 1; + break; default: Usage(); exit(1); @@ -118,12 +136,15 @@ ParseArgs(int argc, char* argv[]) } } - if (theImageBase == 0) + if (theImageBase == 0 && !theListFlag) { Usage(); exit(1); } + if (theListFlag) + theArgsIndex = optind-1; + else theArgsIndex = optind; } @@ -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; }