public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Jason Tishler <jason@tishler.net>
To: cygwin@cygwin.com
Subject: rebase utility (was Re: dll_list::load_after_fork() blues ...)
Date: Wed, 12 Dec 2001 05:14:00 -0000	[thread overview]
Message-ID: <20011212080759.A1224@dothill.com> (raw)
In-Reply-To: <20011208010222.GC27247@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 578 bytes --]

Chris,

On Fri, Dec 07, 2001 at 08:02:22PM -0500, Christopher Faylor wrote:
> A rebase utility for cygwin would be pretty nice, I think.

Attached is the beginning of a rebase utility.  It is modeled after the
MS one:

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tools/perfutil_2z39.asp

So far I have only implemented the -b and -d options.

If a stand-alone utility is still deemed useful (as opposed to integrating
the functionality directly into setup.exe), then I will "GNU-ize", clean
up, and submit it to cygwin-patches for consideration.

Jason

[-- Attachment #2: rebase.cc --]
[-- Type: text/plain, Size: 3236 bytes --]

/*
 * 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.4 2001/12/12 12:36:57 jtishler Exp $
 */

#include <iostream>
#include <sstream>
#include <string>
#include <time.h>
#include <stdlib.h>
#include <getopt.h>
#include <sys/cygwin.h>
#include <windows.h>
#include <imagehlp.h>

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;
int theArgsIndex = 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]);
		ULONG anOldImageSize, anOldImageBase, aNewImageSize;
		ULONG aPrevNewImageBase = aNewImageBase;
		BOOL aStatus = ReBaseImage(
			const_cast<char*>(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 << endl;
	}

	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:d";
	for (int anOption; (anOption = getopt(argc, argv, anOptions)) != -1;)
	{
		switch (anOption)
		{
			case 'b':
				theImageBase = StringToUlong(optarg);
				break;
			case 'd':
				theDownFlag = TRUE;
				break;
			default:
				Usage();
				exit(1);
				break;
		}
	}

	if (theImageBase == 0)
	{
		Usage();
		exit(1);
	}

	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] ImageFileName ..." << endl;
}


[-- Attachment #3: Type: text/plain, Size: 214 bytes --]

--
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/

  reply	other threads:[~2001-12-12 13:04 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <Pine.LNX.4.33.0112061015100.898-100000@starship.python.net>
2001-12-06  9:44 ` dll_list::load_after_fork() blues (was Re: [ python-Bugs-489709 ] Building Fails ...) Jason Tishler
2001-12-06 10:12   ` Charles Wilson
2001-12-07  6:54     ` Michael Hudson
2001-12-07  7:03       ` David Abrahams
2001-12-07  7:32         ` Jason Tishler
2001-12-07 15:11     ` Robert Collins
2001-12-07 17:02       ` Charles Wilson
2001-12-07 17:29         ` Christopher Faylor
2001-12-12  5:14           ` Jason Tishler [this message]
2001-12-12  5:45             ` rebase utility (was Re: dll_list::load_after_fork() blues ...) Robert Collins
2001-12-12  6:04             ` Jason Tishler
2001-12-07 18:41         ` dll_list::load_after_fork() blues (was Re: [ python-Bugs-489709 ] Building Fails ...) Robert Collins
2001-12-07 18:19       ` Norman Vine
2001-12-07 18:44         ` Robert Collins
2001-12-10  4:46       ` Jason Tishler
2001-12-10  5:13         ` Robert Collins
2001-12-10  7:44           ` Jason Tishler
2001-12-16  0:12             ` Robert Collins
2001-12-10  7:23         ` Michael Hudson
2001-12-10 10:46           ` Norman Vine
2001-12-12  5:56             ` Jason Tishler
2001-12-18 13:12               ` Cygwin fork() rebase solution (was Re: dll_list::load_after_fork() blues ...) Jason Tishler
2001-12-18 14:07                 ` Robert Collins
2001-12-18 19:56                   ` cygwin " Christopher Faylor
2001-12-21  5:02                     ` Jason Tishler
2001-12-22 17:08                       ` Chris McDonough
2002-01-02 10:45                         ` Jason Tishler
2001-12-19 22:46                 ` Cygwin " Norman Vine
2001-12-16  0:31         ` dll_list::load_after_fork() blues (was Re: [ python-Bugs-489709 ] Building Fails ...) Robert Collins
2001-12-18  5:31           ` Jason Tishler
2001-12-18  6:35             ` Robert Collins
2001-12-07  6:04   ` Jason Tishler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20011212080759.A1224@dothill.com \
    --to=jason@tishler.net \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).