Delphi 64-Bit Code Hook Possible for Runtime VCL Style AV?
Asked Answered
S

0

6

It appears as though there may not be a user solution without a Delphi Tokyo fix, but it seems worth asking.

The simplest way to make this AV reproducible.

  1. Start a new VCL project.
  2. Change Platform to 64-Bit.
  3. Link with Runtime Packages.
  4. Set Style to "Amakrits".
  5. Add High Entropy ASLR Flag. Note - This surfaces out a lot of Win64 bugs.

My Dpr file looks like this (there is no code in the main unit).

program MaskedCrash2;

{$SETPEOPTFLAGS $160} //High Entropy ASLR Flag causes issues with incorrect 64-bit programs.

uses
  Vcl.Forms,
  MaskedCrashed2MainUnt in 'MaskedCrashed2MainUnt.pas' {Form3},
  Vcl.Themes,
  Vcl.Styles;

{$R *.res}

begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  TStyleManager.TrySetStyle('Amakrits');
  Application.CreateForm(TForm3, Form3);
  Application.Run;
end.

The AV appears in Delphi Tokyo in StyleUtils.inc in the procedure TseBitmapLink.CheckingMasked(const Margin: TRect); .

Despite the warning I just recently found at the top of StyleUtils.inc:

//TODO -oUnassigned -cImplement : x64 : Implement PlatformNotImplemented in this unit or disable for x64.

This part of the code was very stable in Delphi Berlin. Dialogs are another matter as posts here show. I have submitted the offending code to the Quality Portal.

Note: In order to get High Entropy ASLR (as shown by process explorer), using runtime packages and setting the High Entropy bit ($20) is necessary as well as $40 for DEP and $100 for ASLR.

In addition to making a program more secure, using High Entropy ASLR has definitely contributed to finding errors in Windows Messages (e.g. using Integer cast in SendMessage, etc.). Using High Entropy ASLR caught many errors in my code when switching to 64-bit that were being masked.

Recompiling Runtime Packages does not seem to be a possibility and using a runtime hook was correctly suggested.

However, the method procedure TseBitmapLink.CheckingMasked(const Margin: TRect); is included in the implementation section:

implementation

uses
  System.Types, System.UITypes, System.SysUtils, Winapi.UxTheme, Vcl.StdCtrls, Vcl.ComCtrls,
  Vcl.Mask, Vcl.GraphUtil, Vcl.ImgList, Vcl.Menus, Vcl.Grids, Vcl.CategoryButtons,
  Vcl.ButtonGroup, Vcl.ExtCtrls, Vcl.Consts, Vcl.SysStyles;

{$I StyleUtils.inc}
{$I StyleAPI.inc}

So is there any way to use a runtime hook as the TseBitmapLink is not available to end users who use runtime packages?

Is this correct?

Does anyone have any suggestions for keeping High Entropy ASLR and Delphi Tokyo?

Sorry this took so long, trying to be complete.

Shapeless answered 8/11, 2017 at 19:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.