Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Installing a DelayedHandlerHook crashes



Permlink Replies: 3 - Last Post: Jun 1, 2017 7:19 AM Last Post By: Christian Aymon
Christian Aymon

Posts: 30
Registered: 10/17/99
Installing a DelayedHandlerHook crashes
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 30, 2017 10:08 AM
I created a new VCL (64 bits) application with ''DelayedDllHandler'' as
the first in the dpr uses clause. Here is the unit in its simplest form:

unit DelayedDllHandler;
interface
uses
System.SysUtils;

implementation

var
LOldNotifyHook, LOldFailureHook: TDelayedLoadHook;

function DelayedHandlerHook(dliNotify: dliNotification; pdli:
PDelayLoadInfo): Pointer; stdcall;
begin
// Do nothing
end;

initialization
LOldNotifyHook := SetDliNotifyHook2(DelayedHandlerHook);
LOldFailureHook := SetDliFailureHook2(DelayedHandlerHook);
finalization
SetDliNotifyHook2(LOldNotifyHook);
SetDliFailureHook2(LOldFailureHook);
end.

The program crashes.

I've tried to step using the CPU view. The problem appears in the
(external) function WTSRegisterSessionNotification (in wtsapi32.dll,
which is delayed...)
The function pushes a bunch of registers, calls DelayLoadHelper2 pops
the registers, and finally ''returns'' with an a ''jmp rax'' that leads
nowhere.

What could be the reason?

It also crashes in 32 bits.

Thanks for helping.

Chris
Christian Aymon

Posts: 30
Registered: 10/17/99
Re: Installing a DelayedHandlerHook crashes
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 31, 2017 12:12 AM   in response to: Christian Aymon in response to: Christian Aymon
On 30-May-17 19:08, Christian Aymon wrote:
I created a new VCL (64 bits) application with ''DelayedDllHandler'' as
the first in the dpr uses clause. Here is the unit in its simplest form:

unit DelayedDllHandler;
interface
uses
System.SysUtils;

implementation

var
LOldNotifyHook, LOldFailureHook: TDelayedLoadHook;

function DelayedHandlerHook(dliNotify: dliNotification; pdli:
PDelayLoadInfo): Pointer; stdcall;
begin
// Do nothing
end;

initialization
LOldNotifyHook := SetDliNotifyHook2(DelayedHandlerHook);
LOldFailureHook := SetDliFailureHook2(DelayedHandlerHook);
finalization
SetDliNotifyHook2(LOldNotifyHook);
SetDliFailureHook2(LOldFailureHook);
end.

The program crashes.

I've tried to step using the CPU view. The problem appears in the
(external) function WTSRegisterSessionNotification (in wtsapi32.dll,
which is delayed...)
The function pushes a bunch of registers, calls DelayLoadHelper2 pops
the registers, and finally ''returns'' with an a ''jmp rax'' that leads
nowhere.

What could be the reason?

It also crashes in 32 bits.

Thanks for helping.

Chris

It seems that returning ''nil'' in the DelayedHandlerHook solves the issue.

The docwiki example:
http://docwiki.embarcadero.com/CodeExamples/Tokyo/en/DelayedLoading_(Delphi)
doesn't show this...

(Delphi 10.1 Berlin)
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Installing a DelayedHandlerHook crashes
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 31, 2017 9:53 AM   in response to: Christian Aymon in response to: Christian Aymon
Christian Aymon wrote:

It seems that returning ''nil'' in the DelayedHandlerHook solves the
issue.

The docwiki example:
http://docwiki.embarcadero.com/CodeExamples/Tokyo/en/DelayedLoading_(Delphi)
doesn't show this...

Yes, it does:

function MyDelayedLoadHook(dliNotify: dliNotification; pdli:
PDelayLoadInfo): Pointer; stdcall;
begin
  ...
  Result := nil;
end;


--
Remy Lebeau (TeamB)
Christian Aymon

Posts: 30
Registered: 10/17/99
Re: Installing a DelayedHandlerHook crashes
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2017 7:19 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
On 31-May-17 18:53, Remy Lebeau (TeamB) wrote:

Yes, it does:

function MyDelayedLoadHook(dliNotify: dliNotification; pdli:
PDelayLoadInfo): Pointer; stdcall;
begin
   ...
   Result := nil;
end;

How can I have missed that? :-/

Mea culpa.

Thank you.

Chris
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02