DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 44UD6d9A2107400
Authentication-Results: delorie.com;
	dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=eCHH3yHy
X-Recipient: archive-cygwin@delorie.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1868B385E830
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
	s=default; t=1717074398;
	bh=vYIn1rmPFdimFsMllLcTNNBqor4q0mVIF4Mre6CbpOA=;
	h=Date:Subject:To:Cc:References:In-Reply-To:List-Id:
	 List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe:
	 From:Reply-To:From;
	b=eCHH3yHyHf/e4nJnwuetEpRfELtuSV1Iv0TzYQgmnEnDvSKaXyFIkWK9sxcdMN63i
	 ktSvfc2QE/TphdSDAWjQFp4SUix2oyWUimZN0EZuBAK0cQ5mULJTWV6wX6b8bTXaUU
	 Io1YlqGcP4Q8I0gmIrT27pakqAVdTvfIW9g9Jqqk=
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 14F80385B529
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 14F80385B529
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717074333; cv=none;
 b=nw2jGdL9JbU11Nm0DzbtLCRUEZFxL+CxEZV4WJ5KtBH5/JXA1m3BsFH+heyf6F8M9/Q/fNFUHxYfEvJLQ+q5pLn5hiAD6VARnPIRXLj6ap4dQwVpPNwJ2/byWpwf0gWMwXq3s590StamtNcbXRb3Wez59L0+sGnCyac3sEwrJ+M=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
 t=1717074333; c=relaxed/simple;
 bh=7qUKK2zzMRdFlfgyTqu3HqLOUV0QWOYM0jgj452cb4o=;
 h=Message-ID:Date:MIME-Version:From:Subject:To;
 b=uepdeGX7W9drf2dnuq52Lmj030ul+nNfOVglKGwNHLHS748pProSVwY4+VFpj2F1x06QgxsoJ9ENrxmm6fklekk/glDTkCkuZiIQRQToGuNEEG9z8EKx6XX48CAL4O+jWzdj0SBb3rKD3Vmb95GZ9O6l4Y40U4ykdfDlUILx4E8=
ARC-Authentication-Results: i=1; server2.sourceware.org
X-SNCR-Rigid: 656684A015A4597D
X-Originating-IP: [86.139.167.83]
X-OWM-Source-IP: 86.139.167.83
X-OWM-Env-Sender: jon.turney@dronecode.org.uk
X-VadeSecure-score: verdict=clean score=0/300, class=clean
X-RazorGate-Vade: gggruggvucftvghtrhhoucdtuddrgedvledrvdekgedgheejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuueftkffvkffujffvgffngfevqffopdfqfgfvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefkffggfgfhuffvvehfjggtgfesthejredttddvjeenucfhrhhomheplfhonhcuvfhurhhnvgihuceojhhonhdrthhurhhnvgihsegurhhonhgvtghouggvrdhorhhgrdhukheqnecuggftrfgrthhtvghrnhepheffgfegkeeuudetiefgkeevtdekfefgleffvddtheelfeeugfdtkeefheekheevnecukfhppeekiedrudefledrudeijedrkeefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehhvghloheplgduledvrdduieekrddurddutdelngdpihhnvghtpeekiedrudefledrudeijedrkeefpdhmrghilhhfrhhomhepjhhonhdrthhurhhnvgihsegurhhonhgvtghouggvrdhorhhgrdhukhdpnhgspghrtghpthhtohepvddprhgtphhtthhopegthihgfihinhestgihghifihhnrdgtohhmpdhrtghpthhtohepmhgrrhhtihhnrdhlrdifvghgvgesghhmrghilhdrtghomhdprhgvvhfkrfephhhoshhtkeeiqddufeelqdduieejqdekfedrrhgrnhhgvgekiedqudefledrsghttggvnhhtrhgrlhhplhhushdrtghomhdprghuthhhpghushgvrhepjhhonhhtuhhrnhgvhiessghtihhnthgvrhhnvghtrdgtohhm
 pdhgvghokffrpefiuedpoffvtefjohhsthepshgrqdhprhguqdhrghhouhhtqddttddu
X-RazorGate-Vade-Verdict: clean 0
X-RazorGate-Vade-Classification: clean
Message-ID: <e550670e-417d-4fa2-9686-aa8464633be5@dronecode.org.uk>
Date: Thu, 30 May 2024 14:05:28 +0100
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: LD_PRELOAD for Win32?
To: Martin Wege <martin.l.wege@gmail.com>
Cc: cygwin@cygwin.com
References: <CANH4o6NbWgcdna8sJUcuPwrmZZDrOeCDu-zU6+FsJS45Fg0mVg@mail.gmail.com>
Content-Language: en-US
In-Reply-To: <CANH4o6NbWgcdna8sJUcuPwrmZZDrOeCDu-zU6+FsJS45Fg0mVg@mail.gmail.com>
X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00, JMQ_SPF_NEUTRAL,
 KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,
 SPF_HELO_PASS, SPF_PASS, TXREP,
 T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6
X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on
 server2.sourceware.org
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.30
Precedence: list
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
From: Jon Turney via Cygwin <cygwin@cygwin.com>
Reply-To: Jon Turney <jon.turney@dronecode.org.uk>
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset="us-ascii"; Format="flowed"
Errors-To: cygwin-bounces+archive-cygwin=delorie.com@cygwin.com
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie.com@cygwin.com>

On 25/05/2024 22:55, Martin Wege via Cygwin wrote:
> Hello,
> 
> Does Cygwin or Win32 have something like LD_PRELOAD, so I can
> override/substitute functions in a DLL or EXE, like it is common for
> UNIX/Linux ELF shared libraries?

This is not generally available on Win32, due to limitations of the PE 
file format.

(basically, the import table lists symbols which are imported, and where 
they are imported from, so the module (shared library or executable) 
which provides a given symbol is determined when the module is *linked*, 
not when it is loaded.


However, when googling "cygwin LD_PRELOAD" (which surely you must have 
done before asking this question?) I discover that there's some voodoo 
in the cygwin DLL (hookapi.cc) which claims to do something like that, 
but it seems (i) this requires the preloaded DLL to explicitly hook 
functions it's overriding, and (ii) maybe only works on functions 
imported by the running executable.

It would be nice to have some documentation for that, and/or a simple 
example which could serve as a testcase.

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple
