MCH v3.1.8 x64 Crash when exception raised in hooked procedure
Posted: Thu Aug 05, 2021 1:48 pm
Hi Madshi,
MadCodeHook: v3.1.8
Compiler: Delphi 10.3.3 (also tested XE3)
OS: Windows 21H1 64-bit
We have a problem with a 64-bit program crashing when an exception is raised inside a hooked procedure. When compiled as 32-bit everything works as expected, so we're not sure if we are doing something wrong or its an issue in madCodeHook.
Below is a trivial example that reproduces the issue only when compiled to 64-bit:
Many thanks,
Tony
MadCodeHook: v3.1.8
Compiler: Delphi 10.3.3 (also tested XE3)
OS: Windows 21H1 64-bit
We have a problem with a 64-bit program crashing when an exception is raised inside a hooked procedure. When compiled as 32-bit everything works as expected, so we're not sure if we are doing something wrong or its an issue in madCodeHook.
Below is a trivial example that reproduces the issue only when compiled to 64-bit:
Code: Select all
unit FMain;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses
madCodeHook;
var
HookMeNext: procedure;
procedure HookMe;
begin
raise Exception.Create('Hooked method');
end;
procedure HookMeCallBack;
begin
HookMeNext;
end;
procedure DontHookMe;
begin
raise Exception.Create('Not Hooked method');
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
HookMe;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
DontHookMe;
end;
initialization
HookCode(@HookMe, @HookMeCallBack, @HookMeNext);
end.
Tony